mirror of
https://github.com/felixfoertsch/wordpress-dev-env.git
synced 2026-04-20 16:22:57 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{{description}}
|
||||
Copyright (C) {{year}} {{fullname}}
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -0,0 +1,93 @@
|
||||
|
||||
@keyframes crontrol-rotating {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.crontrol-rotating {
|
||||
animation: crontrol-rotating 3s linear infinite;
|
||||
}
|
||||
|
||||
table.wp-list-table {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
table-layout: auto;
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
-ms-overflow-style: -ms-autohiding-scrollbar;
|
||||
}
|
||||
|
||||
.wp-list-table pre {
|
||||
white-space: pre-wrap;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.wp-list-table code {
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.wp-list-table td.column-status {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.wp-list-table td.column-cb,
|
||||
.wp-list-table tbody th {
|
||||
border-left: 4px solid transparent;
|
||||
}
|
||||
|
||||
.wp-list-table tr.crontrol-no-action th,
|
||||
.wp-list-table tr.crontrol-stalled th,
|
||||
.wp-list-table tr.crontrol-warning th {
|
||||
border-color: #ffb900;
|
||||
}
|
||||
|
||||
.wp-list-table tr.crontrol-error th {
|
||||
border-color: #dc3232;
|
||||
}
|
||||
|
||||
#crontrol-hash-message {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.status-crontrol-complete,
|
||||
.wp-list-table tr.crontrol-complete td.column-status {
|
||||
color: #080;
|
||||
}
|
||||
|
||||
.status-crontrol-no-action,
|
||||
.status-crontrol-stalled,
|
||||
.status-crontrol-warning,
|
||||
.wp-list-table tr.crontrol-no-action td.column-status,
|
||||
.wp-list-table tr.crontrol-stalled td.column-status,
|
||||
.wp-list-table tr.crontrol-warning td.column-status {
|
||||
color: #c60;
|
||||
}
|
||||
|
||||
.status-crontrol-emergency,
|
||||
.status-crontrol-alert,
|
||||
.status-crontrol-critical,
|
||||
.status-crontrol-error,
|
||||
.wp-list-table tr.crontrol-error td.column-status {
|
||||
color: #a00;
|
||||
}
|
||||
|
||||
.wp-list-table .column-https,
|
||||
.wp-list-table .column-queries,
|
||||
.wp-list-table .column-time {
|
||||
text-align: end;
|
||||
}
|
||||
|
||||
.column-time,
|
||||
.column-ran,
|
||||
.column-crontrol_next {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.row-actions .in-use {
|
||||
color: #666;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Functionality related to Crontrol.
|
||||
*
|
||||
* @package wp-crontrol
|
||||
*/
|
||||
|
||||
const header = document.getElementById( 'crontrol-header' );
|
||||
const wpbody = document.getElementById( 'wpbody-content' );
|
||||
let hashtimer = null;
|
||||
|
||||
if ( header && wpbody ) {
|
||||
wpbody.prepend( header );
|
||||
}
|
||||
|
||||
if ( window.wpCrontrol && window.wpCrontrol.eventsHash && window.wpCrontrol.eventsHashInterval ) {
|
||||
hashtimer = setInterval( crontrolCheckHash, ( 1000 * window.wpCrontrol.eventsHashInterval ) );
|
||||
}
|
||||
|
||||
function crontrolCheckHash() {
|
||||
jQuery.ajax( {
|
||||
url: window.ajaxurl,
|
||||
type: 'post',
|
||||
data: {
|
||||
action: 'crontrol_checkhash',
|
||||
},
|
||||
dataType: 'json',
|
||||
} ).done( function( response ) {
|
||||
if ( response.success && response.data && response.data !== window.wpCrontrol.eventsHash ) {
|
||||
jQuery( '#crontrol-hash-message' ).slideDown();
|
||||
|
||||
if ( hashtimer ) {
|
||||
clearInterval( hashtimer );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
# WP Crontrol #
|
||||
|
||||
Contributors: johnbillion, scompt
|
||||
Tags: cron, wp-cron, crontrol, debug
|
||||
Requires at least: 4.1
|
||||
Tested up to: 5.4
|
||||
Stable tag: 1.8.5
|
||||
Requires PHP: 5.3
|
||||
|
||||
WP Crontrol lets you view and control what's happening in the WP-Cron system.
|
||||
|
||||
## Description ##
|
||||
|
||||
WP Crontrol lets you view and control what's happening in the WP-Cron system. From the admin screens you can:
|
||||
|
||||
* View all cron events along with their arguments, recurrence, callback functions, and when they are next due.
|
||||
* Edit, delete, and immediately run any cron events.
|
||||
* Add new cron events.
|
||||
* Bulk delete cron events.
|
||||
* Add, edit, and remove custom cron schedules.
|
||||
|
||||
The admin screen will show you a warning message if your cron system doesn't appear to be working (for example if your server can't connect to itself to fire scheduled cron events).
|
||||
|
||||
### Usage ###
|
||||
|
||||
1. Go to the `Tools → Cron Events` menu to manage cron events.
|
||||
2. Go to the `Settings → Cron Schedules` menu to manage cron schedules.
|
||||
|
||||
## Frequently Asked Questions ##
|
||||
|
||||
### What's the use of adding new cron schedules? ###
|
||||
|
||||
Cron schedules are used by WordPress and plugins for scheduling events to be executed at regular intervals. Intervals must be provided by the WordPress core or a plugin in order to be used. As an example, many backup plugins provide support for periodic backups. In order to do a weekly backup, a weekly cron schedule must be entered into WP Crontrol first and then a backup plugin can take advantage of it as an interval.
|
||||
|
||||
### How do I create a new cron event? ###
|
||||
|
||||
There are two steps to getting a functioning cron event that executes regularly. The first step is telling WordPress about the hook. This is the part that WP Crontrol was created to provide. The second step is calling a function when your hook is executed.
|
||||
|
||||
*Step One: Adding the hook*
|
||||
|
||||
In the Tools → Cron Events admin panel, click on the "Add Cron Event" tab and enter the details of the hook. You're best off having a hookname that conforms to normal PHP variable naming conventions. The event schedule is how often your hook will be executed. If you don't see a good interval, then add one in the Settings → Cron Schedules admin panel.
|
||||
|
||||
*Step Two: Writing the function*
|
||||
|
||||
This part takes place in PHP code (for example, in the `functions.php` file from your theme). To execute your hook, WordPress runs an action. For this reason, we need to tell WordPress which function to execute when this action is run. The following line accomplishes that:
|
||||
|
||||
add_action( 'my_hookname', 'my_function' );
|
||||
|
||||
The next step is to write your function. Here's a simple example:
|
||||
|
||||
function my_function() {
|
||||
wp_mail( 'hello@example.com', 'WP Crontrol', 'WP Crontrol rocks!' );
|
||||
}
|
||||
|
||||
### How do I create a new PHP cron event? ###
|
||||
|
||||
In the Tools → Cron Events admin panel, click on the "Add PHP Cron Event" tab. In the form that appears, enter the schedule and next run time in the boxes. The event schedule is how often your event will be executed. If you don't see a good interval, then add one in the Settings → Cron Schedules admin panel. In the "Hook code" area, enter the PHP code that should be run when your cron event is executed. You don't need to provide the PHP opening tag (`<?php`).
|
||||
|
||||
### Which users can manage cron events and schedules? ###
|
||||
|
||||
Only users with the `manage_options` capability can manage cron events and schedules. By default, only Administrators have this capability.
|
||||
|
||||
### Which users can manage PHP cron events? Is this dangerous? ###
|
||||
|
||||
Only users with the `edit_files` capability can manage PHP cron events. This means if a user cannot edit files on the site (eg. through the Plugin Editor or Theme Editor) then they cannot edit or add a PHP cron event. By default, only Administrators have this capability, and with Multisite enabled only Super Admins have this capability.
|
||||
|
||||
If file editing has been disabled via the `DISALLOW_FILE_MODS` or `DISALLOW_FILE_EDIT` configuration constants then no user will have the `edit_files` capability, which means editing or adding a PHP cron event will not be permitted.
|
||||
|
||||
Therefore, the user access level required to execute arbitrary PHP code does not change with WP Crontrol activated.
|
||||
|
||||
### Are any WP-CLI commands available? ###
|
||||
|
||||
The cron commands which were previously included in WP Crontrol are now part of WP-CLI (since 0.16), so this plugin no longer provides any WP-CLI commands. See `wp help cron` for more info.
|
||||
|
||||
## Screenshots ##
|
||||
|
||||
1. New cron events can be added, modified, deleted, and executed<br>
|
||||
|
||||
2. New cron schedules can be added, giving plugin developers more options when scheduling events<br>
|
||||
|
||||
## Changelog ##
|
||||
|
||||
### 1.8.5 ###
|
||||
|
||||
* Fix an issue with the tabs in 1.8.4.
|
||||
|
||||
### 1.8.4 ###
|
||||
|
||||
* Add a warning message if the default timezone has been changed. <a href="https://github.com/johnbillion/wp-crontrol/wiki/PHP-default-timezone-is-not-set-to-UTC">More information</a>.
|
||||
* Fixed string being passed to `strtotime()` function when the `Now` option is chosen when adding or editing an event.
|
||||
|
||||
### 1.8.3 ###
|
||||
|
||||
* Fix the editing of events that aren't currently listed on the first page of results.
|
||||
|
||||
### 1.8.2 ###
|
||||
|
||||
* Bypass the duplicate event check when manually running an event. This allows an event to manually run even if it's due within ten minutes or if it's overdue.
|
||||
* Force only one event to fire when manually running a cron event.
|
||||
* Introduce polling of the events list in order to show a warning when the event listing screen is out of date.
|
||||
* Add a warning for cron schedules which are shorter than `WP_CRON_LOCK_TIMEOUT`.
|
||||
* Add the Site Health check event to the list of persistent core hooks.
|
||||
|
||||
|
||||
### 1.8.1 ###
|
||||
|
||||
* Fix the bottom bulk action menu on the event listing screen.
|
||||
* Make the timezone more prominent when adding or editing a cron event.
|
||||
|
||||
### 1.8.0 ###
|
||||
|
||||
* Searching and pagination for cron events
|
||||
* Ability to delete all cron events with a given hook
|
||||
* More accurate response messages when managing events (in WordPress 5.1+)
|
||||
* Visual warnings for events without actions, and PHP events with syntax errors
|
||||
* Timezone-related clarifications and fixes
|
||||
* A more unified UI
|
||||
* Modernised codebase
|
||||
|
||||
|
||||
### 1.7.1 ###
|
||||
|
||||
* Correct the PHP.net URL for the `strtotime()` reference.
|
||||
|
||||
### 1.7.0 ###
|
||||
|
||||
* Remove the `date` and `time` inputs and replace with a couple of preset options and a plain text field. Fixes #24 .
|
||||
* Ensure the schedule name is always correct when multiple schedules exist with the same interval. Add error handling. Fixes #25.
|
||||
* Re-introduce the display of the current site time.
|
||||
* Use a more appropriate HTTP response code for unauthorised request errors.
|
||||
|
||||
|
||||
### 1.6.2 ###
|
||||
|
||||
* Remove the ability to delete a PHP cron event if the user cannot edit files.
|
||||
* Remove the `Edit` link for PHP cron events when the user cannot edit the event.
|
||||
* Avoid a PHP notice due to an undefined variable when adding a new cron event.
|
||||
|
||||
### 1.6.1 ###
|
||||
|
||||
* Fix a potential fatal error on the cron events listing screen.
|
||||
|
||||
### 1.6 ###
|
||||
|
||||
* Introduce bulk deletion of cron events. Yay!
|
||||
* Show the schedule name instead of the schedule interval next to each event.
|
||||
* Add core's new `delete_expired_transients` event to the list of core events.
|
||||
* Don't allow custom cron schedules to be deleted if they're in use.
|
||||
* Add links between the Events and Schedules admin screens.
|
||||
* Add syntax highlighting to the PHP code editor for a PHP cron event.
|
||||
* Styling fixes for events with many arguments or long arguments.
|
||||
* Improvements to help text.
|
||||
* Remove usage of `create_function()`.
|
||||
* Fix some translator comments, improve i18n, improve coding standards.
|
||||
|
||||
### 1.5.0 ###
|
||||
|
||||
* Show the hooked actions for each cron event.
|
||||
* Don't show the `Delete` link for core's built-in cron events, as they get re-populated immediately.
|
||||
* Correct the success message after adding or editing PHP cron events.
|
||||
* Correct the translations directory name.
|
||||
|
||||
### 1.4 ###
|
||||
|
||||
- Switch to requiring cron event times to be input using the site's local timezone instead of UTC.
|
||||
- Add the ability for a PHP cron event to be given an optional display name.
|
||||
- Better UX for users who cannot edit files and therefore cannot add or edit PHP cron events.
|
||||
- Terminology and i18n improvements.
|
||||
|
||||
|
||||
### 1.3.1 ###
|
||||
|
||||
- Display a less scary looking message when `DISABLE_WP_CRON` is defined.
|
||||
- Correct the example code for cron event arguments.
|
||||
|
||||
|
||||
### 1.3 ###
|
||||
|
||||
- Improvements to the UI.
|
||||
- More error detection when testing WP-Cron functionality.
|
||||
- Improve the capability checks for single site and multisite.
|
||||
- Lots of escaping and sanitising.
|
||||
- Fix various issues with multiple events with the same hook name.
|
||||
- Removed the WP-CLI commands, as these have now been added to WP-CLI core (see `wp help cron` for more info)
|
||||
|
||||
|
||||
### 1.2.3 ###
|
||||
|
||||
- Tweaks to i18n and date and args formatting
|
||||
- Properly escape the `crontrol_message` query var (props Julio Potier)
|
||||
|
||||
|
||||
### 1.2.2 ###
|
||||
|
||||
- Added `wp crontrol run-event` and `wp crontrol delete-event` WP-CLI commands
|
||||
- Clarify language regarding hooks/entries/events
|
||||
|
||||
|
||||
### 1.2.1 ###
|
||||
|
||||
- Correctly display the local time when listing cron events
|
||||
- Remove a PHP notice
|
||||
- Pass the WP-Cron spawn check through the same filter as the actual spawner
|
||||
|
||||
|
||||
### 1.2 ###
|
||||
|
||||
- Added support for [WP-CLI](http://wp-cli.org/)
|
||||
- Removed some PHP4 code that's no longer relevant
|
||||
|
||||
|
||||
### 1.1 ###
|
||||
|
||||
- Bug fixes for running cron events and adding cron schedules
|
||||
- Added a cron spawn test to check for errors when spawning cron
|
||||
- Various small tweaks
|
||||
- WordPress 3.4 compatibility
|
||||
|
||||
|
||||
### 1.0 ###
|
||||
|
||||
- Input of PHP code for cron events
|
||||
- Non-repeating cron events
|
||||
- Handles cron events with arguments
|
||||
|
||||
|
||||
### 0.3 ###
|
||||
|
||||
- Internationalization
|
||||
- Editing/deleting/execution of cron events
|
||||
- More text, status messages, etc.
|
||||
- Allow a user to enter a schedule event in a human manner
|
||||
- Looks better on WordPress 2.5
|
||||
|
||||
|
||||
### 0.2 ###
|
||||
|
||||
- Fully documented the code.
|
||||
- Fixed the bug that the activate action wouldn't be run if the plugin wasn't in a subdirectory.
|
||||
- Now will play nicely in case any other plugins specify additional cron schedules.
|
||||
- Minor cosmetic fixes.
|
||||
|
||||
|
||||
### 0.1 ###
|
||||
|
||||
- Super basic, look at what's in WP-Cron functionality.
|
||||
|
||||
@@ -0,0 +1,428 @@
|
||||
<?php
|
||||
/**
|
||||
* List table for cron events.
|
||||
*
|
||||
* @package wp-crontrol
|
||||
*/
|
||||
|
||||
namespace Crontrol\Event;
|
||||
|
||||
use stdClass;
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
||||
|
||||
/**
|
||||
* Cron event list table class.
|
||||
*/
|
||||
class Table extends \WP_List_Table {
|
||||
|
||||
/**
|
||||
* Array of cron event hooks that are persistently added by WordPress core.
|
||||
*
|
||||
* @var string[] Array of hook names.
|
||||
*/
|
||||
protected static $persistent_core_hooks;
|
||||
|
||||
/**
|
||||
* Whether the current user has the capability to edit files.
|
||||
*
|
||||
* @var bool Whether the user can edit files.
|
||||
*/
|
||||
protected static $can_edit_files;
|
||||
|
||||
/**
|
||||
* Array of the count of each hook.
|
||||
*
|
||||
* @var int[] Array of count of each hooked, keyed by hook name.
|
||||
*/
|
||||
protected static $count_by_hook;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct( array(
|
||||
'singular' => 'crontrol-event',
|
||||
'plural' => 'crontrol-events',
|
||||
'ajax' => false,
|
||||
'screen' => 'crontrol-events',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the list table items and arguments.
|
||||
*/
|
||||
public function prepare_items() {
|
||||
self::$persistent_core_hooks = \Crontrol\get_persistent_core_hooks();
|
||||
self::$can_edit_files = current_user_can( 'edit_files' );
|
||||
self::$count_by_hook = count_by_hook();
|
||||
|
||||
$events = get();
|
||||
|
||||
if ( ! empty( $_GET['s'] ) ) {
|
||||
$s = sanitize_text_field( wp_unslash( $_GET['s'] ) );
|
||||
|
||||
$events = array_filter( $events, function( $event ) use ( $s ) {
|
||||
return ( false !== strpos( $event->hook, $s ) );
|
||||
} );
|
||||
}
|
||||
|
||||
$count = count( $events );
|
||||
$per_page = 50;
|
||||
$offset = ( $this->get_pagenum() - 1 ) * $per_page;
|
||||
|
||||
$this->items = array_slice( $events, $offset, $per_page );
|
||||
|
||||
$this->set_pagination_args( array(
|
||||
'total_items' => $count,
|
||||
'per_page' => $per_page,
|
||||
'total_pages' => ceil( $count / $per_page ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of column names for the table.
|
||||
*
|
||||
* @return string[] Array of column names keyed by their ID.
|
||||
*/
|
||||
public function get_columns() {
|
||||
return array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'crontrol_hook' => __( 'Hook', 'wp-crontrol' ),
|
||||
'crontrol_args' => __( 'Arguments', 'wp-crontrol' ),
|
||||
'crontrol_next' => sprintf(
|
||||
/* translators: %s: UTC offset */
|
||||
__( 'Next Run (%s)', 'wp-crontrol' ),
|
||||
\Crontrol\get_utc_offset()
|
||||
),
|
||||
'crontrol_actions' => __( 'Action', 'wp-crontrol' ),
|
||||
'crontrol_recurrence' => __( 'Recurrence', 'wp-crontrol' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of CSS class names for the table.
|
||||
*
|
||||
* @return string[] Array of class names.
|
||||
*/
|
||||
protected function get_table_classes() {
|
||||
return array( 'widefat', 'striped', $this->_args['plural'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an associative array ( option_name => option_title ) with the list
|
||||
* of bulk actions available on this table.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_bulk_actions() {
|
||||
return array(
|
||||
'delete_crons' => esc_html__( 'Delete', 'wp-crontrol' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates content for a single row of the table.
|
||||
*
|
||||
* @param object $event The current event.
|
||||
*/
|
||||
public function single_row( $event ) {
|
||||
$classes = array();
|
||||
|
||||
if ( ( 'crontrol_cron_job' === $event->hook ) && ! empty( $event->args['syntax_error_message'] ) ) {
|
||||
$classes[] = 'crontrol-error';
|
||||
}
|
||||
|
||||
$schedule_name = ( $event->interval ? get_schedule_name( $event ) : false );
|
||||
|
||||
if ( is_wp_error( $schedule_name ) ) {
|
||||
$classes[] = 'crontrol-error';
|
||||
}
|
||||
|
||||
if ( ! \Crontrol\get_hook_callbacks( $event->hook ) ) {
|
||||
$classes[] = 'crontrol-warning';
|
||||
}
|
||||
|
||||
if ( is_late( $event ) ) {
|
||||
$classes[] = 'crontrol-warning';
|
||||
}
|
||||
|
||||
printf(
|
||||
'<tr class="%s">',
|
||||
esc_attr( implode( ' ', $classes ) )
|
||||
);
|
||||
|
||||
$this->single_row_columns( $event );
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates and displays row action links for the table.
|
||||
*
|
||||
* @param stdClass $event The cron event for the current row.
|
||||
* @param string $column_name Current column name.
|
||||
* @param string $primary Primary column name.
|
||||
* @return string The row actions HTML.
|
||||
*/
|
||||
protected function handle_row_actions( $event, $column_name, $primary ) {
|
||||
if ( $primary !== $column_name ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$links = array();
|
||||
|
||||
if ( ( 'crontrol_cron_job' !== $event->hook ) || self::$can_edit_files ) {
|
||||
$link = array(
|
||||
'page' => 'crontrol_admin_manage_page',
|
||||
'action' => 'edit-cron',
|
||||
'id' => rawurlencode( $event->hook ),
|
||||
'sig' => rawurlencode( $event->sig ),
|
||||
'next_run_utc' => rawurlencode( $event->time ),
|
||||
);
|
||||
$link = add_query_arg( $link, admin_url( 'tools.php' ) );
|
||||
|
||||
$links[] = "<a href='" . esc_url( $link ) . "'>" . esc_html__( 'Edit', 'wp-crontrol' ) . '</a>';
|
||||
}
|
||||
|
||||
$link = array(
|
||||
'page' => 'crontrol_admin_manage_page',
|
||||
'action' => 'run-cron',
|
||||
'id' => rawurlencode( $event->hook ),
|
||||
'sig' => rawurlencode( $event->sig ),
|
||||
'next_run_utc' => rawurlencode( $event->time ),
|
||||
);
|
||||
$link = add_query_arg( $link, admin_url( 'tools.php' ) );
|
||||
$link = wp_nonce_url( $link, "run-cron_{$event->hook}_{$event->sig}" );
|
||||
|
||||
$links[] = "<a href='" . esc_url( $link ) . "'>" . esc_html__( 'Run Now', 'wp-crontrol' ) . '</a>';
|
||||
|
||||
if ( ! in_array( $event->hook, self::$persistent_core_hooks, true ) && ( ( 'crontrol_cron_job' !== $event->hook ) || self::$can_edit_files ) ) {
|
||||
$link = array(
|
||||
'page' => 'crontrol_admin_manage_page',
|
||||
'action' => 'delete-cron',
|
||||
'id' => rawurlencode( $event->hook ),
|
||||
'sig' => rawurlencode( $event->sig ),
|
||||
'next_run_utc' => rawurlencode( $event->time ),
|
||||
);
|
||||
$link = add_query_arg( $link, admin_url( 'tools.php' ) );
|
||||
$link = wp_nonce_url( $link, "delete-cron_{$event->hook}_{$event->sig}_{$event->time}" );
|
||||
|
||||
$links[] = "<span class='delete'><a href='" . esc_url( $link ) . "'>" . esc_html__( 'Delete', 'wp-crontrol' ) . '</a></span>';
|
||||
}
|
||||
|
||||
if ( function_exists( 'wp_unschedule_hook' ) && ! in_array( $event->hook, self::$persistent_core_hooks, true ) && ( 'crontrol_cron_job' !== $event->hook ) ) {
|
||||
if ( self::$count_by_hook[ $event->hook ] > 1 ) {
|
||||
$link = array(
|
||||
'page' => 'crontrol_admin_manage_page',
|
||||
'action' => 'delete-hook',
|
||||
'id' => rawurlencode( $event->hook ),
|
||||
);
|
||||
$link = add_query_arg( $link, admin_url( 'tools.php' ) );
|
||||
$link = wp_nonce_url( $link, "delete-hook_{$event->hook}" );
|
||||
|
||||
$text = sprintf(
|
||||
/* translators: %s: Number of events with a given name */
|
||||
_n( 'Delete All %s', 'Delete All %s', self::$count_by_hook[ $event->hook ], 'wp-crontrol' ),
|
||||
number_format_i18n( self::$count_by_hook[ $event->hook ] )
|
||||
);
|
||||
$links[] = "<span class='delete'><a href='" . esc_url( $link ) . "'>" . esc_html( $text ) . '</a></span>';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->row_actions( $links );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the checkbox cell of a table row.
|
||||
*
|
||||
* @param stdClass $event The cron event for the current row.
|
||||
*/
|
||||
protected function column_cb( $event ) {
|
||||
if ( ! in_array( $event->hook, self::$persistent_core_hooks, true ) && ( ( 'crontrol_cron_job' !== $event->hook ) || self::$can_edit_files ) ) {
|
||||
?>
|
||||
<label class="screen-reader-text" for="">
|
||||
<?php printf( esc_html__( 'Select this row', 'wp-crontrol' ) ); ?>
|
||||
</label>
|
||||
<?php
|
||||
printf(
|
||||
'<input type="checkbox" name="delete[%1$s][%2$s]" value="%3$s">',
|
||||
esc_attr( $event->time ),
|
||||
esc_attr( rawurlencode( $event->hook ) ),
|
||||
esc_attr( $event->sig )
|
||||
);
|
||||
?>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output for the hook name cell of a table row.
|
||||
*
|
||||
* @param stdClass $event The cron event for the current row.
|
||||
* @return string The cell output.
|
||||
*/
|
||||
protected function column_crontrol_hook( $event ) {
|
||||
if ( 'crontrol_cron_job' === $event->hook ) {
|
||||
if ( ! empty( $event->args['name'] ) ) {
|
||||
/* translators: 1: The name of the PHP cron event. */
|
||||
return '<em>' . esc_html( sprintf( __( 'PHP Cron (%s)', 'wp-crontrol' ), $event->args['name'] ) ) . '</em>';
|
||||
} else {
|
||||
return '<em>' . esc_html__( 'PHP Cron', 'wp-crontrol' ) . '</em>';
|
||||
}
|
||||
}
|
||||
|
||||
return esc_html( $event->hook );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output for the arguments cell of a table row.
|
||||
*
|
||||
* @param stdClass $event The cron event for the current row.
|
||||
* @return string The cell output.
|
||||
*/
|
||||
protected function column_crontrol_args( $event ) {
|
||||
if ( ! empty( $event->args ) ) {
|
||||
$args = \Crontrol\json_output( $event->args );
|
||||
}
|
||||
|
||||
if ( 'crontrol_cron_job' === $event->hook ) {
|
||||
$return = '<em>' . esc_html__( 'PHP Code', 'wp-crontrol' ) . '</em>';
|
||||
|
||||
if ( ! empty( $event->args['syntax_error_message'] ) ) {
|
||||
$return .= '<br><span class="status-crontrol-error"><span class="dashicons dashicons-warning" aria-hidden="true"></span> ';
|
||||
$return .= sprintf(
|
||||
/* translators: 1: Line number, 2: Error message text */
|
||||
esc_html__( 'Line %1$s: %2$s', 'wp-crontrol' ),
|
||||
esc_html( number_format_i18n( $event->args['syntax_error_line'] ) ),
|
||||
esc_html( $event->args['syntax_error_message'] )
|
||||
);
|
||||
$return .= '</span>';
|
||||
}
|
||||
|
||||
if ( ! empty( $event->args['code'] ) ) {
|
||||
$lines = explode( "\n", trim( $event->args['code'] ) );
|
||||
$code = reset( $lines );
|
||||
$code = substr( $code, 0, 50 );
|
||||
|
||||
$return .= '<br>';
|
||||
$return .= sprintf(
|
||||
'<code>%s</code>…',
|
||||
esc_html( $code )
|
||||
);
|
||||
}
|
||||
|
||||
return $return;
|
||||
} else {
|
||||
if ( empty( $event->args ) ) {
|
||||
return sprintf(
|
||||
'<em>%s</em>',
|
||||
esc_html__( 'None', 'wp-crontrol' )
|
||||
);
|
||||
} else {
|
||||
return sprintf(
|
||||
'<pre>%s</pre>',
|
||||
esc_html( $args )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output for the actions cell of a table row.
|
||||
*
|
||||
* @param stdClass $event The cron event for the current row.
|
||||
* @return string The cell output.
|
||||
*/
|
||||
protected function column_crontrol_actions( $event ) {
|
||||
$hook_callbacks = \Crontrol\get_hook_callbacks( $event->hook );
|
||||
|
||||
if ( 'crontrol_cron_job' === $event->hook ) {
|
||||
return '<em>' . esc_html__( 'WP Crontrol', 'wp-crontrol' ) . '</em>';
|
||||
} elseif ( ! empty( $hook_callbacks ) ) {
|
||||
$callbacks = array();
|
||||
|
||||
foreach ( $hook_callbacks as $callback ) {
|
||||
$callbacks[] = \Crontrol\output_callback( $callback );
|
||||
}
|
||||
|
||||
return implode( '<br>', $callbacks ); // WPCS:: XSS ok.
|
||||
} else {
|
||||
return sprintf(
|
||||
'<span class="status-crontrol-warning"><span class="dashicons dashicons-warning" aria-hidden="true"></span> %s</span>',
|
||||
esc_html__( 'None', 'wp-crontrol' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output for the next run cell of a table row.
|
||||
*
|
||||
* @param stdClass $event The cron event for the current row.
|
||||
* @return string The cell output.
|
||||
*/
|
||||
protected function column_crontrol_next( $event ) {
|
||||
$date_utc = gmdate( 'Y-m-d\TH:i:s+00:00', $event->time );
|
||||
$date_local = get_date_from_gmt( date( 'Y-m-d H:i:s', $event->time ), 'Y-m-d H:i:s' );
|
||||
|
||||
$time = sprintf(
|
||||
'<time datetime="%1$s">%2$s</time>',
|
||||
esc_attr( $date_utc ),
|
||||
esc_html( $date_local )
|
||||
);
|
||||
|
||||
$until = $event->time - time();
|
||||
$late = is_late( $event );
|
||||
|
||||
if ( $late ) {
|
||||
// Show a warning for events that are late.
|
||||
$ago = sprintf(
|
||||
/* translators: %s: Time period, for example "8 minutes" */
|
||||
__( '%s ago', 'wp-crontrol' ),
|
||||
\Crontrol\interval( abs( $until ) )
|
||||
);
|
||||
return sprintf(
|
||||
'%s<br><span class="status-crontrol-warning"><span class="dashicons dashicons-warning" aria-hidden="true"></span> %s</span>',
|
||||
$time,
|
||||
esc_html( $ago )
|
||||
);
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'%s<br>%s',
|
||||
$time,
|
||||
esc_html( \Crontrol\interval( $until ) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output for the recurrence cell of a table row.
|
||||
*
|
||||
* @param stdClass $event The cron event for the current row.
|
||||
* @return string The cell output.
|
||||
*/
|
||||
protected function column_crontrol_recurrence( $event ) {
|
||||
if ( $event->schedule ) {
|
||||
$schedule_name = get_schedule_name( $event );
|
||||
if ( is_wp_error( $schedule_name ) ) {
|
||||
return sprintf(
|
||||
'<span class="status-crontrol-error"><span class="dashicons dashicons-warning" aria-hidden="true"></span> %s</span>',
|
||||
esc_html( $schedule_name->get_error_message() )
|
||||
);
|
||||
} else {
|
||||
return esc_html( $schedule_name );
|
||||
}
|
||||
} else {
|
||||
return esc_html__( 'Non-repeating', 'wp-crontrol' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a message when there are no items to show in the table.
|
||||
*/
|
||||
public function no_items() {
|
||||
esc_html_e( 'There are currently no scheduled cron events.', 'wp-crontrol' );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* Functions related to cron events.
|
||||
*
|
||||
* @package wp-crontrol
|
||||
*/
|
||||
|
||||
namespace Crontrol\Event;
|
||||
|
||||
use stdClass;
|
||||
use Crontrol\Schedule;
|
||||
use WP_Error;
|
||||
|
||||
/**
|
||||
* Executes a cron event immediately.
|
||||
*
|
||||
* Executes an event by scheduling a new single event with the same arguments.
|
||||
*
|
||||
* @param string $hookname The hook name of the cron event to run.
|
||||
* @param string $sig The cron event signature.
|
||||
* @return bool Whether the execution was successful.
|
||||
*/
|
||||
function run( $hookname, $sig ) {
|
||||
$crons = _get_cron_array();
|
||||
foreach ( $crons as $time => $cron ) {
|
||||
if ( isset( $cron[ $hookname ][ $sig ] ) ) {
|
||||
$args = $cron[ $hookname ][ $sig ]['args'];
|
||||
delete_transient( 'doing_cron' );
|
||||
$scheduled = force_schedule_single_event( $hookname, $args ); // UTC
|
||||
|
||||
if ( false === $scheduled ) {
|
||||
return $scheduled;
|
||||
}
|
||||
|
||||
add_filter( 'cron_request', function( array $cron_request_array ) {
|
||||
$cron_request_array['url'] = add_query_arg( 'crontrol-single-event', 1, $cron_request_array['url'] );
|
||||
return $cron_request_array;
|
||||
} );
|
||||
|
||||
spawn_cron();
|
||||
|
||||
sleep( 1 );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcibly schedules a single event for the purpose of manually running it.
|
||||
*
|
||||
* This is used instead of `wp_schedule_single_event()` to avoid the duplicate check that's otherwise performed.
|
||||
*
|
||||
* @param string $hook Action hook to execute when the event is run.
|
||||
* @param array $args Optional. Array containing each separate argument to pass to the hook's callback function.
|
||||
* @return bool True if event successfully scheduled. False for failure.
|
||||
*/
|
||||
function force_schedule_single_event( $hook, $args = array() ) {
|
||||
$event = (object) array(
|
||||
'hook' => $hook,
|
||||
'timestamp' => 1,
|
||||
'schedule' => false,
|
||||
'args' => $args,
|
||||
);
|
||||
$crons = (array) _get_cron_array();
|
||||
$key = md5( serialize( $event->args ) );
|
||||
|
||||
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
|
||||
'schedule' => $event->schedule,
|
||||
'args' => $event->args,
|
||||
);
|
||||
uksort( $crons, 'strnatcasecmp' );
|
||||
|
||||
return _set_cron_array( $crons );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new cron event.
|
||||
*
|
||||
* @param string $next_run_local The time that the event should be run at, in the site's timezone.
|
||||
* @param string $schedule The recurrence of the cron event.
|
||||
* @param string $hookname The name of the hook to execute.
|
||||
* @param array $args Arguments to add to the cron event.
|
||||
* @return bool Whether the addition was successful.
|
||||
*/
|
||||
function add( $next_run_local, $schedule, $hookname, array $args ) {
|
||||
$next_run_local = strtotime( $next_run_local, current_time( 'timestamp' ) );
|
||||
|
||||
if ( false === $next_run_local ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$next_run_utc = get_gmt_from_date( gmdate( 'Y-m-d H:i:s', $next_run_local ), 'U' );
|
||||
|
||||
if ( ! is_array( $args ) ) {
|
||||
$args = array();
|
||||
}
|
||||
|
||||
if ( 'crontrol_cron_job' === $hookname && ! empty( $args['code'] ) && class_exists( '\ParseError' ) ) {
|
||||
try {
|
||||
// phpcs:ignore Squiz.PHP.Eval.Discouraged
|
||||
eval( sprintf(
|
||||
'return true; %s',
|
||||
$args['code']
|
||||
) );
|
||||
// phpcs:ignore PHPCompatibility.Classes.NewClasses.parseerrorFound
|
||||
} catch ( \ParseError $e ) {
|
||||
$args['syntax_error_message'] = $e->getMessage();
|
||||
$args['syntax_error_line'] = $e->getLine();
|
||||
}
|
||||
}
|
||||
|
||||
if ( '_oneoff' === $schedule ) {
|
||||
return ( false !== wp_schedule_single_event( $next_run_utc, $hookname, $args ) );
|
||||
} else {
|
||||
return ( false !== wp_schedule_event( $next_run_utc, $schedule, $hookname, $args ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a cron event.
|
||||
*
|
||||
* @param string $to_delete The hook name of the event to delete.
|
||||
* @param string $sig The cron event signature.
|
||||
* @param string $next_run_utc The UTC time that the event would be run at.
|
||||
* @return bool Whether the deletion was successful.
|
||||
*/
|
||||
function delete( $to_delete, $sig, $next_run_utc ) {
|
||||
$crons = _get_cron_array();
|
||||
if ( isset( $crons[ $next_run_utc ][ $to_delete ][ $sig ] ) ) {
|
||||
$args = $crons[ $next_run_utc ][ $to_delete ][ $sig ]['args'];
|
||||
$unscheduled = wp_unschedule_event( $next_run_utc, $to_delete, $args );
|
||||
|
||||
if ( false === $unscheduled ) {
|
||||
return $unscheduled;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a flattened array of cron events.
|
||||
*
|
||||
* @return object[] An array of cron event objects.
|
||||
*/
|
||||
function get() {
|
||||
$crons = _get_cron_array();
|
||||
$events = array();
|
||||
|
||||
if ( empty( $crons ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ( $crons as $time => $cron ) {
|
||||
foreach ( $cron as $hook => $dings ) {
|
||||
foreach ( $dings as $sig => $data ) {
|
||||
|
||||
// This is a prime candidate for a Crontrol_Event class but I'm not bothering currently.
|
||||
$events[ "$hook-$sig-$time" ] = (object) array(
|
||||
'hook' => $hook,
|
||||
'time' => $time, // UTC
|
||||
'sig' => $sig,
|
||||
'args' => $data['args'],
|
||||
'schedule' => $data['schedule'],
|
||||
'interval' => isset( $data['interval'] ) ? $data['interval'] : null,
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure events are always returned in date descending order.
|
||||
// External cron runners such as Cavalcade don't guarantee events are returned in order of time.
|
||||
uasort( $events, function( $a, $b ) {
|
||||
if ( $a->time === $b->time ) {
|
||||
return 0;
|
||||
} else {
|
||||
return ( $a->time > $b->time ) ? 1 : -1;
|
||||
}
|
||||
} );
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the number of events for each hook.
|
||||
*
|
||||
* @return int[] Array of number of events for each hook, keyed by the hook name.
|
||||
*/
|
||||
function count_by_hook() {
|
||||
$crons = _get_cron_array();
|
||||
$events = array();
|
||||
|
||||
if ( empty( $crons ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ( $crons as $time => $cron ) {
|
||||
foreach ( $cron as $hook => $dings ) {
|
||||
if ( ! isset( $events[ $hook ] ) ) {
|
||||
$events[ $hook ] = 0;
|
||||
}
|
||||
|
||||
$events[ $hook ] += count( $dings );
|
||||
}
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the schedule display name for a given event.
|
||||
*
|
||||
* @param stdClass $event A WP-Cron event.
|
||||
* @return string|WP_Error The interval display name, or a WP_Error object if no such schedule exists.
|
||||
*/
|
||||
function get_schedule_name( stdClass $event ) {
|
||||
$schedules = Schedule\get();
|
||||
|
||||
if ( isset( $schedules[ $event->schedule ] ) ) {
|
||||
return $schedules[ $event->schedule ]['display'];
|
||||
}
|
||||
|
||||
return new WP_Error( 'unknown_schedule', sprintf(
|
||||
/* translators: %s: Schedule name */
|
||||
__( 'Unknown (%s)', 'wp-crontrol' ),
|
||||
$event->schedule
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an event is late.
|
||||
*
|
||||
* An event which has missed its schedule by more than 10 minutes is considered late.
|
||||
*
|
||||
* @param stdClass $event The event.
|
||||
* @return bool Whether the event is late.
|
||||
*/
|
||||
function is_late( stdClass $event ) {
|
||||
$until = $event->time - time();
|
||||
|
||||
return ( $until < ( 0 - ( 10 * MINUTE_IN_SECONDS ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises and returns the list table for events.
|
||||
*
|
||||
* @return Table The list table.
|
||||
*/
|
||||
function get_list_table() {
|
||||
static $table = null;
|
||||
|
||||
if ( ! $table ) {
|
||||
require_once __DIR__ . '/event-list-table.php';
|
||||
|
||||
$table = new Table();
|
||||
$table->prepare_items();
|
||||
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
/**
|
||||
* List table for cron schedules.
|
||||
*
|
||||
* @package wp-crontrol
|
||||
*/
|
||||
|
||||
namespace Crontrol;
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
||||
|
||||
/**
|
||||
* Cron schedule list table class.
|
||||
*/
|
||||
class Schedule_List_Table extends \WP_List_Table {
|
||||
|
||||
/**
|
||||
* Array of cron event schedules that are added by WordPress core.
|
||||
*
|
||||
* @var string[] Array of schedule names.
|
||||
*/
|
||||
protected static $core_schedules;
|
||||
|
||||
/**
|
||||
* Array of cron event schedule names that are in use by events.
|
||||
*
|
||||
* @var string[] Array of schedule names.
|
||||
*/
|
||||
protected static $used_schedules;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct( array(
|
||||
'singular' => 'crontrol-schedule',
|
||||
'plural' => 'crontrol-schedules',
|
||||
'ajax' => false,
|
||||
'screen' => 'crontrol-schedules',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the list table items and arguments.
|
||||
*/
|
||||
public function prepare_items() {
|
||||
$schedules = Schedule\get();
|
||||
$count = count( $schedules );
|
||||
|
||||
self::$core_schedules = get_core_schedules();
|
||||
self::$used_schedules = array_unique( wp_list_pluck( Event\get(), 'schedule' ) );
|
||||
|
||||
$this->items = $schedules;
|
||||
|
||||
$this->set_pagination_args( array(
|
||||
'total_items' => $count,
|
||||
'per_page' => -1,
|
||||
'total_pages' => 1,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of column names for the table.
|
||||
*
|
||||
* @return string[] Array of column names keyed by their ID.
|
||||
*/
|
||||
public function get_columns() {
|
||||
return array(
|
||||
'crontrol_name' => __( 'Name', 'wp-crontrol' ),
|
||||
'crontrol_interval' => __( 'Interval', 'wp-crontrol' ),
|
||||
'crontrol_display' => __( 'Display Name', 'wp-crontrol' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of CSS class names for the table.
|
||||
*
|
||||
* @return string[] Array of class names.
|
||||
*/
|
||||
protected function get_table_classes() {
|
||||
return array( 'widefat', 'striped', $this->_args['plural'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates and displays row action links for the table.
|
||||
*
|
||||
* @param array $schedule The schedule for the current row.
|
||||
* @param string $column_name Current column name.
|
||||
* @param string $primary Primary column name.
|
||||
* @return string The row actions HTML.
|
||||
*/
|
||||
protected function handle_row_actions( $schedule, $column_name, $primary ) {
|
||||
if ( $primary !== $column_name ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$links = array();
|
||||
$new_scheds = get_option( 'crontrol_schedules', array() );
|
||||
|
||||
if ( in_array( $schedule['name'], self::$core_schedules, true ) ) {
|
||||
$links[] = "<span class='in-use'>" . esc_html__( 'This is a WordPress core schedule and cannot be deleted', 'wp-crontrol' ) . '</span>';
|
||||
} elseif ( ! isset( $new_scheds[ $schedule['name'] ] ) ) {
|
||||
$links[] = "<span class='in-use'>" . esc_html__( 'This schedule is added by another plugin and cannot be deleted', 'wp-crontrol' ) . '</span>';
|
||||
} elseif ( in_array( $schedule['name'], self::$used_schedules, true ) ) {
|
||||
$links[] = "<span class='in-use'>" . esc_html__( 'This custom schedule is in use and cannot be deleted', 'wp-crontrol' ) . '</span>';
|
||||
} else {
|
||||
$link = add_query_arg( array(
|
||||
'page' => 'crontrol_admin_options_page',
|
||||
'action' => 'delete-sched',
|
||||
'id' => rawurlencode( $schedule['name'] ),
|
||||
), admin_url( 'options-general.php' ) );
|
||||
$link = wp_nonce_url( $link, 'delete-sched_' . $schedule['name'] );
|
||||
|
||||
$links[] = "<span class='delete'><a href='" . esc_url( $link ) . "'>" . esc_html__( 'Delete', 'wp-crontrol' ) . '</a></span>';
|
||||
}
|
||||
|
||||
return $this->row_actions( $links );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output for the schdule name cell of a table row.
|
||||
*
|
||||
* @param array $schedule The schedule for the current row.
|
||||
* @return string The cell output.
|
||||
*/
|
||||
protected function column_crontrol_name( array $schedule ) {
|
||||
return esc_html( $schedule['name'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output for the interval cell of a table row.
|
||||
*
|
||||
* @param array $schedule The schedule for the current row.
|
||||
* @return string The cell output.
|
||||
*/
|
||||
protected function column_crontrol_interval( array $schedule ) {
|
||||
$interval = sprintf(
|
||||
'%s (%s)',
|
||||
esc_html( $schedule['interval'] ),
|
||||
esc_html( interval( $schedule['interval'] ) )
|
||||
);
|
||||
|
||||
if ( $schedule['interval'] < WP_CRON_LOCK_TIMEOUT ) {
|
||||
$interval .= sprintf(
|
||||
'<span class="status-crontrol-warning"><br><span class="dashicons dashicons-warning" aria-hidden="true"></span> %s</span>',
|
||||
sprintf(
|
||||
/* translators: 1: The name of the configuration constant, 2: The value of the configuration constant */
|
||||
esc_html__( 'This interval is less than the %1$s constant which is set to %2$s. Events that use it may not run on time.', 'wp-crontrol' ),
|
||||
'<code>WP_CRON_LOCK_TIMEOUT</code>',
|
||||
intval( WP_CRON_LOCK_TIMEOUT )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the output for the display name cell of a table row.
|
||||
*
|
||||
* @param array $schedule The schedule for the current row.
|
||||
* @return string The cell output.
|
||||
*/
|
||||
protected function column_crontrol_display( array $schedule ) {
|
||||
return esc_html( $schedule['display'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a message when there are no items to show in the table.
|
||||
*/
|
||||
public function no_items() {
|
||||
esc_html_e( 'There are no schedules.', 'wp-crontrol' );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Functions related to schedules.
|
||||
*
|
||||
* @package wp-crontrol
|
||||
*/
|
||||
|
||||
namespace Crontrol\Schedule;
|
||||
|
||||
/**
|
||||
* Adds a new custom cron schedule.
|
||||
*
|
||||
* @param string $name The internal name of the schedule.
|
||||
* @param int $interval The interval between executions of the new schedule.
|
||||
* @param string $display The display name of the schedule.
|
||||
*/
|
||||
function add( $name, $interval, $display ) {
|
||||
$old_scheds = get_option( 'crontrol_schedules', array() );
|
||||
|
||||
$old_scheds[ $name ] = array(
|
||||
'interval' => $interval,
|
||||
'display' => $display,
|
||||
);
|
||||
update_option( 'crontrol_schedules', $old_scheds );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a custom cron schedule.
|
||||
*
|
||||
* @param string $name The internal_name of the schedule to delete.
|
||||
*/
|
||||
function delete( $name ) {
|
||||
$scheds = get_option( 'crontrol_schedules', array() );
|
||||
unset( $scheds[ $name ] );
|
||||
update_option( 'crontrol_schedules', $scheds );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a sorted (according to interval) list of the cron schedules
|
||||
*
|
||||
* @return array[] Array of cron schedule arrays.
|
||||
*/
|
||||
function get() {
|
||||
$schedules = wp_get_schedules();
|
||||
uasort( $schedules, function( array $a, array $b ) {
|
||||
return ( $a['interval'] - $b['interval'] );
|
||||
} );
|
||||
|
||||
array_walk( $schedules, function( array &$schedule, $name ) {
|
||||
$schedule['name'] = $name;
|
||||
} );
|
||||
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a dropdown filled with the possible schedules, including non-repeating.
|
||||
*
|
||||
* @param bool $current The currently selected schedule.
|
||||
*/
|
||||
function dropdown( $current = false ) {
|
||||
$schedules = get();
|
||||
?>
|
||||
<select class="postform" name="schedule" id="schedule" required>
|
||||
<option <?php selected( $current, '_oneoff' ); ?> value="_oneoff"><?php esc_html_e( 'Non-repeating', 'wp-crontrol' ); ?></option>
|
||||
<?php foreach ( $schedules as $sched_name => $sched_data ) { ?>
|
||||
<option <?php selected( $current, $sched_name ); ?> value="<?php echo esc_attr( $sched_name ); ?>">
|
||||
<?php
|
||||
printf(
|
||||
'%s (%s)',
|
||||
esc_html( $sched_data['display'] ),
|
||||
esc_html( $sched_name )
|
||||
);
|
||||
?>
|
||||
</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
<?php
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user