'', 'message' => '', 'pages' => [], 'always_show_on' => [], ]); } self::$registered_notices[$key][] = $args; } public function cpfm_listen_for_external_notice_registration() { if (!current_user_can('manage_options')) { return; } /** * Allow other plugins to register notices dynamically. * Example usage in other plugins: * do_action('cpf_cpfm_register_notice', 'crypto', [ * 'title' => 'Crypto Plugin Notice', * 'message' => 'This is a crypto dashboard setup notice.', * 'pages' => ['dashboard', 'cpfm_'], * ]); */ do_action('cpfm_register_notice'); } public function cpfm_enqueue_assets() { if (!current_user_can('manage_options')) { return; } $screen = get_current_screen(); $current_page = isset($_GET['page'])? sanitize_key($_GET['page']):''; // Gather all unique pages from registered notices $allowed_pages = []; foreach (self::$registered_notices as $notice) { if (!empty($notice['pages']) && is_array($notice['pages'])) { $allowed_pages = array_merge($allowed_pages, $notice['pages']); } } // Early return if not needed if (!in_array($current_page, array_unique($allowed_pages))) { return; } wp_enqueue_style('cpfm-common-review-style', ATFPP_URL . 'admin/cpfm-feedback/css/cpfm-admin-feedback.css'); wp_enqueue_script( 'cpfm-common-review-script', ATFPP_URL . 'admin/cpfm-feedback/js/cpfm-admin-feedback.js', ['jquery'], ATFPP_V, true ); wp_localize_script('cpfm-common-review-script', 'adminNotice', [ 'ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('dismiss_admin_notice'), 'autoShowPages' => array_unique( array_merge( [], ...array_filter( array_column(self::$registered_notices, 'always_show_on'), function($pages) { return !empty($pages); } ) ) ), ]); } public function cpfm_handle_opt_in_choice() { if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized access.'); } check_ajax_referer('dismiss_admin_notice', 'nonce'); $category = isset($_POST['category']) ? sanitize_text_field( wp_unslash( $_POST['category'] ) ): ''; $opt_in_raw = isset($_POST['opt_in']) ? sanitize_text_field( wp_unslash( $_POST['opt_in'] ) ) : ''; $opt_in = ($opt_in_raw === 'yes') ? 'yes' : 'no'; $category_notices = self::$registered_notices; $registered_notices = isset($GLOBALS['cool_plugins_feedback'])? $GLOBALS['cool_plugins_feedback']:$category_notices; if (!$category || !isset(self::$registered_notices[$category])) { wp_send_json_error('Invalid notice category.'); } update_option("cpfm_opt_in_choice_{$category}", $opt_in); $review_option = get_option("cpfm_opt_in_choice_{$category}"); if ($review_option === 'yes') { foreach (self::$registered_notices[$category] as $notice) { $plugin_name = isset($notice['plugin_name'])?sanitize_key($notice['plugin_name']):''; if($plugin_name){ do_action('cpfm_after_opt_in_' . $plugin_name, $category); } } } wp_send_json_success(); } public function cpfm_render_notice_panel() { if (!current_user_can('manage_options') || !function_exists('get_current_screen')) { return; } $screen = get_current_screen(); $current_page = isset($_GET['page']) ? sanitize_key($_GET['page']) : ''; $unread_count = 0; $auto_show = false; foreach (self::$registered_notices as $notice) { if (!empty($notice['always_show_on']) && in_array($current_page, (array) $notice['always_show_on'])) { $auto_show = true; break; } } $output = ''; $output .= '
' . esc_html__('Opt in to receive email updates about security improvements, new features, helpful tutorials, and occasional special offers. We\'ll collect:', 'ccpw') . '
'; $output .= '