15 * MINUTE_IN_SECONDS, 'display' => __( 'Every 15 minutes (AiM Blog Engine)', 'aim-blog-engine' ), ); return $schedules; } add_filter( 'cron_schedules', 'aim_be_cron_schedules' ); /** * The scheduled pull: fetch pending posts from AiM and publish them as drafts. * Guideline 7: this only runs once the member has connected (opted in) — a * missing site key means we make no outbound call at all. */ function aim_be_run_poll() { $site_key = get_option( AIM_BE_OPT_SITE_KEY, '' ); if ( empty( $site_key ) ) { return; } $api = new Aim_Be_Api(); $publisher = new Aim_Be_Publisher(); $api->heartbeat(); // report version/health each run $pending = $api->get_pending(); if ( is_wp_error( $pending ) || empty( $pending ) ) { return; } foreach ( $pending as $item ) { $result = $publisher->upsert_draft( $item ); $api->ack( $result ); // report post id / url / status back (outbound) } update_option( AIM_BE_OPT_LAST_SYNC, time() ); } add_action( AIM_BE_CRON_HOOK, 'aim_be_run_poll' ); /** * Activation: schedule the poll. No outbound call here (Guideline 7 — we don't * phone home until the member connects). */ function aim_be_activate() { if ( ! wp_next_scheduled( AIM_BE_CRON_HOOK ) ) { wp_schedule_event( time() + MINUTE_IN_SECONDS, AIM_BE_CRON_SCHEDULE, AIM_BE_CRON_HOOK ); } } register_activation_hook( __FILE__, 'aim_be_activate' ); /** * Deactivation: clear the scheduled poll. */ function aim_be_deactivate() { $timestamp = wp_next_scheduled( AIM_BE_CRON_HOOK ); if ( $timestamp ) { wp_unschedule_event( $timestamp, AIM_BE_CRON_HOOK ); } wp_clear_scheduled_hook( AIM_BE_CRON_HOOK ); } register_deactivation_hook( __FILE__, 'aim_be_deactivate' ); // Admin settings page (connect + status + "Sync now"). add_action( 'plugins_loaded', array( 'Aim_Be_Settings', 'init' ) ); /** * Add a shortcut on the Plugins list row: "Connect" until the site is linked, * "Settings" afterward — both open Settings → AiM Blog Engine. * * @param array $links Existing action links. * @return array */ function aim_be_plugin_action_links( $links ) { $connected = (bool) get_option( AIM_BE_OPT_SITE_KEY, '' ); $label = $connected ? __( 'Settings', 'aim-blog-engine' ) : __( 'Connect', 'aim-blog-engine' ); $link = sprintf( '%s', esc_url( admin_url( 'options-general.php?page=aim-blog-engine' ) ), esc_html( $label ) ); array_unshift( $links, $link ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'aim_be_plugin_action_links' ); // BETA channel only: enable one-click self-updates when the `.selfupdate` marker // ships in the zip. The WordPress.org build omits the marker (updates flow // through WordPress.org there, as its guidelines require). // Both the marker AND the class must be present: the WordPress.org build ships // neither, so this stays inert there and never references a missing file. if ( file_exists( AIM_BE_DIR . '.selfupdate' ) && file_exists( AIM_BE_DIR . 'includes/class-aim-be-updater.php' ) ) { require_once AIM_BE_DIR . 'includes/class-aim-be-updater.php'; Aim_Be_Updater::boot(); }