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

Feature / Add edit in customizer buttons #140

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d0c02da
Move customize_url into own function
May 15, 2016
d35ffc6
feature/addeditincustomizerbuttons Initial concept
May 18, 2016
984b7cd
feature/addeditincustomizerbuttons Fix travis build issues
May 18, 2016
dca990b
feature/addeditincustomizerbuttons Fix last travis issue
May 18, 2016
3bb9949
feature/addeditincustomizerbuttons Start refactoring code
May 20, 2016
d18fb24
feature/addeditincustomizerbuttons Check if is defined
May 20, 2016
8011d97
feature/addeditincustomizerbuttons Fix travis issue with comment
May 20, 2016
b54051e
feature/addeditincustomizerbuttons Add to get_customize_url on posts…
May 20, 2016
1ae5186
feature/addeditincustomizerbuttons Restrict button to certain sections
May 20, 2016
ddeb2ff
feature/addeditincustomizerbuttons Check if Post or Page
May 20, 2016
b0e2f20
feature/addeditincustomizerbuttons Remove previewed_post from URL
May 25, 2016
2d54429
Merge branch 'develop' into feature/addeditincustomizerbuttons
May 25, 2016
d39dfd1
feature/addeditincustomizerbuttons Add permalink to get_preview_post_…
May 26, 2016
a335d32
feature/addeditincustomizerbuttons Be more consistant with code
May 26, 2016
e535780
feature/addeditincustomizerbuttons Use get_preview_post_link with pos…
May 26, 2016
9cb8cb6
feature/addeditincustomizerbuttons Add instanceof to get_customize_url
May 26, 2016
f7e53ff
Merge pull request #179 from xwp/release/0.6.1
valendesigns Jun 16, 2016
986c7f4
Ensure that plugin-support and theme-support are included in build
westonruter Jun 18, 2016
d41a4f6
Remove unrecognized Text Domain readme meta
westonruter Jun 18, 2016
e0589bc
Merge pull request #184 from xwp/bugfix/release-0.6.1
westonruter Jun 18, 2016
1ba5017
Fix location of readme change
westonruter Jun 18, 2016
bfdb6c7
Merge pull request #185 from xwp/bugfix/readme-0.6.1
westonruter Jun 18, 2016
04d19b9
Merge master & resolve conflicts
valendesigns Jun 19, 2016
3ab205a
This plugin is not namespaced
valendesigns Jun 19, 2016
f981ad5
Merge branch 'develop' into feature/addeditincustomizerbuttons
valendesigns Jun 19, 2016
3e5b3f9
Remove type hint
valendesigns Jun 19, 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
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = function( grunt ) {
'*.php',
'css/*',
'js/*',
'php/*',
'php/**',
'readme.txt'
],
dest: 'build',
Expand Down
90 changes: 83 additions & 7 deletions php/class-edit-post-preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function __construct( Customize_Posts_Plugin $plugin ) {
add_action( 'customize_controls_init', array( $this, 'remove_static_controls_and_sections' ), 100 );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_customize_scripts' ) );
add_action( 'customize_preview_init', array( $this, 'make_auto_draft_status_previewable' ) );
add_action( 'admin_footer', array( $this, 'add_edit_customizer_button_posts' ) );
add_filter( 'post_row_actions', array( $this, 'add_edit_customizer_to_row_actions' ), 10, 2 );
add_filter( 'page_row_actions', array( $this, 'add_edit_customizer_to_row_actions' ), 10, 2 );
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably loop over all post types that are are eligible for showing in the Customizer instead of hard-coding just two. There is a method for getting all post types and code in the plugin for determining if the post type should show_in_customizer

}

/**
Expand Down Expand Up @@ -126,7 +129,84 @@ public function enqueue_admin_scripts() {
return;
}
wp_enqueue_script( 'edit-post-preview-admin' );
$post = $this->get_previewed_post();

$data = array(
'customize_url' => self::get_customize_url(),
);
wp_scripts()->add_data( 'edit-post-preview-admin', 'data', sprintf( 'var _editPostPreviewAdminExports = %s;', wp_json_encode( $data ) ) );
wp_enqueue_script( 'customize-loader' );
wp_add_inline_script( 'edit-post-preview-admin', 'jQuery( function() { EditPostPreviewAdmin.init(); } );', 'after' );
}

/**
* Add the edit customizer to row actions for Posts/Pages.
*
* @param array $actions Actions.
* @param object $post Post.
* @return array $rebuild_actions
*/
public function add_edit_customizer_to_row_actions( $actions, $post ) {
if ( ! ( $post instanceof WP_Post ) ) {
return false;
}

$post_type_object = get_post_type_object( $post->post_type );

$can_preview = (
(
! empty( $post_type_object->show_in_customizer )
||
in_array( $post->post_type, array( 'post', 'page' ), true )
)
&&
current_user_can( 'edit_post', $post->ID )
);

if ( $can_preview ) {
$actions = array_merge( array( sprintf( '<a href="%1$s">%2$s</a>', esc_url( self::get_customize_url( $post ) ), esc_html__( 'Customize', 'customize-posts' ) ) ), $actions );
}

return $actions;
}

/**
* Add the Edit in Customizer button to the edit post screen.
*/
public function add_edit_customizer_button_posts() {
$post_type_object = get_post_type_object( get_post_type() );

$can_preview = (
! empty( $post_type_object->show_in_customizer )
||
in_array( get_post_type(), array( 'post', 'page' ), true )
);

if ( $can_preview ) {
printf(
'<a id="%1$s" class="%2$s" href="%3$s">%4$s</a>',
esc_html__( 'customize-button', 'customize-posts' ),
esc_html__( 'page-title-action hide-if-no-customize', 'customize-posts' ),
esc_url( self::get_customize_url() ),
esc_html__( 'Edit in Customizer', 'customize-posts' )
);
wp_add_inline_script( 'edit-post-preview-admin', 'jQuery( \'#customize-button\' ).appendTo( \'.wrap h1\' )', 'after' );
}
}

/**
* Get the customize line.
*
* @param array $post Post.
* @return string $customize_url
*/
public function get_customize_url( $post = null ) {
if ( ! ( $post instanceof WP_Post ) ) {
$post = $this->get_previewed_post();
}

if ( ! $post ) {
return false;
}

$customize_url = add_query_arg(
array(
Expand All @@ -137,12 +217,8 @@ public function enqueue_admin_scripts() {
),
wp_customize_url()
);
$data = array(
'customize_url' => $customize_url,
);
wp_scripts()->add_data( 'edit-post-preview-admin', 'data', sprintf( 'var _editPostPreviewAdminExports = %s;', wp_json_encode( $data ) ) );
wp_enqueue_script( 'customize-loader' );
wp_add_inline_script( 'edit-post-preview-admin', 'jQuery( function() { EditPostPreviewAdmin.init(); } );', 'after' );

return $customize_url;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Edit posts and postmeta in the Customizer. Stop editing your posts/postmeta blin
**Tested up to:** 4.6-alpha
**Stable tag:** 0.6.1
**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)
**Text Domain:** customize-posts

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

Expand Down Expand Up @@ -75,6 +74,7 @@ The following are listed in reverse chronological order. The first, more recent
* Add support for focusing on controls for setting properties when those properties are invalid
* Prevent `customized-posts` messages sent via `selective-refresh` from effecting `post-navigation` state
* Improve feature detection for including customize-controls patched for trac-36521
* Included plugin-support and theme-support PHP files that were inadvertantly omitted from the 0.6.0 build.

See full commit log: [`0.6.0...0.6.1`](https://github.com/xwp/wp-customize-posts/compare/0.6.0...0.6.1)

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Tested up to: 4.6-alpha
Stable tag: 0.6.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: customize-posts

Edit posts and postmeta in the Customizer. Stop editing your posts/postmeta blind!

Expand Down Expand Up @@ -73,6 +72,7 @@ The following are listed in reverse chronological order. The first, more recent
* Add support for focusing on controls for setting properties when those properties are invalid
* Prevent `customized-posts` messages sent via `selective-refresh` from effecting `post-navigation` state
* Improve feature detection for including customize-controls patched for trac-36521
* Included plugin-support and theme-support PHP files that were inadvertantly omitted from the 0.6.0 build.

See full commit log: [`0.6.0...0.6.1`](https://github.com/xwp/wp-customize-posts/compare/0.6.0...0.6.1)

Expand Down