Permalink
Browse files

Remove the Disable button

Leave only Enable and Archive, much simpler.
  • Loading branch information...
1 parent f4e54ce commit 8c3cdd8db67d4766b0e7ede88c6a630b0353e54d @nb nb committed Dec 20, 2012
Showing with 16 additions and 28 deletions.
  1. +13 −26 liveblog.php
  2. +3 −2 templates/meta_box.php
View
@@ -308,9 +308,12 @@ private static function is_entries_ajax_request() {
*/
private static function is_liveblog_post( $post_id = null ) {
$state = self::get_liveblog_state( $post_id );
- return $state && 'disable' != $state;
+ return (bool)$state;
}
+ /**
+ * One of: 'enable', 'archive', false.
+ */
private static function get_liveblog_state( $post_id = null ) {
if ( empty( $post_id ) ) {
global $post;
@@ -321,9 +324,6 @@ private static function get_liveblog_state( $post_id = null ) {
if ( 1 == $state ) {
$state = 'enable';
}
- if ( !$state ) {
- $state = 'disable';
- }
return $state;
}
@@ -619,33 +619,20 @@ public static function add_meta_box( $post_type ) {
* @param WP_Post $post
*/
public static function display_meta_box( $post ) {
- $entries_query = new WPCOM_Liveblog_Entry_Query( $post->ID, self::key );
$current_state = self::get_liveblog_state( $post->ID );
- $primary_from_current = array(
- 'enable' => 'archive',
- 'disable' => 'enable',
- );
- $default_button = array( 'primary' => false, 'current' => false, );
$buttons = array(
- 'enable' => array( 'value' => 'enable', 'text' => __( 'Activate', 'liveblog' ),
- 'description' => __( 'Enables liveblog on this post. Posting tools are enabled for editors, visitors get the latest updates.' , 'liveblog'), 'active-text' => sprintf( __( 'There is an <strong>enabled</strong> liveblog on this post. <a href="%s">Visit the liveblog &rarr;</a>', 'liveblog' ), get_permalink( $post ) ), ),
+ 'enable' => array( 'value' => 'enable', 'text' => __( 'Enable', 'liveblog' ),
+ 'description' => __( 'Enables liveblog on this post. Posting tools are enabled for editors, visitors get the latest updates.' , 'liveblog'), 'active-text' => sprintf( __( 'There is an <strong>enabled</strong> liveblog on this post. <a href="%s">Visit the liveblog &rarr;</a>', 'liveblog' ), get_permalink( $post ) ), 'primary' => true, 'disabled' => false, ),
'archive' => array( 'value' => 'archive', 'text' => __( 'Archive', 'liveblog' ),
- 'description' => __( 'Archives the liveblog on this post. Posting tools are hidden, visitors still see all the liveblog entries.' , 'liveblog'), 'active-text' => sprintf( __( 'There is an <strong>archived</strong> liveblog on this post. <a href="%s">Visit the liveblog archive &rarr;</a>', 'liveblog' ), get_permalink( $post ) ) ),
- 'disable' => array( 'value' => 'disable', 'text' => __( 'Disable', 'liveblog' ),
- 'description' => __( 'Disables the liveblog on this post. Turns it into a normal WordPress post, without a liveblog.' , 'liveblog'), 'active-text' => __( 'This is a normal WordPress post, without a liveblog.', 'liveblog' ), ),
+ 'description' => __( 'Archives the liveblog on this post. Visitors still see the liveblog entries, but posting tools are hidden.' , 'liveblog'), 'active-text' => sprintf( __( 'There is an <strong>archived</strong> liveblog on this post. <a href="%s">Visit the liveblog archive &rarr;</a>', 'liveblog' ), get_permalink( $post ) ), 'primary' => false, 'disabled' => false ),
);
- foreach( $buttons as &$button ) {
- $button = array_merge( $default_button, $button );
- }
- $buttons[$current_state]['current'] = true;
- if ( isset( $primary_from_current[$current_state] ) ) {
- $buttons[$primary_from_current[$current_state]]['primary'] = true;
- }
- if ( $entries_query->has_any() ) {
- $buttons['disable']['description'] .= ' ' . __( 'Existing entries are kept, but hidden.' , 'liveblog' );
- $buttons['disable']['active-text'] .= ' ' . __( 'Existing entries are kept, but hidden.' , 'liveblog' );
+ if ( $current_state ) {
+ $active_text = $buttons[$current_state]['active-text'];
+ $buttons[$current_state]['disabled'] = true;
+ } else {
+ $active_text = __( 'This is a normal WordPress post, without a liveblog.', 'liveblog' );
+ $buttons['archive']['disabled'] = true;
}
- $active_text = $buttons[$current_state]['active-text'];
echo self::get_template_part( 'meta_box.php', compact( 'active_text', 'buttons' ) );
}
View
@@ -3,12 +3,13 @@
<ul>
<?php
foreach( $buttons as $button ):
- if ( $button['current'] ) {
+ if ( $button['disabled'] ) {
+ $button['primary'] = false;
$button['description'] = '<span class="disabled">' . $button['description'] . '</span>';
}
?>
<li>
- <button class="button <?php echo $button['primary']? 'button-primary' : '' ?>" <?php echo $button['current']? 'disabled="disabled"' : '' ?> value="<?php echo esc_attr( $button['value'] ) ?>">
+ <button class="button <?php echo $button['primary']? 'button-primary' : '' ?>" <?php echo $button['disabled']? 'disabled="disabled"' : '' ?> value="<?php echo esc_attr( $button['value'] ) ?>">
<?php echo $button['text']; ?>
</button>
<?php echo $button['description'] ?>

0 comments on commit 8c3cdd8

Please sign in to comment.