Skip to content

Enhance/ajax trait#1

Open
sapayth wants to merge 2 commits intoweDevsOfficial:mainfrom
sapayth:enhance/ajax_trait
Open

Enhance/ajax trait#1
sapayth wants to merge 2 commits intoweDevsOfficial:mainfrom
sapayth:enhance/ajax_trait

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