placements = wp_advads_get_placements(); if ( ! $this->contains_background_placement() ) { return; } wp_register_script( 'advanced-ads-pro/background-ads', '', [], AAP_VERSION, false ); wp_enqueue_script( 'advanced-ads-pro/background-ads' ); wp_add_inline_script( 'advanced-ads-pro/background-ads', 'let abort_controller = new AbortController();' ); } /** * Echo the placement output into the footer. * * @return void */ public function footer_injection() { foreach ( $this->placements as $placement ) { if ( $placement->is_type( 'background' ) ) { the_ad_placement( $placement ); } } } /** * Check if a background placement exists. * * @return bool */ protected function contains_background_placement(): bool { foreach ( $this->placements as $placement ) { if ( $placement->is_type( 'background' ) ) { return true; } } return false; } /** * Change ad output. * * @param string $output Ad output. * @param Ad $ad Ad instance. * * @return string */ public function ad_output( $output, $ad ) { $parent = $ad->get_parent(); if ( ! $parent || ! $parent->is_type( 'background' ) || ! $ad->is_type( 'image' ) ) { return $output; } $background_color = sanitize_text_field( $parent->get_prop( 'bg_color' ) ) ?: false; // Get prefix and generate new body class. $class = wp_advads()->get_frontend_prefix() . 'body-background'; // Get the ad image. $image = wp_get_attachment_image_src( $ad->get_image_id(), 'full' ); if ( ! $image || empty ( $image[0] ) ) { return $output; } [ $image_url, $image_width, $image_height ] = $image; $selector = apply_filters( 'advanced-ads-pro-background-selector', 'body' ); $is_amp = function_exists( 'advads_is_amp' ) && advads_is_amp(); /** * Filter the background placement URL. * * @param string $link The URL. * @param Ad $ad The current ad object. */ $link = (string) apply_filters( 'advanced-ads-pro-background-url', $ad->get_url(), $ad ); if ( class_exists( Helpers::class ) ) { $target = Helpers::get_ad_target( $ad, true ); } else { $options = Advanced_Ads::get_instance()->options(); $target = isset( $options['target-blank'] ) ? '_blank' : ''; } $target = '' !== $target ? $target : '_self'; ob_start(); ?> get_prop( 'custom-code' ); if ( ! empty( $custom_code ) ) { echo $custom_code; } return ob_get_clean(); } }