* @since 3.0.0 */ namespace Beyondwords\Wordpress\Component\Post\Metabox; use Beyondwords\Wordpress\Component\Post\GenerateAudio\GenerateAudio; use Beyondwords\Wordpress\Component\Post\DisplayPlayer\DisplayPlayer; use Beyondwords\Wordpress\Component\Post\PostMetaUtils; use Beyondwords\Wordpress\Component\Post\SelectVoice\SelectVoice; use Beyondwords\Wordpress\Component\Post\PlayerStyle\PlayerStyle; use Beyondwords\Wordpress\Component\Settings\SettingsUtils; use Beyondwords\Wordpress\Core\Environment; /** * PostMetabox setup * * @since 3.0.0 */ class Metabox { /** * @var \Beyondwords\Wordpress\Core\ApiClient */ private $apiClient; /** * Init. * * @since 4.0.0 */ public function __construct($apiClient) { $this->apiClient = $apiClient; } /** * Init. * * @since 4.0.0 */ public function init() { add_action('admin_enqueue_scripts', array($this, 'adminEnqueueScripts')); add_action("add_meta_boxes", array($this, 'addMetaBox')); } /** * Enque JS for Bulk Edit feature. */ public function adminEnqueueScripts($hook) { // Only enqueue for Post screens if ($hook === 'post.php' || $hook === 'post-new.php') { // Register the Classic Editor "Metabox" CSS wp_enqueue_style( 'beyondwords-Metabox', BEYONDWORDS__PLUGIN_URI . 'src/Component/Post/Metabox/Metabox.css', false, BEYONDWORDS__PLUGIN_VERSION ); } } /** * Adds the meta box container. * * @param string $postType */ public function addMetaBox($postType) { $postTypes = SettingsUtils::getCompatiblePostTypes(); if (is_array($postTypes) && ! in_array($postType, $postTypes)) { return; } add_meta_box( 'beyondwords', __('BeyondWords', 'speechkit'), array($this, 'renderMetaBoxContent'), $postType, 'side', 'default', [ '__back_compat_meta_box' => true, ] ); } /** * Render Meta Box content. * * @param int|WP_Post $post The WordPress post ID, or post object. * * @since 3.0.0 * @since 3.7.0 Show "Pending review" notice for posts with status of "pending" * @since 4.0.0 Content ID is no longer an int * @since 4.1.0 Add "Player style" and update component display conditions */ public function renderMetaBoxContent($post) { $post = get_post($post); if (!($post instanceof \WP_Post)) { return; } // Show errors for posts with/without audio $this->errors($post); $contentId = PostMetaUtils::getContentId($post->ID); if ($contentId) { // Enable these components for posts with audio if (get_post_status($post) === 'pending') { $this->pendingReviewNotice($post); } else { $this->playerEmbed($post); } echo '
'; (new DisplayPlayer())->element($post); } else { $this->errors($post); // Enable these components for posts without audio (new GenerateAudio())->element($post); } // Enable these components for posts with/without audio (new SelectVoice($this->apiClient))->element($post); (new PlayerStyle())->element($post); echo '
'; $this->help(); } /** * The "Pending review" message, shown instead of the audio player * if the post status in WordPress is "pending". * * This message is displayed instead of the player because the player * cannot be rendered for audio which has been created * with { published: false }. * * @since 3.7.0 * * @var \WP_Post $post Post. */ public function pendingReviewNotice($post) { $projectUrl = sprintf( '%s/dashboard/project/%d/content', Environment::getDashboardUrl(), PostMetaUtils::getProjectId($post) ); ?>
%s', esc_url($projectUrl), esc_html__('BeyondWords dashboard', 'speechkit') ) ); ?>
ID); $contentId = PostMetaUtils::getContentId($post->ID); $previewToken = PostMetaUtils::getPreviewToken($post->ID); if (! $projectId || ! $contentId) { return; } ?> ID); if ($error) : ?>

regenerateInstructions(); ?>

%s', 'mailto:support@beyondwords.io', 'support@beyondwords.io') ); ?>