PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.21
Advanced Ads – Ad Manager & AdSense v2.0.21
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-list.php
advanced-ads / includes / admin Last commit date
ads 3 months ago groups 3 months ago metaboxes 1 year ago pages 3 months ago placements 2 months ago class-action-links.php 1 year ago class-addon-box.php 1 year ago class-addon-updater.php 3 months ago class-admin-menu.php 3 months ago class-admin-notices.php 1 year ago class-ajax.php 3 months ago class-assets.php 3 months ago class-authors.php 1 year ago class-compatibility.php 1 year ago class-edd-updater.php 3 months ago class-list-filters.php 2 months 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 year 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 3 months 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-list.php
193 lines
1 <?php
2 /**
3 * Display ad-related information on the post and page overview page.
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.x.x
8 */
9
10 namespace AdvancedAds\Admin;
11
12 use AdvancedAds\Framework\Utilities\Params;
13 use AdvancedAds\Framework\Interfaces\Integration_Interface;
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * Class Post_List
19 */
20 class Post_List implements Integration_Interface {
21
22 /**
23 * Hook into WordPress.
24 *
25 * @return void
26 */
27 public function hooks(): void {
28 add_action( 'restrict_manage_posts', [ $this, 'add_ads_filter_dropdown' ] );
29 add_action( 'pre_get_posts', [ $this, 'filter_posts_by_ads_status' ] );
30 add_filter( 'manage_posts_columns', [ $this, 'ads_column_init' ] );
31 add_filter( 'manage_pages_columns', [ $this, 'ads_column_init' ] );
32 add_filter( 'manage_edit-post_sortable_columns', [ $this, 'sortable_ads_column' ] );
33 add_filter( 'manage_edit-page_sortable_columns', [ $this, 'sortable_ads_column' ] );
34 add_filter( 'posts_clauses', [ $this, 'request_clauses' ], 10, 2 );
35 add_action( 'manage_posts_custom_column', [ $this, 'ads_column_content' ], 10, 2 );
36 add_action( 'manage_pages_custom_column', [ $this, 'ads_column_content' ], 10, 2 );
37 add_filter( 'default_hidden_columns', [ $this, 'hide_ads_column_by_default' ], 10, 2 );
38 }
39
40 /**
41 * Add a filter dropdown to the post and pages lists.
42 *
43 * @param string $post_type current post type.
44 *
45 * @return void
46 */
47 public function add_ads_filter_dropdown( string $post_type ): void {
48 if ( ! in_array( $post_type, [ 'post', 'page' ], true ) ) {
49 return;
50 }
51
52 $viewability = Params::get( 'ad-viewability', '' );
53 include ADVADS_ABSPATH . 'admin/views/post-list-filter-dropdown.php';
54 }
55
56 /**
57 * Filter the list of posts and pages based on their ads settings
58 *
59 * @param \WP_Query $query The WP_Query object.
60 *
61 * @return void
62 */
63 public function filter_posts_by_ads_status( \WP_Query $query ): void {
64 if ( ! is_admin() || ! $query->is_main_query() || ! $query->get( 'post_type' ) || ! in_array( $query->get( 'post_type' ), [ 'post', 'page' ], true ) ) {
65 return;
66 }
67
68 $viewability = Params::get( 'ad-viewability', '' );
69 if ( ! $viewability ) {
70 return;
71 }
72
73 if ( in_array( $viewability, [ 'disable_ads', 'disable_the_content' ], true ) ) {
74 $query->set( 'meta_key', '_advads_ad_settings' );
75 $query->set( 'meta_compare', 'LIKE' );
76 $query->set( 'meta_value', '"' . $viewability . '";i:1;' );
77 }
78 }
79
80 /**
81 * Order post list by ad status
82 *
83 * @param array $clauses existing request clauses.
84 * @param \WP_Query $query the current WP Query.
85 *
86 * @return array
87 */
88 public function request_clauses( $clauses, $query ) {
89 global $wpdb;
90
91 if ( empty( $query->query_vars['orderby'] ) || 'ad-status' !== $query->query_vars['orderby'] || ! $query->is_main_query() ) {
92 // No need to order by ad status.
93 return $clauses;
94 }
95
96 if ( ! function_exists( 'get_current_screen' ) ) {
97 return $clauses;
98 }
99
100 $screen = get_current_screen();
101
102 if ( ! $screen || ! in_array( $screen->id, [ 'edit-post', 'edit-page' ], true ) ) {
103 // Not the page we're interested in.
104 return $clauses;
105 }
106
107 // Create aliases for ads disabled on the post/page and injection into the content disabled.
108 $clauses['join'] .= " LEFT JOIN (SELECT post_id, IF(meta_value LIKE '%disable_ads\";i:1%', 1, 0) as ads, IF(meta_value LIKE '%disable_the_content\";s:1%', 1, 0) as content FROM {$wpdb->postmeta}"
109 . " WHERE meta_key = '_advads_ad_settings') as advads_meta on {$wpdb->posts}.ID = advads_meta.post_id";
110
111 $order = 'asc' === strtolower( $query->query_vars['order'] ) ? 'DESC' : 'ASC';
112
113 $clauses['orderby'] = "advads_meta.ads {$order}, advads_meta.content {$order}";
114
115 return $clauses;
116 }
117
118 /**
119 * Make the ad status column sortable
120 *
121 * @param array $columns columns list.
122 *
123 * @return array
124 */
125 public function sortable_ads_column( $columns ) {
126 $columns['ad-status'] = 'ad-status';
127
128 return $columns;
129 }
130
131 /**
132 * Adds a new column to the post overview page for public post types.
133 *
134 * @param array $columns An array of column names.
135 *
136 * @return array The modified array of column names.
137 */
138 public function ads_column_init( array $columns ): array {
139 $post_type = wp_doing_ajax() ? Params::post( 'post_type', '' ) : get_current_screen()->post_type;
140
141 if ( $post_type && get_post_type_object( $post_type )->public ) {
142 $columns['ad-status'] = __( 'Ad injection', 'advanced-ads' );
143 }
144
145 return $columns;
146 }
147
148 /**
149 * Displays the value of the "ads" post meta in the "Ads" column.
150 *
151 * @param string $column The name of the column.
152 * @param int $post_id The ID of the post.
153 *
154 * @return void
155 */
156 public function ads_column_content( string $column, int $post_id ): void {
157 // Early bail!!
158 if ( 'ad-status' !== $column ) {
159 return;
160 }
161
162 $ads_post_meta = get_post_meta( $post_id, '_advads_ad_settings', true );
163
164 if ( ! empty( $ads_post_meta['disable_ads'] ) ) {
165 echo '<p>' . esc_html__( 'All ads disabled', 'advanced-ads' ) . '</p>';
166 }
167
168 if ( defined( 'AAP_VERSION' ) && ! empty( $ads_post_meta['disable_the_content'] ) ) {
169 echo '<p>' . esc_html__( 'Ads in content disabled', 'advanced-ads' ) . '</p>';
170 }
171 }
172
173 /**
174 * Hide the Ads column by default
175 *
176 * @param string[] $hidden hidden columns.
177 * @param \WP_Screen $screen screen object.
178 *
179 * @return string[]
180 */
181 public function hide_ads_column_by_default( array $hidden, \WP_Screen $screen ): array {
182 $post_type_object = get_post_type_object( $screen->post_type );
183
184 if ( ! $post_type_object || ! $post_type_object->public ) {
185 return $hidden;
186 }
187
188 $hidden[] = 'ad-status';
189
190 return $hidden;
191 }
192 }
193