• Resolved bjeremymoss

    (@bjeremymoss)


    Hi
    I have a friend running an old theme that is built before custom post types were around so instead of using an event plugin that uses a custom post type they used the schedule posts of a specific category and a custom query to show those posts on the at the date of the scheduled post.

    The issue he’s having is that the subscribe email is sending when the post “publishes” on the day of the event… they would rather have it send for that category when the post is scheduled instead. I was poking around in the publish function of class-s2-core.php but if someone knows a better place I should look any help would be GREATLY appreciated.

    Thanks!

    http://wordpress.org/extend/plugins/subscribe2/

Viewing 11 replies - 1 through 11 (of 11 total)
  • @bjeremymoss,

    just to clarify my understanding – your friend is writing a post and scheduling it for a future date. Subscribe2 sends a notification when the post schedule date is reached (which on a normal site would coincide with it becoming visible). But, on this site the ‘scheduled’ post becomes visible immediately and therefore the notification needs to be sent at the time when it is scheduled – right?

    If that is the case look in the class-s2-core.php file, the publish function is link to the WordPress post transition hooks – essentially these are triggered when a post becomes visible (in a standard install).

    You would need to add to and amend these hooks. I suspect you could remove the future_to_publish hook to stop duplicate emails when the scheduled date is reached and you would want to add in new_to_future, draft_to_future, auto-draft_to_future and pending_to_future hooks.

    Thread Starter bjeremymoss

    (@bjeremymoss)

    For Clarification yes you are correct they want the notification to send when the the post is scheduled not when it publishes itself.

    Of course! I hadn’t thought of using the post status transitions which of course you have set in the core to call the publish function.

    Now all I have to do is add those hooks (THANKS!) and put in a check to see if the post is in the correct category.

    For anyone after me wanting to know about Post Status Transitions
    and to add the actions mattyrob mentions above I’m assuming they start at line 1698 of class-s2-core.php (at least in version 8.9.1 of the plugin) and would look like
    add_action('new_to_future', array(&$this, 'publish')); and so on.

    Thanks again mattyrob!

    @bjeremymoss,

    You’re looking at the right lines of code there. I hope the changes work 🙂

    Thread Starter bjeremymoss

    (@bjeremymoss)

    Well I’m finally getting a chance to try this and it works but it also means that the regular ones won’t work on publish… cause I take those out for events… I’m trying to think of way to trigger difference add_action() elements based on what category is chosen but I think I’m hitting a brick wall… anyone with any ideas?

    @bjeremymoss,

    You’ll need to keep the hooks like draft_to_publish but remove the future_to_publish one to ensure you don’t get duplication on scheduling and it reaching the scheduled time.

    Thread Starter bjeremymoss

    (@bjeremymoss)

    The only issue with that is is that they won’t be able to use future_to_publish on news posts in other categories… I tried getting the post category from the ID to detect which set of actions to apply but it didn’t work… I may have to bite the bullet and tell them not to use publish settings on news items and only on evens unless they want to change even systems from their old school method.

    FYI here’s the code I tried. It’s pretty simple!

    // check for the $post ID
    $id = $_GET['post'];
    // echo 'the post ID = '.$id;
    $isEvents = false;
    if($id){ // Have post ID lets get the categories
    	$categories = get_the_category($id);
    	if($categories){
    		foreach($categories as $category){
    			 echo 'category = '.$category->slug;
    			if($category->slug == 'events'){
    				$isEvents = true;
    			}
    		}
    	};
    }
    
    // If this is a Future Event Category
    if($isEvents){
    	// if it is a future event set actions for going to scheduled post.
    	add_action('new_to_future', array(&$this, 'publish'));
    	add_action('draft_to_future', array(&$this, 'publish'));
    	add_action('auto-draft_to_future', array(&$this, 'publish'));
    	add_action('pending_to_future', array(&$this, 'publish'));
    }else{
    
    	// if it not an event go the nomral route.
    	add_action('new_to_publish', array(&$this, 'publish'));
    	add_action('draft_to_publish', array(&$this, 'publish'));
    	add_action('auto-draft_to_publish', array(&$this, 'publish'));
    	add_action('pending_to_publish', array(&$this, 'publish'));
    	add_action('private_to_publish', array(&$this, 'publish'));
    	add_action('future_to_publish', array(&$this, 'publish'));
    	if ( $this->subscribe2_options['private'] == 'yes' ) {
    		add_action('new_to_private', array(&$this, 'publish'));
    		add_action('draft_to_private', array(&$this, 'publish'));
    		add_action('auto-draft_to_private', array(&$this, 'publish'));
    		add_action('pending_to_private', array(&$this, 'publish'));
    	}
    };

    @bjeremymoss,

    The problem that you have with that code is that the ID of the post may not be available as plugin initiation. Any such code changes might be better placed in the publish() function.

    Thread Starter bjeremymoss

    (@bjeremymoss)

    BAH!!! that’s right… I should have thought of that… by the time the publish function runs I should have the global $post var so I can setup all my actions for every type then decide inside the publish function if the email should actually send or not.

    @bjeremymoss,

    Yes, that should work – it’s not easy deciding where to alter code written by someone else but I’m always happy to give pointers. 🙂

    Thread Starter bjeremymoss

    (@bjeremymoss)

    BEAUTIFUL! It looks like it works thus far! I’ll have to put it through a little more testing on the server but it looks like it works great!

    Thanks for the Help!!!

    @bjeremymoss,

    You are most welcome.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Ability to send on post schedule not just publish’ is closed to new replies.