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

add filters for mapping #58

Open
wants to merge 1 commit into
base: plugin-boilerplate
Choose a base branch
from
Open
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
45 changes: 29 additions & 16 deletions includes/class-doubleclick.php
Original file line number Diff line number Diff line change
@@ -153,20 +153,22 @@ public function enqueue_scripts() {

$data = array(
'network_code' => $this->network_code,
'mappings' => $mappings,
'mappings' => apply_filters( 'dfw_mappings', $mappings ),
'targeting' => $this->targeting(),
);

wp_localize_script( 'jquery.dfw.js', 'dfw', $data );
wp_enqueue_script( 'jquery.dfw.js' );

wp_enqueue_style(
'dfp',
plugins_url( 'assets/css/dfp.css', dirname( __FILE__ ) ),
array(),
DoubleClick_For_WordPress::VERSION,
'all'
);
if ( ! empty( get_option( 'dfw_css' ) ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have a corresponding settings assoc. with it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, in https://github.com/INN/doubleclick-for-wp/blob/plugin-boilerplate/includes/class-options.php#L199

Hold off on merging this for a bit though, I need to add a thing to fire dfw_load(), probably in jquery.dfw.js on document ready but I want to make sure the timing is correct and a callback exists because we have some stuff we need to run before that loads so I just need to do a little more testing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aschweigert Were you planning to add anything else to this pull request, or is it okay to close this?

wp_enqueue_style(
'dfp',
plugins_url( 'assets/css/dfp.css', dirname( __FILE__ ) ),
array(),
DoubleClick_For_WordPress::VERSION,
'all'
);
}
}

/**
@@ -190,14 +192,18 @@ public function footer_script() {
if ( $ad->has_mapping() ) {
$mappings[ "mapping{$ad->id}" ] = $ad->mapping();
}
} ?>
}
$mappings = apply_filters( 'dfw_mappings', $mappings );
?>
<script type="text/javascript">
jQuery('.dfw-unit:not(.dfw-lazy-load)').dfp({
dfpID: <?php echo wp_json_encode( $this->network_code() ); ?>,
collapseEmptyDivs: false,
setTargeting: <?php echo wp_json_encode( $this->targeting() ); ?>,
sizeMapping: <?php echo wp_json_encode( $mappings ); ?>
});
var dfw_load = function() {
jQuery('.dfw-unit:not(.dfw-lazy-load)').dfp({
dfpID: <?php echo wp_json_encode( $this->network_code() ); ?>,
collapseEmptyDivs: false,
setTargeting: <?php echo wp_json_encode( $this->targeting() ); ?>,
sizeMapping: <?php echo wp_json_encode( $mappings ); ?>
});
};
</script>
<?php }
}
@@ -301,6 +307,7 @@ public function place_ad( $identifier, $sizes, $args = null ) {
'data-adunit' => array(),
'data-size-mapping' => array(),
'data-dimensions' => array(),
'data-outofpage' => array(),
)
)
);
@@ -322,6 +329,7 @@ public function get_ad_placement( $identifier, $sizes, $args = null ) {

$defaults = array(
'lazyLoad' => false,
'outofPage' => false,
);

$args = wp_parse_args( $args, $defaults );
@@ -338,7 +346,12 @@ public function get_ad_placement( $identifier, $sizes, $args = null ) {

$id = $ad_object->id;

if ( $ad_object->has_mapping() ) {
if ( $args['outofPage'] ) {
$ad = "<div
class='$classes'
data-adunit='$identifier'
data-outofpage='true'></div>";
} else if ( $ad_object->has_mapping() ) {
$ad = "<div
class='$classes'
data-adunit='$identifier'