public static function init() { self::$api_key = self::get_api_key(); if (is_admin()) { // register settings self::register_settings(); } }
function sa_load_si_zapier_addon() { if (class_exists('Zapier_Controller')) { return; } require_once 'inc/Zapier_Controller.php'; require_once 'inc/Zapier_Settings.php'; require_once 'inc/Zapier_API.php'; require_once 'inc/Zapier_Routes.php'; Zapier_Controller::init(); // init sub classes Zapier_Settings::init(); Zapier_Routes::init(); }
/** * Set callback to endpoint * * @return */ public static function api_callback() { if (!isset($_REQUEST[self::API_QUERY_VAR]) || $_REQUEST[self::API_QUERY_VAR] == '') { return; } if (!self::DEBUG) { // debug should skip authorization // Authentication if (!isset($_SERVER['HTTP_AUTHORIZATION'])) { status_header(403); self::fail('Your API key is missing.'); } $api_key = Zapier_Settings::get_api_key(); $auth = wp_parse_args($_SERVER['HTTP_AUTHORIZATION']); if ($api_key != $auth['api_key']) { status_header(403); self::fail('Your API key is incorrect: ' . $key_sent); } } header('Content-Type: application/json; charset=' . get_option('blog_charset')); header('Expires: ' . gmdate('D, d M Y H:i:s', mktime(date('H') + 2, date('i'), date('s'), date('m'), date('d'), date('Y'))) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); $data = json_decode(file_get_contents('php://input')); switch ($_REQUEST[self::API_QUERY_VAR]) { case 'ping': $response = self::ping($data); break; case 'invoice': $response = self::invoice($data); break; case 'estimate': $response = self::estimate($data); break; case 'payment': $response = self::payment($data); break; case 'client': $response = self::client($data); break; case 'create_invoice': $response = self::create_invoice($data); break; case 'create_estimate': $response = self::create_estimate($data); break; case 'create_payment': $response = self::create_payment($data); break; case 'create_client': $response = self::create_client($data); break; // case 'fields': // $response = self::fields( $data ); // break; // case 'fields': // $response = self::fields( $data ); // break; case 'subscribe': $response = self::subscribe_zap($data); break; case 'unsubscribe': case 'delete': $response = self::unsubscribe_zap($data); break; default: status_header(409); self::fail('Not a valid endpoint.'); break; } echo wp_json_encode($response); exit; }