# tracking-script-manager/2.0.1/classes/class-process-tracking-scripts.php

Tracking Script Manager, version 2.0.1. 62 lines.

- Page: https://pluginprobe.com/plugins/tracking-script-manager/2.0.1/code/classes/class-process-tracking-scripts.php
- Raw: https://pluginprobe.com/plugins/tracking-script-manager/2.0.1/raw/classes/class-process-tracking-scripts.php
- Modified: 2019-04-01T18:51:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tracking-script-manager/2.0.1/code/classes/class-process-tracking-scripts.php#L10-L20`.

```php
<?php 

if ( ! class_exists( 'TSM_Process_Tracking_Scripts' ) ) { 

    class TSM_Process_Tracking_Scripts extends WP_Background_Process {

        /**
         * @var string
         */
        protected $action = 'process_tracking_scripts';
        /**
         * Task
         *
         * Override this method to perform any actions required on each
         * queue item. Return the modified item for further processing
         * in the next pass through. Or, return false to remove the
         * item from the queue.
         *
         * @param mixed $item Queue item to iterate over
         *
         * @return mixed
         */
        protected function task( $script ) {

            $script_post = array(
                'post_type'    => 'r8_tracking_scripts',
                'post_title'   => $script->script_name,
                'post_content' => '',
                'post_status'  => 'publish',
                'meta_input'   => array(
                    'r8_tsm_script_code'     => $script->script_code,
                    'r8_tsm_active'          => $script->active ? 'active' : 'inactive',
                    'r8_tsm_script_order'    => $script->order ? $script->order : 1,
                    'r8_tsm_script_location' => $script->location,
                    'r8_tsm_script_page'	 => $script->page_id ? array($script->page_id) : array()
                ),
            );

            $post_id = wp_insert_post( $script_post );

            return false;
        }

        /**
         * Complete
         *
         * Override if applicable, but ensure that the below actions are
         * performed, or, call parent::complete().
         */
        protected function complete() {
            parent::complete();
            // Show notice to user or perform some other arbitrary task...
            
            delete_option( 'header_tracking_script_code' );
            delete_option( 'page_tracking_script_code' );
            delete_option( 'footer_tracking_script_code' );
            delete_option( 'tsm_is_processing' );
        }

    }

}
```
