Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/ajax trait #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sapayth
Copy link
Member

@sapayth sapayth commented Jun 23, 2023

This trait will reduce some repetitive tasks while registering WordPress AJAX actions.
Example of use:

use WeDevs\WpUtils\AjaxTrait;

class MyAjaxClass {

    use AjaxTrait;

    public function __construct() {
        // Register an AJAX action.
        // This will produce:
        // add_action( 'wp_ajax_yourproject_submit_form, [ $this, 'submit_form_callback' ] );
        // add_action( 'wp_ajax_nopriv_yourproject_submit_form, [ $this, 'submit_form_callback' ] );
        $this->register_ajax( 'yourproject_submit_form', [ $this, 'submit_form_callback' ] );
        $this->register_ajax( 'yourproject_approve_member', 'action_callback', $this->logged_in_only );` // for logged-in users only
        $this->register_ajax( 'yourproject_member_registration', 'action_callback', $this->logged_out_only);` // for logged-out users only
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant