| @@ -66,9 +66,8 @@ | ||
| 66 | 66 | * @since 1.9.6 |
| 67 | 67 | */ |
| 68 | 68 | public function __construct() { |
| 69 | 69 | |
| 70 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); | |
| 71 | 70 | add_action( 'wp', array( $this, 'maybe_tag_subscriber' ) ); |
| 72 | 71 | add_action( 'template_redirect', array( $this, 'output_form' ) ); |
| 73 | 72 | add_action( 'template_redirect', array( $this, 'page_takeover' ) ); |
| 74 | 73 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| @@ -80,64 +79,8 @@ | ||
| 80 | 79 | |
| 81 | 80 | } |
| 82 | 81 | |
| 83 | 82 | /** |
| 84 | - * Register REST API routes. | |
| 85 | - * | |
| 86 | - * @since 3.1.7 | |
| 87 | - */ | |
| 88 | - public function register_routes() { | |
| 89 | - | |
| 90 | - // Register route to store the Kit subscriber's email's ID in a cookie. | |
| 91 | - register_rest_route( | |
| 92 | - 'kit/v1', | |
| 93 | - '/subscriber/store-email-as-id-in-cookie', | |
| 94 | - array( | |
| 95 | - 'methods' => WP_REST_Server::CREATABLE, | |
| 96 | - 'args' => array( | |
| 97 | - // Email: Validate email is included in the request, a valid email address | |
| 98 | - // and sanitize the email address. | |
| 99 | - 'email' => array( | |
| 100 | - 'required' => true, | |
| 101 | - 'validate_callback' => function ( $param ) { | |
| 102 | - | |
| 103 | - return is_string( $param ) && is_email( $param ); | |
| 104 | - | |
| 105 | - }, | |
| 106 | - 'sanitize_callback' => 'sanitize_email', | |
| 107 | - ), | |
| 108 | - ), | |
| 109 | - 'callback' => function ( $request ) { | |
| 110 | - | |
| 111 | - // Get email address. | |
| 112 | - $email = $request->get_param( 'email' ); | |
| 113 | - | |
| 114 | - // Get subscriber ID. | |
| 115 | - $subscriber = new ConvertKit_Subscriber(); | |
| 116 | - $subscriber_id = $subscriber->validate_and_store_subscriber_email( $email ); | |
| 117 | - | |
| 118 | - // Bail if an error occurred i.e. API hasn't been configured. | |
| 119 | - if ( is_wp_error( $subscriber_id ) ) { | |
| 120 | - return rest_ensure_response( $subscriber_id ); | |
| 121 | - } | |
| 122 | - | |
| 123 | - // Return the subscriber ID. | |
| 124 | - return rest_ensure_response( | |
| 125 | - array( | |
| 126 | - 'id' => $subscriber_id, | |
| 127 | - ) | |
| 128 | - ); | |
| 129 | - | |
| 130 | - }, | |
| 131 | - | |
| 132 | - // No authentication required, as this is on the frontend site. | |
| 133 | - 'permission_callback' => '__return_true', | |
| 134 | - ) | |
| 135 | - ); | |
| 136 | - | |
| 137 | - } | |
| 138 | - | |
| 139 | - /** | |
| 140 | 83 | * Tags the subscriber, if: |
| 141 | 84 | * - a subscriber ID exists in the cookie or URL, |
| 142 | 85 | * - the WordPress Page has the "Add a Tag" setting specified |
| 143 | 86 | * |
| @@ -819,11 +762,9 @@ | ||
| 819 | 762 | wp_localize_script( |
| 820 | 763 | 'convertkit-js', |
| 821 | 764 | 'convertkit', |
| 822 | 765 | array( |
| 823 | - 'ajaxurl' => rest_url( 'kit/v1/subscriber/store-email-as-id-in-cookie' ), | |
| 824 | 766 | 'debug' => $settings->debug_enabled(), |
| 825 | - 'nonce' => wp_create_nonce( 'wp_rest' ), | |
| 826 | 767 | 'subscriber_id' => $this->subscriber_id, |
| 827 | 768 | ) |
| 828 | 769 | ); |
| 829 | 770 | |