PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.24
Advanced Ads – Ad Manager & AdSense v2.0.24
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 1 week ago groups 1 week ago metaboxes 1 year ago pages 3 months ago placements 1 week ago class-action-links.php 1 week ago class-addon-box.php 1 year ago class-addon-updater.php 3 months ago class-admin-menu.php 1 week ago class-admin-notices.php 1 year ago class-ajax.php 3 months ago class-assets.php 1 week ago class-authors.php 1 year ago class-edd-updater.php 1 month ago class-list-filters.php 1 week ago class-marketing.php 1 year ago class-metabox-ad-settings.php 1 year ago class-metabox-ad.php 1 year ago class-misc.php 1 week ago class-page-quick-edit.php 1 year ago class-plugin-installer.php 1 year ago class-post-list.php 1 year ago class-post-types.php 1 week ago class-screen-options.php 3 months ago class-settings.php 1 year ago class-shortcode-creator.php 1 year ago class-system-info.php 1 year ago class-tinymce.php 2 years ago class-translation-promo.php 1 year ago class-upgrades.php 1 year ago class-version-control.php 3 months ago class-welcome.php 1 year ago class-wordpress-dashboard.php 1 year ago index.php 2 years ago
class-post-types.php
206 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 stdClass;
13 use AdvancedAds\Constants;
14 use AdvancedAds\Framework\Utilities\Params;
15 use AdvancedAds\Framework\Interfaces\Integration_Interface;
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 *
44 * @return void
45 */
46 public function before_delete_ad( $post_id, $post ): void {
47 global $wpdb;
48
49 if ( ! current_user_can( 'delete_posts' ) ) {
50 return;
51 }
52
53 if ( $post_id > 0 ) {
54 if ( Constants::POST_TYPE_AD === $post->post_type ) {
55 /**
56 * Images uploaded to an image ad type get the `_advanced-ads_parent_id` meta key from WordPress automatically
57 * the following SQL query removes that meta data from any attachment when the ad is removed.
58 */
59 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", '_advanced-ads_parent_id', $post_id ) ); // phpcs:ignore
60
61 $terms = wp_get_object_terms( $post_id, Constants::TAXONOMY_GROUP );
62
63 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
64 $term_ids = wp_list_pluck( $terms, 'term_id' );
65
66 if( ! empty( $term_ids ) ) {
67 foreach( $term_ids as $group_id ) {
68 $group = wp_advads_get_group( $group_id );
69
70 $ad_weights = $group->get_ad_weights();
71
72 unset( $ad_weights[ $post_id ] );
73
74 $group->set_ad_weights( $ad_weights );
75 $group->save();
76 }
77 }
78 }
79 }
80 }
81 }
82
83 /**
84 * Update post counts to have expiring ads.
85 *
86 * @param stdClass $counts An object containing the current post_type's post
87 * counts by status.
88 * @param string $type Post type.
89 *
90 * @return stdClass
91 */
92 public function update_count_posts( $counts, $type ): stdClass {
93 if ( Constants::POST_TYPE_AD !== $type ) {
94 return $counts;
95 }
96
97 $now = time();
98 $expiring = 0;
99
100 foreach ( wp_advads_get_ad_summaries() as $summary ) {
101 if ( ! empty( $summary['expiry_date'] ) && $summary['expiry_date'] > $now ) {
102 ++$expiring;
103 }
104 }
105
106 $counts->{Constants::AD_STATUS_EXPIRING} = $expiring;
107
108 return $counts;
109 }
110
111 /**
112 * Change messages when a post type is updated.
113 *
114 * @since 1.4.7
115 *
116 * @param array $messages Existing post update messages.
117 *
118 * @return array
119 */
120 public function post_updated_messages( $messages = [] ): array {
121 global $post;
122
123 // Added to fix error message array caused by third party code that uses post_updated_messages filter wrong.
124 if ( ! is_array( $messages ) ) {
125 $messages = [];
126 }
127
128 $revision = Params::get( 'revision', 0, FILTER_VALIDATE_INT );
129
130 $messages[ Constants::POST_TYPE_AD ] = [
131 0 => '', // Unused. Messages start at index 1.
132 1 => __( 'Ad updated.', 'advanced-ads' ),
133 4 => __( 'Ad updated.', 'advanced-ads' ),
134 5 => $revision
135 /* translators: %s: date and time of the revision */
136 ? sprintf( __( 'Ad restored to revision from %s', 'advanced-ads' ), wp_post_revision_title( $revision, false ) )
137 : false,
138 6 => __( 'Ad saved.', 'advanced-ads' ),
139 7 => __( 'Ad saved.', 'advanced-ads' ),
140 8 => __( 'Ad submitted.', 'advanced-ads' ),
141 9 => sprintf(
142 /* translators: %s: date */
143 __( 'Ad scheduled for: <strong>%1$s</strong>.', 'advanced-ads' ),
144 '<strong>' . date_i18n( __( 'M j, Y @ G:i', 'advanced-ads' ), strtotime( $post->post_date ) ) . '</strong>'
145 ),
146 10 => __( 'Ad draft updated.', 'advanced-ads' ),
147 ];
148
149 return $messages;
150 }
151
152 /**
153 * Edit ad bulk update messages
154 *
155 * @param array $messages existing bulk update messages.
156 * @param array $counts numbers of updated ads.
157 *
158 * @return array
159 */
160 public function bulk_post_updated_messages( array $messages, array $counts ): array {
161 $messages[ Constants::POST_TYPE_AD ] = [
162 /* translators: %s: ad count */
163 'updated' => _n( '%s ad updated.', '%s ads updated.', $counts['updated'], 'advanced-ads' ),
164 /* translators: %s: ad count */
165 'locked' => _n( '%s ad not updated, somebody is editing it.', '%s ads not updated, somebody is editing them.', $counts['locked'], 'advanced-ads' ),
166 /* translators: %s: ad count */
167 'deleted' => _n( '%s ad permanently deleted.', '%s ads permanently deleted.', $counts['deleted'], 'advanced-ads' ),
168 /* translators: %s: ad count */
169 'trashed' => _n( '%s ad moved to the Trash.', '%s ads moved to the Trash.', $counts['trashed'], 'advanced-ads' ),
170 /* translators: %s: ad count */
171 'untrashed' => _n( '%s ad restored from the Trash.', '%s ads restored from the Trash.', $counts['untrashed'], 'advanced-ads' ),
172 ];
173
174 $messages[ Constants::POST_TYPE_PLACEMENT ] = [
175 /* translators: %s: placement count */
176 'updated' => _n( '%s placement updated.', '%s placements updated.', $counts['updated'], 'advanced-ads' ),
177 /* translators: %s: placement count */
178 'locked' => _n( '%s placement not updated, somebody is editing it.', '%s placements not updated, somebody is editing them.', $counts['locked'], 'advanced-ads' ),
179 /* translators: %s: placement count */
180 'deleted' => _n( '%s placement permanently deleted.', '%s placements permanently deleted.', $counts['deleted'], 'advanced-ads' ),
181 /* translators: %s: placement count */
182 'trashed' => _n( '%s placement moved to the Trash.', '%s placements moved to the Trash.', $counts['trashed'], 'advanced-ads' ),
183 /* translators: %s: placement count */
184 'untrashed' => _n( '%s placement restored from the Trash.', '%s placements restored from the Trash.', $counts['untrashed'], 'advanced-ads' ),
185 ];
186
187 return $messages;
188 }
189
190 /**
191 * Replace the edit link with a link to the modal to edit the placement.
192 *
193 * @param string $link The previous link.
194 * @param int $post_id The \WP_Post::$ID for the current item.
195 *
196 * @return string
197 */
198 public function get_edit_post_link( string $link, int $post_id ): string {
199 if ( get_post_type( $post_id ) === Constants::POST_TYPE_PLACEMENT ) {
200 $link = admin_url( 'edit.php?post_type=' . Constants::POST_TYPE_PLACEMENT . '#modal-placement-edit-' . $post_id );
201 }
202
203 return $link;
204 }
205 }
206