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

Commit cb45595

Browse files
authored
Merge pull request #51 from xwp/feature/add-toolbar-link_issue_48
Added a toolbar link to edit post screen view.
2 parents 3653198 + f692f04 commit cb45595

4 files changed

+39
-9
lines changed

.travis.yml

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ env:
1616
- WP_VERSION=trunk WP_MULTISITE=1
1717
- WP_VERSION=latest WP_MULTISITE=1
1818

19-
branches:
20-
only:
21-
- master
22-
2319
install:
2420
- export DEV_LIB_PATH=dev-lib
2521
- if [ ! -e "$DEV_LIB_PATH" ] && [ -L .travis.yml ]; then export DEV_LIB_PATH=$( dirname $( readlink .travis.yml ) ); fi

dev-lib

Submodule dev-lib updated 1 file

php/class-customize-snapshot-manager.php

+34-2
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,44 @@ public function get_snapshot_uuid() {
765765
}
766766

767767
/**
768-
* Replaces the "Customize" link in the Toolbar.
768+
* Toolbar modifications for Customize Snapshot
769769
*
770770
* @param \WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
771771
*/
772772
public function customize_menu( $wp_admin_bar ) {
773+
774+
$this->replace_customize_link( $wp_admin_bar );
775+
$this->add_post_edit_screen_link( $wp_admin_bar );
776+
777+
add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
778+
}
779+
780+
/**
781+
* Adds a "Snapshot in Dashboard" link to the Toolbar when in Snapshot mode.
782+
*
783+
* @param \WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
784+
*/
785+
public function add_post_edit_screen_link( $wp_admin_bar ) {
786+
$snapshot_post = $this->snapshot->post();
787+
if ( ! $snapshot_post ) {
788+
return;
789+
}
790+
791+
$wp_admin_bar->add_node( array(
792+
'parent' => 'customize',
793+
'id' => 'snapshot-view-link',
794+
'title' => __( 'View Snapshot', 'customize-snapshots' ),
795+
'href' => get_edit_post_link( $snapshot_post->ID ),
796+
) );
797+
}
798+
799+
/**
800+
* Replaces the "Customize" link in the Toolbar.
801+
*
802+
* @param \WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
803+
*/
804+
public function replace_customize_link( $wp_admin_bar ) {
805+
773806
// Don't show for users who can't access the customizer or when in the admin.
774807
if ( ! current_user_can( 'customize' ) || is_admin() ) {
775808
return;
@@ -795,7 +828,6 @@ public function customize_menu( $wp_admin_bar ) {
795828
),
796829
)
797830
);
798-
add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
799831
}
800832

801833
/**

tests/php/test-class-customize-snapshot-manager.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,16 @@ function test_clean_current_url() {
158158
}
159159

160160
/**
161+
* Test Customize_Snapshot_Manager::create_post_type().
162+
*
161163
* @see Customize_Snapshot_Manager::create_post_type()
162164
*/
163165
function test_create_post_type() {
164166
$pobj = get_post_type_object( Customize_Snapshot_Manager::POST_TYPE );
165-
$this->assertInstanceOf( 'stdClass', $pobj );
167+
$this->assertNotNull( $pobj );
166168
$this->assertEquals( Customize_Snapshot_Manager::POST_TYPE, $pobj->name );
167169

168-
// Test some defaults
170+
// Test some defaults.
169171
$this->assertFalse( is_post_type_hierarchical( Customize_Snapshot_Manager::POST_TYPE ) );
170172
$this->assertEquals( array(), get_object_taxonomies( Customize_Snapshot_Manager::POST_TYPE ) );
171173
}

0 commit comments

Comments
 (0)