Author URI: http://petermolnar.net/
License: GPLv3
*/
/* Copyright 2016 Peter Molnar ( hello@petermolnar.net )
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 3, as
published by the Free Software Foundation.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace WP_AUTOSITEMAP;
\register_activation_hook( __FILE__ , '\WP_AUTOSITEMAP\plugin_activate' );
\register_deactivation_hook( __FILE__ , '\WP_AUTOSITEMAP\plugin_deactivate' );
// init all the things!
\add_action( 'init', '\WP_AUTOSITEMAP\init' );
// register new posts
\add_action(
"transition_post_status",
'\WP_AUTOSITEMAP\trigger_sitemap_cron',
1,
3
);
// cron based export for all posts
\add_action( 'wp_autositemap', '\WP_AUTOSITEMAP\generate_sitemap' );
/**
* activate hook
*/
function plugin_activate() {
if ( version_compare( phpversion(), 5.4, '<' ) ) {
die( 'The minimum PHP version required for this plugin is 5.3' );
}
}
/**
*
*/
function plugin_deactivate() {
wp_unschedule_event( time(), 'wp_autositemap' );
wp_clear_scheduled_hook( 'wp_autositemap' );
}
/**
*
*/
function init () {
if ( ! wp_get_schedule( 'wp_autositemap' ))
wp_schedule_event ( time(), 'daily', 'wp_autositemap' );
}
function trigger_sitemap_cron ( $new_status = null , $old_status = null,
$post = null ) {
if ( null === $new_status || null === $old_status || null === $post )
return;
wp_schedule_single_event( time() + 1, 'wp_autositemap' );
}
/**
*
*/
function generate_sitemap () {
$head = '
' . $message . '
' ); exit; } $trace = debug_backtrace(); $caller = $trace[1]; $parent = $caller['function']; if (isset($caller['class'])) $parent = $caller['class'] . '::' . $parent; return error_log( "{$parent}: {$message}" ); }