is_subscribed() ) { return; } $nonce = wp_create_nonce( 'wrio_subscribe' ); ?>

__( 'Permission denied.', 'robin-image-optimizer' ) ] ); } $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; if ( ! is_email( $email ) ) { wp_send_json_error( [ 'message' => __( 'Please enter a valid email address.', 'robin-image-optimizer' ) ] ); } $body = wp_json_encode( [ 'slug' => $this->plugin_name, 'site' => home_url(), 'email' => $email, ] ); // Ensure body is a string, not false. if ( false === $body ) { wp_send_json_error( [ 'message' => __( 'Failed to encode request body.', 'robin-image-optimizer' ) ] ); } $response = wp_remote_post( self::API_URL, [ 'timeout' => 10, 'headers' => [ 'Content-Type' => 'application/json', 'Cache-Control' => 'no-cache', 'Accept' => 'application/json, */*;q=0.1', ], 'body' => $body, ] ); if ( is_wp_error( $response ) ) { wp_send_json_error( [ 'message' => $response->get_error_message() ] ); } $body = wp_remote_retrieve_body( $response ); $data = json_decode( $body, true ); if ( isset( $data['code'] ) ) { update_option( self::OPTION_SUBSCRIBED, 1 ); wp_send_json_success( [ 'message' => __( 'Subscribed successfully!', 'robin-image-optimizer' ) ] ); } wp_send_json_error( [ 'message' => __( 'Subscription failed. Please try again.', 'robin-image-optimizer' ) ] ); } }