WordPress.org

Ready to get started?Download WordPress

Forums

Subscribe2
[resolved] Ability to send on post schedule not just publish (12 posts)

  1. bjeremymoss
    Member
    Posted 1 year ago #

    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/

  2. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @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.

  3. bjeremymoss
    Member
    Posted 1 year ago #

    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!

  4. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @bjeremymoss,

    You're looking at the right lines of code there. I hope the changes work :)

  5. bjeremymoss
    Member
    Posted 1 year ago #

    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?

  6. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @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.

  7. bjeremymoss
    Member
    Posted 1 year ago #

    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'));
    	}
    };
  8. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @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.

  9. bjeremymoss
    Member
    Posted 1 year ago #

    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.

  10. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @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. :)

  11. bjeremymoss
    Member
    Posted 1 year ago #

    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!!!

  12. mattyrob
    Member
    Plugin Contributor

    Posted 1 year ago #

    @bjeremymoss,

    You are most welcome.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.