PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 2.0.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v2.0.3
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 6 years ago class-evf-form-fields.php 2 years ago class-evf-integration.php 5 years ago class-evf-log-handler.php 6 years ago class-evf-session.php 8 years ago class-evf-settings-api.php 4 years ago
class-evf-deprecated-hooks.php
136 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 // Adapt dynamic fields hook deprecation with version support.
39 foreach ( $this->deprecated_hooks as $new_hook => $old_hook ) {
40 if ( is_string( $old_hook ) && false !== strpos( $new_hook, '{field_type}' ) ) {
41 foreach ( $fields as $field ) {
42 $new_dynamic_hooks = str_replace( '{field_type}', $field, $new_hook );
43 $old_dynamic_hooks = str_replace( '{field_type}', $field, $old_hook );
44
45 // Set the new deprecated field specific hooks with its version.
46 $this->deprecated_hooks[ $new_dynamic_hooks ] = $old_dynamic_hooks;
47 $this->deprecated_version[ $old_dynamic_hooks ] = $this->get_deprecated_version( $old_hook );
48 }
49
50 // Remove the unused dynamic fields hooks.
51 unset( $this->deprecated_hooks[ $new_hook ] );
52 unset( $this->deprecated_version[ $old_hook ] );
53 }
54 }
55
56 $new_hooks = array_keys( $this->deprecated_hooks );
57 array_walk( $new_hooks, array( $this, 'hook_in' ) );
58 }
59
60 /**
61 * Hook into the new hook so we can handle deprecated hooks once fired.
62 *
63 * @param string $hook_name Hook name.
64 */
65 abstract public function hook_in( $hook_name );
66
67 /**
68 * Get old hooks to map to new hook.
69 *
70 * @param string $new_hook New hook name.
71 * @return array
72 */
73 public function get_old_hooks( $new_hook ) {
74 $old_hooks = isset( $this->deprecated_hooks[ $new_hook ] ) ? $this->deprecated_hooks[ $new_hook ] : array();
75 $old_hooks = is_array( $old_hooks ) ? $old_hooks : array( $old_hooks );
76
77 return $old_hooks;
78 }
79
80 /**
81 * If the hook is Deprecated, call the old hooks here.
82 */
83 public function maybe_handle_deprecated_hook() {
84 $new_hook = current_filter();
85 $old_hooks = $this->get_old_hooks( $new_hook );
86 $new_callback_args = func_get_args();
87 $return_value = $new_callback_args[0];
88
89 foreach ( $old_hooks as $old_hook ) {
90 $return_value = $this->handle_deprecated_hook( $new_hook, $old_hook, $new_callback_args, $return_value );
91 }
92
93 return $return_value;
94 }
95
96 /**
97 * If the old hook is in-use, trigger it.
98 *
99 * @param string $new_hook New hook name.
100 * @param string $old_hook Old hook name.
101 * @param array $new_callback_args New callback args.
102 * @param mixed $return_value Returned value.
103 * @return mixed
104 */
105 abstract public function handle_deprecated_hook( $new_hook, $old_hook, $new_callback_args, $return_value );
106
107 /**
108 * Get deprecated version.
109 *
110 * @param string $old_hook Old hook name.
111 * @return string
112 */
113 protected function get_deprecated_version( $old_hook ) {
114 return ! empty( $this->deprecated_version[ $old_hook ] ) ? $this->deprecated_version[ $old_hook ] : EVF_VERSION;
115 }
116
117 /**
118 * Display a deprecated notice for old hooks.
119 *
120 * @param string $old_hook Old hook.
121 * @param string $new_hook New hook.
122 */
123 protected function display_notice( $old_hook, $new_hook ) {
124 evf_deprecated_hook( esc_html( $old_hook ), esc_html( $this->get_deprecated_version( $old_hook ) ), esc_html( $new_hook ) );
125 }
126
127 /**
128 * Fire off a legacy hook with it's args.
129 *
130 * @param string $old_hook Old hook name.
131 * @param array $new_callback_args New callback args.
132 * @return mixed
133 */
134 abstract protected function trigger_hook( $old_hook, $new_callback_args );
135 }
136