controller
7 years ago
core
9 years ago
Ga_Admin.php
7 years ago
Ga_Autoloader.php
9 years ago
Ga_Frontend.php
9 years ago
Ga_Helper.php
8 years ago
Ga_Hook.php
9 years ago
Ga_Notice.php
9 years ago
Ga_Sharethis.php
8 years ago
Ga_Stats.php
9 years ago
Ga_Frontend.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | class Ga_Frontend { |
| 4 | |
| 5 | const GA_SHARETHIS_PLATFORM_URL = '//platform-api.sharethis.com/js/sharethis.js'; |
| 6 | |
| 7 | public static function platform_sharethis() { |
| 8 | $url = self::GA_SHARETHIS_PLATFORM_URL . '#product=ga'; |
| 9 | if ( get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ) ) { |
| 10 | $url = $url . '&property=' . get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ); |
| 11 | } |
| 12 | wp_register_script( GA_NAME . '-platform-sharethis', $url, null, null, false ); |
| 13 | wp_enqueue_script( GA_NAME . '-platform-sharethis' ); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Adds frontend actions hooks. |
| 18 | */ |
| 19 | public static function add_actions() { |
| 20 | if ( Ga_Helper::are_features_enabled() ) { |
| 21 | add_action( 'wp_enqueue_scripts', 'Ga_Frontend::platform_sharethis' ); |
| 22 | } |
| 23 | add_action( 'wp_footer', 'Ga_Frontend::insert_ga_script' ); |
| 24 | } |
| 25 | |
| 26 | public static function insert_ga_script() { |
| 27 | if ( Ga_Helper::can_add_ga_code() || Ga_Helper::is_all_feature_disabled() ) { |
| 28 | Ga_View_Core::load( 'ga_googleanalytics_loader', array( |
| 29 | 'ajaxurl' => add_query_arg( Ga_Controller_Core::ACTION_PARAM_NAME, 'googleanalytics_get_script', home_url() ) |
| 30 | ) ); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Gets and returns Web Property Id. |
| 36 | * |
| 37 | * @return string Web Property Id |
| 38 | */ |
| 39 | public static function get_web_property_id() { |
| 40 | $web_property_id = get_option( Ga_Admin::GA_WEB_PROPERTY_ID_OPTION_NAME ); |
| 41 | if ( Ga_Helper::is_code_manually_enabled() || Ga_Helper::is_all_feature_disabled() ) { |
| 42 | $web_property_id = get_option( Ga_Admin::GA_WEB_PROPERTY_ID_MANUALLY_VALUE_OPTION_NAME ); |
| 43 | } |
| 44 | |
| 45 | return $web_property_id; |
| 46 | } |
| 47 | |
| 48 | } |
| 49 |