Changeset 3097616
- Timestamp:
- 06/04/2024 09:28:14 PM (10 months ago)
- Location:
- zapier
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
zapier/tags/1.5.0/readme.txt
r3089542 r3097616 5 5 Tested up to: 6.5 6 6 Requires PHP: 7.4 7 Stable tag: 1. 4.07 Stable tag: 1.5.0 8 8 License: Expat (MIT License) 9 9 License URI: https://spdx.org/licenses/MIT.html … … 119 119 120 120 * Add support for webhooks & add user updated hook 121 122 = 1.5.0 = 123 124 * Add updated post hook -
zapier/tags/1.5.0/zapier.php
r3089542 r3097616 4 4 * Plugin Name: Zapier for WordPress 5 5 * 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. 6 * Version: 1. 4.06 * Version: 1.5.0 7 7 * Author: Zapier 8 8 * Author URI: https://zapier.com … … 81 81 $this->loader->add_plugin_filter('rest_pre_dispatch', $this, 'rest_pre_dispatch'); 82 82 $this->loader->add_plugin_filter('determine_current_user', $this, 'determine_current_user'); 83 84 // Webhooks 83 85 $this->loader->add_plugin_action('wp_update_user', $this, 'updated_user'); 86 $this->loader->add_plugin_action('post_updated', $this, 'updated_post', 10, 3); 84 87 } 85 88 … … 217 220 } 218 221 219 $ALLOWED_ACTIONS = array('wp_update_user' );222 $ALLOWED_ACTIONS = array('wp_update_user','post_updated'); 220 223 221 224 $action = $request->get_param("action"); … … 288 291 $response = wp_remote_post($hook, array( 289 292 'body' => json_encode(array('user_id' => $user_id)), 293 'headers' => array('Content-Type' => 'application/json'), 294 )); 295 } 296 } 297 298 public function updated_post($post_id, $post_after, $post_before) { 299 $option_key = "zapier_hooks_post_updated"; 300 301 $rest_base = get_post_type_object($post_after->post_type)->rest_base; 302 $changed_properties = $this->compareObjects($post_after, $post_before); 303 304 $hooks = get_option($option_key, []); 305 306 foreach($hooks as $hook) { 307 $response = wp_remote_post($hook, array( 308 'body' => json_encode(array( 309 'post_id' => $post_id, 310 'rest_base' => $rest_base, 311 'post_after_status' => $post_after->post_status, 312 'post_before_status' => $post_before->post_status, 313 'post_changed_properties' => $changed_properties 314 )), 290 315 'headers' => array('Content-Type' => 'application/json'), 291 316 )); … … 356 381 return $request; 357 382 } 383 384 private function compareObjects($obj1, $obj2) { 385 $reflect1 = new ReflectionClass($obj1); 386 $reflect2 = new ReflectionClass($obj2); 387 388 if ($reflect1->getName() !== $reflect2->getName()) { 389 throw new Exception('Objects must be instances of the same class'); 390 } 391 392 $properties1 = $reflect1->getProperties(); 393 $changed_properties = []; 394 395 foreach ($properties1 as $property) { 396 // Make property accessible if it's private or protected 397 $property->setAccessible(true); 398 399 $value1 = $property->getValue($obj1); 400 $value2 = $property->getValue($obj2); 401 402 if ($value1 !== $value2) { 403 $changed_properties[] = str_replace('post_', '', $property->getName()); 404 } 405 } 406 407 return $changed_properties; 408 } 358 409 } 359 410 -
zapier/trunk/readme.txt
r3089542 r3097616 5 5 Tested up to: 6.5 6 6 Requires PHP: 7.4 7 Stable tag: 1. 4.07 Stable tag: 1.5.0 8 8 License: Expat (MIT License) 9 9 License URI: https://spdx.org/licenses/MIT.html … … 119 119 120 120 * Add support for webhooks & add user updated hook 121 122 = 1.5.0 = 123 124 * Add updated post hook -
zapier/trunk/zapier.php
r3089542 r3097616 4 4 * Plugin Name: Zapier for WordPress 5 5 * 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. 6 * Version: 1. 4.06 * Version: 1.5.0 7 7 * Author: Zapier 8 8 * Author URI: https://zapier.com … … 81 81 $this->loader->add_plugin_filter('rest_pre_dispatch', $this, 'rest_pre_dispatch'); 82 82 $this->loader->add_plugin_filter('determine_current_user', $this, 'determine_current_user'); 83 84 // Webhooks 83 85 $this->loader->add_plugin_action('wp_update_user', $this, 'updated_user'); 86 $this->loader->add_plugin_action('post_updated', $this, 'updated_post', 10, 3); 84 87 } 85 88 … … 217 220 } 218 221 219 $ALLOWED_ACTIONS = array('wp_update_user' );222 $ALLOWED_ACTIONS = array('wp_update_user','post_updated'); 220 223 221 224 $action = $request->get_param("action"); … … 288 291 $response = wp_remote_post($hook, array( 289 292 'body' => json_encode(array('user_id' => $user_id)), 293 'headers' => array('Content-Type' => 'application/json'), 294 )); 295 } 296 } 297 298 public function updated_post($post_id, $post_after, $post_before) { 299 $option_key = "zapier_hooks_post_updated"; 300 301 $rest_base = get_post_type_object($post_after->post_type)->rest_base; 302 $changed_properties = $this->compareObjects($post_after, $post_before); 303 304 $hooks = get_option($option_key, []); 305 306 foreach($hooks as $hook) { 307 $response = wp_remote_post($hook, array( 308 'body' => json_encode(array( 309 'post_id' => $post_id, 310 'rest_base' => $rest_base, 311 'post_after_status' => $post_after->post_status, 312 'post_before_status' => $post_before->post_status, 313 'post_changed_properties' => $changed_properties 314 )), 290 315 'headers' => array('Content-Type' => 'application/json'), 291 316 )); … … 356 381 return $request; 357 382 } 383 384 private function compareObjects($obj1, $obj2) { 385 $reflect1 = new ReflectionClass($obj1); 386 $reflect2 = new ReflectionClass($obj2); 387 388 if ($reflect1->getName() !== $reflect2->getName()) { 389 throw new Exception('Objects must be instances of the same class'); 390 } 391 392 $properties1 = $reflect1->getProperties(); 393 $changed_properties = []; 394 395 foreach ($properties1 as $property) { 396 // Make property accessible if it's private or protected 397 $property->setAccessible(true); 398 399 $value1 = $property->getValue($obj1); 400 $value2 = $property->getValue($obj2); 401 402 if ($value1 !== $value2) { 403 $changed_properties[] = str_replace('post_', '', $property->getName()); 404 } 405 } 406 407 return $changed_properties; 408 } 358 409 } 359 410
Note: See TracChangeset
for help on using the changeset viewer.