[ Index ]

PHP Cross Reference of WordPress

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 $post, $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  if ( ! wp_is_block_theme() ) {
  23      wp_die( __( 'The theme you are currently using is not compatible with Full Site Editing.' ) );
  24  }
  25  
  26  /**
  27   * Do a server-side redirection if missing `postType` and `postId`
  28   * query args when visiting Site Editor.
  29   */
  30  $home_template = _resolve_home_block_template();
  31  if ( $home_template && empty( $_GET['postType'] ) && empty( $_GET['postId'] ) ) {
  32      $redirect_url = add_query_arg(
  33          $home_template,
  34          admin_url( 'site-editor.php' )
  35      );
  36      wp_safe_redirect( $redirect_url );
  37      exit;
  38  }
  39  
  40  // Used in the HTML title tag.
  41  $title       = __( 'Editor (beta)' );
  42  $parent_file = 'themes.php';
  43  
  44  // Flag that we're loading the block editor.
  45  $current_screen = get_current_screen();
  46  $current_screen->is_block_editor( true );
  47  
  48  // Default to is-fullscreen-mode to avoid jumps in the UI.
  49  add_filter(
  50      'admin_body_class',
  51      static function( $classes ) {
  52          return "$classes is-fullscreen-mode";
  53      }
  54  );
  55  
  56  $indexed_template_types = array();
  57  foreach ( get_default_block_template_types() as $slug => $template_type ) {
  58      $template_type['slug']    = (string) $slug;
  59      $indexed_template_types[] = $template_type;
  60  }
  61  
  62  $block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
  63  $custom_settings      = array(
  64      'siteUrl'                  => site_url(),
  65      'postsPerPage'             => get_option( 'posts_per_page' ),
  66      'styles'                   => get_block_editor_theme_styles(),
  67      'defaultTemplateTypes'     => $indexed_template_types,
  68      'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(),
  69      '__unstableHomeTemplate'   => $home_template,
  70  );
  71  $editor_settings      = get_block_editor_settings( $custom_settings, $block_editor_context );
  72  
  73  if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) {
  74      $post_type = get_post_type_object( $_GET['postType'] );
  75      if ( ! $post_type ) {
  76          wp_die( __( 'Invalid post type.' ) );
  77      }
  78  }
  79  
  80  $active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
  81  $active_theme            = wp_get_theme()->get_stylesheet();
  82  $preload_paths           = array(
  83      array( '/wp/v2/media', 'OPTIONS' ),
  84      '/wp/v2/types?context=view',
  85      '/wp/v2/types/wp_template?context=edit',
  86      '/wp/v2/types/wp_template-part?context=edit',
  87      '/wp/v2/templates?context=edit&per_page=-1',
  88      '/wp/v2/template-parts?context=edit&per_page=-1',
  89      '/wp/v2/themes?context=edit&status=active',
  90      '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit',
  91      '/wp/v2/global-styles/' . $active_global_styles_id,
  92      '/wp/v2/global-styles/themes/' . $active_theme,
  93  );
  94  
  95  block_editor_rest_api_preload( $preload_paths, $block_editor_context );
  96  
  97  wp_add_inline_script(
  98      'wp-edit-site',
  99      sprintf(
 100          'wp.domReady( function() {
 101              wp.editSite.initializeEditor( "site-editor", %s );
 102          } );',
 103          wp_json_encode( $editor_settings )
 104      )
 105  );
 106  
 107  // Preload server-registered block schemas.
 108  wp_add_inline_script(
 109      'wp-blocks',
 110      'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
 111  );
 112  
 113  wp_add_inline_script(
 114      'wp-blocks',
 115      sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ),
 116      'after'
 117  );
 118  
 119  wp_enqueue_script( 'wp-edit-site' );
 120  wp_enqueue_script( 'wp-format-library' );
 121  wp_enqueue_style( 'wp-edit-site' );
 122  wp_enqueue_style( 'wp-format-library' );
 123  wp_enqueue_media();
 124  
 125  if (
 126      current_theme_supports( 'wp-block-styles' ) ||
 127      ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 )
 128  ) {
 129      wp_enqueue_style( 'wp-block-library-theme' );
 130  }
 131  
 132  /** This action is documented in wp-admin/edit-form-blocks.php */
 133  do_action( 'enqueue_block_editor_assets' );
 134  
 135  require_once ABSPATH . 'wp-admin/admin-header.php';
 136  ?>
 137  
 138  <div id="site-editor" class="edit-site"></div>
 139  
 140  <?php
 141  
 142  require_once ABSPATH . 'wp-admin/admin-footer.php';


Generated: Sat Apr 27 01:00:02 2024 Cross-referenced by PHPXref 0.7.1