Title: How does the priority parameter work?
Last modified: August 21, 2016

---

# How does the priority parameter work?

 *  Resolved [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/)
 * I have written 2 plugins that I use in conjunction with each other, Strictly 
   AutoTags which automatically scans a post (usually imported from a feed) for 
   relevant tags and then adds them, reformats the post and re-saves it (deeplinking,
   bold etc) – and Strictly TweetBot which allows you to automatically Tweet to 
   multiple accounts OR the same account with different tweet formats. The usual
   trick is to use the post tags as #hashtags in the Tweet.
 * The priority for the AutoTag plugin is 1 e.g add_action(‘save_post’ , array(&
   $this, ‘SaveAutoTags’),1);
 * The priority for the Tweetbot plugin is 999 and on the publish (as I only want
   to Tweet when the post article goes live and not on drafts etc) e.g add_action(‘
   publish_post’, array(&$this, ‘PostTweets’) , 999);
 * However I have noticed recently that I am getting lots of articles added with
   tags but the tweets are using their default #hashtags NOT the post tags they 
   are supposed to.
 * I can remove the custom field I set that says the tweet has been sent, and re-
   publish the post and if the article has already got tags then I will get a new
   Twitter post (as long as it’s not a duplicate) that contains the correct hash
   tags.
 * E.G two examples from my horse racing site today
 * The first one was sent at 5:35pm > [https://twitter.com/ukhorseracetips/status/395967181042618368](https://twitter.com/ukhorseracetips/status/395967181042618368)
 * New #Racing story Stratford blank 4 McCoy on [http://bit.ly/HrN2Gu](http://bit.ly/HrN2Gu)#
   HorseRacing #RacingNews
 * When I logged in as admin, re-edited and re-published it then I got this tweet
   > [https://twitter.com/ukhorseracetips/status/395976580842807296](https://twitter.com/ukhorseracetips/status/395976580842807296)
 * Stratford blank for AP McCoy > [http://bit.ly/HrN2Gu](http://bit.ly/HrN2Gu) #
   Stratford #APMcoy #Jezki #NationalHunt
 * As you can see if you go to the actual article the 2nd tweet is using the post
   tags attached to the article.
 * Everything was working fine up until a few days ago and I cannot think what has
   changed. I had to turn Omnisearch off on Jetpack due to it causing me issues 
   with one plugin but nothing major has changed.
 * Therefore I am thinking that the timings are out e.g the time it takes to scan
   the post and add the tweets before re-saving the article with new formatted HTML
   is too long and when the TweetBot plugin does its work there are no post tags
   for it to use which is why it reverts to the default ones.
 * This is why when I re-edit an already tagged post and re-publish the tweets have#
   hashtags related to the post tags.
 * Is the priority setting a real “chain” so if I had a job at 1 and another at 
   999 (like my 2 plugins) the 2nd job won’t even start running until any previous
   jobs have finished or is it a more parallel process OR even just a time based
   job e.g the priority 1 job starts 1 ms after publishing whilst the 999 job starts
   999 ms after publishing so if the 1st job isn’t finished tough luck?
 * I am just wondering what has happened here?
 * Any help much appreciated.

Viewing 15 replies - 1 through 15 (of 25 total)

1 [2](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/page/2/?output_format=md)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275850)
 * I’ve no idea what’s causing your problem, but I can explain filter priority. 
   The filter callbacks are stored in the global $wp_filter. The top level keys 
   are the filter tags, followed by priority number, the lowest level key is the
   callback function. The data stored is the callback function string and the number
   of arguments.
 * When `apply_filter()` is called, all array elements under the tag name key are
   sorted by the priority key, priority 1s are thus above priority 999. A do/while
   loop is executed on the priority key elements, so all priority 1s are processed
   before moving on to the next priority. For all callbacks of the same priority,
   they are each called in turn in a foreach loop where `call_user_func()` is applied
   to each callback.
 * I don’t know enough of multi-threading server architecture to authoritatively
   answer your question, but I know enough to hazard a reasonable guess. It is certainly
   not time based. I don’t believe it is totally linear, `call_user_func()` AFAIK
   does not need a return for the loop to continue and call the next callback. Nor
   do I believe it is completely parallel. The threads are not limitless. Once the
   pipeline is filled, a new thread cannot start until one is available.
 * Depending on what other filters are hooked to the same tag, it is conceivable
   for a 999 callback to begin execution nearly in parallel to a 1 callback. The
   1 callback may have been called first, but the 999 callback could conceivably
   begin execution only a ms afterwards, well before the 1 callback has completed.
 * Something else to consider is if some sort of caching is involved, the cache 
   may not be appropriately updated before some value is pulled from it.
 * Another possibility, though unlikely, is if you have upgraded to 3.7, you may
   have been auto-upgraded to 3.7.1. That may coincide with when your problems started.
   Mind you, this is very unlikely. Minor upgrades have been extremely smooth, causing
   virtually no issues, which is why auto-upgrades were implemented after careful
   consideration.
 * If the completion of one filter is dependent on the completion of another, you
   could create a custom action and hook the dependent callback to that action instead
   of the same filter. Thus the dependent callback cannot start until a `do_action()`
   call is only made after some important procedure is completed in the first callback.
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275960)
 * Hi
 * Thanks for replying, By the sounds of it it seems that it’s a not a total sequential
   process with every function in the array to be run waiting on a return / error
   code from that method before carrying on with futher functions.
 * The problem is that these are 2 seperate plugins so putting in a hook for one
   to wait for the other would either have to be an option for the user to select(
   if they used both plugins) or I could combine the plugins into one plugin. Whatever
   I need the TweetBot code to RUN after the AutoTagging code has completed and 
   not before completion..
 * Do you know how other plugin developers develop their code to work with other
   plugins?
 * E.G I know with WP Super Cache (which I use) there are some other plugins it 
   works with like WP Touch or Bad Behaviour.
 * Does the WP Super Cache plugin do database lookups for specific tables and values
   or is there a WordPress array of “plugins” that can be searched to find “active”
   or “de-active” plugins installed by the user?
 * If so that would be great as I could just offer an option and then check for 
   the existence of the other plugin and if it exists make the TweetBot run after
   the AutoTagging has finished 100%. I could still do it with custom wp_option 
   values I suppose but an array of “plugins” and related metadata would be good,
 * I think its down to to the the number of tags a site has as the more articles,
   the more tags which means more searching and reformatting of the text which causes
   the tagging process to take longer hence when TweetBot runs no tags exist EVEN
   if they do later when viewing the article.
 * I still get occassions when they both work together fine and the tweet contains
   relevant new post tags as #hashtags but I have no idea what causes these posts
   to work and the majority of others not to and hence fall back on the default 
   tweet options.
 * Basially I need the WP system to run the priority system sequentially and if 
   it doesn’t do this I am going to have to come up with a workaround.
 * By the wsy I am still on WP 3.6.1. I’ve been in Iceland for a while (sorry for
   the late reply) so I haven’t had a chance to reply or play about with installations.
   You help is much appreciated and any other Z|
    Thanks
 * Rob
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275964)
 * Hi
 * Just to let you know I have done some testing by running a feed import which 
   would take the article from the feed, scan it with plugin 1(priority 1) Strictly
   AutoTags and add relevant tags then (should) run plugin 2 (priority 999) to send
   off the tweets.
 * The TweetBot when it should be using post tags it coming up blank for them and
   instead using the default tags. I can only presume this is due to the tagging
   not having been completed at the time of sending out the tweet.
 * Therefore a workaround is required to ensure anyone with both plugins can get
   the TweetBot to run AFTER any taggng is done. Otherwise you are risking not getting
   the tags used as #hashtags in the tweets.
 * Not everyone has both plugins installed so I either combine the two or somehow“
   check” which other plugins are installed so I can do your hook suggestion or 
   use a temporary option value (scheduled timrt) to ensure the 2nd plugin only 
   runs after that timer doesn’t exist, eg set it when the 1st plugin runs, destory
   on finish then run the 2nd plugin.
 * All ideas welcome.
 * Thanks
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275974)
 * There is an array of active plugins, it’s stored in the options table under the
   key ‘active_plugins’. If the plugin causing issues is in this array, then you
   know additional measures are needed to properly integrate.
 * I don’t think there’s an easy answer to proper integration, it depends on the
   specifics of the conflict. There’s no standard way to know when a foreign hook
   callback has completed execution. However, if you examine the callback source
   code, there may be something it does that could act as a signal that it’s nearing
   completion. Perhaps the developer was kind enough to provide a filter hook similar
   to what we often see at the end of WP core functions 🙂
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275980)
 * Well seeing I am the developer of both plugins I am thinking of just creating
   some wp_option values that will let both plugins know of each others existence
   first.
 * Then if the AutoTag plugin exists I can add an action once the tagging is complete
   and then the TweetBot plugin can hook into it and only run when that action fires.
 * Be much simpler than merging the plugins.
 * Cheers!
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275981)
 * Hi
 * I don’t suppose you know if there is a way of determining within functions hooked
   to the save_post action whether the article being saved is also being published
   at the same time?
 * The problem I have is that at the moment I am doing my tagging on the save_post
   action hook so that you can get tags as a draft, edit or remove/add them before
   publishing the article.
 * However if I add a hook to the publish_post action (even with a higher priority)
   it runs BEFORE the save_post functions.
 * Therefore as I only want to Tweet when the post is being published and not when
   it’s just being saved as a draft I need to know the type of save being done.
 * I thought save_post would run before publish but it doesn’t seem to be that way.
 * I had some code to set an option (with the post id of the article being tagged
   in the name) and then in the publish hook a check for it so that if the tagging
   was still going on I would sleep for a bit (in a loop) until the tagging was 
   complete before calling the “finished_tagging” action which would delete the 
   option. Only on deletion (completion of the tagging) would my TweetBot run its
   job.
 * However because publish runs before save for some reason this doesn’t work as
   on the first loop iteration the check for the option_[postID] is always false(
   as its not been created yet) so it thinks the tagging has finished BEFORE its
   even started.
 * Therefore I need a way of knowing that the save_post is going to publish the 
   article not just save a private/draft version – within the save_post action itself.
 * Having the code run on multiple actions is problematic as it means the tagging
   runs multiple times e.g save/publish/post_syndicated_item and obviously I only
   want to tag it once. Then set some sort of flag to let my other plugin know I
   am publishing (if I am) so it can tweet.
 * Hope you get my drift.
 * Thanks
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275983)
 * I get your drift, though perhaps not the finer points, which may not matter. 
   I think there is something like what you’re looking for, more on that in a bit.
   First, what do you think of this approach:
 * The tweet plugin checks for the existence of an active tagging plugin. If not
   found, no problem, do the tweet thing on publish. If the tagging plugin is active,
   only do the tweet thing when a particular action on the tagging plugin fires,
   which only happens when the tagging process is complete?
 * So in pseudocode, the tagging plugin would be:
 *     ```
       do_tagging stuff();
       do_action('ssm_done_tagging');
       ```
   
 * And the tweet plugin in pseudocode:
 *     ```
       if ( tagging_plugin_installed()) add_action('ssm_done_tagging', 'do_tweet_stuff');
          else do_tweet_stuff();
       function do_tweet_stuff() {
          //actually do the tweet stuff!
       }
       ```
   
 * Regardless if you use my idea or not, you will want to ensure to only tweet on
   a single publish action. As it is, ‘save_post’ can fire multiple times for one‘
   Publish’ click, so hooking ‘save_post’ could result in multiple tweets, very 
   bad!
 * One way around this appears to be checking for certain conditions before doing
   anything. I just recently found this logic in a ‘save_post’ callback for saving
   meta box values:
 *     ```
       if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
             return $post_id;
       //code continues to save meta values
       ```
   
 * This appears to allow code to execute only once when hooked into ‘save_post’ 
   but I haven’t tested this. Unlike tweets, there’s no bad side effects from saving
   a value more than once.
 * Before finding that snippet, I had been using status transitions to run code 
   only once on initial publish and not on updates. I don’t know if you would want
   to retweet on updates, which would still happen on ‘save_post’ even with the 
   AUTOSAVE logic. To only run code on the initial publish, hook the action ‘draft_to_publish’.
   For other status variations hook ‘transition_post_status’ and inspect the old
   and new statuses (statii?) passed for a particular event. See the source code
   for `wp_transition_post_status()` to see how the statuses get worked into various
   action tags. You should surely find something that works for you. Even then, 
   it may be worth including the AUTOSAVE logic as well.
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275984)
 * Hi
 * Thanks for getting back to me so quickly.
 * I have just thought something that maybe causing the problem. However I don’t
   want to debug WP or re-instal old versions of WP to prove it one way or another.
 * The Tagging Plugin always runs on Save Post. However by default the plugin is
   set to ignore posts that already have tags against them so that you can choose
   to add your own tags. Therefore as soon as a post gets tags any future edits/
   saves wouldn’t re-scan and tag it.
 * However there is an option in admin that can be enabled to remove any existing
   tags and clean the HTML (remove links/bolding etc) before re-tagging them on 
   every save (I recommend this to be off but it can be enabled). So basically the
   plugin prevents re-tagging every time the post is edited/saved.
 * The Tweet Plugin however runs on Publish Post.
 * It uses a custom field once a tweet has been posted so that it knows not to re-
   tweet an article if it’s already been tweeted. You can delete this obviously 
   but remember Twitter also returns a “duplicate post” error message to prevent
   duplicate tweets being made to an account.
 * Therefore as my previous comment stated the publish post action seemed to run
   BEFORE the save post action (from the debug) which would explain why no tags 
   existed when the Tweet code ran.
 * I am just wondering IF in recent versions WordPress has changed their code so
   that the order or these 2 actions has either changed or become a parallel process
   rather than sequential. I.E it always used to run in this order **SavePost then
   PublishPost** which allowed my tagging to finish before tweeting. However now
   they run side by side when an article is being published.
 * Another thing could be that maybe I have hit some kind of limit in the number
   of tags that can be handled and scanned in a quick amount of time. My system 
   has 4680 tags so the code could be taking long to run that number of regular 
   expressions. So 3500 tags was fine but 4000 is too long in the time expected 
   of it.
 * This would also explain why when I go in as Admin, delete my Tweet custom field
   and re-save the published article, the Tweet goes out with hash tags made from
   my post tags DUE to the tags already existing.
 * I do like your idea of adding actions as I was just going to use transients or
   set/delete_option(‘currently_tagging_[post_id]’); whilst tagging an article (
   set one at start, delete at end, all unique as they use the ID field from wp_posts.)
 * I could then in my TweetBot check for this option value using get_transient/option
   and if its found, loop, wait, check, loop, wait… up to X times with a X second
   delay in the loop. Another option would be just to set a custom field once the
   post was auto tagged (even if no tags were found) so that the Tweet plugin does
   a similar loop/check/wait until this option appears. It can then delete it after
   tweeting (in case someone wanted to re-tag their posts – remember the tweetbot
   has its own field telling us whether a tweet was sent or not)
 * This would mean that if the post didn’t have tags or was in the process of tagging
   it wouldn’t tweet until it DID have tags OR got to the end of the loop/wait iteration
   where it would use the default tags/categories.
 * I always assumed publish post would be after save post (on new articles) but 
   it seems that this is not the case so I obviously need a way of knowing whether
   its a publish or just a save and to make my publish functions run AFTER any save
   methods.
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275986)
 * I find the WP terminolog for adding hooks and actions quite hard to understand
   sometimes, especially when reading other peoples “how to” articles. If they used
   common terminology such as “creating custom events” or running functions when
   WP events are fired like “onpublish” “onsave” etc then it would translate easier(
   for me at least 🙂 )
 * Therefore this code is split across both plugins and just involves the Tag plugin
   creating a new EVENT “on” finished_doing_tagging which gets fired when the Tag
   plugin has finished tagging.
 * The Tweet plugin needs to run ONLY and ALWAYS just on the “on” publish event.
   The logic decides whether it runs ASAP (if no tagging plugin exists) OR hooks
   into the “on” finished_doing_tagging EVENT before running the code to send Tweets
   out.
 *     ```
       // in my Tagging class in the method that tags the posts
       // tag them and save a flag
       public function save_tags( $post_id = null, $post_data = null ) {
   
       	global $wpdb;
   
       	$object = get_post($post_id);
       	if ( $object == false || $object == null ) {
       		return false;
       	}
   
       	// run my tagging code to add tags to the post
       	do_tagging($object);
   
       	// finished so set the custom field up
       	// so we know that we have already tweeted this post
       	add_post_meta($object->ID, 'strictlytweetbot_posted_tweet', '1', true);
   
       	// fire my custom event so any plugin wanting to run when tagging is completed can now do so
       	do_action('finished_doing_tagging');
   
       }
   
       Then in my TweetBot class I need to define <strong>which EVENT to use</strong> as our trigger for sending Tweets out.
   
       As as we only ever want to tweet on publishing an article not saving a draft we always and only ever call a function attached to the publish_post EVENT as this will determine whether to just carry on tweeting OR to wait for our new EVENT finished_doing_tagging before tweeting anything.
   
       public function __construct()
       {
       	// only ever want to tweet on a publish EVENT so always need to hook code into the event "ON" PUBLISH POST
       	add_action( 'publish_post', array(&$this, 'check_and_post_tweets') , 999);		
   
       }
   
       // always ensure the right method is called
       // if tagging plugin is active wait until tagging has finished and run the send tweet code if tags exist are
       protected function check_and_post_tweets($post_id = null, $post_data = null )
       {
       	global $wpdb;
   
       	// ensure we can get post ino
       	$object = get_post($post_id);
       	if ( $object == false || $object == null ) {
       		return false;
       	}
   
       	// check whether my tag plugin is installed and active by checking the array of active plugins and we havent tweeted already
       	if (is_plugin_active('strictly-autotags/strictlyautotags.class.php') && get_post_meta($post_id, 'posted_tweet', true) !== '1') {
   
       		// hook post_tweets into our finished_doing_tagging EVENT
       		add_action('finished_doing_tagging',array(&$this, 'post_tweets'),99);		
   
       	}else{
       		// just run normal tweet code
       		$this->post_tweets(array(&$this, 'post_tweets'));
       	}
       }
   
       // function to run when the EVENT finished_doing_tagging is fired OR no tagging plugin is running - it sends tweets out
       public function post_tweets($post_id = 0) {
   
       	// get info about the post
       	if($post_id == 0){
   
       		// no post ID!!!
       		return false;
   
       	// already tweeted for this post? If so exit
       	}else if(get_post_meta($post_id, 'posted_tweet', true) == '1'){
   
       		// post meta data says we have already posted so until custom field is deleted we cannot tweet again for this post
       		return false;
       	}
   
       	// format the tweet (more complex than this obviously)
       	$tweet = "blah #blah";
   
       	// call method that sends the tweet out
       	$this->send_tweet($tweet);
   
       	// update meta against tbis post so we know that we have already tweeted this post in case multiple events fire off
       	add_post_meta($post_id, 'strictlytweetbot_posted_tweet', '1', true);
       }
       ```
   
 * What do you think? Can you see any potential problems with this?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275987)
 * Actually, ‘publish_post’ fires before ‘save_post’, but there is literally two
   lines of code between the two, so the firings could be virtually simultaneous.
   The two lines are other `do_action()` calls, so depending what’s hooked in, there
   could in reality be some time between the two on some installations. It’s been
   this way as long as I’ve been involved with WP, v3.0 or so. For your own sanity,
   you should assume both callbacks are called simultaneously and structure your
   code accordingly. Even if the reality is different, this mental model should 
   lead to workable code.
 * I do see some potential issues, perhaps not really problems. First, are you sure‘
   publish_post’ only fires on initial post? My recollection is different, but I
   don’t recollect so well sometimes. Sounds like you’ve insured that even if it
   did, things would work out, which is wise insurance I think.
 * In your tagging script you indicate you are adding meta to signify **tweeting**
   has been completed. Surely you mean _tagging_ has been completed?
 * I think it would be more efficient to decide whether to hook ‘publish_post’ or‘
   finished_doing_tagging’ in `__construct()`. No need to go through ‘publish_post’
   again if doing tagging, as ‘finished_doing_tagging’ is essentially fired by ‘
   publish_post’ in the tagging module. (or is it, it’s not quite clear?) Your way
   is functionally the same, just not as efficient in my eyes. I do realize the 
   tagging is not always run, but there is always a callback execution to see if
   tagging should be done or not. It is the end of that routine where ‘finished_doing_tagging’
   should be fired. Maybe it’s not ‘publish_post’ but ‘save_post’, as long as you’ve
   protected against multiple tweeting for the same post in a way beyond selecting
   the correct action, it doesn’t matter much which action is the initial instigator
   of the whole process.
 * I agree WP terminology leaves something to be desired. ‘Event’ is much more understandable
   to most coders instead of ‘action hook’. And adding an event listener makes more
   sense than hooking a filter. But once understood, using the correct terminology
   goes a long ways when communicating with others. When someone says “this is my
   action hook” I know exactly what sort of code snippet they are presenting. If
   the were to say “this is my event listener” I may still understand, but there
   would be significant doubt in my mind that the person really knows what they 
   are talking about.
 * While such jargon is unfortunate for general communication, it does serve as 
   sort of a secret handshake for coders that says “Hey, I’m cool, you don’t have
   to coddle me like some noob, I know whats going on.” How people present their
   problem is all I have to go on for deciding at what expertise level I should 
   respond with. You can imagine, I’ve many times seriously misjudged so the next
   response is some variation of “Saaayyy whaaaa???” 😀
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275988)
 * Hi
 * Yes you are sort of right. I basically confused things by putting
 * a) code from two different plugins (tweet & autotag) into the same example code.
 * b) the custom field you mentioned was copied n pasted from the tweetbot plugin
   and I was going to use it to note whether tagging has completed but now I don’t
   need it. Also I forgot to change the name so it would have confused anyone reading
   it.
 * Basically I have got the two plugins working together and seamlessly (so no-one
   has to tick any boxes etc)
 * If the AutoTag plugin exists and is active then it shows in the admin panel with
   a disabled checkbox.
 * Basically I have just done this.
 * **Strictly AutoTags Plugin**
 * I have just added a new EVENT / Action into the **SaveAutoTags** method that 
   actually runs on **SavePost** (as you may want a draft and edit the tags before
   publishing). If tags already exist it fires straight away and if tagging has 
   to be carried out it the event is fired at the end of the tagging.
 * I have passed the Post ID in as a parameter as I see this is the only way that
   hooks can get the data they need without storing options etc.
 *     ```
       // fire in case tweetbot needs to tweet
       do_action('finished_doing_tagging', $object->ID);
       ```
   
 * **Strictly TweetBot Plugin**
 * I have changed the code fired on the publish event to call a new function that
   determines what action to take when an article is published.
 * By the way you are right I have put checks in to ensure tweets are not repeatedly
   fired including setting a custom field when they are, checks for dupes and of
   course Twitter usually prevents dupes now anyway.
 * This function does the following
 * a) checks whether a tweet can be sent in the first place by checking for a valid
   post ID, that the article is not a private post and ensure a tweet hasn’t already
   been sent by looking for my “posted_tweet” custom field.
 * b) if the AutoTag plugin is active and the article hasn’t been tweeted already
   then we wait for our “finished_doing_tagging” event/action to fire before running
   our post tweets method. If we have no tagging plugin we just run it ASAP.
 *     ```
       // called on on_publish e.g
       add_action( 'publish_post', array($this, 'CheckAndPostTweets') , 999);
   
       public function CheckAndPostTweets($post_id = 0){
   
       	// can we post a tweet anyway? Ensure post is valid
       	if($this->CanWePostTweets($post_id)){
   
       		// check whether my tag plugin is installed and active by checking the array of active plugins also double check we havent tweeted already
       		if (is_plugin_active('strictly-autotags/strictlyautotags.class.php') && get_post_meta($post_id, 'strictlytweetbot_posted_tweet', true) !== '1') {
   
       			// hook post_tweets into our finished_doing_tagging EVENT and wait til this fires before posting our tweets
       			add_action('finished_doing_tagging',array($this, 'PostTweets'),99,1);			
   
       		}else{
       			// no Strictly AutoTags so just post tweets now using either categories/post tags/default #hashtags
       			$this->PostTweets($post_id);
       		}
       	}
   
       	return;
       }
       ```
   
 * Therefore if the plugins need to run together they now run in the right order(
   tag the post -> send the tweets).
 * You are right publish does seem to run before save so I needed this hack to get
   the two to run in the right order as most of my tweets use automatically generated
   post tags in their tweets as #hashtags.
 * It is all working now anyway. You are right about the wording but coming from
   a C# and JavaScript background I am used to using the words event as it makes
   more sense to me.
 * -being able to run functions “on” an event that exists in the system onclick,
   onchange onblah etc
 * -being able to create your own custom events like ontweet or ontagged onblah 
   that can then be hooked into like standard events etc
 * Preference and semantics I suppose.
 * Thanks for your help anyway. The two are working together at the moment and I
   am just running it over night to see how they work together. At the moment all
   my Tweets which were using default #hashtags due to publish running before Save
   are now all using the post tags created by my AutoTag plugin.
 * It was all working up until a few weeks ago so I guess either a new version of
   WP (I only updated to 3.7.1 today by the way, straight from 3.6.1) or some limit/
   time / memory / cpu used by tagging articles and scanning them with thousands
   of tags (using regex) must have been breached.
 * It happens all the time in SQL, you use a [@temp](https://wordpress.org/support/users/temp/)
   table variable and it works a treat in a stored proc for a while until the data
   being put into it gets too large and suddenly the proc takes forever to run. 
   Answer = swap to a proper table/temporary table and add indexes etc.
 * Just a pain that I had to do it when it was working fine but it had to be done
   I suppose.
 * Thanks for your help.
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275990)
 * Hi
 * Just a follow up. I have checked after a nights running however I have found 
   something out.
 * This code I have done all seems to work fine when I am logged in as admin and
   either posting new articles myself OR running the import feed button from a custom
   WP-O-Matic plugin I put together.
 * However when an automated call to fire off feed imports runs (a WGET request 
   from my server to my site with a special key) the articles get loaded but no 
   tags get added and therefore no tweets go out.
 * The WP-O-Matic plugin adds new articles to the system with this code
 *     ```
       $postid = $this->insertPost($wpdb->escape($title), $wpdb->escape($content), $date, $categories, $campaign->posttype, $campaign->authorid, $campaign->allowpings, $campaign->comment_status, $meta);
       ```
   
 * which in turn calls
 *     ```
       function insertPost($title, $content, $timestamp = null, $category = null, $status = 'draft', $authorid = null, $allowpings = true, $comment_status = 'open', $meta = array())
         {
           $date = ($timestamp) ? gmdate('Y-m-d H:i:s', $timestamp + (get_option('gmt_offset') * 3600)) : null;
           $postid = wp_insert_post(array(
           	'post_title' 	            => $title,
         		'post_content'  	        => $content,
         		'post_content_filtered'  	=> $content,
         		'post_category'           => $category,
         		'post_status' 	          => $status,
         		'post_author'             => $authorid,
         		'post_date'               => $date,
         		'comment_status'          => $comment_status,
         		'ping_status'             => $allowpings
           ));
   
       		foreach($meta as $key => $value)
       			$this->insertPostMeta($postid, $key, $value);			
   
       		return $postid;
         }
       ```
   
 * I am guessing **wp_insert_post** triggers all the events/actions which are then
   hooked into.
 * Again – this all used to work together without a problem so I don’t know what
   has changed. However as on one site most of my articles are imported automatically
   I am obviously getting no tags / tweets.
 * The code above is fired whether the feed is imported OR run manually by myself
   from admin. So in theory (unless I don’t know something) this shouldn’t matter
   and the same logical flow should happen.
 * Feed Import -> Insert Article Post -> Fire Events -> Tagging Fires on SavePost-
   > Tweeting waits for the finished_doing_tagging event before tweeting -> tweets
   are sent out.
 * I am just wondering if some admin / security changes have occurred or something
   which might be effecting this. I know I haven’t put code in my plugins to prevent
   automated calls to them affecting their behaviour.
 * However I can only assume some sort of security issue is blocking this from happening
   somehow.
 * Any ideas?
 * Thanks for your help on this!
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275992)
 * I don’t know what is making this happen. I even set up a test feed with an article
   and ran the CRON job that fires WP-O-Matic. No tags were added and in the debug
   log file I created I couldn’t see any occurrence of the tagging code going on.
 * I have one site that is always adding tags but never in time for the tweetbot
   to use them – so it uses default tags (older versions of my plugin)
 * And now 2 new versions that add tags, use them and tweet them if posting as Admin
   or running WP-O-Matic Feed Fetcher as admin BUT no tags OR tweets when running
   automatically.
 * WordPress is sooooo much fun to work with!!! Everything was fine and then it 
   all goes tits up!
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4275999)
 * Well, that’s no good! 😯 WTF? (Sorry for the slow response, I was away for a 
   few days)
 * You are correct, `wp_insert_post()` is what fires the hooks you are using. Thus
   it really makes no sense how the posts could be inserted via CRON but your callbacks
   are not executed. While it wouldn’t explain the ‘save_post’ hook not firing, 
   if WP-O-Matic in any way plays with the post status or type fields in doing what
   it does, that could interfere with the ‘publish_post’ action. I’m really at a
   loss for any other explanation.
 * I wouldn’t know what else to suggest other than the usual deactivate all plugins,
   the activate one by one to see which one breaks the process. To take WP-O-Matic
   out of the equation, create a simple scheduled task that inserts some static 
   post data, the goal being to simply call `wp_insert_post()` from a CRON job without
   involving WP-O-Matic, as it could be the problem itself.
 *  Thread Starter [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * (@strictly-software)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/#post-4276005)
 * I must apologise first for bombarding you with data here but I thought the more
   info, debug, code etc I gave you the better it would be from your point of view.
 * First off I did as you said and created a basic test page that just called wp_insert_post
   and returned the post ID so I could call it from a CRON or manually from a GET
   request. The code is below.
 *     ```
       if(isset($_REQUEST['code']) && $_REQUEST['code'] == "test")
       {
       	ShowTestDebug("OK - LETS ROLL");
   
       	ShowTestDebug("load up wordpress");
   
       	// load up wordpress spaghetti
       	require_once($_SERVER["DOCUMENT_ROOT"] . "/wp-config.php");
   
       	//ShowDebug("doing cron");
   
       	global $wpdb;
   
       	// output all the various no cache headers eg pragma
       	nocache_headers();
   
       	$campaign_structure = array('main' => array(), 'rewrites' => array(),
                                         'categories' => array(), 'feeds' => array());
   
       	ShowTestDebug("Set Categories");
   
       	$categories = array();
   
       	// set categories up
       	$catid = get_cat_id("Internet");
       	if($catid > 0){
       		ShowTestDebug("ID for Internet is " . $catid );
       		$categories['categories'] = $catid ;
       	}
   
       	ShowTestDebug("Insert the post");
   
       	$title = "This is a test post! Ignore";
       	$content = "This is some test content CIA and the FBI and the Federal Reserve Bank of America is going to have trouble FED and CIA test ignore!";
   
       	$postid = insertPost($wpdb->escape($title), $wpdb->escape($content), null, $categories, "publish", 721, false, "open", array());
   
       	ShowTestDebug( "should be done");
   
       }else{
       	die("Wrong Code");
       }
   
         /**
          * Writes a post to blog
          *
          *
          * @param   string    $title            Post title
          * @param   string    $content          Post content
          * @param   integer   $timestamp        Post timestamp
          * @param   array     $category         Array of categories
          * @param   string    $status           'draft', 'published' or 'private'
          * @param   integer   $authorid         ID of author.
          * @param   boolean   $allowpings       Allow pings
          * @param   boolean   $comment_status   'open', 'closed', 'registered_only'
          * @param   array     $meta             Meta key / values
          * @return  integer   Created post id
          */
         function insertPost($title, $content, $timestamp = null, $category = null, $status = 'draft', $authorid = null, $allowpings = true, $comment_status = 'open', $meta = array())
         {
   
       	ShowTestDebug("in insertPost");
   
       	$date = ($timestamp) ? gmdate('Y-m-d H:i:s', $timestamp + (get_option('gmt_offset') * 3600)) : null;
   
       	ShowTestDebug("date is " . $date);
       	ShowTestDebug("categories are...");
       	ShowTestDebug($category);
       	ShowTestDebug("post status = " . $status);
       	ShowTestDebug("get post ID after we call wp_insert_post now");
   
       	$postid = wp_insert_post(array(
           	'post_title' 	            => $title,
         		'post_content'  	        => $content,
         		'post_content_filtered'  	=> $content,
         		'post_category'           => $category,
         		'post_status' 	          => $status,
         		'post_author'             => $authorid,
         		'post_date'               => $date,
         		'comment_status'          => $comment_status,
         		'ping_status'             => $allowpings
           ));
   
       	ShowTestDebug("new postID " . $postid );
   
       	return $postid;
   
         }
   
       function ShowTestDebug($msg){
   
       	if(is_array($msg)){
       		print_r($msg);
       	}else if(!empty($msg)){
       		echo htmlspecialchars($msg);
       	}
       	echo "<br />";
   
       }
       ```
   
 * With the old code (no hook when the **AutoTagging** finished for the Tweet to
   be sent out) the code worked in that
 * -It saved a post
    -It tagged it all -It sent a tweet although NOT with the post_tags–
   default tags were used instead (so obviously the action/hook didn’t work or it
   Tweeted before the post was saved)
 * The debug on the screen from that test page was the following (just outputting
   debug from my test file here NOT the AutoTag or Tweet plugins)
 * OK – LETS ROLL
    load up wordpress IN GetOptions cache user agent is NOT null 
   = Mozilla/5.0 ([http://www.strictly-software.com](http://www.strictly-software.com))
   Strictly TweetBot/1.1.2 Set Categories ID for Internet is 111 Insert the post
   in insertPost date is categories are… Array ( [categories] => 111 ) post status
   = publish get post ID after we call wp_insert_post now new postID 45273 should
   be done
 * When I put back the code with the hook in my AutoTagging function that the TweetBot
   should be linked to with my Action/Hook etc
 * // fire my custom event so any plugin wanting to run when tagging is completed
   can now do so pass in the post ID as the parameter so others can use it.
 * `do_action('finished_doing_tagging', $object->ID);`
 * The post was saved but with
 * -No tags
    -No tweet send at all (either with default fields or tags) -No custom
   field saved to say a tweet had been sent
 * The debug on the page is just this
 * OK – LETS ROLL
    load up wordpress Set Categories ID for Internet is 111 Insert
   the post in insertPost date is categories are… Array ( [categories] => 111 ) 
   post status = publish get post ID after we call wp_insert_post now
 * **..notice no post ID??**
 * I am guessing there might be some timer going on or something and that the code
   is waiting for the hook before tweeting or bombing out somewhere??
 * If I look in my error log file (I am logging both sets of debug to the same file
   instead of to the screen so I can see whats going on after the fact)
 * I can see that both plugins get instantiated A LOT – I guess thats WordPress 
   loading the same plugin files up on every page / or sections of pages even if
   they are not used etc.
 * I also see for my post (which is the correct post ID) this debug
 * IN TWEETBOT CONSTRUCT!
    IN GetOptions cache user agent is NOT null = Mozilla/
   5.0 ([http://www.strictly-software.com](http://www.strictly-software.com)) Strictly
   TweetBot/1.1.2 got options WE USE AUTOTAG AND POST ON TAG FINISHED TweetBot init
   finished IN CheckAndPostTweets for post id 45266 IN CanWePostTweets 45266 get
   post …notice no return value? Every branch of this function has debug so it should
   return a message e.g
 *     ```
       public function CanWePostTweets($post_id = 0) {
   
       	ShowTweetBotDebug("IN CanWePostTweets $post_id");
   
       	// no post ID? no tweet
       	if($post_id == 0){
       		ShowTweetBotDebug("No post ID!");
       		return false;
       	// already tweeted?
       	}else if(get_post_meta($post_id, 'strictlytweetbot_posted_tweet', true) == '1'){
       		ShowTweetBotDebug("already tweeted this post");
       		return false;
       	}
   
       	// get this far then bombs out???
       	ShowTweetBotDebug("get post");
   
       	// get post
       	$post = get_post($post_id);
   
       	// no post object so go
       	if ( $post == false || $post == null ) {
       		ShowTweetBotDebug("no post object");
       		return false;
       	}
   
       	// check for private posts OR posts added before the plugin was installed
       	if ($post->post_status == 'private'){
       		ShowTweetBotDebug("post is private");
       		return false;
       	}
   
       	// post was before install date - to post update the post date
       	if(!empty($this->install_date) && $post->post_date <= $this->install_date) {
       		ShowTweetBotDebug("before install date");
       		return false;
       	}
   
       	ShowTweetBotDebug("RETURN TRUE");
   
       	return true;
       }
       ```
   
 * I can see **no mention of the AutoTag plugin running at all** for that post.
 * However I can see lots of instances of the AutoTag class being initialised but
   no actual tagging which you would see from a debug message of
 * **IN SaveAutoTags **
 * For example this is some of the debug from the file
 * **IN AutoTag CONSTRUCT!**
    CALL SetValues SetValues finished setting values **
   IN TWEETBOT CONSTRUCT!** IN GetOptions cache user agent is NOT null = Mozilla/
   5.0 ([http://www.strictly-software.com](http://www.strictly-software.com)) Strictly
   TweetBot/1.1.2 got options WE USE AUTOTAG AND POST ON TAG FINISHED TweetBot init
   finished IN CheckAndPostTweets for post id 45266 IN CanWePostTweets 45266 get
   post RETURN TRUE returns true **IN AutoTag CONSTRUCT!** CALL SetValues SetValues
   finished setting values **IN TWEETBOT CONSTRUCT!** IN GetOptions cache user agent
   is NOT null = Mozilla/5.0 ([http://www.strictly-software.com](http://www.strictly-software.com))
   Strictly TweetBot/1.1.2 got options **WE USE AUTOTAG AND POST ON TAG FINISHED**
   TweetBot init finished **IN AutoTag CONSTRUCT!** CALL SetValues SetValues
 * **Lots of AutoTweet/TweetBot Init Constructors but no actual tagging going on!**
 * It’s **like the SavePost action is not being fired at all!** Which would explain
   why not tags, no tweet and no custom field are being created.
 * If I change the debug on both plugins so they output to the screen instead of
   the file (so I just get debug for this post, auto tagging and tweetbot) when 
   I run the test page I get the following debug (stripped out unimportant stuff
   like array outputs etc)
 * OK – LETS ROLL
    load up wordpress **IN AutoTag CONSTRUCT!** CALL SetValues SetValues
   finished setting values **IN TWEETBOT CONSTRUCT!** IN GetOptions cache user agent
   is NOT null = Mozilla/5.0 ([http://www.strictly-software.com](http://www.strictly-software.com))
   Strictly TweetBot/1.1.2 got options **WE USE AUTOTAG AND POST ON TAG FINISHED**
   TweetBot init finished Set Categories ID for Internet is 111 Insert the post 
   in insertPost date is categories are… Array ( [categories] => 111 ) post status
   = publish get post ID after we call wp_insert_post now **IN CheckAndPostTweets
   for post id 45277** **IN CanWePostTweets 45277** Have we posted tweet already
   check from get_post_meta returned get post RETURN TRUE returns true
 * .. then nothing?
 * No Tweets sent
    No tagging done No custom field set A post is saved though!
 * So the the AutoTag init is being fired but there is no mention of the SaveAutoTags
   method which should be fired by the wp_insert_post function call.
 * However if I go into the WP Admin, edit the post at the top of the page I have
   the AutoTag init debug e.g
 * IN AutoTag CONSTRUCT!
    CALL SetValues SetValues finished setting values
 * And if I save the post I get it tagged, a tweet is sent out and a custom field
   set
 * All the debug is below (I commented out as much as I could and bolded important
   parts)
 * **IN AutoTag CONSTRUCT!**
    CALL SetValues SetValues finished setting values IN
   TWEETBOT CONSTRUCT! IN GetOptions cache user agent is NOT null = Mozilla/5.0 (
   [http://www.strictly-software.com](http://www.strictly-software.com)) Strictly
   TweetBot/1.1.2 got options **WE USE AUTOTAG AND POST ON TAG FINISHED** TweetBot
   init finished **IN CheckAndPostTweets for post id 45277** **IN CanWePostTweets
   45277** Have we posted tweet already check from get_post_meta returned get post
   RETURN TRUE returns true **Strictly AutoTags is loaded so wait until the finished_doing_tagging**
   event fires for 45277 RETURN from CanWePostTweets **IN SaveAutoTags post id =
   45277** Do we need to clean any Strictly Goodness? IN CheckAndCleanTags we have
   131 of content no tags saved against post return 131 of content do we deeplink
   = 1 We are deep linking for tags that already have 10 posts associaed with them
   SELECT name,slug FROM wp_terms AS a JOIN wp_term_taxonomy AS c ON a.term_id =
   c.term_id WHERE ( c.taxonomy = ‘post_tag’ AND c.count >= 10 ); there are 1883
   tags with 10 or more posts against them now auto tag IN AutoTag our title is 
   This is a test post! Ignore IN FormatTitle = This is a test post! Ignore RETURN
   = This is a test post Ignore we have 0 search tags we found and 3403 tags from
   the DB look inside our title for terms our title is ‘This is a test post Ignore’
   IN SearchContentForTags This is a test post Ignore – tweak by 1000 tags normal
   tag scan now do the tag equiv IN SearchContentForTags This is a test post Ignore–
   tweak by 1000 equiv Tag equiv scan so we just searched our title now check html
   get other important tags now parse our main bit of content IN SearchContentForTags
   This is some test content CIA and the FBI and the Federal Reserve Bank of America
   is going to have trouble FED and CIA test ignore – tweak by 0 tags normal tag
   scan now do the tag equiv IN SearchContentForTags This is some test content CIA
   and the FBI and the Federal Reserve Bank of America is going to have trouble 
   FED and CIA test ignore – tweak by 0 equiv Tag equiv scan these are the tags 
   we need Array ( [CIA] => Array ( [term] => CIA [count] => 2 ) [FED] => Array ([
   term] => FED [count] => 1 ) [FBI] => Array ( [term] => FBI [count] => 1 ) [America]
   => Array ( [term] => America [count] => 1 ) [Federal Reserve Bank] => Array ([
   term] => Federal Reserve Bank [count] => 1 ) [Intelligence Agencies] => Array([
   term] => Intelligence Agencies [count] => 2 ) ) we are adding 6 to the system
   these are the tags we used Array ( [0] => CIA [1] => FED [2] => FBI [3] => America[
   4] => Federal Reserve Bank [5] => Intelligence Agencies ) we have 6 tags for 
   this post need to store existing A tags as we convert links and dont want nested
   and tag/bold words IN StoreContent direction = STORE match [youtube video] RETURN
   CONTENT == This is some test content CIA and the FBI and the Federal Reserve 
   Bank of America is going to have trouble FED and CIA test ignore! IN StoreContent
   direction = ADDTOSTORE convert text to links do we bold auto tags? == true call
   bold or deeplink tags lets auto bold tags IN AutoBold This is some test content
   CIA and the FBI and the Federal Reserve Bank of America is going to have trouble
   FED and CIA test ignore! we have 6 to bold lets loop through our post tags AutoBold
   finished look at how it would appear BOLDED RETURNS This is some test content
   <strong class=’StrictlyAutoTagBold’>CIA and the <strong class=’StrictlyAutoTagBold’
   >FBI and the <strong class=’StrictlyAutoTagBold’>Federal Reserve Bank of <strong
   class=’StrictlyAutoTagBold’>America is going to have trouble <strong class=’StrictlyAutoTagBold’
   >FED and <strong class=’StrictlyAutoTagBold’>CIA test ignore! auto link tags 
   = 1 lets auto link IN AutoLink put stored content back in IN StoreContent direction
   = RETURN RETURN CONTENT our new content is === This is some test content [CIA](http://www.mywebsite.com/tag/cia/)
   and the [FBI](http://www.mywebsite.com/tag/fbi/) and the <strong class=’StrictlyAutoTagBold’
   >Federal Reserve Bank of [America](http://www.mywebsite.com/tag/america/) is 
   going to have trouble [FED](http://www.mywebsite.com/tag/fed/) and [CIA](http://www.mywebsite.com/tag/cia/)
   test ignore! SQL is UPDATE wp_posts SET post_content = ‘This is some test content
   [CIA](http://www.mywebsite.com/tag/cia/) and the [FBI](http://www.mywebsite.com/tag/fbi/)
   and the <strong class=\’StrictlyAutoTagBold\’>Federal Reserve Bank of [America](http://www.mywebsite.com/tag/america/)
   is going to have trouble [FED](http://www.mywebsite.com/tag/fed/) and [CIA](http://www.mywebsite.com/tag/cia/)
   test ignore!’ WHERE id = 45277; should have been updated rows = 1 after set object
   terms **fire actions on finished_doing_tagging with post ID of 45277 IN PostTweets
   45277 got post title is This is a test post! Ignore DO TWEETING posting tweet
   for post: [http://www.mywebsite.com/2013/11/this-is-a-test-post-ignore/](http://www.mywebsite.com/2013/11/this-is-a-test-post-ignore/)
   Fire off request to [http://www.mywebsite.com/2013/11/this-is-a-test-post-ignore/](http://www.mywebsite.com/2013/11/this-is-a-test-post-ignore/)
   with useragent: to try and cache page before Twitter Rush Analyse content – type
   is ALL we need to check the content do we allow the post = Analyse content – 
   type is ANY we need to check the content do we allow the post = Analyse content–
   type is ANY we need to check the content do we allow the post = Analyse content–
   type is ALL we need to check the content do we allow the post = Analyse content–
   type is ANY we need to check the content do we allow the post = do we allow the
   post = 1 use post tags check 6 terms which we have current post title = This 
   is a test post! Ignore Tweet Shrink the title for this tweet IN TweetShrink This
   is a test post! Ignore shrink with API call to [http://tweetshrink.com/shrink?format=string&text=This+is+a+test+post%21+Ignore](http://tweetshrink.com/shrink?format=string&text=This+is+a+test+post%21+Ignore)
   return This is a test post! Ignore Strictly Shrink the title for this tweet using
   text speak IN StrictlyShrink This is a test post! Ignore current post title =
   ths is a test post! Ignore IN FormatTweet new story on mywebsite %title% %url%%
   hashtags% ,[http://bit.ly/1aOYpEJ](http://bit.ly/1aOYpEJ), ths is a test post!
   Ignore, #America #CIA #FBI #FED MaxLen is 137 IN ReplaceTitleTags ths is a test
   post! Ignore with #America #CIA #FBI #FED loop through tags RETURN ths is a test
   post! Ignore does ths is a test post! Ignore have #hashtags IN TrimTweet len 
   is 0 less than 139 chars long so return it now send this tweet == new story on
   mywebsite ths is a test post! Ignore [http://bit.ly/1aOYpEJ](http://bit.ly/1aOYpEJ)#
   America #CIA #FBI #FED to new article for mytweetaccount POST TWEET tweet sent
   ok SendTweet RETURNS 1 Save messages set a posted tweet custom field with the
   value 1 for strictlytweetbot_posted_tweet END OF AUTOTAG HOOK
 * So as you can see this all works fine! From within ADMIN!
 * It tags the appropriate words in the article e.g America, CIA, FBI, FED and then
   uses them in the tweet **#America #CIA #FBI #FED**
 * So whatever is happening is down to something to do with…
 * the** wp_insert_post not firing SavePost** when it is called automatically?
 * security preventing certain actions being called? However it did use to work.
 * too many tags and a time limit being set somewhere that is being broken preventing
   the tagging from working EVEN though I set unlimited in that call e.g
 *     ```
       public function SaveAutoTags( $post_id = null, $post_data = null ) {
   
       	set_time_limit(0);
   
       	ShowDebugAutoTag("IN SaveAutoTags post id = " . $post_id);
   
       	global $wpdb;
   
       	$object = get_post($post_id);
       	if ( $object == false || $object == null ) {
       		return false;
       	}
   
       	... tagging code
       }
       ```
   
 * something in the CRON job limiting the time?
 * something I have done wrong somewhere – in relation to the hooks/actions?
 * In the TweetBot init I have this code
 *     ```
       // set a function to run whenever posts are saved that will call our AutoTag function
       // so I can quickly over rule auto-tagging if it's going wrong!
       if(IGNOREAUTOTAG){
       	ShowTweetBotDebug("IGNORE AUTOTAG AND POST TWEETS ASAP");
       	add_action( 'publish_post', array($this, 'PostTweets') , 999);
       }else{
       	ShowTweetBotDebug("WE USE AUTOTAG AND POST ON TAG FINISHED");
       	add_action( 'publish_post', array($this, 'CheckAndPostTweets') , 999);
       }
       ```
   
 * Then in the CheckAndPostTweets I have this (which calls the CanWePostTweets function
   I posted up above)
 *     ```
       /**
        * Checks whether we hook into the AutoTag plugin
        *
        */
       public function CheckAndPostTweets($post_id = 0){
   
       	ShowTweetBotDebug("IN CheckAndPostTweets for post id " . $post_id);
   
       	if($this->CanWePostTweets($post_id)){	
   
       		// check whether my tag plugin is installed and active by checking the array of active plugins and we havent tweeted already
       		if (is_plugin_active('strictly-autotags/strictlyautotags.class.php') && get_post_meta($post_id, 'strictlytweetbot_posted_tweet', true) !== '1') {
   
       			ShowTweetBotDebug("Strictly AutoTags is loaded so wait until the finished_doing_tagging event fires for $post_id");
   
       			// hook post_tweets into our finished_doing_tagging EVENT
       			add_action('finished_doing_tagging',array($this, 'PostTweets'),99,1);			
   
       		}else{
   
       			ShowTweetBotDebug("no Strictly AutoTags and no tags/categories so just post tweets now for $post_id");
   
       			// just run normal tweet code to tweet NOW
       			$this->PostTweets($post_id);
       		}
   
       	}else{
   
       		ShowTweetBotDebug("We dont tweet for this post! CanWePostTweets returns false");
       	}
   
       	ShowTweetBotDebug("RETURN from CanWePostTweets");
   
       	return;
       }
       ```
   
 * Is it something to do with how classes are called, objects passed by reference
   and so on?
 * Also what is the best way to init my plugins? I notice from the debug to the 
   log file that these class inits get called A LOT.
 * I used to just put this code underneath the bottom of my code to call the class
   e.g
 *     ```
       class StrictlyAutoTags{
       	..code
       }
   
       // create auto tag object
       $strictlyautotags = new StrictlyAutoTags();
       ```
   
 * Now I use a “Control class” with a singleton to try and reduce the amount of 
   calls e.g
 *     ```
       class StrictlyAutoTagControl{
   
       	// global internal object so if one exists we don't keep creating a new object
       	private static $StrictlyAutoTag;
   
       	/**
       	 * Init is called on every page not just when the plugin is activated and creates an instance of my strictly autotag class if it doesn't already exist
       	 *
       	 */
       	public static function Init(){
   
       		// if class object doesn't already exist
       		if(!isset(StrictlyAutoTagControl::$StrictlyAutoTag)){
       			// create object and store for next time
       			StrictlyAutoTagControl::$StrictlyAutoTag = new StrictlyAutoTags();
       		}
   
       	}
   
       	/**
       	 * Called when plugin is deactivated and removes all the settings related to the plugin
       	 *
       	 */
       	public static function Deactivate(){
       		..code
       	}
   
       	/**
       	 * Called when plugin is deactivated and removes all the settings related to the plugin
       	 *
       	 */
       	public static function Activate(){
       		..code
       	}
   
       }
   
       // register my activate hook to setup the plugin
       register_activation_hook(__FILE__, 'StrictlyAutoTagControl::Activate');
   
       // register my deactivate hook to ensure when the plugin is deactivated everything is cleaned up
       register_deactivation_hook(__FILE__, 'StrictlyAutoTagControl::Deactivate');
   
       add_action('init', 'StrictlyAutoTagControl::Init');
       ```
   
 * What is the best way of calling plugin objects to prevent them being initialised
   when they are not needed? Also to keep the correct data within each object as
   from the log file output there was a lot of class init going on.
 * Now I am wondering if it’s something to do with the interaction between the way
   these two classes are calling each other and so on.
 * I am almost at the point of throwing my AutoTagging code into my custom WP-O-
   Matic so that it does the tagging BEFORE it calls wp_insert_post and then any
   tweets will ALWAYS come after the post is saved.
 * Apart from that I am lost for ideas.
 * Any thoughts?

Viewing 15 replies - 1 through 15 (of 25 total)

1 [2](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/page/2/?output_format=md)

The topic ‘How does the priority parameter work?’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [priority](https://wordpress.org/support/topic-tag/priority/)
 * [timing](https://wordpress.org/support/topic-tag/timing/)
 * [twitter](https://wordpress.org/support/topic-tag/twitter/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 25 replies
 * 2 participants
 * Last reply from: [strictly-software](https://wordpress.org/support/users/strictly-software/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/how-does-the-priority-parameter-work/page/2/#post-4276054)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
