File: /var/www/html/wp-content/plugins/advanced-ads-sticky-ads/includes/class-frontend.php
<?php
/**
* Frontend.
*
* @package AdvancedAds\StickyAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.9.0
*/
namespace AdvancedAds\StickyAds;
use AdvancedAds\Abstracts\Ad;
use AdvancedAds\Utilities\Conditional;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Frontend.
*/
class Frontend implements Integration_Interface {
/**
* Collect the ids of placements.
*
* @var array
*/
private $placements_ids = null;
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_action( 'wp_footer', [ $this, 'footer_injection' ], 10 );
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
}
/**
* Append js file in footer
*
* @return void
*/
public function enqueue_scripts(): void {
if ( Conditional::is_amp() ) {
return;
}
$options = wp_advads_get_sticky_options();
wp_enqueue_script( 'advanced-ads-sticky-footer-js', AA_STICKY_ADS_BASE_URL . 'assets/dist/sticky.js', [], AA_STICKY_ADS_VERSION, true );
wp_localize_script(
'advanced-ads-sticky-footer-js',
'advanced_ads_sticky_settings',
[
'check_position_fixed' => $options['check-position-fixed'],
'sticky_class' => wp_advads_get_sticky_class(),
'placements' => $this->get_sticky_placements_ids(),
]
);
}
/**
* Injects the ads into the footer.
*
* @since 1.2.3
*
* @return void
*/
public function footer_injection(): void {
foreach ( $this->get_sticky_placements_ids() as $placement_id ) {
the_ad_placement( $placement_id );
}
}
/**
* Retrieves an array of sticky placements.
*
* @return array The array of sticky placements.
*/
private function get_sticky_placements_ids(): array {
if ( null === $this->placements_ids ) {
$sticky_placements = [
'sticky_left_sidebar',
'sticky_right_sidebar',
'sticky_header',
'sticky_footer',
'sticky_left_window',
'sticky_right_window',
];
$this->placements_ids = [];
$this->placements_ids = wp_advads_get_placements_by_types( $sticky_placements, 'ids' );
}
return $this->placements_ids;
}
}