PluginProbe
Gutenberg / 9.6.2
Gutenberg v9.6.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / full-site-editing.php

full-site-editing.php in Gutenberg 9.6.2, at lib/full-site-editing.php

124 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Full Site Editing Utils
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Returns whether the current theme is an FSE theme or not.
10 *
11 * @return boolean Whether the current theme is an FSE theme or not.
12 */
13 function gutenberg_is_fse_theme() {
14 return is_readable( get_stylesheet_directory() . '/block-templates/index.html' );
15 }
16
17 /**
18 * Show a notice when a Full Site Editing theme is used.
19 */
20 function gutenberg_full_site_editing_notice() {
21 if ( ! gutenberg_is_fse_theme() ) {
22 return;
23 }
24 ?>
25 <div class="notice notice-warning">
26 <p><?php _e( 'You\'re using an experimental Full Site Editing theme. Full Site Editing is an experimental feature and potential API changes are to be expected!', 'gutenberg' ); ?></p>
27 </div>
28 <?php
29 }
30 add_action( 'admin_notices', 'gutenberg_full_site_editing_notice' );
31
32 /**
33 * Removes legacy pages from FSE themes.
34 */
35 function gutenberg_remove_legacy_pages() {
36 if ( ! gutenberg_is_fse_theme() ) {
37 return;
38 }
39
40 global $submenu;
41 if ( isset( $submenu['themes.php'] ) ) {
42 $indexes_to_remove = array();
43 foreach ( $submenu['themes.php'] as $index => $menu_item ) {
44 if (
45 false !== strpos( $menu_item[2], 'customize.php' ) ||
46 false !== strpos( $menu_item[2], 'gutenberg-widgets' )
47 ) {
48 $indexes_to_remove[] = $index;
49 }
50 }
51
52 foreach ( $indexes_to_remove as $index ) {
53 unset( $submenu['themes.php'][ $index ] );
54 }
55 }
56 }
57
58 add_action( 'admin_menu', 'gutenberg_remove_legacy_pages' );
59
60 /**
61 * Removes legacy adminbar items from FSE themes.
62 *
63 * @param WP_Admin_Bar $wp_admin_bar The admin-bar instance.
64 */
65 function gutenberg_adminbar_items( $wp_admin_bar ) {
66
67 // Early exit if not an FSE theme.
68 if ( ! gutenberg_is_fse_theme() ) {
69 return;
70 }
71
72 // Remove customizer link.
73 $wp_admin_bar->remove_node( 'customize' );
74 $wp_admin_bar->remove_node( 'customize-background' );
75 $wp_admin_bar->remove_node( 'customize-header' );
76 $wp_admin_bar->remove_node( 'widgets' );
77
78 // Add site-editor link.
79 if ( ! is_admin() && current_user_can( 'edit_theme_options' ) ) {
80 $wp_admin_bar->add_node(
81 array(
82 'id' => 'site-editor',
83 'title' => __( 'Edit site', 'gutenberg' ),
84 'href' => admin_url( 'admin.php?page=gutenberg-edit-site' ),
85 )
86 );
87 }
88 }
89
90 add_action( 'admin_bar_menu', 'gutenberg_adminbar_items', 50 );
91
92 /**
93 * Activates the 'menu_order' filter and then hooks into 'menu_order'
94 */
95 add_filter( 'custom_menu_order', '__return_true' );
96 add_filter( 'menu_order', 'gutenberg_menu_order' );
97
98 /**
99 * Filters WordPress default menu order
100 *
101 * @param array $menu_order Menu Order.
102 */
103 function gutenberg_menu_order( $menu_order ) {
104 if ( ! gutenberg_is_fse_theme() ) {
105 return $menu_order;
106 }
107
108 $new_positions = array(
109 // Position the site editor before the appearnce menu.
110 'gutenberg-edit-site' => array_search( 'themes.php', $menu_order, true ),
111 );
112
113 // Traverse through the new positions and move
114 // the items if found in the original menu_positions.
115 foreach ( $new_positions as $value => $new_index ) {
116 $current_index = array_search( $value, $menu_order, true );
117 if ( $current_index ) {
118 $out = array_splice( $menu_order, $current_index, 1 );
119 array_splice( $menu_order, $new_index, 0, $out );
120 }
121 }
122 return $menu_order;
123 }
124