Changeset 1381641
- Timestamp:
- 03/30/2016 04:05:33 AM (8 years ago)
- Location:
- customize-posts/trunk
- Files:
-
- 16 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
customize-posts/trunk
-
Property
svn:ignore
set to
deploy.sh readme.md .git .gitignore
-
Property
svn:ignore
set to
-
customize-posts/trunk/css/customize-posts.css
r1367273 r1381641 68 68 69 69 /* @todo Mobile support for rich text editor */ 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 -
customize-posts/trunk/customize-posts.php
r1367273 r1381641 4 4 * Description: Manage posts and postmeta via the Customizer. Works best in conjunction with the <a href="https://wordpress.org/plugins/customize-setting-validation/">Customize Setting Validation</a> plugin. 5 5 * Plugin URI: https://github.com/xwp/wp-customize-posts/ 6 * Version: 0. 3.06 * Version: 0..0 7 7 * Author: XWP 8 8 * Author URI: https://make.xwp.co/ … … 29 29 */ 30 30 31 define( 'CUSTOMIZE_POSTS_VERSION', '0.3.0' ); 32 33 /** 34 * Determine whether the dependencies are satisfied for the plugin. 35 * 36 * @return bool 37 */ 38 function customize_posts_dependencies_satisfied() { 39 $has_required_wp_version = version_compare( str_replace( array( '-src' ), '', $GLOBALS['wp_version'] ), '4.5-beta2', '>=' ); 40 return $has_required_wp_version; 41 } 42 43 /** 44 * Bootstrap. 45 * 46 * This will be part of the WP_Customize_Manager::__construct() or another such class constructor in #coremerge. 47 * 48 * @param array $components Components. 49 * @param WP_Customize_Manager $wp_customize Manager. 50 * @return array Components. 51 */ 52 function customize_posts_filter_customize_loaded_components( $components, $wp_customize ) { 53 define( 'CUSTOMIZE_POSTS_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 54 define( 'CUSTOMIZE_POSTS_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); 55 56 if ( customize_posts_dependencies_satisfied() ) { 57 require_once dirname( __FILE__ ) . '/php/class-wp-customize-posts.php'; 58 $wp_customize->posts = new WP_Customize_Posts( $wp_customize ); 59 } 60 61 return $components; 62 } 63 add_filter( 'customize_loaded_components', 'customize_posts_filter_customize_loaded_components', 100, 2 ); 64 65 /** 66 * Let users who can edit posts also access the Customizer because there is something for them there. 67 * 68 * @todo Promote Customize link in admin menu. 69 * 70 * @see https://core.trac.wordpress.org/ticket/28605 71 * @param array $allcaps All capabilities. 72 * @param array $caps Capabilities. 73 * @param array $args Args. 74 * @return array All capabilities. 75 */ 76 function customize_posts_grant_capability( $allcaps, $caps, $args ) { 77 if ( customize_posts_dependencies_satisfied() && ! empty( $allcaps['edit_posts'] ) && ! empty( $args ) && 'customize' === $args[0] ) { 78 $allcaps = array_merge( $allcaps, array_fill_keys( $caps, true ) ); 79 } 80 return $allcaps; 81 } 82 add_filter( 'user_has_cap', 'customize_posts_grant_capability', 10, 3 ); 83 84 /** 85 * Show error when is not available. 86 */ 87 function customize_posts_show_dependency_error() { 88 if ( customize_posts_dependencies_satisfied() ) { 89 return; 90 } 91 ?> 92 <div class="error"> 93 <p><?php esc_html_e( 'Customize Posts requires WordPress 4.5-beta2 and should have the Customize Setting Validation plugin active.', 'customize-posts' ); ?></p> 94 </div> 95 <?php 96 } 97 add_action( 'admin_notices', 'customize_posts_show_dependency_error' ); 31 require_once dirname( __FILE__ ) . '/php/class-customize-posts-plugin.php'; 32 $GLOBALS['customize_posts_plugin'] = new Customize_Posts_Plugin(); -
customize-posts/trunk/js/customize-post-section.js
r1367273 r1381641 2 2 (function( api, $ ) { 3 3 'use strict'; 4 4 5 5 6 if ( ! api.Posts ) { … … 38 39 39 40 section.postFieldControls = {}; 41 42 43 44 45 46 47 48 40 49 41 50 api.Section.prototype.initialize.call( section, id, options ); … … 141 150 */ 142 151 addContentControl: function() { 143 var section = this, control, setting = api( section.id ) , editor;152 var section = this, control, setting = api( section.id ); 144 153 145 154 control = new api.controlConstructor.dynamic( section.id + '[post_content]', { … … 163 172 control.updateEditorToggleExpandButtonLabel( control.editorExpanded.get() ); 164 173 165 editor = tinyMCE.get( 'customize-posts-content' );166 167 174 /** 168 175 * Update the setting value when the editor changes its state. 169 176 */ 170 177 control.onVisualEditorChange = function() { 171 var value ;178 var value; 172 179 if ( control.editorSyncSuspended ) { 173 180 return; 174 181 } 182 175 183 value = wp.editor.removep( editor.getContent() ); 176 184 control.editorSyncSuspended = true; … … 195 203 */ 196 204 setting.bind( function( newPostData, oldPostData ) { 205 197 206 if ( control.editorExpanded.get() && ! control.editorSyncSuspended && newPostData.post_content !== oldPostData.post_content ) { 198 207 control.editorSyncSuspended = true; 208 199 209 editor.setContent( wp.editor.autop( newPostData.post_content ) ); 200 210 control.editorSyncSuspended = false; … … 208 218 */ 209 219 control.editorExpanded.bind( function( expanded ) { 210 var textarea = $( '#customize-posts-content' ); 220 var editor, textarea = $( '#customize-posts-content' ); 221 editor = tinyMCE.get( 'customize-posts-content' ); 211 222 control.updateEditorToggleExpandButtonLabel( expanded ); 212 223 $( document.body ).toggleClass( 'customize-posts-content-editor-pane-open', expanded ); … … 238 249 */ 239 250 control.editorToggleExpandButton.on( 'click', function() { 251 240 252 control.editorExpanded.set( ! control.editorExpanded() ); 241 253 if ( control.editorExpanded() ) { … … 250 262 */ 251 263 control.focus = function( args ) { 252 var control = this, editor ;264 var control = this, editor; 253 265 api.controlConstructor.dynamic.prototype.focus.call( control, args ); 254 266 control.editorExpanded.set( true ); 255 256 editor = tinyMCE.get( 'customize-posts-content' );257 267 editor.focus(); 258 268 }; -
customize-posts/trunk/js/customize-preview-posts.js
r1367273 r1381641 1 /*global wp, _wpCustomizePreviewPostsData */1 /*global wp, _wpCustomizePreviewPostsData */ 2 2 ( function( api, $ ) { 3 3 'use strict'; … … 16 16 } ); 17 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 18 53 api.bind( 'preview-ready', function() { 19 54 api.preview.bind( 'active', function() { 20 55 var postSettings = {}, idPattern = /^post\[(.+)]\[(-?\d+)]$/; 21 56 api.each( function( setting ) { 22 var partial; 23 if ( ! idPattern.test( setting.id ) ) { 24 return; 57 if ( idPattern.test( setting.id ) ) { 58 postSettings[ setting.id ] = setting.get(); 25 59 } 26 postSettings[ setting.id ] = setting.get();27 28 // Post field partial for post_title.29 partial = new api.previewPosts.PostFieldPartial( setting.id + '[post_title]', {30 params: {31 settings: [ setting.id ]32 }33 } );34 api.selectiveRefresh.partial.add( partial.id, partial );35 36 // Post field partial for post_content.37 partial = new api.previewPosts.PostFieldPartial( setting.id + '[post_content]', {38 params: {39 settings: [ setting.id ]40 }41 } );42 api.selectiveRefresh.partial.add( partial.id, partial );43 60 } ); 44 61 62 45 63 api.preview.send( 'customized-posts', _.extend( 46 64 {}, … … 63 81 } ); 64 82 } ); 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 65 101 } ); 66 102 -
customize-posts/trunk/php/class-wp-customize-post-field-partial.php
r1367273 r1381641 105 105 if ( ! empty( $post->post_password ) ) { 106 106 /** This filter is documented in wp-includes/post-template.php */ 107 $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post );107 $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post ); 108 108 $rendered = sprintf( $protected_title_format, $rendered ); 109 109 } elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) { 110 110 /** This filter is documented in wp-includes/post-template.php */ 111 $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post );111 $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post ); 112 112 $rendered = sprintf( $private_title_format, $rendered ); 113 113 } -
customize-posts/trunk/php/class-wp-customize-post-setting.php
r1367273 r1381641 316 316 /** This filter is documented in wp-includes/post.php */ 317 317 if ( $strict && apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $post_data ) ) { 318 return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) );318 return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) ); 319 319 } 320 320 … … 369 369 if ( ! $valid_date ) { 370 370 if ( $strict ) { 371 return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );371 return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) ); 372 372 } else { 373 373 $post_data['post_date'] = ''; -
customize-posts/trunk/php/class-wp-customize-posts-preview.php
r1367273 r1381641 54 54 add_filter( 'edit_post_link', array( $this, 'filter_edit_post_link' ), 10, 2 ); 55 55 add_filter( 'get_edit_post_link', array( $this, 'filter_get_edit_post_link' ), 10, 2 ); 56 56 57 } 57 58 … … 219 220 wp_scripts()->add_data( 'customize-preview-posts', 'data', $data ); 220 221 } 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 221 240 } -
customize-posts/trunk/php/class-wp-customize-posts.php
r1367273 r1381641 1 1 <?php 2 2 /** 3 * Customize Posts C lass3 * Customize Posts Class 4 4 * 5 5 * Implements post management in the Customizer. … … 7 7 * @package WordPress 8 8 * @subpackage Customize 9 10 11 12 9 13 */ 10 14 final class WP_Customize_Posts { … … 54 58 require_once dirname( __FILE__ ) . '/class-wp-customize-post-field-partial.php'; 55 59 56 add_action( 'wp_default_scripts', array( $this, 'register_scripts' ), 11 );57 add_action( 'wp_default_styles', array( $this, 'register_styles' ), 11 );58 60 add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 59 61 add_action( 'customize_controls_init', array( $this, 'enqueue_editor' ) ); … … 70 72 * Get post type objects that can be managed in Customizer. 71 73 * 74 75 76 77 72 78 * @return array 73 79 */ 74 80 public function get_post_types() { 75 81 $post_types = array(); 76 foreach ( get_post_types( array( 'show_ui' => true), 'objects' ) as $post_type_object ) {82 foreach ( get_post_types( array(), 'objects' ) as $post_type_object ) { 77 83 if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) { 78 84 continue; 79 85 } 80 $post_types[ $post_type_object->name ] = clone $post_type_object; 81 $post_types[ $post_type_object->name ]->supports = get_all_post_type_supports( $post_type_object->name ); 86 87 $is_included = ( $post_type_object->show_ui && $post_type_object->publicly_queryable ); 88 if ( isset( $post_type_object->show_in_customizer ) ) { 89 $is_included = $post_type_object->show_in_customizer; 90 } 91 92 if ( $is_included ) { 93 $post_types[ $post_type_object->name ] = clone $post_type_object; 94 $post_types[ $post_type_object->name ]->supports = get_all_post_type_supports( $post_type_object->name ); 95 } 82 96 } 83 97 … … 253 267 254 268 /** 255 * Register scripts for Customize Posts.256 *257 * @param WP_Scripts $wp_scripts Scripts.258 */259 public function register_scripts( WP_Scripts $wp_scripts ) {260 $handle = 'customize-base-extensions';261 $src = CUSTOMIZE_POSTS_PLUGIN_URL . 'js/customize-base-extensions.js';262 $deps = array( 'customize-base' );263 $version = CUSTOMIZE_POSTS_VERSION;264 $in_footer = 1;265 $wp_scripts->add( $handle, $src, $deps, $version, $in_footer );266 267 $handle = 'customize-posts-panel';268 $src = CUSTOMIZE_POSTS_PLUGIN_URL . 'js/customize-posts-panel.js';269 $deps = array( 'customize-controls' );270 $version = CUSTOMIZE_POSTS_VERSION;271 $in_footer = 1;272 $wp_scripts->add( $handle, $src, $deps, $version, $in_footer );273 274 $handle = 'customize-post-section';275 $src = CUSTOMIZE_POSTS_PLUGIN_URL . 'js/customize-post-section.js';276 $deps = array( 'customize-controls' );277 $version = CUSTOMIZE_POSTS_VERSION;278 $in_footer = 1;279 $wp_scripts->add( $handle, $src, $deps, $version, $in_footer );280 281 $handle = 'customize-dynamic-control';282 $src = CUSTOMIZE_POSTS_PLUGIN_URL . 'js/customize-dynamic-control.js';283 $deps = array( 'customize-controls' );284 $version = CUSTOMIZE_POSTS_VERSION;285 $in_footer = 1;286 $wp_scripts->add( $handle, $src, $deps, $version, $in_footer );287 288 $handle = 'customize-posts';289 $src = CUSTOMIZE_POSTS_PLUGIN_URL . 'js/customize-posts.js';290 $deps = array(291 'jquery',292 'wp-backbone',293 'customize-base-extensions',294 'customize-controls',295 'customize-posts-panel',296 'customize-post-section',297 'customize-dynamic-control',298 'underscore',299 );300 $version = CUSTOMIZE_POSTS_VERSION;301 $in_footer = 1;302 $wp_scripts->add( $handle, $src, $deps, $version, $in_footer );303 304 $handle = 'customize-post-field-partial';305 $src = CUSTOMIZE_POSTS_PLUGIN_URL . 'js/customize-post-field-partial.js';306 $deps = array( 'customize-selective-refresh' );307 $version = CUSTOMIZE_POSTS_VERSION;308 $in_footer = 1;309 $wp_scripts->add( $handle, $src, $deps, $version, $in_footer );310 311 $handle = 'customize-preview-posts';312 $src = CUSTOMIZE_POSTS_PLUGIN_URL . 'js/customize-preview-posts.js';313 $deps = array( 'jquery', 'customize-preview', 'customize-post-field-partial' );314 $version = CUSTOMIZE_POSTS_VERSION;315 $in_footer = 1;316 $wp_scripts->add( $handle, $src, $deps, $version, $in_footer );317 }318 319 /**320 * Register styles for Customize Posts.321 *322 * @param WP_Styles $wp_styles Styles.323 */324 public function register_styles( WP_Styles $wp_styles ) {325 $handle = 'customize-posts';326 $src = CUSTOMIZE_POSTS_PLUGIN_URL . 'css/customize-posts.css';327 $deps = array( 'wp-admin' );328 $version = CUSTOMIZE_POSTS_VERSION;329 $wp_styles->add( $handle, $src, $deps, $version );330 }331 332 /**333 269 * Enqueue scripts and styles for Customize Posts. 334 270 */ … … 343 279 'l10n' => array( 344 280 /* translators: ▸ is the unicode right-pointing triangle, and %s is the section title in the Customizer */ 345 'sectionCustomizeActionTpl' => __( 'Customizing ▸ %s' ),346 'fieldTitleLabel' => __( 'Title' ),347 'fieldContentLabel' => __( 'Content' ),348 'fieldExcerptLabel' => __( 'Excerpt' ),349 'noTitle' => __( '(no title)' ),281 'sectionCustomizeActionTpl' => __( 'Customizing ▸ %s' ), 282 'fieldTitleLabel' => __( 'Title' ), 283 'fieldContentLabel' => __( 'Content' ), 284 'fieldExcerptLabel' => __( 'Excerpt' ), 285 'noTitle' => __( '(no title)' ), 350 286 'theirChange' => __( 'Their change: %s', 'customize-posts' ), 351 287 'overrideButtonText' => __( 'Override', 'customize-posts' ), … … 364 300 add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_editor' ), 0 ); 365 301 302 303 304 366 305 // @todo These should be included in \_WP_Editors::editor_settings() 367 306 if ( false === has_action( 'customize_controls_print_footer_scripts', array( '_WP_Editors', 'enqueue_scripts' ) ) ) { … … 382 321 'tabfocus_elements' => 'content-html,save-post', 383 322 'editor_height' => 200, 323 384 324 'tinymce' => array( 385 325 'resize' => false, … … 391 331 echo '</div>'; 392 332 } 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 393 357 } -
customize-posts/trunk/readme.txt
r1367273 r1381641 3 3 Tags: customizer, customize, posts, preview, featured-image, page-template 4 4 Requires at least: 4.5-beta2 5 Tested up to: 4.5- beta26 Stable tag: trunk5 Tested up to: 4.5- 6 Stable tag: 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 30 30 1) [2016-03-01] Demonstration of hooking into edit post links so that they actually work in the Customizer and expand the section to edit the given post (as opposed to the link doing nothing at all when clicked), as well as shift-clicking on the title and content (needs better discovery UI, see [#27403](https://core.trac.wordpress.org/ticket/27403)): 31 31 32 [youtube https:// youtu.be/nYfph3NbNCc]32 [youtube https://nYfph3NbNCc] 33 33 34 34 2) [2016-03-03] Demonstration of integration with [Customize Setting Validation](https://github.com/xwp/wp-customize-setting-validation) ([#34893](https://core.trac.wordpress.org/ticket/34893)) to gracefully handle failures to save due to post locking and concurrent user editing: 35 35 36 [youtube https:// youtu.be/OUwwTt6FtlQ]36 [youtube https://OUwwTt6FtlQ] 37 37 38 38 3) [2016-03-04] Demo featuring the WP visual rich text editor (TinyMCE), including the insertion of images from the media library. Post content can be edited in the Customizer and previewed in multiple contexts. For example, this allows you to preview how a Read More tag will appear when the post appears on a post list page, and you can navigate to the single post to continue previewing subsequent paragraphs. You can expand the editor into a full-screen mode to focus on writing and then quickly preview the changes on the site by toggling the editor. You can make changes to as many posts as you want, but none of the changes will go live until you hit Save & Publish: everything is previewed so there is no “save and surprise”. 39 39 40 [youtube https:// youtu.be/QJsEl0gd7dk]40 [youtube https://QJsEl0gd7dk] 41 41 42 42 4) [2016-03-05] Opening a draft post in the Customizer to preview title wrapping. … … 44 44 [youtube https://www.youtube.com/watch?v=sXu2pA42J88] 45 45 46 47 48 49 46 50 == Changelog == 51 52 53 54 55 56 57 58 59 60 47 61 48 62 = 0.3.0 =
Note: See TracChangeset
for help on using the changeset viewer.