* @since 1.50.0 */ namespace AdvancedAds\Admin; use AdvancedAds\Utilities\Conditional; use AdvancedAds\Framework\Utilities\Arr; defined( 'ABSPATH' ) || exit; /** * Admin Addon Box. */ class Addon_Box { /** * Hide active plugins * * @var bool */ private $hide_activated; /** * Internal plugins data * * @var array */ private $plugins; /** * Constructor * * @param bool $hide_activated whether to hide active plugins. */ public function __construct( $hide_activated = false ) { if ( ! is_admin() ) { return; } $this->hide_activated = (bool) $hide_activated; $this->build_plugins_data(); } /** * Build the internal plugin data * * @return void */ private function build_plugins_data() { // phpcs:disable WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned,WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow $aa_plugins = [ 'advanced-ads-pro/advanced-ads-pro.php' => [ 'id' => 'pro', 'constant' => 'AAP_VERSION', 'title' => 'Advanced Ads Pro', 'description' => __( 'Take the monetization of your website to the next level.', 'advanced-ads' ), 'download_link' => 'https://wpadvancedads.com/add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons', 'manual' => 'https://wpadvancedads.com/manual/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons-manual', ], 'advanced-ads-responsive/responsive-ads.php' => [ 'id' => 'ampads', 'constant' => 'AAR_VERSION', 'title' => 'AMP Ads', 'description' => __( 'Integrate your ads on AMP (Accelerated Mobile Pages) and auto-convert your Google AdSense ad units for enhanced mobile performance.', 'advanced-ads' ), 'download_link' => 'https://wpadvancedads.com/add-ons/responsive-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons', 'manual' => 'https://wpadvancedads.com/manual/ads-on-amp-pages/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons-manual', ], 'advanced-ads-gam/advanced-ads-gam.php' => [ 'id' => 'gam', 'constant' => 'AAGAM_VERSION', 'title' => 'Google Ad Manager Integration', 'description' => __( 'Simplify the process of implementing ad units from Google Ad Manager swiftly and without errors.', 'advanced-ads' ), 'download_link' => 'https://wpadvancedads.com/add-ons/google-ad-manager/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons', 'manual' => 'https://wpadvancedads.com/manual/google-ad-manager-integration-manual/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons-manual', ], 'advanced-ads-layer/layer-ads.php' => [ 'id' => 'popuplayer', 'constant' => 'AAPLDS_VERSION', 'title' => 'PopUp and Layer Ads', 'description' => __( 'Capture attention with customizable pop-ups that ensure your ads and messages get noticed. Set timing and closing options for optimal user engagement.', 'advanced-ads' ), 'download_link' => 'https://wpadvancedads.com/add-ons/popup-and-layer-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons', 'manual' => 'https://wpadvancedads.com/manual/popup-and-layer-ads-documentation/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons-manual', ], 'advanced-ads-selling/advanced-ads-selling.php' => [ 'id' => 'sellingads', 'constant' => 'AASA_VERSION', 'title' => 'Selling Ads', 'description' => __( 'Earn more money by enabling advertisers to buy ad space directly on your site’s frontend.', 'advanced-ads' ), 'download_link' => 'https://wpadvancedads.com/add-ons/selling-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons', 'manual' => 'https://wpadvancedads.com/manual/selling-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons-manual', ], 'advanced-ads-sticky-ads/sticky-ads.php' => [ 'id' => 'stickyads', 'constant' => 'AASADS_SLUG', 'title' => 'Sticky Ads', 'description' => __( 'Increase click rates by anchoring ads in sticky positions above, alongside, or below your website.', 'advanced-ads' ), 'download_link' => 'https://wpadvancedads.com/add-ons/sticky-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons', 'manual' => 'https://wpadvancedads.com/manual/sticky-ads-documentation/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons-manual', ], 'advanced-ads-tracking/tracking.php' => [ 'id' => 'tracking', 'constant' => 'AAT_VERSION', 'title' => 'Tracking', 'description' => __( 'Monitor your ad performance to maximize your revenue.', 'advanced-ads' ), 'download_link' => 'https://wpadvancedads.com/add-ons/tracking/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons', 'manual' => 'https://wpadvancedads.com/manual/tracking-documentation/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons-manual', ], 'advanced-ads-slider/slider.php' => [ 'id' => 'adslider', 'constant' => 'AAS_VERSION', 'title' => 'Ad Slider', 'description' => __( 'Create a beautiful ad slider and increase the ad impressions per page view. Free add-on for subscribers to our newsletter.', 'advanced-ads' ), 'download_link' => 'https://wpadvancedads.com/add-ons/slider/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons', 'manual' => 'https://wpadvancedads.com/manual/ad-slider/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons-manual', ], 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php' => [ 'id' => 'adsenseinfeed', 'constant' => 'AAINF_VERSION', 'title' => 'AdSense In-Feed', 'description' => __( 'Place AdSense In-feed ads between posts on homepage, category, and archive pages for optimal engagement.', 'advanced-ads' ), 'download_link' => wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=advanced-ads-adsense-in-feed' ), 'install-plugin_advanced-ads-adsense-in-feed' ), 'manual' => 'https://wpadvancedads.com/add-adsense-in-feed-to-wordpress/#Adding_the_In-feed_ad_to_your_WordPress_site', ], ]; // phpcs:enable WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned,WordPress.Arrays.MultipleStatementAlignment.LongIndexSpaceBeforeDoubleArrow $plugins = get_plugins(); $this->plugins = [ 'plugins' => [], 'premium_level' => 'free', ]; $pro = false; $tracking = false; $bundle_indicators = [ 'ampads', 'stickyads', 'gam', 'sellingads', 'popuplayer', ]; foreach ( $aa_plugins as $file => $data ) { if ( array_key_exists( $file, $plugins ) ) { $this->plugins['plugins'][ $data['id'] ] = [ 'status' => defined( $data['constant'] ) ? 'active' : 'installed' ]; if ( in_array( $data['id'], $bundle_indicators, true ) ) { $this->plugins['premium_level'] = 'bundle'; } if ( in_array( $data['id'], [ 'pro', 'tracking' ], true ) ) { ${$data['id']} = true; } } else { $this->plugins['plugins'][ $data['id'] ] = [ 'status' => 'missing' ]; } $this->plugins['plugins'][ $data['id'] ]['file'] = $file; if ( isset( $plugins[ $file ] ) ) { $this->plugins['plugins'][ $data['id'] ]['name'] = $plugins[ $file ]['Name']; } $this->plugins['plugins'][ $data['id'] ] += $data; } if ( 'bundle' === $this->plugins['premium_level'] ) { return; } if ( $pro || $tracking ) { $this->plugins['premium_level'] = 'premium'; } if ( $pro && $tracking ) { $this->plugins['premium_level'] = 'bundle'; } } /** * Get feature grid data for an addon * * @param string $id add-on internal ID. * * @return array */ private function get_grid_data( $id ) { if ( 'pro' === $id ) { return [ __( 'Cache Busting', 'advanced-ads' ), __( 'Click Fraud Protection', 'advanced-ads' ), __( 'Lazy Loading', 'advanced-ads' ), __( 'Anti Ad Blocker', 'advanced-ads' ), __( 'Geo Targeting', 'advanced-ads' ), __( '+23 Conditions', 'advanced-ads' ), __( '+11 Placements', 'advanced-ads' ), __( 'Parallax Ads', 'advanced-ads' ), __( 'Ad Grids', 'advanced-ads' ), __( 'Ad Refresh', 'advanced-ads' ), __( 'A/B Tests', 'advanced-ads' ), ]; } if ( 'tracking' === $id ) { return [ __( 'Impressions & Clicks', 'advanced-ads' ), __( 'Click-Through Rate', 'advanced-ads' ), __( 'Statistics', 'advanced-ads' ), __( 'Google Analytics', 'advanced-ads' ), __( 'Local Data Processing', 'advanced-ads' ), __( 'Email Reports', 'advanced-ads' ), __( 'Link Cloaking', 'advanced-ads' ), ]; } return []; } /** * Sort plugins by status (missing|installed|enabled) * * @param array $a plugin data. * @param array $b plugin data. * * @return int */ private function sort_by_status( $a, $b ) { static $order; if ( null === $order ) { $order = [ 'missing' => 0, 'installed' => 1, 'active' => 2, ]; } return $order[ $a['status'] ] < $order[ $b['status'] ] ? 1 : -1; } /** * Sort extra add-ons by the order field * * @param int $a order to compare. * @param int $b order to compare. * * @return mixed */ private function sort_by_order( $a, $b ) { return (int) $a['order'] - (int) $b['order']; } /** * Get plugin list to display into a given section * * @param string $section section slug (installed|available|special). * * @return array[] */ private function get_displayable_items( $section ) { switch ( $section ) { case 'special': $items = []; if ( 'missing' === $this->plugins['plugins']['adslider']['status'] ) { $items['adslider'] = $this->plugins['plugins']['adslider']; } if ( 'missing' === $this->plugins['plugins']['adsenseinfeed']['status'] ) { $items['adsenseinfeed'] = $this->plugins['plugins']['adsenseinfeed']; } return $items; case 'available': if ( 'free' === $this->plugins['premium_level'] ) { return [ 'aa' => [ 'id' => 'aa', 'upsell' => true, ], 'aalt' => [ 'id' => 'aalt' ], 'pro' => array_merge( $this->plugins['plugins']['pro'], [ 'grid' => true ] ), 'tracking' => array_merge( $this->plugins['plugins']['tracking'], [ 'grid' => true ] ), ]; } if ( 'premium' === $this->plugins['premium_level'] ) { $items = [ 'aa' => [ 'id' => 'aa', 'upsell' => true, ], 'aalt' => [ 'id' => 'aalt' ], ]; if ( 'missing' === $this->plugins['plugins']['pro']['status'] ) { $items['pro'] = $this->plugins['plugins']['pro']; $items['pro']['grid'] = true; } if ( 'missing' === $this->plugins['plugins']['tracking']['status'] ) { $items['tracking'] = $this->plugins['plugins']['tracking']; $items['tracking']['grid'] = true; } return $items; } if ( 'bundle' === $this->plugins['premium_level'] ) { return [ 'aalt' => [ 'id' => 'aalt' ] ]; } return []; default: // Installed add-ons. if ( 'free' === $this->plugins['premium_level'] && 'missing' === $this->plugins['plugins']['adslider']['status'] && 'missing' === $this->plugins['plugins']['adsenseinfeed']['status'] ) { return [ 'none' => [ 'id' => 'none', ], ]; } if ( 'bundle' === $this->plugins['premium_level'] ) { $items = [ 'aa' => [ 'id' => 'aa' ], ] + Arr::where( $this->get_special_add_ons(), function ( $item ) { return in_array( $item['status'], [ 'installed', 'active' ], true ); } ); return $items; } $displayable_items = Arr::where( $this->plugins['plugins'], function ( $item ) { return 'missing' !== $item['status']; } ); usort( $displayable_items, [ $this, 'sort_by_status' ] ); return $displayable_items; } } /** * Get list of plugins of the "special" section * * @return array */ private function get_special_add_ons() { return Arr::where( $this->plugins['plugins'], function ( $item ) { return in_array( $item['id'], [ 'adslider', 'adsenseinfeed' ], true ); } ); } /** * Print output for a single add-on (not in bundle) * * @param array $item plugin data. * @param string $section section slug. * * @return void */ private function do_single_item( $item, $section ) { if ( 'aa' === $item['id'] ) { $this->all_access( $item['upsell'] ?? false ); return; } if ( 'aalt' === $item['id'] ) { $this->all_access_long_term(); return; } if ( 'none' === $item['id'] ) { ?>
hide_activated && 'active' === $button_class ) { return; } if ( 'active' === $item['status'] ) { $button_class .= ' disabled'; } if ( 'special' === $section && 'adslider' === $item['id'] ) { $button_class = Conditional::user_can_subscribe( 'nl_free_addons' ) ? 'subscribe' : 'subscribed'; } $grid_data = ! empty( $item['grid'] ) ? $this->get_grid_data( $item['id'] ) : false; $button_target = 'available' === $section ? '_blank' : '_self'; ?>
plugins['plugins'][ $id ]['download_link']; if ( 'tracking' !== $id ) { $link = 'https://wpadvancedads.com/pricing/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons'; } return $link; } if ( 'special' === $section && 'adslider' === $id ) { return 'https://wpadvancedads.com/subscriber-resources/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons-manual'; } if ( 'installed' === $section ) { if ( 'installed' === $this->plugins['plugins'][ $id ]['status'] ) { if ( version_compare( '6.5.0', get_bloginfo( 'version' ), '<=' ) ) { return '#activate-aaplugin_' . wp_create_nonce( 'updates' ) . '_' . $this->plugins['plugins'][ $id ]['file'] . '_' . $this->plugins['plugins'][ $id ]['name']; } return wp_nonce_url( 'plugins.php?action=activate&plugin=' . $this->plugins['plugins'][ $id ]['file'] . '&', 'activate-plugin_' . $this->plugins['plugins'][ $id ]['file'] ); } return 'https://wpadvancedads.com/account/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons'; } if ( 'special' === $section && 'adsenseinfeed' === $id && 'missing' === $this->plugins['plugins'][ $id ]['status'] ) { return wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=advanced-ads-adsense-in-feed' ), 'install-plugin_advanced-ads-adsense-in-feed' ); } return '#'; } /** * Print All Access Long Term output * * @return void */ private function all_access_long_term() { ?>
do_bundle_item( $item, $is_upsell ); } ?>
plugins['plugins'][ $id ]['status']; if ( 'active' === $this->plugins['plugins'][ $id ]['status'] ) { $button_class .= ' disabled'; } if ( $is_upsell ) { $button_class = 'disabled'; } $plugin = $this->plugins['plugins'][ $id ]; ?>
" target="">
get_displayable_items( 'installed' ) as $item ) : ?> do_single_item( $item, 'installed' ); ?> get_displayable_items( 'available' ) as $item ) : ?> do_single_item( $item, 'available' ); ?> get_displayable_items( 'special' ) as $item ) : ?> do_single_item( $item, 'special' ); ?>