PluginProbe
Tracking Script Manager / trunk
Tracking Script Manager vtrunk
trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 All 33 releases
tracking-script-manager / classes / class-process-tracking-scripts.php

class-process-tracking-scripts.php in Tracking Script Manager trunk, at classes/class-process-tracking-scripts.php

62 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
62