v1.0.0
This commit is contained in:
parent
0fcf42b47b
commit
443dceb8ca
4830 changed files with 566609 additions and 230 deletions
90
robotstxt-documentation-markdown-cron.php
Normal file
90
robotstxt-documentation-markdown-cron.php
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
/**
|
||||
* Cron Functions
|
||||
*
|
||||
* @package RobotsTxt\DocumentationMarkdown
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Register cron hook.
|
||||
add_action( 'robotstxt_docmd_sync_event', 'robotstxt_docmd_handle_cron_sync' );
|
||||
|
||||
/**
|
||||
* Schedule mapping sync
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int $mapping_id Mapping ID.
|
||||
* @param string $frequency Cron frequency (hourly, twicedaily, daily, weekly).
|
||||
* @return void
|
||||
*/
|
||||
function robotstxt_docmd_schedule_mapping_sync( $mapping_id, $frequency ) {
|
||||
$hook = 'robotstxt_docmd_sync_event';
|
||||
$args = array( $mapping_id );
|
||||
|
||||
// Remove existing schedule.
|
||||
robotstxt_docmd_unschedule_mapping_sync( $mapping_id );
|
||||
|
||||
// Schedule new event.
|
||||
if ( ! wp_next_scheduled( $hook, $args ) ) {
|
||||
wp_schedule_event( time(), $frequency, $hook, $args );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unschedule mapping sync
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int $mapping_id Mapping ID.
|
||||
* @return void
|
||||
*/
|
||||
function robotstxt_docmd_unschedule_mapping_sync( $mapping_id ) {
|
||||
$hook = 'robotstxt_docmd_sync_event';
|
||||
$args = array( $mapping_id );
|
||||
|
||||
$timestamp = wp_next_scheduled( $hook, $args );
|
||||
if ( $timestamp ) {
|
||||
wp_unschedule_event( $timestamp, $hook, $args );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unschedule all cron events
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function robotstxt_docmd_unschedule_all_crons() {
|
||||
$mappings = robotstxt_docmd_get_all_mappings();
|
||||
|
||||
foreach ( $mappings as $mapping ) {
|
||||
robotstxt_docmd_unschedule_mapping_sync( $mapping['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cron sync event
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int $mapping_id Mapping ID.
|
||||
* @return void
|
||||
*/
|
||||
function robotstxt_docmd_handle_cron_sync( $mapping_id ) {
|
||||
$mapping = robotstxt_docmd_get_mapping( $mapping_id );
|
||||
|
||||
// Check if still enabled.
|
||||
if ( ! $mapping || ! $mapping['sync_enabled'] ) {
|
||||
robotstxt_docmd_unschedule_mapping_sync( $mapping_id );
|
||||
return;
|
||||
}
|
||||
|
||||
// Perform sync.
|
||||
robotstxt_docmd_sync_mapping( $mapping_id );
|
||||
}
|
||||
Loading…
Reference in a new issue