Files
wrapartamenty.pl/wp-content/plugins/booking-manager/core/any/activation.php
Roman Pyrih d6241cfa7a first commit
2024-12-19 15:27:13 +01:00

274 lines
10 KiB
PHP

<?php
/**
* @version 1.0
* @package oPlugins
* @category Installation
* @author wpdevelop
*
* @web-site https://oplugins.com/
* @email info@oplugins.com
*
* @modified 2015-04-09, 2016-03-17
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Activation | Deactivation Class
*/
abstract class WPBM_Install {
private $init_option;
function __construct() {
$default_init_option_names = array(
'option-version_num' => 'bookingmanager_version_num'
, 'option-is_delete_if_deactive' => 'bookingmanager_is_delete_if_deactive'
, 'option-activation_process' => 'bookingmanager_activation_process'
, 'transient-wpbm_activation_redirect' => '_bookingmanager_activation_redirect'
, '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>')
, 'link_settings' => '<a href="">Settings</a>'
, 'link_whats_new' => '<a href="">Whats New</a>'
);
$init_option = $this->get_init_option_names();
$this->init_option = wp_parse_args( $init_option, $default_init_option_names );
register_activation_hook( WPBM_FILE, array( $this, 'wpbm_activate_initial' ) ); // WordPress > Plugins > "Activate" link.
register_deactivation_hook( WPBM_FILE, array( $this, 'wpbm_deactivate' ) ); // WordPress > Plugins > "Deactivate" link.
add_filter('upgrader_post_install', array( $this, 'wpbm_install_in_bulk_upgrade' ), 10, 2 ); // Upgrade during bulk upgrade of plugins
// Settings link at the plugin page
add_filter('plugin_action_links', array( $this, 'plugin_links'), 10, 2 );
// Warning message in plugin info
add_filter('plugin_row_meta', array( $this, 'plugin_row_meta'), 10, 4 );
$this->check_if_need_to_update(); // Check upgrade, if was no activation process
}
/** Must be overloaded in child CLASS
* Exmaple:
* return array(
'option-version_num' => 'bookingmanager_version_num'
, 'option-is_delete_if_deactive' => 'bookingmanager_is_delete_if_deactive'
, 'option-activation_process' => 'bookingmanager_activation_process'
, 'transient-wpbm_activation_redirect' => '_bookingmanager_activation_redirect'
, '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 settings page.', '<strong>', '</strong>')
, 'link_settings' => '<a href="">Settings</a>'
, 'link_whats_new' => '<a href="">Whats New</a>'
);
*/
abstract function get_init_option_names();
/** Must be overloaded in child CLASS
* Exmaple:
*
return false
*/
abstract function is_update_from_lower_to_high_version();
////////////////////////////////////////////////////////////////////////////
// <editor-fold defaultstate="collapsed" desc=" Update info of plugin at the plugins section ">
/** Update info of plugin at the plugins section */
function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $context ) {
$this_plugin = plugin_basename( WPBM_FILE );
if ($plugin_file == $this_plugin ) {
$is_delete_if_deactive = get_wpbm_option( $this->init_option['option-is_delete_if_deactive'] ); // check
if ($is_delete_if_deactive == 'On') { ?>
<div class="plugin-update-tr">
<div class="update-message notice inline notice-warning notice-altNO" style="font-size: 1em;line-height: 2em;margin:0 5px 10px;"><?php echo $this->init_option['message-delete_data']; ?></div>
</div>
<?php
}
/*
[$plugin_meta] => Array
(
[0] => Version 2.8.35
[1] => By wpdevelop
[2] => Visit plugin site
)
[$plugin_file] => bookingmanager/WPBM.php
[$plugin_data] => Array
(
[Name] => pluginname
[PluginURI] => https://oplugins.com/plugins/booking-manager/
[Version] => 2.8.35
[Description] => Some description...
[Author] => wpdevelop
[AuthorURI] => https://oplugins.com/
[TextDomain] =>
[DomainPath] =>
[Network] =>
[Title] => Title
[AuthorName] => wpdevelop
)
[$context] => all
/**/
// Echo plugin description here
return $plugin_meta;
} else
return $plugin_meta;
}
// Adds Settings link to plugins settings
function plugin_links($links, $file) {
$this_plugin = plugin_basename( WPBM_FILE );
if ( $file == $this_plugin ) {
if ( ! empty( $this->init_option[ 'link_settings' ] ) )
array_unshift( $links, $this->init_option[ 'link_settings' ] );
if ( ! empty( $this->init_option[ 'link_whats_new' ] ) )
array_unshift( $links, $this->init_option[ 'link_whats_new' ] );
}
return $links;
}
// </editor-fold>
////////////////////////////////////////////////////////////////////////////
// Check about ability to upgrade, if was no activation process
private function check_if_need_to_update() {
if( is_admin() ) {
$wpbm_version_num = get_option( $this->init_option['option-version_num'] );
if ($wpbm_version_num === false )
$wpbm_version_num = '0';
$is_make_activation = false;
if ( version_compare( WPBM_VERSION_NUM, $wpbm_version_num) > 0 ) {
$is_make_activation = true;
} else {
// 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.
$is_make_activation = $this->is_update_from_lower_to_high_version();
}
// Add hook for initial activation.
if ( $is_make_activation ) {
add_action( 'plugins_loaded', array( $this, 'wpbm_activate_initial' ) );
}
}
}
/** Upgrade during bulk upgrade of plugins
*
* @param type $return
* @param type $hook_extra
* @return type
*/
public function wpbm_install_in_bulk_upgrade( $return, $hook_extra ){
if ( is_wp_error( $return ) )
return $return;
if ( isset( $hook_extra ) )
if ( isset( $hook_extra['plugin'] ) ) {
$file_name = basename( WPBM_FILE );
$pos = strpos( $hook_extra['plugin'], trim( $file_name ) );
if ( $pos !== false ) {
$this->wpbm_activate();
}
}
return $return;
}
/** User clicked on "Activate" link at Plugins Menu.
*
* @return type
*/
public function wpbm_activate_initial(){
// Activate the plugin
$this->wpbm_activate();
// Bail if this demo or activating from network, or bulk
if ( is_network_admin() || isset( $_GET['activate-multi'] ) || wpbm_is_this_demo() )
return;
// Add the transient to redirect - Showing Welcome screen
set_transient( $this->init_option['transient-wpbm_activation_redirect'], true, 30 );
}
////////////////////////////////////////////////////////////////////////////
/** Run Activate */
public function wpbm_activate() {
if ( ( function_exists( 'set_time_limit' ) ) && // Try to extend script running to 15 minutes
( ! in_array( ini_get( 'safe_mode' ), array( '1', 'On' ) ) ) // It's doesn't work, if PHP have SAFE MODE ON
) set_time_limit( 900 );
ini_set('memory_limit','256M'); //FixIn:6.1.1.15
update_wpbm_option( $this->init_option['option-activation_process'], 'On' );
make_wpbm_action( 'wpbm_activation' ); // S T A R T
update_wpbm_option( $this->init_option['option-version_num'], WPBM_VERSION_NUM );
update_wpbm_option( $this->init_option['option-activation_process'], 'Off');
}
/** Run Deactivate */
public function wpbm_deactivate() {
if ( ( function_exists( 'set_time_limit' ) ) && // Try to extend script running to 15 minutes
( ! in_array( ini_get( 'safe_mode' ), array( '1', 'On' ) ) ) // It's doesn't work, if PHP have SAFE MODE ON
) set_time_limit( 900 );
$is_delete_if_deactive = get_wpbm_option( $this->init_option['option-is_delete_if_deactive'] ); // check
if ( $is_delete_if_deactive == 'On' ) {
make_wpbm_action( 'wpbm_deactivation' ); // F I N I S H
delete_wpbm_option( $this->init_option['option-version_num'] );
delete_wpbm_option( $this->init_option['option-activation_process'] );
}
}
}