| 1 |
<?php |
| 2 |
/** |
| 3 |
* Author: Alin Marcu |
| 4 |
* Author URI: https://deconf.com |
| 5 |
* Copyright 2013 Alin Marcu |
| 6 |
* License: GPLv2 or later |
| 7 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if ( ! defined( 'ABSPATH' ) ) |
| 11 |
exit(); |
| 12 |
if ( ! class_exists( 'AIWP_Backend_Widgets' ) ) { |
| 13 |
|
| 14 |
class AIWP_Backend_Widgets { |
| 15 |
|
| 16 |
private $aiwp; |
| 17 |
|
| 18 |
public function __construct() { |
| 19 |
$this->aiwp = AIWP(); |
| 20 |
if ( AIWP_Tools::check_roles( $this->aiwp->config->options['access_back'] ) && ( 1 == $this->aiwp->config->options['dashboard_widget'] ) ) { |
| 21 |
add_action( 'wp_dashboard_setup', array( $this, 'add_widget' ) ); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
public function add_widget() { |
| 26 |
wp_add_dashboard_widget( 'aiwp-widget', __( "Analytics Insights", 'analytics-insights' ), array( $this, 'dashboard_widget' ), $control_callback = null ); |
| 27 |
} |
| 28 |
|
| 29 |
public function dashboard_widget() { |
| 30 |
$projectId = 0; |
| 31 |
if ( empty( $this->aiwp->config->options['token'] ) ) { |
| 32 |
echo '<p>' . __( "This plugin needs an authorization:", 'analytics-insights' ) . '</p><form action="' . menu_page_url( 'aiwp_settings', false ) . '" method="POST">' . get_submit_button( __( "Authorize Plugin", 'analytics-insights' ), 'secondary' ) . '</form>'; |
| 33 |
return; |
| 34 |
} |
| 35 |
if ( $this->aiwp->config->options['webstream_jail'] ) { |
| 36 |
$projectId = $this->aiwp->config->options['webstream_jail']; |
| 37 |
} else { |
| 38 |
echo '<p>' . __( "An admin should asign a default Google Analytics property.", 'analytics-insights' ) . '</p><form action="' . menu_page_url( 'aiwp_settings', false ) . '" method="POST">' . get_submit_button( __( "Select Domain", 'analytics-insights' ), 'secondary' ) . '</form>'; |
| 39 |
return; |
| 40 |
} |
| 41 |
if ( ! ( $projectId ) ) { |
| 42 |
echo '<p>' . __( "Something went wrong while retrieving property data. You need to create and properly configure a Google Analytics account:", 'analytics-insights' ) . '</p> <form action="https://deconf.com/how-to-add-google-analytics-to-wordpress-easy-way/" method="POST">' . get_submit_button( __( "Find out more!", 'analytics-insights' ), 'secondary' ) . '</form>'; |
| 43 |
return; |
| 44 |
} |
| 45 |
?> |
| 46 |
<div id="aiwp-window-1"></div> |
| 47 |
<?php |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|