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-misc.php
advanced-ads / includes / admin Last commit date
ads 4 weeks ago groups 4 weeks ago metaboxes 4 weeks ago pages 4 weeks ago placements 4 weeks ago class-action-links.php 4 weeks ago class-addon-box.php 4 weeks ago class-addon-updater.php 4 weeks ago class-admin-menu.php 4 weeks ago class-admin-notices.php 1 year ago class-ajax.php 4 weeks ago class-app.php 1 month ago class-assets.php 4 weeks ago class-authors.php 4 weeks ago class-edd-updater.php 4 weeks ago class-license-admin-post.php 4 weeks ago class-list-filters.php 4 weeks ago class-marketing.php 4 weeks ago class-metabox-ad-settings.php 1 year ago class-metabox-ad.php 4 weeks ago class-misc.php 4 weeks ago class-page-quick-edit.php 1 month ago class-plugin-auto-update.php 1 month ago class-plugin-installer.php 4 weeks ago class-post-list.php 4 weeks ago class-post-types.php 4 weeks ago class-screen-options.php 4 weeks ago class-settings.php 4 weeks ago class-shortcode-creator.php 4 weeks ago class-system-info.php 1 year ago class-tinymce.php 2 years ago class-translation-promo.php 4 weeks ago class-upgrades.php 4 weeks ago class-version-control.php 4 weeks ago class-welcome.php 1 year ago class-wordpress-dashboard.php 1 year ago index.php 2 years ago
class-misc.php
281 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 Advanced_Ads_Admin_Notices;
13 use AdvancedAds\Constants;
14 use AdvancedAds\Framework\Interfaces\Integration_Interface;
15 use AdvancedAds\Framework\Utilities\Params;
16 use AdvancedAds\Importers\XML_Importer;
17 use AdvancedAds\Utilities\Conditional;
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 echo '<div class="wrap">';
135 Advanced_Ads_Admin_Notices::get_instance()->display_notices();
136
137 // Allow other Advanced Ads plugins to show admin notices at this late stage.
138 do_action( 'advanced-ads-admin-notices' );
139 echo '</div>';
140 }
141 }
142
143 /**
144 * Show success message after starter setup was created.
145 *
146 * @return void
147 */
148 public function starter_setup_success_message(): void {
149 $last_post = get_posts( [ 'numberposts' => 1 ] );
150 $last_post_link = isset( $last_post[0]->ID ) ? get_permalink( $last_post[0]->ID ) : false;
151
152 include ADVADS_ABSPATH . 'admin/views/notices/starter-setup-success.php';
153 }
154
155 /**
156 * Recommend additional add-ons
157 *
158 * @param object|WP_Error $result Response object or WP_Error.
159 * @param string $action The type of information being requested from the Plugin Installation API.
160 * @param object $args Plugin API arguments.
161 *
162 * @return object|WP_Error Response object or WP_Error.
163 */
164 public function recommend_suitable_add_ons( $result, $action, $args ) {
165 if (
166 empty( $args->browse )
167 || ! in_array( $args->browse, [ 'featured', 'recommended', 'popular' ], true )
168 || ( isset( $result->info['page'] ) && $result->info['page'] > 1 )
169 ) {
170 return $result;
171 }
172
173 // Grab all slugs from the api results.
174 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
175
176 // Recommend AdSense In-Feed add-on.
177 $result = $this->recommend_plugin(
178 'advanced-ads-adsense-in-feed',
179 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php',
180 $args,
181 $result,
182 $result_slugs
183 );
184
185 // Recommend Genesis Ads add-on.
186 if ( defined( 'PARENT_THEME_NAME' ) && 'Genesis' === PARENT_THEME_NAME ) {
187 $result = $this->recommend_plugin(
188 'advanced-ads-genesis',
189 'advanced-ads-genesis/genesis-ads.php',
190 $args,
191 $result,
192 $result_slugs
193 );
194 }
195
196 // Recommend WP Bakery (former Visual Composer) add-on.
197 if ( defined( 'WPB_VC_VERSION' ) ) {
198 $result = $this->recommend_plugin(
199 'ads-for-visual-composer',
200 'ads-for-visual-composer/advanced-ads-vc.php',
201 $args,
202 $result,
203 $result_slugs
204 );
205 }
206
207 return $result;
208 }
209
210 /**
211 * Import a starter setup for new users
212 *
213 * @return void
214 */
215 public function import_starter_setup(): void {
216 if (
217 'advanced_ads_starter_setup' !== Params::get( 'action' )
218 || ! Conditional::user_can( 'advanced_ads_edit_ads' )
219 ) {
220 return;
221 }
222
223 check_admin_referer( 'advanced-ads-starter-setup' );
224
225 $xml = file_get_contents( ADVADS_ABSPATH . 'admin/assets/xml/starter-setup.xml' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
226
227 ( new XML_Importer() )->import_content( $xml );
228
229 // Redirect to the ads overview page.
230 wp_safe_redirect( admin_url( 'edit.php?post_type=advanced_ads&message=advanced-ads-starter-setup-success' ) );
231 }
232
233 /**
234 * Recommends a plugin based on the provided slug and file path.
235 *
236 * This function checks if the plugin is already active or recommended. If not,
237 * it fetches the plugin data using the WordPress Plugin API and adds it to the result.
238 *
239 * @param string $slug The slug of the plugin to recommend.
240 * @param string $file_path The file path of the plugin.
241 * @param object $args Additional arguments for the recommendation.
242 * @param object $result The current result object containing recommended plugins.
243 * @param array<int, string> $result_slugs An array of slugs of already recommended plugins.
244 *
245 * @return object The updated result object with the recommended plugin added.
246 */
247 private function recommend_plugin( $slug, $file_path, $args, $result, $result_slugs ) {
248 // Check if the plugin is already active or recommended.
249 if (
250 is_plugin_active( $file_path )
251 || is_plugin_active_for_network( $file_path )
252 || in_array( $slug, $result_slugs, true )
253 ) {
254 return $result;
255 }
256
257 // Prepare query arguments to fetch plugin data.
258 $query_args = [
259 'slug' => $slug,
260 'fields' => [
261 'icons' => true,
262 'active_installs' => true,
263 'short_description' => true,
264 'group' => true,
265 ],
266 ];
267 $plugin_data = plugins_api( 'plugin_information', $query_args );
268
269 // Add plugin data to the result if fetched successfully.
270 if ( ! is_wp_error( $plugin_data ) ) {
271 if ( 'featured' === $args->browse ) {
272 array_push( $result->plugins, $plugin_data );
273 } else {
274 array_unshift( $result->plugins, $plugin_data );
275 }
276 }
277
278 return $result;
279 }
280 }
281