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-misc.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 4 weeks 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-misc.php
282 lines
1 <?php
2 /**
3 * Uncategorised functionality.
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\Constants;
13 use Advanced_Ads_Admin_Notices;
14 use AdvancedAds\Utilities\Conditional;
15 use AdvancedAds\Importers\XML_Importer;
16 use AdvancedAds\Framework\Utilities\Params;
17 use AdvancedAds\Framework\Interfaces\Integration_Interface;
18
19 defined( 'ABSPATH' ) || exit;
20
21 /**
22 * Class Misc
23 */
24 class Misc implements Integration_Interface {
25
26 /**
27 * Hook into WordPress.
28 *
29 * @return void
30 */
31 public function hooks(): void {
32 add_filter( 'gettext', [ $this, 'replace_cheating_message' ], 20, 2 );
33 add_filter( 'get_user_option_user-settings', [ $this, 'reset_view_mode_option' ] );
34 add_action( 'in_admin_header', [ $this, 'register_admin_notices' ] );
35 add_action( 'plugins_api_result', [ $this, 'recommend_suitable_add_ons' ], 11, 3 );
36 add_action( 'admin_action_advanced_ads_starter_setup', [ $this, 'import_starter_setup' ] );
37 }
38
39 /**
40 * Replace 'You need a higher level of permission.' message if user role does not have required permissions.
41 *
42 * @param string $translated_text Translated text.
43 * @param string $untranslated_text Text to translate.
44 *
45 * @return string $translation Translated text.
46 */
47 public function replace_cheating_message( $translated_text, $untranslated_text ): string {
48 global $typenow;
49
50 if (
51 isset( $typenow )
52 && 'You need a higher level of permission.' === $untranslated_text
53 && Constants::POST_TYPE_AD === $typenow
54 ) {
55 $translated_text = __( 'You don’t have access to ads. Please deactivate and re-enable Advanced Ads again to fix this.', 'advanced-ads' )
56 . '&nbsp;<a href="https://wpadvancedads.com/manual/user-capabilities/?utm_source=advanced-ads&utm_medium=link&utm_campaign=wrong-user-role#You_dont_have_access_to_ads" target="_blank">' . __( 'Get help', 'advanced-ads' ) . '</a>';
57 }
58
59 return (string) $translated_text;
60 }
61
62 /**
63 * Set the removed post list mode to "List", if it was set to "Excerpt".
64 *
65 * @param string $user_options Query string containing user options.
66 *
67 * @return string
68 */
69 public function reset_view_mode_option( $user_options ): string {
70 return str_replace( '&posts_list_mode=excerpt', '&posts_list_mode=list', $user_options );
71 }
72
73 /**
74 * Registers Advanced Ads admin notices
75 * prevents other notices from showing up on our own pages
76 *
77 * @return void
78 */
79 public function register_admin_notices(): void {
80 /**
81 * Remove all registered admin_notices from AA screens
82 * we need to use this or some users have half or more of their viewports cluttered with unrelated notices
83 */
84 if ( Conditional::is_screen_advanced_ads() ) {
85 remove_all_actions( 'admin_notices' );
86 }
87
88 add_action( 'admin_notices', [ $this, 'admin_notices' ] );
89 }
90
91 /**
92 * Initiate the admin notices class
93 *
94 * @return void
95 */
96 public function admin_notices(): void {
97 // Display ad block warning to everyone who can edit ads.
98 if (
99 Conditional::user_can( 'advanced_ads_edit_ads' )
100 && Conditional::is_screen_advanced_ads()
101 ) {
102 $ad_blocker_notice_id = wp_advads()->get_frontend_prefix() . 'abcheck-' . md5( microtime() );
103 wp_register_script( $ad_blocker_notice_id . '-adblocker-notice', false, [], ADVADS_VERSION, true );
104 wp_enqueue_script( $ad_blocker_notice_id . '-adblocker-notice' );
105 wp_add_inline_script(
106 $ad_blocker_notice_id . '-adblocker-notice',
107 "jQuery( document ).ready( function () {
108 let has_brave_shields = ( typeof navigator.brave !== 'undefined' && typeof advanced_ads_admin === 'undefined' ) ? true : false;
109
110 if ( typeof advanced_ads_adblocker_test === 'undefined' && ( typeof navigator.brave === 'undefined' || has_brave_shields ) ) {
111 jQuery( '#" . esc_attr( $ad_blocker_notice_id ) . ".message' ).show();
112 }
113 } );"
114 );
115 include_once ADVADS_ABSPATH . 'admin/views/notices/adblock.php';
116 }
117
118 // Show success notice after starter setup was imported. Registered here because it will be visible only once.
119 if ( 'advanced-ads-starter-setup-success' === Params::get( 'message' ) ) {
120 add_action( 'advanced-ads-admin-notices', [ $this, 'starter_setup_success_message' ] );
121 }
122
123 /*
124 Register our own notices on Advanced Ads pages, except
125 -> the overview page where they should appear in the notices section,
126 -> revision page to prevent duplicate revision controls.
127 */
128 $screen = get_current_screen();
129 if (
130 Conditional::user_can( 'advanced_ads_edit_ads' )
131 && ( ! isset( $screen->id ) || 'toplevel_page_advanced-ads' !== $screen->id )
132 && 'revision' !== $screen->id
133 ) {
134
135 echo '<div class="wrap">';
136 Advanced_Ads_Admin_Notices::get_instance()->display_notices();
137
138 // Allow other Advanced Ads plugins to show admin notices at this late stage.
139 do_action( 'advanced-ads-admin-notices' );
140 echo '</div>';
141 }
142 }
143
144 /**
145 * Show success message after starter setup was created.
146 *
147 * @return void
148 */
149 public function starter_setup_success_message(): void {
150 $last_post = get_posts( [ 'numberposts' => 1 ] );
151 $last_post_link = isset( $last_post[0]->ID ) ? get_permalink( $last_post[0]->ID ) : false;
152
153 include ADVADS_ABSPATH . 'admin/views/notices/starter-setup-success.php';
154 }
155
156 /**
157 * Recommend additional add-ons
158 *
159 * @param object|WP_Error $result Response object or WP_Error.
160 * @param string $action The type of information being requested from the Plugin Installation API.
161 * @param object $args Plugin API arguments.
162 *
163 * @return object|WP_Error Response object or WP_Error.
164 */
165 public function recommend_suitable_add_ons( $result, $action, $args ) {
166 if (
167 empty( $args->browse )
168 || ! in_array( $args->browse, [ 'featured', 'recommended', 'popular' ], true )
169 || ( isset( $result->info['page'] ) && $result->info['page'] > 1 )
170 ) {
171 return $result;
172 }
173
174 // Grab all slugs from the api results.
175 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
176
177 // Recommend AdSense In-Feed add-on.
178 $result = $this->recommend_plugin(
179 'advanced-ads-adsense-in-feed',
180 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php',
181 $args,
182 $result,
183 $result_slugs
184 );
185
186 // Recommend Genesis Ads add-on.
187 if ( defined( 'PARENT_THEME_NAME' ) && 'Genesis' === PARENT_THEME_NAME ) {
188 $result = $this->recommend_plugin(
189 'advanced-ads-genesis',
190 'advanced-ads-genesis/genesis-ads.php',
191 $args,
192 $result,
193 $result_slugs
194 );
195 }
196
197 // Recommend WP Bakery (former Visual Composer) add-on.
198 if ( defined( 'WPB_VC_VERSION' ) ) {
199 $result = $this->recommend_plugin(
200 'ads-for-visual-composer',
201 'ads-for-visual-composer/advanced-ads-vc.php',
202 $args,
203 $result,
204 $result_slugs
205 );
206 }
207
208 return $result;
209 }
210
211 /**
212 * Import a starter setup for new users
213 *
214 * @return void
215 */
216 public function import_starter_setup(): void {
217 if (
218 'advanced_ads_starter_setup' !== Params::get( 'action' )
219 || ! Conditional::user_can( 'advanced_ads_edit_ads' )
220 ) {
221 return;
222 }
223
224 check_admin_referer( 'advanced-ads-starter-setup' );
225
226 $xml = file_get_contents( ADVADS_ABSPATH . 'admin/assets/xml/starter-setup.xml' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
227
228 ( new XML_Importer() )->import_content( $xml );
229
230 // Redirect to the ads overview page.
231 wp_safe_redirect( admin_url( 'edit.php?post_type=advanced_ads&message=advanced-ads-starter-setup-success' ) );
232 }
233
234 /**
235 * Recommends a plugin based on the provided slug and file path.
236 *
237 * This function checks if the plugin is already active or recommended. If not,
238 * it fetches the plugin data using the WordPress Plugin API and adds it to the result.
239 *
240 * @param string $slug The slug of the plugin to recommend.
241 * @param string $file_path The file path of the plugin.
242 * @param object $args Additional arguments for the recommendation.
243 * @param object $result The current result object containing recommended plugins.
244 * @param array $result_slugs An array of slugs of already recommended plugins.
245 *
246 * @return object The updated result object with the recommended plugin added.
247 */
248 private function recommend_plugin( $slug, $file_path, $args, $result, $result_slugs ) {
249 // Check if the plugin is already active or recommended.
250 if (
251 is_plugin_active( $file_path )
252 || is_plugin_active_for_network( $file_path )
253 || in_array( $slug, $result_slugs, true )
254 ) {
255 return $result;
256 }
257
258 // Prepare query arguments to fetch plugin data.
259 $query_args = [
260 'slug' => $slug,
261 'fields' => [
262 'icons' => true,
263 'active_installs' => true,
264 'short_description' => true,
265 'group' => true,
266 ],
267 ];
268 $plugin_data = plugins_api( 'plugin_information', $query_args );
269
270 // Add plugin data to the result if fetched successfully.
271 if ( ! is_wp_error( $plugin_data ) ) {
272 if ( 'featured' === $args->browse ) {
273 array_push( $result->plugins, $plugin_data );
274 } else {
275 array_unshift( $result->plugins, $plugin_data );
276 }
277 }
278
279 return $result;
280 }
281 }
282