true, 'single' => true, 'type' => 'boolean', 'auth_callback' => function() { return current_user_can('edit_posts'); }, ]); } public static function add_adblock_guard_toggle() { global $post; error_log('Attempting to add AdBlock Guard toggle.'); // Debugging // For debugging purposes, replace with `if (true)` to force the box to appear if (Settings_Check::is_posts_guard_enabled()) { error_log('AdBlock Guard is enabled.'); // Debugging $value = get_post_meta($post->ID, '_adblock_guard_enabled', true); wp_nonce_field('adblock_guard_meta_nonce', 'adblock_guard_meta_nonce'); echo '
'; } else { error_log('AdBlock Guard is NOT enabled.'); // Debugging } } public static function save_post($post_id) { // Verify the nonce if ( !isset($_POST['adblock_guard_meta_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['adblock_guard_meta_nonce'])), 'adblock_guard_meta_nonce') ) { return; } // Autosave checks if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // Check user capabilities if (!current_user_can('edit_post', $post_id)) { return; } // Update the meta field based on the checkbox value $is_enabled = isset($_POST['adblock_guard_enabled']) ? '1' : ''; update_post_meta($post_id, '_adblock_guard_enabled', $is_enabled); } } // Initialize the Meta_Box class Meta_Box::init();