/** * Schedule social media posts with wp_schedule_single_event * @param id $post_id * @param object $post * @return void */ function ppp_schedule_share($post_id, $post) { global $ppp_options; $allowed_post_types = isset($ppp_options['post_types']) ? $ppp_options['post_types'] : array(); $allowed_post_types = apply_filters('ppp_schedule_share_post_types', $allowed_post_types); if (!isset($_POST['post_status']) || !array_key_exists($post->post_type, $allowed_post_types)) { return; } ppp_remove_scheduled_shares($post_id); if ($_POST['post_status'] == 'publish' && $_POST['original_post_status'] == 'publish' || $_POST['post_status'] == 'future' && $_POST['original_post_status'] == 'future') { // Be sure to clear any currently scheduled tweets so we aren't creating multiple instances // This will stop something from moving between draft and post and continuing to schedule tweets ppp_remove_scheduled_shares($post_id); } if ($_POST['post_status'] == 'publish' && $_POST['original_post_status'] != 'publish' || $_POST['post_status'] == 'future' && $_POST['original_post_status'] == 'future' || $_POST['post_status'] == 'publish' && $_POST['original_post_status'] == 'publish') { // Updating an already published post global $ppp_options, $ppp_social_settings; $timestamps = ppp_get_timestamps($post_id); foreach ($timestamps as $timestamp => $name) { wp_schedule_single_event($timestamp, 'ppp_share_post_event', array($post_id, $name)); } } }
/** * Unschedule any tweets when the post is unscheduled * * @since 2.1.2 * @param string $old_status The old status of the post * @param string $new_status The new status of the post * @param object $post The Post Object * @return void */ function ppp_tw_unschedule_shares($new_status, $old_status, $post) { if (($old_status == 'publish' || $old_status == 'future') && ($new_status != 'publish' && $new_status != 'future')) { ppp_remove_scheduled_shares($post->ID); } }
<?php // Exit if accessed directly if (!defined('ABSPATH')) { exit; } /** * Runs whenever the 'uninstall' link is clicked in the Plugins List * * Removes our settings if the option to 'delete on uninstall is set' */ $options = get_option('ppp_options'); if (isset($options['delete_on_uninstall'])) { require_once 'includes/cron-functions.php'; $crons = ppp_get_shceduled_crons(); foreach ($crons as $cron) { $ppp_data = $cron['ppp_share_post_event']; $array_keys = array_keys($ppp_data); $hash_key = $array_keys[0]; $event_info = $ppp_data[$hash_key]; ppp_remove_scheduled_shares($event_info['args'][0]); } delete_option('ppp_options'); delete_option('_ppp_license_key'); delete_option('ppp_social_settings'); delete_option('ppp_share_settings'); delete_option('_ppp_license_key_status'); delete_transient('ppp_social_tokens'); }