| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @version 1.0 |
| 4 | 4 | * @package Booking Calendar |
| @@ -19,15 +19,42 @@ | ||
| 19 | 19 | |
| 20 | 20 | // --------------------------------------------------------------------------------------------------------------------- |
| 21 | 21 | // Internal plugin action hooks system |
| 22 | 22 | // --------------------------------------------------------------------------------------------------------------------- |
| 23 | +// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 24 | +global $wpbc_bk_action, $wpbc_bk_filter; | |
| 25 | + | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * Mark whether destructive Booking Calendar deactivation is running in this request. | |
| 29 | + * | |
| 30 | + * WordPress cannot unload plugin PHP after deactivate_plugins() is called. This | |
| 31 | + * state lets already-loaded Pro and MultiUser callbacks avoid using deleted data. | |
| 32 | + * | |
| 33 | + * @param bool $is_deactivating Whether deactivation is in progress. | |
| 34 | + */ | |
| 35 | +function wpbc_set_plugin_deactivation_state( $is_deactivating ) { | |
| 36 | + global $wpbc_plugin_deactivation_in_progress; | |
| 37 | + | |
| 38 | + $wpbc_plugin_deactivation_in_progress = (bool) $is_deactivating; | |
| 39 | +} | |
| 40 | + | |
| 41 | + | |
| 42 | +/** | |
| 43 | + * Check whether destructive Booking Calendar deactivation is running. | |
| 44 | + * | |
| 45 | + * @return bool | |
| 46 | + */ | |
| 47 | +function wpbc_is_plugin_deactivation_in_progress() { | |
| 48 | + global $wpbc_plugin_deactivation_in_progress; | |
| 49 | + | |
| 50 | + return ! empty( $wpbc_plugin_deactivation_in_progress ); | |
| 51 | +} | |
| 23 | 52 | |
| 24 | -global $wpdev_bk_action, $wpdev_bk_filter; | |
| 25 | 53 | |
| 54 | +function add_bk_filter( $filter_type, $filter ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 55 | + global $wpbc_bk_filter; | |
| 26 | 56 | |
| 27 | -function add_bk_filter( $filter_type, $filter ) { | |
| 28 | - global $wpdev_bk_filter; | |
| 29 | - | |
| 30 | 57 | $args = array(); |
| 31 | 58 | if ( is_array( $filter ) && 1 == count( $filter ) && is_object( $filter[0] ) ) { |
| 32 | 59 | $args[] =& $filter[0]; |
| 33 | 60 | } else { |
| @@ -36,30 +63,30 @@ | ||
| 36 | 63 | for ( $a = 2; $a < func_num_args(); $a++ ) { |
| 37 | 64 | $args[] = func_get_arg( $a ); |
| 38 | 65 | } |
| 39 | 66 | |
| 40 | - if ( is_array( $wpdev_bk_filter ) ) { | |
| 41 | - if ( isset( $wpdev_bk_filter[ $filter_type ] ) ) { | |
| 42 | - if ( is_array( $wpdev_bk_filter[ $filter_type ] ) ) { | |
| 43 | - $wpdev_bk_filter[ $filter_type ][] = $args; | |
| 67 | + if ( is_array( $wpbc_bk_filter ) ) { | |
| 68 | + if ( isset( $wpbc_bk_filter[ $filter_type ] ) ) { | |
| 69 | + if ( is_array( $wpbc_bk_filter[ $filter_type ] ) ) { | |
| 70 | + $wpbc_bk_filter[ $filter_type ][] = $args; | |
| 44 | 71 | } else { |
| 45 | - $wpdev_bk_filter[ $filter_type ] = array( $args ); | |
| 72 | + $wpbc_bk_filter[ $filter_type ] = array( $args ); | |
| 46 | 73 | } |
| 47 | 74 | } else { |
| 48 | - $wpdev_bk_filter[ $filter_type ] = array( $args ); | |
| 75 | + $wpbc_bk_filter[ $filter_type ] = array( $args ); | |
| 49 | 76 | } |
| 50 | 77 | } else { |
| 51 | - $wpdev_bk_filter = array( $filter_type => array( $args ) ); | |
| 78 | + $wpbc_bk_filter = array( $filter_type => array( $args ) ); | |
| 52 | 79 | } |
| 53 | 80 | } |
| 54 | 81 | |
| 55 | -function remove_bk_filter( $filter_type, $filter ) { | |
| 56 | - global $wpdev_bk_filter; | |
| 82 | +function remove_bk_filter( $filter_type, $filter ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 83 | + global $wpbc_bk_filter; | |
| 57 | 84 | |
| 58 | - if ( isset( $wpdev_bk_filter[ $filter_type ] ) ) { | |
| 59 | - for ( $i = 0; $i < count( $wpdev_bk_filter[ $filter_type ] ); $i++ ) { | |
| 60 | - if ( $wpdev_bk_filter[ $filter_type ][ $i ][0] == $filter ) { | |
| 61 | - $wpdev_bk_filter[ $filter_type ][ $i ] = null; | |
| 85 | + if ( isset( $wpbc_bk_filter[ $filter_type ] ) ) { | |
| 86 | + for ( $i = 0; $i < count( $wpbc_bk_filter[ $filter_type ] ); $i++ ) { | |
| 87 | + if ( $wpbc_bk_filter[ $filter_type ][ $i ][0] == $filter ) { | |
| 88 | + $wpbc_bk_filter[ $filter_type ][ $i ] = null; | |
| 62 | 89 | |
| 63 | 90 | return; |
| 64 | 91 | } |
| 65 | 92 | } |
| @@ -65,10 +92,10 @@ | ||
| 65 | 92 | } |
| 66 | 93 | } |
| 67 | 94 | } |
| 68 | 95 | |
| 69 | -function apply_bk_filter( $filter_type ) { | |
| 70 | - global $wpdev_bk_filter; | |
| 96 | +function apply_bk_filter( $filter_type ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 97 | + global $wpbc_bk_filter; | |
| 71 | 98 | |
| 72 | 99 | |
| 73 | 100 | $args = array(); |
| 74 | 101 | for ( $a = 1; $a < func_num_args(); $a++ ) { |
| @@ -80,11 +107,11 @@ | ||
| 80 | 107 | } else { |
| 81 | 108 | $value = false; |
| 82 | 109 | } |
| 83 | 110 | |
| 84 | - if ( is_array( $wpdev_bk_filter ) ) { | |
| 85 | - if ( isset( $wpdev_bk_filter[ $filter_type ] ) ) { | |
| 86 | - foreach ( $wpdev_bk_filter[ $filter_type ] as $filter ) { | |
| 111 | + if ( is_array( $wpbc_bk_filter ) ) { | |
| 112 | + if ( isset( $wpbc_bk_filter[ $filter_type ] ) ) { | |
| 113 | + foreach ( $wpbc_bk_filter[ $filter_type ] as $filter ) { | |
| 87 | 114 | $filter_func = array_shift( $filter ); |
| 88 | 115 | $parameter = $args; |
| 89 | 116 | $value = call_user_func_array( $filter_func, $parameter ); |
| 90 | 117 | } |
| @@ -94,10 +121,10 @@ | ||
| 94 | 121 | return $value; |
| 95 | 122 | } |
| 96 | 123 | |
| 97 | 124 | |
| 98 | -function make_bk_action( $action_type ) { | |
| 99 | - global $wpdev_bk_action; | |
| 125 | +function make_bk_action( $action_type ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 126 | + global $wpbc_bk_action; | |
| 100 | 127 | |
| 101 | 128 | $args = array(); |
| 102 | 129 | for ( $a = 1; $a < func_num_args(); $a++ ) { |
| 103 | 130 | $args[] = func_get_arg( $a ); |
| @@ -102,11 +129,11 @@ | ||
| 102 | 129 | for ( $a = 1; $a < func_num_args(); $a++ ) { |
| 103 | 130 | $args[] = func_get_arg( $a ); |
| 104 | 131 | } |
| 105 | 132 | |
| 106 | - if ( is_array( $wpdev_bk_action ) ) { | |
| 107 | - if ( isset( $wpdev_bk_action[ $action_type ] ) ) { | |
| 108 | - foreach ( $wpdev_bk_action[ $action_type ] as $action ) { | |
| 133 | + if ( is_array( $wpbc_bk_action ) ) { | |
| 134 | + if ( isset( $wpbc_bk_action[ $action_type ] ) ) { | |
| 135 | + foreach ( $wpbc_bk_action[ $action_type ] as $action ) { | |
| 109 | 136 | $action_func = array_shift( $action ); |
| 110 | 137 | $parameter = $action; |
| 111 | 138 | call_user_func_array( $action_func, $args ); |
| 112 | 139 | } |
| @@ -113,10 +140,10 @@ | ||
| 113 | 140 | } |
| 114 | 141 | } |
| 115 | 142 | } |
| 116 | 143 | |
| 117 | -function add_bk_action( $action_type, $action ) { | |
| 118 | - global $wpdev_bk_action; | |
| 144 | +function add_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 145 | + global $wpbc_bk_action; | |
| 119 | 146 | |
| 120 | 147 | $args = array(); |
| 121 | 148 | if ( is_array( $action ) && 1 == count( $action ) && is_object( $action[0] ) ) // array(&$this) |
| 122 | 149 | { |
| @@ -127,31 +154,31 @@ | ||
| 127 | 154 | for ( $a = 2; $a < func_num_args(); $a++ ) { |
| 128 | 155 | $args[] = func_get_arg( $a ); |
| 129 | 156 | } |
| 130 | 157 | |
| 131 | - if ( is_array( $wpdev_bk_action ) ) { | |
| 132 | - if ( isset( $wpdev_bk_action[ $action_type ] ) ) { | |
| 133 | - if ( is_array( $wpdev_bk_action[ $action_type ] ) ) { | |
| 134 | - $wpdev_bk_action[ $action_type ][] = $args; | |
| 158 | + if ( is_array( $wpbc_bk_action ) ) { | |
| 159 | + if ( isset( $wpbc_bk_action[ $action_type ] ) ) { | |
| 160 | + if ( is_array( $wpbc_bk_action[ $action_type ] ) ) { | |
| 161 | + $wpbc_bk_action[ $action_type ][] = $args; | |
| 135 | 162 | } else { |
| 136 | - $wpdev_bk_action[ $action_type ] = array( $args ); | |
| 163 | + $wpbc_bk_action[ $action_type ] = array( $args ); | |
| 137 | 164 | } |
| 138 | 165 | } else { |
| 139 | - $wpdev_bk_action[ $action_type ] = array( $args ); | |
| 166 | + $wpbc_bk_action[ $action_type ] = array( $args ); | |
| 140 | 167 | } |
| 141 | 168 | } else { |
| 142 | - $wpdev_bk_action = array( $action_type => array( $args ) ); | |
| 169 | + $wpbc_bk_action = array( $action_type => array( $args ) ); | |
| 143 | 170 | } |
| 144 | 171 | } |
| 145 | 172 | |
| 146 | -function remove_bk_action( $action_type, $action ) { | |
| 147 | - global $wpdev_bk_action; | |
| 173 | +function remove_bk_action( $action_type, $action ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 174 | + global $wpbc_bk_action; | |
| 148 | 175 | |
| 149 | - $elements_count = count( $wpdev_bk_action[ $action_type ] ); | |
| 150 | - if ( isset( $wpdev_bk_action[ $action_type ] ) ) { | |
| 176 | + $elements_count = count( $wpbc_bk_action[ $action_type ] ); | |
| 177 | + if ( isset( $wpbc_bk_action[ $action_type ] ) ) { | |
| 151 | 178 | for ( $i = 0; $i < $elements_count; $i++ ) { |
| 152 | - if ( $wpdev_bk_action[ $action_type ][ $i ][0] == $action ) { | |
| 153 | - $wpdev_bk_action[ $action_type ][ $i ] = null; | |
| 179 | + if ( $wpbc_bk_action[ $action_type ][ $i ][0] == $action ) { | |
| 180 | + $wpbc_bk_action[ $action_type ][ $i ] = null; | |
| 154 | 181 | |
| 155 | 182 | return; |
| 156 | 183 | } |
| 157 | 184 | } |
| @@ -158,10 +185,20 @@ | ||
| 158 | 185 | } |
| 159 | 186 | } |
| 160 | 187 | |
| 161 | 188 | |
| 162 | -function get_bk_option( $option, $default = false ) { | |
| 189 | +function get_bk_option( $option, $default = false ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 163 | 190 | |
| 191 | + global $wpbc__skip_get_bk_options; | |
| 192 | + | |
| 193 | + if ( | |
| 194 | + ! empty( $wpbc__skip_get_bk_options ) | |
| 195 | + && is_array( $wpbc__skip_get_bk_options ) | |
| 196 | + && in_array( $option, $wpbc__skip_get_bk_options, true ) | |
| 197 | + ) { | |
| 198 | + return $default; | |
| 199 | + } | |
| 200 | + | |
| 164 | 201 | $u_value = apply_bk_filter( 'wpdev_bk_get_option', 'no-values', $option, $default ); |
| 165 | 202 | if ( 'no-values' !== $u_value ) { |
| 166 | 203 | return $u_value; |
| 167 | 204 | } |
| @@ -167,9 +204,9 @@ | ||
| 167 | 204 | } |
| 168 | 205 | return get_option( $option, $default ); |
| 169 | 206 | } |
| 170 | 207 | |
| 171 | -function update_bk_option( $option, $newvalue ) { | |
| 208 | +function update_bk_option( $option, $newvalue ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 172 | 209 | |
| 173 | 210 | $u_value = apply_bk_filter( 'wpdev_bk_update_option', 'no-values', $option, $newvalue ); |
| 174 | 211 | if ( 'no-values' !== $u_value ) { |
| 175 | 212 | return $u_value; |
| @@ -176,9 +213,9 @@ | ||
| 176 | 213 | } |
| 177 | 214 | return update_option( $option, $newvalue ); |
| 178 | 215 | } |
| 179 | 216 | |
| 180 | -function delete_bk_option( $option ) { | |
| 217 | +function delete_bk_option( $option ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 181 | 218 | |
| 182 | 219 | $u_value = apply_bk_filter( 'wpdev_bk_delete_option', 'no-values', $option ); |
| 183 | 220 | if ( 'no-values' !== $u_value ) { |
| 184 | 221 | return $u_value; |
| @@ -185,9 +222,9 @@ | ||
| 185 | 222 | } |
| 186 | 223 | return delete_option( $option ); |
| 187 | 224 | } |
| 188 | 225 | |
| 189 | -function add_bk_option( $option, $value = '', $deprecated = '', $autoload = null ) { | |
| 226 | +function add_bk_option( $option, $value = '', $deprecated = '', $autoload = null ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 190 | 227 | |
| 191 | 228 | $u_value = apply_bk_filter( 'wpdev_bk_add_option', 'no-values', $option, $value, $deprecated, $autoload ); |
| 192 | 229 | if ( 'no-values' !== $u_value ) { |
| 193 | 230 | return $u_value; |
| @@ -282,5 +319,5 @@ | ||
| 282 | 319 | } |
| 283 | 320 | } |
| 284 | 321 | |
| 285 | 322 | return $exist_booking_option_arr; |
| 286 | -} | |
| 323 | +} | |