PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.19
Advanced Ads – Ad Manager & AdSense v2.0.19
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 3 months ago groups 3 months ago metaboxes 1 year ago pages 3 months ago placements 3 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 1 year 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-misc.php
280 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 if ( typeof advanced_ads_adblocker_test === 'undefined' ) {
109 jQuery( '#" . esc_attr( $ad_blocker_notice_id ) . ".message' ).show();
110 }
111 } );"
112 );
113 include_once ADVADS_ABSPATH . 'admin/views/notices/adblock.php';
114 }
115
116 // Show success notice after starter setup was imported. Registered here because it will be visible only once.
117 if ( 'advanced-ads-starter-setup-success' === Params::get( 'message' ) ) {
118 add_action( 'advanced-ads-admin-notices', [ $this, 'starter_setup_success_message' ] );
119 }
120
121 /*
122 Register our own notices on Advanced Ads pages, except
123 -> the overview page where they should appear in the notices section,
124 -> revision page to prevent duplicate revision controls.
125 */
126 $screen = get_current_screen();
127 if (
128 Conditional::user_can( 'advanced_ads_edit_ads' )
129 && ( ! isset( $screen->id ) || 'toplevel_page_advanced-ads' !== $screen->id )
130 && 'revision' !== $screen->id
131 ) {
132
133 echo '<div class="wrap">';
134 Advanced_Ads_Admin_Notices::get_instance()->display_notices();
135
136 // Allow other Advanced Ads plugins to show admin notices at this late stage.
137 do_action( 'advanced-ads-admin-notices' );
138 echo '</div>';
139 }
140 }
141
142 /**
143 * Show success message after starter setup was created.
144 *
145 * @return void
146 */
147 public function starter_setup_success_message(): void {
148 $last_post = get_posts( [ 'numberposts' => 1 ] );
149 $last_post_link = isset( $last_post[0]->ID ) ? get_permalink( $last_post[0]->ID ) : false;
150
151 include ADVADS_ABSPATH . 'admin/views/notices/starter-setup-success.php';
152 }
153
154 /**
155 * Recommend additional add-ons
156 *
157 * @param object|WP_Error $result Response object or WP_Error.
158 * @param string $action The type of information being requested from the Plugin Installation API.
159 * @param object $args Plugin API arguments.
160 *
161 * @return object|WP_Error Response object or WP_Error.
162 */
163 public function recommend_suitable_add_ons( $result, $action, $args ) {
164 if (
165 empty( $args->browse )
166 || ! in_array( $args->browse, [ 'featured', 'recommended', 'popular' ], true )
167 || ( isset( $result->info['page'] ) && $result->info['page'] > 1 )
168 ) {
169 return $result;
170 }
171
172 // Grab all slugs from the api results.
173 $result_slugs = wp_list_pluck( $result->plugins, 'slug' );
174
175 // Recommend AdSense In-Feed add-on.
176 $result = $this->recommend_plugin(
177 'advanced-ads-adsense-in-feed',
178 'advanced-ads-adsense-in-feed/advanced-ads-in-feed.php',
179 $args,
180 $result,
181 $result_slugs
182 );
183
184 // Recommend Genesis Ads add-on.
185 if ( defined( 'PARENT_THEME_NAME' ) && 'Genesis' === PARENT_THEME_NAME ) {
186 $result = $this->recommend_plugin(
187 'advanced-ads-genesis',
188 'advanced-ads-genesis/genesis-ads.php',
189 $args,
190 $result,
191 $result_slugs
192 );
193 }
194
195 // Recommend WP Bakery (former Visual Composer) add-on.
196 if ( defined( 'WPB_VC_VERSION' ) ) {
197 $result = $this->recommend_plugin(
198 'ads-for-visual-composer',
199 'ads-for-visual-composer/advanced-ads-vc.php',
200 $args,
201 $result,
202 $result_slugs
203 );
204 }
205
206 return $result;
207 }
208
209 /**
210 * Import a starter setup for new users
211 *
212 * @return void
213 */
214 public function import_starter_setup(): void {
215 if (
216 'advanced_ads_starter_setup' !== Params::get( 'action' )
217 || ! Conditional::user_can( 'advanced_ads_edit_ads' )
218 ) {
219 return;
220 }
221
222 check_admin_referer( 'advanced-ads-starter-setup' );
223
224 $xml = file_get_contents( ADVADS_ABSPATH . 'admin/assets/xml/starter-setup.xml' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
225
226 ( new XML_Importer() )->import_content( $xml );
227
228 // Redirect to the ads overview page.
229 wp_safe_redirect( admin_url( 'edit.php?post_type=advanced_ads&message=advanced-ads-starter-setup-success' ) );
230 }
231
232 /**
233 * Recommends a plugin based on the provided slug and file path.
234 *
235 * This function checks if the plugin is already active or recommended. If not,
236 * it fetches the plugin data using the WordPress Plugin API and adds it to the result.
237 *
238 * @param string $slug The slug of the plugin to recommend.
239 * @param string $file_path The file path of the plugin.
240 * @param object $args Additional arguments for the recommendation.
241 * @param object $result The current result object containing recommended plugins.
242 * @param array $result_slugs An array of slugs of already recommended plugins.
243 *
244 * @return object The updated result object with the recommended plugin added.
245 */
246 private function recommend_plugin( $slug, $file_path, $args, $result, $result_slugs ) {
247 // Check if the plugin is already active or recommended.
248 if (
249 is_plugin_active( $file_path )
250 || is_plugin_active_for_network( $file_path )
251 || in_array( $slug, $result_slugs, true )
252 ) {
253 return $result;
254 }
255
256 // Prepare query arguments to fetch plugin data.
257 $query_args = [
258 'slug' => $slug,
259 'fields' => [
260 'icons' => true,
261 'active_installs' => true,
262 'short_description' => true,
263 'group' => true,
264 ],
265 ];
266 $plugin_data = plugins_api( 'plugin_information', $query_args );
267
268 // Add plugin data to the result if fetched successfully.
269 if ( ! is_wp_error( $plugin_data ) ) {
270 if ( 'featured' === $args->browse ) {
271 array_push( $result->plugins, $plugin_data );
272 } else {
273 array_unshift( $result->plugins, $plugin_data );
274 }
275 }
276
277 return $result;
278 }
279 }
280