is_maintenance_mode_active() ) { wp_dequeue_script( 'wp-color-picker-alpha' ); wp_dequeue_script( 'media-audiovideo' ); } }, 100 ); } /** * Import maintenance mode demo in Background from Remote Address. * * @return void */ public function dnxte_import_mm_demo_from_remote() { if ( get_option( self::IMPORTED_FLAG_OPTION ) ) { return; } $files = array( '1', '2', '3', '4', '5', '6' ); foreach ( $files as $file ) { $remote_url = sprintf( 'https://raw.githubusercontent.com/anisurz7/maintenance-mode-demos/main/Demo-%s.json', rawurlencode( $file ) ); $response = wp_remote_get( $remote_url, array( 'timeout' => 15, 'headers' => array( 'Accept' => 'application/json', ), ) ); if ( is_wp_error( $response ) ) { wp_die( esc_html__( 'Failed to fetch remote JSON: ', 'your-text-domain' ) . esc_html( $response->get_error_message() ) ); } $body = wp_remote_retrieve_body( $response ); if ( empty( $body ) ) { wp_die( esc_html__( 'Empty response from remote file: Demo-', 'your-text-domain' ) . esc_html( $file ) . '.json' ); } $json_data = json_decode( $body, true ); if ( json_last_error() !== JSON_ERROR_NONE || ! isset( $json_data['data'] ) || ! is_array( $json_data['data'] ) ) { wp_die( esc_html__( 'Invalid JSON format in Demo-', 'your-text-domain' ) . esc_html( $file ) . '.json' ); } foreach ( $json_data['data'] as $post_data ) { $new_post = array( 'post_title' => sanitize_text_field( $post_data['post_title'] ?? '' ), 'post_content' => wp_kses_post( $post_data['post_content'] ?? '' ), 'post_status' => 'publish', 'post_type' => 'et_pb_layout', 'meta_input' => $this->sanitize_post_meta( $post_data['post_meta'] ?? array() ), ); $post_id = wp_insert_post( wp_slash( $new_post ) ); // Prevent unescaped data // if ( ! is_wp_error( $post_id ) && $post_id ) { // error_log( 'Imported layout: ' . $new_post['post_title'] ); // } } } // Mark as imported update_option( self::IMPORTED_FLAG_OPTION, 1 ); } /** * Sanitize post meta data. * * @param array $meta The post meta data. * @return array The sanitized post meta data. */ private function sanitize_post_meta( array $meta ): array { $clean = array(); foreach ( $meta as $key => $value ) { if ( is_array( $value ) ) { $clean[ $key ] = wp_json_encode( $value ); } else { $clean[ $key ] = $value; } } return $clean; } /** * Determine if maintenance mode extension is active. * * @since 1.0.0 * @return bool Whether maintenance mode is active. */ public function is_maintenance_mode_active() { $inactive_extensions = get_option( 'dnxte_inactive_extensions' ); return is_array( $inactive_extensions ) ? ! in_array( 'dnxte-maintenance-mode', $inactive_extensions, true ) : true; } /** * Show maintenance page to non-admin users if enabled. * * @since 1.0.0 * @return void */ public function check_for_maintenance_mode() { if ( ! $this->is_maintenance_mode_active() ) { return; } if ( current_user_can( 'manage_options' ) ) { return; } $dnext_mm_options = get_option( self::OPTION_KEY, array() ); $dnext_mm_type = isset( $dnext_mm_options['dnext_mm_type'] ) ? trim( sanitize_text_field( $dnext_mm_options['dnext_mm_type'] ) ) : 'page'; $maintenance_page_id = isset( $dnext_mm_options['dnext_mm_page'] ) ? (int) $dnext_mm_options['dnext_mm_page'] : 0; $maintenance_template = isset( $dnext_mm_options['dnext_mm_template'] ) ? trim( sanitize_text_field( $dnext_mm_options['dnext_mm_template'] ) ) : 'demo-1'; $header_hide = isset( $dnext_mm_options['dnext_mm_header'] ) && filter_var( sanitize_key( $dnext_mm_options['dnext_mm_header'] ), FILTER_VALIDATE_BOOLEAN ); $footer_hide = isset( $dnext_mm_options['dnext_mm_footer'] ) && filter_var( sanitize_key( $dnext_mm_options['dnext_mm_footer'] ), FILTER_VALIDATE_BOOLEAN ); $full_height = isset( $dnext_mm_options['dnext_mm_full_height'] ) && filter_var( sanitize_key( $dnext_mm_options['dnext_mm_full_height'] ), FILTER_VALIDATE_BOOLEAN ); $template_fallback = get_template_directory() . '/maintenance-template.php'; // Check if a demo template is selected (starting with 'demo-') $is_demo_template = ( strpos( $maintenance_template, 'demo-' ) === 0 ); // Generate CSS classes for full height if enabled $body_class = 'maintenance-mode'; $content_class = 'maintenance-mode-content'; if ( $full_height ) { $body_class .= ' maintenance-full-height'; $content_class .= ' maintenance-full-height-content'; } if ( $header_hide ) { $body_class .= ' maintenance-hidden-header'; } if ( $footer_hide ) { $body_class .= ' maintenance-hidden-footer'; } header( 'Content-Type: text/html; charset=utf-8' ); if ( 'page' === $dnext_mm_type && $maintenance_page_id && get_post_status( $maintenance_page_id ) === 'publish' ) { $mm_post = get_post( $maintenance_page_id ); // Do not override $post global setup_postdata( $mm_post ); add_filter( 'template_include', function ( $template ) { do_action( 'wp_enqueue_scripts' ); do_action( 'wp_head' ); return $template; } ); $title = get_the_title( $maintenance_page_id ); $content = apply_filters( 'the_content', $mm_post->post_content ); ?> > <?php echo esc_html( $title ); ?> >
get_divi_layout_by_slug( $maintenance_template ); if ( $layout ) { if ( function_exists( 'et_builder_add_main_elements' ) ) { et_builder_add_main_elements(); } // Ensure Divi scripts and styles are loaded if ( function_exists( 'et_divi_load_scripts_styles' ) ) { add_action( 'wp_enqueue_scripts', 'et_divi_load_scripts_styles', 20 ); } // Force load Divi Builder styles if ( function_exists( 'et_builder_enqueue_assets_main' ) ) { add_action( 'wp_enqueue_scripts', 'et_builder_enqueue_assets_main' ); } // Get the layout content $title = $layout->post_title; // Use proper method to render the layout $content = apply_filters( 'the_content', $layout->post_content ); // If content is still empty, try direct post content if ( empty( $content ) ) { $content = $layout->post_content; } ?> > <?php echo esc_html( $title ); ?> >
'et_pb_layout', 'posts_per_page' => 1, 'name' => $slug, 'post_status' => 'publish', ); $query = new \WP_Query( $args ); if ( $query->have_posts() ) { return $query->posts[0]; } return false; } /** * Add admin bar notification if maintenance mode is active. * * @since 1.0.0 * @param \WP_Admin_Bar $admin_bar The WP_Admin_Bar instance. * @return void */ public function add_admin_bar_notice( $admin_bar ) { if ( ! $this->is_maintenance_mode_active() || ! current_user_can( 'manage_options' ) ) { return; } $admin_bar->add_node( array( 'id' => 'maintenance-mode-notice', 'title' => '' . esc_html__( 'Maintenance Mode Active', 'divi-essential' ), 'href' => esc_url( admin_url( 'admin.php?page=dnext-maintenance-mode' ) ), 'meta' => array( 'class' => 'maintenance-mode-active', 'title' => esc_attr__( 'Maintenance Mode is currently active. Click to manage.', 'divi-essential' ), ), ) ); } /** * Output custom styles for admin bar node. * * @since 1.0.0 * @return void */ public function output_maintenance_bar_styles() { ?> clear_maintenance_cache(); // Redirect to the maintenance settings page wp_safe_redirect( add_query_arg( 'updated', 'true', admin_url( 'admin.php?page=maintenance-settings' ) ) ); exit; } /** * Clear Divi cache when the maintenance mode option is updated. * * @since 1.0.0 * @return void */ public function clear_cache_after_select_maintenance_mode_page() { if ( isset( $_POST['mm_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_POST['mm_nonce'] ), 'mm_action' ) ) { if ( isset( $_POST['dnext_essential_maintenance_mode_clear_cache'] ) && 1 === $_POST['dnext_essential_maintenance_mode_clear_cache'] ) { // Check user capabilities if ( ! current_user_can( 'manage_options' ) ) { return; } // Clear Divi cache if ( class_exists( 'ET_Core_PageResource' ) && method_exists( 'ET_Core_PageResource', 'remove_static_resources' ) ) { \ET_Core_PageResource::remove_static_resources( 'all', 'all' ); } } } } private function output_full_height_styles() { ?>