\StreamSera\PostTypes\Player::POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => 100, 'orderby' => 'title', 'order' => 'ASC' ) ) as $p ) { $players[ $p->ID ] = streamsera_plain_title( $p ); } $layouts = array( '' => __( 'Player default', 'streamsera' ) ); foreach ( streamsera_layouts() as $id => $layout ) { $layouts[ $id ] = is_array( $layout ) ? ( $layout['label'] ?? $id ) : (string) $layout; } return array( 'players' => $players, 'layouts' => $layouts ); } /** * Render a player for a builder (never fatal, editor-friendly notice). * * @param int $player_id Player. * @param string $layout Layout. * @return string */ public static function render( $player_id, $layout = '' ) { $player_id = (int) $player_id; if ( ! $player_id ) { return self::notice( __( 'StreamSera: choose a player.', 'streamsera' ) ); } // Unknown / unpublished / deleted player: tell editors, render nothing for visitors. if ( \StreamSera\PostTypes\Player::POST_TYPE !== get_post_type( $player_id ) || 'publish' !== get_post_status( $player_id ) ) { return self::notice( __( 'StreamSera: player not found.', 'streamsera' ) ); } $html = streamsera_render_player( $player_id, array_filter( array( 'layout' => $layout ) ) ); // Core returns an inline notice (no station, …) for editors; never leak it to visitors. if ( ! self::can_see_notices() && false !== strpos( $html, 'class="streamsera-notice"' ) ) { return ''; } return $html; } /** * Whether builder notices may be shown (editors, or inside a builder's editor/preview). * * @return bool */ public static function can_see_notices() { if ( current_user_can( 'edit_posts' ) ) { return true; } if ( class_exists( '\\Elementor\\Plugin' ) && isset( \Elementor\Plugin::$instance ) ) { $elementor = \Elementor\Plugin::$instance; if ( ( isset( $elementor->editor ) && $elementor->editor->is_edit_mode() ) || ( isset( $elementor->preview ) && $elementor->preview->is_preview_mode() ) ) { return true; } } if ( function_exists( 'et_core_is_fb_enabled' ) && et_core_is_fb_enabled() ) { return true; } return false; } /** * Editor-only notice. * * @param string $message Message. * @return string */ private static function notice( $message ) { return self::can_see_notices() ? '