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 ); ?> >