How to add points each time a GET Request is sent to admin post?
-
Hi there! I would like to add points to a specific User ID every time my WordPress site detects a GET Request being sent to admin-post.php at https://www.somabugs.com/bugs/wp-admin/admin-post.php?varName=value .
I’ve registered a custom hook in my child theme using the following code:
function __construct( $hook_prefs, $type = 'mycred_default' ) { parent::__construct( array( 'id' => 'bugtracker_bug_added', 'defaults' => array( 'creds' => 1, 'log' => '%plural% for submitting a BugTracker bug' ) ), $hook_prefs, $type ); } /** * Hook into WordPress */ public function run() { // Since we are running a single instance, we do not need to check // if points are set to zero (disable). myCRED will check if this // hook has been enabled before calling this method so no need to check // that either. add_action( 'admin_post_nopriv', array( $this, 'adminpost_ping' ) ); add_action( 'admin_post', array( $this, 'adminpost_ping' ) ); } /** * Check if this is a request from the BugTracker to give points */ public function adminpost_ping( $user_id ) { $this->core->add_creds( 'bugtracker_ping', 2, $this->prefs['creds'], $this->prefs['log'], '', '', $this->mycred_type ); $this->core->update_users_balance( 2, 5 ); } }
I want the user with User ID 2 to receive points each time a GET request is sent to the URL I listed above. However, currently the user receives no points when the URL is pinged. How should I go about this differently?
Thanks so much!
P.S. I excluded pasting my
preferences()
andsanitise_preferences()
functions here to keep from bloating the post, but they are written into the custom class as well.
- The topic ‘How to add points each time a GET Request is sent to admin post?’ is closed to new replies.