PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.8.3
Advanced Ads – Ad Manager & AdSense v1.8.3
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 / admin / includes / class-meta-box.php
advanced-ads / admin / includes Last commit date
class-ad-groups-list.php 9 years ago class-ad-type.php 9 years ago class-licenses.php 9 years ago class-menu.php 9 years ago class-meta-box.php 9 years ago class-notices.php 9 years ago class-options.php 9 years ago class-overview-widgets.php 9 years ago class-settings.php 9 years ago class-shortcode-creator.php 9 years ago notices.php 9 years ago shortcode-creator-l10n.php 10 years ago
class-meta-box.php
440 lines
1 <?php
2 defined( 'ABSPATH' ) || exit;
3
4 class Advanced_Ads_Admin_Meta_Boxes {
5 /**
6 * Instance of this class.
7 *
8 * @var object
9 */
10 protected static $instance = null;
11
12 /**
13 * meta box ids
14 *
15 * @since 1.7.4.2
16 * @var array
17 */
18 protected $meta_box_ids = array();
19
20
21 private function __construct() {
22 add_action( 'add_meta_boxes_' . Advanced_Ads::POST_TYPE_SLUG, array( $this, 'add_meta_boxes' ) );
23 // add meta box for post types edit pages
24 add_action( 'add_meta_boxes', array( $this, 'add_post_meta_box' ) );
25 add_action( 'save_post', array( $this, 'save_post_meta_box' ) );
26 // register dashboard widget
27 add_action( 'wp_dashboard_setup', array($this, 'add_dashboard_widget') );
28 }
29
30 /**
31 * Return an instance of this class.
32 *
33 * @return object A single instance of this class.
34 */
35 public static function get_instance() {
36 // If the single instance hasn't been set, set it now.
37 if ( null == self::$instance ) {
38 self::$instance = new self;
39 }
40
41 return self::$instance;
42 }
43
44 /**
45 * Add meta boxes
46 *
47 * @since 1.0.0
48 */
49 public function add_meta_boxes() {
50 $post_type = Advanced_Ads::POST_TYPE_SLUG;
51
52 add_meta_box(
53 'ad-main-box', __( 'Ad Type', 'advanced-ads' ), array($this, 'markup_meta_boxes'), $post_type, 'normal', 'high'
54 );
55 // use dynamic filter from to add close class to ad type meta box after saved first time
56 add_filter( 'postbox_classes_advanced_ads_ad-main-box', array( $this, 'close_ad_type_metabox' ) );
57
58 add_meta_box(
59 'ad-parameters-box', __( 'Ad Parameters', 'advanced-ads' ), array($this, 'markup_meta_boxes'), $post_type, 'normal', 'high'
60 );
61 add_meta_box(
62 'ad-output-box', __( 'Layout / Output', 'advanced-ads' ), array($this, 'markup_meta_boxes'), $post_type, 'normal', 'high'
63 );
64 add_meta_box(
65 'ad-display-box', __( 'Display Conditions', 'advanced-ads' ), array($this, 'markup_meta_boxes'), $post_type, 'normal', 'high'
66 );
67 add_meta_box(
68 'ad-visitor-box', __( 'Visitor Conditions', 'advanced-ads' ), array($this, 'markup_meta_boxes'), $post_type, 'normal', 'high'
69 );
70
71 // register meta box ids
72 $this->meta_box_ids = array(
73 'ad-main-box',
74 'ad-parameters-box',
75 'ad-output-box',
76 'ad-display-box',
77 'ad-visitor-box',
78 'revisionsdiv', // revisions – only when activated
79 'advanced_ads_groupsdiv' // automatically added by ad groups taxonomy
80 );
81
82 // force AA meta boxes to never be completely hidden by screen options
83 add_filter( 'hidden_meta_boxes', array( $this, 'unhide_meta_boxes' ), 10, 2 );
84
85 $whitelist = apply_filters( 'advanced-ads-ad-edit-allowed-metaboxes', array_merge(
86 $this->meta_box_ids,
87 array(
88 'submitdiv',
89 'slugdiv',
90 'tracking-ads-box',
91 'ad-layer-ads-box', // deprecated
92 )
93 ) );
94
95 global $wp_meta_boxes;
96 // remove non-white-listed meta boxes
97 foreach ( array( 'normal', 'advanced', 'side' ) as $context ) {
98 if ( isset( $wp_meta_boxes[ $post_type ][ $context ] ) ) {
99 foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
100 if ( isset( $wp_meta_boxes[ $post_type ][ $context ][ $priority ]) ) {
101 foreach ( (array) $wp_meta_boxes[ $post_type ][ $context ][ $priority ] as $id => $box ) {
102 if ( ! in_array( $id, $whitelist ) ) {
103 unset( $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ] );
104 }
105 }
106 }
107 }
108 }
109 }
110 }
111
112 /**
113 * load templates for all meta boxes
114 *
115 * @since 1.0.0
116 * @param obj $post
117 * @param array $box
118 * @todo move ad initialization to main function and just global it
119 */
120 public function markup_meta_boxes($post, $box) {
121 $ad = new Advanced_Ads_Ad( $post->ID );
122
123 switch ( $box['id'] ) {
124 case 'ad-main-box':
125 $view = 'ad-main-metabox.php';
126 $hndlelinks = '<a href="' . ADVADS_URL . 'manual/ad-types#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-ad-type" target="_blank">' . __('Manual', 'advanced-ads') . '</a>';
127 break;
128 case 'ad-parameters-box':
129 $view = 'ad-parameters-metabox.php';
130 break;
131 case 'ad-output-box':
132 $view = 'ad-output-metabox.php';
133 break;
134 case 'ad-display-box':
135 $view = 'ad-display-metabox.php';
136 $hndlelinks = '<a href="#" class="advads-video-link">' . __('Video', 'advanced-ads') . '</a>';
137 $hndlelinks .= '<a href="' . ADVADS_URL . 'manual/display-conditions#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-display" target="_blank">' . __('Manual', 'advanced-ads') . '</a>';
138 $videomarkup = '<iframe width="420" height="315" src="https://www.youtube-nocookie.com/embed/wVB6UpeyWNA?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>';
139 break;
140 case 'ad-visitor-box':
141 $view = 'ad-visitor-metabox.php';
142 $hndlelinks = '<a href="' . ADVADS_URL . 'manual/visitor-conditions#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor" target="_blank">' . __('Manual', 'advanced-ads') . '</a>';
143 break;
144 }
145
146 if ( ! isset( $view ) ) {
147 return;
148 }
149 // markup moved to handle headline of the metabox
150 if( isset( $hndlelinks ) ){
151 ?><span class="advads-hndlelinks hidden"><?php echo $hndlelinks; ?></span>
152 <?php
153 }
154 // show video markup
155 if( isset( $videomarkup ) ){
156 echo '<div class="advads-video-link-container" data-videolink=\'' . $videomarkup . '\'></div>';
157 }
158 /**
159 * list general notices
160 *
161 * elements in $warnings contain [text] and [class] attributes
162 */
163 $warnings = array();
164 // show warning if ad contains https in parameters box
165 if ( 'ad-parameters-box' === $box['id'] && $message = Advanced_Ads_Ad_Debug::is_https_and_http( $ad ) ) {
166 $warnings[] = array(
167 'text' => $message,
168 'class' =>'advads-ad-notice-https-missing error'
169 );
170 }
171
172 $warnings = apply_filters( 'advanced-ads-ad-notices', $warnings, $box, $post );
173 echo '<ul id="' .$box['id'].'-notices" class="advads-metabox-notices">';
174 foreach( $warnings as $_warning ){
175 if( isset( $_warning['text'] ) ) :
176 $warning_class = isset( $_warning['class'] ) ? $_warning['class'] : '';
177 echo '<li class="'. $warning_class . '">';
178 echo $_warning['text'];
179 echo '</li>';
180 endif;
181 }
182 echo '</ul>';
183 include ADVADS_BASE_PATH . 'admin/views/' . $view;
184 }
185
186 /**
187 * force all AA related meta boxes to stay visible
188 *
189 * @since 1.7.4.2
190 * @param array $hidden An array of hidden meta boxes
191 * @param WP_Screen $screen WP_Screen object of the current screen
192 */
193 public function unhide_meta_boxes( $hidden, $screen ){
194 // only check on Advanced Ads edit screen
195 if ( ! isset( $screen->id ) || $screen->id !== 'advanced_ads' || !is_array( $this->meta_box_ids ) ) {
196 return $hidden;
197 }
198
199 // return only hidden elements which are not among the Advanced Ads meta box ids
200 return array_diff( $hidden, $this->meta_box_ids );
201 }
202
203 /**
204 * add a meta box to post type edit screens with ad settings
205 *
206 * @since 1.3.10
207 * @param string $post_type current post type
208 */
209 public function add_post_meta_box($post_type = ''){
210 // don’t display for non admins
211 if( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
212 return;
213 }
214
215 // get public post types
216 $public_post_types = get_post_types( array('public' => true, 'publicly_queryable' => true), 'names', 'or' );
217
218 //limit meta box to public post types
219 if ( in_array( $post_type, $public_post_types ) ) {
220 add_meta_box(
221 'advads-ad-settings',
222 __( 'Ad Settings', 'advanced-ads' ),
223 array( $this, 'render_post_meta_box' ),
224 $post_type,
225 'advanced',
226 'low'
227 );
228 }
229 }
230
231 /**
232 * render meta box for ad settings on a per post basis
233 *
234 * @since 1.3.10
235 * @param WP_Post $post The post object.
236 */
237 public function render_post_meta_box( $post ) {
238
239 // nonce field to check when we save the values
240 wp_nonce_field( 'advads_post_meta_box', 'advads_post_meta_box_nonce' );
241
242 // retrieve an existing value from the database.
243 $values = get_post_meta( $post->ID, '_advads_ad_settings', true );
244
245 // load the view
246 include ADVADS_BASE_PATH . 'admin/views/post-ad-settings-metabox.php';
247
248 do_action( 'advanced_ads_render_post_meta_box', $post, $values );
249 }
250
251 /**
252 * save the ad meta when the post is saved.
253 *
254 * @since 1.3.10
255 * @param int $post_id The ID of the post being saved.
256 */
257 public function save_post_meta_box( $post_id ) {
258
259 if( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
260 return;
261 }
262
263 // check nonce
264 if ( ! isset( $_POST['advads_post_meta_box_nonce'] ) ) {
265 return $post_id; }
266
267 $nonce = $_POST['advads_post_meta_box_nonce'];
268
269 // Verify that the nonce is valid.
270 if ( ! wp_verify_nonce( $nonce, 'advads_post_meta_box' ) ) {
271 return $post_id; }
272
273 // don’t save on autosave
274 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
275 return $post_id; }
276
277 // check the user's permissions.
278 if ( 'page' == $_POST['post_type'] ) {
279 if ( ! current_user_can( 'edit_page', $post_id ) ) {
280 return $post_id; }
281 } else {
282 if ( ! current_user_can( 'edit_post', $post_id ) ) {
283 return $post_id; }
284 }
285
286 // Sanitize the user input.
287 $_data['disable_ads'] = isset($_POST['advanced_ads']['disable_ads']) ? absint( $_POST['advanced_ads']['disable_ads'] ) : 0;
288
289 $_data = apply_filters( 'advanced_ads_save_post_meta_box', $_data );
290
291 // Update the meta field.
292 update_post_meta( $post_id, '_advads_ad_settings', $_data );
293 }
294
295 /**
296 * add "close" class to collapse the ad-type metabox after ad was saved first
297 *
298 * @since 1.7.2
299 * @param arr $classes
300 * @return arr $classes
301 */
302 public function close_ad_type_metabox( $classes = array() ) {
303 global $post;
304 if ( isset( $post->ID ) && 'edit' === $post->filter ) {
305 if ( ! in_array( 'closed', $classes ) ) {
306 $classes[] = 'closed';
307 }
308 } else {
309 $classes = array();
310 }
311 return $classes;
312 }
313
314 /**
315 * add dashboard widget with ad stats and additional information
316 *
317 * @since 1.3.12
318 */
319 public function add_dashboard_widget(){
320 // display dashboard widget only to authors and higher roles
321 if( ! current_user_can('publish_posts') ) {
322 return;
323 }
324 add_meta_box( 'advads_dashboard_widget', __( 'Ads Dashboard', 'advanced-ads' ), array($this, 'dashboard_widget_function'), 'dashboard', 'side', 'high' );
325 }
326
327 /**
328 * display widget functions
329 */
330 public static function dashboard_widget_function($post, $callback_args){
331 // load ad optimization feed
332 $feeds = array(
333 array(
334 'link' => 'http://webgilde.com/en/ad-optimization/',
335 'url' => 'http://webgilde.com/en/ad-optimization/feed/',
336 'title' => __( 'From the ad optimization universe', 'advanced-ads' ),
337 'items' => 2,
338 'show_summary' => 0,
339 'show_author' => 0,
340 'show_date' => 0,
341 ),
342 array(
343 'link' => ADVADS_URL,
344 'url' => ADVADS_URL . 'feed/',
345 'title' => __( 'Advanced Ads Tutorials', 'advanced-ads' ),
346 'items' => 2,
347 'show_summary' => 0,
348 'show_author' => 0,
349 'show_date' => 0,
350 ),
351 );
352
353 // get number of ads
354 $ads_count = Advanced_Ads::get_number_of_ads();
355 if( current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
356 echo '<p>';
357 printf(__( '%d ads – <a href="%s">manage</a> - <a href="%s">new</a>', 'advanced-ads' ),
358 $ads_count,
359 'edit.php?post_type='. Advanced_Ads::POST_TYPE_SLUG,
360 'post-new.php?post_type='. Advanced_Ads::POST_TYPE_SLUG);
361 echo '</p>';
362 }
363
364 // get and display plugin version
365 $advads_plugin_data = get_plugin_data( ADVADS_BASE_PATH . 'advanced-ads.php' );
366 if ( isset($advads_plugin_data['Version']) ){
367 $version = $advads_plugin_data['Version'];
368 echo '<p><a href="'.ADVADS_URL.'#utm_source=advanced-ads&utm_medium=link&utm_campaign=dashboard" target="_blank" title="'.
369 __( 'plugin manual and homepage', 'advanced-ads' ).'">Advanced Ads</a> '. $version .'</p>';
370 }
371
372 $notice_options = Advanced_Ads_Admin_Notices::get_instance()->options();
373 $_notice = 'nl_first_steps';
374 if ( ! isset($notice_options['closed'][ $_notice ] ) ) {
375 ?><div class="advads-admin-notice">
376 <p><button type="button" class="button-primary advads-notices-button-subscribe" data-notice="<?php echo $_notice ?>"><?php _e('Get the tutorial via email', 'advanced-ads'); ?></button></p>
377 </div><?php
378 }
379
380 $_notice = 'nl_adsense';
381 if ( ! isset($notice_options['closed'][ $_notice ] ) ) {
382 ?><div class="advads-admin-notice">
383 <p><button type="button" class="button-primary advads-notices-button-subscribe" data-notice="<?php echo $_notice ?>"><?php _e('Get AdSense tips via email', 'advanced-ads'); ?></button></p>
384 </div><?php
385 }
386
387 // rss feed
388 // $this->dashboard_widget_function_output('advads_dashboard_widget', $feed);
389 self::dashboard_cached_rss_widget( 'advads_dashboard_widget', array( 'self', 'dashboard_widget_function_output' ), array( 'advads' => $feeds ) );
390
391 // add markup for utm variables
392 // todo: move to js file
393 ?><script>jQuery('#advads_dashboard_widget .rss-widget a').each(function(){ this.href = this.href + '#utm_source=advanced-ads&utm_medium=rss-link&utm_campaign=dashboard'; })</script><?php
394 }
395
396 /**
397 * checks to see if there are feed urls in transient cache; if not, load them
398 * built using a lot of https://developer.wordpress.org/reference/functions/wp_dashboard_cached_rss_widget/
399 *
400 * @since 1.3.12
401 * @param string $widget_id
402 * @param callback $callback
403 * @param array $check_urls RSS feeds
404 * @return bool False on failure. True on success.
405 */
406 static function dashboard_cached_rss_widget( $widget_id, $callback, $feeds = array() ) {
407 if ( empty($feeds) ) {
408 return;
409 }
410
411 $cache_key = 'dash_' . md5( $widget_id );
412 if ( false !== ( $output = get_transient( $cache_key ) ) ) {
413 echo $output;
414 return true;
415 }
416 if ( $callback && is_callable( $callback ) ) {
417 ob_start();
418 call_user_func_array( $callback, $feeds );
419 set_transient( $cache_key, ob_get_flush(), 48 * HOUR_IN_SECONDS ); // Default lifetime in cache of 48 hours
420 }
421
422 return true;
423 }
424
425 /**
426 * create the rss output of the widget
427 *
428 * @param string $widget_id Widget ID.
429 * @param array $feeds Array of RSS feeds.
430 */
431 static function dashboard_widget_function_output( $feeds ) {
432 foreach ( $feeds as $_feed ){
433 echo '<div class="rss-widget">';
434 echo '<h4>'.$_feed['title'].'</h4>';
435 wp_widget_rss_output( $_feed['url'], $_feed );
436 echo '</div>';
437 }
438 }
439
440 }