| @@ -1,62 +1,61 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -if ( ! class_exists( 'TSM_Process_Tracking_Scripts' ) ) { | |
| 4 | - | |
| 5 | - class TSM_Process_Tracking_Scripts extends WP_Background_Process { | |
| 6 | - | |
| 7 | - /** | |
| 8 | - * @var string | |
| 9 | - */ | |
| 10 | - protected $action = 'process_tracking_scripts'; | |
| 11 | - /** | |
| 12 | - * Task | |
| 13 | - * | |
| 14 | - * Override this method to perform any actions required on each | |
| 15 | - * queue item. Return the modified item for further processing | |
| 16 | - * in the next pass through. Or, return false to remove the | |
| 17 | - * item from the queue. | |
| 18 | - * | |
| 19 | - * @param mixed $item Queue item to iterate over | |
| 20 | - * | |
| 21 | - * @return mixed | |
| 22 | - */ | |
| 23 | - protected function task( $script ) { | |
| 24 | - | |
| 25 | - $script_post = array( | |
| 26 | - 'post_type' => 'r8_tracking_scripts', | |
| 27 | - 'post_title' => $script->script_name, | |
| 28 | - 'post_content' => '', | |
| 29 | - 'post_status' => 'publish', | |
| 30 | - 'meta_input' => array( | |
| 31 | - 'r8_tsm_script_code' => $script->script_code, | |
| 32 | - 'r8_tsm_active' => $script->active ? 'active' : 'inactive', | |
| 33 | - 'r8_tsm_script_order' => $script->order ? $script->order : 1, | |
| 34 | - 'r8_tsm_script_location' => $script->location, | |
| 35 | - 'r8_tsm_script_page' => $script->page_id ? array($script->page_id) : array() | |
| 36 | - ), | |
| 37 | - ); | |
| 38 | - | |
| 39 | - $post_id = wp_insert_post( $script_post ); | |
| 40 | - | |
| 41 | - return false; | |
| 42 | - } | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * Complete | |
| 46 | - * | |
| 47 | - * Override if applicable, but ensure that the below actions are | |
| 48 | - * performed, or, call parent::complete(). | |
| 49 | - */ | |
| 50 | - protected function complete() { | |
| 51 | - parent::complete(); | |
| 52 | - // Show notice to user or perform some other arbitrary task... | |
| 53 | - | |
| 54 | - delete_option( 'header_tracking_script_code' ); | |
| 55 | - delete_option( 'page_tracking_script_code' ); | |
| 56 | - delete_option( 'footer_tracking_script_code' ); | |
| 57 | - delete_option( 'tsm_is_processing' ); | |
| 58 | - } | |
| 59 | - | |
| 60 | - } | |
| 61 | - | |
| 62 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +if ( ! class_exists( 'TSM_Process_Tracking_Scripts' ) ) { | |
| 4 | + | |
| 5 | + class TSM_Process_Tracking_Scripts extends WP_Background_Process { | |
| 6 | + | |
| 7 | + /** | |
| 8 | + * @var string | |
| 9 | + */ | |
| 10 | + protected $action = 'process_tracking_scripts'; | |
| 11 | + /** | |
| 12 | + * Task | |
| 13 | + * | |
| 14 | + * Override this method to perform any actions required on each | |
| 15 | + * queue item. Return the modified item for further processing | |
| 16 | + * in the next pass through. Or, return false to remove the | |
| 17 | + * item from the queue. | |
| 18 | + * | |
| 19 | + * @param mixed $item Queue item to iterate over | |
| 20 | + * | |
| 21 | + * @return mixed | |
| 22 | + */ | |
| 23 | + protected function task( $script ) { | |
| 24 | + $script_post = array( | |
| 25 | + 'post_type' => 'r8_tracking_scripts', | |
| 26 | + 'post_title' => $script->script_name, | |
| 27 | + 'post_content' => '', | |
| 28 | + 'post_status' => 'publish', | |
| 29 | + 'meta_input' => array( | |
| 30 | + 'r8_tsm_script_code' => $script->script_code, | |
| 31 | + 'r8_tsm_active' => $script->active ? 'active' : 'inactive', | |
| 32 | + 'r8_tsm_script_order' => $script->order ? $script->order : 1, | |
| 33 | + 'r8_tsm_script_location' => $script->location, | |
| 34 | + 'r8_tsm_script_page' => $script->page_id ? array( $script->page_id ) : array(), | |
| 35 | + ), | |
| 36 | + ); | |
| 37 | + | |
| 38 | + $post_id = wp_insert_post( $script_post ); | |
| 39 | + | |
| 40 | + return false; | |
| 41 | + } | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Complete | |
| 45 | + * | |
| 46 | + * Override if applicable, but ensure that the below actions are | |
| 47 | + * performed, or, call parent::complete(). | |
| 48 | + */ | |
| 49 | + protected function complete() { | |
| 50 | + parent::complete(); | |
| 51 | + // Show notice to user or perform some other arbitrary task... | |
| 52 | + | |
| 53 | + delete_option( 'header_tracking_script_code' ); | |
| 54 | + delete_option( 'page_tracking_script_code' ); | |
| 55 | + delete_option( 'footer_tracking_script_code' ); | |
| 56 | + delete_option( 'tsm_is_processing' ); | |
| 57 | + } | |
| 58 | + | |
| 59 | + } | |
| 60 | + | |
| 61 | +} | |