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

Fix status list, calendar, and story budget to show custom post statuses and show post states in post list. #446

Merged
merged 20 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions common/php/class-module.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,42 +186,7 @@ function filter_posts_link( $slug, $post_type = 'post' ) {
$filter_link = add_query_arg( 'post_type', $post_type, $filter_link );
return $filter_link;
}

/**
* Returns the friendly name for a given status
*
* @since 0.7
*
* @param string $status The status slug
* @return string $status_friendly_name The friendly name for the status
*/
function get_post_status_friendly_name( $status ) {
global $edit_flow;

$status_friendly_name = '';

$builtin_stati = array(
'publish' => __( 'Published', 'edit-flow' ),
'draft' => __( 'Draft', 'edit-flow' ),
'future' => __( 'Scheduled', 'edit-flow' ),
'private' => __( 'Private', 'edit-flow' ),
'pending' => __( 'Pending Review', 'edit-flow' ),
'trash' => __( 'Trash', 'edit-flow' ),
);

// Custom statuses only handles workflow statuses
if ( $this->module_enabled( 'custom_status' )
&& !in_array( $status, array( 'publish', 'future', 'private', 'trash' ) ) ) {
$status_object = $edit_flow->custom_status->get_custom_status_by( 'slug', $status );
if( $status_object && !is_wp_error( $status_object ) ) {
$status_friendly_name = $status_object->name;
}
} else if ( array_key_exists( $status, $builtin_stati ) ) {
$status_friendly_name = $builtin_stati[$status];
}
return $status_friendly_name;
}


/**
* Enqueue any resources (CSS or JS) associated with datepicker functionality
*
Expand Down
41 changes: 21 additions & 20 deletions modules/calendar/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ function handle_ics_subscription() {
$start_date = self::ics_format_time( $post->post_date );
$end_date = self::ics_format_time( $post->post_date, 5 * MINUTE_IN_SECONDS );
$last_modified = self::ics_format_time( $post->post_modified );

$post_status_obj = get_post_status_object( get_post_status( $post->ID ) );
// Remove the convert chars and wptexturize filters from the title
remove_filter( 'the_title', 'convert_chars' );
remove_filter( 'the_title', 'wptexturize' );

$formatted_post = array(
'BEGIN' => 'VEVENT',
'UID' => $post->guid,
'SUMMARY' => $this->do_ics_escaping( apply_filters( 'the_title', $post->post_title ) ) . ' - ' . $this->get_post_status_friendly_name( get_post_status( $post->ID ) ),
'SUMMARY' => $this->do_ics_escaping( apply_filters( 'the_title', $post->post_title ) ) . ' - ' . $post_status_obj->label,
'DTSTART' => $start_date,
'DTEND' => $end_date,
'LAST-MODIFIED' => $last_modified,
Expand Down Expand Up @@ -856,6 +856,7 @@ function generate_post_li_html( $post, $post_date, $num = 0 ){
ob_start();
$post_id = $post->ID;
$edit_post_link = get_edit_post_link( $post_id );
$status_object = get_post_status_object( get_post_status( $post_id ) );

$post_classes = array(
'day-item',
Expand Down Expand Up @@ -884,7 +885,7 @@ function generate_post_li_html( $post, $post_date, $num = 0 ){
<div style="clear:right;"></div>
<div class="item-static">
<div class="item-default-visible">
<div class="item-status"><span class="status-text"><?php echo esc_html__( $this->get_post_status_friendly_name( get_post_status( $post_id ) ), 'edit-flow' ); ?></span></div>
<div class="item-status"><span class="status-text"><?php echo esc_html( $status_object->label ); ?></span></div>
<div class="inner">
<span class="item-headline post-title"><strong><?php echo esc_html( _draft_or_post_title( $post->ID ) ); ?></strong></span>
</div>
Expand Down Expand Up @@ -1213,17 +1214,17 @@ function get_calendar_posts_for_week( $args = array(), $context = 'dashboard' )

$args = array_merge( $defaults, $args );

// Unpublished as a status is just an array of everything but 'publish'
if ( $args['post_status'] == 'unpublish' ) {
// Unpublished as a status is just an array of everything but 'publish'.
if ( 'unpublish' == $args['post_status'] ) {
$args['post_status'] = '';
$post_statuses = $this->get_post_statuses();
foreach ( $post_statuses as $post_status ) {
$args['post_status'] .= $post_status->slug . ', ';
$post_stati = get_post_stati();
unset($post_stati['inherit'], $post_stati['auto-draft'], $post_stati['trash'], $post_stati['publish'] );
if ( ! apply_filters( 'ef_show_scheduled_as_unpublished', false ) ) {
unset( $post_stati['future'] );
}
foreach ( $post_stati as $post_status ) {
$args['post_status'] .= $post_status . ', ';
}
$args['post_status'] = rtrim( $args['post_status'], ', ' );
// Optional filter to include scheduled content as unpublished
if ( apply_filters( 'ef_show_scheduled_as_unpublished', false ) )
$args['post_status'] .= ', future';
}
// The WP functions for printing the category and author assign a value of 0 to the default
// options, but passing this to the query is bad (trashed and auto-draft posts appear!), so
Expand Down Expand Up @@ -1683,10 +1684,9 @@ function sanitize_filter( $key, $dirty_value ) {
switch( $key ) {
case 'post_status':
// Whitelist-based validation for this parameter
$valid_statuses = wp_list_pluck( $this->get_post_statuses(), 'slug' );
$valid_statuses[] = 'future';
$valid_statuses = get_post_stati();
$valid_statuses[] = 'unpublish';
$valid_statuses[] = 'publish';
unset( $valid_statuses['inherit'], $valid_statuses['auto-draft'], $valid_statuses['trash'] );
if ( in_array( $dirty_value, $valid_statuses ) )
return $dirty_value;
else
Expand Down Expand Up @@ -1716,18 +1716,19 @@ function sanitize_filter( $key, $dirty_value ) {
function calendar_filter_options( $select_id, $select_name, $filters ) {
switch( $select_id ){
case 'post_status':
$post_statuses = $this->get_post_statuses();
$post_stati = get_post_stati();
unset( $post_stati['inherit'], $post_stati['auto-draft'], $post_stati['trash'] );
?>
<select id="<?php echo $select_id; ?>" name="<?php echo $select_name; ?>" >
<option value=""><?php _e( 'View all statuses', 'edit-flow' ); ?></option>
<?php
foreach ( $post_statuses as $post_status ) {
echo "<option value='" . esc_attr( $post_status->slug ) . "' " . selected( $post_status->slug, $filters['post_status'] ) . ">" . esc_html( $post_status->name ) . "</option>";
foreach ( $post_stati as $post_status ) {
$value = $post_status;
$status = get_post_status_object($post_status);
echo "<option value='" . esc_attr( $value ) . "' " . selected( $value, $filters['post_status'] ) . ">" . esc_html( $status->label ) . "</option>";
}
?>
<option value="future" <?php selected( 'future', $filters['post_status'] ) ?> > <?php echo __( 'Scheduled', 'edit-flow' ) ?> </option>
<option value="unpublish" <?php selected( 'unpublish', $filters['post_status'] ) ?> > <?php echo __( 'Unpublished', 'edit-flow' ) ?> </option>
<option value="publish" <?php selected( 'publish', $filters['post_status'] ) ?> > <?php echo __( 'Published', 'edit-flow' ) ?> </option>
</select>
<?php
break;
Expand Down
23 changes: 20 additions & 3 deletions modules/custom-status/custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ function init() {
// Pagination for custom post statuses when previewing posts
add_filter( 'wp_link_pages_link', array( $this, 'modify_preview_link_pagination_url' ), 10, 2 );

// Filter through Post States and run a function to check if they are also a Status
add_filter( 'display_post_states', array( $this, 'check_if_post_state_is_status' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -722,11 +724,26 @@ function _filter_manage_posts_custom_column( $column_name ) {

if ( $column_name == 'status' ) {
global $post;
echo $this->get_post_status_friendly_name( $post->post_status );
$post_status_obj = get_post_status_object( get_post_status( $post->ID ) );
echo esc_html( $post_status_obj->label );
}

}

/**
* Check if Post State is a Status and display if it is not.
*
* @param array $post_states An array of post display states.
*/
function check_if_post_state_is_status($post_states) {

global $post;
$statuses = get_post_status_object(get_post_status($post->ID));
foreach ( $post_states as $state ) {
if ( $state !== $statuses->label ) {
echo '<span class="show"></span>';
}
}
return $post_states;
}

/**
* Determines whether the slug indicated belongs to a restricted status or not
Expand Down
3 changes: 3 additions & 0 deletions modules/custom-status/lib/custom-status.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* Hide the post-state (status) span since we display a custom column with post status */
span.post-state {
display: none;
}
.show + span.post-state {
display: inline-block;
}
11 changes: 7 additions & 4 deletions modules/notifications/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ function notification_status_change( $new_status, $old_status, $post ) {
// Email subject and first line of body
// Set message subjects according to what action is being taken on the Post
if ( $old_status == 'new' || $old_status == 'auto-draft' ) {
$old_status_friendly_name = "New";
/* translators: 1: site name, 2: post type, 3. post title */
$subject = sprintf( __( '[%1$s] New %2$s Created: "%3$s"', 'edit-flow' ), $blogname, $post_type, $post_title );
/* translators: 1: post type, 2: post id, 3. post title, 4. user name, 5. user email */
Expand Down Expand Up @@ -546,14 +547,16 @@ function notification_status_change( $new_status, $old_status, $post ) {
$subject = sprintf( __( '[%1$s] %2$s Status Changed for "%3$s"', 'edit-flow' ), $blogname, $post_type, $post_title );
/* translators: 1: post type, 2: post id, 3. post title, 4. user name, 5. user email */
$body .= sprintf( __( 'Status was changed for %1$s #%2$s "%3$s" by %4$s %5$s', 'edit-flow'), $post_type, $post_id, $post_title, $current_user_display_name, $current_user_email ) . "\r\n";
$old_status_post_obj = get_post_status_object( $old_status );
$old_status_friendly_name = $old_status_post_obj->label;
}

/* translators: 1: date, 2: time, 3: timezone */
$body .= sprintf( __( 'This action was taken on %1$s at %2$s %3$s', 'edit-flow' ), date_i18n( get_option( 'date_format' ) ), date_i18n( get_option( 'time_format' ) ), get_option( 'timezone_string' ) ) . "\r\n";
$old_status_friendly_name = $this->get_post_status_friendly_name( $old_status );
$new_status_friendly_name = $this->get_post_status_friendly_name( $new_status );


$new_status_post_obj = get_post_status_object( $new_status );
$new_status_friendly_name = $new_status_post_obj->label;
// Email body
$body .= "\r\n";
/* translators: 1: old status, 2: new status */
Expand Down
37 changes: 19 additions & 18 deletions modules/story-budget/story-budget.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,19 @@ function get_posts_for_term( $term, $args = null ) {
),
);

// Unpublished as a status is just an array of everything but 'publish'
if ( $args['post_status'] == 'unpublish' ) {
// Unpublished as a status is just an array of everything but 'publish'.
if ( 'unpublish' == $args['post_status'] ) {
$args['post_status'] = '';
$post_statuses = $this->get_post_statuses();
foreach ( $post_statuses as $post_status ) {
$args['post_status'] .= $post_status->slug . ', ';
$post_stati = get_post_stati();
unset( $post_stati['inherit'], $post_stati['auto-draft'], $post_stati['trash'], $post_stati['publish'] );
if ( ! apply_filters( 'ef_show_scheduled_as_unpublished', false ) ) {
unset( $post_stati['future'] );
}
foreach ( $post_stati as $post_status ) {
$args['post_status'] .= $post_status . ', ';
}
$args['post_status'] = rtrim( $args['post_status'], ', ' );
// Optional filter to include scheduled content as unpublished
if ( apply_filters( 'ef_show_scheduled_as_unpublished', false ) )
$args['post_status'] .= ', future';
}

// Filter by post_author if it's set
if ( $args['author'] === '0' ) unset( $args['author'] );

Expand Down Expand Up @@ -497,8 +497,8 @@ function term_column_default( $post, $column_name, $parent_term ) {

switch( $column_name ) {
case 'status':
$status_name = $this->get_post_status_friendly_name( $post->post_status );
return $status_name;
$status_name = get_post_status_object( $post->post_status );
return $status_name->label;
break;
case 'author':
$post_author = get_userdata( $post->post_author );
Expand Down Expand Up @@ -716,17 +716,18 @@ function story_budget_filters() {
function story_budget_filter_options( $select_id, $select_name, $filters ) {
switch( $select_id ) {
case 'post_status':
$post_statuses = $this->get_post_statuses();
$post_stati = get_post_stati();
unset( $post_stati['inherit'], $post_stati['auto-draft'], $post_stati['trash'] );
?>
<select id="post_status" name="post_status"><!-- Status selectors -->
<option value=""><?php _e( 'View all statuses', 'edit-flow' ); ?></option>
<?php
foreach ( $post_statuses as $post_status ) {
echo "<option value='" . esc_attr( $post_status->slug ) . "' " . selected( $post_status->slug, $filters['post_status'] ) . ">" . esc_html( $post_status->name ) . "</option>";
foreach ( $post_stati as $post_status ) {
$value = $post_status;
$status = get_post_status_object($post_status)->label;
echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $filters['post_status'] ) . '>' . esc_html( $status ) . '</option>';
}
echo "<option value='future'" . selected('future', $filters['post_status']) . ">" . __( 'Scheduled', 'edit-flow' ) . "</option>";
echo "<option value='unpublish'" . selected('unpublish', $filters['post_status']) . ">" . __( 'Unpublished', 'edit-flow' ) . "</option>";
echo "<option value='publish'" . selected('publish', $filters['post_status']) . ">" . __( 'Published', 'edit-flow' ) . "</option>";
echo '<option value="unpublish"' . selected('unpublish', $filters['post_status']) . '>' . __( 'Unpublished', 'edit-flow' ) . '</option>';
?>
</select>
<?php
Expand Down