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,124 @@
<?php
/**
* Manage group and ad relationship.
*
* @since 2.0.7
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
*/
namespace AdvancedAds\Groups;
use AdvancedAds\Constants;
use AdvancedAds\Abstracts\Group;
defined( 'ABSPATH' ) || exit;
/**
* Group ad relation class.
*/
class Group_Ad_Relation {
/**
* Hold ads.
*
* @var array
*/
private $ads = [];
/**
* Create ad group relation.
*
* @param Group $group Group object.
*
* @return void
*/
public function relate( &$group ): void {
$data = $group->get_data();
$changes = $group->get_changes();
$old_ads = $data['ad_weights'] ? array_keys( $data['ad_weights'] ) : [];
$new_ads = $changes['ad_weights'] ? array_keys( $changes['ad_weights'] ) : [];
$removed_ads = array_diff( $old_ads, $new_ads );
$added_ads = array_diff( $new_ads, $old_ads );
$this->handle_removed_ads( $removed_ads, $group->get_id() );
$this->handle_added_ads( $added_ads, $group );
}
/**
* Handles the removed ads for a group.
*
* @param array $removed_ads An array of ad IDs that have been removed.
* @param int $group_id The ID of the group.
*
* @return void
*/
private function handle_removed_ads( $removed_ads, $group_id ): void {
foreach ( $removed_ads as $ad_id ) {
$terms = wp_get_object_terms( $ad_id, Constants::TAXONOMY_GROUP );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term_ids = wp_list_pluck( $terms, 'term_id' );
$term_ids = array_diff( $term_ids, [ $group_id ] );
wp_set_object_terms( $ad_id, $term_ids, Constants::TAXONOMY_GROUP );
update_post_meta( $ad_id, Constants::AD_META_GROUP_IDS, $term_ids );
}
}
}
/**
* Handles the added ads for a group.
*
* @param array $added_ads An array of ad IDs that have been added.
* @param Group $group Group instance.
*
* @return void
*/
private function handle_added_ads( $added_ads, &$group ): void {
$changes = $group->get_changes();
$new_ads_final = $changes['ad_weights'] ?? [];
$new_ads = $changes['ad_weights'] ? array_keys( $changes['ad_weights'] ) : [];
foreach ( $new_ads as $ad_id ) {
/**
* Check if this ad is representing the current group and remove it in this case
* could cause an infinite loop otherwise
*/
if ( $this->is_ad_type_group( $ad_id, $group ) ) {
unset( $new_ads_final[ $ad_id ] );
continue;
}
$terms = wp_get_object_terms( $ad_id, Constants::TAXONOMY_GROUP );
if ( ! is_wp_error( $terms ) ) {
$term_ids = wp_list_pluck( $terms, 'term_id' );
$term_ids[] = $group->get_id();
$term_ids = array_unique( $term_ids );
wp_set_object_terms( $ad_id, $term_ids, Constants::TAXONOMY_GROUP );
update_post_meta( $ad_id, Constants::AD_META_GROUP_IDS, $term_ids );
}
}
$group->set_ad_weights( $new_ads_final );
}
/**
* Check if ad is of type 'group' and belongs to the current group.
*
* @param int $ad_id Ad id.
* @param Group $group Group instance.
*
* @return bool
*/
private function is_ad_type_group( int $ad_id, Group $group ): bool {
if ( ! isset( $this->ads[ $ad_id ] ) ) {
$this->ads[ $ad_id ] = wp_advads_get_ad( $ad_id );
}
$ad = $this->ads[ $ad_id ];
return $ad && $ad->is_type( 'group' ) && $ad->get_group_id() === $group->get_id();
}
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* The group Factory.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.48.0
*/
namespace AdvancedAds\Groups;
use WP_Term;
use Exception;
use AdvancedAds\Abstracts\Group;
use AdvancedAds\Abstracts\Factory;
defined( 'ABSPATH' ) || exit;
/**
* Groups Factory.
*/
class Group_Factory extends Factory {
/**
* Create an empty group object
*
* @param string $type Type of group to create.
*
* @return Group|bool Group object or false if the group type not found.
*/
public function create_group( $type = 'default' ) {
$group_type = wp_advads_get_group_type( $type );
if ( ! $group_type ) {
return false;
}
$classname = $group_type->get_classname();
// Create group.
$group = new $classname( 0 );
$group->set_type( $group_type->get_id() );
return $group;
}
/**
* Get the group object.
*
* @param Group|WP_Term|int|bool $group_id Group instance, term instance or numeric.
* @param string $new_type Change type of group.
*
* @return Group|bool Group object or false if the group cannot be loaded.
*/
public function get_group( $group_id, $new_type = '' ) {
$group_id = $this->get_group_id( $group_id );
if ( ! $group_id ) {
return false;
}
$group_type = '' !== $new_type ? $new_type : $this->get_group_type( $group_id );
$classname = $this->get_classname( wp_advads_get_group_type_manager(), $group_type );
try {
return new $classname( $group_id );
} catch ( Exception $e ) {
return false;
}
return new Group_Standard();
}
/**
* Get the type of the group.
*
* @param int $group_id Group ID.
*
* @return string The type of the group.
*/
private function get_group_type( $group_id ): string {
// Allow the overriding of the lookup in this function. Return the group type here.
$override = apply_filters( 'advanced-ads-group-type', false, $group_id );
if ( $override ) {
return $override;
}
$type = get_term_meta( $group_id, Group_Repository::TYPE_METAKEY, true );
if ( empty( $type ) ) {
$options = get_option( 'advads-ad-groups', [] );
$type = $options[ $group_id ]['type'] ?? 'default';
update_term_meta( $group_id, Group_Repository::TYPE_METAKEY, $type );
}
return $type ?? 'default';
}
/**
* Get the group ID depending on what was passed.
*
* @param Group|WP_Term|int|bool $group Group instance, term instance or numeric.
*
* @return int|bool false on failure
*/
private function get_group_id( $group ) {
if ( is_numeric( $group ) ) {
return $group;
}
if ( is_a_group( $group ) ) {
return $group->get_id();
}
if ( ! empty( $group->term_id ) ) {
return $group->term_id;
}
return false;
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* This class is responsible to model ordered groups.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.48.0
*/
namespace AdvancedAds\Groups;
use AdvancedAds\Interfaces\Group_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Ordered group.
*/
class Group_Ordered extends Group_Standard implements Group_Interface {}

View File

@@ -0,0 +1,321 @@
<?php
/**
* Group Repository.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.48.0
*/
namespace AdvancedAds\Groups;
use Exception;
use AdvancedAds\Constants;
use AdvancedAds\Abstracts\Group;
use AdvancedAds\Framework\Utilities\Formatting;
defined( 'ABSPATH' ) || exit;
/**
* Group Repository.
*/
class Group_Repository {
/**
* Group options metakey
*
* @var string
*/
const OPTION_METAKEY = 'advanced_ads_group_options';
/**
* Group type metakey
*
* @var string
*/
const TYPE_METAKEY = '_advads_group_type';
/* CRUD Methods ------------------- */
/**
* Create a new group in the database.
*
* @param Group $group Group object.
*
* @return Group
*/
public function create( &$group ): Group {
apply_filters( 'advanced-ads-group-pre-save', $group );
$ids = wp_insert_term(
$group->get_title(),
Constants::TAXONOMY_GROUP,
[
'description' => $group->get_content(),
'slug' => $group->get_slug(),
]
);
if ( $ids && ! is_wp_error( $ids ) ) {
$group->set_id( $ids['term_id'] );
$this->update_term_meta( $group );
$group->apply_changes();
}
return $group;
}
/**
* Read an group from the database.
*
* @param Group $group Group object.
* @throws Exception If invalid group.
*
* @return void
*/
public function read( &$group ): void {
$group->set_defaults();
$term_object = get_term( $group->get_id(), Constants::TAXONOMY_GROUP );
if ( null === $term_object || is_wp_error( $term_object ) ) {
throw new Exception( esc_html__( 'Invalid group.', 'advanced-ads' ) );
}
$group->set_title( $term_object->name );
$group->set_slug( $term_object->slug );
$group->set_content( $term_object->description );
$this->read_group_data( $group );
$group->set_object_read( true );
}
/**
* Update an existing group in the database.
*
* @param Group $group Group object.
*
* @return void
*/
public function update( &$group ): void {
apply_filters( 'advanced-ads-group-pre-save', $group );
$changed = array_keys( $group->get_changes() );
// Only update term when the term data changes.
if ( in_array( 'name', $changed, true ) ) {
wp_update_term( $group->get_id(), Constants::TAXONOMY_GROUP, [ 'name' => $group->get_name( 'edit' ) ] );
}
if ( in_array( 'title', $changed, true ) ) {
wp_update_term( $group->get_id(), Constants::TAXONOMY_GROUP, [ 'name' => $group->get_title( 'edit' ) ] );
}
// Only update weights when there is a change.
if ( in_array( 'ad_weights', $changed, true ) ) {
( new Group_Ad_Relation() )->relate( $group );
}
$this->update_term_meta( $group );
$group->apply_changes();
}
/**
* Delete an group from the database.
*
* @param Group $group Group object or Id.
*
* @return void
*/
public function delete( &$group ): void {
// Early bail!!
if ( ! $group || ! $group->get_id() ) {
return;
}
wp_delete_term( $group->get_id(), Constants::TAXONOMY_GROUP );
$this->update_old_storage( $group->get_id() );
$group->set_id( 0 );
$group->set_status( 'trash' );
}
/* Finder Methods ------------------- */
/**
* Get all groups object.
*
* @return Group[]
*/
public function get_all_groups(): array {
static $advads_all_groups;
if ( isset( $advads_all_groups ) ) {
return $advads_all_groups;
}
$advads_all_groups = [];
foreach ( $this->get_groups_dropdown() as $term_id => $name ) {
$advads_all_groups[ $term_id ] = wp_advads_get_group( $term_id );
}
return $advads_all_groups;
}
/**
* Get all group as dropdown.
*
* @return array
*/
public function get_groups_dropdown(): array {
$terms = get_terms(
[
'taxonomy' => Constants::TAXONOMY_GROUP,
'hide_empty' => false,
'number' => 0,
'orderby' => 'name',
'update_term_meta_cache' => false,
]
);
return ! empty( $terms ) && ! is_wp_error( $terms ) ? wp_list_pluck( $terms, 'name', 'term_id' ) : [];
}
/**
* Get groups associated with a given ad id.
*
* @param int $ad_id The ID of the ad.
*
* @return Group[] Groups array
*/
public function get_groups_by_ad_id( $ad_id ) {
$terms = $ad_id ? wp_get_object_terms( $ad_id, Constants::TAXONOMY_GROUP ) : false;
// Early bail!!
if ( is_wp_error( $terms ) || empty( $terms ) ) {
return [];
}
$groups = [];
foreach ( $terms as $group_id ) {
$groups[] = wp_advads_get_group( $group_id );
}
return $groups;
}
/* Additional Methods ------------------- */
/**
* Read group data. Can be overridden by child classes to load other props.
*
* @param Group $group Group object.
*
* @return void
*/
private function read_group_data( &$group ): void {
$type = get_term_meta( $group->get_id(), self::TYPE_METAKEY, true );
$meta_values = get_term_meta( $group->get_id(), self::OPTION_METAKEY, true );
$publish_date = get_term_meta( $group->get_id(), 'publish_date', true );
$modified_date = get_term_meta( $group->get_id(), 'modified_date', true );
if ( empty( $meta_values ) ) {
$meta_values = $this->migrate_values( $group );
$type = $meta_values['type'] ?? $type;
}
if ( 'ordered' === $type || 'default' === $type ) {
$type = 'refresh';
}
if ( isset( $meta_values['options'], $meta_values['options'][ $type ] ) ) {
$meta_values = array_merge( $meta_values['options'][ $type ], $meta_values );
}
$meta_values['publish_date'] = $publish_date ?? '';
$meta_values['modified_date'] = $modified_date ?? '';
$group->set_props( $meta_values );
foreach ( [ 'random', 'enabled' ] as $prop ) {
if ( array_key_exists( $prop, $meta_values ) ) {
$value = $meta_values[ $prop ];
$value = Formatting::string_to_bool( $value );
$group->set_prop( $prop, $value );
}
}
}
/**
* Update group data. Can be overridden by child classes to load other props.
*
* @param Group $group Group object.
*
* @return void
*/
private function update_term_meta( &$group ): void {
$current_date = current_time( 'mysql', true );
$meta_values = [
'type' => $group->get_type(),
'ad_count' => $group->get_ad_count(),
'options' => $group->get_options(),
'ad_weights' => $group->get_ad_weights(),
];
update_term_meta( $group->get_id(), self::TYPE_METAKEY, $group->get_type() );
update_term_meta( $group->get_id(), self::OPTION_METAKEY, $meta_values );
update_term_meta( $group->get_id(), 'modified_date', $current_date );
if ( empty( $group->get_publish_date() ) ) {
update_term_meta( $group->get_id(), 'publish_date', $current_date );
}
}
/**
* Migrate values to new version
*
* @param Group $group Group object.
*
* @return array
*/
private function migrate_values( $group ): array {
$values = [];
$all_groups = get_option( 'advads-ad-groups', [] );
$ad_weights = get_option( 'advads-ad-weights', [] );
if ( isset( $all_groups[ $group->get_id() ] ) && is_array( $all_groups[ $group->get_id() ] ) ) {
$values = $all_groups[ $group->get_id() ];
}
if ( isset( $ad_weights[ $group->get_id() ] ) && is_array( $ad_weights[ $group->get_id() ] ) ) {
$values['ad_weights'] = $ad_weights[ $group->get_id() ];
}
return $values;
}
/**
* Update old storage.
*
* TODO: Remove it later
*
* @param int $id Group ID.
*
* @return void
*/
private function update_old_storage( $id ): void {
$all_groups = get_option( 'advads-ad-groups', [] );
$all_weights = get_option( 'advads-ad-weights', [] );
if ( $all_groups && isset( $all_groups[ $id ] ) ) {
unset( $all_groups[ $id ] );
update_option( 'advads-ad-groups', $all_groups );
}
if ( $all_weights && isset( $all_weights[ $id ] ) ) {
unset( $all_weights[ $id ] );
update_option( 'advads-ad-weights', $all_weights );
}
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* This class is responsible to model slider groups.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.48.0
*/
namespace AdvancedAds\Groups;
use AdvancedAds\Abstracts\Group;
use AdvancedAds\Interfaces\Group_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Slider group.
*/
class Group_Slider extends Group implements Group_Interface {
/**
* Get delay.
*
* @param string $context What the value is for. Valid values are view and edit.
*
* @return int
*/
public function get_delay( $context = 'view' ): int {
return $this->get_prop( 'delay', $context );
}
/**
* Is grid display random.
*
* @param string $context What the value is for. Valid values are view and edit.
*
* @return bool
*/
public function is_random( $context = 'view' ): bool {
return $this->get_prop( 'random', $context );
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* This class is responsible to model standard groups.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.48.0
*/
namespace AdvancedAds\Groups;
use AdvancedAds\Abstracts\Group;
use AdvancedAds\Interfaces\Group_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Standard group.
*/
class Group_Standard extends Group implements Group_Interface {
/**
* Get interval.
*
* @param string $context What the value is for. Valid values are view and edit.
*
* @return int
*/
public function get_interval( $context = 'view' ): int {
return $this->get_prop( 'interval', $context );
}
/**
* Is refresh enabled.
*
* @param string $context What the value is for. Valid values are view and edit.
*
* @return bool
*/
public function is_refresh( $context = 'view' ): bool {
$value = $this->get_prop( 'enabled', $context );
return $value ?? false;
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Group types manager.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.47.0
*/
namespace AdvancedAds\Groups;
use AdvancedAds\Abstracts\Types;
use AdvancedAds\Groups\Types\Grid;
use AdvancedAds\Groups\Types\Slider;
use AdvancedAds\Groups\Types\Ordered;
use AdvancedAds\Groups\Types\Unknown;
use AdvancedAds\Groups\Types\Standard;
use AdvancedAds\Interfaces\Group_Type;
defined( 'ABSPATH' ) || exit;
/**
* Group Types.
*/
class Group_Types extends Types {
/**
* Hook to filter types.
*
* @var string
*/
protected $hook = 'advanced-ads-group-types';
/**
* Class for unknown type.
*
* @var string
*/
protected $type_unknown = Unknown::class;
/**
* Type interface to check.
*
* @var string
*/
protected $type_interface = Group_Type::class;
/**
* Register default types.
*
* @return void
*/
protected function register_default_types(): void {
$this->register_type( Standard::class );
$this->register_type( Ordered::class );
$this->register_type( Grid::class );
$this->register_type( Slider::class );
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* This class is responsible to hold all the Groups functionality.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.47.0
*/
namespace AdvancedAds\Groups;
use AdvancedAds\Framework\Interfaces\Initializer_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Groups.
*/
class Groups implements Initializer_Interface {
/**
* Hold factory instance
*
* @var Group_Factory
*/
public $factory = null;
/**
* Hold repository instance
*
* @var Group_Repository
*/
public $repository = null;
/**
* Hold types manager
*
* @var Group_Types
*/
public $types = null;
/**
* Runs this initializer.
*
* @return void
*/
public function initialize(): void {
$this->factory = new Group_Factory();
$this->types = new Group_Types();
$this->repository = new Group_Repository();
$this->types->hooks();
}
}

View File

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

View File

@@ -0,0 +1,75 @@
<?php
/**
* This class represents the "Grid" group type.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.47.0
*/
namespace AdvancedAds\Groups\Types;
use AdvancedAds\Groups\Group_Standard;
use AdvancedAds\Interfaces\Group_Type;
defined( 'ABSPATH' ) || exit;
/**
* Type Grid.
*/
class Grid implements Group_Type {
/**
* Get the unique identifier (ID) of the group type.
*
* @return string The unique ID of the group type.
*/
public function get_id(): string {
return 'grid';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Group_Standard::class;
}
/**
* Get the title or name of the group type.
*
* @return string The title of the group type.
*/
public function get_title(): string {
return __( 'Grid', 'advanced-ads' );
}
/**
* Get a description of the group type.
*
* @return string The description of the group type.
*/
public function get_description(): string {
return '';
}
/**
* Check if this group type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return true;
}
/**
* Get the URL for upgrading to this group type.
*
* @return string The upgrade URL for the group type.
*/
public function get_image(): string {
return ADVADS_BASE_URL . 'admin/assets/img/groups/grid.svg';
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* This class represents the "Ordered" group type.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.47.0
*/
namespace AdvancedAds\Groups\Types;
use AdvancedAds\Groups\Group_Ordered;
use AdvancedAds\Interfaces\Group_Type;
defined( 'ABSPATH' ) || exit;
/**
* Type Ordered.
*/
class Ordered implements Group_Type {
/**
* Get the unique identifier (ID) of the group type.
*
* @return string The unique ID of the group type.
*/
public function get_id(): string {
return 'ordered';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Group_Ordered::class;
}
/**
* Get the title or name of the group type.
*
* @return string The title of the group type.
*/
public function get_title(): string {
return __( 'Ordered ads', 'advanced-ads' );
}
/**
* Get a description of the group type.
*
* @return string The description of the group type.
*/
public function get_description(): string {
return __( 'Display ads with the highest ad weight first', 'advanced-ads' );
}
/**
* Check if this group 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 group type.
*
* @return string The upgrade URL for the group type.
*/
public function get_image(): string {
return ADVADS_BASE_URL . 'admin/assets/img/groups/ordered.svg';
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* This class represents the "Slider" group type.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.47.0
*/
namespace AdvancedAds\Groups\Types;
use AdvancedAds\Groups\Group_Slider;
use AdvancedAds\Interfaces\Group_Type;
defined( 'ABSPATH' ) || exit;
/**
* Type Slider.
*/
class Slider implements Group_Type {
/**
* Get the unique identifier (ID) of the group type.
*
* @return string The unique ID of the group type.
*/
public function get_id(): string {
return 'slider';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Group_Slider::class;
}
/**
* Get the title or name of the group type.
*
* @return string The title of the group type.
*/
public function get_title(): string {
return __( 'Ad Slider', 'advanced-ads' );
}
/**
* Get a description of the group type.
*
* @return string The description of the group type.
*/
public function get_description(): string {
return '';
}
/**
* Check if this group type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return true;
}
/**
* Get the URL for upgrading to this group type.
*
* @return string The upgrade URL for the group type.
*/
public function get_image(): string {
return ADVADS_BASE_URL . 'admin/assets/img/groups/slider.svg';
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* This class represents the "Standard" group type.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.47.0
*/
namespace AdvancedAds\Groups\Types;
use AdvancedAds\Groups\Group_Standard;
use AdvancedAds\Interfaces\Group_Type;
defined( 'ABSPATH' ) || exit;
/**
* Type Standard.
*/
class Standard implements Group_Type {
/**
* Get the unique identifier (ID) of the group type.
*
* @return string The unique ID of the group type.
*/
public function get_id(): string {
return 'default';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return Group_Standard::class;
}
/**
* Get the title or name of the group type.
*
* @return string The title of the group type.
*/
public function get_title(): string {
return __( 'Random ads', 'advanced-ads' );
}
/**
* Get a description of the group type.
*
* @return string The description of the group type.
*/
public function get_description(): string {
return __( 'Display random ads based on ad weight', 'advanced-ads' );
}
/**
* Check if this group 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 group type.
*
* @return string The upgrade URL for the group type.
*/
public function get_image(): string {
return ADVADS_BASE_URL . 'admin/assets/img/groups/random.svg';
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* This class represents the "Unknown" group type.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.47.0
*/
namespace AdvancedAds\Groups\Types;
use AdvancedAds\Groups\Group_Standard;
use AdvancedAds\Interfaces\Group_Type;
defined( 'ABSPATH' ) || exit;
/**
* Type Unknown.
*/
class Unknown implements Group_Type {
/**
* Hold type data.
*
* @var array
*/
private $data = [];
/**
* The constructor.
*
* @param array $data Array of type data.
*/
public function __construct( array $data ) {
$this->data = $data;
}
/**
* Get the unique identifier (ID) of the group type.
*
* @return string The unique ID of the group type.
*/
public function get_id(): string {
return $this->data['id'] ?? 'default';
}
/**
* Get the class name of the object as a string.
*
* @return string
*/
public function get_classname(): string {
return $this->data['classname'] ?? Group_Standard::class;
}
/**
* Get the title or name of the group type.
*
* @return string The title of the group type.
*/
public function get_title(): string {
return $this->data['title'] ?? __( 'Unknown type', 'advanced-ads' );
}
/**
* Get a description of the group type.
*
* @return string The description of the group type.
*/
public function get_description(): string {
return $this->data['description'] ?? __( 'No description', 'advanced-ads' );
}
/**
* Check if this group type requires premium.
*
* @return bool True if premium is required; otherwise, false.
*/
public function is_premium(): bool {
return boolval( $this->data['is_premium'] ?? true );
}
/**
* Get the URL for upgrading to this group type.
*
* @return string The upgrade URL for the group type.
*/
public function get_image(): string {
$fallback = ADVADS_BASE_URL . 'admin/assets/img/placements/manual.png';
return $this->data['image'] ?? $fallback;
}
}