| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin boot |
| 4 |
* |
| 5 |
* @author Webcraftic <wordpress.webraftic@gmail.com> |
| 6 |
* @copyright Webcraftic 25.05.2017 |
| 7 |
* @version 1.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
if( !defined('ABSPATH') ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
if( defined('LOADING_ASSETS_MANAGER_AS_ADDON') ) { |
| 16 |
|
| 17 |
/** |
| 18 |
* Уведомление, которое сообщает о возможности импорта опций из плагина Assets manager в Clearfy |
| 19 |
* |
| 20 |
* @param array $notices |
| 21 |
*/ |
| 22 |
/*add_filter( 'wbcr/factory/admin_notices', function ( $notices ) { |
| 23 |
|
| 24 |
if ( is_multisite() && is_network_admin() ) { |
| 25 |
$am_options = get_site_option( 'wbcr_gnz_assets_manager_options' ); |
| 26 |
} else { |
| 27 |
$am_options = get_option( 'wbcr_gnz_assets_manager_options' ); |
| 28 |
} |
| 29 |
|
| 30 |
if ( $am_options ) { |
| 31 |
$notice_text = '<p><b>Clearfy:</b> ' . __( 'We detected that you used the Assets manager plugin. Do you want to import settings from this plugin to the Clearfy plugin?', 'gonzales' ) . '</p>'; |
| 32 |
$notice_text .= '<p><a href="' . admin_url( '?wbcr_assets_manager_transfer' ) . '" class="button button-default">' . __( 'Import options', 'gonzales' ) . '</a></p>'; |
| 33 |
|
| 34 |
$notices[] = [ |
| 35 |
'id' => 'gnz_plugin_import_options', |
| 36 |
'type' => 'warning', |
| 37 |
'dismissible' => true, |
| 38 |
'dismiss_expires' => 0, |
| 39 |
'text' => $notice_text |
| 40 |
]; |
| 41 |
} |
| 42 |
|
| 43 |
if ( isset( $_GET['wbcr_assets_manager_transfer_completed'] ) ) { |
| 44 |
$notices[] = [ |
| 45 |
'id' => 'gnz_plugin_transfer_options_completed', |
| 46 |
'type' => 'success', |
| 47 |
'dismissible' => false, |
| 48 |
'dismiss_expires' => 0, |
| 49 |
'text' => '<p><b>Clearfy:</b> ' . __( 'Settings has been successfully imported!', 'gonzales' ) |
| 50 |
]; |
| 51 |
} |
| 52 |
|
| 53 |
return $notices; |
| 54 |
}, 10, 2 );*/ |
| 55 |
|
| 56 |
/** |
| 57 |
* Импорт опций из плагина Assets manager в плагин Clearfy. |
| 58 |
* При попытке использовать премиум версию, у многи� |
| 59 |
пользователей уже настроен бесплатный плагин и |
| 60 |
* на ручной перенос настроек у� |
| 61 |
одит очень много времени. Этот кусок кода решает проблему переноса настроек между плагинами. |
| 62 |
*/ |
| 63 |
/*add_action( 'admin_init', function () { |
| 64 |
if ( isset( $_GET['wbcr_assets_manager_transfer'] ) ) { |
| 65 |
global $wpdb; |
| 66 |
|
| 67 |
if ( is_multisite() && is_network_admin() ) { |
| 68 |
$am_options = get_site_option( 'wbcr_gnz_assets_manager_options' ); |
| 69 |
} else { |
| 70 |
$am_options = get_option( 'wbcr_gnz_assets_manager_options' ); |
| 71 |
} |
| 72 |
|
| 73 |
if ( ! $am_options || ! class_exists( 'WCL_Plugin' ) ) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
$am_prefix = 'wbcr_gnz_'; |
| 78 |
|
| 79 |
if ( is_multisite() && is_network_admin() ) { |
| 80 |
$request = $wpdb->get_results( "SELECT meta_key, meta_value |
| 81 |
FROM {$wpdb->sitemeta} |
| 82 |
WHERE option_name LIKE '{$am_prefix}_%'" ); |
| 83 |
} else { |
| 84 |
$request = $wpdb->get_results( "SELECT option_name, option_value |
| 85 |
FROM {$wpdb->options} |
| 86 |
WHERE option_name LIKE '{$am_prefix}_%'" ); |
| 87 |
} |
| 88 |
|
| 89 |
if ( $request ) { |
| 90 |
foreach ( (array) $request as $option ) { |
| 91 |
if ( is_multisite() && is_network_admin() ) { |
| 92 |
$new_option_name = str_replace( $am_prefix, WCL_Plugin::app()->getPrefix(), $option->meta_key ); |
| 93 |
update_site_option( $new_option_name, $option->meta_value ); |
| 94 |
delete_site_option( $option->meta_key ); |
| 95 |
} else { |
| 96 |
$new_option_name = str_replace( $am_prefix, WCL_Plugin::app()->getPrefix(), $option->option_name ); |
| 97 |
update_option( $new_option_name, $option->option_value ); |
| 98 |
delete_option( $option->option_name ); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
wp_redirect( admin_url( '?wbcr_assets_manager_transfer_completed' ) ); |
| 103 |
die(); |
| 104 |
} |
| 105 |
} |
| 106 |
} );*/ |
| 107 |
|
| 108 |
function wbcr_gnz_group_options($options) |
| 109 |
{ |
| 110 |
$options[] = [ |
| 111 |
'name' => 'disable_assets_manager', |
| 112 |
'title' => __('Disable assets manager', 'gonzales'), |
| 113 |
'tags' => [], |
| 114 |
'values' => [] |
| 115 |
]; |
| 116 |
|
| 117 |
$options[] = [ |
| 118 |
'name' => 'disable_assets_manager_panel', |
| 119 |
'title' => __('Disable assets manager panel', 'gonzales'), |
| 120 |
'tags' => [] |
| 121 |
]; |
| 122 |
|
| 123 |
$options[] = [ |
| 124 |
'name' => 'disable_assets_manager_on_front', |
| 125 |
'title' => __('Disable assets manager on front', 'gonzales'), |
| 126 |
'tags' => [] |
| 127 |
]; |
| 128 |
|
| 129 |
$options[] = [ |
| 130 |
'name' => 'disable_assets_manager_on_backend', |
| 131 |
'title' => __('Disable assets manager on back-end', 'gonzales'), |
| 132 |
'tags' => [] |
| 133 |
]; |
| 134 |
|
| 135 |
$options[] = [ |
| 136 |
'name' => 'manager_options', |
| 137 |
'title' => __('Assets manager options', 'gonzales'), |
| 138 |
'tags' => [] |
| 139 |
]; |
| 140 |
|
| 141 |
return $options; |
| 142 |
} |
| 143 |
|
| 144 |
add_filter("wbcr_clearfy_group_options", 'wbcr_gnz_group_options'); |
| 145 |
} else { |
| 146 |
|
| 147 |
/** |
| 148 |
* Удаляем лишние виджеты в левом сайдбаре |
| 149 |
* |
| 150 |
* @param array $widgets |
| 151 |
* @param string $position |
| 152 |
* @param Wbcr_Factory480_Plugin $plugin |
| 153 |
*/ |
| 154 |
add_filter('wbcr/factory/pages/impressive/widgets', function ($widgets, $position, $plugin) { |
| 155 |
if( $plugin->getPluginName() == WGZ_Plugin::app()->getPluginName() ) { |
| 156 |
unset($widgets['business_suggetion']); |
| 157 |
|
| 158 |
if( $position == 'right' ) { |
| 159 |
unset($widgets['donate_widget']); |
| 160 |
unset($widgets['rating_widget']); |
| 161 |
unset($widgets['info_widget']); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
return $widgets; |
| 166 |
}, 20, 3); |
| 167 |
|
| 168 |
/** |
| 169 |
* Заменяем премиум возможности в бизнес виджете |
| 170 |
* |
| 171 |
* @param array $features |
| 172 |
* @param string $page_id |
| 173 |
* @param string $plugin |
| 174 |
*/ |
| 175 |
add_filter('wbcr/clearfy/pages/suggetion_features', function ($features, $plugin_name, $page_id) { |
| 176 |
|
| 177 |
if( !empty($plugin_name) && ($plugin_name == WGZ_Plugin::app()->getPluginName()) ) { |
| 178 |
$upgrade_feature = []; |
| 179 |
$upgrade_feature[] = __('Disable plugins (groups of scripts)', 'gonzales'); |
| 180 |
$upgrade_feature[] = __('Conditions by the link template', 'gonzales'); |
| 181 |
$upgrade_feature[] = __('Conditions by the regular expression', 'gonzales'); |
| 182 |
$upgrade_feature[] = __('Safe mode', 'gonzales'); |
| 183 |
$upgrade_feature[] = __('Statistics and optimization results', 'gonzales'); |
| 184 |
|
| 185 |
return $upgrade_feature; |
| 186 |
} |
| 187 |
|
| 188 |
return $features; |
| 189 |
}, 20, 3); |
| 190 |
|
| 191 |
function wbcr_gnz_set_plugin_meta($links, $file) |
| 192 |
{ |
| 193 |
if( $file == WGZ_PLUGIN_BASE ) { |
| 194 |
$url = WGZ_Plugin::app()->get_support()->get_tracking_page_url('assets-manager', 'plugin_row'); |
| 195 |
$links[] = '<a href="' . $url . '" style="color: #FF5722;font-weight: bold;" target="_blank">' . __('Get premium', 'gonzales') . '</a>'; |
| 196 |
} |
| 197 |
|
| 198 |
return $links; |
| 199 |
} |
| 200 |
|
| 201 |
add_filter('plugin_row_meta', 'wbcr_gnz_set_plugin_meta', 10, 2); |
| 202 |
|
| 203 |
function wbcr_gnz_rating_widget_url($page_url, $plugin_name) |
| 204 |
{ |
| 205 |
if( !defined('LOADING_ASSETS_MANAGER_AS_ADDON') && ($plugin_name == WGZ_Plugin::app()->getPluginName()) ) { |
| 206 |
return 'https://wordpress.org/support/plugin/gonzales/reviews/'; |
| 207 |
} |
| 208 |
|
| 209 |
return $page_url; |
| 210 |
} |
| 211 |
|
| 212 |
add_filter('wbcr_factory_pages_480_imppage_rating_widget_url', 'wbcr_gnz_rating_widget_url', 10, 2); |
| 213 |
|
| 214 |
/** |
| 215 |
* Initialize Assets Manager Farewell notice system |
| 216 |
*/ |
| 217 |
add_action('admin_init', function() { |
| 218 |
if ( ! class_exists('WGZ_Farewell') ) { |
| 219 |
require_once WGZ_PLUGIN_DIR . '/admin/includes/class.farewell.php'; |
| 220 |
} |
| 221 |
new WGZ_Farewell(); |
| 222 |
}); |
| 223 |
|
| 224 |
/** |
| 225 |
* Load farewell notice styles on dashboard |
| 226 |
*/ |
| 227 |
add_action('admin_enqueue_scripts', function($hook) { |
| 228 |
if ( 'index.php' === $hook || $hook === 'settings_page_assets-manager-wbcr_gonzales' ) { |
| 229 |
wp_enqueue_style('wgz-farewell-notice', WGZ_PLUGIN_URL . '/admin/assets/css/farewell-notice.css', [], WGZ_PLUGIN_VERSION); |
| 230 |
} |
| 231 |
}); |
| 232 |
} |