PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.26
Advanced Ads – Ad Manager & AdSense v2.0.26
2.0.26 2.0.25 2.0.24 2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / includes / admin / class-post-types.php
advanced-ads / includes / admin Last commit date
ads 3 weeks ago groups 3 weeks ago metaboxes 3 weeks ago pages 3 weeks ago placements 3 weeks ago class-action-links.php 3 weeks ago class-addon-box.php 3 weeks ago class-addon-updater.php 3 weeks ago class-admin-menu.php 3 weeks ago class-admin-notices.php 1 year ago class-ajax.php 3 weeks ago class-app.php 1 month ago class-assets.php 3 weeks ago class-authors.php 3 weeks ago class-edd-updater.php 3 weeks ago class-license-admin-post.php 3 weeks ago class-list-filters.php 3 weeks ago class-marketing.php 3 weeks ago class-metabox-ad-settings.php 1 year ago class-metabox-ad.php 3 weeks ago class-misc.php 3 weeks ago class-page-quick-edit.php 1 month ago class-plugin-auto-update.php 1 month ago class-plugin-installer.php 3 weeks ago class-post-list.php 3 weeks ago class-post-types.php 3 weeks ago class-screen-options.php 3 weeks ago class-settings.php 3 weeks ago class-shortcode-creator.php 3 weeks ago class-system-info.php 1 year ago class-tinymce.php 2 years ago class-translation-promo.php 3 weeks ago class-upgrades.php 3 weeks ago class-version-control.php 3 weeks ago class-welcome.php 1 year ago class-wordpress-dashboard.php 1 year ago index.php 2 years ago
class-post-types.php
195 lines
1 <?php
2 /**
3 * The class is responsible for handling the edit posts views and some functionality on the edit post screen.
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.48.2
8 */
9
10 namespace AdvancedAds\Admin;
11
12 use AdvancedAds\Constants;
13 use AdvancedAds\Framework\Interfaces\Integration_Interface;
14 use AdvancedAds\Framework\Utilities\Params;
15 use stdClass;
16
17 defined( 'ABSPATH' ) || exit;
18
19 /**
20 * Post Types.
21 */
22 class Post_Types implements Integration_Interface {
23
24 /**
25 * Hook into WordPress.
26 *
27 * @return void
28 */
29 public function hooks(): void {
30 add_action( 'before_delete_post', [ $this, 'before_delete_ad' ], 10, 2 );
31
32 add_filter( 'post_updated_messages', [ $this, 'post_updated_messages' ] );
33 add_filter( 'bulk_post_updated_messages', [ $this, 'bulk_post_updated_messages' ], 10, 2 );
34
35 add_filter( 'wp_count_posts', [ $this, 'update_count_posts' ], 10, 2 );
36 add_filter( 'get_edit_post_link', [ $this, 'get_edit_post_link' ], 10, 2 );
37 }
38
39 /**
40 * Prepare the ad groups for ad deletion
41 *
42 * @param int $post_id id of the post.
43 * @param WP_Post $post Post object.
44 *
45 * @return void
46 */
47 public function before_delete_ad( $post_id, $post ): void {
48 global $wpdb;
49
50 if (
51 ! current_user_can( 'delete_posts' )
52 || $post_id <= 0
53 || Constants::POST_TYPE_AD !== $post->post_type
54 ) {
55 return;
56 }
57
58 /**
59 * Images uploaded to an image ad type get the `_advanced-ads_parent_id` meta key from WordPress automatically
60 * the following SQL query removes that meta data from any attachment when the ad is removed.
61 */
62 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", '_advanced-ads_parent_id', $post_id ) ); // phpcs:ignore
63
64 foreach ( wp_advads_get_groups_by_ad_id( $post_id ) as $group ) {
65 $ad_weights = $group->get_ad_weights();
66 unset( $ad_weights[ $post_id ] );
67 $group->set_ad_weights( $ad_weights );
68 $group->save();
69 }
70 }
71
72 /**
73 * Update post counts to have expiring ads.
74 *
75 * @param stdClass $counts An object containing the current post_type's post
76 * counts by status.
77 * @param string $type Post type.
78 *
79 * @return stdClass
80 */
81 public function update_count_posts( $counts, $type ): stdClass {
82 if ( Constants::POST_TYPE_AD !== $type ) {
83 return $counts;
84 }
85
86 $now = time();
87 $expiring = 0;
88
89 foreach ( wp_advads_get_ad_summaries() as $summary ) {
90 if ( ! empty( $summary['expiry_date'] ) && $summary['expiry_date'] > $now ) {
91 ++$expiring;
92 }
93 }
94
95 $counts->{Constants::AD_STATUS_EXPIRING} = $expiring;
96
97 return $counts;
98 }
99
100 /**
101 * Change messages when a post type is updated.
102 *
103 * @since 1.4.7
104 *
105 * @param array<string, array<int, string>> $messages Existing post update messages.
106 *
107 * @return array<string, array<int, string>>
108 */
109 public function post_updated_messages( $messages = [] ): array {
110 global $post;
111
112 // Added to fix error message array caused by third party code that uses post_updated_messages filter wrong.
113 if ( ! is_array( $messages ) ) {
114 $messages = [];
115 }
116
117 $revision = Params::get( 'revision', 0, FILTER_VALIDATE_INT );
118
119 $messages[ Constants::POST_TYPE_AD ] = [
120 0 => '', // Unused. Messages start at index 1.
121 1 => __( 'Ad updated.', 'advanced-ads' ),
122 4 => __( 'Ad updated.', 'advanced-ads' ),
123 5 => $revision
124 /* translators: %s: date and time of the revision */
125 ? sprintf( __( 'Ad restored to revision from %s', 'advanced-ads' ), wp_post_revision_title( $revision, false ) )
126 : false,
127 6 => __( 'Ad saved.', 'advanced-ads' ),
128 7 => __( 'Ad saved.', 'advanced-ads' ),
129 8 => __( 'Ad submitted.', 'advanced-ads' ),
130 9 => sprintf(
131 /* translators: %s: date */
132 __( 'Ad scheduled for: <strong>%1$s</strong>.', 'advanced-ads' ),
133 '<strong>' . date_i18n( __( 'M j, Y @ G:i', 'advanced-ads' ), strtotime( $post->post_date ) ) . '</strong>'
134 ),
135 10 => __( 'Ad draft updated.', 'advanced-ads' ),
136 ];
137
138 return $messages;
139 }
140
141 /**
142 * Edit ad bulk update messages
143 *
144 * @param array<string, array<string, string>> $messages Existing bulk update messages.
145 * @param array<string, int> $counts Numbers of updated ads.
146 *
147 * @return array<string, array<string, string>>
148 */
149 public function bulk_post_updated_messages( array $messages, array $counts ): array {
150 $messages[ Constants::POST_TYPE_AD ] = [
151 /* translators: %s: ad count */
152 'updated' => _n( '%s ad updated.', '%s ads updated.', $counts['updated'], 'advanced-ads' ),
153 /* translators: %s: ad count */
154 'locked' => _n( '%s ad not updated, somebody is editing it.', '%s ads not updated, somebody is editing them.', $counts['locked'], 'advanced-ads' ),
155 /* translators: %s: ad count */
156 'deleted' => _n( '%s ad permanently deleted.', '%s ads permanently deleted.', $counts['deleted'], 'advanced-ads' ),
157 /* translators: %s: ad count */
158 'trashed' => _n( '%s ad moved to the Trash.', '%s ads moved to the Trash.', $counts['trashed'], 'advanced-ads' ),
159 /* translators: %s: ad count */
160 'untrashed' => _n( '%s ad restored from the Trash.', '%s ads restored from the Trash.', $counts['untrashed'], 'advanced-ads' ),
161 ];
162
163 $messages[ Constants::POST_TYPE_PLACEMENT ] = [
164 /* translators: %s: placement count */
165 'updated' => _n( '%s placement updated.', '%s placements updated.', $counts['updated'], 'advanced-ads' ),
166 /* translators: %s: placement count */
167 'locked' => _n( '%s placement not updated, somebody is editing it.', '%s placements not updated, somebody is editing them.', $counts['locked'], 'advanced-ads' ),
168 /* translators: %s: placement count */
169 'deleted' => _n( '%s placement permanently deleted.', '%s placements permanently deleted.', $counts['deleted'], 'advanced-ads' ),
170 /* translators: %s: placement count */
171 'trashed' => _n( '%s placement moved to the Trash.', '%s placements moved to the Trash.', $counts['trashed'], 'advanced-ads' ),
172 /* translators: %s: placement count */
173 'untrashed' => _n( '%s placement restored from the Trash.', '%s placements restored from the Trash.', $counts['untrashed'], 'advanced-ads' ),
174 ];
175
176 return $messages;
177 }
178
179 /**
180 * Replace the edit link with a link to the modal to edit the placement.
181 *
182 * @param string $link The previous link.
183 * @param int $post_id The \WP_Post::$ID for the current item.
184 *
185 * @return string
186 */
187 public function get_edit_post_link( string $link, int $post_id ): string {
188 if ( Constants::POST_TYPE_PLACEMENT === get_post_type( $post_id ) ) {
189 return admin_url( 'edit.php?post_type=' . Constants::POST_TYPE_PLACEMENT . '#modal-placement-edit-' . $post_id );
190 }
191
192 return $link;
193 }
194 }
195