Changeset 3283205
- Timestamp:
- 04/28/2025 08:28:54 AM (8 months ago)
- Location:
- advanced-ads
- Files:
-
- 8 added
- 28 edited
- 1 copied
-
tags/2.0.8 (copied) (copied from advanced-ads/trunk)
-
tags/2.0.8/advanced-ads.php (modified) (2 diffs)
-
tags/2.0.8/includes/abstracts/abstract-ad.php (modified) (4 diffs)
-
tags/2.0.8/includes/admin/class-admin-menu.php (modified) (1 diff)
-
tags/2.0.8/includes/admin/class-metabox-ad-settings.php (modified) (2 diffs)
-
tags/2.0.8/includes/admin/class-quick-bulk-edit.php (modified) (3 diffs)
-
tags/2.0.8/includes/admin/pages/class-ads-editing.php (modified) (2 diffs)
-
tags/2.0.8/includes/ads/class-ad-group-relation.php (added)
-
tags/2.0.8/includes/ads/class-ad-repository.php (modified) (3 diffs)
-
tags/2.0.8/includes/class-constants.php (modified) (1 diff)
-
tags/2.0.8/includes/class-upgrades.php (modified) (2 diffs)
-
tags/2.0.8/includes/groups/class-group-ad-relation.php (added)
-
tags/2.0.8/includes/groups/class-group-repository.php (modified) (2 diffs)
-
tags/2.0.8/languages/advanced-ads.pot (modified) (7 diffs)
-
tags/2.0.8/packages/composer/autoload_classmap.php (modified) (2 diffs)
-
tags/2.0.8/packages/composer/autoload_static.php (modified) (2 diffs)
-
tags/2.0.8/readme.txt (modified) (2 diffs)
-
tags/2.0.8/upgrades/upgrade-2.0.8.php (added)
-
tags/2.0.8/wp.advads (added)
-
trunk/advanced-ads.php (modified) (2 diffs)
-
trunk/includes/abstracts/abstract-ad.php (modified) (4 diffs)
-
trunk/includes/admin/class-admin-menu.php (modified) (1 diff)
-
trunk/includes/admin/class-metabox-ad-settings.php (modified) (2 diffs)
-
trunk/includes/admin/class-quick-bulk-edit.php (modified) (3 diffs)
-
trunk/includes/admin/pages/class-ads-editing.php (modified) (2 diffs)
-
trunk/includes/ads/class-ad-group-relation.php (added)
-
trunk/includes/ads/class-ad-repository.php (modified) (3 diffs)
-
trunk/includes/class-constants.php (modified) (1 diff)
-
trunk/includes/class-upgrades.php (modified) (2 diffs)
-
trunk/includes/groups/class-group-ad-relation.php (added)
-
trunk/includes/groups/class-group-repository.php (modified) (2 diffs)
-
trunk/languages/advanced-ads.pot (modified) (7 diffs)
-
trunk/packages/composer/autoload_classmap.php (modified) (2 diffs)
-
trunk/packages/composer/autoload_static.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/upgrades/upgrade-2.0.8.php (added)
-
trunk/wp.advads (added)
Legend:
- Unmodified
- Added
- Removed
-
advanced-ads/tags/2.0.8/advanced-ads.php
r3269753 r3283205 11 11 * @wordpress-plugin 12 12 * Plugin Name: Advanced Ads 13 * Version: 2.0. 713 * Version: 2.0.8 14 14 * Description: Manage and optimize your ads in WordPress 15 15 * Plugin URI: https://wpadvancedads.com … … 38 38 39 39 define( 'ADVADS_FILE', __FILE__ ); 40 define( 'ADVADS_VERSION', '2.0. 7' );40 define( 'ADVADS_VERSION', '2.0.8' ); 41 41 42 42 // Load the autoloader. -
advanced-ads/tags/2.0.8/includes/abstracts/abstract-ad.php
r3259235 r3283205 14 14 use Advanced_Ads_Utils; 15 15 use Advanced_Ads_Visitor_Conditions; 16 use AdvancedAds\ Compatibility\Compatibility;16 use AdvancedAds\Traits; 17 17 use AdvancedAds\Constants; 18 use AdvancedAds\Framework\Utilities\Arr;19 use AdvancedAds\Framework\Utilities\Formatting;20 use AdvancedAds\Framework\Utilities\Str;21 18 use AdvancedAds\Frontend\Stats; 22 19 use AdvancedAds\Interfaces\Ad_Type; 23 use AdvancedAds\ Traits;20 use AdvancedAds\Utilities\WordPress; 24 21 use AdvancedAds\Utilities\Conditional; 25 use AdvancedAds\Utilities\WordPress; 26 use DateInterval; 27 use DateTime; 22 use AdvancedAds\Framework\Utilities\Arr; 23 use AdvancedAds\Framework\Utilities\Str; 24 use AdvancedAds\Compatibility\Compatibility; 25 use AdvancedAds\Framework\Utilities\Formatting; 28 26 29 27 defined( 'ABSPATH' ) || exit; … … 789 787 */ 790 788 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() ); 791 792 $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';795 793 796 794 $status_type = get_post_status( $this->get_id() ) ?? 'published'; … … 810 808 $expiry = $this->get_expiry_date(); 811 809 $expiry_date = date_create( '@' . $expiry ); 812 $expiry_date->setTimezone( WordPress::get_timezone() );810 $expiry_date->setTimezone( new \DateTimeZone( 'UTC' ) ); 813 811 $html_classes .= ' advads-filter-any-exp-date'; 814 812 … … 900 898 } 901 899 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' ) ); 904 901 $gm_date = $expiration_date->format( 'Y-m-d-H-i' ); 905 902 -
advanced-ads/tags/2.0.8/includes/admin/class-admin-menu.php
r3253289 r3283205 247 247 * @return string 248 248 */ 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 : ''; 250 252 $screen_ids = $this->get_screen_ids(); 251 253 $wp_screen = get_current_screen(); -
advanced-ads/tags/2.0.8/includes/admin/class-metabox-ad-settings.php
r3253289 r3283205 40 40 add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] ); 41 41 add_action( 'save_post', [ $this, 'save_settings' ], 10, 2 ); 42 add_action( 'set_object_terms', [ $this, 'set_group_terms' ], 10, 6 );43 42 } 44 43 … … 132 131 update_post_meta( $post_id, self::SETTING_METAKEY, $data ); 133 132 } 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 void147 */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 void164 */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 void187 */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 }203 133 } -
advanced-ads/tags/2.0.8/includes/admin/class-quick-bulk-edit.php
r3269753 r3283205 196 196 197 197 try { 198 $date = new DateTime( 'now', wp_timezone() );198 $date = new DateTime( 'now', new \DateTimeZone( 'UTC' ) ); 199 199 $date->setDate( $year, $month, $day ); 200 200 $date->setTime( $hours, $minutes ); … … 276 276 public static function print_date_time_inputs( $timestamp = 0, $prefix = '', $seconds = false ) { 277 277 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(); 279 279 } catch ( Exception $e ) { 280 280 $initial_date = current_datetime(); … … 341 341 if ( $expiry ) { 342 342 $expiry_date = array_combine( 343 [ 'year', 'month', 'day', 'hour', 'minute s' ],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' ) ) ) 345 345 ); 346 346 } -
advanced-ads/tags/2.0.8/includes/admin/pages/class-ads-editing.php
r3259235 r3283205 10 10 namespace AdvancedAds\Admin\Pages; 11 11 12 use DateTimeImmutable; 12 13 use AdvancedAds\Constants; 14 use AdvancedAds\Utilities\WordPress; 13 15 use AdvancedAds\Framework\Utilities\Params; 14 use AdvancedAds\Utilities\WordPress;15 use DateTime;16 16 17 17 defined( 'ABSPATH' ) || exit; … … 158 158 // Get time set for ad or current timestamp (both GMT). 159 159 $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' ) ); 162 161 [ $curr_year, $curr_month, $curr_day, $curr_hour, $curr_minute ] = explode( '-', $utc_time->format( 'Y-m-d-H-i' ) ); 163 162 $enabled = 1 - empty( $ad->get_expiry_date() ); -
advanced-ads/tags/2.0.8/includes/ads/class-ad-repository.php
r3257709 r3283205 67 67 68 68 $this->update_post_meta( $ad ); 69 $this->update_post_term( $ad ); 69 70 $this->update_version( $ad ); 70 71 … … 164 165 165 166 $this->update_post_meta( $ad ); 167 $this->update_post_term( $ad ); 166 168 167 169 $ad->apply_changes(); … … 419 421 420 422 /** 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 /** 421 434 * Make sure we store the ad version (to track data changes). 422 435 * -
advanced-ads/tags/2.0.8/includes/class-constants.php
r3253289 r3283205 118 118 const AD_META_EXPIRATION_TIME = 'advanced_ads_expiration_time'; 119 119 120 /** 121 * Ad metakey for group ids. 122 * 123 * @var string 124 */ 125 const AD_META_GROUP_IDS = 'advanced_ads_ad_group_ids'; 126 120 127 /* User Meta Keys ------------------- */ 121 128 -
advanced-ads/tags/2.0.8/includes/class-upgrades.php
r3253289 r3283205 20 20 class Upgrades extends Updates implements Initializer_Interface { 21 21 22 const DB_VERSION = '1.53. 0';22 const DB_VERSION = '1.53.1'; 23 23 24 24 /** … … 35 35 '1.52.1' => 'upgrade-1.52.1.php', 36 36 '2.0.0' => 'upgrade-2.0.0.php', 37 '2.0.8' => 'upgrade-2.0.8.php', 37 38 ]; 38 39 } -
advanced-ads/tags/2.0.8/includes/groups/class-group-repository.php
r3265208 r3283205 113 113 // Only update weights when there is a change. 114 114 if ( in_array( 'ad_weights', $changed, true ) ) { 115 $this->update_ads_terms( $group );115 ( new Group_Ad_Relation() )->relate( $group ); 116 116 } 117 117 … … 273 273 274 274 /** 275 * Update group ad terms.276 *277 * @param Group $group Group object.278 *279 * @return void280 */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 case308 * could cause an infinite loop otherwise309 */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 /**330 275 * Migrate values to new version 331 276 * -
advanced-ads/tags/2.0.8/languages/advanced-ads.pot
r3269753 r3283205 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Advanced Ads 2.0. 6\n"5 "Project-Id-Version: Advanced Ads 2.0.7\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/advanced-ads\n" 7 7 "Last-Translator: Thomas Maier <[email protected]>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "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" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.11.0\n" … … 1183 1183 1184 1184 #: classes/display-conditions.php:729 1185 #: includes/abstracts/abstract-ad.php:83 21185 #: includes/abstracts/abstract-ad.php:830 1186 1186 #: includes/admin/class-groups-list-table.php:362 1187 1187 #: views/admin/placements/quick-edit.php:16 … … 1551 1551 1552 1552 #. translators: %s is a date. 1553 #: includes/abstracts/abstract-ad.php:80 61553 #: includes/abstracts/abstract-ad.php:804 1554 1554 msgid "starts %s" 1555 1555 msgstr "" 1556 1556 1557 1557 #. translators: %s is a date. 1558 #: includes/abstracts/abstract-ad.php:8 201558 #: includes/abstracts/abstract-ad.php:818 1559 1559 msgid "expires %s" 1560 1560 msgstr "" 1561 1561 1562 1562 #. translators: %s is a date. 1563 #: includes/abstracts/abstract-ad.php:82 61563 #: includes/abstracts/abstract-ad.php:824 1564 1564 msgid "expired %s" 1565 1565 msgstr "" 1566 1566 1567 #: includes/abstracts/abstract-ad.php:83 51567 #: includes/abstracts/abstract-ad.php:833 1568 1568 #: includes/admin/class-placement-quick-edit.php:48 1569 1569 #: views/admin/placements/edit-modal/fields/status.php:13 … … 1573 1573 msgstr "" 1574 1574 1575 #: includes/abstracts/abstract-ad.php:83 81575 #: includes/abstracts/abstract-ad.php:836 1576 1576 msgid "Trashed" 1577 1577 msgstr "" 1578 1578 1579 1579 #. translators: %1$s is a placement name, %2$s is the ads name. 1580 #: includes/abstracts/abstract-ad.php:121 61580 #: includes/abstracts/abstract-ad.php:1213 1581 1581 msgid "Placement name: %1$s; Ads: %2$s" 1582 1582 msgstr "" … … 2178 2178 msgstr "" 2179 2179 2180 #: includes/admin/class-metabox-ad-settings.php:6 42180 #: includes/admin/class-metabox-ad-settings.php:63 2181 2181 msgid "Ad Settings" 2182 2182 msgstr "" … … 2961 2961 msgstr "" 2962 2962 2963 #: includes/ads/class-ad-repository.php:9 02963 #: includes/ads/class-ad-repository.php:91 2964 2964 msgid "Invalid ad." 2965 2965 msgstr "" -
advanced-ads/tags/2.0.8/packages/composer/autoload_classmap.php
r3269753 r3283205 73 73 'AdvancedAds\\Ads\\Ad_Factory' => $baseDir . '/includes/ads/class-ad-factory.php', 74 74 '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', 75 76 'AdvancedAds\\Ads\\Ad_Image' => $baseDir . '/includes/ads/class-ad-image.php', 76 77 'AdvancedAds\\Ads\\Ad_Plain' => $baseDir . '/includes/ads/class-ad-plain.php', … … 132 133 'AdvancedAds\\Frontend\\Scripts' => $baseDir . '/includes/frontend/class-scripts.php', 133 134 'AdvancedAds\\Frontend\\Stats' => $baseDir . '/includes/frontend/class-stats.php', 135 'AdvancedAds\\Groups\\Group_Ad_Relation' => $baseDir . '/includes/groups/class-group-ad-relation.php', 134 136 'AdvancedAds\\Groups\\Group_Factory' => $baseDir . '/includes/groups/class-group-factory.php', 135 137 'AdvancedAds\\Groups\\Group_Ordered' => $baseDir . '/includes/groups/class-group-ordered.php', -
advanced-ads/tags/2.0.8/packages/composer/autoload_static.php
r3269753 r3283205 100 100 'AdvancedAds\\Ads\\Ad_Factory' => __DIR__ . '/../..' . '/includes/ads/class-ad-factory.php', 101 101 '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', 102 103 'AdvancedAds\\Ads\\Ad_Image' => __DIR__ . '/../..' . '/includes/ads/class-ad-image.php', 103 104 'AdvancedAds\\Ads\\Ad_Plain' => __DIR__ . '/../..' . '/includes/ads/class-ad-plain.php', … … 159 160 'AdvancedAds\\Frontend\\Scripts' => __DIR__ . '/../..' . '/includes/frontend/class-scripts.php', 160 161 'AdvancedAds\\Frontend\\Stats' => __DIR__ . '/../..' . '/includes/frontend/class-stats.php', 162 'AdvancedAds\\Groups\\Group_Ad_Relation' => __DIR__ . '/../..' . '/includes/groups/class-group-ad-relation.php', 161 163 'AdvancedAds\\Groups\\Group_Factory' => __DIR__ . '/../..' . '/includes/groups/class-group-factory.php', 162 164 'AdvancedAds\\Groups\\Group_Ordered' => __DIR__ . '/../..' . '/includes/groups/class-group-ordered.php', -
advanced-ads/tags/2.0.8/readme.txt
r3269753 r3283205 5 5 Tested up to: 6.7 6 6 Requires PHP: 7.4 7 Stable tag: 2.0. 77 Stable tag: 2.0.8 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 361 361 == Changelog == 362 362 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 363 369 = 2.0.7 (April 9, 2025) = 364 370 - Improvement: optimize MailPoet compatibility -
advanced-ads/trunk/advanced-ads.php
r3269753 r3283205 11 11 * @wordpress-plugin 12 12 * Plugin Name: Advanced Ads 13 * Version: 2.0. 713 * Version: 2.0.8 14 14 * Description: Manage and optimize your ads in WordPress 15 15 * Plugin URI: https://wpadvancedads.com … … 38 38 39 39 define( 'ADVADS_FILE', __FILE__ ); 40 define( 'ADVADS_VERSION', '2.0. 7' );40 define( 'ADVADS_VERSION', '2.0.8' ); 41 41 42 42 // Load the autoloader. -
advanced-ads/trunk/includes/abstracts/abstract-ad.php
r3259235 r3283205 14 14 use Advanced_Ads_Utils; 15 15 use Advanced_Ads_Visitor_Conditions; 16 use AdvancedAds\ Compatibility\Compatibility;16 use AdvancedAds\Traits; 17 17 use AdvancedAds\Constants; 18 use AdvancedAds\Framework\Utilities\Arr;19 use AdvancedAds\Framework\Utilities\Formatting;20 use AdvancedAds\Framework\Utilities\Str;21 18 use AdvancedAds\Frontend\Stats; 22 19 use AdvancedAds\Interfaces\Ad_Type; 23 use AdvancedAds\ Traits;20 use AdvancedAds\Utilities\WordPress; 24 21 use AdvancedAds\Utilities\Conditional; 25 use AdvancedAds\Utilities\WordPress; 26 use DateInterval; 27 use DateTime; 22 use AdvancedAds\Framework\Utilities\Arr; 23 use AdvancedAds\Framework\Utilities\Str; 24 use AdvancedAds\Compatibility\Compatibility; 25 use AdvancedAds\Framework\Utilities\Formatting; 28 26 29 27 defined( 'ABSPATH' ) || exit; … … 789 787 */ 790 788 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() ); 791 792 $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';795 793 796 794 $status_type = get_post_status( $this->get_id() ) ?? 'published'; … … 810 808 $expiry = $this->get_expiry_date(); 811 809 $expiry_date = date_create( '@' . $expiry ); 812 $expiry_date->setTimezone( WordPress::get_timezone() );810 $expiry_date->setTimezone( new \DateTimeZone( 'UTC' ) ); 813 811 $html_classes .= ' advads-filter-any-exp-date'; 814 812 … … 900 898 } 901 899 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' ) ); 904 901 $gm_date = $expiration_date->format( 'Y-m-d-H-i' ); 905 902 -
advanced-ads/trunk/includes/admin/class-admin-menu.php
r3253289 r3283205 247 247 * @return string 248 248 */ 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 : ''; 250 252 $screen_ids = $this->get_screen_ids(); 251 253 $wp_screen = get_current_screen(); -
advanced-ads/trunk/includes/admin/class-metabox-ad-settings.php
r3253289 r3283205 40 40 add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] ); 41 41 add_action( 'save_post', [ $this, 'save_settings' ], 10, 2 ); 42 add_action( 'set_object_terms', [ $this, 'set_group_terms' ], 10, 6 );43 42 } 44 43 … … 132 131 update_post_meta( $post_id, self::SETTING_METAKEY, $data ); 133 132 } 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 void147 */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 void164 */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 void187 */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 }203 133 } -
advanced-ads/trunk/includes/admin/class-quick-bulk-edit.php
r3269753 r3283205 196 196 197 197 try { 198 $date = new DateTime( 'now', wp_timezone() );198 $date = new DateTime( 'now', new \DateTimeZone( 'UTC' ) ); 199 199 $date->setDate( $year, $month, $day ); 200 200 $date->setTime( $hours, $minutes ); … … 276 276 public static function print_date_time_inputs( $timestamp = 0, $prefix = '', $seconds = false ) { 277 277 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(); 279 279 } catch ( Exception $e ) { 280 280 $initial_date = current_datetime(); … … 341 341 if ( $expiry ) { 342 342 $expiry_date = array_combine( 343 [ 'year', 'month', 'day', 'hour', 'minute s' ],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' ) ) ) 345 345 ); 346 346 } -
advanced-ads/trunk/includes/admin/pages/class-ads-editing.php
r3259235 r3283205 10 10 namespace AdvancedAds\Admin\Pages; 11 11 12 use DateTimeImmutable; 12 13 use AdvancedAds\Constants; 14 use AdvancedAds\Utilities\WordPress; 13 15 use AdvancedAds\Framework\Utilities\Params; 14 use AdvancedAds\Utilities\WordPress;15 use DateTime;16 16 17 17 defined( 'ABSPATH' ) || exit; … … 158 158 // Get time set for ad or current timestamp (both GMT). 159 159 $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' ) ); 162 161 [ $curr_year, $curr_month, $curr_day, $curr_hour, $curr_minute ] = explode( '-', $utc_time->format( 'Y-m-d-H-i' ) ); 163 162 $enabled = 1 - empty( $ad->get_expiry_date() ); -
advanced-ads/trunk/includes/ads/class-ad-repository.php
r3257709 r3283205 67 67 68 68 $this->update_post_meta( $ad ); 69 $this->update_post_term( $ad ); 69 70 $this->update_version( $ad ); 70 71 … … 164 165 165 166 $this->update_post_meta( $ad ); 167 $this->update_post_term( $ad ); 166 168 167 169 $ad->apply_changes(); … … 419 421 420 422 /** 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 /** 421 434 * Make sure we store the ad version (to track data changes). 422 435 * -
advanced-ads/trunk/includes/class-constants.php
r3253289 r3283205 118 118 const AD_META_EXPIRATION_TIME = 'advanced_ads_expiration_time'; 119 119 120 /** 121 * Ad metakey for group ids. 122 * 123 * @var string 124 */ 125 const AD_META_GROUP_IDS = 'advanced_ads_ad_group_ids'; 126 120 127 /* User Meta Keys ------------------- */ 121 128 -
advanced-ads/trunk/includes/class-upgrades.php
r3253289 r3283205 20 20 class Upgrades extends Updates implements Initializer_Interface { 21 21 22 const DB_VERSION = '1.53. 0';22 const DB_VERSION = '1.53.1'; 23 23 24 24 /** … … 35 35 '1.52.1' => 'upgrade-1.52.1.php', 36 36 '2.0.0' => 'upgrade-2.0.0.php', 37 '2.0.8' => 'upgrade-2.0.8.php', 37 38 ]; 38 39 } -
advanced-ads/trunk/includes/groups/class-group-repository.php
r3265208 r3283205 113 113 // Only update weights when there is a change. 114 114 if ( in_array( 'ad_weights', $changed, true ) ) { 115 $this->update_ads_terms( $group );115 ( new Group_Ad_Relation() )->relate( $group ); 116 116 } 117 117 … … 273 273 274 274 /** 275 * Update group ad terms.276 *277 * @param Group $group Group object.278 *279 * @return void280 */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 case308 * could cause an infinite loop otherwise309 */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 /**330 275 * Migrate values to new version 331 276 * -
advanced-ads/trunk/languages/advanced-ads.pot
r3269753 r3283205 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Advanced Ads 2.0. 6\n"5 "Project-Id-Version: Advanced Ads 2.0.7\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/advanced-ads\n" 7 7 "Last-Translator: Thomas Maier <[email protected]>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "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" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.11.0\n" … … 1183 1183 1184 1184 #: classes/display-conditions.php:729 1185 #: includes/abstracts/abstract-ad.php:83 21185 #: includes/abstracts/abstract-ad.php:830 1186 1186 #: includes/admin/class-groups-list-table.php:362 1187 1187 #: views/admin/placements/quick-edit.php:16 … … 1551 1551 1552 1552 #. translators: %s is a date. 1553 #: includes/abstracts/abstract-ad.php:80 61553 #: includes/abstracts/abstract-ad.php:804 1554 1554 msgid "starts %s" 1555 1555 msgstr "" 1556 1556 1557 1557 #. translators: %s is a date. 1558 #: includes/abstracts/abstract-ad.php:8 201558 #: includes/abstracts/abstract-ad.php:818 1559 1559 msgid "expires %s" 1560 1560 msgstr "" 1561 1561 1562 1562 #. translators: %s is a date. 1563 #: includes/abstracts/abstract-ad.php:82 61563 #: includes/abstracts/abstract-ad.php:824 1564 1564 msgid "expired %s" 1565 1565 msgstr "" 1566 1566 1567 #: includes/abstracts/abstract-ad.php:83 51567 #: includes/abstracts/abstract-ad.php:833 1568 1568 #: includes/admin/class-placement-quick-edit.php:48 1569 1569 #: views/admin/placements/edit-modal/fields/status.php:13 … … 1573 1573 msgstr "" 1574 1574 1575 #: includes/abstracts/abstract-ad.php:83 81575 #: includes/abstracts/abstract-ad.php:836 1576 1576 msgid "Trashed" 1577 1577 msgstr "" 1578 1578 1579 1579 #. translators: %1$s is a placement name, %2$s is the ads name. 1580 #: includes/abstracts/abstract-ad.php:121 61580 #: includes/abstracts/abstract-ad.php:1213 1581 1581 msgid "Placement name: %1$s; Ads: %2$s" 1582 1582 msgstr "" … … 2178 2178 msgstr "" 2179 2179 2180 #: includes/admin/class-metabox-ad-settings.php:6 42180 #: includes/admin/class-metabox-ad-settings.php:63 2181 2181 msgid "Ad Settings" 2182 2182 msgstr "" … … 2961 2961 msgstr "" 2962 2962 2963 #: includes/ads/class-ad-repository.php:9 02963 #: includes/ads/class-ad-repository.php:91 2964 2964 msgid "Invalid ad." 2965 2965 msgstr "" -
advanced-ads/trunk/packages/composer/autoload_classmap.php
r3269753 r3283205 73 73 'AdvancedAds\\Ads\\Ad_Factory' => $baseDir . '/includes/ads/class-ad-factory.php', 74 74 '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', 75 76 'AdvancedAds\\Ads\\Ad_Image' => $baseDir . '/includes/ads/class-ad-image.php', 76 77 'AdvancedAds\\Ads\\Ad_Plain' => $baseDir . '/includes/ads/class-ad-plain.php', … … 132 133 'AdvancedAds\\Frontend\\Scripts' => $baseDir . '/includes/frontend/class-scripts.php', 133 134 'AdvancedAds\\Frontend\\Stats' => $baseDir . '/includes/frontend/class-stats.php', 135 'AdvancedAds\\Groups\\Group_Ad_Relation' => $baseDir . '/includes/groups/class-group-ad-relation.php', 134 136 'AdvancedAds\\Groups\\Group_Factory' => $baseDir . '/includes/groups/class-group-factory.php', 135 137 'AdvancedAds\\Groups\\Group_Ordered' => $baseDir . '/includes/groups/class-group-ordered.php', -
advanced-ads/trunk/packages/composer/autoload_static.php
r3269753 r3283205 100 100 'AdvancedAds\\Ads\\Ad_Factory' => __DIR__ . '/../..' . '/includes/ads/class-ad-factory.php', 101 101 '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', 102 103 'AdvancedAds\\Ads\\Ad_Image' => __DIR__ . '/../..' . '/includes/ads/class-ad-image.php', 103 104 'AdvancedAds\\Ads\\Ad_Plain' => __DIR__ . '/../..' . '/includes/ads/class-ad-plain.php', … … 159 160 'AdvancedAds\\Frontend\\Scripts' => __DIR__ . '/../..' . '/includes/frontend/class-scripts.php', 160 161 'AdvancedAds\\Frontend\\Stats' => __DIR__ . '/../..' . '/includes/frontend/class-stats.php', 162 'AdvancedAds\\Groups\\Group_Ad_Relation' => __DIR__ . '/../..' . '/includes/groups/class-group-ad-relation.php', 161 163 'AdvancedAds\\Groups\\Group_Factory' => __DIR__ . '/../..' . '/includes/groups/class-group-factory.php', 162 164 'AdvancedAds\\Groups\\Group_Ordered' => __DIR__ . '/../..' . '/includes/groups/class-group-ordered.php', -
advanced-ads/trunk/readme.txt
r3269753 r3283205 5 5 Tested up to: 6.7 6 6 Requires PHP: 7.4 7 Stable tag: 2.0. 77 Stable tag: 2.0.8 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 361 361 == Changelog == 362 362 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 363 369 = 2.0.7 (April 9, 2025) = 364 370 - Improvement: optimize MailPoet compatibility
Note: See TracChangeset
for help on using the changeset viewer.