* @since 3.0.0 */ namespace Beyondwords\Wordpress\Component\Post\Panel\Inspect; use Beyondwords\Wordpress\Component\Post\PostMetaUtils; use Beyondwords\Wordpress\Component\Settings\SettingsUtils; /** * Inspect setup * * @since 3.0.0 */ class Inspect { /** * Constructor */ public function __construct() { add_action('admin_enqueue_scripts', array($this, 'adminEnqueueScripts')); add_action("add_meta_boxes", array($this, 'addMetaBox')); add_filter('default_hidden_meta_boxes', array($this, 'hideMetaBox')); } /** * Enqueue JS for Inspect feature. */ public function adminEnqueueScripts($hook) { // Only enqueue for Post screens if ($hook === 'post.php' || $hook === 'post-new.php') { // Clipboard.js dependency wp_enqueue_script( 'clipboard', 'https://cdn.jsdelivr.net/npm/clipboard@2.0.10/dist/clipboard.min.js', array('jquery'), null, true ); // Our script for the "Copy" button wp_enqueue_script( 'beyondwords-inspect', BEYONDWORDS__PLUGIN_URI . 'src/Component/Post/Panel/Inspect/js/inspect.js', array('jquery', 'clipboard'), BEYONDWORDS__PLUGIN_VERSION, true ); } } /** * Hides the metabox by default. * * @param string[] $hidden An array of IDs of meta boxes hidden by default. */ public function hideMetaBox($hidden) { $hidden[] = 'beyondwords__inspect'; return $hidden; } /** * Adds the meta box container for the Classic Editor. * * The Block Editor UI is handled using JavaScript. * * @param $postType */ public function addMetaBox($postType) { $postTypes = SettingsUtils::getSupportedPostTypes(); if (is_array($postTypes) && ! in_array($postType, $postTypes)) { return; } add_meta_box( 'beyondwords__inspect', __('BeyondWords', 'speechkit') . ': ' . __('Inspect', 'speechkit'), array($this, 'renderMetaBoxContent'), $postType, 'advanced', 'low', [ '__back_compat_meta_box' => true, ] ); } /** * Render Meta Box content. * * @param WP_Post $post The post object. */ public function renderMetaBoxContent($post) { $metadata = PostMetaUtils::getAllBeyondwordsMetadata($post->ID); $this->postMetaTable($metadata); ?>
formatPostMetaValue($item['meta_value']); ?>
formatPostMetaValue($m['meta_value']); } $lines[] = "=== " . __('Copied using the Classic Editor', 'speechkit') . " ===\r\n\r\n"; return implode("\r\n\r\n", $lines); } }