3, 'headers' => array( 'Authorization' => 'Bearer ' . AffKeeper_API::api_key(), 'Content-Type' => 'application/json', ), 'body' => wp_json_encode( array( 'host' => (string) wp_parse_url( home_url(), PHP_URL_HOST ) ) ), ) ); } update_option( AFFKEEPER_OPT_KEY, '' ); delete_option( 'affkeeper_account' ); AffKeeper_API::flush_cache(); wp_safe_redirect( add_query_arg( array( 'page' => self::MENU_SLUG, 'affkeeper_status' => 'disconnected' ), admin_url( 'admin.php' ) ) ); exit; } // Connection form — only touch the key when that form was the one submitted, so saving the // prefix form (which has no key field) can't accidentally disconnect the account. if ( isset( $_POST['affkeeper_api_key'] ) ) { $key = sanitize_text_field( wp_unslash( $_POST['affkeeper_api_key'] ) ); $prev = get_option( 'affkeeper_account', array() ); $prev_user = is_array( $prev ) && ! empty( $prev['username'] ) ? (string) $prev['username'] : ''; update_option( AFFKEEPER_OPT_KEY, $key ); AffKeeper_API::flush_cache(); if ( '' === $key ) { // Key removed = disconnected; drop the remembered account so no stale "Connected" badge. delete_option( 'affkeeper_account' ); } if ( '' !== $key ) { $me = AffKeeper_API::me(); AffKeeper_API::remember_connection( $me ); $status = is_wp_error( $me ) ? 'error' : 'connected'; if ( is_wp_error( $me ) ) { set_transient( 'affkeeper_connect_error', $me->get_error_message(), 60 ); } else { // DIFFERENT account than this site was synced to before → deliberate migration: // drop the old tenant's pointers so the sync below creates fresh records on the // new account (the old one keeps its own copies until removed there). $new_user = isset( $me['username'] ) ? (string) $me['username'] : ''; if ( '' !== $prev_user && '' !== $new_user && $prev_user !== $new_user ) { AffKeeper_Local::clear_remote_ids(); set_transient( 'affkeeper_switch_notice', array( 'from' => $prev_user, 'to' => $new_user ), 120 ); } // Just connected: push any links made locally so the account starts monitoring them. $res = AffKeeper_Sync::push_unsynced(); if ( $res['synced'] > 0 || $res['failed'] > 0 || ! empty( $res['quota'] ) ) { set_transient( 'affkeeper_sync_result', $res, 60 ); } } } } // Local link prefix (free tier). Changing it moves every local short link, so re-flush the // rewrite rules on the next request (when the new prefix's rule is registered — see add_rewrite). if ( isset( $_POST['affkeeper_local_prefix'] ) ) { $new = sanitize_title( wp_unslash( $_POST['affkeeper_local_prefix'] ) ); if ( '' === $new ) { $new = AffKeeper_Local::DEFAULT_PREFIX; } $old = AffKeeper_Local::prefix(); if ( $new !== $old ) { // Refuse a prefix that would hijack an existing page, product archive, or another // plugin's URLs — keep the old one and tell the user why. $conflict = AffKeeper_Local::prefix_conflict( $new ); if ( '' !== $conflict ) { set_transient( 'affkeeper_prefix_error', $conflict, 60 ); $status = 'prefix_conflict'; } else { update_option( 'affkeeper_local_prefix', $new ); update_option( 'affkeeper_flush_needed', 1 ); $status = 'prefix_saved'; } } } wp_safe_redirect( add_query_arg( array( 'page' => self::MENU_SLUG, 'affkeeper_status' => $status ), admin_url( 'admin.php' ) ) ); exit; } /** * "Sync now" — push any not-yet-synced local links up to the connected account. */ public function handle_sync() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'affkeeper' ) ); } check_admin_referer( 'affkeeper_sync' ); $res = AffKeeper_Sync::push_unsynced(); set_transient( 'affkeeper_sync_result', $res, 60 ); wp_safe_redirect( add_query_arg( array( 'page' => self::MENU_SLUG, 'affkeeper_status' => 'synced' ), admin_url( 'admin.php' ) ) ); exit; } public function render() { if ( ! current_user_can( 'manage_options' ) ) { return; } $base = AffKeeper_API::base_url(); $key = AffKeeper_API::api_key(); // The remembered account only counts while a key is actually stored — a leftover option // without a key must never render a "Connected" badge. $account = ( '' !== $key ) ? get_option( 'affkeeper_account', array() ) : array(); $status = isset( $_GET['affkeeper_status'] ) ? sanitize_key( wp_unslash( $_GET['affkeeper_status'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only status flag. ?>
0 ) { echo ' '; /* translators: %d: number of links over the plan's monitored-link limit. */ echo esc_html( sprintf( _n( '%d link stayed local-only — your plan\'s monitored-link limit is reached. It keeps redirecting from this site.', '%d links stayed local-only — your plan\'s monitored-link limit is reached. They keep redirecting from this site.', $q, 'affkeeper' ), $q ) ); echo ' ' . esc_html__( 'Upgrade to monitor them', 'affkeeper' ) . ' ↗'; } if ( $f > 0 ) { echo ' '; /* translators: %d: number of links that failed to sync. */ echo esc_html( sprintf( _n( '%d could not be synced — try again.', '%d could not be synced — try again.', $f, 'affkeeper' ), $f ) ); } ?>
' . esc_html( $host . '/' . AffKeeper_Local::prefix() . '/your-slug' ) . '' ); ?>
' . esc_html__( 'Links', 'affkeeper' ) . '' ); ?>
[affkeeper slug="your-slug"]Buy on the marketplace[/affkeeper]
[affkeeper slug="your-slug" domain="affk.cc"]Buy on the marketplace[/affkeeper]