Wordpress Hooks For Responding to Post Content - hook

This is a followup to my question about programmatically adding wordpress categories based on post content.
Which hook (or hooks) are most appropriate for use in a function or plugin that requires access to the content of a post seeks to run code at the time that post is committed to the database?
The former question led to the suggestion of using the edit_post hook. However my reading makes me wonder if I should use publish_post or save_post instead, or, indeed, if there is an even better option out there that I am not considering.
What, exactly, is the difference between these three hooks? If I want something to run at the time a post is made AND at the time any edits are made, is there one of these that encompasses both events, or do I need to tie in to multiple hooks?

save_post is the most reliable single method that you're looking for. More details here: Details
publish_post does not fire if you save a post as a draft or schedule it to be published later. Details
edit_post is not fired in the case where a new post is created. However, edit_post is fired at many other times like when a new comment is created/edited etc. Details

Related

Subscribe to google forms program submit without ownership

With the wake of the pandemic causing schools to go to distance learning, many classes take attendance by using a simple google form sent out to students to complete for each class everyday. While this seems like a simple solution, it is a pain for students to complete and keep track of. One way that I thought I could make this easier would be to keep track of which forms I have submitted everyday.
As of now, my problem is that I need a way to subscribe to the submit of a google form (based on a link). When that google form is submitted all I need to do is find a way to convey that to a program. What I do not understand is how I would be able to do that without having ownership of the form or make a teacher recreate the form. Is there a way that I can check if a google form has been submitted?
A couple of ideas I have had would be to sniff network traffic for a post request from a google form and get that link and compare it to other links in the program to see which one was submitted, but I would think there is an easier way to do this. Any ideas or code is welcomed.
I understand stack overflow is for already written code so if you do not agree with this post either ignore it or point me to the correct place where this should be posted. Thank you.

How to create a slackbot that notifies me if a post someone wrote is not answered after a period of time?

Hello this is my first time attempting to create a slackbot using this resource https://botkit.ai/ , the slackbot I am trying to create should notify me if someone' post on a slack channel is not answered after a period of time,say after 30 minutes
So far I have been able to make my slackbot respond to specific keywords
//make slackbot hear for specific keywords and then reply without directly being mentioned
let now = new Date()
controller.hears(['help', 'I need help', 'stuck', 'question'],['ambient'], function (bot,message) {
// do something to respond to message.
bot.reply(message,'Hello <#'+message.user+'> someone needs help!' );
});
At first I was hoping that botkit already had some time tracking features, but it doesn't seem like it does, how can I make my slackbot notify me of posts that have not been answered after a specific period of time??
I would look into storing state someplace. You can query for the messages in a channel and then store off when they were posted. Then, every minute (or more, depending on your needs), you can run through all those and see if they were answered. Now, it is going to be hard to know what "answered" means, unless you can control that answers are either:
in a thread keyed off the question
reference the original question via a link
tag the original question asker (and then you'd have an issue if someone asked two questions in a row)
marked with a token (like 'ANSWERED') (and then you'd have the same issue as the tag solution)
I can't think of any other way to associate an answer with a question.
Anyway, you can store off the time in a database, google spreadsheet or other solution (depending on where you are running your node code). I'm not familiar with botkit, but Transposit (disclosure, I work for them) has integration with Slack and with Google Sheets, and is free to use.

When a notification feed unfollows a flat feed, are activities removed?

The title pretty much says it all, but I'll repeat in the body with more detail.
When notification feed notification:user1 follows flat feed posts:user2, activities are copied from posts:user2 to notification:user1. The precise number of activities to be copied can be optionally specified by passing an activityCopyLimit integer.
However, when a feed unfollows another feed, there is no similar option to control this behavior. The documentation simply states:
Existing activities in the feed coming from the target feed will be purged (asynchronously)
So my question is: is this also the case when it comes to notification feeds?
Whether it is or not, the option to not purge activities would be very useful. Just because a user no longer needs to receive activities from a given feed doesn't necessarily mean that the history of what has been received should disappear.
Thanks much.
It is possible to not purge the history when unfollowing feeds using the keep_history parameter. This feature is still not available on all official clients but it is described in the API rest documentation. The parameter needs to be provided as part of the query parameters and have value true or 1. If your client is not yet supported, you should open a ticket on its Github repository.
This is currently not possible, the feed will always be purged. I do understand your use case and we will consider adding this feature to our roadmap.

Instagram API media/popular

What are the queries we can use with media/popular. Can we localize it according to country or geolocation?
Also is there a way to get the discovery feature's results with the api?
This API is no longer supported.
Ref : https://www.instagram.com/developer/endpoints/media/
I was recently struggling with same problem and came to conclusion there is no other way except the hard one.
If you want location based popular images you must go with location endpoint.
https://api.instagram.com/v1/locations/214413140/media/recent
This link brings up recent media from custom location, key being the location-id. Your job is now to follow simple pagination api and merge responded arrays into one big bunch of JSON. $response['pagination']['next_max_id'] parameter is responsible for pagination, so you simply send every next request with max_id of previous request.
https://api.instagram.com/v1/locations/214413140/media/recent?max_id=1093665959941411696
End result will depend on the amount of information you gathered. In the end you will just gonna need to sort the array with like count and you're up to go whatever you were going to do.
Of course important part is to save images locally rather than generating every time user opens the webpage. Reason being not only generation time but limited amount of requests per hour.
Hope someone will come up better solution or Instagram API will finally support media/popular by location.

JAVAFX8 updating controls models?

UI Control such as LISTVIEW or Tree or ... comes with model that is observable.
When one make a change to that model, I suppose JavaFX knows how to refresh it automatically in the display.
However my question here is as follows:
Is it the intent way, that someone who wants to update and not replace this model, do so in a background thread with a platform.runlater.
In other words, one has some serious computation to do, and needs to to update an ObservableList as a result. Is it the intended way, to do the heavy work in a background thread and at the end of it, run the update in a platform run later?
I'm asking this because this is what I have been doing so far without problem. But from my reading here and there, in particular in
http://docs.oracle.com/javase/8/javafx/api/javafx/concurrent/Task.html
It seems that some other mechanism shall be used. One should rather return a full list instead of updating the observable list.
But this works only if things comes from the GUI. In case the update is triggered from the back end, there is no way to do so.
The solution that I have used so far, was always to hold a reference to the observable list and updating it by means of platform.Runlater.
Is there any other way ?
The link you give has an example (the PartialResultsTask) that does as you describe: it updates an existing ObservableList as it progresses via a call to Platform.runLater(). So this is clearly a supported way of doing things.
For updating from the back end (i.e. from a class unaware that the data are being used in a UI), you'd really have to post some code for anyone to be able to help. But you might have a look at the techniques used in this article. While he doesn't actually update lists from the backend in the examples there, the same strategy could be used to do so.

Resources