diff --git a/eth-amp-analytics-wp.php b/eth-amp-analytics-wp.php index 0ecbec09936efbcb69d734409a96f35c29a7d7e4..dae97f7aa6b8845cc27badb8d64555f8933744df 100644 --- a/eth-amp-analytics-wp.php +++ b/eth-amp-analytics-wp.php @@ -89,16 +89,10 @@ class ETH_AMP_Analytics_WP { * Conditionally load front-end hooks */ public function action_wp_loaded() { - $ga_options = get_option( $this->plugin_option_name ); - - if ( is_array( $ga_options ) ) { - $this->options = wp_parse_args( $ga_options, $this->plugin_option_defaults ); - + if ( ! empty( $this->get_option( 'property_id' ) ) ) { add_filter( 'amp_component_scripts', array( $this, 'filter_amp_component_scripts' ) ); add_action( 'amp_post_template_footer', array( $this, 'action_amp_post_template_footer' ) ); } - - unset( $ga_options ); } /** @@ -168,6 +162,35 @@ class ETH_AMP_Analytics_WP { public function sanitize_options( $options ) { return $options; } + + /** + * UTILITY FUNCTIONS + */ + + /** + * + */ + private function get_option( $name ) { + // Prepare options if this is the first request + if ( is_null( $this->options ) ) { + $ga_options = get_option( $this->plugin_option_name ); + + if ( is_array( $ga_options ) ) { + $this->options = wp_parse_args( $ga_options, $this->plugin_option_defaults ); + } else { + return false; + } + + unset( $ga_options ); + } + + // Does the key exist? + if ( isset( $this->options[ $name ] ) ) { + return $this->options[ $name ]; + } else { + return false; + } + } } ETH_AMP_Analytics_WP::get_instance(); \ No newline at end of file