true ), 'names' ); foreach ( $post_types as $post_type ) { register_post_meta( $post_type, self::META_KEY, array( 'show_in_rest' => true, 'single' => true, 'type' => 'boolean', 'default' => false, 'auth_callback' => function () { return current_user_can( 'edit_posts' ); }, ) ); } } /** * Add meta box to post types * * In the block editor, the sidebar panel (editor-sidebar.js) replaces * this meta box. Registering a classic meta box in the block editor * disables WordPress 7.0 real-time collaboration for the post. * * Fallback: if the sidebar JS file is missing, the classic meta box * is registered even in the block editor so the user is never left * without the exclusion control. */ public function ayudawp_add_meta_box() { $screen = get_current_screen(); if ( $screen && method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) { $js_file = AYUDAWP_AISS_PLUGIN_DIR . 'assets/js/editor-sidebar.js'; if ( file_exists( $js_file ) ) { // Sidebar JS handles the UI in the block editor. return; } } // Classic editor (or block editor fallback if JS is missing). $post_types = get_post_types( array( 'public' => true ), 'names' ); foreach ( $post_types as $post_type ) { add_meta_box( 'ayudawp_aiss_exclude_metabox', __( 'AI Share & Summarize', 'ai-share-summarize' ), array( $this, 'ayudawp_render_meta_box' ), $post_type, 'side', 'default' ); } } /** * Render meta box content (classic editor only) * * @param WP_Post $post Current post object. */ public function ayudawp_render_meta_box( $post ) { // Add nonce for security. wp_nonce_field( 'ayudawp_aiss_meta_box', 'ayudawp_aiss_meta_box_nonce' ); // Get current value. $excluded = get_post_meta( $post->ID, self::META_KEY, true ); ?>

__( 'AI Share & Summarize', 'ai-share-summarize' ), 'label' => __( 'Hide share buttons on this content', 'ai-share-summarize' ), 'help' => __( 'Check this box to prevent the share and AI buttons from appearing on this specific content.', 'ai-share-summarize' ), ) ); } /** * Check if a post is excluded via meta box * * Works with both classic editor (stores '1' as string) and * block editor (stores true as boolean via REST API). * * @param int $post_id Post ID to check. * @return bool True if excluded, false otherwise. */ public static function ayudawp_is_post_excluded( $post_id ) { return (bool) get_post_meta( $post_id, self::META_KEY, true ); } }