'https://manage.spiderthemes.net/wp-json/noticepilot/v1/content/aab', // How often to pull campaigns, and who may see them. 'schedule' => 'daily', // hourly | twicedaily | daily 'capability' => 'manage_options', // Audience targeting: campaigns can target by version rule + free/Pro. 'plugin_version' => AAGB_VERSION, 'is_pro' => function_exists( 'aab_fs' ) ? aab_fs()->is_premium() : false, // Frequency / dismissal behaviour (keeps notices tasteful — wp.org guideline 11). 'max_notices' => 2, // never stack more than 2 at once 'dismiss_duration' => WEEK_IN_SECONDS, // a dismissal sticks for a week 'snooze_duration' => WEEK_IN_SECONDS, // "Remind me later" cooldown // Analytics consent (wp.org guideline 7): keep beacons OFF until the user // opts in. We reuse Freemius' existing tracking opt-in as the consent // signal (synced just below), so there is no second consent prompt. 'require_consent' => true, // Deactivation feedback is intentionally left OFF: Freemius already shows // its own deactivation survey for this plugin, and enabling the SDK's // prompt too would give the user a duplicate modal on deactivate. // 'deactivation_feedback' => true, // 'plugin_file' => plugin_basename( AAGB_PLUGIN_FILE ), ] ); } ); /** * Keep NoticePilot analytics consent in sync with the user's Freemius * tracking choice. Because init() runs with require_consent => true, no * impression/click/dismissal/goal beacon fires until this grants consent. */ add_action( 'admin_init', function () { // A sibling plugin may have loaded an older copy of the shared SDK class // first; guard the newer method so we never fatal on an outdated class. if ( ! function_exists( 'aab_fs' ) || ! method_exists( 'Noticepilot_Remote_Notice_Client', 'grant_consent' ) ) { return; } // is_tracking_allowed() is true once the user opts in to Freemius tracking. if ( method_exists( aab_fs(), 'is_tracking_allowed' ) && aab_fs()->is_tracking_allowed() ) { Noticepilot_Remote_Notice_Client::grant_consent( 'AAB' ); } else { Noticepilot_Remote_Notice_Client::revoke_consent( 'AAB' ); } } ); /** * Conversion goal: report the Pro upgrade exactly once, attributed to the * campaign/variant that most recently drove it. This is what lets the hub * measure real conversion rate (and pick A/B winners), not just clicks. */ add_action( 'admin_init', function () { if ( ! function_exists( 'aab_fs' ) || ! method_exists( 'Noticepilot_Remote_Notice_Client', 'track_goal' ) ) { return; } if ( aab_fs()->is_premium() && ! get_option( 'aab_np_goal_upgraded' ) ) { // track_goal() returns true only when the beacon actually fired (consent // granted + a campaign was seen). Mark it recorded only then, so a user // who opts in later still gets the conversion attributed. if ( Noticepilot_Remote_Notice_Client::track_goal( 'AAB', 'upgraded_to_pro' ) ) { update_option( 'aab_np_goal_upgraded', 1, false ); } } } ); // Include Documentation Builder page require_once plugin_dir_path(__FILE__) . 'documentation-builder.php'; // Helpdesk docs assistant on Accordion Block admin pages. require_once plugin_dir_path(__FILE__) . 'class-support-assistant.php'; if (is_admin()) { AAB_Support_Assistant::get_instance(); } add_action('admin_init', 'aab_register_general_settings'); if (! function_exists('aab_register_general_settings')) { /** * Register the options saved from the dashboard's Settings tab. * * @return void */ function aab_register_general_settings() { register_setting('aab_general_settings', 'aab_hide_support_assistant', array( 'type' => 'boolean', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean', )); } } add_action('admin_menu', 'aab_plugin_admin_page'); add_action('admin_enqueue_scripts', 'aab_admin_page_assets'); add_action('admin_post_aab_create_page_with_pattern', 'aab_create_page_with_pattern_handler'); /** * Returns the nonced admin-post URL used by the "Create New Page" buttons. * Clicking it creates a draft page seeded with the free Group Accordion pattern * and redirects to the block editor. */ if (! function_exists('aab_get_create_page_with_pattern_url')) { function aab_get_create_page_with_pattern_url(): string { return wp_nonce_url( admin_url('admin-post.php?action=aab_create_page_with_pattern'), 'aab_create_page_with_pattern', 'aab_nonce' ); } } /** * Handler: create a draft page seeded with a free Group Accordion pattern, then * redirect the user into the block editor for that new page. */ if (! function_exists('aab_create_page_with_pattern_handler')) { function aab_create_page_with_pattern_handler(): void { // Capability gate. if (! current_user_can('edit_pages') || ! current_user_can('publish_pages')) { wp_die( esc_html__('You do not have permission to create pages.', 'advanced-accordion-block'), esc_html__('Unauthorized', 'advanced-accordion-block'), ['response' => 403] ); } // Nonce verification. check_admin_referer('aab_create_page_with_pattern', 'aab_nonce'); // Pull the registered free pattern content. Patterns are registered on `init`, // which fires before admin-post handlers, so the registry is populated here. $pattern_slug = 'advanced-accordion-block/pattern-simple-accordion'; $content = ''; if (class_exists('WP_Block_Patterns_Registry')) { $pattern = WP_Block_Patterns_Registry::get_instance()->get_registered($pattern_slug); if (is_array($pattern) && ! empty($pattern['content'])) { $content = $pattern['content']; } } // Fallback: minimal Group Accordion block if the pattern is unavailable for any reason. if ('' === $content) { $content = '' . "\n" . '
' . "\n" . ''; } // The pattern markup includes ', ], [ 'name' => __('Spider Elements', 'advanced-accordion-block'), 'desc' => __('More widgets for Elementor', 'advanced-accordion-block'), 'slug' => 'spider-elements', 'plugin_file' => 'spider-elements/spider-elements.php', 'color' => '#4C4CF1', 'icon' => ' ', ], ]; // Check plugin status foreach ($extensions as &$extension) { if (is_plugin_active($extension['plugin_file'])) { $extension['status'] = 'active'; } elseif (file_exists(WP_PLUGIN_DIR . '/' . $extension['plugin_file'])) { $extension['status'] = 'installed'; } else { $extension['status'] = 'not_installed'; } } return $extensions; } } /** * Helper function to render comparison table row */ if (! function_exists('aab_render_comparison_row')) { function aab_render_comparison_row($item): string { $highlight_class = isset($item['highlight']) && $item['highlight'] ? 'aab-pro-highlight' : ''; $free_icon = ''; if ($item['free'] === true) { $free_icon = ''; } elseif ($item['free'] === 'limited') { $free_icon = 'Limited'; } else { $free_icon = ''; } $pro_icon = ''; return sprintf( '%s%s%s', esc_attr($highlight_class), esc_html($item['feature']), $free_icon, $pro_icon ); } } /** * AJAX handler for installing EazyDocs plugin */ add_action('wp_ajax_aab_install_plugin', 'aab_install_plugin_ajax'); if (! function_exists('aab_install_plugin_ajax')) { function aab_install_plugin_ajax() { check_ajax_referer('aab_plugin_action', 'nonce'); if (! current_user_can('install_plugins')) { wp_send_json_error(['message' => 'You do not have permission to install plugins.']); } $slug = isset($_POST['slug']) ? sanitize_text_field($_POST['slug']) : ''; if (empty($slug)) { wp_send_json_error(['message' => 'Plugin slug is required.']); } require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; $api = plugins_api('plugin_information', [ 'slug' => $slug, 'fields' => ['sections' => false], ]); if (is_wp_error($api)) { wp_send_json_error(['message' => 'Failed to get plugin information: ' . $api->get_error_message()]); } $upgrader = new Plugin_Upgrader(new WP_Ajax_Upgrader_Skin()); $result = $upgrader->install($api->download_link); if (is_wp_error($result)) { wp_send_json_error(['message' => 'Installation failed: ' . $result->get_error_message()]); } if (! $result) { wp_send_json_error(['message' => 'Installation failed. Please try again.']); } $plugin_file = $upgrader->plugin_info(); if (! $plugin_file) { wp_send_json_error(['message' => 'Plugin installed but could not determine plugin file.']); } wp_send_json_success([ 'message' => 'EazyDocs has been installed successfully!', 'plugin_file' => $plugin_file, ]); } } /** * AJAX handler for activating EazyDocs plugin */ add_action('wp_ajax_aab_activate_plugin', 'aab_activate_plugin_ajax'); if (! function_exists('aab_activate_plugin_ajax')) { function aab_activate_plugin_ajax() { check_ajax_referer('aab_plugin_action', 'nonce'); if (! current_user_can('activate_plugins')) { wp_send_json_error(['message' => 'You do not have permission to activate plugins.']); } $plugin = isset($_POST['plugin']) ? sanitize_text_field($_POST['plugin']) : ''; if (empty($plugin)) { wp_send_json_error(['message' => 'Plugin file is required.']); } $result = activate_plugin($plugin); if (is_wp_error($result)) { wp_send_json_error(['message' => 'Activation failed: ' . $result->get_error_message()]); } wp_send_json_success([ 'message' => 'EazyDocs has been activated successfully!', 'redirect_url' => admin_url('edit.php?post_type=docs'), ]); } } if (! class_exists('WP_List_Table')) { require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; } /** * Renders the Block Usage Table in the WordPress admin interface for the Accordion Block plugin. * * @return void */ if (! function_exists('aab_render_block_usage_table')) { function aab_render_block_usage_table() { $table = new AAB_Block_Usage_Table(); $table->prepare_items(); echo '
'; echo '

Block Usage

'; echo '
'; $table->search_box('Search Pages/Posts', 'aab-block-usage-search'); $table->display(); echo '
'; echo '
'; } } /** * Extends the WP_List_Table class to manage and display block usage data in a list table format. * * This class is designed to handle various actions such as preparing data, * managing columns, sorting, filtering, pagination, and bulk actions for displaying * the usage of specific block types (e.g., 'Separate Accordion', 'Group Accordion') * in WordPress posts and pages. */ if (! class_exists('AAB_Block_Usage_Table')) { class AAB_Block_Usage_Table extends WP_List_Table { private $blocks = [ 'aab/accordion-block ' => 'Separate Accordion', 'aab/group-accordion ' => 'Group Accordion', 'aab/horizontal-accordion ' => 'Horizontal Accordion', ]; public function __construct() { parent::__construct([ 'singular' => 'block_usage', 'plural' => 'block_usages', 'ajax' => false, ]); } public function get_columns() { return [ 'cb' => '', // Checkbox for bulk actions 'title' => __('Title', 'advanced-accordion-block'), 'author' => __('Author', 'advanced-accordion-block'), 'block_names' => __('Block Name', 'advanced-accordion-block'), 'block_count' => __('Total Block Count', 'advanced-accordion-block'), 'post_type' => __('Post Type', 'advanced-accordion-block'), // Add Post Type Column 'date' => __('Date', 'advanced-accordion-block'), ]; } public function get_sortable_columns() { return [ 'title' => ['title', true], 'author' => ['author', false], 'block_count' => ['block_count', false], 'date' => ['date', false], ]; } public function get_bulk_actions() { return [ 'delete' => 'Delete', ]; } public function column_cb($item) { return sprintf('', $item['ID']); } public function column_title($item) { $actions = [ 'edit' => sprintf('Edit', get_edit_post_link($item['ID'])), 'trash' => sprintf('Trash', get_delete_post_link($item['ID'])), 'view' => sprintf('View', get_permalink($item['ID'])), ]; return sprintf( '%s %s', esc_url(get_edit_post_link($item['ID'])), esc_html($item['title']), $this->row_actions($actions) ); } /** * Prepares the items for display in a list table. * * This method applies various tasks such as searching, filtering, sorting, * pagination, and setting column headers for the items in the list table. * * @return void */ public function prepare_items() { $search = isset($_POST['s']) ? sanitize_text_field($_POST['s']) : ''; $date_filter = isset($_POST['m']) ? sanitize_text_field($_POST['m']) : ''; $data = $this->get_block_usage_data($search, $date_filter); // Handle bulk actions $this->process_bulk_action(); // Handle sorting $orderby = $_GET['orderby'] ?? 'title'; $order = $_GET['order'] ?? 'asc'; usort($data, function ($a, $b) use ($orderby, $order) { $result = strnatcmp($a[$orderby], $b[$orderby]); return ($order === 'asc') ? $result : -$result; }); // Pagination setup $per_page = 20; $current_page = $this->get_pagenum(); $total_items = count($data); $data = array_slice($data, ($current_page - 1) * $per_page, $per_page); $this->set_pagination_args([ 'total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page), ]); $columns = $this->get_columns(); $hidden = []; $sortable = $this->get_sortable_columns(); $this->_column_headers = [$columns, $hidden, $sortable]; $this->items = $data; } public function column_default($item, $column_name) { return $item[$column_name] ?? ''; } private function get_block_usage_data($search = '', $date_filter = '') { global $wpdb; $data = []; $where_clause = ''; if (! empty($search)) { $where_clause .= $wpdb->prepare( "AND post_title LIKE %s", '%' . $wpdb->esc_like($search) . '%' ); } if (! empty($date_filter)) { $where_clause .= $wpdb->prepare( "AND DATE_FORMAT(post_date, '%%Y%%m') = %s", $date_filter ); } $block_search = []; foreach (array_keys($this->blocks) as $block_name) { $search_string = '