Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Support Customize Menus #55

Merged
merged 24 commits into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bef6bc6
Fix menu locations bug
miina Jun 14, 2016
bfe83dc
Add menu filters. Not complete.
miina Jun 15, 2016
3b033d2
Fix phpcs issues
miina Jun 15, 2016
78affd1
Add isset check.
miina Jun 15, 2016
bf9938b
Fix the issue of negative ID proccesing by overriding the default pro…
miina Jun 16, 2016
9f0b918
Merge branch 'develop' into bugfix/saving-menus-issue_2
valendesigns Jun 28, 2016
4c73e3d
Rework compatiblity with nav menus
valendesigns Jun 29, 2016
390083c
Fix phpcs issues
valendesigns Jun 29, 2016
7d619f1
Fix tests
valendesigns Jun 29, 2016
726e194
Merge branch 'bugfix/saving-menus-issue_2' of https://github.com/xwp/…
valendesigns Jun 29, 2016
8ae0764
Ensure items are added to existing menus
valendesigns Jun 29, 2016
44d8d4a
Add some tests. Not complete.
miina Jun 29, 2016
b7176d3
Add more test coverage. Some still missing.
miina Jun 29, 2016
3488780
Add test coverage. Test for Customize_Snapshot_Nav_Menu_Section missing.
miina Jun 29, 2016
6393ddd
Unit tests for menu changes.
miina Jun 30, 2016
924c872
Remove nav menu code in favor of re-using methods in WP_Customize_Nav…
westonruter Jul 5, 2016
19bbcfa
Fix test_create_post_type for 4.6-beta
westonruter Jul 5, 2016
e42ac1a
Rename MENU_ID to NAV_MENU_ITEM_ID
westonruter Jul 5, 2016
2617a10
Remove now unused Customize_Snapshot_Nav_Menu_Section
westonruter Jul 5, 2016
310b365
Merge branch 'develop' of https://github.com/xwp/wp-customize-snapsho…
westonruter Jul 5, 2016
22504bd
Merge branch 'bugfix/saving-menus-issue_2' into bugfix/saving-menus-i…
westonruter Jul 5, 2016
bce3453
Preview nav menu settings early so that the sections and controls for…
westonruter Jul 6, 2016
adca567
Remove test setup code that is not used
westonruter Jul 6, 2016
d5e0bbc
Merge pull request #56 from xwp/bugfix/saving-menus-issue_3
westonruter Jul 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions php/class-customize-snapshot-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,46 @@ public function __construct( Plugin $plugin ) {
}
}

/*
* Add WP_Customize_Nav_Menu component hooks which were short-circuited in 4.5 (r36611 for #35895).
* See https://core.trac.wordpress.org/ticket/35895
*/
if ( isset( $this->customize_manager->nav_menus ) && ! current_user_can( 'edit_theme_options' ) ) {
$hooks = array(
'customize_register' => array(
'callback' => array( $this->customize_manager->nav_menus, 'customize_register' ),
'priority' => 11,
),
'customize_dynamic_setting_args' => array(
'callback' => array( $this->customize_manager->nav_menus, 'filter_dynamic_setting_args' ),
'priority' => 10,
),
'customize_dynamic_setting_class' => array(
'callback' => array( $this->customize_manager->nav_menus, 'filter_dynamic_setting_class' ),
'priority' => 10,
),
'wp_nav_menu_args' => array(
'callback' => array( $this->customize_manager->nav_menus, 'filter_wp_nav_menu_args' ),
'priority' => 1000,
),
'wp_nav_menu' => array(
'callback' => array( $this->customize_manager->nav_menus, 'filter_wp_nav_menu' ),
'priority' => 10,
),
);
foreach ( $hooks as $hook_name => $hook_args ) {
// Note that add_action()/has_action() are just aliases for add_filter()/has_filter().
if ( ! has_filter( $hook_name, $hook_args['callback'] ) ) {
add_filter( $hook_name, $hook_args['callback'], $hook_args['priority'], PHP_INT_MAX );
}
}
}

// Preview a Snapshot.
add_action( 'after_setup_theme', array( $this, 'set_post_values' ), 1 );
if ( isset( $this->customize_manager->nav_menus ) ) {
add_action( 'customize_register', array( $this, 'preview_early_nav_menus_in_customizer' ), 9 );
}
add_action( 'wp_loaded', array( $this, 'preview' ) );

/*
Expand Down Expand Up @@ -917,4 +955,33 @@ public function preview() {
}
}
}

/**
* Preview nav menu settings early so that the sections and controls for snapshot values will be added properly.
*
* This must happen at `customize_register` priority prior to 11 which is when `WP_Customize_Nav_Menus::customize_register()` runs.
* This is only relevant when accessing the Customizer app (customize.php), as this is where sections/controls matter.
*
* @see \WP_Customize_Nav_Menus::customize_register()
*/
public function preview_early_nav_menus_in_customizer() {
if ( ! is_admin() ) {
return;
}

$this->customize_manager->add_dynamic_settings( array_keys( $this->snapshot()->data() ) );
foreach ( $this->snapshot->settings() as $setting ) {
$is_nav_menu_setting = (
$setting instanceof \WP_Customize_Nav_Menu_Setting
||
$setting instanceof \WP_Customize_Nav_Menu_Item_Setting
||
preg_match( '/^nav_menu_locations\[/', $setting->id )
);
if ( $is_nav_menu_setting ) {
$setting->preview();
$setting->dirty = true;
}
}
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Allow Customizer states to be drafted, and previewed with a private URL.

**Contributors:** [westonruter](https://profiles.wordpress.org/westonruter), [valendesigns](https://profiles.wordpress.org/valendesigns), [xwp](https://profiles.wordpress.org/xwp), [newscorpau](https://profiles.wordpress.org/newscorpau)
**Tags:** [customizer](https://wordpress.org/plugins/tags/customizer), [customize](https://wordpress.org/plugins/tags/customize), [snapshots](https://wordpress.org/plugins/tags/snapshots)
**Requires at least:** 4.5
**Requires at least:** 4.6-beta2
**Tested up to:** trunk
**Stable tag:** 0.4.0
**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)

[![Build Status](https://travis-ci.org/xwp/wp-customize-snapshots.svg?branch=master)](https://travis-ci.org/xwp/wp-customize-snapshots) [![Coverage Status](https://coveralls.io/repos/xwp/wp-customize-snapshots/badge.svg?branch=master)](https://coveralls.io/github/xwp/wp-customize-snapshots) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com) [![devDependency Status](https://david-dm.org/xwp/wp-customize-snapshots/dev-status.svg)](https://david-dm.org/xwp/wp-customize-snapshots#info=devDependencies)
[![Build Status](https://travis-ci.org/xwp/wp-customize-snapshots.svg?branch=master)](https://travis-ci.org/xwp/wp-customize-snapshots) [![Coverage Status](https://coveralls.io/repos/xwp/wp-customize-snapshots/badge.svg?branch=master)](https://coveralls.io/github/xwp/wp-customize-snapshots) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com) [![devDependency Status](https://david-dm.org/xwp/wp-customize-snapshots/dev-status.svg)](https://david-dm.org/xwp/wp-customize-snapshots#info=devDependencies)

## Description ##

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=== Customize Snapshots ===
Contributors: westonruter, valendesigns, xwp, newscorpau
Requires at least: 4.5
Requires at least: 4.6-beta2
Tested up to: trunk
Stable tag: 0.4.0
License: GPLv2 or later
Expand Down
6 changes: 3 additions & 3 deletions tests/php/test-class-customize-snapshot-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ function test_clean_current_url() {
* @see Customize_Snapshot_Manager::create_post_type()
*/
function test_create_post_type() {
$pobj = get_post_type_object( Customize_Snapshot_Manager::POST_TYPE );
$this->assertNotNull( $pobj );
$this->assertEquals( Customize_Snapshot_Manager::POST_TYPE, $pobj->name );
$post_type_object = get_post_type_object( Customize_Snapshot_Manager::POST_TYPE );
$this->assertNotNull( $post_type_object );
$this->assertEquals( Customize_Snapshot_Manager::POST_TYPE, $post_type_object->name );

// Test some defaults.
$this->assertFalse( is_post_type_hierarchical( Customize_Snapshot_Manager::POST_TYPE ) );
Expand Down