Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
14644c5
Member Content: Use REST API
n7studios Nov 11, 2025
e3bee74
Merge branch 'main' into replace-admin-ajax-with-rest-api-restrict-co…
n7studios Nov 12, 2025
ef4f036
Update logic for REST API replacement
n7studios Nov 12, 2025
b38832d
Merge branch 'main' into replace-admin-ajax-with-rest-api-restrict-co…
n7studios Nov 13, 2025
77f23d1
Merge branch 'main' into replace-admin-ajax-with-rest-api-restrict-co…
n7studios Nov 18, 2025
ee2dcdd
Started tests
n7studios Nov 18, 2025
c7c7896
Start refactor of JS and non-JS methods
n7studios Nov 18, 2025
112b354
WIP
n7studios Nov 18, 2025
63e1a17
First pass at working functionality for products
n7studios Nov 18, 2025
b329057
Refactor for gated content by Tag
n7studios Nov 18, 2025
5bf0aa4
Remove Rest API checks
n7studios Nov 18, 2025
b5290b2
Added tests
n7studios Nov 18, 2025
35bece6
Coding standards, PHPStan compat.
n7studios Nov 18, 2025
b2ef6f5
Add missing reCAPTCHA code
n7studios Nov 18, 2025
ba6a3e4
Merge branch 'main' into replace-admin-ajax-with-rest-api-restrict-co…
n7studios Nov 19, 2025
d5e65e6
Fix class initialisation
n7studios Nov 19, 2025
43fe89f
Isolate failing integration test
n7studios Nov 19, 2025
df6f9d9
Isolate test another way
n7studios Nov 19, 2025
8c9b83c
Initialize classes using singleton
n7studios Nov 19, 2025
44eb9d9
Debug failure
n7studios Nov 19, 2025
8dabe19
Include error in JSON response
n7studios Nov 19, 2025
3b92ebd
Use singleton across REST API routes
n7studios Nov 19, 2025
b9d602b
Reinstate all tests
n7studios Nov 19, 2025
4770649
Rename functions from run_* to more specific API calls for clarity
n7studios Nov 20, 2025
944bf8b
Update comments to make clearer what the returned data is
n7studios Nov 20, 2025
27e81ca
Merge branch 'main' into replace-admin-ajax-with-rest-api-restrict-co…
n7studios Nov 20, 2025
51cb301
Coding standards on tests
n7studios Nov 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions includes/class-convertkit-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ public function __construct() {
add_action( 'wp_ajax_nopriv_convertkit_store_subscriber_email_as_id_in_cookie', array( $this, 'store_subscriber_email_as_id_in_cookie' ) );
add_action( 'wp_ajax_convertkit_store_subscriber_email_as_id_in_cookie', array( $this, 'store_subscriber_email_as_id_in_cookie' ) );

add_action( 'wp_ajax_nopriv_convertkit_subscriber_authentication_send_code', array( $this, 'subscriber_authentication_send_code' ) );
add_action( 'wp_ajax_convertkit_subscriber_authentication_send_code', array( $this, 'subscriber_authentication_send_code' ) );

add_action( 'wp_ajax_nopriv_convertkit_subscriber_verification', array( $this, 'subscriber_verification' ) );
add_action( 'wp_ajax_convertkit_subscriber_verification', array( $this, 'subscriber_verification' ) );

}

/**
Expand Down Expand Up @@ -78,79 +72,4 @@ public function store_subscriber_email_as_id_in_cookie() {

}

/**
* Calls the API to send the subscriber a magic link by email containing a code when
* the modal version of Restrict Content is used, and the user has submitted their email address.
*
* Returns a view of either:
* - an error message and email input i.e. the user entered an invalid email address,
* - the code input, which is then displayed in the modal for the user to enter the code sent by email.
*
* See maybe_run_subscriber_verification() for logic once they enter the code on screen.
*
* @since 2.3.8
*/
public function subscriber_authentication_send_code() {

// Load Restrict Content class.
$output_restrict_content = WP_ConvertKit()->get_class( 'output_restrict_content' );

// Run subscriber authentication.
$output_restrict_content->maybe_run_subscriber_authentication();

// Fetch Post ID, Resource Type and Resource ID for the view.
$post_id = $output_restrict_content->post_id;
$resource_type = $output_restrict_content->resource_type;
$resource_id = $output_restrict_content->resource_id;

// If an error occured, build the email form view with the error message.
if ( is_wp_error( $output_restrict_content->error ) ) {
ob_start();
include CONVERTKIT_PLUGIN_PATH . '/views/frontend/restrict-content/login-modal-content-email.php';
$output = trim( ob_get_clean() );
wp_send_json_success( $output );
}

// Build authentication code view to return for output.
ob_start();
include CONVERTKIT_PLUGIN_PATH . '/views/frontend/restrict-content/login-modal-content-code.php';
$output = trim( ob_get_clean() );
wp_send_json_success( $output );

}

/**
* Calls the API to verify the token and entered subscriber code, which tells us that the email
* address supplied truly belongs to the user, and that we can safely trust their subscriber ID
* to be valid.
*
* @since 2.3.8
*/
public function subscriber_verification() {

// Load Restrict Content class.
$output_restrict_content = WP_ConvertKit()->get_class( 'output_restrict_content' );

// Run subscriber authentication.
$output_restrict_content->maybe_run_subscriber_verification();

// Fetch Post ID, Resource Type and Resource ID for the view.
$post_id = $output_restrict_content->post_id;
$resource_type = $output_restrict_content->resource_type;
$resource_id = $output_restrict_content->resource_id;

// If an error occured, build the code form view with the error message.
if ( is_wp_error( $output_restrict_content->error ) ) {
ob_start();
include CONVERTKIT_PLUGIN_PATH . '/views/frontend/restrict-content/login-modal-content-code.php';
$output = trim( ob_get_clean() );
wp_send_json_error( $output );
}

// Return success with the URL to the Post, including the `ck-cache-bust` parameter.
// JS will load the given URL to show the restricted content.
wp_send_json_success( $output_restrict_content->get_url( true ) );

}

}
Loading