| @@ -89,8 +89,308 @@ | ||
| 89 | 89 | |
| 90 | 90 | add_action( 'mainwp_help_sidebar_content', array( static::get_class_name(), 'mainwp_help_content' ) ); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + /** | |
| 94 | + * Get the registered Settings subpages. | |
| 95 | + * | |
| 96 | + * @return array<int, array<string, mixed>> Settings subpages. | |
| 97 | + */ | |
| 98 | + private static function get_subpages() { | |
| 99 | + if ( isset( static::$subPages ) && is_array( static::$subPages ) ) { | |
| 100 | + return static::$subPages; | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * Settings Subpages | |
| 105 | + * | |
| 106 | + * Filters subpages for the Settings page. | |
| 107 | + * | |
| 108 | + * @since Unknown | |
| 109 | + */ | |
| 110 | + $sub_pages = apply_filters_deprecated( 'mainwp-getsubpages-settings', array( array() ), '4.0.7.2', 'mainwp_getsubpages_settings' ); // @deprecated Use 'mainwp_getsubpages_settings' instead. NOSONAR - not IP. | |
| 111 | + static::$subPages = apply_filters( 'mainwp_getsubpages_settings', $sub_pages ); | |
| 112 | + | |
| 113 | + return is_array( static::$subPages ) ? static::$subPages : array(); | |
| 114 | + } | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * Get the built-in Settings pages used across menu registration and navigation rendering. | |
| 118 | + * | |
| 119 | + * @return array<int, array<string, mixed>> Settings page definitions. | |
| 120 | + */ | |
| 121 | + private static function get_core_pages() { | |
| 122 | + $pages = array( | |
| 123 | + array( | |
| 124 | + 'slug' => 'Settings', | |
| 125 | + 'page_title' => __( 'Settings Global options', 'mainwp' ), | |
| 126 | + 'menu_title' => ' <span id="mainwp-Settings">' . esc_html__( 'Settings', 'mainwp' ) . '</span>', | |
| 127 | + 'nav_title' => esc_html__( 'General Settings', 'mainwp' ), | |
| 128 | + 'callback' => array( static::get_class_name(), 'render' ), | |
| 129 | + 'active_keys' => array( '', 'Settings' ), | |
| 130 | + ), | |
| 131 | + array( | |
| 132 | + 'slug' => 'MainWPTools', | |
| 133 | + 'page_title' => __( 'Tools', 'mainwp' ), | |
| 134 | + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Tools', 'mainwp' ) . '</div>', | |
| 135 | + 'nav_title' => esc_html__( 'Tools', 'mainwp' ), | |
| 136 | + 'callback' => array( static::get_class_name(), 'render_mainwp_tools' ), | |
| 137 | + 'active_keys' => array( 'MainWPTools' ), | |
| 138 | + ), | |
| 139 | + array( | |
| 140 | + 'slug' => 'CostTrackerSettings', | |
| 141 | + 'page_title' => esc_html__( 'Cost Tracker Settings', 'mainwp' ), | |
| 142 | + 'menu_title' => '<div class="mainwp-hidden">' . esc_html__( 'Cost Tracker', 'mainwp' ) . '</div>', | |
| 143 | + 'nav_title' => esc_html__( 'Cost Tracker Settings', 'mainwp' ), | |
| 144 | + 'callback' => array( Cost_Tracker_Settings::get_instance(), 'render_settings_page' ), | |
| 145 | + 'active_keys' => array( 'CostTrackerSettings' ), | |
| 146 | + ), | |
| 147 | + array( | |
| 148 | + 'slug' => 'SettingsAdvanced', | |
| 149 | + 'page_title' => __( 'Advanced Options', 'mainwp' ), | |
| 150 | + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Advanced Options', 'mainwp' ) . '</div>', | |
| 151 | + 'nav_title' => esc_html__( 'Advanced Settings', 'mainwp' ), | |
| 152 | + 'callback' => array( static::get_class_name(), 'render_advanced' ), | |
| 153 | + 'active_keys' => array( 'Advanced', 'SettingsAdvanced' ), | |
| 154 | + ), | |
| 155 | + array( | |
| 156 | + 'slug' => 'MonitoringSettings', | |
| 157 | + 'page_title' => __( 'Monitoring Options', 'mainwp' ), | |
| 158 | + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Monitoring Options', 'mainwp' ) . '</div>', | |
| 159 | + 'nav_title' => esc_html__( 'Monitoring Settings', 'mainwp' ), | |
| 160 | + 'callback' => array( static::get_class_name(), 'render_monitoring' ), | |
| 161 | + 'active_keys' => array( 'Monitoring', 'MonitoringSettings' ), | |
| 162 | + ), | |
| 163 | + array( | |
| 164 | + 'slug' => 'SettingsEmail', | |
| 165 | + 'page_title' => __( 'Email Settings', 'mainwp' ), | |
| 166 | + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Email Settings', 'mainwp' ) . '</div>', | |
| 167 | + 'nav_title' => esc_html__( 'Email Settings', 'mainwp' ), | |
| 168 | + 'callback' => array( static::get_class_name(), 'render_email_settings' ), | |
| 169 | + 'active_keys' => array( 'Emails', 'SettingsEmail' ), | |
| 170 | + ), | |
| 171 | + array( | |
| 172 | + 'slug' => 'PremiumUpdates', | |
| 173 | + 'page_title' => __( 'Premium Updates', 'mainwp' ), | |
| 174 | + 'menu_title' => ' <div class="mainwp-hidden">' . esc_html__( 'Premium Updates', 'mainwp' ) . '</div>', | |
| 175 | + 'nav_title' => esc_html__( 'Premium Updates', 'mainwp' ), | |
| 176 | + 'callback' => array( MainWP_Settings_Premium_Updates::get_class_name(), 'render' ), | |
| 177 | + 'active_keys' => array( 'Premium', 'PremiumUpdates' ), | |
| 178 | + ), | |
| 179 | + ); | |
| 180 | + | |
| 181 | + $visible_pages = array(); | |
| 182 | + | |
| 183 | + foreach ( $pages as $page ) { | |
| 184 | + if ( 'Settings' !== $page['slug'] && MainWP_Menu::is_disable_menu_item( 3, $page['slug'] ) ) { | |
| 185 | + continue; | |
| 186 | + } | |
| 187 | + | |
| 188 | + $visible_pages[] = $page; | |
| 189 | + } | |
| 190 | + | |
| 191 | + return $visible_pages; | |
| 192 | + } | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * Convert a navigation href into a usable URL. | |
| 196 | + * | |
| 197 | + * @param string $href Navigation href. | |
| 198 | + * | |
| 199 | + * @return string Navigation URL. | |
| 200 | + */ | |
| 201 | + private static function get_navigation_item_url( $href ) { | |
| 202 | + $href = trim( wp_specialchars_decode( (string) $href, ENT_QUOTES ) ); | |
| 203 | + | |
| 204 | + if ( empty( $href ) ) { | |
| 205 | + return ''; | |
| 206 | + } | |
| 207 | + | |
| 208 | + if ( preg_match( '/^https?:\/\//i', $href ) ) { | |
| 209 | + return $href; | |
| 210 | + } | |
| 211 | + | |
| 212 | + return admin_url( ltrim( $href, '/' ) ); | |
| 213 | + } | |
| 214 | + | |
| 215 | + /** | |
| 216 | + * Get dynamic Settings subpage items using the legacy left-menu normalization path. | |
| 217 | + * | |
| 218 | + * @return array<int, array<string, mixed>> Settings navigation items. | |
| 219 | + */ | |
| 220 | + private static function get_filtered_subpage_navigation_items() { | |
| 221 | + $menu_items = array(); | |
| 222 | + $core_slugs = array(); | |
| 223 | + | |
| 224 | + foreach ( static::get_navigation_items( 'left_menu_core' ) as $item ) { | |
| 225 | + $core_slugs[ $item['slug'] ] = true; | |
| 226 | + $menu_items[] = array( | |
| 227 | + 'title' => $item['title'], | |
| 228 | + 'parent_key' => 'Settings', | |
| 229 | + 'href' => $item['href'], | |
| 230 | + 'slug' => $item['slug'], | |
| 231 | + 'right' => '', | |
| 232 | + 'before_title' => isset( $item['before_title'] ) ? $item['before_title'] : '', | |
| 233 | + ); | |
| 234 | + } | |
| 235 | + | |
| 236 | + MainWP_Menu::init_subpages_left_menu( static::get_subpages(), $menu_items, 'Settings', 'Settings' ); | |
| 237 | + | |
| 238 | + $items = array(); | |
| 239 | + | |
| 240 | + foreach ( $menu_items as $menu_item ) { | |
| 241 | + if ( empty( $menu_item['slug'] ) || empty( $menu_item['title'] ) || empty( $menu_item['href'] ) ) { | |
| 242 | + continue; | |
| 243 | + } | |
| 244 | + | |
| 245 | + if ( isset( $core_slugs[ $menu_item['slug'] ] ) ) { | |
| 246 | + continue; | |
| 247 | + } | |
| 248 | + | |
| 249 | + if ( isset( $menu_item['item_slug'] ) ) { | |
| 250 | + if ( MainWP_Menu::is_disable_menu_item( 3, $menu_item['item_slug'] ) ) { | |
| 251 | + continue; | |
| 252 | + } | |
| 253 | + } elseif ( MainWP_Menu::is_disable_menu_item( 3, $menu_item['slug'] ) ) { | |
| 254 | + continue; | |
| 255 | + } | |
| 256 | + | |
| 257 | + $active_slug = 0 === strpos( $menu_item['slug'], 'Settings' ) ? substr( $menu_item['slug'], strlen( 'Settings' ) ) : $menu_item['slug']; | |
| 258 | + $item = array( | |
| 259 | + 'slug' => $menu_item['slug'], | |
| 260 | + 'title' => $menu_item['title'], | |
| 261 | + 'href' => $menu_item['href'], | |
| 262 | + 'active_keys' => array( $active_slug, $menu_item['slug'] ), | |
| 263 | + 'menu_hidden' => false, | |
| 264 | + ); | |
| 265 | + | |
| 266 | + if ( ! empty( $menu_item['before_title'] ) ) { | |
| 267 | + $item['before_title'] = $menu_item['before_title']; | |
| 268 | + } | |
| 269 | + | |
| 270 | + if ( isset( $menu_item['item_slug'] ) ) { | |
| 271 | + $item['item_slug'] = $menu_item['item_slug']; | |
| 272 | + } | |
| 273 | + | |
| 274 | + $items[] = $item; | |
| 275 | + } | |
| 276 | + | |
| 277 | + return $items; | |
| 278 | + } | |
| 279 | + | |
| 280 | + /** | |
| 281 | + * Get the Settings navigation items. | |
| 282 | + * | |
| 283 | + * @return array<int, array<string, mixed>> Settings navigation items. | |
| 284 | + */ | |
| 285 | + public static function get_navigation_items( $context = 'default' ) { | |
| 286 | + $core_items = array(); | |
| 287 | + $dynamic_items = array(); | |
| 288 | + $items = array(); | |
| 289 | + | |
| 290 | + foreach ( static::get_core_pages() as $page ) { | |
| 291 | + $core_items[ $page['slug'] ] = array( | |
| 292 | + 'slug' => $page['slug'], | |
| 293 | + 'title' => $page['nav_title'], | |
| 294 | + 'href' => 'admin.php?page=' . $page['slug'], | |
| 295 | + 'active_keys' => $page['active_keys'], | |
| 296 | + 'menu_hidden' => false, | |
| 297 | + ); | |
| 298 | + } | |
| 299 | + | |
| 300 | + if ( 'command_palette' === $context ) { | |
| 301 | + $dynamic_items = static::get_filtered_subpage_navigation_items(); | |
| 302 | + } else { | |
| 303 | + foreach ( static::get_subpages() as $subPage ) { | |
| 304 | + if ( empty( $subPage['slug'] ) || MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) { | |
| 305 | + continue; | |
| 306 | + } | |
| 307 | + | |
| 308 | + $item = array( | |
| 309 | + 'slug' => 'Settings' . $subPage['slug'], | |
| 310 | + 'title' => $subPage['title'], | |
| 311 | + 'href' => ! empty( $subPage['href'] ) ? $subPage['href'] : 'admin.php?page=Settings' . $subPage['slug'], | |
| 312 | + 'active_keys' => array( $subPage['slug'], 'Settings' . $subPage['slug'] ), | |
| 313 | + 'menu_hidden' => ! empty( $subPage['menu_hidden'] ), | |
| 314 | + ); | |
| 315 | + | |
| 316 | + if ( ! empty( $subPage['before_title'] ) ) { | |
| 317 | + $item['before_title'] = $subPage['before_title']; | |
| 318 | + } | |
| 319 | + | |
| 320 | + if ( isset( $subPage['class'] ) ) { | |
| 321 | + $item['class'] = $subPage['class']; | |
| 322 | + } | |
| 323 | + | |
| 324 | + if ( isset( $subPage['item_slug'] ) ) { | |
| 325 | + $item['item_slug'] = $subPage['item_slug']; | |
| 326 | + } | |
| 327 | + | |
| 328 | + $dynamic_items[] = $item; | |
| 329 | + } | |
| 330 | + } | |
| 331 | + | |
| 332 | + $base_order = array( 'Settings', 'SettingsAdvanced', 'MonitoringSettings', 'SettingsEmail', 'PremiumUpdates' ); | |
| 333 | + | |
| 334 | + if ( in_array( $context, array( 'left_menu', 'left_menu_core' ), true ) ) { | |
| 335 | + $base_order[] = 'MainWPTools'; | |
| 336 | + $base_order[] = 'CostTrackerSettings'; | |
| 337 | + } else { | |
| 338 | + $base_order[] = 'CostTrackerSettings'; | |
| 339 | + } | |
| 340 | + | |
| 341 | + foreach ( $base_order as $slug ) { | |
| 342 | + if ( isset( $core_items[ $slug ] ) ) { | |
| 343 | + $items[] = $core_items[ $slug ]; | |
| 344 | + } | |
| 345 | + } | |
| 346 | + | |
| 347 | + if ( 'left_menu_core' !== $context ) { | |
| 348 | + $items = array_merge( $items, $dynamic_items ); | |
| 349 | + } | |
| 350 | + | |
| 351 | + if ( ! in_array( $context, array( 'left_menu', 'left_menu_core' ), true ) && isset( $core_items['MainWPTools'] ) ) { | |
| 352 | + $items[] = $core_items['MainWPTools']; | |
| 353 | + } | |
| 354 | + | |
| 355 | + return $items; | |
| 356 | + } | |
| 357 | + | |
| 358 | + /** | |
| 359 | + * Get the Settings command palette items. | |
| 360 | + * | |
| 361 | + * @return array<int, array<string, mixed>> Command palette item definitions. | |
| 362 | + */ | |
| 363 | + public static function get_command_palette_items() { | |
| 364 | + $items = array(); | |
| 365 | + | |
| 366 | + foreach ( static::get_navigation_items( 'command_palette' ) as $item ) { | |
| 367 | + if ( ! empty( $item['menu_hidden'] ) ) { | |
| 368 | + continue; | |
| 369 | + } | |
| 370 | + | |
| 371 | + $path_title = $item['title']; | |
| 372 | + $path_titles = array( esc_html__( 'Settings', 'mainwp' ), $path_title ); | |
| 373 | + | |
| 374 | + if ( ! empty( $item['before_title'] ) ) { | |
| 375 | + $path_title = trim( wp_strip_all_tags( $item['before_title'] ) . ' ' . $item['title'] ); | |
| 376 | + $path_titles[1] = $path_title; | |
| 377 | + } | |
| 378 | + | |
| 379 | + if ( 'Settings' === $item['slug'] ) { | |
| 380 | + $path_titles[1] = esc_html__( 'General Settings', 'mainwp' ); | |
| 381 | + } | |
| 382 | + | |
| 383 | + $items[] = array( | |
| 384 | + 'slug' => $item['slug'], | |
| 385 | + 'href' => $item['href'], | |
| 386 | + 'path_titles' => $path_titles, | |
| 387 | + ); | |
| 388 | + } | |
| 389 | + | |
| 390 | + return $items; | |
| 391 | + } | |
| 392 | + | |
| 93 | 393 | /** Run the export_sites method that exports the Child Sites .csv file */ |
| 94 | 394 | public static function admin_init() { // phpcs:ignore -- NOSONAR - complex. |
| 95 | 395 | static::export_sites(); |
| 96 | 396 | if ( isset( $_GET['clearActivationData'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'clear_activation_data' ) ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| @@ -144,108 +444,26 @@ | ||
| 144 | 444 | * |
| 145 | 445 | * @uses \MainWP\Dashboard\MainWP_Menu::is_disable_menu_item() |
| 146 | 446 | */ |
| 147 | 447 | public static function init_menu() { |
| 148 | - add_submenu_page( | |
| 149 | - 'mainwp_tab', | |
| 150 | - __( 'Settings Global options', 'mainwp' ), | |
| 151 | - ' <span id="mainwp-Settings">' . esc_html__( 'Settings', 'mainwp' ) . '</span>', | |
| 152 | - 'read', | |
| 153 | - 'Settings', | |
| 154 | - array( | |
| 155 | - static::get_class_name(), | |
| 156 | - 'render', | |
| 157 | - ) | |
| 158 | - ); | |
| 159 | - | |
| 160 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MainWPTools' ) ) { | |
| 448 | + foreach ( static::get_core_pages() as $page ) { | |
| 161 | 449 | add_submenu_page( |
| 162 | 450 | 'mainwp_tab', |
| 163 | - __( 'Tools', 'mainwp' ), | |
| 164 | - ' <div class="mainwp-hidden">' . esc_html__( 'Tools', 'mainwp' ) . '</div>', | |
| 451 | + $page['page_title'], | |
| 452 | + $page['menu_title'], | |
| 165 | 453 | 'read', |
| 166 | - 'MainWPTools', | |
| 167 | - array( | |
| 168 | - static::get_class_name(), | |
| 169 | - 'render_mainwp_tools', | |
| 170 | - ) | |
| 454 | + $page['slug'], | |
| 455 | + $page['callback'] | |
| 171 | 456 | ); |
| 172 | 457 | } |
| 173 | 458 | |
| 174 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'CostTrackerSettings' ) ) { | |
| 175 | - add_submenu_page( | |
| 176 | - 'mainwp_tab', | |
| 177 | - esc_html__( 'Cost Tracker Settings', 'mainwp' ), | |
| 178 | - '<div class="mainwp-hidden">' . esc_html__( 'Cost Tracker', 'mainwp' ) . '</div>', | |
| 179 | - 'read', | |
| 180 | - 'CostTrackerSettings', | |
| 181 | - array( | |
| 182 | - Cost_Tracker_Settings::get_instance(), | |
| 183 | - 'render_settings_page', | |
| 184 | - ) | |
| 185 | - ); | |
| 186 | - } | |
| 459 | + foreach ( static::get_subpages() as $subPage ) { | |
| 460 | + if ( empty( $subPage['slug'] ) || MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) { | |
| 461 | + continue; | |
| 462 | + } | |
| 187 | 463 | |
| 188 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsAdvanced' ) ) { | |
| 189 | - add_submenu_page( | |
| 190 | - 'mainwp_tab', | |
| 191 | - __( 'Advanced Options', 'mainwp' ), | |
| 192 | - ' <div class="mainwp-hidden">' . esc_html__( 'Advanced Options', 'mainwp' ) . '</div>', | |
| 193 | - 'read', | |
| 194 | - 'SettingsAdvanced', | |
| 195 | - array( | |
| 196 | - static::get_class_name(), | |
| 197 | - 'render_advanced', | |
| 198 | - ) | |
| 199 | - ); | |
| 464 | + add_submenu_page( 'mainwp_tab', $subPage['title'], '<div class="mainwp-hidden">' . $subPage['title'] . '</div>', 'read', 'Settings' . $subPage['slug'], $subPage['callback'] ); | |
| 200 | 465 | } |
| 201 | - | |
| 202 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MonitoringSettings' ) ) { | |
| 203 | - add_submenu_page( | |
| 204 | - 'mainwp_tab', | |
| 205 | - __( 'Monitoring Options', 'mainwp' ), | |
| 206 | - ' <div class="mainwp-hidden">' . esc_html__( 'Monitoring Options', 'mainwp' ) . '</div>', | |
| 207 | - 'read', | |
| 208 | - 'MonitoringSettings', | |
| 209 | - array( | |
| 210 | - static::get_class_name(), | |
| 211 | - 'render_monitoring', | |
| 212 | - ) | |
| 213 | - ); | |
| 214 | - } | |
| 215 | - | |
| 216 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsEmail' ) ) { | |
| 217 | - add_submenu_page( | |
| 218 | - 'mainwp_tab', | |
| 219 | - __( 'Email Settings', 'mainwp' ), | |
| 220 | - ' <div class="mainwp-hidden">' . esc_html__( 'Email Settings', 'mainwp' ) . '</div>', | |
| 221 | - 'read', | |
| 222 | - 'SettingsEmail', | |
| 223 | - array( | |
| 224 | - static::get_class_name(), | |
| 225 | - 'render_email_settings', | |
| 226 | - ) | |
| 227 | - ); | |
| 228 | - } | |
| 229 | - | |
| 230 | - /** | |
| 231 | - * Settings Subpages | |
| 232 | - * | |
| 233 | - * Filters subpages for the Settings page. | |
| 234 | - * | |
| 235 | - * @since Unknown | |
| 236 | - */ | |
| 237 | - $sub_pages = apply_filters_deprecated( 'mainwp-getsubpages-settings', array( array() ), '4.0.7.2', 'mainwp_getsubpages_settings' ); // @deprecated Use 'mainwp_getsubpages_settings' instead. NOSONAR - not IP. | |
| 238 | - static::$subPages = apply_filters( 'mainwp_getsubpages_settings', $sub_pages ); | |
| 239 | - | |
| 240 | - if ( isset( static::$subPages ) && is_array( static::$subPages ) ) { | |
| 241 | - foreach ( static::$subPages as $subPage ) { | |
| 242 | - if ( MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) { | |
| 243 | - continue; | |
| 244 | - } | |
| 245 | - add_submenu_page( 'mainwp_tab', $subPage['title'], '<div class="mainwp-hidden">' . $subPage['title'] . '</div>', 'read', 'Settings' . $subPage['slug'], $subPage['callback'] ); | |
| 246 | - } | |
| 247 | - } | |
| 248 | 466 | } |
| 249 | 467 | |
| 250 | 468 | /** |
| 251 | 469 | * Instantiate Settings SubPages Menu. |
| @@ -257,36 +475,11 @@ | ||
| 257 | 475 | <div id="menu-mainwp-Settings" class="mainwp-submenu-wrapper"> |
| 258 | 476 | <div class="wp-submenu sub-open" style=""> |
| 259 | 477 | <div class="mainwp_boxout"> |
| 260 | 478 | <div class="mainwp_boxoutin"></div> |
| 261 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=Settings' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'General Settings', 'mainwp' ); ?></a> | |
| 262 | - <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsAdvanced' ) ) { ?> | |
| 263 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=SettingsAdvanced' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Advanced Settings', 'mainwp' ); ?></a> | |
| 479 | + <?php foreach ( static::get_navigation_items() as $item ) { ?> | |
| 480 | + <a href="<?php echo esc_url( static::get_navigation_item_url( $item['href'] ) ); ?>" class="mainwp-submenu"><?php echo isset( $item['before_title'] ) ? $item['before_title'] . ' ' : ''; // phpcs:ignore WordPress.Security.EscapeOutput ?><?php echo esc_html( $item['title'] ); ?></a> | |
| 264 | 481 | <?php } ?> |
| 265 | - <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MonitoringSettings' ) ) { ?> | |
| 266 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=MonitoringSettings' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Monitoring Settings', 'mainwp' ); ?></a> | |
| 267 | - <?php } ?> | |
| 268 | - <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsEmail' ) ) { ?> | |
| 269 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=SettingsEmail' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Email Settings', 'mainwp' ); ?></a> | |
| 270 | - <?php } ?> | |
| 271 | - <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'CostTrackerSettings' ) ) { ?> | |
| 272 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=CostTrackerSettings' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Cost Tracker Settings', 'mainwp' ); ?></a> | |
| 273 | - <?php } ?> | |
| 274 | - <?php | |
| 275 | - if ( isset( static::$subPages ) && is_array( static::$subPages ) && ! empty( static::$subPages ) ) { | |
| 276 | - foreach ( static::$subPages as $subPage ) { | |
| 277 | - if ( MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) { | |
| 278 | - continue; | |
| 279 | - } | |
| 280 | - ?> | |
| 281 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=Settings' . $subPage['slug'] ) ); ?>" class="mainwp-submenu"><?php echo isset( $subPage['before_title'] ) ? $subPage['before_title'] : ''; // phpcs:ignore WordPress.Security.EscapeOutput ?> <?php echo esc_html( $subPage['title'] ); ?></a> | |
| 282 | - <?php | |
| 283 | - } | |
| 284 | - } | |
| 285 | - ?> | |
| 286 | - <?php if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MainWPTools' ) ) { ?> | |
| 287 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=MainWPTools' ) ); ?>" class="mainwp-submenu"><?php esc_html_e( 'Tools', 'mainwp' ); ?></a> | |
| 288 | - <?php } ?> | |
| 289 | 482 | </div> |
| 290 | 483 | </div> |
| 291 | 484 | </div> |
| 292 | 485 | <?php |
| @@ -314,56 +507,33 @@ | ||
| 314 | 507 | ), |
| 315 | 508 | 0 |
| 316 | 509 | ); |
| 317 | 510 | |
| 318 | - $init_sub_subleftmenu = array( | |
| 319 | - array( | |
| 320 | - 'title' => esc_html__( 'General Settings', 'mainwp' ), | |
| 321 | - 'parent_key' => 'Settings', | |
| 322 | - 'href' => 'admin.php?page=Settings', | |
| 323 | - 'slug' => 'Settings', | |
| 324 | - 'right' => '', | |
| 325 | - ), | |
| 326 | - array( | |
| 327 | - 'title' => esc_html__( 'Advanced Settings', 'mainwp' ), | |
| 328 | - 'parent_key' => 'Settings', | |
| 329 | - 'href' => 'admin.php?page=SettingsAdvanced', | |
| 330 | - 'slug' => 'SettingsAdvanced', | |
| 331 | - 'right' => '', | |
| 332 | - ), | |
| 333 | - array( | |
| 334 | - 'title' => esc_html__( 'Monitoring Settings', 'mainwp' ), | |
| 335 | - 'parent_key' => 'Settings', | |
| 336 | - 'href' => 'admin.php?page=MonitoringSettings', | |
| 337 | - 'slug' => 'MonitoringSettings', | |
| 338 | - 'right' => '', | |
| 339 | - ), | |
| 340 | - array( | |
| 341 | - 'title' => esc_html__( 'Email Settings', 'mainwp' ), | |
| 342 | - 'parent_key' => 'Settings', | |
| 343 | - 'href' => 'admin.php?page=SettingsEmail', | |
| 344 | - 'slug' => 'SettingsEmail', | |
| 345 | - 'right' => '', | |
| 346 | - ), | |
| 347 | - array( | |
| 348 | - 'title' => esc_html__( 'Tools', 'mainwp' ), | |
| 349 | - 'parent_key' => 'Settings', | |
| 350 | - 'href' => 'admin.php?page=MainWPTools', | |
| 351 | - 'slug' => 'MainWPTools', | |
| 352 | - 'right' => '', | |
| 353 | - ), | |
| 354 | - array( | |
| 355 | - 'title' => esc_html__( 'Cost Tracker Settings', 'mainwp' ), | |
| 356 | - 'parent_key' => 'Settings', | |
| 357 | - 'href' => 'admin.php?page=CostTrackerSettings', | |
| 358 | - 'slug' => 'CostTrackerSettings', | |
| 359 | - 'right' => '', | |
| 360 | - ), | |
| 361 | - ); | |
| 511 | + $init_sub_subleftmenu = array(); | |
| 362 | 512 | |
| 513 | + foreach ( static::get_navigation_items( 'left_menu_core' ) as $item ) { | |
| 514 | + $init_sub_subleftmenu[] = array( | |
| 515 | + 'title' => $item['title'], | |
| 516 | + 'parent_key' => 'Settings', | |
| 517 | + 'href' => $item['href'], | |
| 518 | + 'slug' => $item['slug'], | |
| 519 | + 'right' => '', | |
| 520 | + 'before_title' => isset( $item['before_title'] ) ? $item['before_title'] : '', | |
| 521 | + ); | |
| 522 | + } | |
| 523 | + | |
| 524 | + if ( empty( $subPages ) ) { | |
| 525 | + $subPages = static::get_subpages(); | |
| 526 | + } | |
| 527 | + | |
| 363 | 528 | MainWP_Menu::init_subpages_left_menu( $subPages, $init_sub_subleftmenu, 'Settings', 'Settings' ); |
| 529 | + | |
| 364 | 530 | foreach ( $init_sub_subleftmenu as $item ) { |
| 365 | - if ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) { | |
| 531 | + if ( isset( $item['item_slug'] ) ) { | |
| 532 | + if ( MainWP_Menu::is_disable_menu_item( 3, $item['item_slug'] ) ) { | |
| 533 | + continue; | |
| 534 | + } | |
| 535 | + } elseif ( MainWP_Menu::is_disable_menu_item( 3, $item['slug'] ) ) { | |
| 366 | 536 | continue; |
| 367 | 537 | } |
| 368 | 538 | |
| 369 | 539 | MainWP_Menu::add_left_menu( $item, 2 ); |
| @@ -388,72 +558,24 @@ | ||
| 388 | 558 | MainWP_UI::render_top_header( $params ); |
| 389 | 559 | |
| 390 | 560 | $renderItems = array(); |
| 391 | 561 | |
| 392 | - $renderItems[] = array( | |
| 393 | - 'title' => esc_html__( 'General Settings', 'mainwp' ), | |
| 394 | - 'href' => 'admin.php?page=Settings', | |
| 395 | - 'active' => ( '' === $shownPage ) ? true : false, | |
| 396 | - ); | |
| 397 | - | |
| 398 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsAdvanced' ) ) { | |
| 399 | - $renderItems[] = array( | |
| 400 | - 'title' => esc_html__( 'Advanced Settings', 'mainwp' ), | |
| 401 | - 'href' => 'admin.php?page=SettingsAdvanced', | |
| 402 | - 'active' => ( 'Advanced' === $shownPage ) ? true : false, | |
| 562 | + foreach ( static::get_navigation_items() as $item ) { | |
| 563 | + $render_item = array( | |
| 564 | + 'title' => $item['title'], | |
| 565 | + 'href' => $item['href'], | |
| 566 | + 'active' => in_array( $shownPage, $item['active_keys'], true ), | |
| 403 | 567 | ); |
| 404 | - } | |
| 405 | 568 | |
| 406 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MonitoringSettings' ) ) { | |
| 407 | - $renderItems[] = array( | |
| 408 | - 'title' => esc_html__( 'Monitoring Settings', 'mainwp' ), | |
| 409 | - 'href' => 'admin.php?page=MonitoringSettings', | |
| 410 | - 'active' => ( 'Monitoring' === $shownPage ) ? true : false, | |
| 411 | - ); | |
| 412 | - } | |
| 569 | + if ( ! empty( $item['before_title'] ) ) { | |
| 570 | + $render_item['before_title'] = $item['before_title']; | |
| 571 | + } | |
| 413 | 572 | |
| 414 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'SettingsEmail' ) ) { | |
| 415 | - $renderItems[] = array( | |
| 416 | - 'title' => esc_html__( 'Email Settings', 'mainwp' ), | |
| 417 | - 'href' => 'admin.php?page=SettingsEmail', | |
| 418 | - 'active' => ( 'Emails' === $shownPage ) ? true : false, | |
| 419 | - ); | |
| 420 | - } | |
| 421 | - | |
| 422 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'CostTrackerSettings' ) ) { | |
| 423 | - $renderItems[] = array( | |
| 424 | - 'title' => esc_html__( 'Cost Tracker Settings', 'mainwp' ), | |
| 425 | - 'href' => 'admin.php?page=CostTrackerSettings', | |
| 426 | - 'active' => ( 'CostTrackerSettings' === $shownPage ) ? true : false, | |
| 427 | - ); | |
| 428 | - } | |
| 429 | - | |
| 430 | - if ( isset( static::$subPages ) && is_array( static::$subPages ) ) { | |
| 431 | - foreach ( static::$subPages as $subPage ) { | |
| 432 | - if ( MainWP_Menu::is_disable_menu_item( 3, 'Settings' . $subPage['slug'] ) ) { | |
| 433 | - continue; | |
| 434 | - } | |
| 435 | - $item = array(); | |
| 436 | - $item['title'] = $subPage['title']; | |
| 437 | - $item['href'] = 'admin.php?page=Settings' . $subPage['slug']; | |
| 438 | - $item['active'] = ( $subPage['slug'] === $shownPage ) ? true : false; | |
| 439 | - if ( ! empty( $subPage['before_title'] ) ) { | |
| 440 | - $item['before_title'] = $subPage['before_title']; | |
| 441 | - } | |
| 442 | - | |
| 443 | - if ( isset( $subPage['class'] ) ) { | |
| 444 | - $item['class'] = $subPage['class']; | |
| 445 | - } | |
| 446 | - $renderItems[] = $item; | |
| 573 | + if ( isset( $item['class'] ) ) { | |
| 574 | + $render_item['class'] = $item['class']; | |
| 447 | 575 | } |
| 448 | - } | |
| 449 | 576 | |
| 450 | - if ( ! MainWP_Menu::is_disable_menu_item( 3, 'MainWPTools' ) ) { | |
| 451 | - $renderItems[] = array( | |
| 452 | - 'title' => esc_html__( 'Tools', 'mainwp' ), | |
| 453 | - 'href' => 'admin.php?page=MainWPTools', | |
| 454 | - 'active' => ( 'MainWPTools' === $shownPage ) ? true : false, | |
| 455 | - ); | |
| 577 | + $renderItems[] = $render_item; | |
| 456 | 578 | } |
| 457 | 579 | |
| 458 | 580 | MainWP_UI::render_page_navigation( $renderItems, 'nav_mainwp_settings' ); |
| 459 | 581 | } |
| @@ -1471,8 +1593,9 @@ | ||
| 1471 | 1593 | MainWP_Utility::update_option( 'mainwp_wp_cron', $use_wpcron ); |
| 1472 | 1594 | MainWP_Utility::update_option( 'mainwp_warm_cache_pages_ttl', intval( $_POST['mainwp_warm_cache_pages_ttl'] ) ); |
| 1473 | 1595 | |
| 1474 | 1596 | MainWP_Utility::update_option( 'mainwp_optimize', ( ! isset( $_POST['mainwp_optimize'] ) ? 0 : 1 ) ); |
| 1597 | + MainWP_Utility::update_option( 'mainwp_auto_correct_site_url', ( ! isset( $_POST['mainwp_auto_correct_site_url'] ) ? 0 : 1 ) ); | |
| 1475 | 1598 | MainWP_Utility::update_option( 'mainwp_maximum_uptime_monitoring_requests', ! empty( $_POST['mainwp_maximumUptimeMonitoringRequests'] ) ? intval( $_POST['mainwp_maximumUptimeMonitoringRequests'] ) : 10 ); |
| 1476 | 1599 | MainWP_Utility::update_option( 'mainwp_chunksitesnumber', isset( $_POST['mainwp_chunksitesnumber'] ) ? intval( $_POST['mainwp_chunksitesnumber'] ) : 10 ); |
| 1477 | 1600 | MainWP_Utility::update_option( 'mainwp_chunksleepinterval', isset( $_POST['mainwp_chunksleepinterval'] ) ? intval( $_POST['mainwp_chunksleepinterval'] ) : 5 ); |
| 1478 | 1601 | |
| @@ -1744,8 +1867,19 @@ | ||
| 1744 | 1867 | <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will cache updates for faster loading.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left"> |
| 1745 | 1868 | <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_optimize" id="mainwp_optimize" <?php echo 1 === (int) get_option( 'mainwp_optimize', 1 ) ? 'checked="true"' : ''; ?> /><label><?php esc_html_e( 'Default: Enabled', 'mainwp' ); ?></label> |
| 1746 | 1869 | </div> |
| 1747 | 1870 | </div> |
| 1871 | + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="1"> | |
| 1872 | + <label class="six wide column middle aligned"> | |
| 1873 | + <?php | |
| 1874 | + MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_auto_correct_site_url', (int) get_option( 'mainwp_auto_correct_site_url', 1 ) ); | |
| 1875 | + esc_html_e( 'Auto-correct site URLs', 'mainwp' ); | |
| 1876 | + ?> | |
| 1877 | + </label> | |
| 1878 | + <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, your MainWP Dashboard will automatically correct the stored site URL when the child site reports a different address. Only safe changes are applied (www variant and HTTP to HTTPS); the corrected URL is verified before saving, and sites with a locked URL are never changed.', 'mainwp' ); ?>" data-inverted="" data-position="top left"> | |
| 1879 | + <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_auto_correct_site_url" id="mainwp_auto_correct_site_url" <?php echo 1 === (int) get_option( 'mainwp_auto_correct_site_url', 1 ) ? 'checked="true"' : ''; ?> /><label><?php esc_html_e( 'Default: Enabled', 'mainwp' ); ?></label> | |
| 1880 | + </div> | |
| 1881 | + </div> | |
| 1748 | 1882 | <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-miscellaneous" default-indi-value="10"> |
| 1749 | 1883 | <label class="six wide column middle aligned"> |
| 1750 | 1884 | <?php |
| 1751 | 1885 | MainWP_Settings_Indicator::render_not_default_indicator( 'mainwp_warm_cache_pages_ttl', (int) get_option( 'mainwp_warm_cache_pages_ttl', 10 ) ); |
| @@ -1856,8 +1990,9 @@ | ||
| 1856 | 1990 | <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/> |
| 1857 | 1991 | </form> |
| 1858 | 1992 | </div> |
| 1859 | 1993 | </div> |
| 1994 | + <?php static::render_disable_installed_plugins_sync_modal(); ?> | |
| 1860 | 1995 | <script> |
| 1861 | 1996 | jQuery(document).ready(function() { |
| 1862 | 1997 | const maximumRequests = <?php echo ! empty( get_option( 'mainwp_maximumRequests' ) ) ? esc_js( get_option( 'mainwp_maximumRequests' ) ) : 4; ?>; |
| 1863 | 1998 | jQuery('#mainwp_maximumRequests_slider').slider({ |
| @@ -2058,8 +2193,61 @@ | ||
| 2058 | 2193 | ?> |
| 2059 | 2194 | </ul> |
| 2060 | 2195 | </div> |
| 2061 | 2196 | </div> |
| 2197 | + <?php | |
| 2198 | + } | |
| 2199 | + | |
| 2200 | + /** | |
| 2201 | + * Render the Installed plugins sync warning modal. | |
| 2202 | + * | |
| 2203 | + * @since 6.1.3 | |
| 2204 | + * | |
| 2205 | + * @return void | |
| 2206 | + */ | |
| 2207 | + public static function render_disable_installed_plugins_sync_modal() { | |
| 2208 | + ?> | |
| 2209 | + <div class="ui small modal" id="mainwp-disable-installed-plugins-sync-modal"> | |
| 2210 | + <div class="header"><?php esc_html_e( 'Disable Installed Plugins Sync?', 'mainwp' ); ?></div> | |
| 2211 | + <div class="content"> | |
| 2212 | + <div class="ui yellow message"> | |
| 2213 | + <div class="header"><?php esc_html_e( 'MainWP Add-ons may not work as expected', 'mainwp' ); ?></div> | |
| 2214 | + <p><?php esc_html_e( 'Some MainWP Add-ons need the installed plugins data to detect required plugins on your Child Sites. If you disable this option, those Add-ons may not work as expected.', 'mainwp' ); ?></p> | |
| 2215 | + </div> | |
| 2216 | + </div> | |
| 2217 | + <div class="actions"> | |
| 2218 | + <div class="ui basic cancel button"><?php esc_html_e( 'Cancel', 'mainwp' ); ?></div> | |
| 2219 | + <div class="ui green approve button"><?php esc_html_e( 'I understand', 'mainwp' ); ?></div> | |
| 2220 | + </div> | |
| 2221 | + </div> | |
| 2222 | + <script type="text/javascript"> | |
| 2223 | + jQuery( document ).ready( function () { | |
| 2224 | + const installedPluginsCheckbox = jQuery( '#mainwp_select_sync_plugins' ); | |
| 2225 | + const warningModal = jQuery( '#mainwp-disable-installed-plugins-sync-modal' ); | |
| 2226 | + let disableConfirmed = false; | |
| 2227 | + | |
| 2228 | + installedPluginsCheckbox.on( 'change', function () { | |
| 2229 | + if ( installedPluginsCheckbox.is( ':checked' ) ) { | |
| 2230 | + disableConfirmed = false; | |
| 2231 | + return; | |
| 2232 | + } | |
| 2233 | + | |
| 2234 | + if ( disableConfirmed ) { | |
| 2235 | + return; | |
| 2236 | + } | |
| 2237 | + | |
| 2238 | + warningModal.modal( { | |
| 2239 | + closable: false, | |
| 2240 | + onApprove: function () { | |
| 2241 | + disableConfirmed = true; | |
| 2242 | + }, | |
| 2243 | + onDeny: function () { | |
| 2244 | + installedPluginsCheckbox.prop( 'checked', true ).trigger( 'change' ); | |
| 2245 | + } | |
| 2246 | + } ).modal( 'show' ); | |
| 2247 | + } ); | |
| 2248 | + } ); | |
| 2249 | + </script> | |
| 2062 | 2250 | <?php |
| 2063 | 2251 | } |
| 2064 | 2252 | |
| 2065 | 2253 | /** |