Skip to content

Function

Handle AJAX activation of extension licenses.

tml_admin_ajax_activate_extension_license( )

Source

function tml_admin_ajax_activate_extension_license() {
    if ( ! check_ajax_referer( 'theme-my-login-licenses-options', '_wpnonce', false ) ) {
        // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated string verbatim (see wp-includes/class-wp-customize-manager.php), not a TML-specific string.
        tml_send_ajax_error( __( 'There was an authentication problem. Please reload and try again.' ) );
    }

    $extension = tml_get_extension( tml_get_request_value( 'extension', 'post' ) );
    if ( ! $extension ) {
        tml_send_ajax_error( __( 'Invalid extension.', 'theme-my-login' ) );
    }

    if ( ! current_user_can( 'manage_options' ) ) {
        // phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- reusing WP core's translated string verbatim (see wp-admin/options-general.php), not a TML-specific string.
        tml_send_ajax_error( __( 'Sorry, you are not allowed to manage options for this site.' ) );
    }

    $extension->set_license_key( tml_get_request_value( 'key', 'post' ) );

    $response = tml_activate_extension_license( $extension );

    if ( is_wp_error( $response ) ) {
        $extension->set_license_key();
        $extension->set_license_status();

        tml_send_ajax_error( $response->get_error_message() );
    }

    $extension->set_license_status( $response );

    tml_send_ajax_success( __( 'Active', 'theme-my-login' ) );
}

Uses

Changelog

VersionDescription
7.1 Introduced.