• I am creating a wordpress theme for a nonprofit which allows WordPress to function as CMS. I am doing so using custom post types. I would like the event date to be the date of an “event” custom post type. However, the organization needs to utilize contributors. By default, contributors cannot adjust the the date of the post (or custom post type “event” by extension) from the main editing window. A contributor, can however, set the date by selecting “quick edit” from the “events” listing (the same is true for regular posts). Therefore, I suspect that the capability is already organic to the contributor role. Does anyone know of a plugin that allows one to modify the behavior of the “Publish” box, such that a user assigned the “contributor” role can input a date?

    If there isn’t; can someone offer a good starting point toward me writing a plugin that could do it? I’ve never written a plugin before.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Did you ever, by chance, find a solution to this? I’m needing similar functionality…

    Thread Starter kurtmunz

    (@kurtmunz)

    In the core, meta-boxes.php, this is the code which controls it:

    if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
    <div class="misc-pub-section curtime misc-pub-section-last">
    	<span id="timestamp">
    	<?php printf($stamp, $date); ?></span>
    	<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a>
    	<div id="timestampdiv" class="hide-if-js"><?php touch_time(($action == 'edit'),1,4); ?></div>
    </div><?php // /misc-pub-section ?>
    <?php endif; ?>

    I decided to go a different route from showing the box to contributors. Instead, I show a custom meta box to all users and take the date and time values from the inputs of that meta box for the date and time of the post.

    The code I wrote is ghetto, but it works.

    Thread Starter kurtmunz

    (@kurtmunz)

    Here’s the code I used as a plugin:

    function kurt_pagedate_change($id)
    {
    	global $wpdb, $post_type;
    	$post_type_object = get_post_type_object($post_type);
    	$can_publish = current_user_can($post_type_object->cap->publish_posts);
    
    	// check if this is a page
    	if ( ($post_type == "event" || $post_type == "movie_show" || $post_type == "cclass") && isset($id))
    	{
    
    	  if ( $_POST['event_date'] ) {
    
    		$form_date = $_POST['event_date'];
    		$form_time = $_POST['event_time'];
    		$form_date = $form_date." ".$form_time;
    		$date_obj = date_create($form_date);
    //		0000-00-00 00:00:00
    		$form_date_formatted = date_format($date_obj, 'Y-m-d H:i:s');
    
    		// modify date
    		$now = $form_date_formatted;
    		$now_gmt 	= $form_date_formatted;
    		$query = "UPDATE {$wpdb->posts} SET post_date = '$now', post_date_gmt = '$now_gmt' WHERE ID = '$id'";
    		$wpdb->query($query);
    
    	if ( $can_publish ) : // Contributors don't get to "Schedule"
    		// set post status as future
    		$sql = "UPDATE {$wpdb->posts} SET post_status = 'future'
    				WHERE ID = '$id'";
    		$wpdb->get_results($sql);
    	endif;
    
    	  } // end if event_date has value
    	} // end if page
    }
    
    /** Add actions **/
    add_action('edit_post', 	'kurt_pagedate_change');
    add_action('publish_post', 	'kurt_pagedate_change');
    add_action('save_post', 	'kurt_pagedate_change');
    
    ?>

    Anonymous User 2630056

    (@anonymized-2630056)

    My code is simpler and it doesnt require modifying the core:

    function mostrar_editar_fecha($post)
    {
    	$post_type_object = get_post_type_object('post');
    	$can_publish = current_user_can($post_type_object->cap->publish_posts);
    
    	$datef = __( 'M j, Y @ G:i' );
    	if ( 0 != $post->ID ) {
    		if ( 'future' == $post->post_status ) { // scheduled for publishing at a future date
    			$stamp = __('Scheduled for: <b>%1$s</b>');
    		} else if ( 'publish' == $post->post_status || 'private' == $post->post_status ) { // already published
    			$stamp = __('Published on: <b>%1$s</b>');
    		} else if ( '0000-00-00 00:00:00' == $post->post_date_gmt ) { // draft, 1 or more saves, no date specified
    			$stamp = __('Publish <b>immediately</b>');
    		} else if ( time() < strtotime( $post->post_date_gmt . ' +0000' ) ) { // draft, 1 or more saves, future date specified
    			$stamp = __('Schedule for: <b>%1$s</b>');
    		} else { // draft, 1 or more saves, date specified
    			$stamp = __('Publish on: <b>%1$s</b>');
    		}
    		$date = date_i18n( $datef, strtotime( $post->post_date ) );
    	} else { // draft (no saves, and thus no date specified)
    		$stamp = __('Publish <b>immediately</b>');
    		$date = date_i18n( $datef, strtotime( current_time('mysql') ) );
    	}
    
    	if (!($can_publish)) : // Contributors don't get to choose the date of publish ?>
    		<div class="misc-pub-section curtime misc-pub-section-last">
    			<span id="timestamp">
    			<?php printf($stamp, $date); ?></span>
    			<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e('Edit') ?></a>
    			<div id="timestampdiv" class="hide-if-js"><?php touch_time(($action == 'edit'),1,4); ?></div>
    		</div>
    	<?php
    	endif;
    }
    
    add_action ('post_submitbox_misc_actions', 'mostrar_editar_fecha');
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Allow Contributor Role To Suggest Scheduled Post Date’ is closed to new replies.