Plugin Directory

Changeset 3253296


Ignore:
Timestamp:
03/10/2025 11:54:27 AM (9 months ago)
Author:
advancedads
Message:

Update to version 2.0.0 from GitHub

Location:
advanced-ads-adsense-in-feed
Files:
72 added
2 deleted
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • advanced-ads-adsense-in-feed/tags/2.0.0/advanced-ads-in-feed.php

    r3243698 r3253296  
    11<?php
    22/**
     3 * Advanced Ads – Google AdSense In-feed Placement
     4 *
     5 * @package   AdvancedAds
     6 * @author    Advanced Ads <[email protected]>
     7 * @license   GPL-2.0+
     8 * @link      https://wpadvancedads.com
     9 * @copyright since 2013 Advanced Ads
     10 *
     11 * @wordpress-plugin
    312 * Plugin Name:       Advanced Ads – Google AdSense In-feed Placement
    4  * Plugin URI:        https://wpadvancedads.com
     13 * Version:           2.0.0
    514 * Description:       Display AdSense In-feed ads between posts
    6  * Version:           1.1.4
     15 * Plugin URI:        https://wpadvancedads.com/
    716 * Author:            Advanced Ads
    817 * Author URI:        https://wpadvancedads.com
     
    1019 * Domain Path:       /languages
    1120 * License:           GPL-2.0+
    12  * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     21 * License URI:       https://www.gnu.org/licenses/gpl-2.0.txt
     22 *
     23 * @requires
     24 * Requires at least: 5.7
     25 * Requires PHP:      7.4
    1326 */
    1427
    15 if ( ! defined( 'ABSPATH' ) ) {
    16     die( '-1' );
     28// Early bail!!
     29if ( ! function_exists( 'add_filter' ) ) {
     30    header( 'Status: 403 Forbidden' );
     31    header( 'HTTP/1.1 403 Forbidden' );
     32    exit();
    1733}
    1834
    19 define( 'AAIF_FILE', __FILE__ );
    20 define( 'AAIF_VERSION', '1.1.4' );
     35if ( defined( 'AAINF_FILE' ) ) {
     36    return;
     37}
    2138
    22 /**
    23  * Class Advanced_Ads_In_Feed
    24  */
    25 class Advanced_Ads_In_Feed {
     39define( 'AAINF_FILE', __FILE__ );
     40define( 'AAINF_VERSION', '2.0.0' );
     41
     42// Load the autoloader.
     43require_once __DIR__ . '/includes/class-autoloader.php';
     44\AdvancedAds\InFeed\Autoloader::get()->initialize();
     45
     46if ( ! function_exists( 'wp_advads_infeed' ) ) {
    2647    /**
    27      * Advanced_Ads_In_Feed constructor.
     48     * Returns the main instance of the plugin.
     49     *
     50     * @return \AdvancedAds\InFeed\Plugin
     51     * @since 1.2.0
    2852     */
    29     public function __construct() {
    30         add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
    31         add_action( 'init', array( $this, 'check_dependencies' ) );
    32     }
    33 
    34     /**
    35      * Load when plugin are loaded
    36      */
    37     public function plugins_loaded() {
    38         if ( ! defined( 'ADVADS_VERSION' ) ) {
    39             return;
    40         }
    41         // load translations.
    42         add_filter( 'advanced-ads-placement-types', array( $this, 'add_placement_types' ) );
    43         // inject ads into archive pages.
    44         add_action( 'the_post', array( $this, 'inject_in_feed' ), 20, 2 );
    45         // options for placement.
    46         add_action( 'advanced-ads-placement-options-before', array( $this, 'placement_options_check' ), 10, 2 );
    47         add_action( 'advanced-ads-placement-options-after', array( $this, 'placement_options' ), 11, 2 );
    48     }
    49 
    50     /**
    51      * Check if Advanced Ads basic plugin is activated
    52      */
    53     public function check_dependencies() {
    54         // Check if Advanced Ads is installed.
    55         if ( ! defined( 'ADVADS_VERSION' ) ) {
    56             // Display notice that Advanced Ads is required.
    57             add_action( 'admin_notices', array( $this, 'show_advads_version_notice' ) );
    58         }
    59     }
    60 
    61     /**
    62      * Add placement types
    63      *
    64      * @param array $types array of ad types.
    65      *
    66      * @return array $types
    67      * @since   1.0.0
    68      */
    69     public function add_placement_types( $types ) {
    70         // ad injection at a hand selected element in the frontend.
    71         $types['adsense_in_feed'] = array(
    72             'title'       => __( 'AdSense In-feed', 'advanced-ads-adsense-in-feed' ),
    73             'description' => __( 'Display an AdSense In-feed ad between posts', 'advanced-ads-adsense-in-feed' ),
    74             'image'       => plugin_dir_url( __FILE__ ) . 'adsense-in-feed.png',
    75             'order'       => 21,
    76             'options'     => array(
    77                 'show_position'  => true,
    78                 'show_lazy_load' => true,
    79             ),
    80         );
    81 
    82         return $types;
    83     }
    84 
    85     /**
    86      * Echo ad before/after posts in loops on archive pages
    87      *
    88      * @param array    $post post object.
    89      * @param WP_Query $wp_query query object.
    90      *
    91      * @since 1.0
    92      */
    93     public function inject_in_feed( $post, $wp_query = null ) {
    94         if (
    95             ! $wp_query instanceof WP_Query || is_feed() ||
    96             is_admin() || $wp_query->is_singular() || ! $wp_query->in_the_loop ||
    97             ! isset( $wp_query->current_post ) || ! $wp_query->is_main_query()
    98         ) {
    99             return;
    100         }
    101 
    102         $curr_index = $wp_query->current_post + 1; // normalize index.
    103 
    104         // handle the situation when wp_reset_postdata() is used after secondary query inside main query.
    105         static $handled_indexes = array();
    106         if ( isset( $handled_indexes[ $curr_index ] ) ) {
    107             return;
    108         }
    109         $handled_indexes[] = $curr_index;
    110 
    111         $placements = get_option( 'advads-ads-placements', array() );
    112         if ( is_array( $placements ) ) {
    113             foreach ( $placements as $_placement_id => $_placement ) {
    114                 if ( empty( $_placement['item'] ) ) {
    115                     continue;
    116                 }
    117 
    118                 if ( isset( $_placement['type'] ) && 'adsense_in_feed' === $_placement['type'] ) {
    119                     $_options = isset( $_placement['options'] ) ? $_placement['options'] : array();
    120                     $ad_index = isset( $_options['adsense_in_feed_pages_index'] ) ? absint( ( $_options['adsense_in_feed_pages_index'] ) ) : 1;
    121                     if ( $ad_index === $curr_index ) {
    122                         $_options['placement']['type'] = $_placement['type'];
    123                         if ( isset( $_placement['item'] ) && $this->is_infeed_ad_item( $_placement['item'] ) ) {
    124                             echo Advanced_Ads_Select::get_instance()->get_ad_by_method( $_placement_id, Advanced_Ads_Select::PLACEMENT, $_options );
    125                         }
    126                     }
    127                 }
    128             }
    129         }
    130     }
    131 
    132     /**
    133      * Check if the current ad is indeed an infeed item
    134      *
    135      * @param string $item_id item ID from a placement.
    136      *
    137      * @return  bool    true if it is an infeed ad
    138      */
    139     private function is_infeed_ad_item( $item_id ) {
    140         $_item = explode( '_', $item_id );
    141 
    142         if ( 'ad' !== $_item[0] || ! isset( $_item[1] ) || empty( $_item[1] ) ) {
    143             return false;
    144         }
    145 
    146         // load the ad.
    147         $ad = new Advanced_Ads_Ad( $_item[1] );
    148         if (
    149             isset( $ad->type ) && 'adsense' === $ad->type
    150             && isset( $ad->content )
    151             && strpos( $ad->content, 'in-feed' )
    152         ) {
    153             return true;
    154         }
    155 
    156         return false;
    157     }
    158 
    159     /**
    160      * Show warning about missing Advanced Ads basic plugin
    161      */
    162     public function show_advads_version_notice() {
    163         $plugin_data = get_plugin_data( __FILE__ );
    164         $plugins     = get_plugins();
    165         if ( isset( $plugins['advanced-ads/advanced-ads.php'] ) ) { // is installed, but not active.
    166             $link = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=advanced-ads/advanced-ads.php&amp', 'activate-plugin_advanced-ads/advanced-ads.php' ) . '">' . __( 'Activate Now', 'advanced-ads-adsense-in-feed' ) . '</a>';
    167         } else {
    168             $link = '<a class="button button-primary" href="' . wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . 'advanced-ads' ), 'install-plugin_' . 'advanced-ads' ) . '">' . __( 'Install Now', 'advanced-ads-adsense-in-feed' ) . '</a>';
    169         }
    170         echo '
    171         <div class="error">
    172           <p>' . sprintf( __( '<strong>%s</strong> requires the <strong><a href="https://wpadvancedads.com/#utm_source=advanced-ads&utm_medium=link&utm_campaign=activate-in-feed" target="_blank">Advanced Ads</a></strong> plugin to be installed and activated on your site.', 'advanced-ads-adsense-in-feed' ), $plugin_data['Name'] ) .
    173              '&nbsp;' . $link . '</p></div>';
    174     }
    175 
    176     function load_plugin_textdomain() {
    177         load_plugin_textdomain( 'advanced-ads-adsense-in-feed', false, basename( dirname( __FILE__ ) ) . '/languages/' );
    178     }
    179 
    180     /**
    181      * Check if this is indeed an In-feed ad
    182      *
    183      * @param string $placement_slug id of the placement.
    184      * @param array  $placement array with placement options.
    185      *
    186      * @since 1.0
    187      */
    188     public function placement_options_check( $placement_slug, $placement ) {
    189         if ( isset( $placement['type'] ) && 'adsense_in_feed' === $placement['type'] ) {
    190             // check if this is the correct item type (AdSense In-feed).
    191             if ( isset( $placement['item'] ) && ! $this->is_infeed_ad_item( $placement['item'] ) ) {
    192                 echo '<p class="advads-error-message">' . sprintf(
    193                     // translators: %s is a link.
    194                         __( 'This placement can only deliver a single In-feed ad. Use the <a href="%s" target="_blank">Post Lists placement</a> for other ad types.', 'advanced-ads-adsense-in-feed' ),
    195                         esc_url( ADVADS_URL ) . 'manual/placement-post-lists/'
    196                     ) . '</p>';
    197             }
    198         }
    199     }
    200 
    201     /**
    202      * Render placement options
    203      *
    204      * @param string $placement_slug id of the placement.
    205      * @param array  $placement array with placement options.
    206      *
    207      * @since 1.0
    208      */
    209     public function placement_options( $placement_slug, $placement ) {
    210         if ( isset( $placement['type'] ) && 'adsense_in_feed' === $placement['type'] ) {
    211             $index          = ( isset( $placement['options']['adsense_in_feed_pages_index'] ) ) ? $placement['options']['adsense_in_feed_pages_index'] : 1;
    212             $index_option   = '<input type="number" name="advads[placements][' . $placement_slug . '][options][adsense_in_feed_pages_index]" value="'
    213                               . $index . '" name="advads-placements-adsense-in-feed-index' . $placement_slug . '"/>';
    214             $option_content = sprintf(
    215             // translators: $s is an index, e.g., "5".
    216                 __( 'Inject before %s. post', 'advanced-ads-adsense-in-feed' ),
    217                 $index_option
    218             );
    219 
    220             $description = __( 'Before which post to inject the ad on post lists.', 'advanced-ads-adsense-in-feed' );
    221             if ( class_exists( 'Advanced_Ads_Admin_Options' ) ) {
    222                 Advanced_Ads_Admin_Options::render_option(
    223                     'placement-in-feed-position',
    224                     __( 'position', 'advanced-ads-adsense-in-feed' ),
    225                     $option_content,
    226                     $description
    227                 );
    228             }
    229         }
     53    function wp_advads_infeed() {
     54        return \AdvancedAds\InFeed\Plugin::get();
    23055    }
    23156}
    23257
    233 /**
    234  * Halt code remove with new release.
    235  *
    236  * @return void
    237  */
    238 function wp_advads_in_feed_halt_code() {
    239     global $advads_halt_notices;
    240 
    241     // Early bail!!
    242     if ( ! defined( 'ADVADS_VERSION' ) ) {
    243         return;
    244     }
    245 
    246     if ( version_compare( ADVADS_VERSION, '2.0.0', '>=' ) ) {
    247         if ( ! isset( $advads_halt_notices ) ) {
    248             $advads_halt_notices = [];
    249         }
    250         $advads_halt_notices[] = __( 'Advanced Ads – Google AdSense In-feed Placement', 'advanced-ads-adsense-in-feed' );
    251 
    252         add_action(
    253             'all_admin_notices',
    254             static function () {
    255                 global $advads_halt_notices;
    256 
    257                 // Early bail!!
    258                 if ( 'plugins' === get_current_screen()->base || empty( $advads_halt_notices ) ) {
    259                     return;
    260                 }
    261                 ?>
    262                 <div class="notice notice-error">
    263                     <h2><?php esc_html_e( 'Important Notice', 'advanced-ads-adsense-in-feed' ); ?></h2>
    264                     <p>
    265                         <?php
    266                         echo wp_kses_post(
    267                             sprintf(
    268                                 /* translators: %s: Plugin name */
    269                                 __( 'Your versions of the Advanced Ads addons listed below are incompatible with <strong>Advanced Ads 2.0</strong> and have been deactivated. Please update them to their latest version. If you cannot update, e.g., due to an expired license, you can <a href="%1$s">roll back to a compatible version of the Advanced Ads plugin</a> at any time or <a href="%2$s">renew your license</a>.', 'advanced-ads-adsense-in-feed' ),
    270                                 esc_url( admin_url( 'admin.php?page=advanced-ads-tools&sub_page=version' ) ),
    271                                 'https://wpadvancedads.com/account/#h-licenses'
    272                             )
    273                         )
    274                         ?>
    275                     </p>
    276                     <h3><?php esc_html_e( 'The following addons are affected:', 'advanced-ads-adsense-in-feed' ); ?></h3>
    277                     <ul>
    278                         <?php foreach ( $advads_halt_notices as $notice ) : ?>
    279                             <li><strong><?php echo esc_html( $notice ); ?></strong></li>
    280                         <?php endforeach; ?>
    281                     </ul>
    282                 </div>
    283                 <?php
    284                 $advads_halt_notices = [];
    285             }
    286         );
    287 
    288         add_action(
    289             'after_plugin_row_' . plugin_basename( __FILE__ ),
    290             static function () {
    291                 echo '<tr class="active"><td colspan="5" class="plugin-update colspanchange">';
    292                 wp_admin_notice(
    293                     sprintf(
    294                         /* translators: %s: Plugin name */
    295                         __( 'Your version of <strong>Advanced Ads – Google AdSense In-feed Placement</strong> is incompatible with <strong>Advanced Ads 2.0</strong> and has been deactivated. Please update the plugin to the latest version. If you cannot update the plugin, e.g., due to an expired license, you can <a href="%1$s">roll back to a compatible version of the Advanced Ads plugin</a> at any time or <a href="%2$s">renew your license</a>.', 'advanced-ads-pro' ),
    296                         esc_url( admin_url( 'admin.php?page=advanced-ads-tools&sub_page=version' ) ),
    297                         'https://wpadvancedads.com/account/#h-licenses'
    298                     ),
    299                     [
    300                         'type'               => 'error',
    301                         'additional_classes' => array( 'notice-alt', 'inline', 'update-message' ),
    302                     ]
    303                 );
    304                 echo '</td></tr>';
    305             }
    306         );
    307         return;
    308     }
    309 
    310     // Autoload and activate.
    311     new Advanced_Ads_In_Feed();
    312 }
    313 
    314 add_action( 'plugins_loaded', 'wp_advads_in_feed_halt_code', 5 );
     58\AdvancedAds\InFeed\Bootstrap::get()->start();
  • advanced-ads-adsense-in-feed/tags/2.0.0/readme.txt

    r3243698 r3253296  
    22Contributors: advancedads, webzunft
    33Tags: adsense, in-feed, in-feed ads, ads, google adsense, loop, post list, post lists, archive pages, category pages, tag pages
    4 Requires at least: 5.0
     4Requires at least: 5.7
    55Tested up to: 6.7
    6 Stable tag: 1.1.4
     6Requires PHP: 7.4
     7Stable tag: 2.0.0
    78License: GPLv2 or later
    89License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1617Google AdSense InFeed ads are a dedicated Google AdSense ad type to monetize such post lists pages with a highly engaging layout and specialized options.
    1718
    18 Advanced Ads was developed to place, manage and test ads on pages to increase revenue and usability. 
     19Advanced Ads was developed to place, manage and test ads on pages to increase revenue and usability.
    1920
    20 The plugin comes with plenty of features, e.g., 
     21The plugin comes with plenty of features, e.g.,
    2122
    2223* Support for all Google AdSense types like link units, responsive, In-feed, In-article and matched content
     
    4243== Changelog ==
    4344
    44 = 1.1.4 =
    45 * Improvement: add compatibility code for Advanced Ads 2.0
     45= 2.0.0 =
     46- Feature: achieve full compatibility with Advanced Ads 2.0
     47- Improvement: enhance performance and efficiency with new codebase
    4648
    4749= 1.1.3 =
  • advanced-ads-adsense-in-feed/trunk/advanced-ads-in-feed.php

    r3243698 r3253296  
    11<?php
    22/**
     3 * Advanced Ads – Google AdSense In-feed Placement
     4 *
     5 * @package   AdvancedAds
     6 * @author    Advanced Ads <[email protected]>
     7 * @license   GPL-2.0+
     8 * @link      https://wpadvancedads.com
     9 * @copyright since 2013 Advanced Ads
     10 *
     11 * @wordpress-plugin
    312 * Plugin Name:       Advanced Ads – Google AdSense In-feed Placement
    4  * Plugin URI:        https://wpadvancedads.com
     13 * Version:           2.0.0
    514 * Description:       Display AdSense In-feed ads between posts
    6  * Version:           1.1.4
     15 * Plugin URI:        https://wpadvancedads.com/
    716 * Author:            Advanced Ads
    817 * Author URI:        https://wpadvancedads.com
     
    1019 * Domain Path:       /languages
    1120 * License:           GPL-2.0+
    12  * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     21 * License URI:       https://www.gnu.org/licenses/gpl-2.0.txt
     22 *
     23 * @requires
     24 * Requires at least: 5.7
     25 * Requires PHP:      7.4
    1326 */
    1427
    15 if ( ! defined( 'ABSPATH' ) ) {
    16     die( '-1' );
     28// Early bail!!
     29if ( ! function_exists( 'add_filter' ) ) {
     30    header( 'Status: 403 Forbidden' );
     31    header( 'HTTP/1.1 403 Forbidden' );
     32    exit();
    1733}
    1834
    19 define( 'AAIF_FILE', __FILE__ );
    20 define( 'AAIF_VERSION', '1.1.4' );
     35if ( defined( 'AAINF_FILE' ) ) {
     36    return;
     37}
    2138
    22 /**
    23  * Class Advanced_Ads_In_Feed
    24  */
    25 class Advanced_Ads_In_Feed {
     39define( 'AAINF_FILE', __FILE__ );
     40define( 'AAINF_VERSION', '2.0.0' );
     41
     42// Load the autoloader.
     43require_once __DIR__ . '/includes/class-autoloader.php';
     44\AdvancedAds\InFeed\Autoloader::get()->initialize();
     45
     46if ( ! function_exists( 'wp_advads_infeed' ) ) {
    2647    /**
    27      * Advanced_Ads_In_Feed constructor.
     48     * Returns the main instance of the plugin.
     49     *
     50     * @return \AdvancedAds\InFeed\Plugin
     51     * @since 1.2.0
    2852     */
    29     public function __construct() {
    30         add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
    31         add_action( 'init', array( $this, 'check_dependencies' ) );
    32     }
    33 
    34     /**
    35      * Load when plugin are loaded
    36      */
    37     public function plugins_loaded() {
    38         if ( ! defined( 'ADVADS_VERSION' ) ) {
    39             return;
    40         }
    41         // load translations.
    42         add_filter( 'advanced-ads-placement-types', array( $this, 'add_placement_types' ) );
    43         // inject ads into archive pages.
    44         add_action( 'the_post', array( $this, 'inject_in_feed' ), 20, 2 );
    45         // options for placement.
    46         add_action( 'advanced-ads-placement-options-before', array( $this, 'placement_options_check' ), 10, 2 );
    47         add_action( 'advanced-ads-placement-options-after', array( $this, 'placement_options' ), 11, 2 );
    48     }
    49 
    50     /**
    51      * Check if Advanced Ads basic plugin is activated
    52      */
    53     public function check_dependencies() {
    54         // Check if Advanced Ads is installed.
    55         if ( ! defined( 'ADVADS_VERSION' ) ) {
    56             // Display notice that Advanced Ads is required.
    57             add_action( 'admin_notices', array( $this, 'show_advads_version_notice' ) );
    58         }
    59     }
    60 
    61     /**
    62      * Add placement types
    63      *
    64      * @param array $types array of ad types.
    65      *
    66      * @return array $types
    67      * @since   1.0.0
    68      */
    69     public function add_placement_types( $types ) {
    70         // ad injection at a hand selected element in the frontend.
    71         $types['adsense_in_feed'] = array(
    72             'title'       => __( 'AdSense In-feed', 'advanced-ads-adsense-in-feed' ),
    73             'description' => __( 'Display an AdSense In-feed ad between posts', 'advanced-ads-adsense-in-feed' ),
    74             'image'       => plugin_dir_url( __FILE__ ) . 'adsense-in-feed.png',
    75             'order'       => 21,
    76             'options'     => array(
    77                 'show_position'  => true,
    78                 'show_lazy_load' => true,
    79             ),
    80         );
    81 
    82         return $types;
    83     }
    84 
    85     /**
    86      * Echo ad before/after posts in loops on archive pages
    87      *
    88      * @param array    $post post object.
    89      * @param WP_Query $wp_query query object.
    90      *
    91      * @since 1.0
    92      */
    93     public function inject_in_feed( $post, $wp_query = null ) {
    94         if (
    95             ! $wp_query instanceof WP_Query || is_feed() ||
    96             is_admin() || $wp_query->is_singular() || ! $wp_query->in_the_loop ||
    97             ! isset( $wp_query->current_post ) || ! $wp_query->is_main_query()
    98         ) {
    99             return;
    100         }
    101 
    102         $curr_index = $wp_query->current_post + 1; // normalize index.
    103 
    104         // handle the situation when wp_reset_postdata() is used after secondary query inside main query.
    105         static $handled_indexes = array();
    106         if ( isset( $handled_indexes[ $curr_index ] ) ) {
    107             return;
    108         }
    109         $handled_indexes[] = $curr_index;
    110 
    111         $placements = get_option( 'advads-ads-placements', array() );
    112         if ( is_array( $placements ) ) {
    113             foreach ( $placements as $_placement_id => $_placement ) {
    114                 if ( empty( $_placement['item'] ) ) {
    115                     continue;
    116                 }
    117 
    118                 if ( isset( $_placement['type'] ) && 'adsense_in_feed' === $_placement['type'] ) {
    119                     $_options = isset( $_placement['options'] ) ? $_placement['options'] : array();
    120                     $ad_index = isset( $_options['adsense_in_feed_pages_index'] ) ? absint( ( $_options['adsense_in_feed_pages_index'] ) ) : 1;
    121                     if ( $ad_index === $curr_index ) {
    122                         $_options['placement']['type'] = $_placement['type'];
    123                         if ( isset( $_placement['item'] ) && $this->is_infeed_ad_item( $_placement['item'] ) ) {
    124                             echo Advanced_Ads_Select::get_instance()->get_ad_by_method( $_placement_id, Advanced_Ads_Select::PLACEMENT, $_options );
    125                         }
    126                     }
    127                 }
    128             }
    129         }
    130     }
    131 
    132     /**
    133      * Check if the current ad is indeed an infeed item
    134      *
    135      * @param string $item_id item ID from a placement.
    136      *
    137      * @return  bool    true if it is an infeed ad
    138      */
    139     private function is_infeed_ad_item( $item_id ) {
    140         $_item = explode( '_', $item_id );
    141 
    142         if ( 'ad' !== $_item[0] || ! isset( $_item[1] ) || empty( $_item[1] ) ) {
    143             return false;
    144         }
    145 
    146         // load the ad.
    147         $ad = new Advanced_Ads_Ad( $_item[1] );
    148         if (
    149             isset( $ad->type ) && 'adsense' === $ad->type
    150             && isset( $ad->content )
    151             && strpos( $ad->content, 'in-feed' )
    152         ) {
    153             return true;
    154         }
    155 
    156         return false;
    157     }
    158 
    159     /**
    160      * Show warning about missing Advanced Ads basic plugin
    161      */
    162     public function show_advads_version_notice() {
    163         $plugin_data = get_plugin_data( __FILE__ );
    164         $plugins     = get_plugins();
    165         if ( isset( $plugins['advanced-ads/advanced-ads.php'] ) ) { // is installed, but not active.
    166             $link = '<a class="button button-primary" href="' . wp_nonce_url( 'plugins.php?action=activate&amp;plugin=advanced-ads/advanced-ads.php&amp', 'activate-plugin_advanced-ads/advanced-ads.php' ) . '">' . __( 'Activate Now', 'advanced-ads-adsense-in-feed' ) . '</a>';
    167         } else {
    168             $link = '<a class="button button-primary" href="' . wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . 'advanced-ads' ), 'install-plugin_' . 'advanced-ads' ) . '">' . __( 'Install Now', 'advanced-ads-adsense-in-feed' ) . '</a>';
    169         }
    170         echo '
    171         <div class="error">
    172           <p>' . sprintf( __( '<strong>%s</strong> requires the <strong><a href="https://wpadvancedads.com/#utm_source=advanced-ads&utm_medium=link&utm_campaign=activate-in-feed" target="_blank">Advanced Ads</a></strong> plugin to be installed and activated on your site.', 'advanced-ads-adsense-in-feed' ), $plugin_data['Name'] ) .
    173              '&nbsp;' . $link . '</p></div>';
    174     }
    175 
    176     function load_plugin_textdomain() {
    177         load_plugin_textdomain( 'advanced-ads-adsense-in-feed', false, basename( dirname( __FILE__ ) ) . '/languages/' );
    178     }
    179 
    180     /**
    181      * Check if this is indeed an In-feed ad
    182      *
    183      * @param string $placement_slug id of the placement.
    184      * @param array  $placement array with placement options.
    185      *
    186      * @since 1.0
    187      */
    188     public function placement_options_check( $placement_slug, $placement ) {
    189         if ( isset( $placement['type'] ) && 'adsense_in_feed' === $placement['type'] ) {
    190             // check if this is the correct item type (AdSense In-feed).
    191             if ( isset( $placement['item'] ) && ! $this->is_infeed_ad_item( $placement['item'] ) ) {
    192                 echo '<p class="advads-error-message">' . sprintf(
    193                     // translators: %s is a link.
    194                         __( 'This placement can only deliver a single In-feed ad. Use the <a href="%s" target="_blank">Post Lists placement</a> for other ad types.', 'advanced-ads-adsense-in-feed' ),
    195                         esc_url( ADVADS_URL ) . 'manual/placement-post-lists/'
    196                     ) . '</p>';
    197             }
    198         }
    199     }
    200 
    201     /**
    202      * Render placement options
    203      *
    204      * @param string $placement_slug id of the placement.
    205      * @param array  $placement array with placement options.
    206      *
    207      * @since 1.0
    208      */
    209     public function placement_options( $placement_slug, $placement ) {
    210         if ( isset( $placement['type'] ) && 'adsense_in_feed' === $placement['type'] ) {
    211             $index          = ( isset( $placement['options']['adsense_in_feed_pages_index'] ) ) ? $placement['options']['adsense_in_feed_pages_index'] : 1;
    212             $index_option   = '<input type="number" name="advads[placements][' . $placement_slug . '][options][adsense_in_feed_pages_index]" value="'
    213                               . $index . '" name="advads-placements-adsense-in-feed-index' . $placement_slug . '"/>';
    214             $option_content = sprintf(
    215             // translators: $s is an index, e.g., "5".
    216                 __( 'Inject before %s. post', 'advanced-ads-adsense-in-feed' ),
    217                 $index_option
    218             );
    219 
    220             $description = __( 'Before which post to inject the ad on post lists.', 'advanced-ads-adsense-in-feed' );
    221             if ( class_exists( 'Advanced_Ads_Admin_Options' ) ) {
    222                 Advanced_Ads_Admin_Options::render_option(
    223                     'placement-in-feed-position',
    224                     __( 'position', 'advanced-ads-adsense-in-feed' ),
    225                     $option_content,
    226                     $description
    227                 );
    228             }
    229         }
     53    function wp_advads_infeed() {
     54        return \AdvancedAds\InFeed\Plugin::get();
    23055    }
    23156}
    23257
    233 /**
    234  * Halt code remove with new release.
    235  *
    236  * @return void
    237  */
    238 function wp_advads_in_feed_halt_code() {
    239     global $advads_halt_notices;
    240 
    241     // Early bail!!
    242     if ( ! defined( 'ADVADS_VERSION' ) ) {
    243         return;
    244     }
    245 
    246     if ( version_compare( ADVADS_VERSION, '2.0.0', '>=' ) ) {
    247         if ( ! isset( $advads_halt_notices ) ) {
    248             $advads_halt_notices = [];
    249         }
    250         $advads_halt_notices[] = __( 'Advanced Ads – Google AdSense In-feed Placement', 'advanced-ads-adsense-in-feed' );
    251 
    252         add_action(
    253             'all_admin_notices',
    254             static function () {
    255                 global $advads_halt_notices;
    256 
    257                 // Early bail!!
    258                 if ( 'plugins' === get_current_screen()->base || empty( $advads_halt_notices ) ) {
    259                     return;
    260                 }
    261                 ?>
    262                 <div class="notice notice-error">
    263                     <h2><?php esc_html_e( 'Important Notice', 'advanced-ads-adsense-in-feed' ); ?></h2>
    264                     <p>
    265                         <?php
    266                         echo wp_kses_post(
    267                             sprintf(
    268                                 /* translators: %s: Plugin name */
    269                                 __( 'Your versions of the Advanced Ads addons listed below are incompatible with <strong>Advanced Ads 2.0</strong> and have been deactivated. Please update them to their latest version. If you cannot update, e.g., due to an expired license, you can <a href="%1$s">roll back to a compatible version of the Advanced Ads plugin</a> at any time or <a href="%2$s">renew your license</a>.', 'advanced-ads-adsense-in-feed' ),
    270                                 esc_url( admin_url( 'admin.php?page=advanced-ads-tools&sub_page=version' ) ),
    271                                 'https://wpadvancedads.com/account/#h-licenses'
    272                             )
    273                         )
    274                         ?>
    275                     </p>
    276                     <h3><?php esc_html_e( 'The following addons are affected:', 'advanced-ads-adsense-in-feed' ); ?></h3>
    277                     <ul>
    278                         <?php foreach ( $advads_halt_notices as $notice ) : ?>
    279                             <li><strong><?php echo esc_html( $notice ); ?></strong></li>
    280                         <?php endforeach; ?>
    281                     </ul>
    282                 </div>
    283                 <?php
    284                 $advads_halt_notices = [];
    285             }
    286         );
    287 
    288         add_action(
    289             'after_plugin_row_' . plugin_basename( __FILE__ ),
    290             static function () {
    291                 echo '<tr class="active"><td colspan="5" class="plugin-update colspanchange">';
    292                 wp_admin_notice(
    293                     sprintf(
    294                         /* translators: %s: Plugin name */
    295                         __( 'Your version of <strong>Advanced Ads – Google AdSense In-feed Placement</strong> is incompatible with <strong>Advanced Ads 2.0</strong> and has been deactivated. Please update the plugin to the latest version. If you cannot update the plugin, e.g., due to an expired license, you can <a href="%1$s">roll back to a compatible version of the Advanced Ads plugin</a> at any time or <a href="%2$s">renew your license</a>.', 'advanced-ads-pro' ),
    296                         esc_url( admin_url( 'admin.php?page=advanced-ads-tools&sub_page=version' ) ),
    297                         'https://wpadvancedads.com/account/#h-licenses'
    298                     ),
    299                     [
    300                         'type'               => 'error',
    301                         'additional_classes' => array( 'notice-alt', 'inline', 'update-message' ),
    302                     ]
    303                 );
    304                 echo '</td></tr>';
    305             }
    306         );
    307         return;
    308     }
    309 
    310     // Autoload and activate.
    311     new Advanced_Ads_In_Feed();
    312 }
    313 
    314 add_action( 'plugins_loaded', 'wp_advads_in_feed_halt_code', 5 );
     58\AdvancedAds\InFeed\Bootstrap::get()->start();
  • advanced-ads-adsense-in-feed/trunk/readme.txt

    r3243698 r3253296  
    22Contributors: advancedads, webzunft
    33Tags: adsense, in-feed, in-feed ads, ads, google adsense, loop, post list, post lists, archive pages, category pages, tag pages
    4 Requires at least: 5.0
     4Requires at least: 5.7
    55Tested up to: 6.7
    6 Stable tag: 1.1.4
     6Requires PHP: 7.4
     7Stable tag: 2.0.0
    78License: GPLv2 or later
    89License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1617Google AdSense InFeed ads are a dedicated Google AdSense ad type to monetize such post lists pages with a highly engaging layout and specialized options.
    1718
    18 Advanced Ads was developed to place, manage and test ads on pages to increase revenue and usability. 
     19Advanced Ads was developed to place, manage and test ads on pages to increase revenue and usability.
    1920
    20 The plugin comes with plenty of features, e.g., 
     21The plugin comes with plenty of features, e.g.,
    2122
    2223* Support for all Google AdSense types like link units, responsive, In-feed, In-article and matched content
     
    4243== Changelog ==
    4344
    44 = 1.1.4 =
    45 * Improvement: add compatibility code for Advanced Ads 2.0
     45= 2.0.0 =
     46- Feature: achieve full compatibility with Advanced Ads 2.0
     47- Improvement: enhance performance and efficiency with new codebase
    4648
    4749= 1.1.3 =
Note: See TracChangeset for help on using the changeset viewer.