api
3 years ago
abstract-wc-legacy-order.php
5 years ago
abstract-wc-legacy-payment-token.php
5 years ago
abstract-wc-legacy-product.php
5 years ago
class-wc-legacy-api.php
4 years ago
class-wc-legacy-cart.php
5 years ago
class-wc-legacy-coupon.php
5 years ago
class-wc-legacy-customer.php
5 years ago
class-wc-legacy-shipping-zone.php
5 years ago
class-wc-legacy-webhook.php
5 years ago
class-wc-legacy-webhook.php
130 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Legacy Webhook |
| 4 | * |
| 5 | * Legacy and deprecated functions are here to keep the WC_Legacy_Webhook class clean. |
| 6 | * This class will be removed in future versions. |
| 7 | * |
| 8 | * @version 3.2.0 |
| 9 | * @package WooCommerce\Classes |
| 10 | * @category Class |
| 11 | * @author Automattic |
| 12 | */ |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Legacy Webhook class. |
| 20 | */ |
| 21 | abstract class WC_Legacy_Webhook extends WC_Data { |
| 22 | |
| 23 | /** |
| 24 | * Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past. |
| 25 | * |
| 26 | * @param string $key Item to check. |
| 27 | * @return bool |
| 28 | */ |
| 29 | public function __isset( $key ) { |
| 30 | $legacy_keys = array( |
| 31 | 'id', |
| 32 | 'status', |
| 33 | 'post_data', |
| 34 | 'delivery_url', |
| 35 | 'secret', |
| 36 | 'topic', |
| 37 | 'hooks', |
| 38 | 'resource', |
| 39 | 'event', |
| 40 | 'failure_count', |
| 41 | 'api_version', |
| 42 | ); |
| 43 | |
| 44 | if ( in_array( $key, $legacy_keys, true ) ) { |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Magic __get method for backwards compatibility. Maps legacy vars to new getters. |
| 53 | * |
| 54 | * @param string $key Item to get. |
| 55 | * @return mixed |
| 56 | */ |
| 57 | public function __get( $key ) { |
| 58 | wc_doing_it_wrong( $key, 'Webhook properties should not be accessed directly.', '3.2' ); |
| 59 | |
| 60 | switch ( $key ) { |
| 61 | case 'id' : |
| 62 | $value = $this->get_id(); |
| 63 | break; |
| 64 | case 'status' : |
| 65 | $value = $this->get_status(); |
| 66 | break; |
| 67 | case 'post_data' : |
| 68 | $value = null; |
| 69 | break; |
| 70 | case 'delivery_url' : |
| 71 | $value = $this->get_delivery_url(); |
| 72 | break; |
| 73 | case 'secret' : |
| 74 | $value = $this->get_secret(); |
| 75 | break; |
| 76 | case 'topic' : |
| 77 | $value = $this->get_topic(); |
| 78 | break; |
| 79 | case 'hooks' : |
| 80 | $value = $this->get_hooks(); |
| 81 | break; |
| 82 | case 'resource' : |
| 83 | $value = $this->get_resource(); |
| 84 | break; |
| 85 | case 'event' : |
| 86 | $value = $this->get_event(); |
| 87 | break; |
| 88 | case 'failure_count' : |
| 89 | $value = $this->get_failure_count(); |
| 90 | break; |
| 91 | case 'api_version' : |
| 92 | $value = $this->get_api_version(); |
| 93 | break; |
| 94 | |
| 95 | default : |
| 96 | $value = ''; |
| 97 | break; |
| 98 | } // End switch(). |
| 99 | |
| 100 | return $value; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Get the post data for the webhook. |
| 105 | * |
| 106 | * @deprecated 3.2.0 |
| 107 | * @since 2.2 |
| 108 | * @return null|WP_Post |
| 109 | */ |
| 110 | public function get_post_data() { |
| 111 | wc_deprecated_function( 'WC_Webhook::get_post_data', '3.2' ); |
| 112 | |
| 113 | return null; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Update the webhook status. |
| 118 | * |
| 119 | * @deprecated 3.2.0 |
| 120 | * @since 2.2.0 |
| 121 | * @param string $status Status to set. |
| 122 | */ |
| 123 | public function update_status( $status ) { |
| 124 | wc_deprecated_function( 'WC_Webhook::update_status', '3.2', 'WC_Webhook::set_status' ); |
| 125 | |
| 126 | $this->set_status( $status ); |
| 127 | $this->save(); |
| 128 | } |
| 129 | } |
| 130 |