<?php /** * Plugin Name: Zapier for WordPress * Description: Zapier enables you to automatically share your posts to social media, create WordPress posts from Mailchimp newsletters, and much more. Visit https://zapier.com/apps/wordpress/integrations for more details. * Version: 1.0.4 * Author: Zapier * Author URI: https://zapier.com * License: Expat (MIT License) * License URI: https://spdx.org/licenses/MIT.html */ require_once dirname(__FILE__) . '/vendor/autoload.php'; use \Firebase\JWT\JWT; class Zapier_Auth_Loader { protected $actions; protected $filters; public function __construct() { $this->actions = array(); $this->filters = array(); } public function add_plugin_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) { $this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args); } public function add_plugin_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) { $this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args); } private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) { $hooks[] = array( 'hook' => $hook, 'component' => $component, 'callback' => $callback, 'priority' => $priority, 'accepted_args' => $accepted_args, ); return $hooks; } public function run() { foreach ($this->filters as $hook) { add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); } foreach ($this->actions as $hook) { add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], $hook['accepted_args']); } } } class Zapier_Auth { private $error = null; protected $namespace; protected $loader; public function __construct() { $this->namespace = 'zapier/v1'; $this->loader = new Zapier_Auth_Loader(); $this->define_public_hooks(); } private function define_public_hooks() { $this->loader->add_plugin_action('rest_api_init', $this, 'add_api_routes'); $this->loader->add_plugin_filter('rest_pre_dispatch', $this, 'rest_pre_dispatch'); $this->loader->add_plugin_filter('determine_current_user', $this, 'determine_current_user'); } public function run() { $this->loader->run(); } public function add_api_routes() { register_rest_route($this->namespace, '/token', array( 'methods' => "POST", 'callback' => array($this, 'generate_token'), 'permission_callback' => '__return_true' )); } public function generate_token($request) { $secret_key = get_option('zapier_secret'); $username = $request->get_param('username'); $password = $request->get_param('password'); $user = wp_authenticate($username, $password); if (is_wp_error($user)) { $error_code = $user->get_error_code(); return new WP_Error( $error_code, $user->get_error_message($error_code), array( 'status' => 401, ) ); } $issuedAt = time(); $token = array( 'iss' => get_bloginfo('url'), 'iat' => $issuedAt, 'nbf' => $issuedAt, 'exp' => $issuedAt + 300, 'data' => array( 'user_id' => $user->data->ID, ), ); return array( 'token' => JWT::encode($token, $secret_key), ); } public function get_user_from_token() { try { JWT::$leeway = 240; // $leeway in seconds $token = JWT::decode( $_SERVER['HTTP_X_ZAPIER_AUTH'], get_option('zapier_secret'), array('HS256') ); if ($token->iss != get_bloginfo('url')) { $this->error = new WP_Error( 'bad_issuer', 'The issuer does not match with this server', array( 'status' => 401, ) ); } elseif (!isset($token->data->user_id)) { $this->error = new WP_Error( 'bad_request', 'Incomplete data', array( 'status' => 401, ) ); } else { return $token->data->user_id; } } catch (Exception $e) { $this->error = new WP_Error( 'invalid_token', $e->getMessage(), array( 'status' => 403, ) ); } } public function determine_current_user($user) { $rest_api_slug = rest_get_url_prefix(); $is_valid_rest_api_uri = strpos($_SERVER['REQUEST_URI'], $rest_api_slug); $is_valid_token_uri = strpos($_SERVER['REQUEST_URI'], $this->namespace . '/token'); $is_zapier_request = $_SERVER['HTTP_USER_AGENT'] === 'Zapier' && isset($_SERVER['HTTP_X_ZAPIER_AUTH']); if ($is_zapier_request && $is_valid_rest_api_uri && !$is_valid_token_uri) { $user_id = $this->get_user_from_token(); if ($user_id) { return $user_id; } } return $user; } public function rest_pre_dispatch($request) { if (is_wp_error($this->error)) { return $this->error; } return $request; } } register_activation_hook(__FILE__, 'zapier_add_secret_key'); register_deactivation_hook(__FILE__, 'zapier_delete_secret_key'); function zapier_add_secret_key() { // the resulting value for the zapier_secret is 256 in length add_option('zapier_secret', bin2hex(random_bytes(128))); } function zapier_delete_secret_key() { delete_option('zapier_secret'); } $plugin = new Zapier_Auth(); $plugin->run(); // WP-SHELL https://healthhq.guru Health – Page 4 – Health-HQ
Skip to content
  • Home
  • About
    • Sitemap
  • Health
    • Migraine or Headache? How To Tell The Difference
    • Are There Any New Diabetes Breakthroughs?
    • Is Diabetes An Epidemic And What Can We Do?
    • Do These To Lower Your Risk Of Heart Disease
    • Heart Disease; Are You At Risk?
    • Best things to do if you get Migraines
  • Lifestyle
  • Culture
  • Travel
  • Food
  • Contact
  • Privacy Policy
  • Terms Of Service

Health-HQ

Master Your Health

Category: Health

Best Natural Drinks to Have Before Training

HealthVictoria StephensAugust 22, 2022

Best Natural Drinks to Have Before Training

Continue Reading

Do You Have a Urinary Tract Infection or Just An Overactive Bladder?

HealthVictoria StephensAugust 22, 2022

Do You Have a Urinary Tract Infection or Just An Overactive Bladder?

Continue Reading

How Soy Germs Isoflavones Help Treat Urinary Urgency

HealthVictoria StephensAugust 22, 2022

How Soy Germs Isoflavones Help Treat Urinary Urgency

Continue Reading

Keep Your Health in Check with These Body Cleansing Tips

HealthVictoria StephensAugust 22, 2022

Keep Your Health in Check with These Body Cleansing Tips

Continue Reading

What’s the Connection between Testosterone and Sex Drive?

HealthVictoria StephensAugust 22, 2022

What’s the Connection between Testosterone and Sex Drive?

Continue Reading

The Most Common Problems Caused by Low Testosterone

HealthVictoria StephensAugust 22, 2022

The Most Common Problems Caused by Low Testosterone

Continue Reading

Low energy and no sexual appetite? Here’s what you can do!

HealthVictoria StephensAugust 22, 2022

Low energy and no sexual appetite? Here’s what you can do!

Continue Reading

Avoid These Foods that Slash Your Testosterone Production

HealthVictoria StephensAugust 22, 2022

Avoid These Foods that Slash Your Testosterone Production

Continue Reading

Post-Workout Electrolytes for Ideal Recovery

HealthVictoria StephensAugust 22, 2022

Post-Workout Electrolytes for Ideal Recovery

Continue Reading

How to Get into the Right Mindset before Working Out

HealthVictoria StephensAugust 22, 2022

How to Get into the Right Mindset before Working Out

Continue Reading

Posts navigation

Older posts
Newer posts

Some tips and tricks for finding the right lawyer for your needs...

  • Criminal Defense Lawyers
  • Lawyers for victims
  • Employment Lawyers
  • Injury Lawyers
  • Social Securutiy Disability Lawyers
  • Veterans Disability Lawyers
  • Asthma Information
  • Bankruptcy Information
  • Bipolar Information
  • Credit Repair Information
  • Debt Settlement Information
  • Debt Collector
  • Veterans Benefits
  • VA Disability
  • Veterans Loans
  • Veterans PTSD
  • Victim of Crime
  • Sitemaps

Finding health related information...

  • ADHD
  • Arthritis
  • Asthma
  • Bipolar
  • Cancer
  • Cirrhosis
  • Smokers
  • Weight Loss
  • COPD
  • Diabetes
  • Hearing Aids
  • Heart Disease
  • Migraines
  • Plasma Donation
  • Pain
  • PTSD
  • Sleep Apnea
  • Telehealth
  • Depression Information
  • Depression Information
  • Eczema Information
  • Medicare Information
  • Sitemaps
  • October 2022
  • August 2022
  • June 2022
  • March 2022
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • November 2018

Copyright © 2026 Health-HQ. All Rights Reserved.

Boston Theme by FameThemes