PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / abstracts / class-evf-deprecated-hooks.php
everest-forms / includes / abstracts Last commit date
legacy 6 years ago class-evf-background-process.php 7 years ago class-evf-deprecated-hooks.php 2 months ago class-evf-form-fields-upload.php 2 weeks ago class-evf-form-fields.php 1 month ago class-evf-integration.php 5 years ago class-evf-log-handler.php 6 years ago class-evf-session.php 1 year ago class-evf-settings-api.php 4 years ago
class-evf-deprecated-hooks.php
142 lines
1 <?php
2 /**
3 * Abstract deprecated hooks
4 *
5 * @package EverestForms\Abstracts
6 * @since 1.2.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Deprecated_Hooks class maps old actions and filters to new ones. This is the base class for handling those deprecated hooks.
13 *
14 * Based on the WCS_Hook_Deprecator class by Prospress.
15 */
16 abstract class EVF_Deprecated_Hooks {
17
18 /**
19 * Array of deprecated hooks we need to handle.
20 *
21 * @var array
22 */
23 protected $deprecated_hooks = array();
24
25 /**
26 * Array of versions on each hook has been deprecated.
27 *
28 * @var array
29 */
30 protected $deprecated_version = array();
31
32 /**
33 * Constructor.
34 */
35 public function __construct() {
36 $fields = evf()->form_fields->get_form_field_types();
37
38
39 $fields = array_filter( $fields, 'is_string' );
40
41 foreach ( $this->deprecated_hooks as $new_hook => $old_hook ) {
42 if ( is_string( $old_hook ) && false !== strpos( $new_hook, '{field_type}' ) ) {
43 foreach ( $fields as $field ) {
44 if ( null === $field || '' === $field ) {
45 continue;
46 }
47
48 $field = (string) $field;
49
50 $new_dynamic_hooks = str_replace( '{field_type}', $field, $new_hook );
51 $old_dynamic_hooks = str_replace( '{field_type}', $field, $old_hook );
52
53 $this->deprecated_hooks[ $new_dynamic_hooks ] = $old_dynamic_hooks;
54 $this->deprecated_version[ $old_dynamic_hooks ] = $this->get_deprecated_version( $old_hook );
55 }
56
57 unset( $this->deprecated_hooks[ $new_hook ] );
58 unset( $this->deprecated_version[ $old_hook ] );
59 }
60 }
61
62 $new_hooks = array_keys( $this->deprecated_hooks );
63 array_walk( $new_hooks, array( $this, 'hook_in' ) );
64 }
65
66 /**
67 * Hook into the new hook so we can handle deprecated hooks once fired.
68 *
69 * @param string $hook_name Hook name.
70 */
71 abstract public function hook_in( $hook_name );
72
73 /**
74 * Get old hooks to map to new hook.
75 *
76 * @param string $new_hook New hook name.
77 * @return array
78 */
79 public function get_old_hooks( $new_hook ) {
80 $old_hooks = isset( $this->deprecated_hooks[ $new_hook ] ) ? $this->deprecated_hooks[ $new_hook ] : array();
81 $old_hooks = is_array( $old_hooks ) ? $old_hooks : array( $old_hooks );
82
83 return $old_hooks;
84 }
85
86 /**
87 * If the hook is Deprecated, call the old hooks here.
88 */
89 public function maybe_handle_deprecated_hook() {
90 $new_hook = current_filter();
91 $old_hooks = $this->get_old_hooks( $new_hook );
92 $new_callback_args = func_get_args();
93 $return_value = $new_callback_args[0];
94
95 foreach ( $old_hooks as $old_hook ) {
96 $return_value = $this->handle_deprecated_hook( $new_hook, $old_hook, $new_callback_args, $return_value );
97 }
98
99 return $return_value;
100 }
101
102 /**
103 * If the old hook is in-use, trigger it.
104 *
105 * @param string $new_hook New hook name.
106 * @param string $old_hook Old hook name.
107 * @param array $new_callback_args New callback args.
108 * @param mixed $return_value Returned value.
109 * @return mixed
110 */
111 abstract public function handle_deprecated_hook( $new_hook, $old_hook, $new_callback_args, $return_value );
112
113 /**
114 * Get deprecated version.
115 *
116 * @param string $old_hook Old hook name.
117 * @return string
118 */
119 protected function get_deprecated_version( $old_hook ) {
120 return ! empty( $this->deprecated_version[ $old_hook ] ) ? $this->deprecated_version[ $old_hook ] : EVF_VERSION;
121 }
122
123 /**
124 * Display a deprecated notice for old hooks.
125 *
126 * @param string $old_hook Old hook.
127 * @param string $new_hook New hook.
128 */
129 protected function display_notice( $old_hook, $new_hook ) {
130 evf_deprecated_hook( esc_html( $old_hook ), esc_html( $this->get_deprecated_version( $old_hook ) ), esc_html( $new_hook ) );
131 }
132
133 /**
134 * Fire off a legacy hook with it's args.
135 *
136 * @param string $old_hook Old hook name.
137 * @param array $new_callback_args New callback args.
138 * @return mixed
139 */
140 abstract protected function trigger_hook( $old_hook, $new_callback_args );
141 }
142