| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | Description: Forumax is forum software for community discussions with public and private replies, private chats, voting, solved topics and more. |
| 6 | 6 | Author: spider-themes |
| 7 | 7 | Author URI: https://forumax.spider-themes.net/ |
| 8 | 8 | Text Domain: forumax |
| 9 | -Version: 2.1.0 | |
| 9 | +Version: 2.2.0 | |
| 10 | 10 | Requires at least: 5.0 |
| 11 | 11 | Tested up to: 6.9 |
| 12 | 12 | Requires PHP: 7.4 |
| 13 | 13 | License: GPLv3 or later |
| @@ -84,9 +84,9 @@ | ||
| 84 | 84 | * Plugin's heart |
| 85 | 85 | */ |
| 86 | 86 | final class Forumax |
| 87 | 87 | { |
| 88 | - const VERSION = '2.1.0'; | |
| 88 | + const VERSION = '2.2.0'; | |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * Class constructor. |
| 92 | 92 | */ |
| @@ -96,8 +96,9 @@ | ||
| 96 | 96 | $this->define_constants(); |
| 97 | 97 | $this->core_includes(); |
| 98 | 98 | |
| 99 | 99 | register_activation_hook(__FILE__, [$this, 'activate']); |
| 100 | + register_deactivation_hook(__FILE__, [$this, 'deactivate']); | |
| 100 | 101 | add_action('plugins_loaded', [$this, 'init_plugin']); |
| 101 | 102 | add_action('after_setup_theme', [$this, 'load_csf_files'], 20); |
| 102 | 103 | |
| 103 | 104 | // Added Documentation links to plugin row meta |
| @@ -102,10 +103,11 @@ | ||
| 102 | 103 | |
| 103 | 104 | // Added Documentation links to plugin row meta |
| 104 | 105 | add_filter('plugin_row_meta', [$this, 'forumax_row_meta'], 10, 2); |
| 105 | 106 | |
| 106 | - // Theme compatibility notice | |
| 107 | - add_action('admin_notices', [$this, 'theme_compatibility_notice']); | |
| 107 | + // Prevent deactivation if Forumax Pro is active | |
| 108 | + add_action('admin_init', [$this, 'prevent_deactivation_if_pro_active']); | |
| 109 | + add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'modify_deactivate_link'], 10, 4); | |
| 108 | 110 | |
| 109 | 111 | /** |
| 110 | 112 | * Removes admin notices on the Forumax Forum builder page. |
| 111 | 113 | * |
| @@ -226,9 +228,9 @@ | ||
| 226 | 228 | update_option('bbpc_version', FORUMAX_VERSION); |
| 227 | 229 | |
| 228 | 230 | // Ensure default option for forumax_settings |
| 229 | 231 | $defaults = [ |
| 230 | - 'is_bbpc_insert_media' => true, | |
| 232 | + 'is_bbpc_insert_media' => false, | |
| 231 | 233 | ]; |
| 232 | 234 | |
| 233 | 235 | $current = get_option('bbp_core_settings', []); |
| 234 | 236 | $updated = wp_parse_args($current, $defaults); |
| @@ -239,8 +241,18 @@ | ||
| 239 | 241 | $this->migrate_docy_core_widgets(); |
| 240 | 242 | } |
| 241 | 243 | |
| 242 | 244 | /** |
| 245 | + * Actions on plugin deactivation. | |
| 246 | + * | |
| 247 | + * @return void | |
| 248 | + */ | |
| 249 | + public function deactivate() | |
| 250 | + { | |
| 251 | + wp_clear_scheduled_hook('frmx_auto_close_stale_topics'); | |
| 252 | + } | |
| 253 | + | |
| 254 | + /** | |
| 243 | 255 | * Migrate old Docy Core Forums widgets to Forumax widgets |
| 244 | 256 | * |
| 245 | 257 | * This function automatically converts any existing docy-core Forums widgets |
| 246 | 258 | * to the new Forumax Forums List widgets to ensure seamless transition. |
| @@ -434,85 +446,9 @@ | ||
| 434 | 446 | update_option('forumax_widget_migration_done', true); |
| 435 | 447 | } |
| 436 | 448 | } |
| 437 | 449 | |
| 438 | - /** | |
| 439 | - * Display admin notice for theme compatibility | |
| 440 | - * | |
| 441 | - * Checks if the active theme meets the minimum required version | |
| 442 | - * for Forumax compatibility and displays a warning notice if not. | |
| 443 | - * | |
| 444 | - * @return void | |
| 445 | - */ | |
| 446 | - public function theme_compatibility_notice() { | |
| 447 | - $theme = wp_get_theme(); | |
| 448 | - $theme_name = $theme->get( 'Name' ); | |
| 449 | - $current_theme_v = $theme->get( 'Version' ); | |
| 450 | 450 | |
| 451 | - // Set required version for each theme | |
| 452 | - $my_themes = array( | |
| 453 | - 'Docy' => '4.4.0', | |
| 454 | - 'Docly' => '2.3.2', | |
| 455 | - 'Ama' => '1.7.1' | |
| 456 | - ); | |
| 457 | - | |
| 458 | - foreach ( $my_themes as $name => $required_v ) { | |
| 459 | - // Check if theme name contains one of our themes | |
| 460 | - if ( stripos( $theme_name, $name ) !== false ) { | |
| 461 | - | |
| 462 | - // Check if current version is less than required version | |
| 463 | - if ( version_compare( $current_theme_v, $required_v, '<' ) ) { | |
| 464 | - ?> | |
| 465 | - <div class="notice notice-error" style="border-left-color: #dc3232; padding: 15px;"> | |
| 466 | - <div style="display: flex; align-items: flex-start; gap: 15px;"> | |
| 467 | - <span style="font-size: 40px; line-height: 1;">⚠️</span> | |
| 468 | - <div style="flex: 1;"> | |
| 469 | - <h2 style="margin: 0 0 10px 0; color: #dc3232; font-size: 18px;"> | |
| 470 | - <?php esc_html_e( '🚨 CRITICAL: Immediate Action Required!', 'forumax' ); ?> | |
| 471 | - </h2> | |
| 472 | - <p style="font-size: 15px; margin: 0 0 10px 0; line-height: 1.6;"> | |
| 473 | - <strong><?php esc_html_e( 'Your site may break or malfunction!', 'forumax' ); ?></strong> | |
| 474 | - </p> | |
| 475 | - <p style="font-size: 14px; margin: 0 0 15px 0; line-height: 1.6;"> | |
| 476 | - <?php | |
| 477 | - printf( | |
| 478 | - /* translators: 1: Theme name, 2: Current version, 3: Required version */ | |
| 479 | - esc_html__( 'Your %1$s theme is outdated (version %2$s). Please update to version %3$s or higher. We have made significant changes to the Forumax plugin, and using an outdated theme will cause compatibility issues and may break your website.', 'forumax' ), | |
| 480 | - '<strong>' . esc_html( $theme_name ) . '</strong>', | |
| 481 | - '<code style="background: #fff3cd; padding: 2px 6px; border-radius: 3px; color: #856404;">' . esc_html( $current_theme_v ) . '</code>', | |
| 482 | - '<code style="background: #d4edda; padding: 2px 6px; border-radius: 3px; color: #155724; font-weight: bold;">' . esc_html( $required_v ) . '</code>' | |
| 483 | - ); | |
| 484 | - ?> | |
| 485 | - </p> | |
| 486 | - <div style="background: #fff3cd; border-left: 4px solid #ffc107; padding: 12px; margin-bottom: 15px;"> | |
| 487 | - <p style="margin: 0; font-size: 13px; color: #856404;"> | |
| 488 | - <strong><?php esc_html_e( '⚡ What has changed:', 'forumax' ); ?></strong><br> | |
| 489 | - <?php esc_html_e( 'We have completely restructured the Forumax plugin with new features, improved performance, and enhanced security. Your current theme version is not compatible with these updates.', 'forumax' ); ?> | |
| 490 | - </p> | |
| 491 | - </div> | |
| 492 | - <p style="margin: 0;"> | |
| 493 | - <a href="<?php echo esc_url( admin_url( 'update-core.php' ) ); ?>" class="button button-primary" style="background: #dc3232; border-color: #dc3232; font-size: 14px; height: auto; padding: 8px 20px;"> | |
| 494 | - <?php esc_html_e( '🔄 Update Theme Now', 'forumax' ); ?> | |
| 495 | - </a> | |
| 496 | - <span style="margin-left: 15px; color: #666; font-size: 13px;"> | |
| 497 | - <?php esc_html_e( 'This update is mandatory for your site to function properly.', 'forumax' ); ?> | |
| 498 | - </span> | |
| 499 | - </p> | |
| 500 | - </div> | |
| 501 | - </div> | |
| 502 | - </div> | |
| 503 | - <style> | |
| 504 | - .notice.notice-error h2 { | |
| 505 | - font-size: 18px !important; | |
| 506 | - } | |
| 507 | - </style> | |
| 508 | - <?php | |
| 509 | - } | |
| 510 | - break; // Stop loop once theme is found | |
| 511 | - } | |
| 512 | - } | |
| 513 | - } | |
| 514 | - | |
| 515 | 451 | /** |
| 516 | 452 | * Include CSF files include |
| 517 | 453 | */ |
| 518 | 454 | public function load_csf_files() |
| @@ -533,8 +469,11 @@ | ||
| 533 | 469 | if (forumax_get_opt('is_solved_topics', true)) { |
| 534 | 470 | require FORUMAX_FEAT_PATH . 'bbp_solved_topic.php'; |
| 535 | 471 | } |
| 536 | 472 | |
| 473 | + // Auto Close Stale Topics | |
| 474 | + require FORUMAX_FEAT_PATH . 'forumax_auto_close.php'; | |
| 475 | + | |
| 537 | 476 | if (forumax_get_opt('is_private_replies', true)) { |
| 538 | 477 | require FORUMAX_FEAT_PATH . 'bbp-private-replies.php'; |
| 539 | 478 | } |
| 540 | 479 | |
| @@ -570,8 +509,67 @@ | ||
| 570 | 509 | } |
| 571 | 510 | |
| 572 | 511 | return $links; |
| 573 | 512 | } |
| 513 | + | |
| 514 | +/** | |
| 515 | + * Prevent deactivation of Forumax if Forumax Pro is active | |
| 516 | + * Users must deactivate Forumax Pro first before deactivating Forumax | |
| 517 | + * | |
| 518 | + * @return void | |
| 519 | + */ | |
| 520 | +public function prevent_deactivation_if_pro_active() | |
| 521 | +{ | |
| 522 | + // Check if we're on the plugins page | |
| 523 | + if (!isset($_SERVER['REQUEST_URI']) || strpos($_SERVER['REQUEST_URI'], 'plugins.php') === false) { | |
| 524 | + return; | |
| 525 | + } | |
| 526 | + | |
| 527 | + // Check if user is trying to deactivate this plugin | |
| 528 | + if (isset($_GET['action']) && $_GET['action'] === 'deactivate' && | |
| 529 | + isset($_GET['plugin']) && $_GET['plugin'] === plugin_basename(__FILE__)) { | |
| 530 | + | |
| 531 | + // Check if Forumax Pro is active | |
| 532 | + if (is_plugin_active('forumax-pro/forumax.php')) { | |
| 533 | + // Prevent deactivation | |
| 534 | + wp_die( | |
| 535 | + '<h1>' . esc_html__('Cannot Deactivate Forumax', 'forumax') . '</h1>' . | |
| 536 | + '<p>' . esc_html__('You cannot deactivate Forumax while Forumax Pro is active.', 'forumax') . '</p>' . | |
| 537 | + '<p>' . esc_html__('Please deactivate Forumax Pro first, then you can deactivate Forumax.', 'forumax') . '</p>', | |
| 538 | + esc_html__('Plugin Dependency Error', 'forumax'), | |
| 539 | + array('back_link' => true) | |
| 540 | + ); | |
| 541 | + } | |
| 542 | + } | |
| 543 | +} | |
| 544 | + | |
| 545 | +/** | |
| 546 | + * Modify the deactivate link to show a disabled state when Forumax Pro is active | |
| 547 | + * | |
| 548 | + * @param array $actions An array of plugin action links. | |
| 549 | + * @param string $plugin_file Path to the plugin file relative to the plugins directory. | |
| 550 | + * @param array $plugin_data An array of plugin data. | |
| 551 | + * @param string $context The plugin context (active, inactive, etc). | |
| 552 | + * @return array Modified action links | |
| 553 | + */ | |
| 554 | +public function modify_deactivate_link($actions, $plugin_file, $plugin_data, $context) | |
| 555 | +{ | |
| 556 | + // Check if Forumax Pro is active | |
| 557 | + if (is_plugin_active('forumax-pro/forumax.php')) { | |
| 558 | + // Remove the default deactivate link | |
| 559 | + if (isset($actions['deactivate'])) { | |
| 560 | + unset($actions['deactivate']); | |
| 561 | + | |
| 562 | + // Add a disabled deactivate message | |
| 563 | + $actions['deactivate_disabled'] = '<span style="color: #a0a5aa; cursor: not-allowed;" title="' . | |
| 564 | + esc_attr__('Please deactivate Forumax Pro first', 'forumax') . '">' . | |
| 565 | + esc_html__('Deactivate', 'forumax') . | |
| 566 | + '</span>'; | |
| 567 | + } | |
| 568 | + } | |
| 569 | + | |
| 570 | + return $actions; | |
| 571 | +} | |
| 574 | 572 | |
| 575 | 573 | } |
| 576 | 574 | |
| 577 | 575 | /** |