connect( $code ); self::redirect( is_wp_error( $result ) ? 'connect_failed' : 'connected' ); } /** * Handle disconnect: forget the site key locally. * * @return void */ public static function handle_disconnect() { if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You do not have permission to do this.', 'aim-blog-engine' ) ); } check_admin_referer( 'aim_be_disconnect' ); delete_option( AIM_BE_OPT_SITE_KEY ); delete_option( AIM_BE_OPT_SITE_ID ); update_option( AIM_BE_OPT_STATUS, 'disconnected' ); self::redirect( 'disconnected' ); } /** * Handle an on-demand sync. * * @return void */ public static function handle_sync_now() { if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You do not have permission to do this.', 'aim-blog-engine' ) ); } check_admin_referer( 'aim_be_sync_now' ); aim_be_run_poll(); self::redirect( 'synced' ); } /** * Redirect back to the settings page with a notice flag. * * @param string $notice Notice key. * @return void */ private static function redirect( $notice ) { wp_safe_redirect( add_query_arg( array( 'page' => self::SLUG, 'aim_be_notice' => rawurlencode( $notice ), ), admin_url( 'options-general.php' ) ) ); exit; } /** * Map a notice key to human text. * * @param string $key Notice key. * @return string */ private static function notice_text( $key ) { switch ( $key ) { case 'connected': return __( 'Connected to AiM Blog Engine.', 'aim-blog-engine' ); case 'connect_failed': return __( 'That Connect Code was not accepted. Generate a new one in your AiM account and try again.', 'aim-blog-engine' ); case 'missing_code': return __( 'Please paste your Connect Code.', 'aim-blog-engine' ); case 'disconnected': return __( 'Disconnected. AiM will no longer publish to this site.', 'aim-blog-engine' ); case 'synced': return __( 'Sync complete.', 'aim-blog-engine' ); default: return ''; } } }