Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add control to manipulate the post parent #189

Closed
wants to merge 9 commits into from

Conversation

Projects
None yet
2 participants
@sunnyratilal
Copy link
Contributor

commented Jun 26, 2016

Pull request for #65

@@ -224,6 +224,9 @@
if ( 'undefined' === typeof EditPostPreviewCustomize ) {
section.addPostStatusControl();
}
if ( postTypeObj.supports['page-attributes'] ) {

This comment has been minimized.

Copy link
@westonruter

westonruter Jul 5, 2016

Contributor

As seen above with postTypeObj.supports.slug, I suggest we introduce a discrete feature for parent, so this could be:

if ( postTypeObj.supports['page-attributes'] || postTypeObj.supports.parent ) {
@@ -592,6 +619,7 @@ public function enqueue_scripts() {
'fieldExcerptLabel' => __( 'Excerpt', 'customize-posts' ),
'fieldDiscussionLabel' => __( 'Discussion', 'customize-posts' ),
'fieldAuthorLabel' => __( 'Author', 'customize-posts' ),
'postParentLabel' => __( 'Parent', 'customize-posts' ),

This comment has been minimized.

Copy link
@westonruter

westonruter Jul 5, 2016

Contributor

Let's rename this to fieldParentLabel

params: {
section: section.id,
priority: 20,
label: api.Posts.data.l10n.postParentLabel,

This comment has been minimized.

Copy link
@westonruter

westonruter Jul 5, 2016

Contributor

Per below, fieldParentLabel

foreach ( (array) $pages as $page ) {
$choices[] = array(
'value' => (int) $page->ID,
'text' => esc_html( sprintf( '%s', $page->post_title ) ),

This comment has been minimized.

Copy link
@westonruter

westonruter Jul 5, 2016

Contributor

Using esc_html() isn't appropriate here, because the data will get exported as JSON, and so this could incidentally cause HTML entities to appear in the dropdown.

$post_id = url_to_postid( $this->manager->get_preview_url() );

$pages = get_pages( array(
'exclude' => array( $post_id ),

This comment has been minimized.

Copy link
@westonruter

westonruter Jul 5, 2016

Contributor

This isn't going to work. Since the user can navigate around the site in the preview, the preview URL will change. If a page is to be disabled in the dropdown, it will need to be disabled via JS.

@westonruter

This comment has been minimized.

Copy link
Contributor

commented Jul 5, 2016

@sunnyratilal this is looking good. I left some feedback.

Something you may want to consider, perhaps in a separate PR, also is adding support for the Object Selector Control, wherein if it is present, the dropdown could be replaced with a select2 field for loading pages on demand.

@westonruter westonruter modified the milestone: 0.8 Aug 6, 2016

@westonruter

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2016

The Customize Object Selector has some new changes that allow it to be used for manipulating the post_parent via passing a setting_property param. This is part of a PR: xwp/wp-customize-object-selector#10

@sunnyratilal

This comment has been minimized.

Copy link
Contributor Author

commented Aug 20, 2016

@westonruter will make the amendments soon. Sorry been stuck with university exams in the past few weeks hence I didn't get the chance

@westonruter

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2016

@sunnyratilal no worries! I can pick it up from you if you like.

@westonruter

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2016

@sunnyratilal here's some code for addPostParentControl for how the Object Selector Control can be used if it is available (again, if xwp/wp-customize-object-selector#10 is merged or the branch is checked out):

var section = this, control, setting = api( section.id ), controlId, params;

controlId = section.id + '[post_parent]';
params = {
    section: section.id,
    priority: 20,
    label: api.Posts.data.l10n.postParentLabel,
    active: true,
    settings: {
        'default': setting.id
    },
    field_type: 'select',
    setting_property: 'post_parent',
    choices: api.Posts.data.postParentChoices
};
if ( api.controlConstructor.object_selector ) {
    control = new api.controlConstructor.object_selector( controlId, {
        params: _.extend( params, {
            post_query_vars: {
                post_type: section.params.post_type,
                post_status: 'publish',
                post__not_in: [ section.params.post_id ]
            },
            select2_options: {
                multiple: false
            }
        } )
    } );
} else {
    control = new api.controlConstructor.dynamic( controlId, {
        params: _.extend( params, {
            field_type: 'select',
            choices: api.Posts.data.postParentChoices
        } )
    } );
}
@westonruter

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2016

(Updated JS snippet to include post__not_in to prevent a page from selecting itself as the parent, and to query all objects of the same post type since non-pages can have post parents as well.)

@westonruter

This comment has been minimized.

Copy link
Contributor

commented Aug 20, 2016

Here's what it looks like with the object selector control:

image

@westonruter westonruter changed the title Add control to manipulate the post parent [WIP] Add control to manipulate the post parent Aug 20, 2016

@sunnyratilal

This comment has been minimized.

Copy link
Contributor Author

commented Aug 29, 2016

@westonruter I'm going to be really tied up for the next few weeks with other projects so if you'd like to take over, feel free. Sorry for the delay in getting this out.

@westonruter

This comment has been minimized.

Copy link
Contributor

commented Aug 29, 2016

No worries. Thanks for the help!

@westonruter westonruter referenced this pull request Aug 30, 2016

Merged

Add control to manipulate the post parent #233

8 of 10 tasks complete
@westonruter

This comment has been minimized.

Copy link
Contributor

commented Aug 30, 2016

Picking this up in #233.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.