Title: Some extensions causing server error
Last modified: August 21, 2016

---

# Some extensions causing server error

 *  [ThePopularizer](https://wordpress.org/support/users/thepopularizer/)
 * (@thepopularizer)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/)
 * Hi there,
 * I’m trying to implement a couple of extensions through functions.php:
    - [http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/](http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/)
    - [http://editflow.org/extend/limit-custom-statuses-based-on-user-role/](http://editflow.org/extend/limit-custom-statuses-based-on-user-role/)
 * However, the above codes give me a server error. ‘Hide the “Publish” button for
   certain custom statuses’ extension ([http://editflow.org/extend/hide-the-publish-button-for-certain-custom-statuses/](http://editflow.org/extend/hide-the-publish-button-for-certain-custom-statuses/))
   works well, so I’m not sure what’s triggering these.
 * Thanks for the fantastic plugin.
 * Regards,
    Tim
 * [http://wordpress.org/extend/plugins/edit-flow/](http://wordpress.org/extend/plugins/edit-flow/)

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Plugin Author [Mohammad Jangda](https://wordpress.org/support/users/batmoo/)
 * (@batmoo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868216)
 * Hi Tim,
 * Can you please look in your error logs to see what the error is?
 *  Thread Starter [ThePopularizer](https://wordpress.org/support/users/thepopularizer/)
 * (@thepopularizer)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868271)
 * Hi Mohammad, thanks for the response.
 * I have the following recorded in the site’s error log:
 * “PHP Parse error: syntax error, unexpected T_VARIABLE in [functions.php] on line
   74”
 * Line 74 is “global $edit_flow;”. Here is the full code, from line 73 onwards (
   basically an implementation of the auto-subscribe extension: [http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/](http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/)):
 *     ```
       function efx_auto_subscribe_usergroup( $new_status, $old_status, $post ) {
           global $edit_flow;
        
           // When the post is first created, you might want to automatically set
           // all of the user's user groups as following the post
           if ( 'draft' == $new_status ) {
               // Get all of the user groups for this post_author
               $usergroup_ids_to_follow = $edit_flow->user_groups->get_usergroups_for_user( $post->post_author );
               $usergroup_ids_to_follow = array_map( 'intval', $usergroup_ids_to_follow );
               $edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
           }
        
           // You could also follow a specific user group based on post_status
           if ( 'pending' == $new_status ) {
               // You'll need to get term IDs for your user groups and place them as
               // comma-separated values
               $usergroup_ids_to_follow = array(
                       14, 17,
                   );
               $edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
           }
        
           // Return true to send the email notification
           return $new_status;
       }
       add_filter( 'ef_notification_status_change', 'efx_auto_subscribe_usergroup', 10, 3 );
       ```
   
 * Thanks again.
 * Tim
 *  [Grant Bivens](https://wordpress.org/support/users/rgbivens/)
 * (@rgbivens)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868274)
 * Is there any update on this? I’m having the exact same issue when trying to implement
   these two extension scripts. I’m running WP 3.6.
 * On the limit custom status script it throws the following error:
 * `Parse error: syntax error, unexpected T_STRING in /home/EXAMPLE/public_html/
   wp-content/themes/MYTHEME/functions.php on line 414`
 * where line 414 is the $current_user = wp_get_current_user(); line in the snippet.
   Here is my full snipped after making modifications to fit my custom statuses:
 *     ```
       /**
        * Limit custom statuses based on user role
        * In this example, we limit the statuses available to the
        * 'contributor' user role
        *
        * @see http://editflow.org/extend/limit-custom-statuses-based-on-user-role/
        *
        * @param array $custom_statuses The existing custom status objects
        * @return array $custom_statuses Our possibly modified set of custom statuses
        */
       function efx_limit_custom_statuses_by_role( $custom_statuses ) {
        
           $current_user = wp_get_current_user();
           switch( $current_user->roles[0] ) {
               // Only allow a contributor to access specific statuses from the dropdown
               case 'contributor':
                   $permitted_statuses = array(
                           'pending-review',
                           'draft'
                       );
                   // Remove the custom status if it's not whitelisted
                   foreach( $custom_statuses as $key => $custom_status ) {
                       if ( !in_array( $custom_status->slug, $permitted_statuses ) )
                           unset( $custom_statuses[$key] );
                   }
                   break;
           }
           return $custom_statuses;
       }
       add_filter( 'ef_custom_status_list', 'efx_limit_custom_statuses_by_role' );
       ```
   
 * Any help would be appreciated! These two scripts will basically determine if 
   I can or can’t use this plugin and I would really like it to work because it’s
   the cleanest looking workflow plugin out there.
 * Thanks,
    GB
 *  [keintze](https://wordpress.org/support/users/keintze/)
 * (@keintze)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868275)
 * Same problem here. Tried adding the unmodified code from: [http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/](http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/)
 * into functions.php and got the same error.
    Parse error: syntax error, unexpected
   T_VARIABLE on line 12
 * Which seems to point to this chunk. Line 12 is the declaration for $edit_flow.
 * function efx_auto_subscribe_usergroup( $new_status, $old_status, $post ) {
     
   global $edit_flow
 * If any of the Edit Flow team members could throw some light on this it’ll be 
   greatly appreciated.
 *  [cojennin](https://wordpress.org/support/users/comradefuzz/)
 * (@comradefuzz)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868276)
 * Hey,
    What were you doing when this error occured? Were you on the post editing
   screen, saving a post, browsing the site? What does the code around that function
   look like?
 * Thanks!
 * -CJ
 *  [keintze](https://wordpress.org/support/users/keintze/)
 * (@keintze)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868277)
 * hey CJ.
 * All I did was to reload the Users (All Users) page after I uploaded the modified
   code via FTP.
 * I appended the Edit Flow snippet at the end of functions.php, gave the same error.
   The code right above that was:
 *     ```
       // Initialize framework
   
       $air->run();
       ```
   
 * Update: I tried appending the code to custom_functions.php today (used by my 
   theme for adding custom code), noting that I added another chunk of Edit Flow
   code on top for fixing the publishing date earlier on, and it seems to be working
   now. Odd.
 * The file looks like this now (I removed the php code start and end):
 *     ```
       /* --- Place custom functions below ---------------------------------------- */
   
       add_action( 'admin_init', 'ef_check_timestamp_on_publish' );
       add_filter( 'wp_insert_post_data', 'ef_fix_custom_status_timestamp' );
       /**
        * This is a hack! hack! hack! until core is fixed/better supports custom statuses
        *
        * When publishing a post with a custom status, set the status to 'pending' temporarily
        * Works around this limitation: http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post.php#L2694
        * Original thread: http://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
        * Core ticket: http://core.trac.wordpress.org/ticket/18362
        */
       function ef_check_timestamp_on_publish() {
       	global $edit_flow, $pagenow, $wpdb;
   
       	// Handles the transition to 'publish' on edit.php
       	if ( isset( $edit_flow ) && $pagenow == 'edit.php' && isset( $_REQUEST['bulk_edit'] ) ) {
       		// For every post_id, set the post_status as 'pending' only when there's no timestamp set for $post_date_gmt
       		if ( $_REQUEST['_status'] == 'publish' ) {
       			$post_ids = array_map( 'intval', (array) $_REQUEST['post'] );
       			foreach ( $post_ids as $post_id ) {
       				$wpdb->update( $wpdb->posts, array( 'post_status' => 'pending' ), array( 'ID' => $post_id, 'post_date_gmt' => '0000-00-00 00:00:00' ) );
       			}
       		}
       	}
   
       	// Handles the transition to 'publish' on post.php
       	if ( isset( $edit_flow ) && $pagenow == 'post.php' && isset( $_POST['publish'] ) ) {
       		// Set the post_status as 'pending' only when there's no timestamp set for $post_date_gmt
       		if ( isset( $_POST['post_ID'] ) ) {
       			$post_id = (int) $_POST['post_ID'];
       			$wpdb->update( $wpdb->posts, array( 'post_status' => 'pending' ), array( 'ID' => $post_id, 'post_date_gmt' => '0000-00-00 00:00:00' ) );
       		}
       	}
   
       }
       /**
        * This is a hack! hack! hack! until core is fixed/better supports custom statuses
        *
        * Normalize post_date_gmt if it isn't set to the past or the future
        * Works around this limitation: http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/post.php#L2506
        * Original thread: http://wordpress.org/support/topic/plugin-edit-flow-custom-statuses-create-timestamp-problem
        * Core ticket: http://core.trac.wordpress.org/ticket/18362
        */
       function ef_fix_custom_status_timestamp( $data ) {
       	global $edit_flow, $pagenow;
       	// Don't run this if Edit Flow isn't active, or we're on some other page
       	if ( !isset( $edit_flow ) || $pagenow != 'post.php' || !isset( $_POST ) )
       		return $data;
       	$custom_statuses = get_terms( 'post_status', array( 'get' => 'all' ) );
       	$status_slugs = array();
       	foreach( $custom_statuses as $custom_status )
       	    $status_slugs[] = $custom_status->slug;
       	$ef_normalize_post_date_gmt = true;
       	// We're only going to normalize the post_date_gmt if the user hasn't set a custom date in the metabox
       	// and the current post_date_gmt isn't already future or past-ized
       	foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
       		if ( !empty( $_POST['hidden_' . $timeunit] ) && (($_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) || ( $_POST['hidden_' . $timeunit] != $_POST['cur_' . $timeunit] )) ) {
       			$ef_normalize_post_date_gmt = false;
       			break;
       		}
       	}
       	if ( $ef_normalize_post_date_gmt )
       		if ( in_array( $data['post_status'], $status_slugs ) )
       			$data['post_date_gmt'] = '0000-00-00 00:00:00';
       	return $data;
       }
   
       /**
        * Auto-subscribe or unsubscribe an Edit Flow user group when a post changes status
        *
        * @see http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/
        *
        * @param string $new_status New post status
        * @param string $old_status Old post status (empty if the post was just created)
        * @param object $post The post being updated
        * @return bool $send_notif Return true to send the email notification, return false to not
        */
       function efx_auto_subscribe_usergroup( $new_status, $old_status, $post ) {
           global $edit_flow;
   
           // When the post is first created, you might want to automatically set
           // all of the user's user groups as following the post
           if ( 'draft' == $new_status ) {
               // Get all of the user groups for this post_author
               $usergroup_ids_to_follow = $edit_flow->user_groups->get_usergroups_for_user( $post->post_author );
               $usergroup_ids_to_follow = array_map( 'intval', $usergroup_ids_to_follow );
               $edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
           }
   
           // You could also follow a specific user group based on post_status
           if ( 'copy-edit' == $new_status ) {
               // You'll need to get term IDs for your user groups and place them as
               // comma-separated values
               $usergroup_ids_to_follow = array(
                       // 18,
                   );
               $edit_flow->notifications->follow_post_usergroups( $post->ID, $usergroup_ids_to_follow, true );
           }
   
           // Return true to send the email notification
           return $new_status;
       }
       add_filter( 'ef_notification_status_change', 'efx_auto_subscribe_usergroup', 10, 3 );
       ```
   
 *  [cojennin](https://wordpress.org/support/users/comradefuzz/)
 * (@comradefuzz)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868278)
 * Interesting. So if you paste this code at the end of your functions.php file 
   it causes an error, but pasted in custom_functions.php it seems to work without
   issue?
 *  [keintze](https://wordpress.org/support/users/keintze/)
 * (@keintze)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868279)
 * To be exact, I actually tried the same code (as in only the code from: [http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/](http://editflow.org/extend/auto-subscribe-user-groups-for-notifications/))
   in custom_functions.php, but it threw the same error.
 * It was only the added Edit Flow code snippets for fixing the published date that
   somehow made it work this time. That’s how I see it. Strange, but so long as 
   it works I’m not complaining!
 *  [djblurb](https://wordpress.org/support/users/djblurb/)
 * (@djblurb)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868283)
 * Thank you for sharing this code [@keintze](https://wordpress.org/support/users/keintze/)!
 * I’m doing dev work for a client with a network (multisite) and your code saved
   my ass on launch day.
 * I pasted the code as is; I didn’t add any groups to the specific user group block.
 *  [Madloxxx](https://wordpress.org/support/users/madloxxx/)
 * (@madloxxx)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868306)
 * I have the same error with the extensions. Is there still no solution?
 *  [keintze](https://wordpress.org/support/users/keintze/)
 * (@keintze)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868307)
 * No worries [@djblurb](https://wordpress.org/support/users/djblurb/) 🙂 Glad to
   hear it worked for you!
 * [@madloxxx](https://wordpress.org/support/users/madloxxx/) it worked for me in
   the end, perhaps try dropping the code in the way I did it.
 *  [Madloxxx](https://wordpress.org/support/users/madloxxx/)
 * (@madloxxx)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868312)
 * [@keintze](https://wordpress.org/support/users/keintze/) i have the error with
   this extension:
    [http://editflow.org/extend/limit-custom-statuses-based-on-user-role/](http://editflow.org/extend/limit-custom-statuses-based-on-user-role/)
 * And i think i didnt saw there a date. So this can’t be the issue i think. i tryied
   to put it in a custom_functions.php too, but i had the same error.
 *  [keintze](https://wordpress.org/support/users/keintze/)
 * (@keintze)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868313)
 * Did you try pasting the chunk of code from my segment on the publishing date,
   and adding the code for what you need (custom statuses) below that?
 * I’m out of ideas if that doesn’t work, it’ll be up to the Edit Flow gurus to 
   see if they can offer a hand.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Some extensions causing server error’ is closed to new replies.

 * ![](https://ps.w.org/edit-flow/assets/icon-256x256.png?rev=3433533)
 * [Edit Flow](https://wordpress.org/plugins/edit-flow/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/edit-flow/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/edit-flow/)
 * [Active Topics](https://wordpress.org/support/plugin/edit-flow/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/edit-flow/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/edit-flow/reviews/)

## Tags

 * [extensions](https://wordpress.org/support/topic-tag/extensions/)
 * [server-error](https://wordpress.org/support/topic-tag/server-error/)

 * 13 replies
 * 7 participants
 * Last reply from: [keintze](https://wordpress.org/support/users/keintze/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/some-extensions-causing-server-error/#post-3868313)
 * Status: not resolved