Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only enqueue CSS if ad layers debug query var present #69

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion php/ad-servers/class-ad-layers-ad-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ public function enqueue_scripts() {
wp_enqueue_script( $this->handle, AD_LAYERS_ASSETS_DIR . 'js/ad-layers.js', $dependencies, AD_LAYERS_GLOBAL_ASSET_VERSION, false );

// Load the CSS. Mostly used in debug mode.
wp_enqueue_style( $this->handle, AD_LAYERS_ASSETS_DIR . 'css/ad-layers.css', array(), AD_LAYERS_GLOBAL_ASSET_VERSION );
if ( false !== get_query_var( 'adlayers_debug', false ) ) {
wp_enqueue_style( $this->handle, AD_LAYERS_ASSETS_DIR . 'css/ad-layers.css', array(), AD_LAYERS_GLOBAL_ASSET_VERSION );
}

// Localize the base API with the class name
wp_localize_script( 'ad-layers', 'adLayersAdServer', array(
Expand Down
4 changes: 3 additions & 1 deletion php/ad-servers/class-ad-layers-dfp.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ public function enqueue_scripts() {
wp_enqueue_script( $this->handle, AD_LAYERS_ASSETS_DIR . 'js/ad-layers-dfp.js', array( 'jquery' ), AD_LAYERS_GLOBAL_ASSET_VERSION, false );

// Load the CSS. Mostly used in debug mode.
wp_enqueue_style( $this->handle, AD_LAYERS_ASSETS_DIR . 'css/ad-layers-dfp.css', array(), AD_LAYERS_GLOBAL_ASSET_VERSION );
if ( false !== get_query_var( 'adlayers_debug', false ) ) {
wp_enqueue_style( $this->handle, AD_LAYERS_ASSETS_DIR . 'css/ad-layers-dfp.css', array(), AD_LAYERS_GLOBAL_ASSET_VERSION );
}

// Localize the base API with static text strings so they can be translated
wp_localize_script( $this->handle, 'adLayersDFP', array(
Expand Down
13 changes: 12 additions & 1 deletion php/class-ad-layers.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,22 @@ public function setup() {
// Load current settings
$this->ad_layers = apply_filters( 'ad_layers', get_option( 'ad_layers' ) );
$this->custom_variables = apply_filters( 'ad_layers_custom_variables', get_option( 'ad_layers_custom_variables' ) );

add_filter( 'query_vars', array( $this, 'add_ad_layer_debug_query_var' ) );
// Set the active ad layer before anything else.
add_action( 'wp_head', array( $this, 'set_active_ad_layer' ), 1 );
}

/**
* Add debug query var.
*
* @param array $query_vars Supported query ar.
* @return array Filtered.
*/
public function add_ad_layer_debug_query_var( $query_vars ) {
$query_vars[] = 'adlayers_debug';
return $query_vars;
}

/**
* Get taxonomies that can be used for targeting.
*
Expand Down