| 1 |
<?php |
| 2 |
/* Begin Analytics Embed */ |
| 3 |
add_action( 'wp_ajax_wp_insert_trackingcodes_google_analytics_form_get_content', 'wp_insert_trackingcodes_google_analytics_form_get_content' ); |
| 4 |
function wp_insert_trackingcodes_google_analytics_form_get_content() { |
| 5 |
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' ); |
| 6 |
|
| 7 |
$trackingCodes = get_option( 'wp_insert_trackingcodes' ); |
| 8 |
if ( ! is_array( $trackingCodes ) ) { |
| 9 |
$trackingCodes = []; |
| 10 |
} |
| 11 |
echo '<div class="wp_insert_popup_content_wrapper">'; |
| 12 |
$control = new smartlogixControls( |
| 13 |
[ |
| 14 |
'optionIdentifier' => 'wp_insert_trackingcodes[analytics]', |
| 15 |
'values' => ( $trackingCodes['analytics'] ?? [] ), |
| 16 |
] |
| 17 |
); |
| 18 |
$control->add_control( |
| 19 |
[ |
| 20 |
'type' => 'ipCheckbox', |
| 21 |
'optionName' => 'status', |
| 22 |
] |
| 23 |
); |
| 24 |
$control->add_control( |
| 25 |
[ |
| 26 |
'type' => 'textarea', |
| 27 |
'optionName' => 'code', |
| 28 |
'label' => 'Google Analytics Tracker ID', |
| 29 |
'helpText' => 'Your Google Analytics Tracker ID (XX-XXXXX-X)', |
| 30 |
] |
| 31 |
); |
| 32 |
wp_insert_echo_html( $control->HTML ); |
| 33 |
echo '<script type="text/javascript">'; |
| 34 |
wp_insert_echo_html( $control->JS ); |
| 35 |
echo '</script>'; |
| 36 |
echo '</div>'; |
| 37 |
wp_die(); |
| 38 |
} |
| 39 |
|
| 40 |
add_action( 'wp_ajax_wp_insert_trackingcodes_google_analytics_form_save_action', 'wp_insert_trackingcodes_google_analytics_form_save_action' ); |
| 41 |
function wp_insert_trackingcodes_google_analytics_form_save_action() { |
| 42 |
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' ); |
| 43 |
|
| 44 |
$trackingCodes = get_option( 'wp_insert_trackingcodes' ); |
| 45 |
if ( ! is_array( $trackingCodes ) ) { |
| 46 |
$trackingCodes = []; |
| 47 |
} |
| 48 |
$trackingCodes['analytics']['status'] = ( ( isset( $_POST['wp_insert_trackingcodes_analytics_status'] ) && ( $_POST['wp_insert_trackingcodes_analytics_status'] == 'true' ) ) ? '1' : '' ); |
| 49 |
$trackingCodes['analytics']['code'] = ( ( isset( $_POST['wp_insert_trackingcodes_analytics_code'] ) ) ? sanitize_text_field( wp_unslash( $_POST['wp_insert_trackingcodes_analytics_code'] ) ) : '' ); |
| 50 |
update_option( 'wp_insert_trackingcodes', $trackingCodes ); |
| 51 |
wp_die(); |
| 52 |
} |
| 53 |
|
| 54 |
add_action( 'wp_footer', 'wp_insert_trackingcodes_google_analytics_wp_footer' ); |
| 55 |
function wp_insert_trackingcodes_google_analytics_wp_footer() { |
| 56 |
$trackingCodes = get_option( 'wp_insert_trackingcodes' ); |
| 57 |
if ( ! is_array( $trackingCodes ) ) { |
| 58 |
$trackingCodes = []; |
| 59 |
} |
| 60 |
if ( isset( $trackingCodes['analytics']['status'] ) && wp_validate_boolean( $trackingCodes['analytics']['status'] ) && isset( $trackingCodes['analytics']['code'] ) && ! empty( $trackingCodes['analytics']['code'] ) ) { |
| 61 |
echo '<script type="text/javascript">'; |
| 62 |
echo 'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");'; |
| 63 |
echo 'document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));'; |
| 64 |
echo '</script>'; |
| 65 |
echo '<script type="text/javascript">'; |
| 66 |
echo 'var pageTracker = _gat._getTracker("' . esc_js( $trackingCodes['analytics']['code'] ) . '");'; |
| 67 |
echo 'pageTracker._trackPageview();'; |
| 68 |
echo '</script>'; |
| 69 |
} |
| 70 |
} |
| 71 |
/* End Analytics Embed */ |
| 72 |
|
| 73 |
/* Begin Header Code Embed */ |
| 74 |
add_action( 'wp_ajax_wp_insert_trackingcodes_header_form_get_content', 'wp_insert_trackingcodes_header_form_get_content' ); |
| 75 |
function wp_insert_trackingcodes_header_form_get_content() { |
| 76 |
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' ); |
| 77 |
|
| 78 |
$trackingCodes = get_option( 'wp_insert_trackingcodes' ); |
| 79 |
if ( ! is_array( $trackingCodes ) ) { |
| 80 |
$trackingCodes = []; |
| 81 |
} |
| 82 |
echo '<div class="wp_insert_popup_content_wrapper">'; |
| 83 |
$control = new smartlogixControls( |
| 84 |
[ |
| 85 |
'optionIdentifier' => 'wp_insert_trackingcodes[header]', |
| 86 |
'values' => ( $trackingCodes['header'] ?? [] ), |
| 87 |
] |
| 88 |
); |
| 89 |
$control->add_control( |
| 90 |
[ |
| 91 |
'type' => 'ipCheckbox', |
| 92 |
'optionName' => 'status', |
| 93 |
] |
| 94 |
); |
| 95 |
$control->add_control( |
| 96 |
[ |
| 97 |
'type' => 'textarea', |
| 98 |
'optionName' => 'code', |
| 99 |
'label' => 'Embed Code', |
| 100 |
] |
| 101 |
); |
| 102 |
wp_insert_echo_html( $control->HTML ); |
| 103 |
echo '<script type="text/javascript">'; |
| 104 |
wp_insert_echo_html( $control->JS ); |
| 105 |
echo '</script>'; |
| 106 |
echo '</div>'; |
| 107 |
wp_die(); |
| 108 |
} |
| 109 |
|
| 110 |
add_action( 'wp_ajax_wp_insert_trackingcodes_header_form_save_action', 'wp_insert_trackingcodes_header_form_save_action' ); |
| 111 |
function wp_insert_trackingcodes_header_form_save_action() { |
| 112 |
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' ); |
| 113 |
|
| 114 |
$trackingCodes = get_option( 'wp_insert_trackingcodes' ); |
| 115 |
if ( ! is_array( $trackingCodes ) ) { |
| 116 |
$trackingCodes = []; |
| 117 |
} |
| 118 |
$trackingCodes['header']['status'] = ( ( isset( $_POST['wp_insert_trackingcodes_header_status'] ) && ( $_POST['wp_insert_trackingcodes_header_status'] == 'true' ) ) ? '1' : '' ); |
| 119 |
// Embed code is stored raw (slashed) for unfiltered_html users; see wp_insert_sanitize_ad_field(). |
| 120 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash |
| 121 |
$trackingCodes['header']['code'] = wp_insert_sanitize_ad_field( 'primary_ad_code', ( ( isset( $_POST['wp_insert_trackingcodes_header_code'] ) ) ? $_POST['wp_insert_trackingcodes_header_code'] : '' ) ); |
| 122 |
update_option( 'wp_insert_trackingcodes', $trackingCodes ); |
| 123 |
|
| 124 |
if ( function_exists( 'wp_insert_adstxt_adsense_admin_notice_reset' ) ) { |
| 125 |
wp_insert_adstxt_adsense_admin_notice_reset(); |
| 126 |
} |
| 127 |
wp_die(); |
| 128 |
} |
| 129 |
|
| 130 |
add_action( 'wp_head', 'wp_insert_trackingcodes_header_wp_head' ); |
| 131 |
function wp_insert_trackingcodes_header_wp_head() { |
| 132 |
$trackingCodes = get_option( 'wp_insert_trackingcodes' ); |
| 133 |
if ( ! is_array( $trackingCodes ) ) { |
| 134 |
$trackingCodes = []; |
| 135 |
} |
| 136 |
if ( isset( $trackingCodes['header']['status'] ) && wp_validate_boolean( $trackingCodes['header']['status'] ) && isset( $trackingCodes['header']['code'] ) && ! empty( $trackingCodes['header']['code'] ) ) { |
| 137 |
wp_insert_echo_ad_code( stripslashes( $trackingCodes['header']['code'] ) ); |
| 138 |
} |
| 139 |
} |
| 140 |
/* End Header Code Embed */ |
| 141 |
|
| 142 |
/* Begin Footer Code Embed */ |
| 143 |
add_action( 'wp_ajax_wp_insert_trackingcodes_footer_form_get_content', 'wp_insert_trackingcodes_footer_form_get_content' ); |
| 144 |
function wp_insert_trackingcodes_footer_form_get_content() { |
| 145 |
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' ); |
| 146 |
|
| 147 |
$trackingCodes = get_option( 'wp_insert_trackingcodes' ); |
| 148 |
if ( ! is_array( $trackingCodes ) ) { |
| 149 |
$trackingCodes = []; |
| 150 |
} |
| 151 |
echo '<div class="wp_insert_popup_content_wrapper">'; |
| 152 |
$control = new smartlogixControls( |
| 153 |
[ |
| 154 |
'optionIdentifier' => 'wp_insert_trackingcodes[footer]', |
| 155 |
'values' => ( $trackingCodes['footer'] ?? [] ), |
| 156 |
] |
| 157 |
); |
| 158 |
$control->add_control( |
| 159 |
[ |
| 160 |
'type' => 'ipCheckbox', |
| 161 |
'optionName' => 'status', |
| 162 |
] |
| 163 |
); |
| 164 |
$control->add_control( |
| 165 |
[ |
| 166 |
'type' => 'textarea', |
| 167 |
'optionName' => 'code', |
| 168 |
'label' => 'Embed Code', |
| 169 |
] |
| 170 |
); |
| 171 |
wp_insert_echo_html( $control->HTML ); |
| 172 |
echo '<script type="text/javascript">'; |
| 173 |
wp_insert_echo_html( $control->JS ); |
| 174 |
echo '</script>'; |
| 175 |
echo '</div>'; |
| 176 |
wp_die(); |
| 177 |
} |
| 178 |
|
| 179 |
add_action( 'wp_ajax_wp_insert_trackingcodes_footer_form_save_action', 'wp_insert_trackingcodes_footer_form_save_action' ); |
| 180 |
function wp_insert_trackingcodes_footer_form_save_action() { |
| 181 |
check_ajax_referer( 'wp-insert', 'wp_insert_nonce' ); |
| 182 |
|
| 183 |
$trackingCodes = get_option( 'wp_insert_trackingcodes' ); |
| 184 |
if ( ! is_array( $trackingCodes ) ) { |
| 185 |
$trackingCodes = []; |
| 186 |
} |
| 187 |
$trackingCodes['footer']['status'] = ( ( isset( $_POST['wp_insert_trackingcodes_footer_status'] ) && ( $_POST['wp_insert_trackingcodes_footer_status'] == 'true' ) ) ? '1' : '' ); |
| 188 |
// Embed code is stored raw (slashed) for unfiltered_html users; see wp_insert_sanitize_ad_field(). |
| 189 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash |
| 190 |
$trackingCodes['footer']['code'] = wp_insert_sanitize_ad_field( 'primary_ad_code', ( ( isset( $_POST['wp_insert_trackingcodes_footer_code'] ) ) ? $_POST['wp_insert_trackingcodes_footer_code'] : '' ) ); |
| 191 |
update_option( 'wp_insert_trackingcodes', $trackingCodes ); |
| 192 |
|
| 193 |
if ( function_exists( 'wp_insert_adstxt_adsense_admin_notice_reset' ) ) { |
| 194 |
wp_insert_adstxt_adsense_admin_notice_reset(); |
| 195 |
} |
| 196 |
wp_die(); |
| 197 |
} |
| 198 |
|
| 199 |
add_action( 'wp_footer', 'wp_insert_trackingcodes_footer_wp_footer' ); |
| 200 |
function wp_insert_trackingcodes_footer_wp_footer() { |
| 201 |
$trackingCodes = get_option( 'wp_insert_trackingcodes' ); |
| 202 |
if ( ! is_array( $trackingCodes ) ) { |
| 203 |
$trackingCodes = []; |
| 204 |
} |
| 205 |
if ( isset( $trackingCodes['footer']['status'] ) && wp_validate_boolean( $trackingCodes['footer']['status'] ) && isset( $trackingCodes['footer']['code'] ) && ! empty( $trackingCodes['footer']['code'] ) ) { |
| 206 |
wp_insert_echo_ad_code( stripslashes( $trackingCodes['footer']['code'] ) ); |
| 207 |
} |
| 208 |
} |
| 209 |
/* End Footer Code Embed */ |
| 210 |
|