Skip to content

Instantly share code, notes, and snippets.

@pospi
Last active July 5, 2020 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pospi/6457955 to your computer and use it in GitHub Desktop.
Save pospi/6457955 to your computer and use it in GitHub Desktop.
Wordpress edit page metaboxes reshuffler: moves 'author' and 'revisions' boxes to the sidebar, and places the excerpt above the editor. Excerpt hint text is configurable.
<?php
add_action('add_meta_boxes', array('AdminBoxShuffle', 'repositionDefaultMetaboxes'), 0);
class AdminBoxShuffle
{
const EXCERPT_HINTTEXT = 'This excerpt is shown at the top of your posts and will form the preview text on gateway pages.';
/**
* Reposition default metaboxes
*/
public static function repositionDefaultMetaboxes()
{
global $_wp_post_type_features;
$shownPT = get_post_type();
// put author & revisions to the side
if (post_type_supports($shownPT, 'author')) {
remove_meta_box( 'authordiv', $allposttypes, 'side' );
add_meta_box( 'authordiv', 'Author', 'post_author_meta_box', $allposttypes, 'side', 'default' );
}
if (post_type_supports($shownPT, 'revisions')) {
remove_meta_box( 'revisionsdiv', $allposttypes, 'side' );
add_meta_box( 'revisionsdiv', 'Revisions', 'post_revisions_meta_box', $allposttypes, 'side', 'default' );
}
// replace excerpt with our own metabox including custom hint text
if (post_type_supports($shownPT, 'excerpt')) {
remove_meta_box( 'postexcerpt', $allposttypes, 'normal' );
add_meta_box( 'postexcerpt', 'Excerpt', array(get_class(), 'doExcerptMetabox'), $allposttypes, 'normal', 'high' );
}
// pop out the editor box and re-add it as a "real" metabox so priority is taken into account
if (post_type_supports($shownPT, 'editor')) {
unset($_wp_post_type_features[$shownPT]['editor']);
add_meta_box(
'postdivrich',
__('Content'),
array(get_class(), 'doContentMetabox'),
$shownPT, 'normal', 'high'
);
}
}
public static function doExcerptMetabox($post)
{
?>
<label class="screen-reader-text" for="excerpt"><?php _e('Excerpt') ?></label><textarea rows="1" cols="40" name="excerpt" id="excerpt"><?php echo $post->post_excerpt; // textarea_escaped ?></textarea>
<p><?php _e(self::EXCERPT_HINTTEXT); ?></p>
<?php
}
public static function doContentMetabox($post)
{
// ensure the edit box is white like the default one
?>
<style type="text/css">
#content_ifr { background: white; }
</style>
<?php
// markup taken from wp-admin/edit-form-advanced.php
?>
<div id="postdivrich" class="postarea">
<?php wp_editor($post->post_content, 'content', array('dfw' => true, 'tabfocus_elements' => 'sample-permalink,post-preview', 'editor_height' => 360) ); ?>
<table id="post-status-info" cellspacing="0"><tbody><tr>
<td id="wp-word-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></td>
<td class="autosave-info">
<span class="autosave-message">&nbsp;</span>
<?php
if ( 'auto-draft' != $post->post_status ) {
echo '<span id="last-edit">';
if ( $last_id = get_post_meta($post_ID, '_edit_last', true) ) {
$last_user = get_userdata($last_id);
printf(__('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
} else {
printf(__('Last edited on %1$s at %2$s'), mysql2date(get_option('date_format'), $post->post_modified), mysql2date(get_option('time_format'), $post->post_modified));
}
echo '</span>';
} ?>
</td>
</tr></tbody></table>
</div>
<?php
}
}
@tom-cichy-cityos
Copy link

Undefined variable: allposttypes --> add:
$allposttypes = get_post_types();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment