| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: Google Analytics Dashboard By Analytify |
| 4 |
* Plugin URI: http://wp-analytify.com/details |
| 5 |
* Description: Analytify brings a brand new and modern feeling Google Analytics superbly integrated with WordPress Dashboard. It presents the statistics in a beautiful way under the WordPress Posts/Pages at front end, backend and in its own Dashboard. This provides Stats from Country, Referrers, Social media, General stats, New visitors, Returning visitors, Exit pages, Browser wise and Top keywords. This plugin provides the RealTime statistics in a new UI which is easy to understand & looks good. |
| 6 |
* Version: 1.2.3 |
| 7 |
* Author: WPBrigade |
| 8 |
* Author URI: http://wpbrigade.com/ |
| 9 |
* License: GPLv3 |
| 10 |
* Text Domain: wp-analytify |
| 11 |
* Min WP Version: 3.0 |
| 12 |
* Max WP Version: 4.4 |
| 13 |
* Domain Path: /lang |
| 14 |
*/ |
| 15 |
|
| 16 |
// Exit if accessed directly |
| 17 |
if ( !defined( 'ABSPATH' ) ) exit; |
| 18 |
|
| 19 |
ini_set( 'include_path', dirname(__FILE__) . '/lib/' ); |
| 20 |
|
| 21 |
include_once( 'inc/class-wpa-ajax.php' ); |
| 22 |
include_once( 'inc/wpa-core-functions.php' ); |
| 23 |
include_once( 'inc/class-wpa-adminbar.php' ); |
| 24 |
|
| 25 |
if ( !class_exists( 'WP_Analytify' ) ) { |
| 26 |
|
| 27 |
if ( !class_exists( 'Analytify_General_FREE' ) ) { |
| 28 |
|
| 29 |
require_once WP_PLUGIN_DIR .'/wp-analytify/analytify-general.php'; |
| 30 |
} |
| 31 |
|
| 32 |
class WP_Analytify extends Analytify_General_FREE{ |
| 33 |
|
| 34 |
public $token = false; |
| 35 |
public $client = null; |
| 36 |
|
| 37 |
function __construct() { |
| 38 |
|
| 39 |
parent::__construct(); |
| 40 |
|
| 41 |
if ( !class_exists( 'Analytify_Google_Client' ) ) { |
| 42 |
|
| 43 |
require_once ANALYTIFY_LIB_PATH . 'Google/Client.php'; |
| 44 |
require_once ANALYTIFY_LIB_PATH . 'Google/Service/Analytics.php'; |
| 45 |
} |
| 46 |
|
| 47 |
add_action( 'plugin_action_links', array( |
| 48 |
$this, |
| 49 |
'pa_plugin_links' |
| 50 |
),10,2); |
| 51 |
|
| 52 |
add_action( 'plugin_row_meta', array( |
| 53 |
$this, |
| 54 |
'analytify_plugin_row_meta' |
| 55 |
),10,2); |
| 56 |
|
| 57 |
add_action( 'admin_enqueue_scripts', array( |
| 58 |
$this, |
| 59 |
'pa_scripts' |
| 60 |
)); |
| 61 |
add_action( 'admin_enqueue_scripts', array( |
| 62 |
$this, |
| 63 |
'pa_styles' |
| 64 |
)); |
| 65 |
|
| 66 |
add_action( 'wp_enqueue_scripts', array( |
| 67 |
$this, |
| 68 |
'pa_front_scripts' |
| 69 |
)); |
| 70 |
add_action( 'wp_enqueue_scripts', array( |
| 71 |
$this, |
| 72 |
'pa_front_styles' |
| 73 |
)); |
| 74 |
|
| 75 |
add_action( 'admin_menu', array( |
| 76 |
$this, |
| 77 |
'wpa_add_menu' |
| 78 |
)); |
| 79 |
|
| 80 |
add_action( 'admin_init', array( |
| 81 |
$this, |
| 82 |
'wpa_check_authentication' |
| 83 |
)); |
| 84 |
|
| 85 |
|
| 86 |
/*Insert Google Analytics Code*/ |
| 87 |
if( get_option( 'analytify_code') == 1 ) { |
| 88 |
|
| 89 |
add_action( 'wp_head', array( |
| 90 |
$this, |
| 91 |
'analytify_add_analytics_code' |
| 92 |
)); |
| 93 |
} |
| 94 |
|
| 95 |
add_action( 'wp_ajax_nopriv_get_ajax_single_admin_analytics', array( |
| 96 |
$this, |
| 97 |
'get_ajax_single_admin_analytics' |
| 98 |
)); |
| 99 |
|
| 100 |
add_action( 'wp_ajax_get_ajax_single_admin_analytics', array( |
| 101 |
$this, |
| 102 |
'get_ajax_single_admin_analytics' |
| 103 |
)); |
| 104 |
|
| 105 |
add_action( 'wp_ajax_get_ajax_secret_keys', array( |
| 106 |
$this, |
| 107 |
'get_ajax_secret_keys' |
| 108 |
)); |
| 109 |
|
| 110 |
if( get_option( 'analytify_disable_front') == 0 ) { |
| 111 |
|
| 112 |
add_filter( 'the_content', array( |
| 113 |
$this, |
| 114 |
'get_single_front_analytics' |
| 115 |
)); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* load Analytics under the EDIT POST Screen |
| 120 |
* add action runs only for admin section and load metabox. |
| 121 |
*/ |
| 122 |
|
| 123 |
if ( is_admin() ) { |
| 124 |
add_action( 'load-post.php', array( |
| 125 |
$this, |
| 126 |
'load_metaboxes' |
| 127 |
)); |
| 128 |
} |
| 129 |
|
| 130 |
// Show welcome message when user activate plugin. |
| 131 |
if ( get_option( 'show_tracking_pointer_1' ) != 1 ) { |
| 132 |
|
| 133 |
add_action( 'admin_print_footer_scripts', array( |
| 134 |
$this, |
| 135 |
'pa_welcome_message' |
| 136 |
) ); |
| 137 |
} |
| 138 |
|
| 139 |
/* |
| 140 |
* localization language file filter |
| 141 |
*/ |
| 142 |
|
| 143 |
add_action( 'init', array( |
| 144 |
$this, |
| 145 |
'analytify_textdomain') ); |
| 146 |
|
| 147 |
//add_action( 'admin_footer', array( &$this, 'profile_warning' ) ); |
| 148 |
/*add_action( 'admin_footer', array( |
| 149 |
&$this, |
| 150 |
'profile_warning' |
| 151 |
));*/ |
| 152 |
|
| 153 |
add_action('admin_notices', array( |
| 154 |
$this, |
| 155 |
'analytify_admin_notice') |
| 156 |
); |
| 157 |
|
| 158 |
add_action('admin_init', array( |
| 159 |
$this, |
| 160 |
'analytify_nag_ignore') |
| 161 |
); |
| 162 |
|
| 163 |
add_action( 'admin_init', array( |
| 164 |
$this, |
| 165 |
'analytify_review_notice' |
| 166 |
) ); |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
/** |
| 171 |
* Save Authentication code on return |
| 172 |
* @since 1.2.0 |
| 173 |
*/ |
| 174 |
public function wpa_check_authentication() { |
| 175 |
|
| 176 |
if( isset($_GET['code']) && isset($_GET['state']) ) { |
| 177 |
|
| 178 |
$key_google_token = sanitize_text_field( $_GET['code'] ); |
| 179 |
WP_Analytify::pt_save_data( $key_google_token ); |
| 180 |
wp_redirect( esc_url_raw( $_GET['state'] .'&tab=profile' ) ); |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
/* |
| 185 |
* Set plugin language/localizations files directory |
| 186 |
*/ |
| 187 |
public function analytify_textdomain() { |
| 188 |
|
| 189 |
$plugin_dir = basename( dirname(__FILE__) ); |
| 190 |
load_plugin_textdomain( 'wp-analytify', false , $plugin_dir . '/lang/'); |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
/* |
| 195 |
* Show analytics sections under the posts/pages in the metabox. |
| 196 |
*/ |
| 197 |
|
| 198 |
public function load_metaboxes() { |
| 199 |
|
| 200 |
add_action( 'add_meta_boxes', array( |
| 201 |
$this, |
| 202 |
'show_admin_single_analytics_add_metabox' |
| 203 |
)); |
| 204 |
} |
| 205 |
|
| 206 |
/* |
| 207 |
* Show metabox under each Post type to display Analytics of single post/page in wp-admin |
| 208 |
*/ |
| 209 |
public function show_admin_single_analytics_add_metabox() { |
| 210 |
|
| 211 |
global $post; |
| 212 |
|
| 213 |
if(! isset( $post ) ) |
| 214 |
return false; |
| 215 |
|
| 216 |
// Don't show statistics on posts which are not published. |
| 217 |
if( $post->post_status !== 'publish') return false; |
| 218 |
|
| 219 |
$post_types = get_option( 'analytify_posts_stats' ); |
| 220 |
|
| 221 |
// Don't load boxes/sections if no any post type is selected. |
| 222 |
if( !empty($post_types)) |
| 223 |
foreach ( $post_types as $post_type ) { |
| 224 |
|
| 225 |
add_meta_box('pa-single-admin-analytics', // $id |
| 226 |
'Analytify: Google Analytics of this page.', // $title |
| 227 |
array( |
| 228 |
'WP_Analytify', |
| 229 |
'show_admin_single_analytics' |
| 230 |
), // $callback |
| 231 |
|
| 232 |
$post_type, // $posts |
| 233 |
'normal', // $context |
| 234 |
'high' // $priority |
| 235 |
); |
| 236 |
} //$post_types as $post_type |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
public static function get_ajax_secret_keys(){ |
| 241 |
|
| 242 |
$response = wp_remote_get( "http://wp-analytify.com/secret/keys.json" ); |
| 243 |
if( is_wp_error( $response ) ) { |
| 244 |
$error_message = $response->get_error_message(); |
| 245 |
echo "Something went wrong: $error_message"; |
| 246 |
} else { |
| 247 |
print_r($response['body']); |
| 248 |
} |
| 249 |
die(); |
| 250 |
} |
| 251 |
|
| 252 |
/* |
| 253 |
* Show Analytics of single post/page in wp-admin under EDIT screen. |
| 254 |
*/ |
| 255 |
public static function show_admin_single_analytics() { |
| 256 |
|
| 257 |
global $post; |
| 258 |
|
| 259 |
// // Don't show statistics on posts which are not published. |
| 260 |
// if ( get_post_status ( $post->ID ) != 'publish' ) { |
| 261 |
// esc_html_e( 'Statistics will be loaded after you publish this content.', 'wp-analytify' ); |
| 262 |
// return false; |
| 263 |
// } |
| 264 |
|
| 265 |
|
| 266 |
$back_exclude_posts = explode( ',', get_option( 'post_analytics_exclude_posts_back' )); |
| 267 |
|
| 268 |
if ( is_array( $back_exclude_posts ) ) { |
| 269 |
|
| 270 |
if ( in_array( $post->ID, $back_exclude_posts ) ) { |
| 271 |
|
| 272 |
_e('This post is excluded and will not show Analytics.'); |
| 273 |
|
| 274 |
return; |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
$urlPost = ''; |
| 279 |
$start_date = ''; |
| 280 |
$end_date = ''; |
| 281 |
|
| 282 |
$wp_analytify = new WP_Analytify(); |
| 283 |
$urlPost = parse_url( get_permalink( $post->ID ) ); |
| 284 |
|
| 285 |
if( get_the_time('Y', $post->ID) < 2005 ) { |
| 286 |
|
| 287 |
$start_date = '2005-01-01'; |
| 288 |
} |
| 289 |
else { |
| 290 |
|
| 291 |
$start_date = get_the_time('Y-m-d', $post->ID); |
| 292 |
} |
| 293 |
|
| 294 |
$end_date = date('Y-m-d'); |
| 295 |
|
| 296 |
$is_access_level = get_option( 'post_analytics_access_back' ); |
| 297 |
|
| 298 |
if( $wp_analytify->pa_check_roles( $is_access_level ) ){ ?> |
| 299 |
|
| 300 |
<div class="pa-filter"> |
| 301 |
<table cellspacing="0" cellpadding="0" width="400"> |
| 302 |
<tbody> |
| 303 |
<tr> |
| 304 |
<td width="0"> |
| 305 |
<input type="text" id="start_date" name="start_date" value="<?php echo $start_date;?>"> |
| 306 |
</td> |
| 307 |
<td width="0"> |
| 308 |
<input type="text" id="end_date" name="end_date" value="<?php echo $end_date;?>"> |
| 309 |
</td> |
| 310 |
<input type="hidden" name="urlpost" id="urlpost" value="<?php echo $urlPost['path']; ?>"> |
| 311 |
<td width="0"> |
| 312 |
<input type="button" id="view_analytics" name="view_analytics" value="View Analytics" class="button-primary btn-green"> |
| 313 |
</td> |
| 314 |
</tr> |
| 315 |
</tbody> |
| 316 |
</table> |
| 317 |
</div> |
| 318 |
<div class="loading" style="display:none"> |
| 319 |
<img src="<?php echo plugins_url('images/loading.gif', __FILE__);?>"> |
| 320 |
</div> |
| 321 |
<div class="show-hide"> |
| 322 |
<?php $wp_analytify->get_single_admin_analytics( $start_date, $end_date, $post->ID, 0 ); ?> |
| 323 |
</div> |
| 324 |
<?php |
| 325 |
} |
| 326 |
else{ |
| 327 |
echo _e( 'You are not allowed to see stats', 'wp-analytify' ); |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
// Add Google Analytics JS code |
| 332 |
public function analytify_add_analytics_code() { |
| 333 |
|
| 334 |
global $current_user; |
| 335 |
|
| 336 |
$roles = $current_user->roles; |
| 337 |
|
| 338 |
if ( isset( $roles[0] ) and in_array( $roles[0], get_option( 'display_tracking_code' ) )) { |
| 339 |
|
| 340 |
} |
| 341 |
else{ |
| 342 |
|
| 343 |
echo '<!-- This code is added by Analytify v - ' . ANALYTIFY_VERSION . ' http://wp-analytify.com/ !--> '; |
| 344 |
|
| 345 |
if ( get_option( 'analytify_tracking_code' ) == 'universal' ) { ?> |
| 346 |
|
| 347 |
<script> |
| 348 |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
| 349 |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
| 350 |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
| 351 |
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); |
| 352 |
ga('create', '<?php echo get_option( "webPropertyId" );?>', 'auto'); |
| 353 |
ga('send', 'pageview'); |
| 354 |
</script> |
| 355 |
|
| 356 |
<?php |
| 357 |
} |
| 358 |
|
| 359 |
if ( get_option( 'analytify_tracking_code' ) == 'ga' ) { ?> |
| 360 |
|
| 361 |
<script type="text/javascript">//<![CDATA[ |
| 362 |
var _gaq = _gaq || []; |
| 363 |
_gaq.push(['_setAccount', '<?php echo get_option( "webPropertyId" );?>']); |
| 364 |
_gaq.push(['_trackPageview']); |
| 365 |
(function () { |
| 366 |
var ga = document.createElement('script'); |
| 367 |
ga.type = 'text/javascript'; |
| 368 |
ga.async = true; |
| 369 |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; |
| 370 |
var s = document.getElementsByTagName('script')[0]; |
| 371 |
s.parentNode.insertBefore(ga, s); |
| 372 |
})(); |
| 373 |
//]]> |
| 374 |
</script> |
| 375 |
|
| 376 |
<?php |
| 377 |
} |
| 378 |
|
| 379 |
echo '<!-- This code is added by Analytify v - ' . ANALYTIFY_VERSION . ' !-->'; |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* Add a link to the settings page to the plugins list |
| 385 |
*/ |
| 386 |
public function pa_plugin_links( $links, $file ) { |
| 387 |
|
| 388 |
static $this_plugin; |
| 389 |
|
| 390 |
if ( empty( $this_plugin ) ){ |
| 391 |
|
| 392 |
$this_plugin = 'wp-analytify/wp-analytify.php'; |
| 393 |
} |
| 394 |
|
| 395 |
if ( $file == $this_plugin ) { |
| 396 |
|
| 397 |
$settings_link = '<a href="' . admin_url("admin.php?page=analytify-settings") . '">' . __( 'Settings', 'wp-analytify' ) . '</a> | <a href="' . admin_url("admin.php?page=analytify-dashboard") . '">' . __( 'Dashboard', 'wp-analytify' ) . '</a>'; |
| 398 |
array_unshift( $links, $settings_link ); |
| 399 |
} |
| 400 |
|
| 401 |
return $links; |
| 402 |
} |
| 403 |
|
| 404 |
/** |
| 405 |
* Plugin row meta links |
| 406 |
* |
| 407 |
* @since 1.1 |
| 408 |
* @param array $input already defined meta links |
| 409 |
* @param string $file plugin file path and name being processed |
| 410 |
* @return array $input |
| 411 |
*/ |
| 412 |
function analytify_plugin_row_meta( $input, $file ) { |
| 413 |
if ( $file != 'wp-analytify/wp-analytify.php' ) |
| 414 |
return $input; |
| 415 |
|
| 416 |
$links = array( |
| 417 |
'<a href="http://wp-analytify.com/">' . esc_html__( 'Buy Pro Version', 'edd' ) . '</a>', |
| 418 |
'<a href="http://wp-analytify.com/add-ons/">' . esc_html__( 'Add Ons', 'edd' ) . '</a>', |
| 419 |
); |
| 420 |
|
| 421 |
$input = array_merge( $input, $links ); |
| 422 |
|
| 423 |
return $input; |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
/** |
| 428 |
* Display warning if profiles are not selected. |
| 429 |
*/ |
| 430 |
public function pa_check_warnings(){ |
| 431 |
|
| 432 |
add_action( 'admin_footer', array( |
| 433 |
&$this, |
| 434 |
'profile_warning' |
| 435 |
)); |
| 436 |
} |
| 437 |
|
| 438 |
/** |
| 439 |
* Get current screen details |
| 440 |
*/ |
| 441 |
public static function pa_page_file_path() { |
| 442 |
|
| 443 |
$screen = get_current_screen(); |
| 444 |
|
| 445 |
if ( strpos( $screen->base, 'analytify-settings' ) !== false ) { |
| 446 |
include( ANALYTIFY_ROOT_PATH . '/inc/analytify-settings.php' ); |
| 447 |
} |
| 448 |
else if ( strpos( $screen->base, 'analytify-campaigns' ) !== false ) { |
| 449 |
include_once( ANALYTIFY_ROOT_PATH . '/inc/analytify-campaigns.php' ); |
| 450 |
} |
| 451 |
else if ( strpos( $screen->base, 'analytify-addons' ) !== false ) { |
| 452 |
include_once( ANALYTIFY_ROOT_PATH . '/inc/page-addons.php' ); |
| 453 |
} |
| 454 |
else { |
| 455 |
include( ANALYTIFY_ROOT_PATH . '/inc/analytify-dashboard.php' ); |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
/** |
| 460 |
* Styling: loading stylesheets for the plugin. |
| 461 |
*/ |
| 462 |
public function pa_styles( $page ) { |
| 463 |
|
| 464 |
wp_enqueue_style( 'wp-analytify-style', plugins_url('css/wp-analytify-style.css', __FILE__)); |
| 465 |
|
| 466 |
// wp_enqueue_style( 'ui-css', plugins_url('jquery-ui-theme/jquery-ui.css', __FILE__)); |
| 467 |
wp_enqueue_style( 'chosen', plugins_url('css/chosen.css', __FILE__)); |
| 468 |
// wp_enqueue_style( 'jquery-ui-tooltip-css', plugins_url('css/jquery.ui.tooltip.html.css', __FILE__) ); |
| 469 |
|
| 470 |
if ( get_option( 'show_tracking_pointer_1' ) != 1 ) wp_enqueue_style( 'wp-pointer' ); |
| 471 |
} |
| 472 |
|
| 473 |
public function pa_front_styles( $page ) { |
| 474 |
|
| 475 |
if( get_option( 'analytify_disable_front') == 0 ) { |
| 476 |
|
| 477 |
wp_enqueue_style( 'front-end-style', plugins_url('css/frontend_styles.css', __FILE__),false,ANALYTIFY_VERSION); |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
/** |
| 482 |
* Loading scripts js for the plugin. |
| 483 |
*/ |
| 484 |
public function pa_scripts( $page ) { |
| 485 |
|
| 486 |
wp_enqueue_script ( 'jquery' ); |
| 487 |
wp_enqueue_script ( 'charts_api_js', 'https://www.google.com/jsapi', false, ANALYTIFY_VERSION ); |
| 488 |
wp_enqueue_script ( 'chosen-js', plugins_url('js/chosen.jquery.js', __FILE__), false, ANALYTIFY_VERSION ); |
| 489 |
wp_enqueue_script ( 'script-js', plugins_url('js/wp-analytify.js', __FILE__), false, ANALYTIFY_VERSION ); |
| 490 |
wp_enqueue_script ( 'jquery-ui-tooltip' ); |
| 491 |
wp_enqueue_script ( 'jquery-ui-datepicker'); |
| 492 |
|
| 493 |
if ( get_option( 'show_tracking_pointer_1' ) != 1 ) wp_enqueue_script( 'wp-pointer' ); |
| 494 |
|
| 495 |
} |
| 496 |
|
| 497 |
/** |
| 498 |
* Loading scripts js for the plugin. |
| 499 |
*/ |
| 500 |
public function pa_front_scripts( $page ) { |
| 501 |
|
| 502 |
if( get_option( 'analytify_disable_front') == 0 ){ |
| 503 |
|
| 504 |
wp_enqueue_script ('jquery'); |
| 505 |
wp_enqueue_script ('analytify-classie', plugins_url('js/classie.js', __FILE__), false, ANALYTIFY_VERSION); |
| 506 |
wp_enqueue_script ('analytify-selectfx', plugins_url('js/selectFx.js', __FILE__), false, ANALYTIFY_VERSION); |
| 507 |
wp_enqueue_script ('analytify-script', plugins_url('js/script.js', __FILE__), false, ANALYTIFY_VERSION); |
| 508 |
|
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
/** |
| 513 |
* Create Analytics menu at the left side of dashboard |
| 514 |
*/ |
| 515 |
public static function wpa_add_menu() { |
| 516 |
|
| 517 |
add_menu_page( ANALYTIFY_NICK, 'Analytify', 'manage_options', 'analytify-dashboard', array( |
| 518 |
__CLASS__, |
| 519 |
'pa_page_file_path' |
| 520 |
), plugins_url('images/wp-analytics-logo.png', __FILE__),'2.1.9'); |
| 521 |
|
| 522 |
add_submenu_page( 'analytify-dashboard', ANALYTIFY_NICK . ' Dashboard', ' Dashboard', 'manage_options', 'analytify-dashboard', array( |
| 523 |
__CLASS__, |
| 524 |
'pa_page_file_path' |
| 525 |
)); |
| 526 |
|
| 527 |
add_submenu_page( 'analytify-dashboard', ANALYTIFY_NICK . ' Campaign', ' Campaigns', 'manage_options', 'analytify-campaigns', array( |
| 528 |
__CLASS__, |
| 529 |
'pa_page_file_path' |
| 530 |
)); |
| 531 |
|
| 532 |
add_submenu_page( 'analytify-dashboard', ANALYTIFY_NICK . ' Settings', '<b style="color:#f9845b">Settings</b>', 'manage_options', 'analytify-settings', array( |
| 533 |
__CLASS__, |
| 534 |
'pa_page_file_path' |
| 535 |
)); |
| 536 |
|
| 537 |
add_submenu_page( 'analytify-dashboard', ANALYTIFY_NICK . ' Addons', '<b>Add-ons</b>', 'manage_options', 'analytify-addons', array( |
| 538 |
__CLASS__, |
| 539 |
'pa_page_file_path' |
| 540 |
)); |
| 541 |
} |
| 542 |
|
| 543 |
/** |
| 544 |
* Creating tabs for settings |
| 545 |
* @since 1.0 |
| 546 |
*/ |
| 547 |
|
| 548 |
public function pa_settings_tabs( $current = 'authentication' ) { |
| 549 |
|
| 550 |
$tabs = array( |
| 551 |
'authentication' => 'Authentication', |
| 552 |
'profile' => 'Profile', |
| 553 |
'admin' => 'Admin', |
| 554 |
'advanced' => 'Advanced' |
| 555 |
); |
| 556 |
|
| 557 |
echo '<div class="left-area">'; |
| 558 |
echo '<div id="icon-themes" class="icon32"><br></div>'; |
| 559 |
echo '<h2 class="nav-tab-wrapper">'; |
| 560 |
|
| 561 |
foreach( $tabs as $tab => $name ) { |
| 562 |
|
| 563 |
$class = ( $tab == $current ) ? ' nav-tab-active' : ''; |
| 564 |
echo "<a class='nav-tab$class' href='?page=analytify-settings&tab=$tab'>$name</a>"; |
| 565 |
} |
| 566 |
|
| 567 |
echo '</h2>'; |
| 568 |
} |
| 569 |
|
| 570 |
/** |
| 571 |
* Get profiles from user Google Analytics account profiles. |
| 572 |
*/ |
| 573 |
public function pt_get_analytics_accounts() { |
| 574 |
|
| 575 |
try { |
| 576 |
|
| 577 |
if( get_option( 'pa_google_token' ) !='' ) { |
| 578 |
$profiles = $this->service->management_profiles->listManagementProfiles( "~all", "~all" ); |
| 579 |
return $profiles; |
| 580 |
} |
| 581 |
|
| 582 |
else{ |
| 583 |
echo '<br /><p class="description">' . __( 'You must authenticate to access your web profiles.', 'wp-analytify' ) . '</p>'; |
| 584 |
} |
| 585 |
|
| 586 |
} |
| 587 |
|
| 588 |
catch (Exception $e) { |
| 589 |
die('An error occured: ' . $e->getMessage() . '\n'); |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
public function pa_setting_url() { |
| 594 |
|
| 595 |
return admin_url('admin.php?page=analytify-settings'); |
| 596 |
|
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
public function pt_save_data( $key_google_token ) { |
| 601 |
|
| 602 |
update_option( 'post_analytics_token', $key_google_token ); |
| 603 |
$this->pa_connect(); |
| 604 |
|
| 605 |
return true; |
| 606 |
} |
| 607 |
|
| 608 |
/** |
| 609 |
* Warning messages. |
| 610 |
*/ |
| 611 |
public function profile_warning() { |
| 612 |
|
| 613 |
$profile_id = get_option( "pt_webprofile" ); |
| 614 |
$acces_token = get_option( "post_analytics_token" ); |
| 615 |
|
| 616 |
if (! isset( $acces_token ) || empty( $acces_token )) { |
| 617 |
|
| 618 |
echo "<div id='message' class='error'><p><strong>" . __( "Analytify is not active. Please <a href='" . menu_page_url ( 'analytify-settings', false ) ."'>Authenticate</a> in order to get started using this plugin.", 'wp-analytify' )."</p></div>"; |
| 619 |
} |
| 620 |
else{ |
| 621 |
|
| 622 |
if (! isset( $profile_id ) || empty( $profile_id )){ |
| 623 |
echo '<div class="error"><p><strong>' . __( 'Google Analytics Profile is not set. Set the <a href="' . menu_page_url ( 'analytify-settings', false ) . '&tab=profile">Profile</a> ', 'wp-analytify' ) . '</p></div>'; |
| 624 |
} |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
public function get_single_front_analytics( $content ) { |
| 630 |
|
| 631 |
global $post, $wp_analytify; |
| 632 |
|
| 633 |
$front_access = get_option( 'post_analytics_access' ); |
| 634 |
|
| 635 |
if ( is_single() || is_page() ) { |
| 636 |
|
| 637 |
$post_type = get_post_type( $post->ID ); |
| 638 |
|
| 639 |
if( strlen( get_option( 'analytify_posts_stats_front' ) < 3) ) { |
| 640 |
return $content; |
| 641 |
} |
| 642 |
|
| 643 |
if( is_array( get_option( 'analytify_posts_stats_front' )) and !in_array( $post_type, get_option( 'analytify_posts_stats_front' ) ) ) { |
| 644 |
|
| 645 |
return $content; |
| 646 |
} |
| 647 |
|
| 648 |
if ( is_array( get_option( 'post_analytics_exclude_posts_front' ) ) ) { |
| 649 |
|
| 650 |
if ( in_array( get_the_ID(), get_option( 'post_analytics_exclude_posts_front' ) ) ) { |
| 651 |
|
| 652 |
return $content; |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
// Showing stats to guests |
| 657 |
if ( $front_access[0] == 'every-one' || $this->pa_check_roles( $front_access )) { |
| 658 |
|
| 659 |
$post_analytics_settings_front = array(); |
| 660 |
$post_analytics_settings_front = get_option( 'post_analytics_settings_front' ); |
| 661 |
|
| 662 |
$urlPost = parse_url( get_permalink( $post->ID ) ); |
| 663 |
|
| 664 |
if ( $urlPost['host'] == 'localhost' ) |
| 665 |
$filter = 'ga:pagePath==/'; //.$u_post['path']; |
| 666 |
else |
| 667 |
$filter = 'ga:pagePath==' .$urlPost['path']. ''; |
| 668 |
|
| 669 |
if( get_the_time('Y', $post->ID) < 2005 ) { |
| 670 |
|
| 671 |
$start_date = '2005-01-01'; |
| 672 |
} |
| 673 |
else { |
| 674 |
|
| 675 |
$start_date = get_the_time('Y-m-d', $post->ID); |
| 676 |
} |
| 677 |
|
| 678 |
$end_date = date('Y-m-d'); |
| 679 |
|
| 680 |
ob_start(); |
| 681 |
|
| 682 |
include ANALYTIFY_ROOT_PATH . '/inc/front-menus.php'; |
| 683 |
|
| 684 |
if(! empty( $post_analytics_settings_front )){ |
| 685 |
|
| 686 |
if (is_array( $post_analytics_settings_front )){ |
| 687 |
|
| 688 |
$stats = $this->pa_get_analytics( 'ga:sessions,ga:bounces,ga:newUsers,ga:entrances,ga:pageviews,ga:sessionDuration,ga:avgTimeOnPage,ga:users',$start_date, $end_date, false, false, $filter); |
| 689 |
|
| 690 |
if ( isset( $stats->totalsForAllResults ) ) { |
| 691 |
|
| 692 |
include ANALYTIFY_ROOT_PATH . '/views/front/general-stats.php'; |
| 693 |
pa_include_general( $this, $stats); |
| 694 |
} |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
$content .= ob_get_contents(); |
| 699 |
ob_get_clean(); |
| 700 |
} |
| 701 |
|
| 702 |
} |
| 703 |
|
| 704 |
return $content; |
| 705 |
|
| 706 |
} |
| 707 |
|
| 708 |
/* |
| 709 |
* get the Analytics data from ajax() call |
| 710 |
* |
| 711 |
*/ |
| 712 |
|
| 713 |
public function get_ajax_single_admin_analytics() { |
| 714 |
|
| 715 |
$startDate = ''; |
| 716 |
$endDate = ''; |
| 717 |
$postID = 0 ; |
| 718 |
$startDate = $_POST['start_date']; |
| 719 |
$endDate = $_POST['end_date']; |
| 720 |
$postID = $_POST['post_id']; |
| 721 |
$this->get_single_admin_analytics( $startDate, $endDate, $postID, 1 ); |
| 722 |
|
| 723 |
die(); |
| 724 |
} |
| 725 |
|
| 726 |
/* |
| 727 |
* get the Analytics data for wp-admin posts/pages. |
| 728 |
* |
| 729 |
*/ |
| 730 |
public function get_single_admin_analytics( $start_date = '', $end_date = '', $postID = 0, $ajax = 0 ) { |
| 731 |
|
| 732 |
global $post; |
| 733 |
|
| 734 |
if( wpa_check_profile_selection( 'Analytify', '<br /><b class="wpa_notice_error">Select your website profile at Analytify->settings->profile tab to load stats.</b>') ) return; |
| 735 |
|
| 736 |
|
| 737 |
if ( $postID == 0 ) { |
| 738 |
$u_post = '/'; //$urlPost['path']; |
| 739 |
} |
| 740 |
else{ |
| 741 |
$u_post = parse_url( get_permalink( $postID ) ); |
| 742 |
} |
| 743 |
|
| 744 |
if ( $u_post['host'] == 'localhost' ) |
| 745 |
$filter = false; |
| 746 |
else |
| 747 |
$filter = 'ga:pagePath==' .$u_post['path']. ''; |
| 748 |
|
| 749 |
|
| 750 |
if ( $start_date == '' ) { |
| 751 |
|
| 752 |
$s_date = get_the_time('Y-m-d', $post->ID); |
| 753 |
if(get_the_time('Y', $post->ID) < 2005){ |
| 754 |
$s_date = '2005-01-01'; |
| 755 |
} |
| 756 |
} |
| 757 |
else{ |
| 758 |
$s_date = $start_date; |
| 759 |
} |
| 760 |
|
| 761 |
if ( $end_date == '' ) { |
| 762 |
$e_date = date('Y-m-d'); |
| 763 |
} |
| 764 |
else{ |
| 765 |
$e_date = $end_date; |
| 766 |
} |
| 767 |
|
| 768 |
$show_settings = array(); |
| 769 |
$show_settings = get_option('post_analytics_settings_back'); |
| 770 |
|
| 771 |
// Stop here, if user has disable backend analytics i.e OFF |
| 772 |
if ( get_option( 'post_analytics_disable_back' ) == 1 and $ajax == 0) { |
| 773 |
return; |
| 774 |
} |
| 775 |
|
| 776 |
echo '<p> Displaying Analytics of this page from ' . date("jS F, Y", strtotime($s_date)) . ' to '. date("jS F, Y", strtotime($e_date)) . '</p>'; |
| 777 |
|
| 778 |
if( !empty( $show_settings )){ |
| 779 |
|
| 780 |
if (is_array( $show_settings )){ |
| 781 |
|
| 782 |
if (in_array( 'show-overall-back', $show_settings )) { |
| 783 |
|
| 784 |
$stats = $this->pa_get_analytics( 'ga:sessions,ga:bounces,ga:newUsers,ga:entrances,ga:pageviews,ga:sessionDuration,ga:avgTimeOnPage,ga:users',$s_date, $e_date, false, false, $filter); |
| 785 |
|
| 786 |
if ( isset( $stats->totalsForAllResults ) ) { |
| 787 |
|
| 788 |
include ANALYTIFY_ROOT_PATH . '/views/admin/single-general-stats.php'; |
| 789 |
wpa_single_include_general( $this, $stats); |
| 790 |
} |
| 791 |
} |
| 792 |
} |
| 793 |
} |
| 794 |
} |
| 795 |
|
| 796 |
|
| 797 |
/* |
| 798 |
* Pretty numbers |
| 799 |
*/ |
| 800 |
function wpa_pretty_numbers( $num ) { |
| 801 |
|
| 802 |
return round(($num/1000),2).'k'; |
| 803 |
} |
| 804 |
|
| 805 |
/* |
| 806 |
* format numbers |
| 807 |
*/ |
| 808 |
function wpa_number_format( $num ) { |
| 809 |
|
| 810 |
return number_format($num); |
| 811 |
} |
| 812 |
|
| 813 |
/* |
| 814 |
* Pretty time to display |
| 815 |
*/ |
| 816 |
function pa_pretty_time( $time ) { |
| 817 |
|
| 818 |
// Check if numeric |
| 819 |
if ( is_numeric($time) ) { |
| 820 |
|
| 821 |
$value = array( |
| 822 |
"years" => '00', |
| 823 |
"days" => '00', |
| 824 |
"hours" => '', |
| 825 |
"minutes" => '', |
| 826 |
"seconds" => '' |
| 827 |
); |
| 828 |
|
| 829 |
if ($time >= 31556926) { |
| 830 |
$value["years"] = floor($time / 31556926); |
| 831 |
$time = ($time % 31556926); |
| 832 |
} //$time >= 31556926 |
| 833 |
|
| 834 |
if ($time >= 86400) |
| 835 |
{ |
| 836 |
$value["days"] = floor($time / 86400); |
| 837 |
$time = ($time % 86400); |
| 838 |
} //$time >= 86400 |
| 839 |
if ($time >= 3600) |
| 840 |
{ |
| 841 |
$value["hours"] = str_pad(floor($time / 3600), 1, 0, STR_PAD_LEFT); |
| 842 |
$time = ($time % 3600); |
| 843 |
} //$time >= 3600 |
| 844 |
if ($time >= 60) |
| 845 |
{ |
| 846 |
$value["minutes"] = str_pad(floor($time / 60), 1, 0, STR_PAD_LEFT); |
| 847 |
$time = ($time % 60); |
| 848 |
} //$time >= 60 |
| 849 |
$value["seconds"] = str_pad(floor($time), 1, 0, STR_PAD_LEFT); |
| 850 |
# Get the hour:minute:second version |
| 851 |
if($value['hours']!=''){ |
| 852 |
$attach_hours='<sub>h</sub> '; |
| 853 |
} |
| 854 |
if($value['minutes']!=''){ |
| 855 |
$attach_min='<sub>min</sub> '; |
| 856 |
} |
| 857 |
if($value['seconds']!=''){ |
| 858 |
$attach_sec='<sub>sec</sub>'; |
| 859 |
} |
| 860 |
return $value['hours'] .@$attach_hours. $value['minutes'] .@$attach_min. $value['seconds'].$attach_sec; |
| 861 |
//return $value['hours'] . ':' . $value['minutes'] . ':' . $value['seconds']; |
| 862 |
} //is_numeric($time) |
| 863 |
else |
| 864 |
{ |
| 865 |
return false; |
| 866 |
} |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
public function pa_check_roles( $access_level ) { |
| 871 |
|
| 872 |
if ( is_user_logged_in () && isset ( $access_level ) ) { |
| 873 |
|
| 874 |
global $current_user; |
| 875 |
$roles = $current_user->roles; |
| 876 |
|
| 877 |
/*if ( ( current_user_can ( 'manage_options' ) ) ) { |
| 878 |
|
| 879 |
return true; |
| 880 |
}*/ |
| 881 |
|
| 882 |
if ( in_array ( $roles[0], $access_level ) ) { |
| 883 |
|
| 884 |
return true; |
| 885 |
} |
| 886 |
else { |
| 887 |
|
| 888 |
return false; |
| 889 |
} |
| 890 |
} |
| 891 |
} |
| 892 |
|
| 893 |
/** |
| 894 |
* Show pointers for announcements |
| 895 |
*/ |
| 896 |
|
| 897 |
public function pa_welcome_message() { |
| 898 |
|
| 899 |
$pointer_content = '<h3>Announcement:</h3>'; |
| 900 |
$pointer_content .= '<p><input type="checkbox" name="wpa_allow_tracking" value="1" id="wpa_allow_tracking"> '; |
| 901 |
$pointer_content .= 'Help us making Analytify even better by sharing very basic plugin usage data.'; |
| 902 |
$pointer_content .= ' Opt-in and receive a $5 Off coupon for <a href="https://wp-analytify.com/upgrade-from-free">Analytify PRO</a>.</p>'; |
| 903 |
?> |
| 904 |
|
| 905 |
<script type="text/javascript"> |
| 906 |
//<![CDATA[ |
| 907 |
jQuery(document).ready( function($) { |
| 908 |
|
| 909 |
if(typeof(jQuery().pointer) != 'undefined') { |
| 910 |
|
| 911 |
$('#toplevel_page_analytify-dashboard').pointer({ |
| 912 |
|
| 913 |
content: '<?php echo $pointer_content; ?>', |
| 914 |
position: { |
| 915 |
edge: 'left', |
| 916 |
align: 'center' |
| 917 |
}, |
| 918 |
close: function() { |
| 919 |
$.post( ajaxurl, { |
| 920 |
pointer: 'tracking', |
| 921 |
wpa_allow: $('#wpa_allow_tracking:checked').val(), |
| 922 |
action: 'analytify_dismiss_pointer' |
| 923 |
}); |
| 924 |
|
| 925 |
if($('#wpa_allow_tracking:checked').val() == 1) alert('Thankyou!\nYour Coupon code is Analytify2015'); |
| 926 |
} |
| 927 |
}).pointer('open'); |
| 928 |
}; |
| 929 |
}); |
| 930 |
//]]> |
| 931 |
</script> |
| 932 |
|
| 933 |
<?php |
| 934 |
} |
| 935 |
|
| 936 |
/* Display a notice that can be dismissed */ |
| 937 |
|
| 938 |
function analytify_admin_notice() { |
| 939 |
|
| 940 |
$profile_id = get_option( "pt_webprofile" ); |
| 941 |
$acces_token = get_option( "post_analytics_token" ); |
| 942 |
|
| 943 |
if ( current_user_can( 'install_plugins' )) { |
| 944 |
|
| 945 |
global $current_user ; |
| 946 |
$user_id = $current_user->ID; |
| 947 |
/* Check that the user hasn't already clicked to ignore the message */ |
| 948 |
if ( ! get_user_meta($user_id, 'analytify_ignore_notice110') ) { |
| 949 |
|
| 950 |
echo '<div class="updated"><p>'; |
| 951 |
printf(__('<b>Note:</b> Enhanced eCommerce Tracking for <b><a href="https://wp-analytify.com/go/WooCommerce" target="_blank">WooCommerce</a></b> is finally available with Analytify! Increase sales and track - Product Clicks, Adds to cart, Checkouts and <a href="https://wp-analytify.com/go/WooCommerce-Announcement-blog" target="_blank">many more</a>. <a href="%1$s">[Hide Notice]</a>'), admin_url( 'admin.php?page=analytify-dashboard&analytify_nag_ignore=0' )); |
| 952 |
echo "</p></div>"; |
| 953 |
|
| 954 |
} |
| 955 |
} |
| 956 |
|
| 957 |
/* Show notices */ |
| 958 |
if (! isset( $acces_token ) || empty( $acces_token ) || ! get_option( 'pa_google_token' ) ) { |
| 959 |
|
| 960 |
echo "<div class='error notice is-dismissible'><p><b>Notice:</b> " . __( "<b><a style=\"text-decoration:none\" href='" . menu_page_url ( 'analytify-settings', false ) ."'>Connect</a></b> Analytify with your Google account.", 'wp-analytify' )."</p></div>"; |
| 961 |
} |
| 962 |
else{ |
| 963 |
|
| 964 |
if ((! isset( $profile_id ) || empty( $profile_id )) && ! isset($_POST[ 'save_profile' ]) ) { |
| 965 |
|
| 966 |
echo '<div class="error notice is-dismissible"><p>' . __( 'Congratulations! Analytify is now authenticated. Select your website profile <a href="' . menu_page_url ( 'analytify-settings', false ) . '&tab=profile">here</a> ', 'wp-analytify' ) . '</p></div>'; |
| 967 |
} |
| 968 |
} |
| 969 |
} |
| 970 |
|
| 971 |
function analytify_nag_ignore() { |
| 972 |
global $current_user; |
| 973 |
|
| 974 |
$user_id = $current_user->ID; |
| 975 |
/* If user clicks to ignore the notice, add that to their user meta */ |
| 976 |
if ( isset($_GET['analytify_nag_ignore']) && '0' == $_GET['analytify_nag_ignore'] ) { |
| 977 |
add_user_meta($user_id, 'analytify_ignore_notice110', 'true', true); |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
/** |
| 982 |
* Check and Dismiss review message. |
| 983 |
* |
| 984 |
* @since 1.2.2 |
| 985 |
*/ |
| 986 |
private function review_dismissal() { |
| 987 |
|
| 988 |
//delete_site_option( 'wp_analytify_review_dismiss' ); |
| 989 |
|
| 990 |
if (!is_admin() || |
| 991 |
!current_user_can('manage_options') || |
| 992 |
!isset($_GET['_wpnonce']) || |
| 993 |
!wp_verify_nonce($_GET['_wpnonce'], 'analytify-review-nonce') || |
| 994 |
!isset($_GET['wp_analytify_review_dismiss'])) { |
| 995 |
|
| 996 |
return; |
| 997 |
} |
| 998 |
|
| 999 |
add_site_option( 'wp_analytify_review_dismiss', 'yes' ); |
| 1000 |
} |
| 1001 |
|
| 1002 |
/** |
| 1003 |
* Ask users to review our plugin on .org |
| 1004 |
* |
| 1005 |
* @since 1.2.2 |
| 1006 |
* @return boolean false |
| 1007 |
*/ |
| 1008 |
public function analytify_review_notice() { |
| 1009 |
|
| 1010 |
$this->review_dismissal(); |
| 1011 |
|
| 1012 |
$activation_time = get_site_option( 'wp_analytify_active_time' ); |
| 1013 |
$review_dismissal = get_site_option( 'wp_analytify_review_dismiss' ); |
| 1014 |
|
| 1015 |
if ($review_dismissal == 'yes') { |
| 1016 |
return; |
| 1017 |
} |
| 1018 |
|
| 1019 |
|
| 1020 |
if ( !$activation_time ) { |
| 1021 |
|
| 1022 |
$activation_time = time(); |
| 1023 |
add_site_option( 'wp_analytify_active_time', $activation_time ); |
| 1024 |
} |
| 1025 |
|
| 1026 |
// 1296000 = 15 Days in seconds |
| 1027 |
if ( time() - $activation_time > 1296000 ) { |
| 1028 |
add_action( 'admin_notices' , array( $this , 'analytify_review_notice_message' ) ); |
| 1029 |
} |
| 1030 |
|
| 1031 |
} |
| 1032 |
|
| 1033 |
/** |
| 1034 |
* Review notice message |
| 1035 |
* |
| 1036 |
* @since 1.2.2 |
| 1037 |
* @return NULL |
| 1038 |
*/ |
| 1039 |
public function analytify_review_notice_message() { |
| 1040 |
|
| 1041 |
$scheme = (parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY)) ? '&' : '?'; |
| 1042 |
$url = $_SERVER['REQUEST_URI'] . $scheme . 'wp_analytify_review_dismiss=yes'; |
| 1043 |
$dismiss_url = wp_nonce_url( $url, 'analytify-review-nonce'); |
| 1044 |
|
| 1045 |
echo '<div class="updated"> |
| 1046 |
<p>' . __('You have been using the ', 'wp-analytify') . '<a href="' . admin_url( 'admin.php?page=analytify-dashboard' ) . '">WP Analytify</a>' . __( ' for some time now, do you like it? If so, please consider leaving us a review on WordPress.org! It would help us out a lot and we would really appreciate it.', 'wp-analytify' ) . ' |
| 1047 |
<br><br> |
| 1048 |
<a onclick="location.href=\'' . $dismiss_url . '\';" class="button button-primary" href="' . esc_url( 'https://wordpress.org/support/view/plugin-reviews/wp-analytify?rate=5#postform' ) . '" target="_blank">' . __( 'Leave a Review', 'wp-analytify' ) . '</a> |
| 1049 |
<a href="' . esc_url( $dismiss_url ) . '">' . __( 'No thanks', 'wp-analytify' ) . '</a> |
| 1050 |
</p> |
| 1051 |
</div>'; |
| 1052 |
|
| 1053 |
} |
| 1054 |
|
| 1055 |
|
| 1056 |
} |
| 1057 |
|
| 1058 |
$wp_analytify = new WP_Analytify(); |
| 1059 |
|
| 1060 |
} //end if |
| 1061 |
|
| 1062 |
//update_option('show_tracking_pointer_1', 0); |
| 1063 |
|
| 1064 |
register_activation_hook( __FILE__, 'install' ); |
| 1065 |
register_deactivation_hook( __FILE__, 'uninstall' ); |
| 1066 |
register_uninstall_hook( __FILE__, 'delete' ); |
| 1067 |
|
| 1068 |
/* |
| 1069 |
* Activate options by default on installing the plugin. |
| 1070 |
*/ |
| 1071 |
function install() { |
| 1072 |
|
| 1073 |
update_option( 'analytify_posts_stats', array( 'post','page' )); |
| 1074 |
update_option( 'post_analytics_disable_back' , 1 ); |
| 1075 |
update_option( 'analytify_code' , 1 ); |
| 1076 |
update_option( 'post_analytics_settings_back' , array( 'show-overall-back' ) ); |
| 1077 |
update_option( 'post_analytics_access_back' , array( 'editor','administrator' ) ); |
| 1078 |
update_option( 'display_tracking_code' , array( 'administrator' ) ); |
| 1079 |
//send_status_analytify( get_option( 'admin_email' ), 'active'); |
| 1080 |
} |
| 1081 |
|
| 1082 |
function uninstall() { |
| 1083 |
|
| 1084 |
if(get_option('wpa_allow_tracking') == 1) send_status_analytify( get_option( 'admin_email' ), 'in-active'); |
| 1085 |
|
| 1086 |
delete_option( 'analytify_posts_stats' ); |
| 1087 |
delete_option( 'pa_google_token' ); |
| 1088 |
delete_option( 'show_tracking_pointer_1' ); |
| 1089 |
delete_option( 'post_analytics_token' ); |
| 1090 |
|
| 1091 |
} |
| 1092 |
|
| 1093 |
function delete() { |
| 1094 |
|
| 1095 |
if(get_option('wpa_allow_tracking') == 1) send_status_analytify( get_option( 'admin_email' ), 'delete'); |
| 1096 |
} |
| 1097 |
|
| 1098 |
/** |
| 1099 |
* @param $email |
| 1100 |
* @param $status |
| 1101 |
*/ |
| 1102 |
|
| 1103 |
function send_status_analytify( $email, $status ) { |
| 1104 |
|
| 1105 |
$url = "https://wp-analytify.com/plugin-manager/"; |
| 1106 |
|
| 1107 |
if ( $email == "" ) { |
| 1108 |
$email = "track@wp-analytify.com"; |
| 1109 |
} |
| 1110 |
|
| 1111 |
$fields = array( |
| 1112 |
"email" => $email , |
| 1113 |
"site" => get_site_url(), |
| 1114 |
"status" => $status, |
| 1115 |
"type" => 'FREE' |
| 1116 |
); |
| 1117 |
|
| 1118 |
wp_remote_post( $url, array( |
| 1119 |
"method" => "POST", |
| 1120 |
"timeout" => 5, |
| 1121 |
"httpversion" => "1.0", |
| 1122 |
"blocking" => false, |
| 1123 |
"headers" => array(), |
| 1124 |
"body" => $fields |
| 1125 |
) |
| 1126 |
); |
| 1127 |
} |
| 1128 |
?> |
| 1129 |
|