| 1 |
<?php |
| 2 |
require_once __DIR__ . '/asking-for-review.php'; |
| 3 |
require_once __DIR__ . '/offer.php'; |
| 4 |
require_once __DIR__ . '/bbPress-required.php'; |
| 5 |
require_once __DIR__ . '/deactivate-other-forum-plugins.php'; |
| 6 |
require_once __DIR__ . '/class-remote-notice-client.php'; |
| 7 |
require_once __DIR__ . '/update-notice.php'; |
| 8 |
require_once __DIR__ . '/theme-compatibility.php'; |
| 9 |
|
| 10 |
/** |
| 11 |
* NoticePilot — remote admin-notice campaigns (SDK v1.6.1). |
| 12 |
* |
| 13 |
* Product id .......... 'Forumax' (used for every SDK call below — keep consistent). |
| 14 |
* Hub endpoint ........ manage.spider-themes.net → /content/forumax |
| 15 |
* |
| 16 |
* This lives in the free bbp-core plugin, which is always active (Forumax Pro |
| 17 |
* requires it), so this single integration covers both free and Pro users — |
| 18 |
* forumax_is_premium()/forumax_is_promax() report which one is running. |
| 19 |
*/ |
| 20 |
add_action( 'plugins_loaded', function () { |
| 21 |
if ( ! class_exists( 'Noticepilot_Remote_Notice_Client' ) ) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
Noticepilot_Remote_Notice_Client::init( 'Forumax', [ |
| 26 |
'api_url' => 'https://manage.spider-themes.net/wp-json/noticepilot/v1/content/forumax', |
| 27 |
|
| 28 |
// How often to pull campaigns, and who may see them. |
| 29 |
'schedule' => 'daily', // hourly | twicedaily | daily |
| 30 |
'capability' => 'manage_options', |
| 31 |
|
| 32 |
// Audience targeting: campaigns can target by version rule + free/Pro. |
| 33 |
'plugin_version' => FORUMAX_VERSION, |
| 34 |
'is_pro' => ( forumax_is_premium() || forumax_is_promax() ), |
| 35 |
|
| 36 |
// Frequency / dismissal behaviour (keeps notices tasteful — wp.org guideline 11). |
| 37 |
'max_notices' => 2, // never stack more than 2 at once |
| 38 |
'dismiss_duration' => WEEK_IN_SECONDS, // a dismissal sticks for a week |
| 39 |
'snooze_duration' => WEEK_IN_SECONDS, // "Remind me later" cooldown |
| 40 |
|
| 41 |
// Analytics consent (wp.org guideline 7): keep beacons OFF until the user |
| 42 |
// opts in. We reuse Forumax' existing Freemius tracking opt-in as the |
| 43 |
// consent signal (synced just below), so there is no second consent prompt. |
| 44 |
'require_consent' => true, |
| 45 |
|
| 46 |
// Deactivation feedback is intentionally left OFF: Freemius already shows |
| 47 |
// its own deactivation survey for Forumax, so enabling the SDK prompt too |
| 48 |
// would give the user a duplicate modal on deactivate. |
| 49 |
// 'deactivation_feedback' => true, |
| 50 |
// 'plugin_file' => 'bbp-core/bbp-core.php', |
| 51 |
] ); |
| 52 |
} ); |
| 53 |
|
| 54 |
/** |
| 55 |
* Keep NoticePilot analytics consent in sync with the user's Freemius |
| 56 |
* tracking choice. Because init() runs with require_consent => true, no |
| 57 |
* impression/click/dismissal/goal beacon fires until this grants consent. |
| 58 |
*/ |
| 59 |
add_action( 'admin_init', function () { |
| 60 |
// A sibling plugin may have loaded an older copy of the shared SDK class |
| 61 |
// first; guard the newer method so we never fatal on an outdated class. |
| 62 |
if ( ! function_exists( 'bc_fs' ) || ! method_exists( 'Noticepilot_Remote_Notice_Client', 'grant_consent' ) ) { |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
// is_tracking_allowed() is true once the user opts in to Freemius tracking. |
| 67 |
if ( method_exists( bc_fs(), 'is_tracking_allowed' ) && bc_fs()->is_tracking_allowed() ) { |
| 68 |
Noticepilot_Remote_Notice_Client::grant_consent( 'Forumax' ); |
| 69 |
} else { |
| 70 |
Noticepilot_Remote_Notice_Client::revoke_consent( 'Forumax' ); |
| 71 |
} |
| 72 |
} ); |
| 73 |
|
| 74 |
/** |
| 75 |
* Conversion goal: report the Pro upgrade once, attributed to the campaign / |
| 76 |
* variant that most recently drove it. This is what lets the hub measure real |
| 77 |
* conversion rate (and pick A/B winners), not just clicks. |
| 78 |
*/ |
| 79 |
add_action( 'admin_init', function () { |
| 80 |
if ( ! function_exists( 'forumax_is_premium' ) || ! method_exists( 'Noticepilot_Remote_Notice_Client', 'track_goal' ) ) { |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
if ( forumax_is_premium() && ! get_option( 'forumax_np_goal_upgraded' ) ) { |
| 85 |
// track_goal() returns true only when the beacon actually fired (consent |
| 86 |
// granted + a campaign was seen). Mark it recorded only then, so a user |
| 87 |
// who opts in later still gets the conversion attributed. |
| 88 |
if ( Noticepilot_Remote_Notice_Client::track_goal( 'Forumax', 'upgraded_to_pro' ) ) { |
| 89 |
update_option( 'forumax_np_goal_upgraded', 1, false ); |
| 90 |
} |
| 91 |
} |
| 92 |
} ); |
| 93 |
|
| 94 |
/** |
| 95 |
* Smart-trigger metric: report the live number of published forum topics. |
| 96 |
* NoticePilot only stores the number — WE do the counting. On the hub you can |
| 97 |
* then trigger a campaign at a milestone (e.g. nudge for Pro once a community |
| 98 |
* has "topics_created" >= 25). |
| 99 |
* |
| 100 |
* Fires wherever a topic is saved (front-end or admin). Reporting the current |
| 101 |
* total is idempotent, so edits and re-saves simply re-report the same count. |
| 102 |
*/ |
| 103 |
add_action( 'save_post_topic', function ( $post_id, $post ) { |
| 104 |
if ( ! method_exists( 'Noticepilot_Remote_Notice_Client', 'set_metric' ) ) { |
| 105 |
return; |
| 106 |
} |
| 107 |
if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { |
| 108 |
return; |
| 109 |
} |
| 110 |
if ( 'publish' !== $post->post_status ) { |
| 111 |
return; |
| 112 |
} |
| 113 |
|
| 114 |
$count = (int) wp_count_posts( 'topic' )->publish; |
| 115 |
Noticepilot_Remote_Notice_Client::set_metric( 'Forumax', 'topics_created', $count ); |
| 116 |
}, 10, 2 ); |
| 117 |
|