class-wc-legacy-webhook.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. if ( ! defined( 'ABSPATH' ) ) {
  14. exit;
  15. }
  16. /**
  17. * Legacy Webhook class.
  18. */
  19. abstract class WC_Legacy_Webhook extends WC_Data {
  20. /**
  21. * Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.
  22. *
  23. * @param string $key Item to check.
  24. * @return bool
  25. */
  26. public function __isset( $key ) {
  27. $legacy_keys = array(
  28. 'id',
  29. 'status',
  30. 'post_data',
  31. 'delivery_url',
  32. 'secret',
  33. 'topic',
  34. 'hooks',
  35. 'resource',
  36. 'event',
  37. 'failure_count',
  38. 'api_version',
  39. );
  40. if ( in_array( $key, $legacy_keys, true ) ) {
  41. return true;
  42. }
  43. return false;
  44. }
  45. /**
  46. * Magic __get method for backwards compatibility. Maps legacy vars to new getters.
  47. *
  48. * @param string $key Item to get.
  49. * @return mixed
  50. */
  51. public function __get( $key ) {
  52. wc_doing_it_wrong( $key, 'Webhook properties should not be accessed directly.', '3.2' );
  53. switch ( $key ) {
  54. case 'id' :
  55. $value = $this->get_id();
  56. break;
  57. case 'status' :
  58. $value = $this->get_status();
  59. break;
  60. case 'post_data' :
  61. $value = null;
  62. break;
  63. case 'delivery_url' :
  64. $value = $this->get_delivery_url();
  65. break;
  66. case 'secret' :
  67. $value = $this->get_secret();
  68. break;
  69. case 'topic' :
  70. $value = $this->get_topic();
  71. break;
  72. case 'hooks' :
  73. $value = $this->get_hooks();
  74. break;
  75. case 'resource' :
  76. $value = $this->get_resource();
  77. break;
  78. case 'event' :
  79. $value = $this->get_event();
  80. break;
  81. case 'failure_count' :
  82. $value = $this->get_failure_count();
  83. break;
  84. case 'api_version' :
  85. $value = $this->get_api_version();
  86. break;
  87. default :
  88. $value = '';
  89. break;
  90. } // End switch().
  91. return $value;
  92. }
  93. /**
  94. * Get the post data for the webhook.
  95. *
  96. * @deprecated 3.2.0
  97. * @since 2.2
  98. * @return null|WP_Post
  99. */
  100. public function get_post_data() {
  101. wc_deprecated_function( 'WC_Webhook::get_post_data', '3.2' );
  102. return null;
  103. }
  104. /**
  105. * Update the webhook status.
  106. *
  107. * @deprecated 3.2.0
  108. * @since 2.2.0
  109. * @param string $status Status to set.
  110. */
  111. public function update_status( $status ) {
  112. wc_deprecated_function( 'WC_Webhook::update_status', '3.2', 'WC_Webhook::set_status' );
  113. $this->set_status( $status );
  114. $this->save();
  115. }
  116. }