Plugin Directory

Changeset 1381641

Timestamp:
03/30/2016 04:05:33 AM (8 years ago)
Author:
valendesigns
Message:

Committing 0.4.0 to trunk

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
  • customize-posts/trunk/css/customize-posts.css

    r1367273 r1381641  
    6868
    6969/* @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  
    44 * 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.
    55 * Plugin URI: https://github.com/xwp/wp-customize-posts/
    6  * Version: 0.3.0
     6 * Version: 0..0
    77 * Author: XWP
    88 * Author URI: https://make.xwp.co/
     
    2929 */
    3030
    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' );
     31require_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  
    22(function( api, $ ) {
    33    'use strict';
     4
    45
    56    if ( ! api.Posts ) {
     
    3839
    3940            section.postFieldControls = {};
     41
     42
     43
     44
     45
     46
     47
     48
    4049
    4150            api.Section.prototype.initialize.call( section, id, options );
     
    141150         */
    142151        addContentControl: function() {
    143             var section = this, control, setting = api( section.id ), editor;
     152            var section = this, control, setting = api( section.id );
    144153
    145154            control = new api.controlConstructor.dynamic( section.id + '[post_content]', {
     
    163172            control.updateEditorToggleExpandButtonLabel( control.editorExpanded.get() );
    164173
    165             editor = tinyMCE.get( 'customize-posts-content' );
    166 
    167174            /**
    168175             * Update the setting value when the editor changes its state.
    169176             */
    170177            control.onVisualEditorChange = function() {
    171                 var value;
     178                var value;
    172179                if ( control.editorSyncSuspended ) {
    173180                    return;
    174181                }
     182
    175183                value = wp.editor.removep( editor.getContent() );
    176184                control.editorSyncSuspended = true;
     
    195203             */
    196204            setting.bind( function( newPostData, oldPostData ) {
     205
    197206                if ( control.editorExpanded.get() && ! control.editorSyncSuspended && newPostData.post_content !== oldPostData.post_content ) {
    198207                    control.editorSyncSuspended = true;
     208
    199209                    editor.setContent( wp.editor.autop( newPostData.post_content ) );
    200210                    control.editorSyncSuspended = false;
     
    208218             */
    209219            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' );
    211222                control.updateEditorToggleExpandButtonLabel( expanded );
    212223                $( document.body ).toggleClass( 'customize-posts-content-editor-pane-open', expanded );
     
    238249             */
    239250            control.editorToggleExpandButton.on( 'click', function() {
     251
    240252                control.editorExpanded.set( ! control.editorExpanded() );
    241253                if ( control.editorExpanded() ) {
     
    250262             */
    251263            control.focus = function( args ) {
    252                 var control = this, editor;
     264                var control = this, editor;
    253265                api.controlConstructor.dynamic.prototype.focus.call( control, args );
    254266                control.editorExpanded.set( true );
    255 
    256                 editor = tinyMCE.get( 'customize-posts-content' );
    257267                editor.focus();
    258268            };
  • customize-posts/trunk/js/customize-preview-posts.js

    r1367273 r1381641  
    1 /*global wp, _wpCustomizePreviewPostsData */
     1/*global wp, _wpCustomizePreviewPostsData */
    22( function( api, $ ) {
    33    'use strict';
     
    1616    } );
    1717
     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
    1853    api.bind( 'preview-ready', function() {
    1954        api.preview.bind( 'active', function() {
    2055            var postSettings = {}, idPattern = /^post\[(.+)]\[(-?\d+)]$/;
    2156            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();
    2559                }
    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 );
    4360            } );
    4461
     62
    4563            api.preview.send( 'customized-posts', _.extend(
    4664                {},
     
    6381            } );
    6482        } );
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
    65101    } );
    66102
  • customize-posts/trunk/php/class-wp-customize-post-field-partial.php

    r1367273 r1381641  
    105105            if ( ! empty( $post->post_password ) ) {
    106106                /** 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 );
    108108                $rendered = sprintf( $protected_title_format, $rendered );
    109109            } elseif ( isset( $post->post_status ) && 'private' === $post->post_status ) {
    110110                /** 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 );
    112112                $rendered = sprintf( $private_title_format, $rendered );
    113113            }
  • customize-posts/trunk/php/class-wp-customize-post-setting.php

    r1367273 r1381641  
    316316        /** This filter is documented in wp-includes/post.php */
    317317        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.' ) );
    319319        }
    320320
     
    369369        if ( ! $valid_date ) {
    370370            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.' ) );
    372372            } else {
    373373                $post_data['post_date'] = '';
  • customize-posts/trunk/php/class-wp-customize-posts-preview.php

    r1367273 r1381641  
    5454        add_filter( 'edit_post_link', array( $this, 'filter_edit_post_link' ), 10, 2 );
    5555        add_filter( 'get_edit_post_link', array( $this, 'filter_get_edit_post_link' ), 10, 2 );
     56
    5657    }
    5758
     
    219220        wp_scripts()->add_data( 'customize-preview-posts', 'data', $data );
    220221    }
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
    221240}
  • customize-posts/trunk/php/class-wp-customize-posts.php

    r1367273 r1381641  
    11<?php
    22/**
    3  * Customize Posts Class
     3 * Customize Posts Class
    44 *
    55 * Implements post management in the Customizer.
     
    77 * @package WordPress
    88 * @subpackage Customize
     9
     10
     11
     12
    913 */
    1014final class WP_Customize_Posts {
     
    5458        require_once dirname( __FILE__ ) . '/class-wp-customize-post-field-partial.php';
    5559
    56         add_action( 'wp_default_scripts', array( $this, 'register_scripts' ), 11 );
    57         add_action( 'wp_default_styles', array( $this, 'register_styles' ), 11 );
    5860        add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    5961        add_action( 'customize_controls_init', array( $this, 'enqueue_editor' ) );
     
    7072     * Get post type objects that can be managed in Customizer.
    7173     *
     74
     75
     76
     77
    7278     * @return array
    7379     */
    7480    public function get_post_types() {
    7581        $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 ) {
    7783            if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) {
    7884                continue;
    7985            }
    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            }
    8296        }
    8397
     
    253267
    254268    /**
    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     /**
    333269     * Enqueue scripts and styles for Customize Posts.
    334270     */
     
    343279            'l10n' => array(
    344280                /* translators: &#9656; is the unicode right-pointing triangle, and %s is the section title in the Customizer */
    345                 'sectionCustomizeActionTpl' => __( 'Customizing &#9656; %s' ),
    346                 'fieldTitleLabel' => __( 'Title' ),
    347                 'fieldContentLabel' => __( 'Content' ),
    348                 'fieldExcerptLabel' => __( 'Excerpt' ),
    349                 'noTitle' => __( '(no title)' ),
     281                'sectionCustomizeActionTpl' => __( 'Customizing &#9656; %s' ),
     282                'fieldTitleLabel' => __( 'Title' ),
     283                'fieldContentLabel' => __( 'Content' ),
     284                'fieldExcerptLabel' => __( 'Excerpt' ),
     285                'noTitle' => __( '(no title)' ),
    350286                'theirChange' => __( 'Their change: %s', 'customize-posts' ),
    351287                'overrideButtonText' => __( 'Override', 'customize-posts' ),
     
    364300        add_action( 'customize_controls_print_footer_scripts', array( $this, 'render_editor' ), 0 );
    365301
     302
     303
     304
    366305        // @todo These should be included in \_WP_Editors::editor_settings()
    367306        if ( false === has_action( 'customize_controls_print_footer_scripts', array( '_WP_Editors', 'enqueue_scripts' ) ) ) {
     
    382321            'tabfocus_elements' => 'content-html,save-post',
    383322            'editor_height' => 200,
     323
    384324            'tinymce' => array(
    385325                'resize' => false,
     
    391331        echo '</div>';
    392332    }
     333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
    393357}
  • customize-posts/trunk/readme.txt

    r1367273 r1381641  
    33Tags:              customizer, customize, posts, preview, featured-image, page-template
    44Requires at least: 4.5-beta2
    5 Tested up to:      4.5-beta2
    6 Stable tag:        trunk
     5Tested up to:      4.5-
     6Stable tag:       
    77License:           GPLv2 or later
    88License URI:       http://www.gnu.org/licenses/gpl-2.0.html
     
    30301) [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)):
    3131
    32 [youtube https://youtu.be/nYfph3NbNCc]
     32[youtube https://nYfph3NbNCc]
    3333
    34342) [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:
    3535
    36 [youtube https://youtu.be/OUwwTt6FtlQ]
     36[youtube https://OUwwTt6FtlQ]
    3737
    38383) [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”.
    3939
    40 [youtube https://youtu.be/QJsEl0gd7dk]
     40[youtube https://QJsEl0gd7dk]
    4141
    42424) [2016-03-05] Opening a draft post in the Customizer to preview title wrapping.
     
    4444[youtube https://www.youtube.com/watch?v=sXu2pA42J88]
    4545
     46
     47
     48
     49
    4650== Changelog ==
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
    4761
    4862= 0.3.0 =
Note: See TracChangeset for help on using the changeset viewer.