Plugin Directory

Changeset 3283205


Ignore:
Timestamp:
04/28/2025 08:28:54 AM (8 months ago)
Author:
advancedads
Message:

Update to version 2.0.8 from GitHub

Location:
advanced-ads
Files:
8 added
28 edited
1 copied

Legend:

Unmodified
Added
Removed
  • advanced-ads/tags/2.0.8/advanced-ads.php

    r3269753 r3283205  
    1111 * @wordpress-plugin
    1212 * Plugin Name:       Advanced Ads
    13  * Version:           2.0.7
     13 * Version:           2.0.8
    1414 * Description:       Manage and optimize your ads in WordPress
    1515 * Plugin URI:        https://wpadvancedads.com
     
    3838
    3939define( 'ADVADS_FILE', __FILE__ );
    40 define( 'ADVADS_VERSION', '2.0.7' );
     40define( 'ADVADS_VERSION', '2.0.8' );
    4141
    4242// Load the autoloader.
  • advanced-ads/tags/2.0.8/includes/abstracts/abstract-ad.php

    r3259235 r3283205  
    1414use Advanced_Ads_Utils;
    1515use Advanced_Ads_Visitor_Conditions;
    16 use AdvancedAds\Compatibility\Compatibility;
     16use AdvancedAds\Traits;
    1717use AdvancedAds\Constants;
    18 use AdvancedAds\Framework\Utilities\Arr;
    19 use AdvancedAds\Framework\Utilities\Formatting;
    20 use AdvancedAds\Framework\Utilities\Str;
    2118use AdvancedAds\Frontend\Stats;
    2219use AdvancedAds\Interfaces\Ad_Type;
    23 use AdvancedAds\Traits;
     20use AdvancedAds\Utilities\WordPress;
    2421use AdvancedAds\Utilities\Conditional;
    25 use AdvancedAds\Utilities\WordPress;
    26 use DateInterval;
    27 use DateTime;
     22use AdvancedAds\Framework\Utilities\Arr;
     23use AdvancedAds\Framework\Utilities\Str;
     24use AdvancedAds\Compatibility\Compatibility;
     25use AdvancedAds\Framework\Utilities\Formatting;
    2826
    2927defined( 'ABSPATH' ) || exit;
     
    789787     */
    790788    public function get_ad_schedule_details(): array {
     789        $status_strings     = [];
     790        $html_classes       = 'advads-filter-timing';
     791        $post_start         = get_post_time( 'U', true, $this->get_id() );
    791792        $expiry_date_format = get_option( 'date_format' ) . ', ' . get_option( 'time_format' );
    792         $status_strings     = [];
    793         $post_start         = get_post_time( 'U', true, $this->get_id() );
    794         $html_classes       = 'advads-filter-timing';
    795793
    796794        $status_type = get_post_status( $this->get_id() ) ?? 'published';
     
    810808            $expiry      = $this->get_expiry_date();
    811809            $expiry_date = date_create( '@' . $expiry );
    812             $expiry_date->setTimezone( WordPress::get_timezone() );
     810            $expiry_date->setTimezone( new \DateTimeZone( 'UTC' ) );
    813811            $html_classes .= ' advads-filter-any-exp-date';
    814812
     
    900898        }
    901899
    902         $wp_time = new DateTime( 'now', wp_timezone() );
    903         $expiration_date->sub( new DateInterval( 'PT' . $wp_time->getOffset() . 'S' ) );
     900        $expiration_date->setTimezone( new \DateTimeZone( 'UTC' ) );
    904901        $gm_date = $expiration_date->format( 'Y-m-d-H-i' );
    905902
  • advanced-ads/tags/2.0.8/includes/admin/class-admin-menu.php

    r3253289 r3283205  
    247247     * @return string
    248248     */
    249     public function add_body_class( string $classes ): string {
     249    public function add_body_class( $classes ): string {
     250        // Ensure $classes is always a string due to 3rd party plugins interfering with the filter.
     251        $classes    = is_string( $classes ) ? $classes : '';
    250252        $screen_ids = $this->get_screen_ids();
    251253        $wp_screen  = get_current_screen();
  • advanced-ads/tags/2.0.8/includes/admin/class-metabox-ad-settings.php

    r3253289 r3283205  
    4040        add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] );
    4141        add_action( 'save_post', [ $this, 'save_settings' ], 10, 2 );
    42         add_action( 'set_object_terms', [ $this, 'set_group_terms' ], 10, 6 );
    4342    }
    4443
     
    132131        update_post_meta( $post_id, self::SETTING_METAKEY, $data );
    133132    }
    134 
    135     /**
    136      * Sets the group terms for an ad.
    137      *
    138      * Handles the removed and added groups accordingly.
    139      *
    140      * @param int    $ad_id      The ID of the ad.
    141      * @param array  $terms      The terms to set for the ad.
    142      * @param array  $tt_ids     The term taxonomy IDs to set for the ad.
    143      * @param string $taxonomy   The taxonomy to set the terms for.
    144      * @param bool   $append     Whether to append the terms or replace them.
    145      * @param array  $old_tt_ids The old term taxonomy IDs for the ad.
    146      * @return void
    147      */
    148     public function set_group_terms( $ad_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
    149         if ( Constants::TAXONOMY_GROUP === $taxonomy ) {
    150             $removed_terms = array_diff( $old_tt_ids, $tt_ids );
    151             $added_terms   = array_diff( $tt_ids, $old_tt_ids );
    152 
    153             $this->handle_removed_terms( $removed_terms, $ad_id );
    154             $this->handle_added_terms( $added_terms, $ad_id );
    155         }
    156     }
    157 
    158     /**
    159      * Handles the removed terms for an ad.
    160      *
    161      * @param array $removed_terms An array of term IDs that have been removed.
    162      * @param int   $ad_id         The ID of the ad.
    163      * @return void
    164      */
    165     private function handle_removed_terms( $removed_terms, $ad_id ) {
    166         foreach ( $removed_terms as $group_id ) {
    167             $group = wp_advads_get_group( $group_id );
    168             if ( ! $group ) {
    169                 continue;
    170             }
    171 
    172             $weights = $group->get_ad_weights();
    173             if ( isset( $weights[ $ad_id ] ) ) {
    174                 unset( $weights[ $ad_id ] );
    175                 $group->set_ad_weights( $weights );
    176                 $group->save();
    177             }
    178         }
    179     }
    180 
    181     /**
    182      * Handles the added terms for an ad.
    183      *
    184      * @param array $added_terms An array of term IDs that have been added.
    185      * @param int   $ad_id       The ID of the ad.
    186      * @return void
    187      */
    188     private function handle_added_terms( $added_terms, $ad_id ) {
    189         foreach ( $added_terms as $group_id ) {
    190             $group = wp_advads_get_group( $group_id );
    191             if ( ! $group ) {
    192                 continue;
    193             }
    194 
    195             $weights = $group->get_ad_weights();
    196             if ( ! isset( $weights[ $ad_id ] ) ) {
    197                 $weights[ $ad_id ] = Constants::GROUP_AD_DEFAULT_WEIGHT;
    198                 $group->set_ad_weights( $weights );
    199                 $group->save();
    200             }
    201         }
    202     }
    203133}
  • advanced-ads/tags/2.0.8/includes/admin/class-quick-bulk-edit.php

    r3269753 r3283205  
    196196
    197197        try {
    198             $date = new DateTime( 'now', wp_timezone() );
     198            $date = new DateTime( 'now', new \DateTimeZone( 'UTC' ) );
    199199            $date->setDate( $year, $month, $day );
    200200            $date->setTime( $hours, $minutes );
     
    276276    public static function print_date_time_inputs( $timestamp = 0, $prefix = '', $seconds = false ) {
    277277        try {
    278             $initial_date = (bool) $timestamp ? new \DateTimeImmutable( "@$timestamp", wp_timezone() ) : current_datetime();
     278            $initial_date = (bool) $timestamp ? new \DateTimeImmutable( "@$timestamp", new \DateTimeZone( 'UTC' ) ) : current_datetime();
    279279        } catch ( Exception $e ) {
    280280            $initial_date = current_datetime();
     
    341341        if ( $expiry ) {
    342342            $expiry_date = array_combine(
    343                 [ 'year', 'month', 'day', 'hour', 'minutes' ],
    344                 explode( '-', wp_date( 'Y-m-d-H-i', $expiry ) )
     343                [ 'year', 'month', 'day', 'hour', 'minute' ],
     344                explode( '-', wp_date( 'Y-m-d-H-i', $expiry, new \DateTimeZone( 'UTC' ) ) )
    345345            );
    346346        }
  • advanced-ads/tags/2.0.8/includes/admin/pages/class-ads-editing.php

    r3259235 r3283205  
    1010namespace AdvancedAds\Admin\Pages;
    1111
     12use DateTimeImmutable;
    1213use AdvancedAds\Constants;
     14use AdvancedAds\Utilities\WordPress;
    1315use AdvancedAds\Framework\Utilities\Params;
    14 use AdvancedAds\Utilities\WordPress;
    15 use DateTime;
    1616
    1717defined( 'ABSPATH' ) || exit;
     
    158158        // Get time set for ad or current timestamp (both GMT).
    159159        $utc_ts   = $ad->get_expiry_date() ?: current_time( 'timestamp', true ); // phpcs:ignore
    160         $utc_time = new DateTime( '@' . $utc_ts );
    161         $utc_time->setTimezone( \Advanced_Ads_Utils::get_wp_timezone() );
     160        $utc_time = new DateTimeImmutable( '@' . $utc_ts, new \DateTimeZone( 'UTC' ) );
    162161        [ $curr_year, $curr_month, $curr_day, $curr_hour, $curr_minute ] = explode( '-', $utc_time->format( 'Y-m-d-H-i' ) );
    163162        $enabled = 1 - empty( $ad->get_expiry_date() );
  • advanced-ads/tags/2.0.8/includes/ads/class-ad-repository.php

    r3257709 r3283205  
    6767
    6868            $this->update_post_meta( $ad );
     69            $this->update_post_term( $ad );
    6970            $this->update_version( $ad );
    7071
     
    164165
    165166        $this->update_post_meta( $ad );
     167        $this->update_post_term( $ad );
    166168
    167169        $ad->apply_changes();
     
    419421
    420422    /**
     423     * Update ad groups.
     424     *
     425     * @param Ad $ad Ad object.
     426     *
     427     * @return void
     428     */
     429    private function update_post_term( &$ad ): void {
     430        ( new Ad_Group_Relation() )->relate( $ad );
     431    }
     432
     433    /**
    421434     * Make sure we store the ad version (to track data changes).
    422435     *
  • advanced-ads/tags/2.0.8/includes/class-constants.php

    r3253289 r3283205  
    118118    const AD_META_EXPIRATION_TIME = 'advanced_ads_expiration_time';
    119119
     120    /**
     121     * Ad metakey for group ids.
     122     *
     123     * @var string
     124     */
     125    const AD_META_GROUP_IDS = 'advanced_ads_ad_group_ids';
     126
    120127    /* User Meta Keys ------------------- */
    121128
  • advanced-ads/tags/2.0.8/includes/class-upgrades.php

    r3253289 r3283205  
    2020class Upgrades extends Updates implements Initializer_Interface {
    2121
    22     const DB_VERSION = '1.53.0';
     22    const DB_VERSION = '1.53.1';
    2323
    2424    /**
     
    3535            '1.52.1' => 'upgrade-1.52.1.php',
    3636            '2.0.0'  => 'upgrade-2.0.0.php',
     37            '2.0.8'  => 'upgrade-2.0.8.php',
    3738        ];
    3839    }
  • advanced-ads/tags/2.0.8/includes/groups/class-group-repository.php

    r3265208 r3283205  
    113113        // Only update weights when there is a change.
    114114        if ( in_array( 'ad_weights', $changed, true ) ) {
    115             $this->update_ads_terms( $group );
     115            ( new Group_Ad_Relation() )->relate( $group );
    116116        }
    117117
     
    273273
    274274    /**
    275      * Update group ad terms.
    276      *
    277      * @param Group $group Group object.
    278      *
    279      * @return void
    280      */
    281     private function update_ads_terms( &$group ): void {
    282         // Early bail!!
    283         if ( empty( $group->get_ad_weights() ) ) {
    284             return;
    285         }
    286 
    287         $data    = $group->get_data();
    288         $changes = $group->get_changes();
    289         $old_ads = $data['ad_weights'] ? array_keys( $data['ad_weights'] ) : [];
    290         $new_ads = $changes['ad_weights'] ? array_keys( $changes['ad_weights'] ) : [];
    291         $removed = array_diff( $old_ads, $new_ads );
    292 
    293         foreach ( $removed as $ad_id ) {
    294             $terms = wp_get_object_terms( $ad_id, Constants::TAXONOMY_GROUP );
    295 
    296             if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
    297                 $term_ids = wp_list_pluck( $terms, 'term_id' );
    298                 $term_ids = array_diff( $term_ids, [ $group->get_id() ] );
    299                 wp_set_object_terms( $ad_id, $term_ids, Constants::TAXONOMY_GROUP );
    300             }
    301         }
    302 
    303         $new_ads_final = $changes['ad_weights'] ?? [];
    304 
    305         foreach ( $new_ads as $ad_id ) {
    306             /**
    307              * Check if this ad is representing the current group and remove it in this case
    308              * could cause an infinite loop otherwise
    309              */
    310             $ad = wp_advads_get_ad( $ad_id );
    311             if ( $ad && $ad->is_type( 'group' ) && $ad->get_group_id() === $group->get_id() ) {
    312                 unset( $new_ads_final[ $ad_id ] );
    313                 continue;
    314             }
    315 
    316             $terms = wp_get_object_terms( $ad_id, Constants::TAXONOMY_GROUP );
    317 
    318             if ( ! is_wp_error( $terms ) ) {
    319                 $term_ids   = wp_list_pluck( $terms, 'term_id' );
    320                 $term_ids[] = $group->get_id();
    321                 $term_ids   = array_unique( $term_ids );
    322                 wp_set_object_terms( $ad_id, $term_ids, Constants::TAXONOMY_GROUP );
    323             }
    324         }
    325 
    326         $group->set_ad_weights( $new_ads_final );
    327     }
    328 
    329     /**
    330275     * Migrate values to new version
    331276     *
  • advanced-ads/tags/2.0.8/languages/advanced-ads.pot

    r3269753 r3283205  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Advanced Ads 2.0.6\n"
     5"Project-Id-Version: Advanced Ads 2.0.7\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/advanced-ads\n"
    77"Last-Translator: Thomas Maier <[email protected]>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2025-04-09T05:01:12+00:00\n"
     12"POT-Creation-Date: 2025-04-28T07:32:04+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.11.0\n"
     
    11831183
    11841184#: classes/display-conditions.php:729
    1185 #: includes/abstracts/abstract-ad.php:832
     1185#: includes/abstracts/abstract-ad.php:830
    11861186#: includes/admin/class-groups-list-table.php:362
    11871187#: views/admin/placements/quick-edit.php:16
     
    15511551
    15521552#. translators: %s is a date.
    1553 #: includes/abstracts/abstract-ad.php:806
     1553#: includes/abstracts/abstract-ad.php:804
    15541554msgid "starts %s"
    15551555msgstr ""
    15561556
    15571557#. translators: %s is a date.
    1558 #: includes/abstracts/abstract-ad.php:820
     1558#: includes/abstracts/abstract-ad.php:818
    15591559msgid "expires %s"
    15601560msgstr ""
    15611561
    15621562#. translators: %s is a date.
    1563 #: includes/abstracts/abstract-ad.php:826
     1563#: includes/abstracts/abstract-ad.php:824
    15641564msgid "expired %s"
    15651565msgstr ""
    15661566
    1567 #: includes/abstracts/abstract-ad.php:835
     1567#: includes/abstracts/abstract-ad.php:833
    15681568#: includes/admin/class-placement-quick-edit.php:48
    15691569#: views/admin/placements/edit-modal/fields/status.php:13
     
    15731573msgstr ""
    15741574
    1575 #: includes/abstracts/abstract-ad.php:838
     1575#: includes/abstracts/abstract-ad.php:836
    15761576msgid "Trashed"
    15771577msgstr ""
    15781578
    15791579#. translators: %1$s is a placement name, %2$s is the ads name.
    1580 #: includes/abstracts/abstract-ad.php:1216
     1580#: includes/abstracts/abstract-ad.php:1213
    15811581msgid "Placement name: %1$s; Ads: %2$s"
    15821582msgstr ""
     
    21782178msgstr ""
    21792179
    2180 #: includes/admin/class-metabox-ad-settings.php:64
     2180#: includes/admin/class-metabox-ad-settings.php:63
    21812181msgid "Ad Settings"
    21822182msgstr ""
     
    29612961msgstr ""
    29622962
    2963 #: includes/ads/class-ad-repository.php:90
     2963#: includes/ads/class-ad-repository.php:91
    29642964msgid "Invalid ad."
    29652965msgstr ""
  • advanced-ads/tags/2.0.8/packages/composer/autoload_classmap.php

    r3269753 r3283205  
    7373    'AdvancedAds\\Ads\\Ad_Factory' => $baseDir . '/includes/ads/class-ad-factory.php',
    7474    'AdvancedAds\\Ads\\Ad_Group' => $baseDir . '/includes/ads/class-ad-group.php',
     75    'AdvancedAds\\Ads\\Ad_Group_Relation' => $baseDir . '/includes/ads/class-ad-group-relation.php',
    7576    'AdvancedAds\\Ads\\Ad_Image' => $baseDir . '/includes/ads/class-ad-image.php',
    7677    'AdvancedAds\\Ads\\Ad_Plain' => $baseDir . '/includes/ads/class-ad-plain.php',
     
    132133    'AdvancedAds\\Frontend\\Scripts' => $baseDir . '/includes/frontend/class-scripts.php',
    133134    'AdvancedAds\\Frontend\\Stats' => $baseDir . '/includes/frontend/class-stats.php',
     135    'AdvancedAds\\Groups\\Group_Ad_Relation' => $baseDir . '/includes/groups/class-group-ad-relation.php',
    134136    'AdvancedAds\\Groups\\Group_Factory' => $baseDir . '/includes/groups/class-group-factory.php',
    135137    'AdvancedAds\\Groups\\Group_Ordered' => $baseDir . '/includes/groups/class-group-ordered.php',
  • advanced-ads/tags/2.0.8/packages/composer/autoload_static.php

    r3269753 r3283205  
    100100        'AdvancedAds\\Ads\\Ad_Factory' => __DIR__ . '/../..' . '/includes/ads/class-ad-factory.php',
    101101        'AdvancedAds\\Ads\\Ad_Group' => __DIR__ . '/../..' . '/includes/ads/class-ad-group.php',
     102        'AdvancedAds\\Ads\\Ad_Group_Relation' => __DIR__ . '/../..' . '/includes/ads/class-ad-group-relation.php',
    102103        'AdvancedAds\\Ads\\Ad_Image' => __DIR__ . '/../..' . '/includes/ads/class-ad-image.php',
    103104        'AdvancedAds\\Ads\\Ad_Plain' => __DIR__ . '/../..' . '/includes/ads/class-ad-plain.php',
     
    159160        'AdvancedAds\\Frontend\\Scripts' => __DIR__ . '/../..' . '/includes/frontend/class-scripts.php',
    160161        'AdvancedAds\\Frontend\\Stats' => __DIR__ . '/../..' . '/includes/frontend/class-stats.php',
     162        'AdvancedAds\\Groups\\Group_Ad_Relation' => __DIR__ . '/../..' . '/includes/groups/class-group-ad-relation.php',
    161163        'AdvancedAds\\Groups\\Group_Factory' => __DIR__ . '/../..' . '/includes/groups/class-group-factory.php',
    162164        'AdvancedAds\\Groups\\Group_Ordered' => __DIR__ . '/../..' . '/includes/groups/class-group-ordered.php',
  • advanced-ads/tags/2.0.8/readme.txt

    r3269753 r3283205  
    55Tested up to: 6.7
    66Requires PHP: 7.4
    7 Stable tag: 2.0.7
     7Stable tag: 2.0.8
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    361361== Changelog ==
    362362
     363= 2.0.8 (April 28, 2025) =
     364
     365- Improvement: type safety in `add_body_class` to prevent issues from third-party filters
     366- Improvement: improve the ad and group relation both way
     367- Fix: expiry date not updating for ads that already had one set
     368
    363369= 2.0.7 (April 9, 2025) =
    364370- Improvement: optimize MailPoet compatibility
  • advanced-ads/trunk/advanced-ads.php

    r3269753 r3283205  
    1111 * @wordpress-plugin
    1212 * Plugin Name:       Advanced Ads
    13  * Version:           2.0.7
     13 * Version:           2.0.8
    1414 * Description:       Manage and optimize your ads in WordPress
    1515 * Plugin URI:        https://wpadvancedads.com
     
    3838
    3939define( 'ADVADS_FILE', __FILE__ );
    40 define( 'ADVADS_VERSION', '2.0.7' );
     40define( 'ADVADS_VERSION', '2.0.8' );
    4141
    4242// Load the autoloader.
  • advanced-ads/trunk/includes/abstracts/abstract-ad.php

    r3259235 r3283205  
    1414use Advanced_Ads_Utils;
    1515use Advanced_Ads_Visitor_Conditions;
    16 use AdvancedAds\Compatibility\Compatibility;
     16use AdvancedAds\Traits;
    1717use AdvancedAds\Constants;
    18 use AdvancedAds\Framework\Utilities\Arr;
    19 use AdvancedAds\Framework\Utilities\Formatting;
    20 use AdvancedAds\Framework\Utilities\Str;
    2118use AdvancedAds\Frontend\Stats;
    2219use AdvancedAds\Interfaces\Ad_Type;
    23 use AdvancedAds\Traits;
     20use AdvancedAds\Utilities\WordPress;
    2421use AdvancedAds\Utilities\Conditional;
    25 use AdvancedAds\Utilities\WordPress;
    26 use DateInterval;
    27 use DateTime;
     22use AdvancedAds\Framework\Utilities\Arr;
     23use AdvancedAds\Framework\Utilities\Str;
     24use AdvancedAds\Compatibility\Compatibility;
     25use AdvancedAds\Framework\Utilities\Formatting;
    2826
    2927defined( 'ABSPATH' ) || exit;
     
    789787     */
    790788    public function get_ad_schedule_details(): array {
     789        $status_strings     = [];
     790        $html_classes       = 'advads-filter-timing';
     791        $post_start         = get_post_time( 'U', true, $this->get_id() );
    791792        $expiry_date_format = get_option( 'date_format' ) . ', ' . get_option( 'time_format' );
    792         $status_strings     = [];
    793         $post_start         = get_post_time( 'U', true, $this->get_id() );
    794         $html_classes       = 'advads-filter-timing';
    795793
    796794        $status_type = get_post_status( $this->get_id() ) ?? 'published';
     
    810808            $expiry      = $this->get_expiry_date();
    811809            $expiry_date = date_create( '@' . $expiry );
    812             $expiry_date->setTimezone( WordPress::get_timezone() );
     810            $expiry_date->setTimezone( new \DateTimeZone( 'UTC' ) );
    813811            $html_classes .= ' advads-filter-any-exp-date';
    814812
     
    900898        }
    901899
    902         $wp_time = new DateTime( 'now', wp_timezone() );
    903         $expiration_date->sub( new DateInterval( 'PT' . $wp_time->getOffset() . 'S' ) );
     900        $expiration_date->setTimezone( new \DateTimeZone( 'UTC' ) );
    904901        $gm_date = $expiration_date->format( 'Y-m-d-H-i' );
    905902
  • advanced-ads/trunk/includes/admin/class-admin-menu.php

    r3253289 r3283205  
    247247     * @return string
    248248     */
    249     public function add_body_class( string $classes ): string {
     249    public function add_body_class( $classes ): string {
     250        // Ensure $classes is always a string due to 3rd party plugins interfering with the filter.
     251        $classes    = is_string( $classes ) ? $classes : '';
    250252        $screen_ids = $this->get_screen_ids();
    251253        $wp_screen  = get_current_screen();
  • advanced-ads/trunk/includes/admin/class-metabox-ad-settings.php

    r3253289 r3283205  
    4040        add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] );
    4141        add_action( 'save_post', [ $this, 'save_settings' ], 10, 2 );
    42         add_action( 'set_object_terms', [ $this, 'set_group_terms' ], 10, 6 );
    4342    }
    4443
     
    132131        update_post_meta( $post_id, self::SETTING_METAKEY, $data );
    133132    }
    134 
    135     /**
    136      * Sets the group terms for an ad.
    137      *
    138      * Handles the removed and added groups accordingly.
    139      *
    140      * @param int    $ad_id      The ID of the ad.
    141      * @param array  $terms      The terms to set for the ad.
    142      * @param array  $tt_ids     The term taxonomy IDs to set for the ad.
    143      * @param string $taxonomy   The taxonomy to set the terms for.
    144      * @param bool   $append     Whether to append the terms or replace them.
    145      * @param array  $old_tt_ids The old term taxonomy IDs for the ad.
    146      * @return void
    147      */
    148     public function set_group_terms( $ad_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
    149         if ( Constants::TAXONOMY_GROUP === $taxonomy ) {
    150             $removed_terms = array_diff( $old_tt_ids, $tt_ids );
    151             $added_terms   = array_diff( $tt_ids, $old_tt_ids );
    152 
    153             $this->handle_removed_terms( $removed_terms, $ad_id );
    154             $this->handle_added_terms( $added_terms, $ad_id );
    155         }
    156     }
    157 
    158     /**
    159      * Handles the removed terms for an ad.
    160      *
    161      * @param array $removed_terms An array of term IDs that have been removed.
    162      * @param int   $ad_id         The ID of the ad.
    163      * @return void
    164      */
    165     private function handle_removed_terms( $removed_terms, $ad_id ) {
    166         foreach ( $removed_terms as $group_id ) {
    167             $group = wp_advads_get_group( $group_id );
    168             if ( ! $group ) {
    169                 continue;
    170             }
    171 
    172             $weights = $group->get_ad_weights();
    173             if ( isset( $weights[ $ad_id ] ) ) {
    174                 unset( $weights[ $ad_id ] );
    175                 $group->set_ad_weights( $weights );
    176                 $group->save();
    177             }
    178         }
    179     }
    180 
    181     /**
    182      * Handles the added terms for an ad.
    183      *
    184      * @param array $added_terms An array of term IDs that have been added.
    185      * @param int   $ad_id       The ID of the ad.
    186      * @return void
    187      */
    188     private function handle_added_terms( $added_terms, $ad_id ) {
    189         foreach ( $added_terms as $group_id ) {
    190             $group = wp_advads_get_group( $group_id );
    191             if ( ! $group ) {
    192                 continue;
    193             }
    194 
    195             $weights = $group->get_ad_weights();
    196             if ( ! isset( $weights[ $ad_id ] ) ) {
    197                 $weights[ $ad_id ] = Constants::GROUP_AD_DEFAULT_WEIGHT;
    198                 $group->set_ad_weights( $weights );
    199                 $group->save();
    200             }
    201         }
    202     }
    203133}
  • advanced-ads/trunk/includes/admin/class-quick-bulk-edit.php

    r3269753 r3283205  
    196196
    197197        try {
    198             $date = new DateTime( 'now', wp_timezone() );
     198            $date = new DateTime( 'now', new \DateTimeZone( 'UTC' ) );
    199199            $date->setDate( $year, $month, $day );
    200200            $date->setTime( $hours, $minutes );
     
    276276    public static function print_date_time_inputs( $timestamp = 0, $prefix = '', $seconds = false ) {
    277277        try {
    278             $initial_date = (bool) $timestamp ? new \DateTimeImmutable( "@$timestamp", wp_timezone() ) : current_datetime();
     278            $initial_date = (bool) $timestamp ? new \DateTimeImmutable( "@$timestamp", new \DateTimeZone( 'UTC' ) ) : current_datetime();
    279279        } catch ( Exception $e ) {
    280280            $initial_date = current_datetime();
     
    341341        if ( $expiry ) {
    342342            $expiry_date = array_combine(
    343                 [ 'year', 'month', 'day', 'hour', 'minutes' ],
    344                 explode( '-', wp_date( 'Y-m-d-H-i', $expiry ) )
     343                [ 'year', 'month', 'day', 'hour', 'minute' ],
     344                explode( '-', wp_date( 'Y-m-d-H-i', $expiry, new \DateTimeZone( 'UTC' ) ) )
    345345            );
    346346        }
  • advanced-ads/trunk/includes/admin/pages/class-ads-editing.php

    r3259235 r3283205  
    1010namespace AdvancedAds\Admin\Pages;
    1111
     12use DateTimeImmutable;
    1213use AdvancedAds\Constants;
     14use AdvancedAds\Utilities\WordPress;
    1315use AdvancedAds\Framework\Utilities\Params;
    14 use AdvancedAds\Utilities\WordPress;
    15 use DateTime;
    1616
    1717defined( 'ABSPATH' ) || exit;
     
    158158        // Get time set for ad or current timestamp (both GMT).
    159159        $utc_ts   = $ad->get_expiry_date() ?: current_time( 'timestamp', true ); // phpcs:ignore
    160         $utc_time = new DateTime( '@' . $utc_ts );
    161         $utc_time->setTimezone( \Advanced_Ads_Utils::get_wp_timezone() );
     160        $utc_time = new DateTimeImmutable( '@' . $utc_ts, new \DateTimeZone( 'UTC' ) );
    162161        [ $curr_year, $curr_month, $curr_day, $curr_hour, $curr_minute ] = explode( '-', $utc_time->format( 'Y-m-d-H-i' ) );
    163162        $enabled = 1 - empty( $ad->get_expiry_date() );
  • advanced-ads/trunk/includes/ads/class-ad-repository.php

    r3257709 r3283205  
    6767
    6868            $this->update_post_meta( $ad );
     69            $this->update_post_term( $ad );
    6970            $this->update_version( $ad );
    7071
     
    164165
    165166        $this->update_post_meta( $ad );
     167        $this->update_post_term( $ad );
    166168
    167169        $ad->apply_changes();
     
    419421
    420422    /**
     423     * Update ad groups.
     424     *
     425     * @param Ad $ad Ad object.
     426     *
     427     * @return void
     428     */
     429    private function update_post_term( &$ad ): void {
     430        ( new Ad_Group_Relation() )->relate( $ad );
     431    }
     432
     433    /**
    421434     * Make sure we store the ad version (to track data changes).
    422435     *
  • advanced-ads/trunk/includes/class-constants.php

    r3253289 r3283205  
    118118    const AD_META_EXPIRATION_TIME = 'advanced_ads_expiration_time';
    119119
     120    /**
     121     * Ad metakey for group ids.
     122     *
     123     * @var string
     124     */
     125    const AD_META_GROUP_IDS = 'advanced_ads_ad_group_ids';
     126
    120127    /* User Meta Keys ------------------- */
    121128
  • advanced-ads/trunk/includes/class-upgrades.php

    r3253289 r3283205  
    2020class Upgrades extends Updates implements Initializer_Interface {
    2121
    22     const DB_VERSION = '1.53.0';
     22    const DB_VERSION = '1.53.1';
    2323
    2424    /**
     
    3535            '1.52.1' => 'upgrade-1.52.1.php',
    3636            '2.0.0'  => 'upgrade-2.0.0.php',
     37            '2.0.8'  => 'upgrade-2.0.8.php',
    3738        ];
    3839    }
  • advanced-ads/trunk/includes/groups/class-group-repository.php

    r3265208 r3283205  
    113113        // Only update weights when there is a change.
    114114        if ( in_array( 'ad_weights', $changed, true ) ) {
    115             $this->update_ads_terms( $group );
     115            ( new Group_Ad_Relation() )->relate( $group );
    116116        }
    117117
     
    273273
    274274    /**
    275      * Update group ad terms.
    276      *
    277      * @param Group $group Group object.
    278      *
    279      * @return void
    280      */
    281     private function update_ads_terms( &$group ): void {
    282         // Early bail!!
    283         if ( empty( $group->get_ad_weights() ) ) {
    284             return;
    285         }
    286 
    287         $data    = $group->get_data();
    288         $changes = $group->get_changes();
    289         $old_ads = $data['ad_weights'] ? array_keys( $data['ad_weights'] ) : [];
    290         $new_ads = $changes['ad_weights'] ? array_keys( $changes['ad_weights'] ) : [];
    291         $removed = array_diff( $old_ads, $new_ads );
    292 
    293         foreach ( $removed as $ad_id ) {
    294             $terms = wp_get_object_terms( $ad_id, Constants::TAXONOMY_GROUP );
    295 
    296             if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
    297                 $term_ids = wp_list_pluck( $terms, 'term_id' );
    298                 $term_ids = array_diff( $term_ids, [ $group->get_id() ] );
    299                 wp_set_object_terms( $ad_id, $term_ids, Constants::TAXONOMY_GROUP );
    300             }
    301         }
    302 
    303         $new_ads_final = $changes['ad_weights'] ?? [];
    304 
    305         foreach ( $new_ads as $ad_id ) {
    306             /**
    307              * Check if this ad is representing the current group and remove it in this case
    308              * could cause an infinite loop otherwise
    309              */
    310             $ad = wp_advads_get_ad( $ad_id );
    311             if ( $ad && $ad->is_type( 'group' ) && $ad->get_group_id() === $group->get_id() ) {
    312                 unset( $new_ads_final[ $ad_id ] );
    313                 continue;
    314             }
    315 
    316             $terms = wp_get_object_terms( $ad_id, Constants::TAXONOMY_GROUP );
    317 
    318             if ( ! is_wp_error( $terms ) ) {
    319                 $term_ids   = wp_list_pluck( $terms, 'term_id' );
    320                 $term_ids[] = $group->get_id();
    321                 $term_ids   = array_unique( $term_ids );
    322                 wp_set_object_terms( $ad_id, $term_ids, Constants::TAXONOMY_GROUP );
    323             }
    324         }
    325 
    326         $group->set_ad_weights( $new_ads_final );
    327     }
    328 
    329     /**
    330275     * Migrate values to new version
    331276     *
  • advanced-ads/trunk/languages/advanced-ads.pot

    r3269753 r3283205  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Advanced Ads 2.0.6\n"
     5"Project-Id-Version: Advanced Ads 2.0.7\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/advanced-ads\n"
    77"Last-Translator: Thomas Maier <[email protected]>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2025-04-09T05:01:12+00:00\n"
     12"POT-Creation-Date: 2025-04-28T07:32:04+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.11.0\n"
     
    11831183
    11841184#: classes/display-conditions.php:729
    1185 #: includes/abstracts/abstract-ad.php:832
     1185#: includes/abstracts/abstract-ad.php:830
    11861186#: includes/admin/class-groups-list-table.php:362
    11871187#: views/admin/placements/quick-edit.php:16
     
    15511551
    15521552#. translators: %s is a date.
    1553 #: includes/abstracts/abstract-ad.php:806
     1553#: includes/abstracts/abstract-ad.php:804
    15541554msgid "starts %s"
    15551555msgstr ""
    15561556
    15571557#. translators: %s is a date.
    1558 #: includes/abstracts/abstract-ad.php:820
     1558#: includes/abstracts/abstract-ad.php:818
    15591559msgid "expires %s"
    15601560msgstr ""
    15611561
    15621562#. translators: %s is a date.
    1563 #: includes/abstracts/abstract-ad.php:826
     1563#: includes/abstracts/abstract-ad.php:824
    15641564msgid "expired %s"
    15651565msgstr ""
    15661566
    1567 #: includes/abstracts/abstract-ad.php:835
     1567#: includes/abstracts/abstract-ad.php:833
    15681568#: includes/admin/class-placement-quick-edit.php:48
    15691569#: views/admin/placements/edit-modal/fields/status.php:13
     
    15731573msgstr ""
    15741574
    1575 #: includes/abstracts/abstract-ad.php:838
     1575#: includes/abstracts/abstract-ad.php:836
    15761576msgid "Trashed"
    15771577msgstr ""
    15781578
    15791579#. translators: %1$s is a placement name, %2$s is the ads name.
    1580 #: includes/abstracts/abstract-ad.php:1216
     1580#: includes/abstracts/abstract-ad.php:1213
    15811581msgid "Placement name: %1$s; Ads: %2$s"
    15821582msgstr ""
     
    21782178msgstr ""
    21792179
    2180 #: includes/admin/class-metabox-ad-settings.php:64
     2180#: includes/admin/class-metabox-ad-settings.php:63
    21812181msgid "Ad Settings"
    21822182msgstr ""
     
    29612961msgstr ""
    29622962
    2963 #: includes/ads/class-ad-repository.php:90
     2963#: includes/ads/class-ad-repository.php:91
    29642964msgid "Invalid ad."
    29652965msgstr ""
  • advanced-ads/trunk/packages/composer/autoload_classmap.php

    r3269753 r3283205  
    7373    'AdvancedAds\\Ads\\Ad_Factory' => $baseDir . '/includes/ads/class-ad-factory.php',
    7474    'AdvancedAds\\Ads\\Ad_Group' => $baseDir . '/includes/ads/class-ad-group.php',
     75    'AdvancedAds\\Ads\\Ad_Group_Relation' => $baseDir . '/includes/ads/class-ad-group-relation.php',
    7576    'AdvancedAds\\Ads\\Ad_Image' => $baseDir . '/includes/ads/class-ad-image.php',
    7677    'AdvancedAds\\Ads\\Ad_Plain' => $baseDir . '/includes/ads/class-ad-plain.php',
     
    132133    'AdvancedAds\\Frontend\\Scripts' => $baseDir . '/includes/frontend/class-scripts.php',
    133134    'AdvancedAds\\Frontend\\Stats' => $baseDir . '/includes/frontend/class-stats.php',
     135    'AdvancedAds\\Groups\\Group_Ad_Relation' => $baseDir . '/includes/groups/class-group-ad-relation.php',
    134136    'AdvancedAds\\Groups\\Group_Factory' => $baseDir . '/includes/groups/class-group-factory.php',
    135137    'AdvancedAds\\Groups\\Group_Ordered' => $baseDir . '/includes/groups/class-group-ordered.php',
  • advanced-ads/trunk/packages/composer/autoload_static.php

    r3269753 r3283205  
    100100        'AdvancedAds\\Ads\\Ad_Factory' => __DIR__ . '/../..' . '/includes/ads/class-ad-factory.php',
    101101        'AdvancedAds\\Ads\\Ad_Group' => __DIR__ . '/../..' . '/includes/ads/class-ad-group.php',
     102        'AdvancedAds\\Ads\\Ad_Group_Relation' => __DIR__ . '/../..' . '/includes/ads/class-ad-group-relation.php',
    102103        'AdvancedAds\\Ads\\Ad_Image' => __DIR__ . '/../..' . '/includes/ads/class-ad-image.php',
    103104        'AdvancedAds\\Ads\\Ad_Plain' => __DIR__ . '/../..' . '/includes/ads/class-ad-plain.php',
     
    159160        'AdvancedAds\\Frontend\\Scripts' => __DIR__ . '/../..' . '/includes/frontend/class-scripts.php',
    160161        'AdvancedAds\\Frontend\\Stats' => __DIR__ . '/../..' . '/includes/frontend/class-stats.php',
     162        'AdvancedAds\\Groups\\Group_Ad_Relation' => __DIR__ . '/../..' . '/includes/groups/class-group-ad-relation.php',
    161163        'AdvancedAds\\Groups\\Group_Factory' => __DIR__ . '/../..' . '/includes/groups/class-group-factory.php',
    162164        'AdvancedAds\\Groups\\Group_Ordered' => __DIR__ . '/../..' . '/includes/groups/class-group-ordered.php',
  • advanced-ads/trunk/readme.txt

    r3269753 r3283205  
    55Tested up to: 6.7
    66Requires PHP: 7.4
    7 Stable tag: 2.0.7
     7Stable tag: 2.0.8
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    361361== Changelog ==
    362362
     363= 2.0.8 (April 28, 2025) =
     364
     365- Improvement: type safety in `add_body_class` to prevent issues from third-party filters
     366- Improvement: improve the ad and group relation both way
     367- Fix: expiry date not updating for ads that already had one set
     368
    363369= 2.0.7 (April 9, 2025) =
    364370- Improvement: optimize MailPoet compatibility
Note: See TracChangeset for help on using the changeset viewer.