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

Commit

Permalink
Merge 8e0edb3 into 855e98b
Browse files Browse the repository at this point in the history
  • Loading branch information
valendesigns committed Apr 12, 2016
2 parents 855e98b + 8e0edb3 commit ae2a554
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions js/customize-post-field-partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
args.params.selector = baseSelector + ' .entry-title';
} else if ( 'post_content' === args.params.field_id ) {
args.params.selector = baseSelector + ' .entry-content';
} else if ( 'post_excerpt' === args.params.field_id ) {
args.params.selector = baseSelector + ' .entry-summary';
}
}
api.selectiveRefresh.Partial.prototype.initialize.call( partial, id, args );
Expand Down
41 changes: 41 additions & 0 deletions js/customize-post-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
if ( postTypeObj.supports.editor ) {
section.addContentControl();
}
if ( postTypeObj.supports.excerpt ) {
section.addExcerptControl();
}
},

/**
Expand Down Expand Up @@ -295,6 +298,44 @@
return control;
},

/**
* Add post excerpt control.
*
* @returns {wp.customize.Control}
*/
addExcerptControl: function() {
var section = this, control, setting = api( section.id );
control = new api.controlConstructor.dynamic( section.id + '[post_excerpt]', {
params: {
section: section.id,
priority: 1,
label: api.Posts.data.l10n.fieldExcerptLabel,
active: true,
settings: {
'default': setting.id
},
field_type: 'textarea',
setting_property: 'post_excerpt'
}
} );

// Override preview trying to de-activate control not present in preview context.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.post_excerpt = control;
api.control.add( control.id, control );

// Remove the setting from the settingValidationMessages since it is not specific to this field.
if ( control.settingValidationMessages ) {
control.settingValidationMessages.remove( setting.id );
control.settingValidationMessages.add( control.id, new api.Value( '' ) );
}
return control;
},

/**
* Set up setting validation.
*/
Expand Down
8 changes: 8 additions & 0 deletions js/customize-preview-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
}
} );
api.selectiveRefresh.partial.add( partial.id, partial );

// Post field partial for post_excerpt.
partial = new api.previewPosts.PostFieldPartial( id + '[post_excerpt]', {
params: {
settings: [ id ]
}
} );
api.selectiveRefresh.partial.add( partial.id, partial );
} );

};
Expand Down
4 changes: 3 additions & 1 deletion js/edit-post-preview-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ var EditPostPreviewAdmin = (function( $ ) {
// Send the current input fields from the edit post page to the Customizer via sessionStorage.
postSettingValue = {
post_title: $( '#title' ).val(),
post_content: editor && ! editor.isHidden() ? wp.editor.removep( editor.getContent() ) : $( '#content' ).val()
post_content: editor && ! editor.isHidden() ? wp.editor.removep( editor.getContent() ) : $( '#content' ).val(),
post_excerpt: $( '#excerpt' ).val()
};
postSettingId = 'post[' + postType + '][' + postId + ']';
settings[ postSettingId ] = postSettingValue;
Expand All @@ -63,6 +64,7 @@ var EditPostPreviewAdmin = (function( $ ) {
editor.setContent( wp.editor.autop( data[ postSettingId ].post_content ) );
}
$( '#content' ).val( data[ postSettingId ].post_content ).trigger( 'change' );
$( '#excerpt' ).val( data[ postSettingId ].post_excerpt ).trigger( 'change' );
}
} );

Expand Down
5 changes: 5 additions & 0 deletions php/class-wp-customize-post-field-partial.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public function render_callback( WP_Customize_Partial $partial, $context = array
/** This filter is documented in wp-includes/post-template.php */
$rendered = apply_filters( 'the_content', $rendered );
$rendered = str_replace( ']]>', ']]>', $rendered );
} else if ( 'post_excerpt' === $partial->field_id ) {
$rendered = get_the_excerpt();

/** This filter is documented in wp-includes/post-template.php */
$rendered = apply_filters( 'the_excerpt', $rendered );
}

wp_reset_postdata();
Expand Down

0 comments on commit ae2a554

Please sign in to comment.