class-acf-location-user-form.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Location_User_Form' ) ) :
  6. class ACF_Location_User_Form extends ACF_Location {
  7. /**
  8. * Initializes props.
  9. *
  10. * @date 5/03/2014
  11. * @since 5.0.0
  12. *
  13. * @param void
  14. * @return void
  15. */
  16. public function initialize() {
  17. $this->name = 'user_form';
  18. $this->label = __( 'User Form', 'acf' );
  19. $this->category = 'user';
  20. $this->object_type = 'user';
  21. }
  22. /**
  23. * Matches the provided rule against the screen args returning a bool result.
  24. *
  25. * @date 9/4/20
  26. * @since 5.9.0
  27. *
  28. * @param array $rule The location rule.
  29. * @param array $screen The screen args.
  30. * @param array $field_group The field group settings.
  31. * @return bool
  32. */
  33. public function match( $rule, $screen, $field_group ) {
  34. // REST API has no forms, so we should always allow it.
  35. if ( ! empty( $screen['rest'] ) ) {
  36. return true;
  37. }
  38. // Check screen args.
  39. if ( isset( $screen['user_form'] ) ) {
  40. $user_form = $screen['user_form'];
  41. } else {
  42. return false;
  43. }
  44. // The "Add / Edit" choice (foolishly valued "edit") should match true for either "add" or "edit".
  45. if ( $rule['value'] === 'edit' && $user_form === 'add' ) {
  46. $user_form = 'edit';
  47. }
  48. // Compare rule against $user_form.
  49. return $this->compare_to_rule( $user_form, $rule );
  50. }
  51. /**
  52. * Returns an array of possible values for this rule type.
  53. *
  54. * @date 9/4/20
  55. * @since 5.9.0
  56. *
  57. * @param array $rule A location rule.
  58. * @return array
  59. */
  60. public function get_values( $rule ) {
  61. return array(
  62. 'all' => __( 'All', 'acf' ),
  63. 'add' => __( 'Add', 'acf' ),
  64. 'edit' => __( 'Add / Edit', 'acf' ),
  65. 'register' => __( 'Register', 'acf' ),
  66. );
  67. }
  68. }
  69. // Register.
  70. acf_register_location_type( 'ACF_Location_User_Form' );
  71. endif; // class_exists check