| @@ -34,9 +34,9 @@ | ||
| 34 | 34 | * Public static variable to hold the current plugin version. |
| 35 | 35 | * |
| 36 | 36 | * @var string Current plugin version. |
| 37 | 37 | */ |
| 38 | - public static $version = '6.2'; // NOSONAR. | |
| 38 | + public static $version = '6.2.1'; // NOSONAR. | |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Private static variable to hold the single instance of the class. |
| 42 | 42 | * |
| @@ -63,9 +63,9 @@ | ||
| 63 | 63 | * Private variable to hold the check update version number. |
| 64 | 64 | * |
| 65 | 65 | * @var string The plugin current update version. |
| 66 | 66 | */ |
| 67 | - private $check_ver_update = '0.0.5'; | |
| 67 | + private $check_ver_update = '0.0.8'; | |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Private variable to hold the plugin slug (mainwp/mainwp.php) |
| 71 | 71 | * |
| @@ -239,8 +239,9 @@ | ||
| 239 | 239 | MainWP_Bulk_Post::get_instance(); |
| 240 | 240 | |
| 241 | 241 | add_action( 'admin_init', array( &$this, 'admin_init' ), 20 ); |
| 242 | 242 | add_action( 'admin_init', array( $this, 'hook_admin_update_check' ) ); |
| 243 | + add_action( 'admin_init', array( $this, 'admin_init_update' ) ); | |
| 243 | 244 | add_action( 'after_setup_theme', array( &$this, 'after_setup_theme' ) ); |
| 244 | 245 | |
| 245 | 246 | add_action( 'init', array( &$this, 'parse_init' ) ); |
| 246 | 247 | add_action( 'init', array( &$this, 'init_jobs' ) ); |
| @@ -401,8 +402,9 @@ | ||
| 401 | 402 | 'mainwp_show_language_updates', |
| 402 | 403 | 'mainwp_logger_check_daily', |
| 403 | 404 | 'mainwp_site_actions_notification_enable', |
| 404 | 405 | 'mainwp_update_check_version', |
| 406 | + 'mainwp_admin_init_update_data', | |
| 405 | 407 | 'mainwp_setting_demo_mode_enabled', |
| 406 | 408 | 'mainwp_log_wait_lasttime', |
| 407 | 409 | 'mainwp_cron_license_deactivated_alert_lasttime', |
| 408 | 410 | 'mainwp_updatescheck_is_running', |
| @@ -791,19 +793,15 @@ | ||
| 791 | 793 | * Method hook_admin_update_check() |
| 792 | 794 | */ |
| 793 | 795 | public function hook_admin_update_check() { |
| 794 | 796 | $current_ver = $this->check_ver_update; |
| 795 | - $saved_ver = get_option( 'mainwp_update_check_version', false ); | |
| 797 | + $saved_ver = get_option( 'mainwp_update_check_version', '' ); | |
| 796 | 798 | |
| 797 | - if ( false === $saved_ver ) { | |
| 798 | - return; | |
| 799 | - } | |
| 800 | - | |
| 801 | 799 | if ( version_compare( $saved_ver, $current_ver, '=' ) ) { |
| 802 | 800 | return; |
| 803 | 801 | } |
| 804 | 802 | |
| 805 | - if ( version_compare( $saved_ver, '0.0.4', '<' ) ) { | |
| 803 | + if ( ! empty( $saved_ver ) && version_compare( $saved_ver, '0.0.4', '<' ) ) { | |
| 806 | 804 | $sched = wp_next_scheduled( 'mainwp_cronstats_action' ); |
| 807 | 805 | if ( ! empty( $sched ) ) { |
| 808 | 806 | wp_unschedule_event( $sched, 'mainwp_cronstats_action' ); |
| 809 | 807 | } |
| @@ -810,9 +808,9 @@ | ||
| 810 | 808 | global $wpdb; |
| 811 | 809 | $wpdb->query( 'DELETE FROM ' . $wpdb->usermeta . ' WHERE meta_key = "mainwp_widgets_sorted_toplevel_page_mainwp_tab" OR meta_key="mainwp_settings_show_widgets"' );//phpcs:ignore -- safe. |
| 812 | 810 | } |
| 813 | 811 | |
| 814 | - if ( version_compare( $saved_ver, '0.0.5', '<' ) ) { | |
| 812 | + if ( ! empty( $saved_ver ) && version_compare( $saved_ver, '0.0.5', '<' ) ) { | |
| 815 | 813 | $all_ext = MainWP_Extensions_View::get_available_extensions(); |
| 816 | 814 | foreach ( $all_ext as $slug => $info ) { |
| 817 | 815 | $data = MainWP_Api_Manager::instance()->get_activation_info( $slug ); |
| 818 | 816 | if ( is_array( $data ) && isset( $data['api_key'] ) ) { |
| @@ -823,12 +821,73 @@ | ||
| 823 | 821 | } |
| 824 | 822 | update_option( 'mainwp_extensions_all_activation_cached', '' ); |
| 825 | 823 | } |
| 826 | 824 | |
| 825 | + if ( version_compare( $saved_ver, '0.0.8', '<' ) ) { | |
| 826 | + static::handle_admin_perform_update( 'attempted_repair_primary_monitors' ); // init attempted repair. | |
| 827 | + } | |
| 828 | + | |
| 827 | 829 | MainWP_Utility::update_option( 'mainwp_update_check_version', $current_ver ); |
| 828 | 830 | } |
| 829 | 831 | |
| 832 | + | |
| 830 | 833 | /** |
| 834 | + * Method admin_init_update() | |
| 835 | + */ | |
| 836 | + public function admin_init_update() { | |
| 837 | + static::handle_admin_perform_update(); | |
| 838 | + } | |
| 839 | + | |
| 840 | + | |
| 841 | + /** | |
| 842 | + * Method handle_admin_perform_update() | |
| 843 | + * | |
| 844 | + * @param string $action Init action. | |
| 845 | + */ | |
| 846 | + public function handle_admin_perform_update( $action = '' ) { | |
| 847 | + | |
| 848 | + $update_actions = get_option( 'mainwp_admin_init_update_data' ); | |
| 849 | + | |
| 850 | + /** | |
| 851 | + * Filters the update actions. | |
| 852 | + * | |
| 853 | + * @param array $update_actions The available update actions. | |
| 854 | + * @param string $action The current update action. | |
| 855 | + * | |
| 856 | + * @since 6.2.1 | |
| 857 | + * | |
| 858 | + * @return array The filtered update actions. | |
| 859 | + */ | |
| 860 | + $update_actions = apply_filters( 'mainwp_admin_init_update_data', $update_actions, $action ); | |
| 861 | + | |
| 862 | + if ( ! empty( $action ) ) { | |
| 863 | + if ( ! is_array( $update_actions ) ) { | |
| 864 | + $update_actions = array(); | |
| 865 | + } | |
| 866 | + if ( 'attempted_repair_primary_monitors' === $action ) { | |
| 867 | + $update_actions['attempted_repair_primary_monitors'] = 0; | |
| 868 | + } | |
| 869 | + } | |
| 870 | + | |
| 871 | + if ( is_array( $update_actions ) ) { | |
| 872 | + $update = false; | |
| 873 | + if ( isset( $update_actions['attempted_repair_primary_monitors'] ) ) { | |
| 874 | + $result = MainWP_DB_Uptime_Monitoring::instance()->repair_missing_primary_monitors( $update_actions['attempted_repair_primary_monitors'] ); | |
| 875 | + if ( is_array( $result ) && ! empty( $result['attempted'] ) ) { | |
| 876 | + $update_actions['attempted_repair_primary_monitors'] = $result['attempted']; | |
| 877 | + } else { | |
| 878 | + unset( $update_actions['attempted_repair_primary_monitors'] ); | |
| 879 | + } | |
| 880 | + $update = true; | |
| 881 | + } | |
| 882 | + | |
| 883 | + if ( $update ) { | |
| 884 | + MainWP_Utility::update_option( 'mainwp_admin_init_update_data', $update_actions ); | |
| 885 | + } | |
| 886 | + } | |
| 887 | + } | |
| 888 | + | |
| 889 | + /** | |
| 831 | 890 | * Method admin_init() |
| 832 | 891 | * |
| 833 | 892 | * Do nothing if current user is not an Admin else display the page. |
| 834 | 893 | * |
| @@ -972,8 +1031,9 @@ | ||
| 972 | 1031 | remove_action( 'admin_notices', 'update_nag', 3 ); |
| 973 | 1032 | } |
| 974 | 1033 | } |
| 975 | 1034 | |
| 1035 | + | |
| 976 | 1036 | /** |
| 977 | 1037 | * Method hook_wp_shutdown() |
| 978 | 1038 | */ |
| 979 | 1039 | public function hook_wp_shutdown() { |
| @@ -1268,9 +1328,9 @@ | ||
| 1268 | 1328 | * |
| 1269 | 1329 | * @return array<string, array<int, mixed>> Command palette configuration. |
| 1270 | 1330 | */ |
| 1271 | 1331 | private function get_command_palette_data() { |
| 1272 | - $registered_pages = $this->get_command_palette_registered_pages(); | |
| 1332 | + $registered_pages = $this->get_command_palette_registered_pages(); | |
| 1273 | 1333 | $registered_page_urls = array(); |
| 1274 | 1334 | |
| 1275 | 1335 | foreach ( $registered_pages as $slug => $page_data ) { |
| 1276 | 1336 | $registered_page_urls[ $slug ] = $page_data['url']; |