id === 'dashboard') {
// Code that should only run for admin users on the dashboard page
// to disable shell_exec in php.ini use: disable_functions = shell_exec
// check if shell_exec is available
if (is_shell_exec_enabled()) {
global $is_server_cron_active;
// shell_exec available
$output = shell_exec('crontab -l');
$php_version_long = phpversion();
$php_version = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
$php_bin = PHP_BINDIR . '/php'.$php_version;
$running_user = posix_getpwuid(posix_geteuid())['name'];
$wp_cron_path = ABSPATH . 'wp-cron.php';
$is_server_cron_active = strpos($output, $wp_cron_path) !== false;
if ($is_server_cron_active) {
// The server-side cron job is active, run this code
//
if (!is_disable_wp_cron_active()) {
// DISABLE_WP_CRON is not defined or not set to true, run this code
add_action('admin_notices', 'disable_wp_cron_admin_notice');
enable_disable_wp_cron();
}
} else {
// The server-side cron job is not active, run this code
// set disable cron to false if no server cronjob is active
disable_disable_wp_cron();
// display message to add cron
$message = sprintf( __('There is no server-side cron job for the WP-cron. To add one, use the following command:
*/15 * * * * %1$s %2$s
Make sure to run the cron job as the user %3$s.
Your server is running PHP version %4$s.', AATIWPF_TEXTDOMAIN), $php_bin, $wp_cron_path, $running_user, $php_version_long );
echo '
';
//if disable cron is not active display error
if (!is_disable_wp_cron_active()) {
// DISABLE_WP_CRON is not defined or not set to true, run this code
add_action('admin_notices', 'disable_wp_cron_admin_notice');
}
}
} else {
$php_version_long = phpversion();
$php_version = PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
$php_bin = PHP_BINDIR . '/php'.$php_version;
$running_user = posix_getpwuid(posix_geteuid())['name'];
$wp_cron_path = ABSPATH . 'wp-cron.php';
// NO shell_exec available
add_action('admin_notices', 'shell_exec_not_available_notice');
// check if in wp-config
if (!is_disable_wp_cron_active()) {
// DISABLE_WP_CRON is not defined or not set to true, run this code
add_action('admin_notices', 'disable_wp_cron_admin_notice');
}
$message = sprintf( __('There is no server-side cron job for the WP-cron. To add one, use the following command:
*/15 * * * * %1$s %2$s
Make sure to run the cron job as the user %3$s.
Your server is running PHP version %4$s.', AATIWPF_TEXTDOMAIN), $php_bin, $wp_cron_path, $running_user, $php_version_long );
echo '';
}
}
}
add_action('admin_notices', 'server_cron_status_admin_notices');
function shell_exec_not_available_notice() {
echo 'shell_exec is not available on your server. This might affect the ability to check the server-side cron status.
';
}
function is_disable_wp_cron_active() {
return defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true;
}
function disable_wp_cron_admin_notice() {
// DISABLE_WP_CRON is not defined or not set to true, show the admin notice
echo 'DISABLE_WP_CRON is not active.
';
}
function enable_disable_wp_cron() {
update_wp_cron_setting(true);
}
function disable_disable_wp_cron() {
update_wp_cron_setting(false);
}
function update_wp_cron_setting($should_disable_wp_cron) {
$wp_config_path = ABSPATH . 'wp-config.php';
if (file_exists($wp_config_path) && is_writable($wp_config_path)) {
$wp_config_contents = file_get_contents($wp_config_path);
$pattern = "/(define\s*\(\s*['\"]DISABLE_WP_CRON['\"]\s*,\s*)(false|true)(\s*\))/i";
$php_opening_tag = "The wp-config.php file is not writable. Please update the DISABLE_WP_CRON setting manually.
';
}
}