abstract-acf-legacy-location.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Legacy_Location' ) ) :
  6. abstract class ACF_Legacy_Location {
  7. /**
  8. * Constructor.
  9. *
  10. * @date 5/03/2014
  11. * @since 5.0.0
  12. *
  13. * @param void
  14. * @return void
  15. */
  16. public function __construct() {
  17. // Add legacy method filters.
  18. if ( method_exists( $this, 'rule_match' ) ) {
  19. add_filter( "acf/location/rule_match/{$this->name}", array( $this, 'rule_match' ), 5, 3 );
  20. }
  21. if ( method_exists( $this, 'rule_operators' ) ) {
  22. add_filter( "acf/location/rule_operators/{$this->name}", array( $this, 'rule_operators' ), 5, 2 );
  23. }
  24. if ( method_exists( $this, 'rule_values' ) ) {
  25. add_filter( "acf/location/rule_values/{$this->name}", array( $this, 'rule_values' ), 5, 2 );
  26. }
  27. }
  28. /**
  29. * Magic __call method for backwards compatibility.
  30. *
  31. * @date 10/4/20
  32. * @since 5.9.0
  33. *
  34. * @param string $name The method name.
  35. * @param array $arguments The array of arguments.
  36. * @return mixed
  37. */
  38. public function __call( $name, $arguments ) {
  39. // Add backwards compatibility for legacy methods.
  40. // - Combine 3x legacy filters cases together (remove first args).
  41. switch ( $name ) {
  42. case 'rule_match':
  43. $method = isset( $method ) ? $method : 'match';
  44. $arguments[3] = isset( $arguments[3] ) ? $arguments[3] : false; // Add $field_group param.
  45. case 'rule_operators':
  46. $method = isset( $method ) ? $method : 'get_operators';
  47. case 'rule_values':
  48. $method = isset( $method ) ? $method : 'get_values';
  49. array_shift( $arguments );
  50. return call_user_func_array( array( $this, $method ), $arguments );
  51. case 'compare':
  52. return call_user_func_array( array( $this, 'compare_to_rule' ), $arguments );
  53. }
  54. }
  55. }
  56. endif; // class_exists check