| @@ -17,43 +17,53 @@ | ||
| 17 | 17 | /** |
| 18 | 18 | * Activation | Deactivation Class |
| 19 | 19 | */ |
| 20 | 20 | abstract class WPBC_Install { |
| 21 | - | |
| 22 | - private $init_option; | |
| 23 | - | |
| 24 | - function __construct() { | |
| 25 | - | |
| 26 | - $default_init_option_names = array( | |
| 27 | - 'option-version_num' => 'booking_version_num' | |
| 28 | - , 'option-is_delete_if_deactive' => 'booking_is_delete_if_deactive' | |
| 29 | - , 'option-activation_process' => 'booking_activation_process' | |
| 30 | - , 'transient-wpbc_activation_redirect' => '_booking_activation_redirect' | |
| 31 | - , 'message-delete_data' => '<strong>Warning!</strong> ' . 'All plugin data will be deleted when plugin had deactivated.' . '<br />' | |
| 32 | - . sprintf( 'If you want to save your plugin data, please uncheck the %s"Delete plugin data"%s at the', '<strong>', '</strong>') | |
| 33 | - , 'link_settings' => '<a href="">Settings</a>' | |
| 34 | - , 'link_whats_new' => '<a href="">Whats New</a>' | |
| 35 | - ); | |
| 36 | - | |
| 37 | - $init_option = $this->get_init_option_names(); | |
| 38 | - | |
| 39 | - $this->init_option = wp_parse_args( $init_option, $default_init_option_names ); | |
| 40 | 21 | |
| 41 | - | |
| 42 | - register_activation_hook( WPBC_FILE, array( $this, 'wpbc_activate_initial' ) ); // WordPress > Plugins > "Activate" link. | |
| 43 | - | |
| 44 | - register_deactivation_hook( WPBC_FILE, array( $this, 'wpbc_deactivate' ) ); // WordPress > Plugins > "Deactivate" link. | |
| 45 | - | |
| 46 | - add_filter('upgrader_post_install', array( $this, 'wpbc_install_in_bulk_upgrade' ), 10, 2 ); // Upgrade during bulk upgrade of plugins | |
| 47 | - | |
| 48 | - // Settings link at the plugin page | |
| 49 | - add_filter('plugin_action_links', array( $this, 'plugin_links'), 10, 2 ); | |
| 50 | - // Warning message in plugin info | |
| 51 | - add_filter('plugin_row_meta', array( $this, 'plugin_row_meta'), 10, 4 ); | |
| 52 | - | |
| 53 | - $this->check_if_need_to_update(); // Check upgrade, if was no activation process | |
| 54 | - } | |
| 22 | + /** | |
| 23 | + * Init option | |
| 24 | + * | |
| 25 | + * @var array | |
| 26 | + */ | |
| 27 | + private $init_option; | |
| 55 | 28 | |
| 29 | + /** | |
| 30 | + * Constructor | |
| 31 | + */ | |
| 32 | + public function __construct() { | |
| 33 | + | |
| 34 | + $default_init_option_names = array( | |
| 35 | + 'option-version_num' => 'booking_version_num', | |
| 36 | + 'option-is_delete_if_deactive' => 'booking_is_delete_if_deactive', | |
| 37 | + 'option-activation_process' => 'booking_activation_process', | |
| 38 | + 'transient-wpbc_activation_redirect' => '_booking_activation_redirect', | |
| 39 | + 'message-delete_data' => '<strong>Warning!</strong> All plugin data will be deleted when plugin had deactivated.<br />' . sprintf( 'If you want to save your plugin data, please uncheck the %s"Delete plugin data"%s at the', '<strong>', '</strong>' ), | |
| 40 | + 'link_settings' => '<a href="">Settings</a>', | |
| 41 | + 'link_whats_new' => '<a href="">Whats New</a>', | |
| 42 | + ); | |
| 43 | + | |
| 44 | + $init_option = $this->get_init_option_names(); | |
| 45 | + | |
| 46 | + $this->init_option = wp_parse_args( $init_option, $default_init_option_names ); | |
| 47 | + | |
| 48 | + // WordPress > Plugins > "Activate" link. | |
| 49 | + register_activation_hook( WPBC_FILE, array( $this, 'wpbc_activate_initial' ) ); | |
| 50 | + | |
| 51 | + // WordPress > Plugins > "Deactivate" link. | |
| 52 | + register_deactivation_hook( WPBC_FILE, array( $this, 'wpbc_deactivate' ) ); | |
| 53 | + | |
| 54 | + // Upgrade during bulk upgrade of plugins. | |
| 55 | + add_filter( 'upgrader_post_install', array( $this, 'wpbc_install_in_bulk_upgrade' ), 10, 2 ); | |
| 56 | + | |
| 57 | + // Settings link at the plugin page. | |
| 58 | + add_filter( 'plugin_action_links', array( $this, 'plugin_links' ), 10, 2 ); | |
| 59 | + // Warning message in plugin info. | |
| 60 | + add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 ); | |
| 61 | + | |
| 62 | + // TODO: 2025-06-06 - required to be commented, if we use the Pro version as separate plugin. | |
| 63 | + $this->check_if_need_to_update(); // Check upgrade, if was no activation process | |
| 64 | + } | |
| 65 | + | |
| 56 | 66 | |
| 57 | 67 | /** |
| 58 | 68 | * Must be overloaded in child CLASS |
| 59 | 69 | * |
| @@ -82,11 +92,9 @@ | ||
| 82 | 92 | */ |
| 83 | 93 | abstract function is_update_from_lower_to_high_version(); |
| 84 | 94 | |
| 85 | 95 | |
| 86 | - //////////////////////////////////////////////////////////////////////////// | |
| 87 | - | |
| 88 | - | |
| 96 | + // ----------------------------------------------------------------------------------------------------------------- | |
| 89 | 97 | // <editor-fold defaultstate="collapsed" desc=" Update info of plugin at the plugins section "> |
| 90 | 98 | |
| 91 | 99 | /** Update info of plugin at the plugins section */ |
| 92 | 100 | function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $context ) { |
| @@ -98,14 +106,23 @@ | ||
| 98 | 106 | $is_delete_if_deactive = get_bk_option( $this->init_option['option-is_delete_if_deactive'] ); // check |
| 99 | 107 | |
| 100 | 108 | if ($is_delete_if_deactive == 'On') { ?> |
| 101 | 109 | <div class="plugin-update-tr"> |
| 102 | - <div class="update-message notice inline notice-warning notice-altNO" style="font-size: 1em;line-height: 2em;margin:0 5px 10px;border-left: 3px solid #dd7000;"><?php | |
| 103 | - echo $this->init_option['message-delete_data']; ?></div> | |
| 104 | - </div> | |
| 110 | + <div class="update-message notice inline notice-error" style="line-height: 2.2em;border-left: 3px solid #cc1818;margin-left: 0;color: #cc1818;background: #fff6f4;"><?php | |
| 111 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 112 | + echo $this->init_option['message-delete_data']; ?></div> | |
| 113 | + </div> | |
| 105 | 114 | <?php |
| 106 | 115 | } |
| 107 | 116 | |
| 117 | + $version = wpbc_get_plugin_version_title(); | |
| 118 | + | |
| 119 | + if ( 'Free' !== $version ) { | |
| 120 | + $plugin_meta[0] .= ' | ' . __( 'Version type', 'booking' ) . ': <strong>Free + ' . ucfirst( $version ) . '</strong>'; | |
| 121 | + } else { | |
| 122 | + $plugin_meta[0] .= ' | ' . __( 'Version type', 'booking' ) . ': <strong>' . ucfirst( $version ) . '</strong>'; | |
| 123 | + } | |
| 124 | + | |
| 108 | 125 | /* |
| 109 | 126 | [$plugin_meta] => Array |
| 110 | 127 | ( |
| 111 | 128 | [0] => Version 2.8.35 |
| @@ -145,15 +162,34 @@ | ||
| 145 | 162 | |
| 146 | 163 | $this_plugin = plugin_basename( WPBC_FILE ); |
| 147 | 164 | |
| 148 | 165 | if ( $file == $this_plugin ) { |
| 149 | - | |
| 166 | + | |
| 167 | + | |
| 150 | 168 | array_unshift( $links, $this->init_option['link_settings'] ); |
| 151 | 169 | |
| 152 | 170 | //array_unshift( $links, $this->init_option['link_whats_new'] ); |
| 153 | 171 | array_unshift( $links, $this->init_option['link_faq'] ); |
| 172 | + | |
| 173 | + | |
| 174 | + $links = array_merge( $links, array( | |
| 175 | + '<a class="wpbc_plugins_links__start_tour" title="' . esc_attr( sprintf( __('We\'ll guide you through the steps to set up WP Booking Calendar on your site.','booking'), '<strong>WP Booking Calendar</strong>' ) ) . '" href="' | |
| 176 | + . esc_url( wpbc_get_settings_url() . '&wpbc_setup_wizard=reset&_wpnonce=' . wp_create_nonce( 'wpbc_settings_url_nonce' ) ) | |
| 177 | + //. esc_url( admin_url( add_query_arg( array( 'page' => 'wpbc-about' ), 'index.php' ) ) ) | |
| 178 | + . '">' . esc_attr__( 'Start Setup Wizard', 'booking' ) . '</a>' | |
| 179 | + ) | |
| 180 | + ); | |
| 181 | + | |
| 182 | + | |
| 154 | 183 | if ( ! class_exists( 'wpdev_bk_personal' ) ) { |
| 155 | - array_unshift( $links, $this->init_option['link_up'] ); | |
| 184 | + if ( wpbc_is_updated_paid_to_free() ) { | |
| 185 | + array_unshift( | |
| 186 | + $links, | |
| 187 | + '<a style="font-weight:600;" class="wpbc_plugins_links__start_tour" title="' . esc_attr( __( 'Request Update', 'booking' ) ) . '" href="' . esc_url( 'https://wpbookingcalendar.com/request-update/' ) . '">' . esc_attr__( 'Request Pro Version', 'booking' ) . '</a>' | |
| 188 | + ); | |
| 189 | + } else { | |
| 190 | + array_unshift( $links, $this->init_option['link_up'] ); | |
| 191 | + } | |
| 156 | 192 | } else { |
| 157 | 193 | if ( ! class_exists( 'wpdev_bk_multiuser' ) ) { |
| 158 | 194 | array_unshift( $links, $this->init_option['link_upgrade'] ); |
| 159 | 195 | } |
| @@ -163,132 +199,135 @@ | ||
| 163 | 199 | return $links; |
| 164 | 200 | } |
| 165 | 201 | |
| 166 | 202 | // </editor-fold> |
| 167 | - | |
| 168 | - | |
| 169 | - //////////////////////////////////////////////////////////////////////////// | |
| 170 | - | |
| 171 | - | |
| 172 | - // Check about ability to upgrade, if was no activation process | |
| 173 | - private function check_if_need_to_update() { | |
| 174 | - | |
| 175 | - if( is_admin() ) { | |
| 176 | 203 | |
| 177 | - $wpbc_version_num = get_option( $this->init_option['option-version_num'] ); | |
| 178 | 204 | |
| 179 | - if ($wpbc_version_num === false ) | |
| 180 | - $wpbc_version_num = '0'; | |
| 205 | + // ----------------------------------------------------------------------------------------------------------------- | |
| 181 | 206 | |
| 182 | - $is_make_activation = false; | |
| 183 | - | |
| 184 | - if ( version_compare( WP_BK_VERSION_NUM, $wpbc_version_num) > 0 ) { | |
| 207 | + /** | |
| 208 | + * Check about ability to upgrade, if was no activation process | |
| 209 | + * | |
| 210 | + * @return void | |
| 211 | + */ | |
| 212 | + private function check_if_need_to_update() { | |
| 185 | 213 | |
| 186 | - $is_make_activation = true; | |
| 214 | + if ( is_admin() ) { | |
| 187 | 215 | |
| 188 | - } else { | |
| 189 | - | |
| 190 | - // Check if we was update from free to paid or from lower to higher versions, | |
| 191 | - // and do not make normal activation. In this case we need to make update. | |
| 192 | - $is_make_activation = $this->is_update_from_lower_to_high_version(); | |
| 193 | - | |
| 194 | - } | |
| 195 | - | |
| 196 | - // Add hook for initial activation. | |
| 197 | - if ( $is_make_activation ) { | |
| 198 | - add_action( 'plugins_loaded', array( $this, 'wpbc_activate_initial' ) , 1030 ); | |
| 199 | - } | |
| 200 | - } | |
| 201 | - } | |
| 202 | - | |
| 203 | - | |
| 204 | - /** | |
| 216 | + $wpbc_version_num = get_option( $this->init_option['option-version_num'] ); | |
| 217 | + | |
| 218 | + if ( false === $wpbc_version_num ) { | |
| 219 | + $wpbc_version_num = '0'; | |
| 220 | + } | |
| 221 | + | |
| 222 | + $is_make_activation = false; | |
| 223 | + | |
| 224 | + if ( version_compare( WP_BK_VERSION_NUM, $wpbc_version_num ) > 0 ) { | |
| 225 | + | |
| 226 | + $is_make_activation = true; | |
| 227 | + | |
| 228 | + } else { | |
| 229 | + | |
| 230 | + // Check if we was update from free to paid or from lower to higher versions, and do not make normal activation. In this case we need to make update. | |
| 231 | + // TODO: 2025-11-23 - Commented, if we use the Pro version as separate plugin. | |
| 232 | + // $is_make_activation = $this->is_update_from_lower_to_high_version(); | |
| 233 | + | |
| 234 | + } | |
| 235 | + | |
| 236 | + // Add hook for initial activation. | |
| 237 | + if ( $is_make_activation ) { | |
| 238 | + // add_action( 'plugins_loaded', array( $this, 'wpbc_activate_initial' ), 1030 ); | |
| 239 | + add_action( 'init', array( $this, 'wpbc_activate_initial' ), 1030 ); | |
| 240 | + } | |
| 241 | + } | |
| 242 | + } | |
| 243 | + | |
| 244 | + | |
| 245 | + /** | |
| 205 | 246 | * Upgrade during bulk upgrade of plugins |
| 206 | - * | |
| 207 | - * @param type $return | |
| 208 | - * @param type $hook_extra | |
| 209 | - * @return type | |
| 210 | - */ | |
| 211 | - public function wpbc_install_in_bulk_upgrade( $return, $hook_extra ){ | |
| 247 | + * | |
| 248 | + * @param type $return_val | |
| 249 | + * @param type $hook_extra | |
| 250 | + * | |
| 251 | + * @return type | |
| 252 | + */ | |
| 253 | + public function wpbc_install_in_bulk_upgrade( $return_val, $hook_extra ) { | |
| 212 | 254 | |
| 213 | - if ( is_wp_error( $return ) ) | |
| 214 | - return $return; | |
| 255 | + if ( is_wp_error( $return_val ) ) { | |
| 256 | + return $return_val; | |
| 257 | + } | |
| 215 | 258 | |
| 216 | - if ( isset( $hook_extra ) ) | |
| 217 | - if ( isset( $hook_extra['plugin'] ) ) { | |
| 218 | - $file_name = basename( WPBC_FILE ); | |
| 219 | - $pos = strpos( $hook_extra['plugin'], trim( $file_name ) ); | |
| 220 | - if ( $pos !== false ) { | |
| 221 | - $this->wpbc_activate(); | |
| 222 | - } | |
| 223 | - } | |
| 224 | - return $return; | |
| 225 | - } | |
| 259 | + if ( isset( $hook_extra ) ) { | |
| 260 | + if ( isset( $hook_extra['plugin'] ) ) { | |
| 261 | + $file_name = basename( WPBC_FILE ); | |
| 262 | + $pos = strpos( $hook_extra['plugin'], trim( $file_name ) ); | |
| 263 | + if ( false !== $pos ) { | |
| 264 | + $this->wpbc_activate(); | |
| 265 | + } | |
| 266 | + } | |
| 267 | + } | |
| 226 | 268 | |
| 227 | - | |
| 228 | - /** | |
| 269 | + return $return_val; | |
| 270 | + } | |
| 271 | + | |
| 272 | + | |
| 273 | + /** | |
| 229 | 274 | * User clicked on "Activate" link at Plugins Menu. |
| 230 | - * | |
| 231 | - * @return type | |
| 232 | - */ | |
| 233 | - public function wpbc_activate_initial(){ | |
| 275 | + * | |
| 276 | + * @return type | |
| 277 | + */ | |
| 278 | + public function wpbc_activate_initial() { | |
| 234 | 279 | |
| 235 | - // Activate the plugin | |
| 236 | - $this->wpbc_activate(); | |
| 280 | + // Activate the plugin. | |
| 281 | + $this->wpbc_activate(); | |
| 237 | 282 | |
| 238 | - // Bail if this demo or activating from network, or bulk | |
| 239 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) || wpbc_is_this_demo() ) | |
| 240 | - return; | |
| 283 | + // Bail if this demo or activating from network, or bulk. | |
| 284 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) || wpbc_is_this_demo() ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 285 | + return; | |
| 286 | + } | |
| 241 | 287 | |
| 242 | - // Add the transient to redirect - Showing Welcome screen | |
| 243 | - set_transient( $this->init_option['transient-wpbc_activation_redirect'], true, 30 ); | |
| 244 | - } | |
| 288 | + // Add the transient to redirect - Showing Welcome screen. | |
| 289 | + set_transient( $this->init_option['transient-wpbc_activation_redirect'], true, 30 ); | |
| 290 | + } | |
| 245 | 291 | |
| 246 | - | |
| 247 | - //////////////////////////////////////////////////////////////////////////// | |
| 248 | - | |
| 249 | - | |
| 250 | - /** Run Activate */ | |
| 251 | - public function wpbc_activate() { | |
| 292 | + // ----------------------------------------------------------------------------------------------------------------- | |
| 252 | 293 | |
| 253 | - //FixIn: 8.4.7.24 | |
| 254 | - if ( function_exists( 'set_time_limit' ) ) { | |
| 255 | - set_time_limit( 900 ); | |
| 256 | - } | |
| 257 | - | |
| 258 | - ini_set('memory_limit','256M'); //FixIn:6.1.1.15 | |
| 259 | - ini_set('max_execution_time', 300); //FixIn: 7.0.1.57 | |
| 260 | - | |
| 261 | - update_bk_option( $this->init_option['option-activation_process'], 'On' ); | |
| 294 | + /** | |
| 295 | + * Run Activate | |
| 296 | + */ | |
| 297 | + public function wpbc_activate() { | |
| 262 | 298 | |
| 263 | - make_bk_action( 'wpbc_activation' ); // S T A R T | |
| 299 | + WPBC_Action_Scheduler_Compatibility::raise_memory_limit(); | |
| 300 | + WPBC_Action_Scheduler_Compatibility::raise_time_limit( 300 ); | |
| 264 | 301 | |
| 265 | - update_bk_option( $this->init_option['option-version_num'], WP_BK_VERSION_NUM ); | |
| 302 | + update_bk_option( $this->init_option['option-activation_process'], 'On' ); | |
| 266 | 303 | |
| 267 | - update_bk_option( $this->init_option['option-activation_process'], 'Off'); | |
| 268 | - } | |
| 304 | + make_bk_action( 'wpbc_activation' ); // S T A R T. | |
| 269 | 305 | |
| 306 | + update_bk_option( $this->init_option['option-version_num'], WP_BK_VERSION_NUM ); | |
| 270 | 307 | |
| 271 | - /** Run Deactivate */ | |
| 272 | - public function wpbc_deactivate() { | |
| 308 | + update_bk_option( $this->init_option['option-activation_process'], 'Off' ); | |
| 309 | + } | |
| 273 | 310 | |
| 274 | - //FixIn: 8.4.7.24 | |
| 275 | - if ( function_exists( 'set_time_limit' ) ) { | |
| 276 | - set_time_limit( 900 ); | |
| 277 | - } | |
| 278 | 311 | |
| 279 | - ini_set('memory_limit','256M'); //FixIn:6.1.1.15 | |
| 280 | - ini_set('max_execution_time', 300); //FixIn: 7.0.1.57 | |
| 312 | + /** | |
| 313 | + * Run Deactivate | |
| 314 | + */ | |
| 315 | + public function wpbc_deactivate() { | |
| 316 | + wpbc_set_plugin_deactivation_state( true ); | |
| 281 | 317 | |
| 282 | - $is_delete_if_deactive = get_bk_option( $this->init_option['option-is_delete_if_deactive'] ); // check | |
| 318 | + WPBC_Action_Scheduler_Compatibility::raise_memory_limit(); | |
| 319 | + WPBC_Action_Scheduler_Compatibility::raise_time_limit( 300 ); | |
| 283 | 320 | |
| 284 | - if ( $is_delete_if_deactive == 'On' ) { | |
| 321 | + $is_delete_if_deactive = get_bk_option( $this->init_option['option-is_delete_if_deactive'] ); // check. | |
| 285 | 322 | |
| 286 | - make_bk_action( 'wpbc_deactivation' ); // F I N I S H | |
| 287 | - | |
| 288 | - delete_bk_option( $this->init_option['option-version_num'] ); | |
| 289 | - | |
| 290 | - delete_bk_option( $this->init_option['option-activation_process'] ); | |
| 291 | - } | |
| 292 | - } | |
| 323 | + if ( 'On' === $is_delete_if_deactive ) { | |
| 293 | 324 | |
| 294 | -} | |
| 325 | + make_bk_action( 'wpbc_deactivation' ); // F I N I S H. | |
| 326 | + | |
| 327 | + delete_bk_option( $this->init_option['option-version_num'] ); | |
| 328 | + | |
| 329 | + delete_bk_option( $this->init_option['option-activation_process'] ); | |
| 330 | + } | |
| 331 | + } | |
| 332 | + | |
| 333 | +} | |