settings = $settings; if ( ! is_admin() ) { return; } // Register the unified metabox add_action( 'add_meta_boxes', [ $this, 'register_metabox' ], 5 ); // Enqueue scripts and styles add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); } /** * Register the unified metabox */ public function register_metabox() { // Build tabs array $this->build_tabs(); // Only add metabox if there are tabs to show if ( empty( $this->tabs ) ) { return; } add_meta_box( 'betterdocs-unified-metabox', __( 'BetterDocs', 'betterdocs' ), [ $this, 'render_metabox' ], 'docs', 'normal', 'high' ); } /** * Build the tabs array based on enabled features */ private function build_tabs() { $this->tabs = []; // Article Quality Analysis tab (always available) $this->tabs['quality-analysis'] = [ 'id' => 'quality-analysis', 'label' => __( 'Article Quality Analysis', 'betterdocs' ), 'callback' => [ $this, 'render_quality_analysis_tab' ], 'priority' => 10 ]; // Estimated Reading Time tab if ( $this->settings->get( 'enable_estimated_reading_time' ) ) { $this->tabs['reading-time'] = [ 'id' => 'reading-time', 'label' => __( 'Estimated Reading Time', 'betterdocs' ), 'callback' => [ $this, 'render_reading_time_tab' ], 'priority' => 20 ]; } // Attachments tab (from Pro) if ( $this->settings->get( 'show_attachment' ) ) { $this->tabs['attachments'] = [ 'id' => 'attachments', 'label' => __( 'Attachments', 'betterdocs' ), 'callback' => [ $this, 'render_attachments_tab' ], 'priority' => 30 ]; } // Related Docs tab (from Pro) if ( $this->settings->get( 'show_related_docs' ) ) { $this->tabs['related-docs'] = [ 'id' => 'related-docs', 'label' => __( 'Related Docs', 'betterdocs' ), 'callback' => [ $this, 'render_related_docs_tab' ], 'priority' => 40 ]; } // Allow other plugins/features to add tabs $this->tabs = apply_filters( 'betterdocs_unified_metabox_tabs', $this->tabs ); // Sort tabs by priority uasort( $this->tabs, function( $a, $b ) { return ( $a['priority'] ?? 999 ) - ( $b['priority'] ?? 999 ); }); } /** * Render the unified metabox * * @param \WP_Post $post Current post object */ public function render_metabox( $post ) { if ( empty( $this->tabs ) ) { return; } $first_tab = array_key_first( $this->tabs ); ?>
tabs as $tab_id => $tab ) : ?>
tabs as $tab_id => $tab ) : ?>
'; // Hook for Estimated Reading Time to render its content do_action( 'betterdocs_reading_time_tab_content', $post ); echo ''; } /** * Render Attachments tab * * @param \WP_Post $post Current post object */ public function render_attachments_tab( $post ) { echo '
'; // Hook for Attachments (Pro) to render its content do_action( 'betterdocs_attachments_tab_content', $post ); echo '
'; } /** * Render Related Docs tab * * @param \WP_Post $post Current post object */ public function render_related_docs_tab( $post ) { echo ''; } /** * Enqueue assets for the unified metabox * * @param string $hook Current admin page hook */ public function enqueue_assets( $hook ) { global $post_type; // Only load on docs edit screens if ( ( $hook === 'post.php' || $hook === 'post-new.php' ) && $post_type === 'docs' ) { betterdocs()->assets->enqueue( 'betterdocs-unified-metabox', 'admin/js/unified-metabox.js' ); // Enqueue styles wp_enqueue_style( 'betterdocs-unified-metabox', BETTERDOCS_ABSURL . 'assets/build/admin/css/unified-metabox.css', [], BETTERDOCS_VERSION ); } } /** * Get AI icon SVG * * @return string SVG icon markup */ private function get_ai_icon() { return ' '; } }