Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation screen: Add opt-in Navigation block rendering #24503

Merged
merged 8 commits into from
Aug 18, 2020
19 changes: 16 additions & 3 deletions lib/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
* `'menu-item-content'` on a menu item. When merged to Core, this functionality
* should exist in `wp_update_nav_menu_item()`.
*
* 2) The `customize_save` ajax action supports setting `'content'` on a nav
* 2) Updating a menu via nav-menus.php supports setting `'menu-item-content'`
* on a menu item. When merged to Core, this functionality should exist in
* `wp_nav_menu_update_menu_items()`.
*
* 3) The `customize_save` ajax action supports setting `'content'` on a nav
* menu item. When merged to Core, this functionality should exist in
* `WP_Customize_Manager::save()`.
*
Expand All @@ -32,8 +36,15 @@
function gutenberg_update_nav_menu_item_content( $menu_id, $menu_item_db_id, $args ) {
global $wp_customize;

// Support setting content in nav-menus.php by grabbing the value from
// $_POST. This belongs in `wp_nav_menu_update_menu_items()`.
if ( isset( $_POST['menu-item-content'][ $menu_item_db_id ] ) ) {
$args['menu-item-content'] = wp_unslash( $_POST['menu-item-content'][ $menu_item_db_id ] );
}

// Support setting content in customize_save admin-ajax.php requests by
// grabbing the unsanitized $_POST values.
// grabbing the unsanitized $_POST values. This belongs in
// `WP_Customize_Manager::save()`.
if ( isset( $wp_customize ) ) {
$values = $wp_customize->unsanitized_post_values();
if ( isset( $values[ "nav_menu_item[$menu_item_db_id]" ]['content'] ) ) {
Expand All @@ -45,6 +56,8 @@ function gutenberg_update_nav_menu_item_content( $menu_id, $menu_item_db_id, $ar
}
}

// Everything else belongs in `wp_update_nav_menu_item()`.

$defaults = array(
'menu-item-content' => '',
);
Expand Down Expand Up @@ -323,7 +336,7 @@ function gutenberg_output_block_menu_item_custom_fields( $item_id, $item ) {
<p class="field-content description description-wide">
<label for="edit-menu-item-content-<?php echo $item_id; ?>">
<?php _e( 'Content', 'gutenberg' ); ?><br />
<textarea readonly><?php echo esc_textarea( trim( $item->content ) ); ?></textarea>
<textarea readonly name="menu-item-content[<?php echo $item_id; ?>]"><?php echo esc_textarea( trim( $item->content ) ); ?></textarea>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing some square brackets in the in the interpolation for the name here:
Screenshot 2020-08-18 at 5 39 26 pm

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. PHP interprets form values with [] as an array.

https://www.php.net/manual/en/reserved.variables.post.php#87650

</label>
</p>
<?php
Expand Down