* @since 4.1.0 */ namespace Beyondwords\Wordpress\Component\Post\PlayerStyle; use Beyondwords\Wordpress\Component\Post\PostMetaUtils; use Beyondwords\Wordpress\Component\Settings\Fields\PlayerStyle\PlayerStyle as PlayerStyleSetting; use Beyondwords\Wordpress\Component\Settings\SettingsUtils; /** * PlayerStyle * * @since 4.1.0 */ class PlayerStyle { /** * Player styles. * * @var array Arry of player styles. */ public const PLAYER_STYLES = [ 'small', 'standard', 'large', 'screen', 'video', ]; /** * Constructor * * @since 6.0.0 Make static. */ public static function init() { add_action('rest_api_init', [self::class, 'restApiInit']); add_action('wp_loaded', function (): void { $postTypes = SettingsUtils::getCompatiblePostTypes(); if (is_array($postTypes)) { foreach ($postTypes as $postType) { add_action("save_post_{$postType}", [self::class, 'save'], 10); } } }); } /** * HTML output for this component. * * @since 4.1.0 * @since 4.5.1 Hide element if no language data exists. * @since 6.0.0 Make static. * * @param \WP_Post $post The post object. * * @return string|null */ public static function element($post) { $playerStyle = PostMetaUtils::getPlayerStyle($post->ID); $allPlayerStyles = PlayerStyleSetting::getOptions(); wp_nonce_field('beyondwords_player_style', 'beyondwords_player_style_nonce'); ?>

[0-9]+)/player-styles', [ 'methods' => \WP_REST_Server::READABLE, 'callback' => [self::class, 'playerStylesRestApiResponse'], 'permission_callback' => fn() => current_user_can('edit_posts'), ]); } /** * "Player styles" WP REST API response (required for the Gutenberg editor). * * @since 4.1.0 * @since 5.0.0 Stop saving a dedicated player styles transient for each project ID. * @since 6.0.0 Make static. */ public static function playerStylesRestApiResponse() { $response = PlayerStyleSetting::getOptions(); // Convert from object to array so we can use find() in Block Editor JS. $response = array_values($response); return new \WP_REST_Response($response); } }