| 1 |
<?php |
| 2 |
/** |
| 3 |
* Setup Ultimate Dashboard plugin. |
| 4 |
* |
| 5 |
* @package Ultimate_Dashboard |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Udb; |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || die( "Can't access directly" ); |
| 11 |
|
| 12 |
use Udb\Vars; |
| 13 |
use Udb\Helpers\Content_Helper; |
| 14 |
|
| 15 |
/** |
| 16 |
* Class to setup Ultimate Dashboard plugin. |
| 17 |
*/ |
| 18 |
class Setup { |
| 19 |
|
| 20 |
/** |
| 21 |
* The class instanace |
| 22 |
* |
| 23 |
* @var object |
| 24 |
*/ |
| 25 |
public static $instance = null; |
| 26 |
|
| 27 |
/** |
| 28 |
* Get the class instance. |
| 29 |
* |
| 30 |
* @return object |
| 31 |
*/ |
| 32 |
public static function get_instance() { |
| 33 |
if ( null === self::$instance ) { |
| 34 |
self::$instance = new self(); |
| 35 |
} |
| 36 |
|
| 37 |
return self::$instance; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Init the class setup. |
| 42 |
*/ |
| 43 |
public static function init() { |
| 44 |
|
| 45 |
$instance = new Setup(); |
| 46 |
$instance->setup(); |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Get saved/default modules. |
| 52 |
* |
| 53 |
* @return array The saved/default modules. |
| 54 |
*/ |
| 55 |
public function saved_modules() { |
| 56 |
|
| 57 |
$defaults = array( |
| 58 |
'white_label' => 'true', |
| 59 |
'login_customizer' => 'true', |
| 60 |
'login_redirect' => 'true', |
| 61 |
'admin_pages' => 'true', |
| 62 |
'admin_menu_editor' => 'true', |
| 63 |
'admin_bar_editor' => 'true', |
| 64 |
); |
| 65 |
|
| 66 |
$saved_modules = get_option( 'udb_modules', $defaults ); |
| 67 |
$new_modules = array_diff_key( $defaults, $saved_modules ); |
| 68 |
|
| 69 |
if ( ! empty( $new_modules ) ) { |
| 70 |
$updated_modules = array_merge( $saved_modules, $new_modules ); |
| 71 |
update_option( 'udb_modules', $updated_modules ); |
| 72 |
} |
| 73 |
|
| 74 |
return apply_filters( 'udb_saved_modules', get_option( 'udb_modules', $defaults ) ); |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Setup the class. |
| 80 |
*/ |
| 81 |
public function setup() { |
| 82 |
|
| 83 |
/** |
| 84 |
* We use 20 as the priority in the free version |
| 85 |
* because the PRO version has to run first. |
| 86 |
* |
| 87 |
* The PRO version has to run before the free version |
| 88 |
* because the PRO version hooks some action/filter to the free version. |
| 89 |
* So in order to make them executed, the PRO version has to run first. |
| 90 |
*/ |
| 91 |
|
| 92 |
register_activation_hook( ULTIMATE_DASHBOARD_PLUGIN_FILE, array( $this, 'on_plugin_activation' ), 20 ); |
| 93 |
|
| 94 |
add_action( 'plugins_loaded', array( $this, 'load_modules' ), 20 ); |
| 95 |
add_action( 'plugins_loaded', array( $this, 'load_plugin_onboarding_module' ), 20 ); |
| 96 |
add_action( 'plugins_loaded', array( $this, 'load_onboarding_wizard_module' ), 20 ); |
| 97 |
add_action( 'init', array( self::get_instance(), 'check_activation_meta' ) ); |
| 98 |
add_action( 'init', array( $this, 'register_action_links' ) ); |
| 99 |
add_action( 'admin_menu', array( $this, 'pro_submenu' ), 20 ); |
| 100 |
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ), 20 ); |
| 101 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ), 20 ); |
| 102 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 20 ); |
| 103 |
add_action( 'admin_notices', array( self::get_instance(), 'review_notice' ) ); |
| 104 |
add_action( 'admin_notices', array( self::get_instance(), 'bfcm_notice' ) ); |
| 105 |
add_action( 'wp_ajax_udb_dismiss_review_notice', array( $this, 'dismiss_review_notice' ) ); |
| 106 |
add_action( 'wp_ajax_udb_dismiss_bfcm_notice', array( $this, 'dismiss_bfcm_notice' ) ); |
| 107 |
|
| 108 |
register_deactivation_hook( ULTIMATE_DASHBOARD_PLUGIN_FILE, array( $this, 'deactivation' ), 20 ); |
| 109 |
|
| 110 |
$content_helper = new Content_Helper(); |
| 111 |
add_filter( 'wp_kses_allowed_html', array( $content_helper, 'allow_iframes_in_html' ) ); |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Preload UDB settings. |
| 117 |
* This will reduce the repeated call of get_option across modules. |
| 118 |
* |
| 119 |
* @deprecated 3.7.15 Not good for performance. This method was called both in admin & front area. The benefits were not much, because there was only few places where the preloaded data was re-used. |
| 120 |
*/ |
| 121 |
public function set_data() {} |
| 122 |
|
| 123 |
/** |
| 124 |
* Check plugin activation meta. |
| 125 |
*/ |
| 126 |
public function check_activation_meta() { |
| 127 |
|
| 128 |
if ( ! current_user_can( 'activate_plugins' ) || get_option( 'udb_plugin_activated' ) ) { |
| 129 |
return; |
| 130 |
} |
| 131 |
|
| 132 |
update_option( 'udb_install_date', current_time( 'mysql' ) ); |
| 133 |
update_option( 'udb_plugin_activated', 1 ); |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Admin body class. |
| 139 |
* |
| 140 |
* @param string $classes The class names. |
| 141 |
*/ |
| 142 |
public function admin_body_class( $classes ) { |
| 143 |
|
| 144 |
$current_user = wp_get_current_user(); |
| 145 |
$classes .= ' udb-user-' . $current_user->user_nicename; |
| 146 |
|
| 147 |
$roles = $current_user->roles; |
| 148 |
$roles = $roles ? $roles : array(); |
| 149 |
|
| 150 |
foreach ( $roles as $role ) { |
| 151 |
$classes .= ' udb-role-' . $role; |
| 152 |
} |
| 153 |
|
| 154 |
$screens = array( |
| 155 |
'udb_widgets_page_udb_features', |
| 156 |
'udb_widgets_page_udb-license', |
| 157 |
'udb_widgets_page_udb_tools', |
| 158 |
'udb_widgets_page_udb_branding', |
| 159 |
'udb_widgets_page_udb_settings', |
| 160 |
'udb_widgets_page_udb_login_redirect', |
| 161 |
'udb_widgets_page_udb_admin_menu', |
| 162 |
'udb_widgets_page_udb_admin_bar', |
| 163 |
'udb_widgets_page_udb_plugin_onboarding', |
| 164 |
'udb_widgets_page_udb_onboarding_wizard', |
| 165 |
); |
| 166 |
|
| 167 |
$screen = get_current_screen(); |
| 168 |
|
| 169 |
if ( ! in_array( $screen->id, $screens, true ) ) { |
| 170 |
return $classes; |
| 171 |
} |
| 172 |
|
| 173 |
$classes .= ' heatbox-admin has-header'; |
| 174 |
|
| 175 |
return $classes; |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Register plugin action links filter after init hook. |
| 181 |
* This ensures translations are loaded before the callback is executed. |
| 182 |
*/ |
| 183 |
public function register_action_links() { |
| 184 |
add_filter( 'plugin_action_links_' . ULTIMATE_DASHBOARD_PLUGIN_FILE, array( $this, 'action_links' ) ); |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* Add action links displayed in plugins page. |
| 189 |
* |
| 190 |
* @param array $links The action links array. |
| 191 |
* @return array The modified action links array. |
| 192 |
*/ |
| 193 |
public function action_links( $links ) { |
| 194 |
|
| 195 |
$settings = array( '<a href="' . admin_url( 'edit.php?post_type=udb_widgets&page=udb_settings' ) . '">' . __( 'Settings', 'ultimate-dashboard' ) . '</a>' ); |
| 196 |
|
| 197 |
return array_merge( $links, $settings ); |
| 198 |
|
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* Store an option that tracks the plugin activation. |
| 203 |
*/ |
| 204 |
public function on_plugin_activation() { |
| 205 |
|
| 206 |
// Stop if this is activation from Erident's migration to UDB. |
| 207 |
if ( get_option( 'udb_migration_from_erident' ) ) { |
| 208 |
// Prevent "Setup Wizard" from being shown for Erident's users. |
| 209 |
update_option( 'udb_onboarding_wizard_completed', 1 ); |
| 210 |
return; |
| 211 |
} |
| 212 |
|
| 213 |
// We bail out early in multisite because this function will still be called in the main site. |
| 214 |
if ( is_multisite() || udb_is_pro_active() ) { |
| 215 |
return; |
| 216 |
} |
| 217 |
|
| 218 |
update_option( 'udb_onboarding_wizard_redirect', 1 ); |
| 219 |
|
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Load Ultimate Dashboard modules. |
| 224 |
*/ |
| 225 |
public function load_modules() { |
| 226 |
|
| 227 |
$modules['Udb\\Widget\\Widget_Module'] = __DIR__ . '/modules/widget/class-widget-module.php'; |
| 228 |
|
| 229 |
if ( ! defined( 'ULTIMATE_DASHBOARD_PRO_PLUGIN_VERSION' ) || ULTIMATE_DASHBOARD_PRO_PLUGIN_VERSION >= '3.1' ) { |
| 230 |
$modules['Udb\\Feature\\Feature_Module'] = __DIR__ . '/modules/feature/class-feature-module.php'; |
| 231 |
} |
| 232 |
|
| 233 |
$modules['Udb\\Setting\\Setting_Module'] = __DIR__ . '/modules/setting/class-setting-module.php'; |
| 234 |
|
| 235 |
$saved_modules = $this->saved_modules(); |
| 236 |
|
| 237 |
if ( isset( $saved_modules['white_label'] ) && 'true' === $saved_modules['white_label'] ) { |
| 238 |
$modules['Udb\\Branding\\Branding_Module'] = __DIR__ . '/modules/branding/class-branding-module.php'; |
| 239 |
} |
| 240 |
|
| 241 |
if ( isset( $saved_modules['admin_pages'] ) && 'true' === $saved_modules['admin_pages'] ) { |
| 242 |
$modules['Udb\\AdminPage\\Admin_Page_Module'] = __DIR__ . '/modules/admin-page/class-admin-page-module.php'; |
| 243 |
} |
| 244 |
|
| 245 |
if ( isset( $saved_modules['login_customizer'] ) && 'true' === $saved_modules['login_customizer'] ) { |
| 246 |
$modules['Udb\\LoginCustomizer\\Login_Customizer_Module'] = __DIR__ . '/modules/login-customizer/class-login-customizer-module.php'; |
| 247 |
} |
| 248 |
|
| 249 |
if ( isset( $saved_modules['login_redirect'] ) && 'true' === $saved_modules['login_redirect'] ) { |
| 250 |
$modules['Udb\\LoginRedirect\\Login_Redirect_Module'] = __DIR__ . '/modules/login-redirect/class-login-redirect-module.php'; |
| 251 |
} |
| 252 |
|
| 253 |
if ( isset( $saved_modules['admin_menu_editor'] ) && 'true' === $saved_modules['admin_menu_editor'] ) { |
| 254 |
$modules['Udb\\AdminMenu\\Admin_Menu_Module'] = __DIR__ . '/modules/admin-menu/class-admin-menu-module.php'; |
| 255 |
} |
| 256 |
|
| 257 |
if ( isset( $saved_modules['admin_bar_editor'] ) && 'true' === $saved_modules['admin_bar_editor'] ) { |
| 258 |
$modules['Udb\\AdminBar\\Admin_Bar_Module'] = __DIR__ . '/modules/admin-bar/class-admin-bar-module.php'; |
| 259 |
} |
| 260 |
|
| 261 |
$modules['Udb\\Tool\\Tool_Module'] = __DIR__ . '/modules/tool/class-tool-module.php'; |
| 262 |
|
| 263 |
$modules = apply_filters( 'udb_modules', $modules ); |
| 264 |
|
| 265 |
foreach ( $modules as $class => $file ) { |
| 266 |
$splits = explode( '/', $file ); |
| 267 |
$module_name = $splits[ count( $splits ) - 2 ]; |
| 268 |
$filter_name = str_ireplace( '-', '_', $module_name ); |
| 269 |
$filter_name = 'udb_' . $filter_name; |
| 270 |
|
| 271 |
// We have a filter here udb_$module_name to allow us to prevent loading modules under certain circumstances. |
| 272 |
// Not sure if currently in use. |
| 273 |
if ( apply_filters( $filter_name, true ) ) { |
| 274 |
|
| 275 |
require_once $file; |
| 276 |
$module = new $class(); |
| 277 |
$module->setup(); |
| 278 |
|
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
} |
| 283 |
|
| 284 |
/** |
| 285 |
* Load plugin onboarding module. |
| 286 |
*/ |
| 287 |
public function load_plugin_onboarding_module() { |
| 288 |
|
| 289 |
$need_setup = false; |
| 290 |
$referrer = ''; |
| 291 |
|
| 292 |
// Erident's migration takes the highest priority. |
| 293 |
if ( get_option( 'udb_migration_from_erident' ) ) { |
| 294 |
$need_setup = true; |
| 295 |
$referrer = 'erident'; |
| 296 |
} elseif ( get_option( 'udb_referred_by_kirki' ) ) { |
| 297 |
$need_setup = true; |
| 298 |
$referrer = 'kirki'; |
| 299 |
} |
| 300 |
// In the future, we might allow UDB to be installed from other plugins as well. |
| 301 |
|
| 302 |
if ( ! $need_setup ) { |
| 303 |
return; |
| 304 |
} |
| 305 |
|
| 306 |
require_once __DIR__ . '/modules/plugin-onboarding/class-plugin-onboarding-module.php'; |
| 307 |
$module = new PluginOnboarding\Plugin_Onboarding_Module(); |
| 308 |
$module->setup( $referrer ); |
| 309 |
|
| 310 |
} |
| 311 |
|
| 312 |
/** |
| 313 |
* Load onboarding wizard module. |
| 314 |
*/ |
| 315 |
public function load_onboarding_wizard_module() { |
| 316 |
|
| 317 |
if ( is_multisite() || udb_is_pro_active() ) { |
| 318 |
return; |
| 319 |
} |
| 320 |
|
| 321 |
if ( get_option( 'udb_onboarding_wizard_completed' ) ) { |
| 322 |
return; |
| 323 |
} |
| 324 |
|
| 325 |
if ( get_option( 'udb_onboarding_wizard_redirect' ) ) { |
| 326 |
// Redirect to onboarding wizard page. |
| 327 |
add_action( 'current_screen', array( $this, 'redirect_to_onboarding_wizard_page' ), 20 ); |
| 328 |
} |
| 329 |
|
| 330 |
require_once __DIR__ . '/modules/onboarding-wizard/class-onboarding-wizard-module.php'; |
| 331 |
$module = new OnboardingWizard\Onboarding_Wizard_Module(); |
| 332 |
$module->setup(); |
| 333 |
|
| 334 |
} |
| 335 |
|
| 336 |
/** |
| 337 |
* Redirect to the Onboarding Wizard page after activate the plugin. |
| 338 |
*/ |
| 339 |
public function redirect_to_onboarding_wizard_page() { |
| 340 |
|
| 341 |
$current_screen = get_current_screen(); |
| 342 |
|
| 343 |
if ( is_null( $current_screen ) ) { |
| 344 |
return; |
| 345 |
} |
| 346 |
|
| 347 |
// Stop if current screen is onboarding wizard page. |
| 348 |
if ( 'udb_widgets_page_udb_onboarding_wizard' === $current_screen->id ) { |
| 349 |
return; |
| 350 |
} |
| 351 |
|
| 352 |
// Stop if this request is not supposed to be redirected. |
| 353 |
if ( ! get_option( 'udb_onboarding_wizard_redirect' ) ) { |
| 354 |
return; |
| 355 |
} |
| 356 |
|
| 357 |
// Immediately delete the redirect option because redirect is supposed to happen once. |
| 358 |
delete_option( 'udb_onboarding_wizard_redirect' ); |
| 359 |
|
| 360 |
// Redirect to the Onboarding Wizard page. |
| 361 |
wp_safe_redirect( admin_url( 'edit.php?post_type=udb_widgets&page=udb_onboarding_wizard' ) ); |
| 362 |
exit; |
| 363 |
|
| 364 |
} |
| 365 |
|
| 366 |
/** |
| 367 |
* Generate PRO submenu link. |
| 368 |
*/ |
| 369 |
public function pro_submenu() { |
| 370 |
|
| 371 |
// Stop if PRO version is active. |
| 372 |
if ( udb_is_pro_active() ) { |
| 373 |
return; |
| 374 |
} |
| 375 |
|
| 376 |
// Stop if user isn't an admin. |
| 377 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 378 |
return; |
| 379 |
} |
| 380 |
|
| 381 |
global $submenu; |
| 382 |
|
| 383 |
$submenu['edit.php?post_type=udb_widgets'][] = array( 'Upgrade to PRO', 'manage_options', 'https://ultimatedashboard.io/pro/' ); |
| 384 |
|
| 385 |
} |
| 386 |
|
| 387 |
/** |
| 388 |
* Enqueue admin styles. |
| 389 |
*/ |
| 390 |
public function admin_styles() { |
| 391 |
|
| 392 |
wp_enqueue_style( 'udb-admin', ULTIMATE_DASHBOARD_PLUGIN_URL . '/assets/css/admin.css', array(), ULTIMATE_DASHBOARD_PLUGIN_VERSION ); |
| 393 |
|
| 394 |
} |
| 395 |
|
| 396 |
/** |
| 397 |
* Enqueue admin scripts. |
| 398 |
*/ |
| 399 |
public function admin_scripts() { |
| 400 |
|
| 401 |
wp_enqueue_script( 'udb-notice-dismissal', ULTIMATE_DASHBOARD_PLUGIN_URL . '/assets/js/notice-dismissal.js', array( 'jquery' ), ULTIMATE_DASHBOARD_PLUGIN_VERSION, true ); |
| 402 |
|
| 403 |
wp_localize_script( |
| 404 |
'udb-notice-dismissal', |
| 405 |
'udbNoticeDismissal', |
| 406 |
array( |
| 407 |
'nonce' => wp_create_nonce( 'udb_dismiss_notice' ), |
| 408 |
) |
| 409 |
); |
| 410 |
|
| 411 |
} |
| 412 |
|
| 413 |
/** |
| 414 |
* Show review notice after certain number of day(s). |
| 415 |
*/ |
| 416 |
public function review_notice() { |
| 417 |
|
| 418 |
// Stop if user isn't an admin. |
| 419 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 420 |
return; |
| 421 |
} |
| 422 |
|
| 423 |
// Stop if review notice had been dismissed. |
| 424 |
if ( get_option( 'review_notice_dismissed' ) ) { |
| 425 |
return; |
| 426 |
} |
| 427 |
|
| 428 |
$install_date = get_option( 'udb_install_date' ); |
| 429 |
|
| 430 |
// Stop if there's no install date. |
| 431 |
if ( empty( $install_date ) ) { |
| 432 |
return; |
| 433 |
} |
| 434 |
|
| 435 |
$diff = round( ( time() - strtotime( $install_date ) ) / 24 / 60 / 60 ); |
| 436 |
|
| 437 |
// Don't show the notice if Ultimate Dashboard is running not more than 5 days. |
| 438 |
if ( $diff < 5 ) { |
| 439 |
return; |
| 440 |
} |
| 441 |
|
| 442 |
$emoji = '😍'; |
| 443 |
$review_url = 'https://wordpress.org/support/plugin/ultimate-dashboard/reviews/?rate=5#new-post'; |
| 444 |
$link_start = '<a href="' . $review_url . '" target="_blank">'; |
| 445 |
$link_end = '</a>'; |
| 446 |
// translators: %1$s: Emoji, %2$s: Link start tag, %3$s: Link end tag. |
| 447 |
$notice = sprintf( __( '%1$s Love using Ultimate Dashboard? - That\'s Awesome! Help us spread the word and leave us a %2$s 5-star review %3$s in the WordPress repository.', 'ultimate-dashboard' ), $emoji, $link_start, $link_end ); |
| 448 |
$btn_text = __( 'Sure! You deserve it!', 'ultimate-dashboard' ); |
| 449 |
$notice .= '<br/>'; |
| 450 |
$notice .= "<a href=\"$review_url\" style=\"margin-top: 15px;\" target='_blank' class=\"button-primary\">$btn_text</a>"; |
| 451 |
|
| 452 |
echo '<div class="notice udb-notice udb-review-notice notice-success is-dismissible is-permanent-dismissible" data-ajax-action="udb_dismiss_review_notice">'; |
| 453 |
echo '<p>' . wp_kses_post( $notice ) . '</p>'; |
| 454 |
echo '</div>'; |
| 455 |
|
| 456 |
} |
| 457 |
|
| 458 |
/** |
| 459 |
* Dismiss review notice. |
| 460 |
*/ |
| 461 |
public function dismiss_review_notice() { |
| 462 |
|
| 463 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : ''; |
| 464 |
|
| 465 |
if ( ! wp_verify_nonce( $nonce, 'udb_dismiss_notice' ) ) { |
| 466 |
wp_send_json_error( __( 'Invalid token', 'ultimate-dashboard' ) ); |
| 467 |
} |
| 468 |
|
| 469 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 470 |
wp_send_json_error( __( 'You do not have permission to perform this action', 'ultimate-dashboard' ) ); |
| 471 |
} |
| 472 |
|
| 473 |
if ( empty( $_POST['dismiss'] ) ) { |
| 474 |
wp_send_json_error( __( 'Invalid request', 'ultimate-dashboard' ) ); |
| 475 |
} |
| 476 |
|
| 477 |
update_option( 'review_notice_dismissed', 1 ); |
| 478 |
wp_send_json_success( __( 'Review notice has been dismissed.', 'ultimate-dashboard' ) ); |
| 479 |
|
| 480 |
} |
| 481 |
|
| 482 |
/** |
| 483 |
* Show BFCM notice. |
| 484 |
*/ |
| 485 |
public function bfcm_notice() { |
| 486 |
|
| 487 |
// Stop if PRO version is active. |
| 488 |
if ( udb_is_pro_active() ) { |
| 489 |
return; |
| 490 |
} |
| 491 |
|
| 492 |
// Stop here if we are not on the main site of the network. |
| 493 |
if ( ! is_main_site() ) { |
| 494 |
return; |
| 495 |
} |
| 496 |
|
| 497 |
// Stop here if current user is not an admin. |
| 498 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 499 |
return; |
| 500 |
} |
| 501 |
|
| 502 |
// Intentional: using manually written string instead of gmdate( 'Y' ). |
| 503 |
$this_year = '2025'; |
| 504 |
$last_year = $this_year - 1; |
| 505 |
$start = strtotime( 'november 24th, ' . $this_year ); |
| 506 |
$end = strtotime( 'december 1st, ' . $this_year ); |
| 507 |
$now = time(); |
| 508 |
|
| 509 |
// Stop here if we are not in the sales period. |
| 510 |
if ( $now < $start || $now > $end ) { |
| 511 |
return; |
| 512 |
} |
| 513 |
|
| 514 |
// Clean up: Delete initial deal dismissal if triggered. |
| 515 |
if ( ! empty( get_option( 'udb_bfcm_notice_dismissed', 0 ) ) ) { |
| 516 |
delete_option( 'udb_bfcm_notice_dismissed' ); |
| 517 |
} |
| 518 |
|
| 519 |
// Clean up: Delete last years dismissal if triggered. |
| 520 |
if ( ! empty( get_option( 'udb_bfcm_notice_dismissed_' . $last_year, 0 ) ) ) { |
| 521 |
delete_option( 'udb_bfcm_notice_dismissed_' . $last_year ); |
| 522 |
} |
| 523 |
|
| 524 |
// Stop here if notice has been dismissed. |
| 525 |
if ( ! empty( get_option( 'udb_bfcm_notice_dismissed_' . $this_year, 0 ) ) ) { |
| 526 |
return; |
| 527 |
} |
| 528 |
|
| 529 |
$bfcm_url = 'https://ultimatedashboard.io/pricing/?utm_source=repository&utm_medium=bfcm_banner&utm_campaign=udb'; |
| 530 |
?> |
| 531 |
|
| 532 |
<div class="notice udb-notice udb-bfcm-notice notice-info is-dismissible is-permanent-dismissible" data-ajax-action="udb_dismiss_bfcm_notice"> |
| 533 |
<div class="notice-body"> |
| 534 |
<div class="notice-icon"> |
| 535 |
<img src="<?php echo esc_url( ULTIMATE_DASHBOARD_PLUGIN_URL ); ?>/assets/img/logo.png" alt="Ultimate Dashboard Logo"> |
| 536 |
</div> |
| 537 |
<div class="notice-content"> |
| 538 |
<h2> |
| 539 |
<?php esc_html_e( 'Black Friday Sale! - Up to 25% Off Ultimate Dashboard PRO', 'ultimate-dashboard' ); ?> |
| 540 |
</h2> |
| 541 |
<p> |
| 542 |
<?php echo wp_kses_post( __( 'Save big & upgrade to <strong>Ultimate Dashboard PRO</strong>, today!', 'ultimate-dashboard' ) ); ?> |
| 543 |
</p> |
| 544 |
<p> |
| 545 |
<?php esc_html_e( 'But hurry up, the deal will expire soon!', 'ultimate-dashboard' ); ?><br> |
| 546 |
<em><?php esc_html_e( 'All prices are reduced. No coupon code required.', 'ultimate-dashboard' ); ?></em> |
| 547 |
</p> |
| 548 |
<p> |
| 549 |
<a target="_blank" href="<?php echo esc_url( $bfcm_url ); ?>" class="button button-primary"> |
| 550 |
<?php esc_html_e( 'Learn more', 'ultimate-dashboard' ); ?> |
| 551 |
</a> |
| 552 |
<small><?php esc_html_e( '*Only Administrators will see this message.', 'ultimate-dashboard' ); ?></small> |
| 553 |
</p> |
| 554 |
</div> |
| 555 |
</div> |
| 556 |
</div> |
| 557 |
|
| 558 |
<?php |
| 559 |
} |
| 560 |
|
| 561 |
/** |
| 562 |
* Dismiss BFCM notice. |
| 563 |
*/ |
| 564 |
public function dismiss_bfcm_notice() { |
| 565 |
|
| 566 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : ''; |
| 567 |
|
| 568 |
if ( ! wp_verify_nonce( $nonce, 'udb_dismiss_notice' ) ) { |
| 569 |
wp_send_json_error( __( 'Invalid token', 'ultimate-dashboard' ) ); |
| 570 |
} |
| 571 |
|
| 572 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 573 |
wp_send_json_error( __( 'You do not have permission to perform this action', 'ultimate-dashboard' ) ); |
| 574 |
} |
| 575 |
|
| 576 |
if ( empty( $_POST['dismiss'] ) ) { |
| 577 |
wp_send_json_error( __( 'Invalid request', 'ultimate-dashboard' ) ); |
| 578 |
} |
| 579 |
|
| 580 |
update_option( 'udb_bfcm_notice_dismissed_2025', 1 ); |
| 581 |
wp_send_json_success( __( 'BFCM notice has been dismissed.', 'ultimate-dashboard' ) ); |
| 582 |
|
| 583 |
} |
| 584 |
|
| 585 |
/** |
| 586 |
* Plugin deactivation. |
| 587 |
*/ |
| 588 |
public function deactivation() { |
| 589 |
|
| 590 |
if ( $this->multisite_supported() ) { |
| 591 |
$blueprint = get_site_option( 'udb_multisite_blueprint' ); |
| 592 |
$blueprint = $blueprint ? (int) $blueprint : 0; |
| 593 |
|
| 594 |
$site_ids = get_sites( |
| 595 |
array( |
| 596 |
'fields' => 'ids', |
| 597 |
) |
| 598 |
); |
| 599 |
|
| 600 |
if ( $blueprint ) { |
| 601 |
// When blueprint is set, we get the data removal option from blueprint only. |
| 602 |
$settings = get_blog_option( $blueprint, 'udb_settings', array() ); |
| 603 |
$remove_data = isset( $settings['remove-on-uninstall'] ) ? true : false; |
| 604 |
|
| 605 |
if ( $remove_data ) { |
| 606 |
foreach ( $site_ids as $site_id ) { |
| 607 |
if ( $site_id !== $blueprint ) { |
| 608 |
// Don't restore the data removal option if $site_id is not the blueprint. |
| 609 |
$this->delete_udb_data( $site_id, false ); |
| 610 |
} else { |
| 611 |
$this->delete_udb_data( $site_id ); |
| 612 |
} |
| 613 |
} |
| 614 |
} |
| 615 |
} else { |
| 616 |
// When blueprint is not set, we check the data removal option per-site id. |
| 617 |
foreach ( $site_ids as $site_id ) { |
| 618 |
$settings = get_blog_option( $site_id, 'udb_settings', array() ); |
| 619 |
$remove_data = isset( $settings['remove-on-uninstall'] ) ? true : false; |
| 620 |
|
| 621 |
if ( $remove_data ) { |
| 622 |
$this->delete_udb_data( $site_id ); |
| 623 |
} |
| 624 |
} |
| 625 |
} |
| 626 |
} else { |
| 627 |
$settings = get_option( 'udb_settings' ); |
| 628 |
$remove_data = isset( $settings['remove-on-uninstall'] ) ? true : false; |
| 629 |
|
| 630 |
if ( $remove_data ) { |
| 631 |
$this->delete_udb_data( null ); |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
} |
| 636 |
|
| 637 |
/** |
| 638 |
* Delete free-related options on plugin deactivation. |
| 639 |
* |
| 640 |
* We still have `udb_multisite_blueprint` option and |
| 641 |
* it won't be deleted on both free & pro versions deactivation. |
| 642 |
* So that it wouldn't be a problem if user deactivate free version first or pro version first. |
| 643 |
* Both versions will be able to get the blueprint value. |
| 644 |
* |
| 645 |
* So yea, `udb_multisite_blueprint` will stays in the database. |
| 646 |
* |
| 647 |
* @param int|null $site_id The site id or null. |
| 648 |
* @param bool $restore_removal_option Whether to restore the data removal option or not. |
| 649 |
* This is used to handle the case when the free version is de-activated first, |
| 650 |
* then the pro version is de-activated later. |
| 651 |
*/ |
| 652 |
public function delete_udb_data( $site_id, $restore_removal_option = true ) { |
| 653 |
|
| 654 |
if ( $site_id ) { |
| 655 |
delete_blog_option( $site_id, 'udb_settings' ); |
| 656 |
delete_blog_option( $site_id, 'udb_branding' ); |
| 657 |
delete_blog_option( $site_id, 'udb_login' ); |
| 658 |
delete_blog_option( $site_id, 'udb_login_redirect' ); |
| 659 |
delete_blog_option( $site_id, 'udb_import' ); |
| 660 |
delete_blog_option( $site_id, 'udb_modules' ); |
| 661 |
delete_blog_option( $site_id, 'udb_recent_admin_menu' ); |
| 662 |
|
| 663 |
delete_blog_option( $site_id, 'udb_compat_widget_type' ); |
| 664 |
delete_blog_option( $site_id, 'udb_compat_widget_status' ); |
| 665 |
delete_blog_option( $site_id, 'udb_compat_delete_login_customizer_page' ); |
| 666 |
delete_blog_option( $site_id, 'udb_compat_settings_meta' ); |
| 667 |
delete_blog_option( $site_id, 'udb_compat_old_option' ); |
| 668 |
|
| 669 |
delete_blog_option( $site_id, 'udb_migration_from_erident' ); |
| 670 |
delete_blog_option( $site_id, 'udb_referred_by_kirki' ); |
| 671 |
|
| 672 |
delete_blog_option( $site_id, 'udb_login_customizer_flush_url' ); |
| 673 |
delete_blog_option( $site_id, 'review_notice_dismissed' ); |
| 674 |
|
| 675 |
/** |
| 676 |
* Backwards compatibility |
| 677 |
* We will no longer have to remove related data on multisites as from 2022 on we will only show the bfcm notice on the main site. |
| 678 |
*/ |
| 679 |
delete_blog_option( $site_id, 'udb_bfcm_notice_dismissed' ); |
| 680 |
|
| 681 |
delete_blog_option( $site_id, 'udb_install_date' ); |
| 682 |
delete_blog_option( $site_id, 'udb_plugin_activated' ); |
| 683 |
|
| 684 |
if ( $restore_removal_option && defined( 'ULTIMATE_DASHBOARD_PRO_PLUGIN_VERSION' ) ) { |
| 685 |
update_blog_option( $site_id, 'udb_settings', array( 'remove-on-uninstall' => 1 ) ); |
| 686 |
} |
| 687 |
} else { |
| 688 |
delete_option( 'udb_settings' ); |
| 689 |
delete_option( 'udb_branding' ); |
| 690 |
delete_option( 'udb_login' ); |
| 691 |
delete_option( 'udb_login_redirect' ); |
| 692 |
delete_option( 'udb_import' ); |
| 693 |
delete_option( 'udb_modules' ); |
| 694 |
delete_option( 'udb_recent_admin_menu' ); |
| 695 |
|
| 696 |
delete_option( 'udb_compat_widget_type' ); |
| 697 |
delete_option( 'udb_compat_widget_status' ); |
| 698 |
delete_option( 'udb_compat_delete_login_customizer_page' ); |
| 699 |
delete_option( 'udb_compat_settings_meta' ); |
| 700 |
delete_option( 'udb_compat_old_option' ); |
| 701 |
|
| 702 |
delete_option( 'udb_migration_from_erident' ); |
| 703 |
delete_option( 'udb_referred_by_kirki' ); |
| 704 |
|
| 705 |
delete_option( 'udb_login_customizer_flush_url' ); |
| 706 |
delete_option( 'review_notice_dismissed' ); |
| 707 |
|
| 708 |
delete_option( 'udb_install_date' ); |
| 709 |
delete_option( 'udb_plugin_activated' ); |
| 710 |
|
| 711 |
// These 2 options won't be available in multisite install. |
| 712 |
delete_option( 'udb_onboarding_wizard_redirect' ); |
| 713 |
delete_option( 'udb_onboarding_wizard_completed' ); |
| 714 |
|
| 715 |
if ( $restore_removal_option && defined( 'ULTIMATE_DASHBOARD_PRO_PLUGIN_VERSION' ) ) { |
| 716 |
update_option( $site_id, 'udb_settings', array( 'remove-on-uninstall' => 1 ) ); |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
} |
| 721 |
|
| 722 |
/** |
| 723 |
* Check whether plugin is active on multisite or not. |
| 724 |
* |
| 725 |
* @return bool |
| 726 |
*/ |
| 727 |
private function is_network_active() { |
| 728 |
// Load plugin.php if it doesn't already exist. |
| 729 |
if ( ! function_exists( 'is_plugin_active_for_network' ) || ! function_exists( 'is_plugin_active' ) ) { |
| 730 |
require_once ABSPATH . '/wp-admin/includes/plugin.php'; |
| 731 |
} |
| 732 |
|
| 733 |
return ( is_plugin_active_for_network( 'ultimate-dashboard/ultimate-dashboard.php' ) ? true : false ); |
| 734 |
} |
| 735 |
|
| 736 |
/** |
| 737 |
* Check whether multisite actions are supported or not. |
| 738 |
* |
| 739 |
* But, we don't check for `udb_pro_ms_support` filter here. |
| 740 |
* That filter belongs to the pro version. |
| 741 |
* |
| 742 |
* @return bool |
| 743 |
*/ |
| 744 |
private function multisite_supported() { |
| 745 |
return ( $this->is_network_active() ? true : false ); |
| 746 |
} |
| 747 |
|
| 748 |
} |
| 749 |
|