"Powered-by * credit"), with copy promising "entirely optional... never required * for any feature to work" — but this method used to ignore it * completely here, delegating straight to is_on_paid_plan() with no * regard for the setting at all. A free-plan admin checking that box * saw no change (expected — badge-removal is the paid perk), but a * PAID admin checking it ALSO saw no change, silently, which is a * real bug: a checkbox that unconditionally does nothing in the one * build where it's even wired up at all. Fixed to actually use the * setting as a paid admin's own opt-BACK-in: hidden by default once * paid (unchanged monetization — a free admin still can't remove it * this way, since `is_on_paid_plan()` gates the whole expression), * but a paid admin can now deliberately keep showing it anyway. * WordPress.org build only: scripts/cut-wordpress-org-release.sh * still replaces this method's body wholesale, with the simpler * `return empty( AlpineConsent_General_Settings::get()['show_powered_by_badge'] );` * it already used — that build has no paid-plan concept to gate on * in the first place, so the `is_on_paid_plan() &&` half of this * one is specifically the direct-install build's own addition. * * @return bool */ public static function is_badge_hidden() { return empty( AlpineConsent_General_Settings::get()['show_powered_by_badge'] ); } public function handle_connect_request() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'alpineconsent' ) ); } check_admin_referer( 'alpineconsent_connect' ); $state = wp_generate_password( 32, false ); set_transient( self::STATE_TRANSIENT, $state, self::STATE_TTL ); $url = add_query_arg( array( 'domain' => rawurlencode( (string) wp_parse_url( home_url(), PHP_URL_HOST ) ), 'return_url' => rawurlencode( admin_url( 'admin-post.php?action=alpineconsent_callback' ) ), 'state' => rawurlencode( $state ), 'site_name' => rawurlencode( get_bloginfo( 'name' ) ), ), self::CONNECT_URL ); // Deliberately not wp_safe_redirect() — that restricts targets // to this site's own host plus allowed_redirect_hosts(), but // this target is a fixed, hardcoded, trusted AlpineConsent URL, // never caller-influenced — same trust category as class- // updater.php's own hardcoded RELEASES_API. wp_redirect( $url ); // phpcs:ignore WordPress.Security.SafeRedirect exit; } /** * The admin-post.php URL this handler answers is inherently * reachable by anyone, without auth — but this still requires the * browser landing here to be logged into wp-admin as an admin, * exactly like when Connect was first clicked. There is no * WordPress nonce to check here (a WP nonce can't survive a round * trip through a completely different system, the AlpineConsent * website) — STATE_TRANSIENT is this plugin's own equivalent, * minted and read entirely on this side, never seen by the * AlpineConsent backend. * * All the real logic lives in process_callback() below, which * never calls exit — same "exit-terminated public wrapper around a * directly-testable private method" split class-admin.php's own * handle_scan_request()/discover_from_html() already established * (see test-class-admin.php's own ReflectionMethod use). */ public function handle_callback() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'alpineconsent' ) ); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- a WP nonce cannot survive this round trip (see this method's own docblock above); STATE_TRANSIENT + the hash_equals() check in process_callback() below is this flow's real, equivalent CSRF defense. $state = isset( $_GET['state'] ) ? sanitize_text_field( wp_unslash( $_GET['state'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- see $state above. $code = isset( $_GET['code'] ) ? sanitize_text_field( wp_unslash( $_GET['code'] ) ) : ''; $this->redirect_to_settings( $this->process_callback( $code, $state ) ); } /** * Returns the query args to redirect back into the Settings tab * with — never calls exit itself, so this is the piece tests call * directly (via Reflection, same as discover_from_html()) to * assert on both the return value and the resulting option state, * with wp_remote_post() mocked via WordPress's own pre_http_request * filter — the standard way to fake an HTTP response in a * WP_UnitTestCase without touching the real network. */ private function process_callback( $code, $state ) { $expected = get_transient( self::STATE_TRANSIENT ); delete_transient( self::STATE_TRANSIENT ); if ( ! $code || ! $expected || ! hash_equals( (string) $expected, $state ) ) { return array( 'connect_error' => 'state' ); } $response = wp_remote_post( self::EXCHANGE_API, array( 'timeout' => 10, 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => wp_json_encode( array( 'code' => $code, 'domain' => (string) wp_parse_url( home_url(), PHP_URL_HOST ), ) ), ) ); if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { return array( 'connect_error' => 'exchange' ); } $data = json_decode( wp_remote_retrieve_body( $response ), true ); if ( ! is_array( $data ) || empty( $data['success'] ) || empty( $data['data']['siteKey'] ) ) { return array( 'connect_error' => 'exchange' ); } update_option( self::OPTION_NAME, array( 'site_key' => $data['data']['siteKey'], 'site_id' => isset( $data['data']['siteId'] ) ? $data['data']['siteId'] : '', 'account_email' => isset( $data['data']['accountEmail'] ) ? $data['data']['accountEmail'] : '', 'plan' => isset( $data['data']['plan'] ) ? $data['data']['plan'] : '', 'connected_at' => gmdate( 'c' ), ), false // autoload false — only ever read when the Settings page itself loads, not on every request ); return array( 'connected' => '1' ); } public function handle_disconnect_request() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'alpineconsent' ) ); } check_admin_referer( 'alpineconsent_disconnect' ); delete_option( self::OPTION_NAME ); $this->redirect_to_settings( array( 'disconnected' => '1' ) ); } private function redirect_to_settings( $extra_args ) { wp_safe_redirect( add_query_arg( array_merge( array( 'page' => 'alpineconsent', 'tab' => 'settings' ), $extra_args ), admin_url( 'admin.php' ) ) ); exit; } }