Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<?php
/**
* Admin Ad List Table.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Admin;
use AdvancedAds\Abstracts\Ad;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Admin Ad List Table.
*/
class Ad_List_Table implements Integration_Interface {
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_filter( 'advanced-ads-ad-columns', [ $this, 'add_columns' ] );
add_action( 'advanced-ads-ad-render-columns', [ $this, 'render_columns' ], 10, 2 );
add_filter( 'default_hidden_columns', [ $this, 'set_hidden_columns' ], 10, 2 );
add_filter( 'advanced_ads_optional_filters', [ $this, 'add_optional_filters' ] );
}
/**
* Add columns to view.
*
* @param array $columns columns.
*
* @return array
*/
public function add_columns( array $columns ): array {
$columns['ad_displayonce'] = __( 'Display Once', 'advanced-ads-pro' );
return $columns;
}
/**
* Render columns.
*
* @param string $column column name.
* @param Ad $ad Ad instance.
*
* @return void
*/
public function render_columns( string $column, $ad ): void {
if ( 'ad_displayonce' === $column ) {
$display_once = $ad->get_prop( 'once_per_page' ) ?? false;
include AA_PRO_ABSPATH . 'views/admin/tables/ads/column-displayonce.php';
}
}
/**
* Hidden columns.
*
* @param array $hidden default hidden columns.
* @param WP_Screen $screen current screen.
*
* @return array|mixed
*/
public function set_hidden_columns( $hidden, $screen ) {
if ( isset( $screen->id ) && 'edit-advanced_ads' === $screen->id ) {
$hidden = array_merge( $hidden, [ 'ad_displayonce' ] );
}
return $hidden;
}
/**
* Adds an optional filter to the list of filters.
*
* @param array $optional_filters The array of optional filters.
*
* @return array
*/
public function add_optional_filters( $optional_filters ): array {
$optional_filters['all_displayonce'] = __( 'Display Once', 'advanced-ads-pro' );
return $optional_filters;
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* Backend helper for the AdSense fallback
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
*/
namespace AdvancedAds\Pro\Admin;
use AdvancedAds\Options;
use AdvancedAds\Abstracts\Ad;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
/**
* Backend class
*/
class Adsense implements Integration_Interface {
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_action( 'advanced-ads-gadsense-extra-ad-param', [ $this, 'ad_parameter_setting' ], 10, 3 );
add_action( 'advanced-ads-ad-pre-save', [ $this, 'save_ad_callback' ], 10, 2 );
add_action( 'admin_init', [ $this, 'add_setting_field' ] );
}
/**
* Add setting field on the AdSense tab of the settings page
*
* @return void
*/
public function add_setting_field() {
add_settings_field(
'adsense-fallback',
__( 'Fallback ad/group', 'advanced-ads-pro' ),
[ $this, 'render_adsense_tab_setting' ],
'advanced-ads-adsense-settings-page',
'advanced_ads_adsense_setting_section'
);
}
/**
* Save fallback option when saving the ad
*
* @param Ad $ad the ad.
* @param array $post_data content of $_POST (without the post content).
*
* @return void
*/
public function save_ad_callback( $ad, $post_data ) {
if ( empty( $post_data['adsense_fallback'] ) ) {
return;
}
preg_match( '/^none|default|ad_.+|group_.+|$/', $post_data['adsense_fallback'], $m );
if ( empty( $m[0] ) ) {
return;
}
$ad->set_prop( 'adsense_fallback', $m[0] );
}
/**
* Add fallback settings on the ad edit page
*
* @param array $params extra template parameters.
* @param string $content ad content.
* @param Ad $ad the ad.
*
* @return void
*/
public function ad_parameter_setting( $params, $content, $ad ) {
$this->render_fallback_setting( false, $ad );
}
/**
* Render setting field on the AdSense tab of the settings page
*
* @return void
*/
public function render_adsense_tab_setting() {
$this->render_fallback_setting( true );
}
/**
* Render the fallback setting markup
*
* @param bool $is_global whether it's the global fallback or not.
* @param Ad $ad the adsense ad.
*
* @return void
*/
public function render_fallback_setting( $is_global, $ad = null ) {
$global_fallback = \AdvancedAds\Pro\Adsense::get_global_fallback();
$global_fallback_object = \AdvancedAds\Pro\Adsense::get_global_fallback_object();
$fallback = $is_global ? $global_fallback : \AdvancedAds\Pro\Adsense::get_fallback( $ad );
$cache_busting = Options::instance()->get( 'pro.cache-busting' );
$items = self::get_fallback_items();
require_once AA_PRO_ABSPATH . 'views/admin/tables/ads/adsense-fallback.php';
}
/**
* List of available fallback ad or group for an unfilled AdSense ad
*
* @return array[]
*/
private static function get_fallback_items() {
static $result;
if ( null !== $result ) {
return $result;
}
$result = [
'ads' => [],
'groups' => [],
];
foreach ( wp_advads_get_all_ads() as $ad ) {
if ( ! $ad->is_type( 'adsense' ) && $ad->is_status( 'publish' ) ) {
$result['ads'][ $ad->get_id() ] = $ad;
}
}
foreach ( wp_advads_get_all_groups() as $group ) {
$result['groups'][ $group->get_id() ] = $group;
}
return $result;
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* Admin Duplicate Placement.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Admin;
use AdvancedAds\Constants;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
use AdvancedAds\Framework\Utilities\Params;
use AdvancedAds\Utilities\Conditional;
defined( 'ABSPATH' ) || exit;
/**
* Admin Duplicate Placement.
*/
class Duplicate_Placement implements Integration_Interface {
/**
* Admin action
*
* @var string
*/
private const ACTION = 'advanced_ads_duplicate_placement';
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_filter( 'post_row_actions', [ $this, 'action_link' ], 10, 2 );
add_action( 'admin_action_' . self::ACTION, [ $this, 'duplicate' ] );
}
/**
* Duplicate a placement
*
* @return void
*/
public function duplicate() {
// Early bail!!
$placement_id = Params::get( 'id', 0, FILTER_VALIDATE_INT );
if ( ! $placement_id ) {
return;
}
check_admin_referer( 'duplicate-placement-' . $placement_id );
if ( self::ACTION !== Params::get( 'action' ) || ! Conditional::user_cap( 'advanced_ads_manage_placements' ) ) {
return;
}
$placement = wp_advads_get_placement( $placement_id );
if ( ! $placement && wp_safe_redirect( admin_url( 'edit.php?post_type=advanced_ads_plcmnt' ) ) ) {
exit;
}
$copy_suffix = ' (' . _x( 'copy', 'noun', 'advanced-ads-pro' ) . ' at ' . current_time( 'Y-m-d H:i:s' ) . ')';
$new_placement = clone $placement;
$new_placement->set_id( null ); // reset the ID to save as a new placement.
$new_placement->set_title( $new_placement->get_title() . $copy_suffix );
$new_placement->set_item( '' );
$new_placement->set_prop( 'test_id', null );
$new_id = $new_placement->save();
if ( wp_safe_redirect( admin_url( 'edit.php?post_type=advanced_ads_plcmnt#modal-placement-edit-' . $new_id ) ) ) {
exit;
}
}
/**
* Add duplicate links on placement table
*
* @param array $actions existing actions.
* @param \WP_Post $post the post.
*
* @return array the modified actions list.
*/
public function action_link( $actions, $post ) {
if ( Constants::POST_TYPE_PLACEMENT !== $post->post_type || ! Conditional::user_cap( 'advanced_ads_manage_placements' ) ) {
return $actions;
}
$action = add_query_arg(
[
'action' => self::ACTION,
'id' => $post->ID,
],
admin_url( 'admin.php' )
);
$actions['duplicate-placement'] = sprintf(
'<a href="%s" title="%s">%s</a>',
wp_nonce_url( $action, 'duplicate-placement-' . $post->ID ),
esc_attr__( 'Create a copy of this placement', 'advanced-ads-pro' ),
esc_html__( 'Duplicate', 'advanced-ads-pro' )
);
return $actions;
}
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* Admin Groups Listing Page.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Admin;
use AdvancedAds\Constants;
use AdvancedAds\Abstracts\Group;
use AdvancedAds\Framework\Utilities\Params;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Duplicate Group.
*/
class Group_Duplication implements Integration_Interface {
private const DUPLICATE_ACTION_NAME = 'advanced_ads_duplicate_group';
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_filter( Constants::TAXONOMY_GROUP . '_row_actions', [ $this, 'render_row_actions' ], 10, 2 );
add_action( 'admin_action_' . self::DUPLICATE_ACTION_NAME, [ $this, 'duplicate_group' ] );
}
/**
* Renders the row actions for a group.
*
* @param array $actions An array of row actions.
* @param Group $group The group object.
*
* @return array The modified array of row actions.
*/
public function render_row_actions( $actions, $group ): array {
$actions = $this->render_duplicate_link( $actions, $group );
return $actions;
}
/**
* Renders the duplicate link for a group.
*
* This function checks if the current user has the permission to edit the group.
* If the user has the permission, it generates a duplicate link for the group.
* The link allows the user to create a copy of the group.
*
* @param array $actions An array of row actions for the group.
* @param Group $group The group object.
*
* @return array The updated array of actions with the duplicate link.
*/
public function render_duplicate_link( $actions, $group ): array {
if ( ! Group::can_current_user_edit_group() ) {
return $actions;
}
$action = add_query_arg(
[
'action' => self::DUPLICATE_ACTION_NAME,
'group_id' => $group->get_id(),
],
admin_url( 'admin.php' )
);
$actions['duplicate-group'] = sprintf(
'<a href="%s" title="%s">%s</a>',
wp_nonce_url( $action, 'duplicate-group-' . $group->get_id() ),
esc_attr__( 'Create a copy of this group', 'advanced-ads-pro' ),
esc_html__( 'Duplicate', 'advanced-ads-pro' )
);
return $actions;
}
/**
* Duplicate a group.
*
* This method duplicates a group by creating a copy of it with a "(copy)" suffix in the title.
* If the duplication is successful, the user is redirected to the edit page of the new group.
* If the duplication fails, the user is redirected to the groups listing page.
*
* @since 2.26.0
*/
public function duplicate_group(): void {
// Early bail!!
$group_id = Params::get( 'group_id', 0, FILTER_VALIDATE_INT );
if ( ! $group_id ) {
return;
}
check_admin_referer( 'duplicate-group-' . $group_id );
if (
self::DUPLICATE_ACTION_NAME !== Params::get( 'action' ) ||
! Group::can_current_user_edit_group()
) {
return;
}
$group = wp_advads_get_group( $group_id );
if ( ! $group && wp_safe_redirect( admin_url( 'admin.php?page=advanced-ads-groups' ) ) ) {
exit;
}
$copy_suffix = ' (' . _x( 'copy', 'noun', 'advanced-ads-pro' ) . ' at ' . current_time( 'Y-m-d H:i:s' ) . ')';
$new_group = clone $group;
$new_group->set_id( null ); // reset the ID to save as a new group.
$new_group->set_name( $new_group->get_name() . $copy_suffix );
$new_group_id = $new_group->save();
// Set the taxonomy relationships on the new object.
$ad_ids = get_objects_in_term( $group_id, Constants::TAXONOMY_GROUP );
foreach ( $ad_ids as $ad_id ) {
wp_set_object_terms( $ad_id, $new_group_id, Constants::TAXONOMY_GROUP, true );
}
if ( wp_safe_redirect( $new_group->get_edit_link() ) ) {
exit;
}
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Bulk edit for placements
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
*/
namespace AdvancedAds\Pro\Admin\Placements;
use AdvancedAds\Options;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Framework\Utilities\Params;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Placements Bulk Edit.
*/
class Bulk_Edit implements Integration_Interface {
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_action( 'advanced-ads-placement-bulk-edit-fields', [ $this, 'add_bulk_edit_fields' ] );
add_filter( 'advanced-ads-placement-bulk-edit-has-change', [ $this, 'bulk_edit_has_changes' ] );
add_filter( 'advanced-ads-placement-bulk-edit-save', [ $this, 'save_bulk_edit' ] );
}
/**
* Add the bulk edit inputs
*
* @return void
*/
public function add_bulk_edit_fields(): void {
include_once AA_PRO_ABSPATH . 'views/admin/placements/bulk-edit.php';
}
/**
* Check if bulk edit fields have changes.
*
* @param bool $has_change whether some ads have been changed.
*
* @return bool
*/
public function bulk_edit_has_changes( $has_change ): bool {
$cache_busting = Params::get( 'cache_busting' );
$lazy_loading = Params::get( 'lazy_loading' );
$cache_busting_empty = Params::get( 'cache_busting_empty' );
if ( ! empty( $cache_busting ) || ! empty( $lazy_loading ) || ! empty( $cache_busting_empty ) ) {
$has_change = true;
}
return $has_change;
}
/**
* Save changes made during bulk edit
*
* @param Placement $placement current placement being saved.
*
* @return Placement
*/
public function save_bulk_edit( $placement ): Placement {
$cache_busting = Params::get( 'cache_busting' );
$lazy_loading = Params::get( 'lazy_loading' );
$cache_busting_empty = Params::get( 'cache_busting_empty', false, FILTER_VALIDATE_BOOLEAN );
if ( ! empty( $cache_busting ) ) {
$placement->set_prop( 'cache-busting', $cache_busting );
}
if ( ! empty( $lazy_loading ) ) {
$placement->set_prop( 'lazy_load', $lazy_loading );
}
if ( ! empty( $cache_busting_empty ) ) {
$placement->set_prop( 'cache_busting_empty', 1 === $cache_busting_empty );
}
return $placement;
}
}

View File

@@ -0,0 +1,261 @@
<?php
/**
* Frontend helper for the AdSense fallback
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
*/
namespace AdvancedAds\Pro;
use AdvancedAds\Abstracts\Ad;
use AdvancedAds\Abstracts\Group;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
use AdvancedAds\Options;
/**
* Frontend class
*/
class Adsense implements Integration_Interface {
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
$cache_busting = Options::instance()->get( 'pro.cache-busting' );
// No CB, abort.
if ( empty( $cache_busting['enabled'] ) ) {
return;
}
add_filter( 'advanced-ads-cache-busting-item', [ $this, 'filter_cache_busting_item' ], 10, 2 );
add_filter( 'advanced-ads-pro-ad-needs-backend-request', [ $this, 'filter_cache_busting_method' ], 10, 2 );
add_filter( 'advanced-ads-output-wrapper-options', [ $this, 'filter_ad_wrapper_options' ], 10, 2 );
add_action( 'wp_loaded', [ $this, 'inline_script' ] );
}
/**
* Add inline JS variables
*
* @return void
*/
public function inline_script() {
wp_advads()->json->add(
[
'adHealthNotice' =>
[
'enabled' => \Advanced_Ads_Ad_Health_Notices::notices_enabled(),
'pattern' => sprintf(
/* translators: ad title. */
__( 'AdSense fallback was loaded for empty AdSense ad "%s"', 'advanced-ads-pro' ),
'[ad_title]'
),
],
]
);
}
/**
* Add CSS classes with data about AdSense fallback
*
* @param array $options wrapper options.
* @param Ad $ad the current ad being rendered.
*
* @return mixed
*/
public function filter_ad_wrapper_options( $options, $ad ) {
// Not AdSense, abort.
if ( ! $ad->is_type( 'adsense' ) ) {
return $options;
}
// No CB, abort.
$placement = $ad->get_root_placement();
if ( ! $placement || 'off' === $placement->get_prop( 'cache-busting' ) ) {
return $options;
}
$fallback = $this->get_practical_fallback( $ad );
// No fallback, abort.
if ( 'none' === $fallback ) {
return $options;
}
$options['class'] = [ 'gas_fallback-ad_' . $ad->get_id() . '-' . $fallback ];
return $options;
}
/**
* Add cache busting item data about fallbacks if needed
*
* @param array $item current item data.
* @param array $ad_arguments ad arguments and method.
*
* @return mixed
*/
public function filter_cache_busting_item( $item, $ad_arguments ) {
if ( empty( $ad_arguments['args']['item'] ) ) {
return $item;
}
$exploded_item = explode( '_', $ad_arguments['args']['item'] );
$placement_item = [
'type' => $exploded_item[0],
'id' => (int) $exploded_item[1],
];
// Works only on a placement with an AdSense ad for now (not on an AdSense ad within a group).
if ( 'ad' !== $placement_item['type'] ) {
return $item;
}
$ad = wp_advads_get_ad( $placement_item['id'] );
if ( ! $ad || ! $ad->is_type( 'adsense' ) ) {
return $item;
}
$fallback = $this->get_practical_fallback( $ad );
if ( ! $fallback || 'none' === $fallback ) {
return $item;
}
if ( empty( $placement_item['adsense_fallback'] ) || ! is_array( $placement_item['adsense_fallback'] ) ) {
$item['adsense_fallback'] = [];
}
$item['adsense_fallback'][ 'ad_' . $placement_item['id'] ] = $fallback;
$exploded = explode( '_', $fallback );
$fallback_object = 'ad' === $exploded[0]
? wp_advads_get_ad( (int) $exploded[1] )
: wp_advads_get_group( (int) $exploded[1] );
$item['ads'] += $this->collect_passive_ad_info( $fallback_object );
if ( is_a_group( $fallback_object ) ) {
$item['adsense_fallback_group_info'] = [
'id' => $fallback_object->get_id(),
'name' => $fallback_object->get_title(),
'weights' => $fallback_object->get_ad_weights(),
'type' => $fallback_object->get_type(),
'ordered_ad_ids' => $fallback_object->get_ordered_ad_ids(),
'ad_count' => $fallback_object->get_ad_count(),
];
}
return $item;
}
/**
* Collect passive cache busting info of all fallback ads.
*
* @param Ad|Group $fallback fallback obejct.
*
* @return array[]
*/
private function collect_passive_ad_info( $fallback ) {
$ads = [];
if ( is_an_ad( $fallback ) ) {
return [ $fallback->get_id() => \Advanced_Ads_Pro_Module_Cache_Busting::get_instance()->get_passive_cb_for_ad( $fallback ) ];
}
if ( is_a_group( $fallback ) ) {
foreach ( $fallback->get_ads() as $id => $ad ) {
$ads[ $id ] = \Advanced_Ads_Pro_Module_Cache_Busting::get_instance()->get_passive_cb_for_ad( $ad );
}
}
return $ads;
}
/**
* Force CB if the ad normally doesn't need CB
*
* @param string $method CB method.
* @param Ad $ad the ad.
*
* @return string
*/
public function filter_cache_busting_method( $method, $ad ) {
// "static" = NO CB. If it's not "static" no need to intervene or not AdSense, abort.
if ( 'static' !== $method || ! $ad->is_type( 'adsense' ) ) {
return $method;
}
// If still "static" and we have a fallback, force CB.
return $this->get_practical_fallback( $ad ) ? 'passive' : $method;
}
/**
* Get the actual fallback item for an AdSense ad (ad level if any otherwise return the site wide fallback)
*
* @param Ad $ad the current ad.
*
* @return false|string
*/
public function get_practical_fallback( $ad ) {
$ad_level_fallback = self::get_fallback( $ad );
if ( 'none' === $ad_level_fallback ) {
return false;
}
$global_fallback = self::get_global_fallback();
if ( 'default' === $ad_level_fallback ) {
return 'none' === $global_fallback ? false : $global_fallback;
}
return $ad_level_fallback;
}
/**
* Get the fallback CB item for a given AdSense ad
*
* @param Ad $ad the adsense ad.
*
* @return string
*/
public static function get_fallback( $ad ) {
$fallback = $ad->get_prop( 'adsense_fallback' );
return $fallback ?? 'default';
}
/**
* Get the site wide fallback CB item object
*
* @return Ad|Group|bool `false` if no global fallback found.
*/
public static function get_global_fallback_object() {
$item = self::get_global_fallback();
if ( ! $item || 'none' === $item ) {
return false;
}
$exploded_item = explode( '_', $item );
return 'ad' === $exploded_item[0]
? wp_advads_get_ad( (int) $exploded_item[1] )
: wp_advads_get_group( (int) $exploded_item[1] );
}
/**
* Get the global fallback item
*
* @return string
*/
public static function get_global_fallback() {
$fallback = Options::instance()->get( 'adsense.adsense_fallback' );
return $fallback ?? 'none';
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Assets manager handles the registration of stylesheets and scripts required for plugin functionality.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
*/
namespace AdvancedAds\Pro;
use AdvancedAds\Framework\Assets_Registry;
/**
* Pro's assets manager
*/
class Assets_Manager extends Assets_Registry {
/**
* Base URL for plugin local assets.
*
* @return string
*/
public function get_base_url(): string {
return AA_PRO_BASE_URL;
}
/**
* Prefix to use in handle to make it unique.
*
* @return string
*/
public function get_prefix(): string {
return AA_PRO_SLUG;
}
/**
* Version for plugin local assets.
*
* @return string
*/
public function get_version(): string {
return AAP_VERSION;
}
/**
* Register assets
*
* @return void
*/
public function register_assets(): void {
}
}

View File

@@ -0,0 +1,198 @@
<?php
/**
* The class is responsible for locating and loading the autoloader file used in the plugin.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro;
defined( 'ABSPATH' ) || exit;
/**
* Autoloader.
*/
class Autoloader {
/**
* Hold autoloader.
*
* @var mixed
*/
private $autoloader;
/**
* Main instance
*
* Ensure only one instance is loaded or can be loaded.
*
* @return Autoloader
*/
public static function get(): Autoloader {
static $instance;
if ( null === $instance ) {
$instance = new Autoloader();
}
return $instance;
}
/**
* Get hold autoloader.
*
* @return mixed
*/
public function get_autoloader() {
return $this->autoloader;
}
/**
* Get plugin directory.
*
* @return string
*/
public function get_directory(): string {
return dirname( AAP_FILE );
}
/**
* Runs this initializer.
*
* @return void
*/
public function initialize(): void {
$locate = $this->locate();
if ( ! $locate ) {
add_action( 'admin_notices', [ $this, 'missing_autoloader' ] );
return;
}
$this->autoloader = require $locate;
}
/**
* Locate the autoload file
*
* This function searches for the autoload file in the packages directory and vendor directory.
*
* @return bool|string
*/
private function locate() {
$directory = $this->get_directory();
$packages = $directory . '/packages/autoload.php';
$vendors = $directory . '/vendor/autoload.php';
$is_debug = $this->is_debug() || 'local' === $this->get_environment_type();
if ( is_readable( $packages ) && ( ! $is_debug || ! is_readable( $vendors ) ) ) {
return $packages;
}
if ( is_readable( $vendors ) ) {
return $vendors;
}
return false;
}
/**
* If the autoloader is missing, add an admin notice.
*
* @return void
*/
protected function missing_autoloader(): void {
?>
<div class="notice notice-error">
<p>
<?php
printf(
/* translators: 1: is a link to a support document. 2: closing link */
esc_html__( 'Your installation of Advanced Ads is incomplete. If you installed Advanced Ads from GitHub, %1$s please refer to this document%2$s to set up your development environment.', 'advanced-ads-pro' ),
'<a href="' . esc_url( 'https://github.com/advanced-ads/advanced-ads/wiki/How-to-set-up-development-environment' ) . '" target="_blank" rel="noopener noreferrer">',
'</a>'
);
?>
</p>
</div>
<?php
}
/**
* Retrieves the current environment type.
*
* @return string
*/
public function get_environment_type(): string {
return function_exists( 'wp_get_environment_type' )
? wp_get_environment_type()
: $this->get_environment_type_fallback();
}
/**
* Retrieves the current environment type.
*
* @return string
*/
private function get_environment_type_fallback(): string {
static $current_env = '';
if ( ! defined( 'WP_RUN_CORE_TESTS' ) && $current_env ) {
return $current_env;
}
$wp_environments = [
'local',
'development',
'staging',
'production',
];
// Add a note about the deprecated WP_ENVIRONMENT_TYPES constant.
if ( defined( 'WP_ENVIRONMENT_TYPES' ) && function_exists( '_deprecated_argument' ) ) {
if ( function_exists( '__' ) ) {
/* translators: %s: WP_ENVIRONMENT_TYPES */
$message = sprintf( __( 'The %s constant is no longer supported.', 'advanced-ads-pro' ), 'WP_ENVIRONMENT_TYPES' );
} else {
$message = sprintf( 'The %s constant is no longer supported.', 'WP_ENVIRONMENT_TYPES' );
}
_deprecated_argument(
'define()',
'5.5.1',
$message // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
// Check if the environment variable has been set, if `getenv` is available on the system.
if ( function_exists( 'getenv' ) ) {
$has_env = getenv( 'WP_ENVIRONMENT_TYPE' );
if ( false !== $has_env ) {
$current_env = $has_env;
}
}
// Fetch the environment from a constant, this overrides the global system variable.
if ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE ) {
$current_env = WP_ENVIRONMENT_TYPE;
}
// Make sure the environment is an allowed one, and not accidentally set to an invalid value.
if ( ! in_array( $current_env, $wp_environments, true ) ) {
$current_env = 'production';
}
return $current_env;
}
/**
* Is WordPress debug mode enabled
*
* @return bool
*/
private function is_debug(): bool {
return defined( 'WP_DEBUG' ) && WP_DEBUG;
}
}

View File

@@ -0,0 +1,243 @@
<?php
/**
* Bootstrap.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro;
defined( 'ABSPATH' ) || exit;
/**
* Bootstrap.
*/
class Bootstrap {
/**
* Whether the plugin has been started.
*
* @var bool
*/
private $done = false;
/**
* Get singleton instance.
*
* @return Bootstrap
*/
public static function get() {
static $instance = null;
if ( null === $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Start the plugin.
*
* @return void
*/
public function start(): void {
// Early bail!!
if ( $this->done ) {
return;
}
add_action( 'plugins_loaded', [ $this, 'halt_code' ], -10 );
$this->done = true;
}
/**
* Halt code for new release.
*
* @return void
*/
public function halt_code(): void {
global $advads_halt_notices;
if ( ! isset( $advads_halt_notices ) ) {
$advads_halt_notices = [];
}
// Early bail!!
if ( ! defined( 'ADVADS_VERSION' ) ) {
$advads_halt_notices[] = __( 'Advanced Ads - Pro', 'advanced-ads-pro' );
add_action( 'all_admin_notices', [ $this, 'print_missing_notices' ] );
add_action( 'after_plugin_row_' . plugin_basename( AAP_FILE ), [ $this, 'missing_row' ] );
return;
}
if ( version_compare( ADVADS_VERSION, '2.0.0', '<' ) ) {
$advads_halt_notices[] = __( 'Advanced Ads - Pro', 'advanced-ads-pro' );
add_action( 'all_admin_notices', [ $this, 'print_halt_notices' ] );
add_action( 'after_plugin_row_' . plugin_basename( AAP_FILE ), [ $this, 'compatible_row' ] );
return;
}
// Start it.
add_action( 'advanced-ads-loaded', 'wp_advads_pro' );
}
/**
* Display missing notice row.
*
* @return void
*/
public function missing_row(): void {
$this->print_row(
__( '<strong>Advanced Ads - Pro</strong> requires the <strong>Advanced Ads free</strong> plugin to be installed and activated on your site.', 'advanced-ads-pro' )
. '&nbsp;' . $this->get_button( 'button-link' )
);
}
/**
* Display compatible notice row.
*
* @return void
*/
public function compatible_row(): void {
$this->print_row(
sprintf(
/* translators: %s: Plugin name */
__( 'Your version of <strong>Advanced Ads - Pro</strong> is incompatible with <strong>Advanced Ads %s</strong> and has been deactivated. Please update the plugin to the latest version.', 'advanced-ads-pro' ),
ADVADS_VERSION
)
);
}
/**
* Display missing notices.
*
* @return void
*/
public function print_missing_notices(): void {
global $advads_halt_notices;
// Early bail!!
if ( 'plugins' === get_current_screen()->base || empty( $advads_halt_notices ) ) {
return;
}
$this->print_notices(
__( 'Important Notice', 'advanced-ads-pro' ),
__( 'Addons listed below requires the <strong><a href="https://wpadvancedads.com/?utm_source=advanced-ads&utm_medium=link&utm_campaign=activate-advanced-ads-pro" target="_blank">Advanced Ads</a></strong> plugin to be installed and activated on your site.', 'advanced-ads-pro' )
. '&nbsp;' . $this->get_button(),
$advads_halt_notices
);
$advads_halt_notices = [];
}
/**
* Display halt notices.
*
* @return void
*/
public function print_halt_notices(): void {
global $advads_halt_notices;
// Early bail!!
if ( 'plugins' === get_current_screen()->base || empty( $advads_halt_notices ) ) {
return;
}
$this->print_notices(
__( 'Important Notice', 'advanced-ads-pro' ),
sprintf(
/* translators: %s: Plugin name */
__( 'Your versions of the Advanced Ads addons listed below are incompatible with <strong>Advanced Ads %s</strong> and have been deactivated. Please update the plugin to the latest version.', 'advanced-ads-pro' ),
ADVADS_VERSION
),
$advads_halt_notices
);
$advads_halt_notices = [];
}
/**
* Display notices.
*
* @param string $title Title.
* @param string $description Description.
* @param array $notices Notices.
*
* @return void
*/
private function print_notices( $title, $description, $notices ): void {
?>
<div class="notice notice-error">
<h2><?php echo esc_html( $title ); ?></h2>
<p>
<?php echo wp_kses_post( $description ); ?>
</p>
<h3><?php esc_html_e( 'The following addons are affected:', 'advanced-ads-pro' ); ?></h3>
<ul>
<?php foreach ( $notices as $notice ) : ?>
<li><strong><?php echo esc_html( $notice ); ?></strong></li>
<?php endforeach; ?>
</ul>
</div>
<?php
}
/**
* Print row.
*
* @param string $message Message to print.
*
* @return void
*/
private function print_row( $message ): void {
?>
<tr class="active">
<td colspan="5" class="plugin-update colspanchange">
<div class="notice notice-error notice-alt inline update-message">
<p>
<?php echo wp_kses_post( $message ); ?>
</p>
</div>
</td>
</tr>
<?php
}
/**
* Get button.
*
* @param string $type Button type.
*
* @return string
*/
private function get_button( $type = 'button-primary' ): string {
$plugins = get_plugins();
$link = wp_nonce_url(
self_admin_url( 'update.php?action=install-plugin&plugin=advanced-ads' ),
'install-plugin_advanced-ads'
);
$text = __( 'Install Now', 'advanced-ads-pro' );
// Check if Advanced Ads is already installed.
if ( isset( $plugins['advanced-ads/advanced-ads.php'] ) ) {
$link = wp_nonce_url(
self_admin_url( 'plugins.php?action=activate&plugin=advanced-ads/advanced-ads.php' ),
'activate-plugin_advanced-ads/advanced-ads.php'
);
$text = __( 'Activate Now', 'advanced-ads-pro' );
}
return sprintf(
'<a class="button %s" href="%s">%s</a>',
$type,
$link,
$text
);
}
}

View File

@@ -0,0 +1,165 @@
<?php
/**
* The plugin bootstrap.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro;
use Advanced_Ads_Pro;
use AdvancedAds\Pro\Admin;
use AdvancedAds\Framework\Loader;
use AdvancedAds\Pro\Placements\Placement_Types;
defined( 'ABSPATH' ) || exit;
/**
* Plugin.
*/
class Plugin extends Loader {
/**
* Main instance
*
* Ensure only one instance is loaded or can be loaded.
*
* @return Plugin
*/
public static function get(): Plugin {
static $instance;
if ( null === $instance ) {
$instance = new Plugin();
$instance->setup();
}
return $instance;
}
/**
* Get plugin version
*
* @return string
*/
public function get_version(): string {
return AAP_VERSION;
}
/**
* Bootstrap plugin.
*
* @return void
*/
private function setup(): void {
$this->define_constants();
$this->includes();
$this->includes_admin();
/**
* Old loading strategy
*
* TODO: need to remove it in future.
*/
Advanced_Ads_Pro::get_instance();
add_action( 'init', [ $this, 'load_textdomain' ] );
$this->load();
}
/**
* Define Advanced Ads constant
*
* @return void
*/
private function define_constants(): void {
$this->define( 'AA_PRO_ABSPATH', dirname( AAP_FILE ) . '/' );
$this->define( 'AA_PRO_BASENAME', plugin_basename( AAP_FILE ) );
$this->define( 'AA_PRO_BASE_URL', plugin_dir_url( AAP_FILE ) );
$this->define( 'AA_PRO_SLUG', 'advanced-ads-pro' );
// Deprecated Constants.
/**
* AAP_PATH
*
* @deprecated 2.26.0 use AA_PRO_ABSPATH now.
*/
define( 'AAP_PATH', AA_PRO_ABSPATH );
/**
* AAP_BASE_PATH
*
* @deprecated 2.26.0 use AA_PRO_ABSPATH now.
*/
define( 'AAP_BASE_PATH', AA_PRO_ABSPATH );
/**
* AAP_BASE
*
* @deprecated 2.26.0 use AA_PRO_BASENAME now.
*/
define( 'AAP_BASE', AA_PRO_BASENAME );
/**
* AAP_BASE_URL
*
* @deprecated 2.26.0 use AA_PRO_BASE_URL now.
*/
define( 'AAP_BASE_URL', AA_PRO_BASE_URL );
/**
* AAP_SLUG
*
* @deprecated 2.26.0 use AA_PRO_SLUG now.
*/
define( 'AAP_SLUG', AA_PRO_SLUG );
}
/**
* Load the plugin text domain for translation.
*
* @return void
*/
public function load_textdomain(): void {
$locale = apply_filters( 'plugin_locale', determine_locale(), 'advanced-ads-pro' );
unload_textdomain( 'advanced-ads-pro' );
if ( false === load_textdomain( 'advanced-ads-pro', WP_LANG_DIR . '/plugins/advanced-ads-pro-' . $locale . '.mo' ) ) {
load_textdomain( 'advanced-ads-pro', WP_LANG_DIR . '/advanced-ads-pro/advanced-ads-pro-' . $locale . '.mo' );
}
load_plugin_textdomain( 'advanced-ads-pro', false, dirname( AA_PRO_BASENAME ) . '/languages' );
}
/**
* Includes core files used in admin and on the frontend.
*
* @return void
*/
private function includes(): void {
$this->register_integration( Adsense::class );
$this->register_integration( Assets_Manager::class, 'registry' );
$this->register_integration( Placement_Types::class );
}
/**
* Includes the necessary files for the admin section of the plugin.
*
* @return void
*/
private function includes_admin(): void {
// Early bail!!
if ( ! is_admin() ) {
return;
}
$this->register_initializer( Upgrades::class, 'upgrades' );
$this->register_integration( Admin\Adsense::class );
$this->register_integration( Admin\Ad_List_Table::class );
$this->register_integration( Admin\Group_Duplication::class );
$this->register_integration( Admin\Duplicate_Placement::class );
$this->register_integration( Admin\Placements\Bulk_Edit::class );
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* Upgrades.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro;
use AdvancedAds\Framework\Updates;
use AdvancedAds\Framework\Interfaces\Initializer_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Upgrades.
*/
class Upgrades extends Updates implements Initializer_Interface {
const DB_VERSION = '1.1';
/**
* Get updates that need to run.
*
* @since 2.26.0
*
* @return array
*/
public function get_updates(): array {
return [
'1.1' => 'upgrade-1-1.php',
];
}
/**
* Get folder path
*
* @since 2.26.0
*
* @return string
*/
public function get_folder(): string {
return AA_PRO_ABSPATH . 'upgrades/';
}
/**
* Get plugin version number
*
* @since 2.26.0
*
* @return string
*/
public function get_version(): string {
return self::DB_VERSION;
}
/**
* Get plugin option name.
*
* @since 2.26.0
*
* @return string
*/
public function get_option_name(): string {
return 'advanced_ads_pro_db_version';
}
/**
* Runs this initializer.
*
* @since 2.26.0
*
* @return void
*/
public function initialize(): void {
// Force run the upgrades.
$is_first_time = empty( $this->get_installed_version() );
$this->hooks();
if ( $is_first_time ) {
update_option( $this->get_option_name(), '1.0.0' );
add_action( 'admin_init', [ $this, 'perform_updates' ] );
}
}
}

View File

@@ -0,0 +1,4 @@
<?php
/**
* Silence is golden.
*/

View File

@@ -0,0 +1,190 @@
<?php
/**
* The class provides plugin installation routines.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Installation;
use Advanced_Ads_Pro;
defined( 'ABSPATH' ) || exit;
/**
* Install.
*/
class Install {
/**
* Runs this initializer.
*
* @return void
*/
public function initialize(): void {
if ( null !== AAP_FILE ) {
register_activation_hook( AAP_FILE, [ $this, 'activation' ] );
register_deactivation_hook( AAP_FILE, [ $this, 'deactivation' ] );
add_action( 'wp_initialize_site', [ $this, 'initialize_site' ] );
}
}
/**
* Activation routine.
*
* @param bool $network_wide Whether the plugin is being activated network-wide.
*
* @return void
*/
public function activation( $network_wide = false ): void {
register_uninstall_hook( AAP_FILE, [ static::class, 'uninstall' ] );
if ( ! is_multisite() || ! $network_wide ) {
$this->activate();
return;
}
$this->network_activate_deactivate( 'activate' );
}
/**
* Deactivation routine.
*
* @param bool $network_wide Whether the plugin is being activated network-wide.
*
* @return void
*/
public function deactivation( $network_wide = false ): void {
if ( ! is_multisite() || ! $network_wide ) {
$this->deactivate();
return;
}
$this->network_activate_deactivate( 'deactivate' );
}
/**
* Fired when a new site is activated with a WPMU environment.
*
* @param WP_Site $site The new site's object.
*
* @return void
*/
public function initialize_site( $site ): void {
switch_to_blog( $site->blog_id );
$this->activate();
restore_current_blog();
}
/**
* Run network-wide activation/deactivation of the plugin.
*
* @param string $action Action to perform.
*
* @return void
*/
private function network_activate_deactivate( $action ): void {
global $wpdb;
$site_ids = self::get_sites();
if ( empty( $site_ids ) ) {
return;
}
foreach ( $site_ids as $site_id ) {
switch_to_blog( $site_id );
$this->$action();
restore_current_blog();
}
}
/**
* Get network sites
*
* @return array|int
*/
public static function get_sites() {
global $wpdb;
return get_sites(
[
'archived' => 0,
'spam' => 0,
'deleted' => 0,
'network_id' => $wpdb->siteid,
'fields' => 'ids',
]
);
}
/**
* Plugin activation callback.
*
* @return void
*/
protected function activate(): void {
add_role(
'advanced_ads_admin',
__( 'Ad Admin', 'advanced-ads-pro' ),
[
'read' => true,
'advanced_ads_manage_options' => true,
'advanced_ads_see_interface' => true,
'advanced_ads_edit_ads' => true,
'advanced_ads_manage_placements' => true,
'advanced_ads_place_ads' => true,
'upload_files' => true,
'unfiltered_html' => true,
]
);
add_role(
'advanced_ads_manager',
__( 'Ad Manager', 'advanced-ads-pro' ),
[
'read' => true,
'advanced_ads_see_interface' => true,
'advanced_ads_edit_ads' => true,
'advanced_ads_manage_placements' => true,
'advanced_ads_place_ads' => true,
'upload_files' => true,
'unfiltered_html' => true,
]
);
add_role(
'advanced_ads_user',
__( 'Ad User', 'advanced-ads-pro' ),
[
'read' => true,
'advanced_ads_place_ads' => true,
]
);
Advanced_Ads_Pro::get_instance()
->enable_placement_test_emails();
}
/**
* Plugin deactivation callback.
*
* @return void
*/
protected function deactivate(): void {
remove_role( 'advanced_ads_admin' );
remove_role( 'advanced_ads_manager' );
remove_role( 'advanced_ads_user' );
Advanced_Ads_Pro::get_instance()
->disable_placement_test_emails();
}
/**
* Plugin uninstall callback.
*
* @return void
*/
public static function uninstall(): void {}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "Above Headline" placement
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Above Headline.
*/
class Placement_Above_Headline extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "Archive Pages" placement
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Archive Pages.
*/
class Placement_Archive_Page extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "Background Ad" placement.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Background Ad.
*/
class Placement_Background_Ad extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "BuddyPress" & "BuddyBoss" Comment placement
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Placements Placement Bbpress Comment.
*/
class Placement_Bbpress_Comment extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "BuddyPress" & "BuddyBoss" Static placement
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Placements Placement Bbpress Static.
*/
class Placement_Bbpress_Static extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "BuddyPress" & "BuddyBoss" placement
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Placements Placement Buddypress.
*/
class Placement_Buddypress extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "Post Content Middle" placement
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Post Content Middle.
*/
class Placement_Content_Middle extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "Post Content Random" placement
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Post Content Random.
*/
class Placement_Content_Random extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "Post Custom Position" placement
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Post Custom Position.
*/
class Placement_Custom_Position extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* This class represents the "Server" placement
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Interfaces\Placement_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Server.
*/
class Placement_Server extends Placement implements Placement_Interface {
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* Placements type manager
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements;
use Advanced_Ads_Pro;
use AdvancedAds\Pro\Placements\Types;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Placements Placement Types.
*/
class Placement_Types implements Integration_Interface {
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_action( 'advanced-ads-placement-types-manager', [ $this, 'add_pro_placements' ] );
}
/**
* Add pro placement to list of placements
*
* @since 2.26.0
*
* @param Types $manager Placement types manager.
*
* @return void
*/
public function add_pro_placements( $manager ) {
$manager->register_type( Types\Above_Headline::class );
$manager->register_type( Types\Archive_Pages::class );
$manager->register_type( Types\Content_Middle::class );
$manager->register_type( Types\Content_Random::class );
$manager->register_type( Types\Custom_Position::class );
$manager->register_type( Types\Background_Ad::class );
$options = Advanced_Ads_Pro::get_instance()->get_options();
if ( ! empty( $options['ad-server']['enabled'] ) ) {
$manager->register_type( Types\Server::class );
}
if ( class_exists( 'bbPress', false ) ) {
$manager->register_type( Types\Bbpress_Static::class );
$manager->register_type( Types\Bbpress_Comment::class );
}
if ( class_exists( 'BuddyPress', false ) ) {
$manager->register_type( Types\Buddypress::class );
}
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* Placements Types Above Headline.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
use Advanced_Ads_Pro;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Abstracts\Placement_Type as Base;
use AdvancedAds\Pro\Placements\Placement_Above_Headline;
defined( 'ABSPATH' ) || exit;
/**
* Placements Types Above Headline.
*/
class Above_Headline extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'post_above_headline';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Above_Headline::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
return __( 'Above Headline', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
return __( 'Above the main headline on the page (&lt;h1&gt;).', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
return AA_PRO_BASE_URL . 'modules/inject-content/assets/img/content-above-headline.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 90;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options(
[
'show_position' => true,
'uses_the_content' => true,
'show_lazy_load' => 'php' === Advanced_Ads_Pro::get_instance()->get_options()['placement-positioning'],
]
);
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* Placements Types Archive Pages.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Abstracts\Placement_Type as Base;
use AdvancedAds\Pro\Placements\Placement_Archive_Page;
defined( 'ABSPATH' ) || exit;
/**
* Placements Types Archive Pages.
*/
class Archive_Pages extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'archive_pages';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Archive_Page::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
return __( 'Post Lists', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
return __( 'Display the ad between posts on post lists, e.g. home, archives, search etc.', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
return AA_PRO_BASE_URL . 'modules/inject-content/assets/img/post-list.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 105;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options(
[
'show_position' => true,
'show_lazy_load' => true,
]
);
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* Placements Types Background Ad.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Abstracts\Placement_Type as Base;
use AdvancedAds\Pro\Placements\Placement_Background_Ad;
defined( 'ABSPATH' ) || exit;
/**
* Placements Types Background Ad.
*/
class Background_Ad extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'background';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Background_Ad::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
return __( 'Background Ad', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
return __( 'Background of the website behind the main wrapper.', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
return AA_PRO_BASE_URL . 'modules/background-ads/assets/img/background.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 80;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options(
[
'allowed_ad_types' => [ 'image', 'plain' ],
]
);
}
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* Placements Types Bbpress Comment.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Abstracts\Placement_Type as Base;
use AdvancedAds\Pro\Placements\Placement_Bbpress_Comment;
defined( 'ABSPATH' ) || exit;
/**
* Bbpress Comment.
*/
class Bbpress_Comment extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'bbPress comment';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Bbpress_Comment::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
return __( 'bbPress Reply Content', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
return __( 'Display ads in bbPress replies.', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
return AA_PRO_BASE_URL . 'modules/bbpress/assets/img/bbpress-reply.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 33;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options( [] );
}
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* Placements Types Bbpress Static.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Abstracts\Placement_Type as Base;
use AdvancedAds\Pro\Placements\Placement_Bbpress_Static;
defined( 'ABSPATH' ) || exit;
/**
* Bbpress Static.
*/
class Bbpress_Static extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'bbPress static';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Bbpress_Static::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
return __( 'bbPress Static Content', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
return __( 'Display ads on bbPress related pages.', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
return AA_PRO_BASE_URL . 'modules/bbpress/assets/img/bbpress-static.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 32;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options( [] );
}
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* Placements Types Buddypress.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Abstracts\Placement_Type as Base;
use AdvancedAds\Pro\Modules\BuddyPress\BuddyPress as BuddyPress_Main;
use AdvancedAds\Pro\Placements\Placement_Buddypress;
defined( 'ABSPATH' ) || exit;
/**
* Buddypress.
*/
class Buddypress extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'buddypress';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Buddypress::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
if ( BuddyPress_Main::is_buddyboss() ) {
return __( 'BuddyBoss Content', 'advanced-ads-pro' );
}
return __( 'BuddyPress Content', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
if ( BuddyPress_Main::is_buddyboss() ) {
return __( 'Display ads on BuddyBoss related pages.', 'advanced-ads-pro' );
}
return __( 'Display ads on BuddyPress related pages.', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
if ( BuddyPress_Main::is_buddyboss() ) {
return AA_PRO_BASE_URL . 'modules/buddypress/assets/img/buddyboss.png';
}
return AA_PRO_BASE_URL . 'modules/buddypress/assets/img/buddypress-icon.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 31;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options( [ 'placement-display-conditions' => [ 'request_uri', 'buddypress_group' ] ] );
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* Placements Types Content Middle.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Abstracts\Placement_Type as Base;
use AdvancedAds\Pro\Placements\Placement_Content_Middle;
defined( 'ABSPATH' ) || exit;
/**
* Placements Types Content Middle.
*/
class Content_Middle extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'post_content_middle';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Content_Middle::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
return __( 'Content Middle', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
return __( 'In the middle of the main content based on the number of paragraphs.', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
return AA_PRO_BASE_URL . 'modules/inject-content/assets/img/content-middle.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 95;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options(
[
'show_position' => true,
'uses_the_content' => true,
'amp' => true,
]
);
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* Placements Types Content Random.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Abstracts\Placement_Type as Base;
use AdvancedAds\Pro\Placements\Placement_Content_Random;
defined( 'ABSPATH' ) || exit;
/**
* Placements Types Content Random.
*/
class Content_Random extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'post_content_random';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Content_Random::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
return __( 'Random Paragraph', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
return __( 'After a random paragraph in the main content.', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
return AA_PRO_BASE_URL . 'modules/inject-content/assets/img/content-random.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 85;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options(
[
'show_position' => true,
'uses_the_content' => true,
'amp' => true,
]
);
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* Placements Types Custom Position.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
use Advanced_Ads_Pro;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Abstracts\Placement_Type as Base;
use AdvancedAds\Pro\Placements\Placement_Custom_Position;
defined( 'ABSPATH' ) || exit;
/**
* Placements Types Custom Position.
*/
class Custom_Position extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'custom_position';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Custom_Position::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
return __( 'Custom Position', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
return __( 'Attach the ad to any element in the frontend.', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
return AA_PRO_BASE_URL . 'modules/inject-content/assets/img/custom-position.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 100;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options(
[
'show_position' => true ,
'show_lazy_load' => 'php' === Advanced_Ads_Pro::get_instance()->get_options()['placement-positioning'],
]
);
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* Placements Types Server.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
namespace AdvancedAds\Pro\Placements\Types;
defined( 'ABSPATH' ) || exit;
use AdvancedAds\Interfaces\Placement_Type;
use AdvancedAds\Pro\Placements\Placement_Server;
use AdvancedAds\Abstracts\Placement_Type as Base;
/**
* Placements Types Server.
*/
class Server extends Base implements Placement_Type {
/**
* Get the unique identifier (ID) of the placement type.
*
* @return string The unique ID of the placement type.
*/
public function get_id(): string {
return 'server';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Placement_Server::class;
}
/**
* Get the title or name of the placement type.
*
* @return string The title of the placement type.
*/
public function get_title(): string {
return __( 'Ad Server', 'advanced-ads-pro' );
}
/**
* Get a description of the placement type.
*
* @return string The description of the placement type.
*/
public function get_description(): string {
return __( 'Display ads on external websites.', 'advanced-ads-pro' );
}
/**
* Check if this placement type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return false;
}
/**
* Get the URL for upgrading to this placement type.
*
* @return string The upgrade URL for the placement type.
*/
public function get_image(): string {
return AA_PRO_BASE_URL . 'modules/ad-server/assets/img/server.png';
}
/**
* Get order number for this placement type.
*
* @return int The order number.
*/
public function get_order(): int {
return 110;
}
/**
* Get options for this placement type.
*
* @return array The options array.
*/
public function get_options(): array {
return $this->apply_filter_on_options(
[
'placement-cache-busting' => false,
'placement-display-conditions' => false,
'placement-visitor-conditions' => false,
'placement-item-alternative' => false,
'placement-tests' => false,
]
);
}
}