Plugin Directory

Changeset 2760412


Ignore:
Timestamp:
07/22/2022 05:37:31 PM (4 years ago)
Author:
red8developers
Message:

Security standards update

Location:
tracking-script-manager/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tracking-script-manager/trunk/classes/class-process-tracking-scripts.php

    r2717706 r2760412  
    1 <?php 
     1<?php
    22
    3 if ( ! class_exists( 'TSM_Process_Tracking_Scripts' ) ) { 
     3if ( ! class_exists( 'TSM_Process_Tracking_Scripts' ) ) {
    44
    5     class TSM_Process_Tracking_Scripts extends WP_Background_Process {
     5    class TSM_Process_Tracking_Scripts extends WP_Background_Process {
    66
    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 ) {
     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            );
    2437
    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            $post_id = wp_insert_post( $script_post );
    3839
    39             $post_id = wp_insert_post( $script_post );
     40            return false;
     41        }
    4042
    41             return false;
    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...
    4352
    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         }
     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        }
    5958
    60     }
     59    }
    6160
    6261}
  • tracking-script-manager/trunk/tracking-scripts-manager.php

    r2717706 r2760412  
    5656            add_action( 'add_meta_boxes', array( $this, 'add_script_metaboxes' ) );
    5757            add_action( 'wp_ajax_tracking_scripts_get_posts', array( $this, 'tracking_scripts_posts_ajax_handler' ) );
    58             add_action( 'manage_r8_tracking_scripts_posts_custom_column', array(
    59                 $this,
    60                 'tracking_script_column_content'
    61             ), 10, 2 );
     58            add_action(
     59                'manage_r8_tracking_scripts_posts_custom_column',
     60                array(
     61                    $this,
     62                    'tracking_script_column_content',
     63                ),
     64                10,
     65                2
     66            );
    6267            add_action( 'wp_body_open', array( $this, 'find_page_tracking_codes' ) );
    6368            add_action( 'tsm_page_scripts', array( $this, 'find_page_tracking_codes' ) );
     
    6570            add_action( 'admin_notices', array( $this, 'admin_notices' ) );
    6671            add_action( 'admin_notices', array( $this, 'new_update_admin_notice' ) );
    67             add_action( 'admin_init', array( $this, "init_update_admin_notice" ) );
     72            add_action( 'admin_init', array( $this, 'init_update_admin_notice' ) );
    6873            // fallback for page scripts if wp_body_open action isn't supported
    69             add_action( 'get_footer', function () {
    70                 if ( did_action( 'wp_body_open' ) === 0 ) {
    71                     add_action( 'wp_footer', array( $this, 'find_page_tracking_codes' ) );
    72                 }
    73             } );
     74            add_action(
     75                'get_footer',
     76                function () {
     77                    if ( did_action( 'wp_body_open' ) === 0 ) {
     78                        add_action( 'wp_footer', array( $this, 'find_page_tracking_codes' ) );
     79                    }
     80                }
     81            );
    7482            // Filters
    7583            add_filter( 'manage_r8_tracking_scripts_posts_columns', array( $this, 'add_tracking_script_columns' ) );
    76             add_filter( 'manage_edit-r8_tracking_scripts_sortable_columns', array(
    77                 $this,
    78                 'tracking_scripts_column_sort'
    79             ) );
     84            add_filter(
     85                'manage_edit-r8_tracking_scripts_sortable_columns',
     86                array(
     87                    $this,
     88                    'tracking_scripts_column_sort',
     89                )
     90            );
    8091            // Includes
    8192            require_once plugin_dir_path( __FILE__ ) . 'classes/wp-async-request.php';
     
    89100         **************************************************/
    90101        public function process_handler() {
    91 
    92102            if ( ! isset( $_GET['tsm_update_scripts'] ) || ! isset( $_GET['_wpnonce'] ) ) {
    93103                return;
    94104            }
    95             if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'tsm_update_scripts' ) ) {
     105            if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'tsm_update_scripts' ) ) {
    96106                return;
    97107            }
     
    105115            $scripts = $this->get_tracking_scripts();
    106116            if ( ! empty( $scripts ) ) {
    107 
    108117                foreach ( $scripts as $script ) {
    109118                    $this->process_all->push_to_queue( $script );
     
    113122        }
    114123
     124
    115125        protected function get_tracking_scripts() {
    116 
    117126            $scripts        = array();
    118             $header_scripts = get_option( 'header_tracking_script_code' ) ? unserialize( get_option( 'header_tracking_script_code' ) ) : null;
    119             $page_scripts   = get_option( 'page_tracking_script_code' ) ? unserialize( get_option( 'page_tracking_script_code' ) ) : null;
    120             $footer_scripts = get_option( 'footer_tracking_script_code' ) ? unserialize( get_option( 'footer_tracking_script_code' ) ) : null;
     127            $header_scripts = get_option( 'header_tracking_script_code' ) ? json_decode( get_option( 'header_tracking_script_code' ) ) : null;
     128            $page_scripts   = get_option( 'page_tracking_script_code' ) ? json_decode( get_option( 'page_tracking_script_code' ) ) : null;
     129            $footer_scripts = get_option( 'footer_tracking_script_code' ) ? json_decode( get_option( 'footer_tracking_script_code' ) ) : null;
    121130            if ( ! empty( $header_scripts ) ) {
    122131                $scripts = array_merge( $scripts, $header_scripts );
     
    138147            $footer_scripts       = get_option( 'footer_tracking_script_code' );
    139148            $is_processing        = get_option( 'tsm_is_processing' );
    140             $has_tracking_scripts = ( $header_scripts || $page_scripts || $footer_scripts ) ? true : false;
    141             $is_admin             = current_user_can( 'manage_options' ) ? true : false;
     149            $has_tracking_scripts = $header_scripts || $page_scripts || $footer_scripts;
     150            $is_admin             = current_user_can( 'manage_options' );
    142151            if ( $has_tracking_scripts && $is_processing && $is_admin ) {
    143152                $message = __( 'Your scripts are currently processing. This may take several minutes. If you don’t see all of your scripts please wait a moment and refresh the page.', TRACKING_SCRIPT_TEXTDOMAIN );
    144153                $notice  = sprintf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
    145                 echo $notice;
     154                echo esc_html( $notice );
    146155            }
    147156            if ( $has_tracking_scripts && ! $is_processing && $is_admin ) {
     
    149158                $message = __( 'Tracking Scripts Manager has updated to a new version, click OK to update your scripts to the updated version.', TRACKING_SCRIPT_TEXTDOMAIN );
    150159                $notice  = sprintf( '<div class="%1$s"><p>%2$s</p><a class="button button-primary" href="%3$s" style="margin-bottom: .5em;">OK</a></div>', esc_attr( $class ), esc_html( $message ), esc_url( $url ) );
    151                 echo $notice;
     160                echo esc_html( $notice );
    152161            }
    153162        }
     
    157166         */
    158167        public function init_update_admin_notice() {
    159 
    160168            $user_id = get_current_user_id();
    161169            if ( isset( $_GET['tsm_update_notice_dismissed'] ) ) {
     
    171179            $user_id = get_current_user_id();
    172180            if ( ! get_user_meta( $user_id, 'tsm_update_notice_dismissed' ) ) {
    173                 $url=admin_url()."edit.php?post_type=r8_tracking_scripts&tsm_update_notice_dismissed";
     181                $url = admin_url() . 'edit.php?post_type=r8_tracking_scripts&tsm_update_notice_dismissed';
    174182                ?>
    175183                <div class="notice notice-success ">
    176                     <p><?php _e( 'An error in Tracking Scripts Manager 2.0.6 may have deactivated your scripts. Please click <a href="'.$url.'">here</a> to review the status of your scripts and reactivate them as needed.', '' ); ?></p>
     184                    <p><?php esc_html_e( 'An error in Tracking Scripts Manager 2.0.6 may have deactivated your scripts. Please click <a href="' . esc_url( $url ) . '">here</a> to review the status of your scripts and reactivate them as needed.', TRACKING_SCRIPT_TEXTDOMAIN ); ?></p>
    177185                    <a href="?tsm_update_notice_dismissed">Dismiss this notice</a>
    178186                </div>
     
    181189        }
    182190
    183         public function print_tsm_scripts( $script_id, $page, $page_id, $expiry_info ) {
    184             $expiry_data      = $this->expiry_data( $expiry_info );
    185             $if_expire        = $this->check_expiry_script( $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date'], $script_id );
    186 
    187             if ( $expiry_data['type'] == 'Schedule' ) {
    188                 if ( ! $if_expire ) {
    189                     if ( is_array( $page ) && in_array( intval( $page_id ), $page ) ) {
    190                         echo html_entity_decode( get_post_meta( $script_id, 'r8_tsm_script_code', true ), ENT_QUOTES, 'cp1252' );
    191                     } elseif ( empty( $page ) ) {
    192                         echo html_entity_decode( get_post_meta( $script_id, 'r8_tsm_script_code', true ), ENT_QUOTES, 'cp1252' );
    193                     }
    194                 }
    195             } else {
    196                 if ( is_array( $page ) && in_array( intval( $page_id ), $page ) ) {
    197                     echo html_entity_decode( get_post_meta( $script_id, 'r8_tsm_script_code', true ), ENT_QUOTES, 'cp1252' );
    198                 } elseif ( empty( $page ) ) {
    199                     echo html_entity_decode( get_post_meta( $script_id, 'r8_tsm_script_code', true ), ENT_QUOTES, 'cp1252' );
     191
     192
     193        public function print_tsm_scripts( $script_id, $page, $page_id, $expiry_info ) {
     194            $expiry_data = $this->expiry_data( $expiry_info );
     195            $if_expire   = $this->check_expiry_script( $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date'], $script_id );
     196            $script      = get_post_meta( $script_id, 'r8_tsm_script_code', true );
     197
     198            $encoded_save = get_post_meta( $script_id, 'r8_tsm_encoded_save', true );
     199            if(!$encoded_save){
     200                $script=base64_encode($script);
     201                $this->save_script($script_id,$script);
     202            }
     203
     204            $page_script = $this->esc_script( $script );
     205
     206
     207            // Check if this is the right page
     208            if ( ( is_array( $page ) && in_array( intval( $page_id ), $page, true ) ) || empty( $page ) ) {
     209                // Is it scheduled and not expired or set never to expire?
     210                if ( 'Schedule' === $expiry_data['type'] && ! $if_expire || 'Never' === $expiry_data['type'] ) {
     211                    // Render script
     212                    echo( $page_script );
    200213                }
    201214            }
     
    204217        // Header Tracking Codes
    205218        function find_header_tracking_codes() {
    206 
    207219            global $wp_query;
    208             $page_id = $wp_query->post->ID;
    209             $args = array(
     220            $page_id        = $wp_query->post->ID;
     221            $args           = array(
    210222                'post_type'      => 'r8_tracking_scripts',
    211223                'post_status'    => 'publish',
     
    219231                        'key'     => 'r8_tsm_script_location',
    220232                        'value'   => 'header',
    221                         'compare' => '='
     233                        'compare' => '=',
    222234                    ),
    223235                    array(
    224236                        'key'     => 'r8_tsm_active',
    225237                        'value'   => 'active',
    226                         'compare' => '='
    227                     )
    228                 )
     238                        'compare' => '=',
     239                    ),
     240                ),
    229241            );
    230242            $header_scripts = new WP_Query( $args );
    231243            if ( $header_scripts->have_posts() ) {
    232                 while ( $header_scripts->have_posts() ) : $header_scripts->the_post();
     244                while ( $header_scripts->have_posts() ) :
     245                    $header_scripts->the_post();
    233246                    $page        = get_post_meta( get_the_ID(), 'r8_tsm_script_page', true );
    234247                    $expiry_info = get_post_meta( get_the_ID(), 'r8_tsm_script_expiry_info', true );
     
    240253
    241254        function find_page_tracking_codes() {
    242 
    243255            global $wp_query;
    244             $page_id = $wp_query->post->ID;
    245             $args = array(
     256            $page_id      = $wp_query->post->ID;
     257            $args         = array(
    246258                'post_type'      => 'r8_tracking_scripts',
    247259                'posts_per_page' => - 1,
     
    255267                        'key'     => 'r8_tsm_script_location',
    256268                        'value'   => 'page',
    257                         'compare' => '='
     269                        'compare' => '=',
    258270                    ),
    259271                    array(
    260272                        'key'     => 'r8_tsm_active',
    261273                        'value'   => 'active',
    262                         'compare' => '='
    263                     )
    264                 )
     274                        'compare' => '=',
     275                    ),
     276                ),
    265277            );
    266278            $page_scripts = new WP_Query( $args );
    267279            if ( $page_scripts->have_posts() ) {
    268                 while ( $page_scripts->have_posts() ) : $page_scripts->the_post();
     280                while ( $page_scripts->have_posts() ) :
     281                    $page_scripts->the_post();
    269282                    $page        = get_post_meta( get_the_ID(), 'r8_tsm_script_page', true );
    270283                    $expiry_info = get_post_meta( get_the_ID(), 'r8_tsm_script_expiry_info', true );
     
    277290        function find_footer_tracking_codes() {
    278291            global $wp_query;
    279             $page_id = $wp_query->post->ID;
    280             $args = array(
     292            $page_id        = $wp_query->post->ID;
     293            $args           = array(
    281294                'post_type'      => 'r8_tracking_scripts',
    282295                'posts_per_page' => - 1,
     
    290303                        'key'     => 'r8_tsm_script_location',
    291304                        'value'   => 'footer',
    292                         'compare' => '='
     305                        'compare' => '=',
    293306                    ),
    294307                    array(
    295308                        'key'     => 'r8_tsm_active',
    296309                        'value'   => 'active',
    297                         'compare' => '='
    298                     )
    299                 )
     310                        'compare' => '=',
     311                    ),
     312                ),
    300313            );
    301314            $footer_scripts = new WP_Query( $args );
    302315            if ( $footer_scripts->have_posts() ) {
    303                 while ( $footer_scripts->have_posts() ) : $footer_scripts->the_post();
     316                while ( $footer_scripts->have_posts() ) :
     317                    $footer_scripts->the_post();
    304318                    $page        = get_post_meta( get_the_ID(), 'r8_tsm_script_page', true );
    305319                    $expiry_info = get_post_meta( get_the_ID(), 'r8_tsm_script_expiry_info', true );
     
    311325
    312326        function add_tracking_script_columns( $columns ) {
    313 
    314327            $columns = array(
    315328                'cb'       => '<input type="checkbox" />',
     
    318331                'location' => __( 'Location', TRACKING_SCRIPT_TEXTDOMAIN ),
    319332                'status'   => __( 'Status', TRACKING_SCRIPT_TEXTDOMAIN ),
    320                 'schedule'   => __( 'Schedule', TRACKING_SCRIPT_TEXTDOMAIN ),
     333                'schedule' => __( 'Schedule', TRACKING_SCRIPT_TEXTDOMAIN ),
    321334            );
    322335
     
    325338
    326339        function tracking_script_column_content( $column_name, $post_ID ) {
    327             $expiry_info      = get_post_meta( $post_ID, 'r8_tsm_script_expiry_info', true );
    328             $expiry_data      = $this->expiry_data( $expiry_info );
     340            $expiry_info      = get_post_meta( $post_ID, 'r8_tsm_script_expiry_info', true );
     341            $expiry_data      = $this->expiry_data( $expiry_info );
    329342            $if_expire        = $this->check_expiry_script( $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date'], $post_ID );
    330             $scheduled_status = $this->scheduled_status($if_expire, $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date']);
    331  
     343            $scheduled_status = $this->scheduled_status( $if_expire, $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date'] );
     344
    332345            if ( $column_name === 'status' ) {
    333346                $active = get_post_meta( $post_ID, 'r8_tsm_active', true );
    334                 echo ($active == 'inactive') ? '<span class="expired">' : '<span>';
    335                     if ( $active === 'active' ) {
    336                         echo 'Active';
    337                     } else {
    338                         echo 'Inactive';
    339                     }
    340                     echo $scheduled_status;
     347                echo ( $active === 'inactive' ) ? '<span class="expired">' : '<span>';
     348                if ( $active === 'active' ) {
     349                    echo 'Active';
     350                } else {
     351                    echo 'Inactive';
     352                }
     353                    echo esc_attr( $scheduled_status );
    341354                echo '</span>';
    342355            }
     
    353366                $location = get_post_meta( $post_ID, 'r8_tsm_script_location', true );
    354367                if ( $location ) {
    355                     echo ucwords( $location );
     368                    echo esc_html( ucwords( $location ) );
    356369                }
    357370            }
    358371            if ( $column_name === 'schedule' ) {
    359 
    360                 if ( $expiry_data['type'] == 'Schedule' ) {
    361                     echo sprintf( __( 'Scheduled <b>%s</b> to <b>%s</b>', TRACKING_SCRIPT_TEXTDOMAIN ), $expiry_data['start_date'], $expiry_data['end_date'] );
     372                if ( $expiry_data['type'] === 'Schedule' ) {
     373                    echo esc_html(
     374                        sprintf(
     375                            __( 'Scheduled <b>%1$s</b> to <b>%2$s</b>', TRACKING_SCRIPT_TEXTDOMAIN ),
     376                            ( $expiry_data['start_date'] ),
     377                            ( $expiry_data['end_date'] )
     378                        )
     379                    );
    362380                } else {
    363                     echo __('Never expires', TRACKING_SCRIPT_TEXTDOMAIN);
    364                 } 
     381                    esc_html_e( 'Never expires', TRACKING_SCRIPT_TEXTDOMAIN );
     382                }
    365383            }
    366384        }
    367385
    368386        function tracking_scripts_column_sort( $columns ) {
    369 
    370387            $columns['global']   = 'global';
    371388            $columns['location'] = 'location';
    372389            $columns['status']   = 'status';
    373             $columns['schedule']   = 'schedule';
     390            $columns['schedule'] = 'schedule';
    374391
    375392            return $columns;
     
    377394
    378395        public function add_script_metaboxes() {
    379 
    380             add_meta_box( 'r8_tsm_script_code_wrapper', __( 'Script Code', TRACKING_SCRIPT_TEXTDOMAIN ), array(
    381                 $this,
    382                 'script_code_metabox'
    383             ), 'r8_tracking_scripts', 'normal' );
    384             add_meta_box( 'r8_tsm_script_active', __( 'Script Status', TRACKING_SCRIPT_TEXTDOMAIN ), array(
    385                 $this,
    386                 'script_active_metabox'
    387             ), 'r8_tracking_scripts', 'side' );
    388             add_meta_box( 'r8_tsm_script_expiry', __( 'Schedule', TRACKING_SCRIPT_TEXTDOMAIN ), array(
    389                 $this,
    390                 'script_expiry_metabox'
    391             ), 'r8_tracking_scripts', 'side' );
    392             add_meta_box( 'r8_tsm_script_order', __( 'Script Order', TRACKING_SCRIPT_TEXTDOMAIN ), array(
    393                 $this,
    394                 'script_order_metabox'
    395             ), 'r8_tracking_scripts', 'side' );
    396             add_meta_box( 'r8_tsm_script_location', __( 'Script Location', TRACKING_SCRIPT_TEXTDOMAIN ), array(
    397                 $this,
    398                 'script_location_metabox'
    399             ), 'r8_tracking_scripts', 'normal' );
    400             add_meta_box( 'r8_tsm_script_page', __( 'Specific Script Placement (Page(s) or Post(s))', TRACKING_SCRIPT_TEXTDOMAIN ), array(
    401                 $this,
    402                 'script_page_metabox'
    403             ), 'r8_tracking_scripts', 'normal' );
     396            add_meta_box(
     397                'r8_tsm_script_code_wrapper',
     398                __( 'Script Code', TRACKING_SCRIPT_TEXTDOMAIN ),
     399                array(
     400                    $this,
     401                    'script_code_metabox',
     402                ),
     403                'r8_tracking_scripts',
     404                'normal'
     405            );
     406            add_meta_box(
     407                'r8_tsm_script_active',
     408                __( 'Script Status', TRACKING_SCRIPT_TEXTDOMAIN ),
     409                array(
     410                    $this,
     411                    'script_active_metabox',
     412                ),
     413                'r8_tracking_scripts',
     414                'side'
     415            );
     416            add_meta_box(
     417                'r8_tsm_script_expiry',
     418                __( 'Schedule', TRACKING_SCRIPT_TEXTDOMAIN ),
     419                array(
     420                    $this,
     421                    'script_expiry_metabox',
     422                ),
     423                'r8_tracking_scripts',
     424                'side'
     425            );
     426            add_meta_box(
     427                'r8_tsm_script_order',
     428                __( 'Script Order', TRACKING_SCRIPT_TEXTDOMAIN ),
     429                array(
     430                    $this,
     431                    'script_order_metabox',
     432                ),
     433                'r8_tracking_scripts',
     434                'side'
     435            );
     436            add_meta_box(
     437                'r8_tsm_script_location',
     438                __( 'Script Location', TRACKING_SCRIPT_TEXTDOMAIN ),
     439                array(
     440                    $this,
     441                    'script_location_metabox',
     442                ),
     443                'r8_tracking_scripts',
     444                'normal'
     445            );
     446            add_meta_box(
     447                'r8_tsm_script_page',
     448                __( 'Specific Script Placement (Page(s) or Post(s))', TRACKING_SCRIPT_TEXTDOMAIN ),
     449                array(
     450                    $this,
     451                    'script_page_metabox',
     452                ),
     453                'r8_tracking_scripts',
     454                'normal'
     455            );
    404456        }
    405457
    406458        function script_code_metabox() {
    407 
    408459            global $post;
    409460            $script_code = get_post_meta( $post->ID, 'r8_tsm_script_code', true );
    410             include_once( TRACKING_SCRIPT_DIR_PATH . '/templates/script-code-metabox.php' );
    411         }
    412 
    413         function script_active_metabox() {
     461            /**
     462             * Check if script was saved using base64 encode
     463             */
     464            $encoded_save = get_post_meta( $post->ID, 'r8_tsm_encoded_save', true );
     465            if ( !$encoded_save ) {
     466                $script_code=base64_encode($script_code);
     467                $this->save_script($post->ID,$script_code);
     468            }
     469
     470            if($this->is_file_modification_allowed()){
     471                ?>
     472                <div class="red8_script_notice" style="    padding: 1rem;    border: 1px solid lightcoral;    box-shadow: 0 2px 6px rgb(0 0 0 / 25%);    border-radius: 11px;}">
     473                    <h1>Heads up!</h1>
     474                    <p>
     475                        Adding custom scripts is not recommended and could break your site.
     476                    </p>
     477                    <p>
     478                        Please double check that the code you are adding is secure and make sure your WordPress site is backed up
     479                    in the likely event that something breaks.</p>
     480
     481                    <p>
     482                        <button type="button" class="button button-primary consent">I understand</button>
     483                    </p>
     484
     485                </div>
     486                <script type="text/javascript">
     487                    jQuery(function($){
     488                        $(".red8_script_notice button.consent").on("click",function(){
     489                            $(".red8_script_notice").hide();
     490                            $("#red8_code_editor_wrapper")
     491                            .css("opacity",1)
     492                            .css('height','auto');
     493
     494                        })
     495                    })
     496                </script>
     497
     498                <div id="red8_code_editor_wrapper" style="opacity: 0; height: 0;">
     499                    <textarea name="r8_tsm_script_code" id="r8_tsm_script_code" rows="5" ><?php
     500                        if ( $script_code ) {
     501                            echo stripslashes(html_entity_decode( base64_decode($script_code), ENT_QUOTES, 'cp1252' ));
     502                        }
     503                        ?></textarea>
     504                </div>
     505
     506                <?php
     507            }
     508            else{
     509                ?>
     510                <div class="notice notice-error ">
     511                    <p>File modification & custom scripts have been disallowed by your WordPress config.</p>
     512                </div>
     513                <?php
     514            }
     515
     516        }
     517
     518        function script_active_metabox() {
    414519            global $post;
    415             $active = get_post_meta( $post->ID, 'r8_tsm_active', true );
    416             $expiry_info       = get_post_meta( $post->ID, 'r8_tsm_script_expiry_info', true );
    417             $expiry_data      = $this->expiry_data( $expiry_info );
     520            $active           = get_post_meta( $post->ID, 'r8_tsm_active', true );
     521            $expiry_info      = get_post_meta( $post->ID, 'r8_tsm_script_expiry_info', true );
     522            $expiry_data      = $this->expiry_data( $expiry_info );
    418523            $if_expire        = $this->check_expiry_script( $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date'], $post->ID );
    419             $scheduled_status = $this->scheduled_status($if_expire, $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date']);
    420 
    421             include_once( TRACKING_SCRIPT_DIR_PATH . '/templates/script-active-metabox.php' );
     524            $scheduled_status = $this->scheduled_status( $if_expire, $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date'] );
     525
     526            include_once TRACKING_SCRIPT_DIR_PATH . '/templates/script-active-metabox.php';
    422527        }
    423528
    424529        function script_expiry_metabox() {
    425530            global $post;
    426             $expiry_info       = get_post_meta( $post->ID, 'r8_tsm_script_expiry_info', true );
    427             $expiry_data      = $this->expiry_data( $expiry_info );
     531            $expiry_info      = get_post_meta( $post->ID, 'r8_tsm_script_expiry_info', true );
     532            $expiry_data      = $this->expiry_data( $expiry_info );
    428533            $if_expire        = $this->check_expiry_script( $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date'], $post->ID );
    429             $scheduled_status = $this->scheduled_status($if_expire, $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date']);
    430             include_once( TRACKING_SCRIPT_DIR_PATH . '/templates/script-expiry-metabox.php' );
     534            $scheduled_status = $this->scheduled_status( $if_expire, $expiry_data['type'], $expiry_data['start_date'], $expiry_data['end_date'] );
     535            include_once TRACKING_SCRIPT_DIR_PATH . '/templates/script-expiry-metabox.php';
    431536        }
    432537
    433538        function script_order_metabox() {
    434 
    435539            global $post;
    436540            $order = get_post_meta( $post->ID, 'r8_tsm_script_order', true );
    437             include_once( TRACKING_SCRIPT_DIR_PATH . '/templates/script-order-metabox.php' );
     541            include_once TRACKING_SCRIPT_DIR_PATH . '/templates/script-order-metabox.php';
    438542        }
    439543
    440544        function script_location_metabox() {
    441 
    442545            global $post;
    443546            $location = get_post_meta( $post->ID, 'r8_tsm_script_location', true );
    444             include_once( TRACKING_SCRIPT_DIR_PATH . '/templates/script-location-metabox.php' );
     547            include_once TRACKING_SCRIPT_DIR_PATH . '/templates/script-location-metabox.php';
    445548        }
    446549
    447550        function script_page_metabox() {
    448 
    449551            global $post;
    450552            $script_page = get_post_meta( $post->ID, 'r8_tsm_script_page', true );
    451             include_once( TRACKING_SCRIPT_DIR_PATH . '/templates/script-page-metabox.php' );
    452         } 
     553            include_once TRACKING_SCRIPT_DIR_PATH . '/templates/script-page-metabox.php';
     554        }
    453555
    454556        public function get_date_time( $timespan, $format ) {
     
    460562        }
    461563
    462         public function check_expiry_script( $expiry_date_type, $expiry_start_date, $expiry_end_date, $script_id ) { 
     564        public function check_expiry_script( $expiry_date_type, $expiry_start_date, $expiry_end_date, $script_id ) {
    463565            $result = false;
    464             if ( $expiry_date_type == 'Never' ) {
     566            if ( $expiry_date_type === 'Never' ) {
    465567                return $result;
    466             } 
    467             if ( empty($expiry_start_date) ) {
     568            }
     569            if ( empty( $expiry_start_date ) ) {
    468570                return $result;
    469             } 
    470             if ( empty($expiry_end_date) ) {
     571            }
     572            if ( empty( $expiry_end_date ) ) {
    471573                return $result;
    472             } 
    473  
    474             $date_range = [];
     574            }
     575
     576            $date_range = array();
    475577            $start_time = $expiry_start_date;
    476             $interval = new DateInterval('P1D');
    477             $end_time  = new DateTime( $expiry_end_date );
    478             $end_time->add($interval);
    479             $period = new DatePeriod(new DateTime($start_time), $interval, $end_time);
    480             $today  = new DateTime();
    481             $today_date = $today->format('Y-m-d');
    482             foreach ($period as $key => $value) {
    483                 $array[] = $value->format('Y-m-d');     
    484             }
    485             if ( ! in_array($today_date, $array ) ) {
     578            $interval   = new DateInterval( 'P1D' );
     579            $end_time   = new DateTime( $expiry_end_date );
     580            $end_time->add( $interval );
     581            $period     = new DatePeriod( new DateTime( $start_time ), $interval, $end_time );
     582            $today      = new DateTime();
     583            $today_date = $today->format( 'Y-m-d' );
     584            foreach ( $period as $key => $value ) {
     585                $array[] = $value->format( 'Y-m-d' );
     586            }
     587            if ( ! in_array( $today_date, $array, true ) ) {
    486588                $result = true;
    487589            }
    488             $this->set_script_status( $script_id, $result ); 
     590            $this->set_script_status( $script_id, $result );
    489591            return $result;
    490592        }
     
    494596            if ( ! empty( $post->post_type ) ) {
    495597                if ( $post->post_type === 'r8_tracking_scripts' ) {
    496                     if( $script_id == $post->ID ){
     598                    if ( $script_id === $post->ID ) {
    497599                        $active = get_post_meta( $post->ID, 'r8_tsm_active', true );
    498                         if( $result == true ){ // expire true
     600                        if ( $result === true ) { // expire true
    499601                            if ( 'active' === $active ) {
    500602                                update_post_meta( $post->ID, 'r8_tsm_active', 'inactive' );
    501603                            }
    502                         }else{ // expire false
     604                        } else { // expire false
    503605                            if ( 'inactive' === $active ) {
    504606                                update_post_meta( $post->ID, 'r8_tsm_active', 'active' );
    505607                            }
    506608                        }
    507 
    508                     }
    509                 }
    510             }
    511         }
    512 
    513         public function expiry_data($expiry_info){
    514             $type  = is_object( $expiry_info ) ? $expiry_info->type : 'Never';
    515             $start_date  = is_object( $expiry_info ) ? $expiry_info->schedule_start : '';
    516             $end_date = is_object( $expiry_info ) ? $expiry_info->schedule_end : ''; 
    517             return [
    518                 'type' => $type,
     609                    }
     610                }
     611            }
     612        }
     613
     614        public function expiry_data( $expiry_info ) {
     615            $type       = is_object( $expiry_info ) ? $expiry_info->type : 'Never';
     616            $start_date = is_object( $expiry_info ) ? $expiry_info->schedule_start : '';
     617            $end_date   = is_object( $expiry_info ) ? $expiry_info->schedule_end : '';
     618            return array(
     619                'type'       => $type,
    519620                'start_date' => $start_date,
    520                 'end_date' => $end_date,
    521             ];
    522         }
    523 
    524         public function scheduled_status($if_expire, $expiry_date_type, $expiry_start_date, $expiry_end_date){
     621                'end_date'   => $end_date,
     622            );
     623        }
     624
     625        public function scheduled_status( $if_expire, $expiry_date_type, $expiry_start_date, $expiry_end_date ) {
    525626            $status = '';
    526             $start = new DateTime($expiry_start_date);
    527             $end = new DateTime($expiry_end_date);
    528             $today = new DateTime();
    529             if ( $expiry_date_type == 'Schedule' ) {
    530                 if( !$if_expire ){
     627            $start  = new DateTime( $expiry_start_date );
     628            $end    = new DateTime( $expiry_end_date );
     629            $today  = new DateTime();
     630            if ( $expiry_date_type === 'Schedule' ) {
     631                if ( ! $if_expire ) {
    531632                    $status = '';
    532                 }else{
    533                     if( $today < $start ) {
    534                         $diff = strtotime($today->format("y-m-d")) - strtotime($start->format("y-m-d"));
    535                         $count = abs(round($diff / 86400));   
    536                         $status =  ' (Starting ' . sprintf( _n( 'tomorrow', 'in %s days', $count, 'text-domain' ), number_format_i18n( $count ) ) . ') ';
    537                     }
    538                     if( $today > $end ) $status = " (Expired)";
     633                } else {
     634                    if ( $today < $start ) {
     635                        $diff      = strtotime( $today->format( 'y-m-d' ) ) - strtotime( $start->format( 'y-m-d' ) );
     636                        $count     = abs( round( $diff / 86400 ) );
     637                        $next_date = sprintf( _n( 'tomorrow', 'in %s days', $count, 'tracking-scripts-manager' ), $count );
     638                        $status    = sprintf( '(Starting %s) ', $next_date );
     639                    }
     640                    if ( $today > $end ) {
     641                        $status = ' (Expired)';
     642                    }
    539643                }
    540644            }
     
    543647
    544648        public function register_scripts_post_type() {
    545 
    546649            $labels = array(
    547650                'name'               => _x( 'Tracking Scripts', TRACKING_SCRIPT_TEXTDOMAIN ),
     
    558661                'parent_item_colon'  => __( 'Parent Tracking Scripts:', TRACKING_SCRIPT_TEXTDOMAIN ),
    559662                'not_found'          => __( 'No Tracking Scripts found.', TRACKING_SCRIPT_TEXTDOMAIN ),
    560                 'not_found_in_trash' => __( 'No Tracking Scripts found in Trash.', TRACKING_SCRIPT_TEXTDOMAIN )
    561             );
    562             $args = array(
     663                'not_found_in_trash' => __( 'No Tracking Scripts found in Trash.', TRACKING_SCRIPT_TEXTDOMAIN ),
     664            );
     665            $args   = array(
    563666                'labels'             => $labels,
    564667                'description'        => __( 'Description.', TRACKING_SCRIPT_TEXTDOMAIN ),
     
    578681                    'delete_posts'       => 'manage_options',
    579682                    'publish_posts'      => 'manage_options',
    580                     'read_private_posts' => 'manage_options'
     683                    'read_private_posts' => 'manage_options',
    581684                ),
    582685                'has_archive'        => false,
     
    588691                    'script-active',
    589692                    'script-location',
    590                     'script-order'
    591                 )
     693                    'script-order',
     694                ),
    592695            );
    593696            register_post_type( 'r8_tracking_scripts', $args );
     
    601704            if ( $hook === 'post.php' || $hook === 'post-new.php' ) {
    602705                if ( ! empty( $post->post_type ) && ( $post->post_type === 'r8_tracking_scripts' ) ) {
    603                     wp_enqueue_style( 'r8-tsm-edit-script', plugins_url( '/css/tracking-script-edit.css', __FILE__ ), [], md5_file( plugins_url( '/css/tracking-script-edit.css', __FILE__ ) ) );
    604                     wp_enqueue_style( 'r8-tsm-select2-css', plugins_url( '/css/select2.min.css', __FILE__ ), [], md5_file( plugins_url( '/css/select2.min.css', __FILE__ ) ) );
    605                     wp_enqueue_script( 'r8-tsm-select2-js', plugins_url( '/js/select2.min.js', __FILE__ ), [], md5_file( plugins_url( '/js/select2.min.js', __FILE__ ) ), true );
    606                     wp_enqueue_script( 'r8-tsm-post-edit-js', plugins_url( '/js/post-edit.js', __FILE__ ), [
    607                         'jquery',
    608                         'r8-tsm-select2-js'
    609                     ], md5_file( plugins_url( '/js/post-edit.js', __FILE__ ) ), true );
     706                    wp_enqueue_style( 'r8-tsm-edit-script', plugins_url( '/css/tracking-script-edit.css', __FILE__ ), array(), md5_file( plugins_url( '/css/tracking-script-edit.css', __FILE__ ) ) );
     707                    wp_enqueue_style( 'r8-tsm-select2-css', plugins_url( '/css/select2.min.css', __FILE__ ), array(), md5_file( plugins_url( '/css/select2.min.css', __FILE__ ) ) );
     708                    wp_enqueue_script( 'r8-tsm-select2-js', plugins_url( '/js/select2.min.js', __FILE__ ), array(), md5_file( plugins_url( '/js/select2.min.js', __FILE__ ) ), true );
     709                    wp_enqueue_script(
     710                        'r8-tsm-post-edit-js',
     711                        plugins_url( '/js/post-edit.js', __FILE__ ),
     712                        array(
     713                            'jquery',
     714                            'r8-tsm-select2-js',
     715                        ),
     716                        md5_file( plugins_url( '/js/post-edit.js', __FILE__ ) ),
     717                        true
     718                    );
    610719                    wp_enqueue_style( 'jquery-ui-css', 'https://code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css' );
    611720                    wp_enqueue_script( 'jquery-ui-datepicker' );
     
    614723            if ( $hook === 'post.php' || $hook === 'edit.php' ) {
    615724                if ( ! empty( $post->post_type ) && ( $post->post_type === 'r8_tracking_scripts' ) ) {
    616                     wp_enqueue_style( 'r8-tsm-post-list', plugins_url( '/css/post-list.css', __FILE__ ), [], md5_file( plugins_url( '/css/post-list.css', __FILE__ ) ) );
    617                     wp_enqueue_script( 'r8-tsm-post-list-js', plugins_url( '/js/post-list.js', __FILE__ ), ['jquery'], md5_file( plugins_url( '/js/post-list.js', __FILE__ ) ), true );
     725                    wp_enqueue_style( 'r8-tsm-post-list', plugins_url( '/css/post-list.css', __FILE__ ), array(), md5_file( plugins_url( '/css/post-list.css', __FILE__ ) ) );
     726                    wp_enqueue_script( 'r8-tsm-post-list-js', plugins_url( '/js/post-list.js', __FILE__ ), array( 'jquery' ), md5_file( plugins_url( '/js/post-list.js', __FILE__ ) ), true );
    618727                }
    619728            }
    620729            if ( ! empty( $post->post_type ) && ( $post->post_type === 'r8_tracking_scripts' ) ) {
    621                 // code eidtor support
    622                 $html_editor = wp_enqueue_code_editor( array( 'type' => 'text/html' ) );
    623                 if (false !== $html_editor) {
    624                 wp_add_inline_script(
    625                     'code-editor',
    626                     sprintf(
    627                     'jQuery( function() { wp.codeEditor.initialize( "r8_tsm_script_code", %s ); } );',
    628                     wp_json_encode( $html_editor )
    629                     )
    630                 );
    631                 }
    632             }
     730                // code editor support
     731                $html_editor = wp_enqueue_code_editor( array( 'type' => 'text/html' ) );
     732                if ( false !== $html_editor ) {
     733                    wp_add_inline_script(
     734                        'code-editor',
     735                        sprintf(
     736                            'jQuery( function() { wp.codeEditor.initialize( "r8_tsm_script_code", %s ); } );',
     737                            wp_json_encode( $html_editor )
     738                        )
     739                    );
     740                }
     741            }
     742        }
     743
     744        private function esc_script( $script ) {
     745            return stripslashes(html_entity_decode( base64_decode($script), ENT_QUOTES, 'cp1252' ));
     746        }
     747
     748        private function save_script($post_id,$script_code){
     749            $script_code = stripslashes( wp_unslash($script_code));
     750            update_post_meta( $post_id, 'r8_tsm_script_code', $script_code );
     751            update_post_meta( $post_id, 'r8_tsm_encoded_save', true );
     752        }
     753
     754
     755        private function is_file_modification_allowed(){
     756            if (defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS){
     757                return false;
     758            }
     759            return true;
    633760        }
    634761
    635762        function save_post() {
    636 
    637763            global $post;
    638764            if ( ! empty( $post->post_type ) ) {
    639765                if ( $post->post_type === 'r8_tracking_scripts' ) {
    640                     $expiry_obj        = new \stdClass();
    641                     $expiry_obj->schedule_start  = '';
    642                     $expiry_obj->schedule_end  = '';
    643                     $expiry_obj->type  = '';
    644                     // if ( ! empty( $_POST['r8_tsm_script_code'] ) ) {
    645                     update_post_meta( $post->ID, 'r8_tsm_script_code', stripslashes( esc_textarea( $_POST['r8_tsm_script_code'] ) ) );
    646                     // }
     766                    $expiry_obj                 = new \stdClass();
     767                    $expiry_obj->schedule_start = '';
     768                    $expiry_obj->schedule_end   = '';
     769                    $expiry_obj->type           = '';
     770                    if ( ! empty( $_POST['r8_tsm_script_code'] ) ) {
     771                        $script_code = base64_encode($_POST['r8_tsm_script_code'] );
     772                        $this->save_script($post->ID,$script_code);
     773
     774                    }
    647775                    if ( ! empty( $_POST['r8_tsm_active'] ) ) {
    648                         update_post_meta( $post->ID, 'r8_tsm_active', sanitize_text_field( $_POST['r8_tsm_active'] ) );
     776                        $tsm_active = sanitize_text_field( wp_unslash( $_POST['r8_tsm_active'] ) );
     777                        update_post_meta( $post->ID, 'r8_tsm_active', $tsm_active );
    649778                    }
    650779                    if ( ! empty( $_POST['r8_tsm_script_order'] ) ) {
     
    652781                    }
    653782                    if ( ! empty( $_POST['r8_tsm_script_location'] ) ) {
    654                         update_post_meta( $post->ID, 'r8_tsm_script_location', sanitize_text_field( $_POST['r8_tsm_script_location'] ) );
    655                     }
    656                     if ( ! empty( $_POST['r8_tsm_script_expiry'] ) || ( ! empty( $_POST['schedule_start'] ) && ! empty( $_POST['schedule_end'] ) ) ) { 
    657                         $expiry_obj->type  = $_POST['r8_tsm_script_expiry'] ?: 'Never';
    658                         $expiry_obj->schedule_start = $_POST['schedule_start'] ?: '';
    659                         $expiry_obj->schedule_end = $_POST['schedule_end'] ?: '';
     783                        update_post_meta( $post->ID, 'r8_tsm_script_location', sanitize_text_field( wp_unslash( $_POST['r8_tsm_script_location'] ) ) );
     784                    }
     785                    if ( ! empty( $_POST['r8_tsm_script_expiry'] ) || ( ! empty( $_POST['schedule_start'] ) && ! empty( $_POST['schedule_end'] ) ) ) {
     786                        $expiry_obj->type           = sanitize_text_field( wp_unslash( $_POST['r8_tsm_script_expiry'] ) ) ? : 'Never';
     787                        $expiry_obj->schedule_start = sanitize_text_field( wp_unslash( $_POST['schedule_start'] ) ) ?: '';
     788                        $expiry_obj->schedule_end   = sanitize_text_field( wp_unslash( $_POST['schedule_end'] ) ) ?: '';
    660789                        update_post_meta( $post->ID, 'r8_tsm_script_expiry_info', $expiry_obj );
    661790                        // status updated based on schedule
    662                         if($expiry_obj->type == 'Schedule'){
     791                        if ( $expiry_obj->type === 'Schedule' ) {
    663792                            $this->check_expiry_script( $expiry_obj->type, $expiry_obj->schedule_start, $expiry_obj->schedule_end, $post->ID );
    664793                        }
    665794                    }
    666795                    if ( ! empty( $_POST['r8_tsm_script_page'] ) && is_array( $_POST['r8_tsm_script_page'] ) ) {
    667                         update_post_meta( $post->ID, 'r8_tsm_script_page', $_POST['r8_tsm_script_page'] );
     796                        update_post_meta( $post->ID, 'r8_tsm_script_page', sanitize_text_field( wp_unslash( $_POST['r8_tsm_script_page'] ) ) );
    668797                    } else {
    669798                        update_post_meta( $post->ID, 'r8_tsm_script_page', array() );
     
    681810        public function tracking_scripts_admin_scripts() {
    682811            wp_enqueue_script( 'jquery' );
    683             wp_enqueue_script( 'tracking_script_js', plugin_dir_url( __FILE__ ) . '/js/built.min.js', [], md5_file( plugin_dir_url( __FILE__ ) . '/js/built.min.js' ), true );
     812            wp_enqueue_script( 'tracking_script_js', plugin_dir_url( __FILE__ ) . '/js/built.min.js', array(), md5_file( plugin_dir_url( __FILE__ ) . '/js/built.min.js' ), true );
    684813            wp_localize_script( 'tracking_script_js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
    685814        }
     
    687816        // Ajax Functions
    688817        public function tracking_scripts_posts_ajax_handler() {
    689             $post_type = ( $_POST['postType'] ) ? esc_attr( $_POST['postType'] ) : 'post';
    690             $args = array(
     818            $post_type = isset( $_POST['postType'] ) ? sanitize_text_field( wp_unslash( $_POST['postType'] ) ) : 'post';
     819            $args      = array(
    691820                'post_type'      => $post_type,
    692821                'posts_per_page' => - 1,
    693822                'orderby'        => 'name',
    694                 'order'          => 'ASC'
     823                'order'          => 'ASC',
    695824            );
    696825            ob_start();
    697826            $query = new WP_Query( $args );
    698             echo '<option value="none" id="none">Choose ' . ucwords( $post_type ) . '</option>';
    699             while ( $query->have_posts() ) : $query->the_post();
    700                 echo '<option value="' . get_the_ID() . '" id="' . get_the_ID() . '">' . ucwords( get_the_title() ) . '</option>';
     827            echo '<option value="none" id="none">Choose ' . esc_html( ucwords( $post_type ) ) . '</option>';
     828            while ( $query->have_posts() ) :
     829                $query->the_post();
     830                echo '<option value="' . esc_attr( get_the_ID() ) . '" id="' . esc_attr( get_the_ID() ) . '">' . esc_html( ucwords( get_the_title() ) ) . '</option>';
    701831            endwhile;
    702832            wp_reset_postdata();
    703             echo ob_get_clean();
     833            echo esc_html( ob_get_clean() );
    704834            die();
    705835        }
     
    723853    tracking_scripts();
    724854}
    725 // if ( ! class_exists( 'Tracking_Script' ) ) {
    726 
    727 //  class Tracking_Script {
    728 //      public $script_name;
    729 //      public $script_code;
    730 //      public $active;
    731 //      public $order;
    732 //      public $script_id;
    733 //      public $location;
    734 //      public $script_id;
    735 
    736 //      function __construct() {
    737 
    738 //      }
    739 //  }
    740 // }
Note: See TracChangeset for help on using the changeset viewer.