'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"
. '