* @since 4.1.0 */ namespace Beyondwords\Wordpress\Component\Post\PlayerStyle; use Beyondwords\Wordpress\Core\ApiClient; use Beyondwords\Wordpress\Core\Core; use Beyondwords\Wordpress\Core\CoreUtils; use Beyondwords\Wordpress\Component\Post\PostMetaUtils; use Beyondwords\Wordpress\Component\Settings\Languages\Languages; use Beyondwords\Wordpress\Component\Settings\PlayerStyle\PlayerStyle as PlayerStyleSetting; use Beyondwords\Wordpress\Component\Settings\SettingsUtils; /** * PlayerStyle setup * * @since 4.1.0 */ class PlayerStyle { /** * Constructor */ public function __construct() { add_action('rest_api_init', array($this, 'restApiInit')); add_action('wp_loaded', function () { $postTypes = SettingsUtils::getSupportedPostTypes(); if (is_array($postTypes)) { foreach ($postTypes as $postType) { add_action("save_post_{$postType}", array($this, 'save'), 10); } } }); } /** * @since 4.1.0 */ public function element($post) { $projectId = PostMetaUtils::getProjectId($post->ID); $playerStyle = PostMetaUtils::getPlayerStyle($post->ID); $allPlayerStyles = PlayerStyleSetting::getCachedPlayerStyles($projectId); wp_nonce_field('beyondwords_player_style', 'beyondwords_player_style_nonce'); ?>
[0-9]+)/player-styles', array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array($this, 'playerStylesRestApiResponse'), 'permission_callback' => function () { return current_user_can('edit_posts'); }, )); } /** * "Player styles" WP REST API response (required for the Gutenberg editor). * * @since 4.1.0 * * @return \WP_REST_Response */ public function playerStylesRestApiResponse(\WP_REST_Request $data) { $params = $data->get_url_params(); $response = PlayerStyleSetting::getCachedPlayerStyles($params['projectId']); // Convert from object to array so we can use find() in Block Editor JS. $response = array_values($response); return new \WP_REST_Response($response); } }