• Resolved 2Flow2

    (@emite)


    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 http://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() and sanitise_preferences() functions here to keep from bloating the post, but they are written into the custom class as well.

    • This topic was modified 2 years, 8 months ago by 2Flow2. Reason: Fixed some of the code
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to add points each time a GET Request is sent to admin post?’ is closed to new replies.