I have a multi-author baseball site. I want authors to be able to schedule posts to be published at one of four selected times each day. This is important because some authors write game recaps, and an auto-publish of a game recap once the following game has started is pretty worthless.
I am looking for a plugin to manage this. Through research I have found a few plugins that will pick a time between a set of times set by the admin, but I am looking for something where the Admin can set up a calendar of days/times (or range of times) to allow a post to be published and set a max number of post for each time
The Author writes his post, then is presented with a selection of dates/times to schedule the post to publish.
As I mentioned, there are similar plugins, but none I have found allow Admins to set specific times.
Does anyone know of a plugin or other method? The plugin doesn’t need to be free.
Update with “Vision”
Admin settings: Set dates allowed for post publishing. Set times allowed for post publishing. Set number of posts allowed to be scheduled to publish at each time (if scheduling number has been met per slot it will not be shown to Author).
Author scheduling options: “Publish” button not present. Must choose day of the week to publish post >> Must select from available times to publish post.
My approach is to create an hourly cron event that loops through all the draft status posts and checks for the publish month – date and hour saved in post_meta and publishes if scheduled date is not in the future.
A publish date and time select meta box is added to the publishing div that updates via ajax when a time is chosen.
Update:
Added plugin and date picker css to git: https://github.com/c3mdigital/WP-Schedule
Changed cron function to use timezone configured in WordPress for publishing.
Update:
The date and time will be stored in post_meta as an array:
month' => 'string', time => int
The time integer will be a value that represents an hour of the day 1-24.The options screen has 3 inputs.
I added a jQuery UI Date picker to the post edit screen that is restricted to the dates chosen in the admin. The date and time are updated and saved using ajax.
Updated Plugin Code:
@Todo: Create validation function for saving the options, Create a count option that stores how many posts are scheduled for each time to restrict those times once full, and clean up & document the code.
Here’s my take: https://github.com/stephenh1988/Restrict-Publish
This will be made into a proper plug-in and some point. At the moment, it ‘works’ – but you manually configure the plug-in variables (i.e, no admin options yet).
All restrictions apply to users without the capability to
manage_options
(i.e. admins). But this could be altered as well.The UI
The idea is to load javascript after the WP loads
post.js
(this includes the java-script that controls altering the time input. The plug-in over-rides this, clicking ‘edit’ for the publish time instead opens up a jQuery UI date-time picker.The date-time picker only allows certain dates to be available given some rules (see below). All other dates are not selectable. On selecting the a date/time the appropriate WordPress fields are updated – and so WordPress handles the rest of the processing.
So this part of the plug-in only really prevents certain dates being inputed.
(The date-time picker is positioned a bit too low – something that can be smartened up using jQuery ui positioning).
Server-side checks
It also performs a check on
save_post
– just in case (js disabled? hack by user?) a ‘forbidden’ date is selected, thesave_post
callback checks the date again. If it is found to be invalid, the post is ‘prevented’ from being published/scheduled (as per this answer) and instead returned to draft status. A custom message appears (this message can be changed by setting$fail_message
currently).The rules
These are very basic. The set of rules kept in an
$allows
array:‘days_in_week’ is an array of integers to indicate which days (0=sunday, 1=monday) the user can publish dates on. Similarly ‘months_in_year’ stores an array of allowed months (1=january,…). Extra rules could be added quite easily (including a shortlist of admin-specified dates).
Limiting scheduled post
There is also a
$limit
variable which limits the number of scheduled posts a user can have. If they reach that limit, they loose the capability to publish (instead having to submit it for review – you could remove the right to even create posts, but that would prevent editing as well).The plug-in code
See this GitHub Repro: https://github.com/stephenh1988/Restrict-Publish