[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> site-editor.php (source)

   1  <?php
   2  /**
   3   * Site Editor administration screen.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  global $editor_styles;
  10  
  11  /** WordPress Administration Bootstrap */
  12  require_once  __DIR__ . '/admin.php';
  13  
  14  if ( ! current_user_can( 'edit_theme_options' ) ) {
  15      wp_die(
  16          '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  17          '<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
  18          403
  19      );
  20  }
  21  
  22  $is_template_part        = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] );
  23  $is_template_part_path   = isset( $_GET['path'] ) && 'wp_template_partall' === sanitize_key( $_GET['path'] );
  24  $is_template_part_editor = $is_template_part || $is_template_part_path;
  25  $is_patterns             = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] );
  26  $is_patterns_path        = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] );
  27  $is_patterns_editor      = $is_patterns || $is_patterns_path;
  28  
  29  if ( ! wp_is_block_theme() ) {
  30      if ( ! current_theme_supports( 'block-template-parts' ) && $is_template_part_editor ) {
  31          wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
  32      } elseif ( ! $is_patterns_editor && ! $is_template_part_editor ) {
  33          wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
  34      }
  35  }
  36  
  37  // Used in the HTML title tag.
  38  $title       = _x( 'Editor', 'site editor title tag' );
  39  $parent_file = 'themes.php';
  40  
  41  // Flag that we're loading the block editor.
  42  $current_screen = get_current_screen();
  43  $current_screen->is_block_editor( true );
  44  
  45  // Default to is-fullscreen-mode to avoid jumps in the UI.
  46  add_filter(
  47      'admin_body_class',
  48      static function ( $classes ) {
  49          return "$classes is-fullscreen-mode";
  50      }
  51  );
  52  
  53  $indexed_template_types = array();
  54  foreach ( get_default_block_template_types() as $slug => $template_type ) {
  55      $template_type['slug']    = (string) $slug;
  56      $indexed_template_types[] = $template_type;
  57  }
  58  
  59  $block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
  60  $custom_settings      = array(
  61      'siteUrl'                   => site_url(),
  62      'postsPerPage'              => get_option( 'posts_per_page' ),
  63      'styles'                    => get_block_editor_theme_styles(),
  64      'defaultTemplateTypes'      => $indexed_template_types,
  65      'defaultTemplatePartAreas'  => get_allowed_block_template_part_areas(),
  66      'supportsLayout'            => wp_theme_has_theme_json(),
  67      'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ),
  68  );
  69  
  70  // Add additional back-compat patterns registered by `current_screen` et al.
  71  $custom_settings['__experimentalAdditionalBlockPatterns']          = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true );
  72  $custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true );
  73  
  74  $editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context );
  75  
  76  if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) {
  77      $post_type = get_post_type_object( $_GET['postType'] );
  78      if ( ! $post_type ) {
  79          wp_die( __( 'Invalid post type.' ) );
  80      }
  81  }
  82  
  83  $active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
  84  $active_theme            = get_stylesheet();
  85  
  86  $navigation_rest_route = rest_get_route_for_post_type_items(
  87      'wp_navigation'
  88  );
  89  
  90  $preload_paths = array(
  91      array( '/wp/v2/media', 'OPTIONS' ),
  92      '/wp/v2/types?context=view',
  93      '/wp/v2/types/wp_template?context=edit',
  94      '/wp/v2/types/wp_template-part?context=edit',
  95      '/wp/v2/templates?context=edit&per_page=-1',
  96      '/wp/v2/template-parts?context=edit&per_page=-1',
  97      '/wp/v2/themes?context=edit&status=active',
  98      '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit',
  99      '/wp/v2/global-styles/' . $active_global_styles_id,
 100      '/wp/v2/global-styles/themes/' . $active_theme,
 101      array( $navigation_rest_route, 'OPTIONS' ),
 102      array(
 103          add_query_arg(
 104              array(
 105                  'context'   => 'edit',
 106                  'per_page'  => 100,
 107                  'order'     => 'desc',
 108                  'orderby'   => 'date',
 109                  // array indices are required to avoid query being encoded and not matching in cache.
 110                  'status[0]' => 'publish',
 111                  'status[1]' => 'draft',
 112              ),
 113              $navigation_rest_route
 114          ),
 115          'GET',
 116      ),
 117  );
 118  
 119  block_editor_rest_api_preload( $preload_paths, $block_editor_context );
 120  
 121  wp_add_inline_script(
 122      'wp-edit-site',
 123      sprintf(
 124          'wp.domReady( function() {
 125              wp.editSite.initializeEditor( "site-editor", %s );
 126          } );',
 127          wp_json_encode( $editor_settings )
 128      )
 129  );
 130  
 131  // Preload server-registered block schemas.
 132  wp_add_inline_script(
 133      'wp-blocks',
 134      'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
 135  );
 136  
 137  wp_add_inline_script(
 138      'wp-blocks',
 139      sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( isset( $editor_settings['blockCategories'] ) ? $editor_settings['blockCategories'] : array() ) ),
 140      'after'
 141  );
 142  
 143  wp_enqueue_script( 'wp-edit-site' );
 144  wp_enqueue_script( 'wp-format-library' );
 145  wp_enqueue_style( 'wp-edit-site' );
 146  wp_enqueue_style( 'wp-format-library' );
 147  wp_enqueue_media();
 148  
 149  if (
 150      current_theme_supports( 'wp-block-styles' ) &&
 151      ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 )
 152  ) {
 153      wp_enqueue_style( 'wp-block-library-theme' );
 154  }
 155  
 156  /** This action is documented in wp-admin/edit-form-blocks.php */
 157  do_action( 'enqueue_block_editor_assets' );
 158  
 159  require_once  ABSPATH . 'wp-admin/admin-header.php';
 160  ?>
 161  
 162  <div class="edit-site" id="site-editor">
 163      <?php // JavaScript is disabled. ?>
 164      <div class="wrap hide-if-js site-editor-no-js">
 165          <h1 class="wp-heading-inline"><?php _e( 'Edit site' ); ?></h1>
 166          <?php
 167          /**
 168           * Filters the message displayed in the site editor interface when JavaScript is
 169           * not enabled in the browser.
 170           *
 171           * @since 6.3.0
 172           *
 173           * @param string  $message The message being displayed.
 174           * @param WP_Post $post    The post being edited.
 175           */
 176          $message = apply_filters( 'site_editor_no_javascript_message', __( 'The site editor requires JavaScript. Please enable JavaScript in your browser settings.' ), $post );
 177          wp_admin_notice(
 178              $message,
 179              array(
 180                  'type'               => 'error',
 181                  'additional_classes' => array( 'hide-if-js' ),
 182              )
 183          );
 184          ?>
 185      </div>
 186  </div>
 187  
 188  <?php
 189  
 190  require_once  ABSPATH . 'wp-admin/admin-footer.php';


Generated : Fri Apr 26 08:20:02 2024 Cross-referenced by PHPXref