verygoodplugins

Untitled

May 19th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. class WPF_API {
  2.  
  3.     public function __construct() {
  4.  
  5.         add_action( 'init', array( $this, 'get_actions' ) );
  6.         add_action( 'after_setup_theme', array( $this, 'thrivecart' ) ); // after_setup_theme to get around issues with ThriveCart and headers already being sent by init
  7.  
  8.         add_action( 'wpf_update', array( $this, 'update_user' ) );
  9.         add_action( 'wpf_update_tags', array( $this, 'update_tags' ) );
  10.         add_action( 'wpf_add', array( $this, 'add_user' ) );
  11.  
  12.         // Import / update user actions
  13.         add_action( 'wp_ajax_nopriv_wpf_update_user', array( $this, 'update_user' ) );
  14.         add_action( 'wp_ajax_nopriv_wpf_add_user', array( $this, 'add_user' ) );
  15.  
  16.     }
  17.  
  18.  
  19.     /**
  20.      * Gets actions passed as query params
  21.      *
  22.      * @access public
  23.      * @return void
  24.      */
  25.  
  26.     public function get_actions() {
  27.  
  28.         if ( isset( $_REQUEST['wpf_action'] ) ) {
  29.  
  30.             if ( ! isset( $_REQUEST['access_key'] ) || $_REQUEST['access_key'] != wp_fusion()->settings->get( 'access_key' ) ) {
  31.  
  32.                 wpf_log( 'error', 0, 'Webhook received but access key ' . $_REQUEST['access_key'] . ' was invalid.', array( 'source' => 'api' ) );
  33.  
  34.                 wp_die( 'Invalid Access Key' );
  35.  
  36.             }
  37.  
  38.             if ( $_REQUEST['wpf_action'] == 'test' ) {
  39.  
  40.                 echo json_encode( array( 'status' => 'success' ) );
  41.                 die();
  42.  
  43.             }
  44.  
  45.             if ( has_action( 'wp_ajax_nopriv_wpf_' . $_REQUEST['wpf_action'] ) ) {
  46.                 do_action( 'wp_ajax_nopriv_wpf_' . $_REQUEST['wpf_action'] );
  47.             } else {
  48.                 do_action( 'wpf_' . $_REQUEST['wpf_action'] );
  49.             }
  50.         }
  51.  
  52.     }
Add Comment
Please, Sign In to add comment