PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.25
Advanced Ads – Ad Manager & AdSense v2.0.25
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 / placements / class-edit-modal.php
advanced-ads / includes / admin / placements Last commit date
class-ajax.php 3 months ago class-bulk-edit.php 3 months ago class-create-modal.php 3 months ago class-edit-modal.php 2 months ago class-list-table.php 1 day ago class-quick-edit.php 2 months ago
class-edit-modal.php
396 lines
1 <?php
2 /**
3 * Placement Edit Modal.
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.50.0
8 */
9
10 namespace AdvancedAds\Admin\Placements;
11
12 use AdvancedAds\Modal;
13 use AdvancedAds\Abstracts\Placement;
14 use AdvancedAds\Utilities\WordPress;
15 use AdvancedAds\Framework\Utilities\Params;
16 use AdvancedAds\Utilities\Content_Injection;
17 use AdvancedAds\Framework\Interfaces\Integration_Interface;
18
19 defined( 'ABSPATH' ) || exit;
20
21 /**
22 * Placement Edit Modal.
23 */
24 class Edit_Modal implements Integration_Interface {
25
26 /**
27 * Hold placement
28 *
29 * @var Placement
30 */
31 private $placement = null;
32
33 /**
34 * View path
35 *
36 * @var string
37 */
38 private $view_path = null;
39
40 /**
41 * The constructor
42 *
43 * @param Placement $placement Placement instance.
44 */
45 public function __construct( $placement ) {
46 $this->placement = $placement;
47 $this->view_path = ADVADS_ABSPATH . 'views/admin/placements/edit-modal';
48 }
49
50 /**
51 * Hook into WordPress.
52 *
53 * @return void
54 */
55 public function hooks(): void {
56 add_action( 'admin_footer', [ $this, 'render_modal' ] );
57 }
58
59 /**
60 * Load the modal for creating a new Placement.
61 *
62 * @return void
63 */
64 public function render_modal(): void {
65 Modal::create(
66 [
67 'modal_slug' => 'placement-edit-' . $this->placement->get_id(),
68 'modal_content' => $this->render_modal_content(),
69 /* translators: 1: "Options", 2: the name of a placement. */
70 'modal_title' => sprintf( '%1$s: %2$s', __( 'Options', 'advanced-ads' ), $this->placement->get_title() ),
71 ]
72 );
73 }
74
75 /**
76 * Get form id
77 *
78 * @return string
79 */
80 private function get_form_id(): string {
81 return 'advanced-ads-placement-form-' . $this->placement->get_id();
82 }
83
84 /**
85 * Render the placement modal content as if it was the single edit page for a post.
86 *
87 * @return string
88 */
89 private function render_modal_content(): string {
90 ob_start();
91 $placement = $this->placement;
92 $user_id = wp_get_current_user()->ID;
93 $author_id = get_post_field( 'post_author', $this->placement->get_id() );
94
95 include $this->view_path . '/edit-modal-content.php';
96
97 return ob_get_clean();
98 }
99
100 /**
101 * Render settings.
102 *
103 * @return void
104 */
105 private function render_settings(): void {
106 $basic_settings = [
107 'placement-name' => [
108 'label' => __( 'Name', 'advanced-ads' ),
109 'callback' => [ $this, 'render_placement_name' ],
110 'description' => '',
111 'order' => 5,
112 ],
113 'placement-item' => [
114 'label' => __( 'Item', 'advanced-ads' ),
115 'callback' => [ $this, 'render_placement_item' ],
116 'description' => '',
117 'order' => 5,
118 ],
119 'placement-status' => [
120 'label' => __( 'Status', 'advanced-ads' ),
121 'callback' => [ $this, 'render_placement_status' ],
122 'description' => '',
123 'order' => 5,
124 ],
125 ];
126
127 if ( $this->placement->is_type( 'post_content' ) ) {
128 $basic_settings['placement-content-injection-index'] = [
129 'label' => __( 'position', 'advanced-ads' ),
130 'callback' => [ $this, 'render_placement_position' ],
131 'description' => '',
132 'order' => 6,
133 ];
134 }
135
136 self::render_settings_group( $basic_settings );
137
138 $slug = $this->placement->get_slug();
139
140 /**
141 * Hook before advanced placement options
142 *
143 * @param string $slug the placement slug.
144 * @param Placement $placement the placement.
145 */
146 do_action( 'advanced-ads-placement-options-before-advanced', $slug, $this->placement );
147
148 $type_options = $this->placement->get_type_object()->get_options();
149 $advanced_settings = [];
150
151 if ( ! $this->placement->is_type( 'header' ) ) {
152 if ( $type_options['placement-ad-label'] ?? true ) {
153 $advanced_settings['placement-ad-label'] = [
154 'label' => __( 'ad label', 'advanced-ads' ),
155 'callback' => [ $this, 'render_placement_ad_label' ],
156 'description' => '',
157 'order' => 7,
158 ];
159 }
160
161 if ( isset( $type_options['show_position'] ) && $type_options['show_position'] ) {
162 $advanced_settings['placement-position'] = [
163 'label' => __( 'Position', 'advanced-ads' ),
164 'callback' => [ $this, 'render_placement_label_position' ],
165 'description' => '',
166 'order' => 7,
167 ];
168 }
169
170 $advanced_settings['placement-inline-css'] = [
171 'label' => __( 'Inline CSS', 'advanced-ads' ),
172 'callback' => [ $this, 'render_placement_inline_css' ],
173 'description' => '',
174 'order' => 9,
175 ];
176
177 if ( ! defined( 'AAP_VERSION' ) ) {
178 // Minimum Content Length.
179 $advanced_settings['placement-content-minimum-length'] = [
180 'label' => __( 'Minimum Content Length', 'advanced-ads' ),
181 'callback' => [ $this, 'render_pro_pitch' ],
182 'description' => __( 'Minimum length of content before automatically injected ads are allowed in them.', 'advanced-ads' ),
183 'order' => 10,
184 ];
185
186 // Words Between Ads.
187 $advanced_settings['placement-skip-paragraph'] = [
188 'label' => __( 'Words Between Ads', 'advanced-ads' ),
189 'callback' => [ $this, 'render_pro_pitch' ],
190 'description' => __( 'A minimum amount of words between automatically injected ads.', 'advanced-ads' ),
191 'order' => 10,
192 ];
193 }
194 }
195
196 // show the conditions pitch on the `head` placement as well.
197 if ( ! defined( 'AAP_VERSION' ) ) {
198 // Display Conditions for placements.
199 $advanced_settings['placement-display-conditions'] = [
200 'label' => __( 'Display Conditions', 'advanced-ads' ),
201 'callback' => [ $this, 'render_pro_pitch' ],
202 'description' => __( 'Use display conditions for placements.', 'advanced-ads' ) . ' ' . __( 'The free version provides conditions on the ad edit page.', 'advanced-ads' ),
203 'order' => 10,
204 ];
205
206 // Visitor Condition for placements.
207 $advanced_settings['placement-visitor-conditions'] = [
208 'label' => __( 'Visitor Conditions', 'advanced-ads' ),
209 'callback' => [ $this, 'render_pro_pitch' ],
210 'description' => __( 'Use visitor conditions for placements.', 'advanced-ads' ) . ' ' . __( 'The free version provides conditions on the ad edit page.', 'advanced-ads' ),
211 'order' => 10,
212 ];
213 }
214
215 if ( $advanced_settings ) {
216 self::render_settings_group( $advanced_settings );
217 }
218
219 /**
220 * Hook after advanced placement options
221 *
222 * @param string $slug the placement slug.
223 * @param Placement $placement the placement.
224 */
225 do_action( 'advanced-ads-placement-options-after-advanced', $slug, $this->placement );
226 }
227
228 /**
229 * Render a group of placements options
230 *
231 * @param array $settings placement option fields.
232 *
233 * @return void
234 */
235 private static function render_settings_group( $settings ) {
236 array_multisort( array_column( $settings, 'order' ), SORT_ASC, $settings );
237
238 foreach ( $settings as $setting_id => $setting ) {
239 WordPress::render_option(
240 $setting_id,
241 $setting['label'],
242 $setting['callback']( $setting_id ),
243 $setting['description']
244 );
245 }
246 }
247
248 /**
249 * Render the placement name option.
250 *
251 * @return string
252 */
253 private function render_placement_name(): string {
254 $placement = $this->placement;
255
256 ob_start();
257 include $this->view_path . '/fields/name.php';
258
259 return ob_get_clean();
260 }
261
262 /**
263 * Render the placement item option.
264 *
265 * @return string
266 */
267 private function render_placement_item(): string {
268 $placement = $this->placement;
269
270 ob_start();
271 include $this->view_path . '/fields/item.php';
272
273 return ob_get_clean();
274 }
275
276 /**
277 * Render the placement status option.
278 *
279 * @return string
280 */
281 private function render_placement_status(): string {
282 $placement = $this->placement;
283
284 ob_start();
285 include $this->view_path . '/fields/status.php';
286
287 return ob_get_clean();
288 }
289
290 /**
291 * Render placement ad label option.
292 *
293 * @return string
294 */
295 private function render_placement_ad_label(): string {
296 $label = $this->placement->get_prop( 'ad_label' ) ?? 'default';
297
298 ob_start();
299 include $this->view_path . '/fields/ad-label.php';
300
301 return ob_get_clean();
302 }
303
304 /**
305 * Render the placement label position option.
306 *
307 * @return string
308 */
309 private function render_placement_label_position(): string {
310 $position = $this->placement->get_prop( 'placement_position' ) ?? 'default';
311 $clearfix = ! empty( $this->placement->get_prop( 'placement_clearfix' ) );
312
313 ob_start();
314 include $this->view_path . '/fields/ad-label-position.php';
315
316 return ob_get_clean();
317 }
318
319 /**
320 * Render the placement inline CSS option.
321 *
322 * @return string
323 */
324 private function render_placement_inline_css(): string {
325 $placement = $this->placement;
326 $placement_slug = $this->placement->get_slug();
327 $inline_css = $this->placement->get_prop( 'inline-css' ) ?? '';
328
329 ob_start();
330 include $this->view_path . '/fields/inline-css.php';
331
332 return ob_get_clean();
333 }
334
335 /**
336 * Return `is_pro_pitch` for the options that are pitching the pro version.
337 * WordPress::render_option() handles this string as a special case.
338 *
339 * @return string
340 */
341 private function render_pro_pitch(): string {
342 return 'is_pro_pitch';
343 }
344
345 /**
346 * Render the placement position
347 *
348 * @return string
349 */
350 public function render_placement_position() {
351 $placement = $this->placement;
352 $index = max( 1, (int) ( $placement->get_prop( 'index' ) ?? 1 ) );
353 $tags = Content_Injection::get_tags();
354 $selected_tag = $placement->get_prop( 'tag' ) ?? 'p';
355
356 // Automatically select the 'custom' option.
357 if ( Params::cookie( 'advads_frontend_picker', '' ) === $placement->get_slug() ) {
358 $selected_tag = 'custom';
359 }
360 $xpath = stripslashes( $placement->get_prop( 'xpath' ) ?? '' );
361 $positions = [
362 'after' => __( 'after', 'advanced-ads' ),
363 'before' => __( 'before', 'advanced-ads' ),
364 ];
365 $selected_position = $placement->get_prop( 'position' ) ?? 'after';
366 $start_from_bottom = $placement->get_prop( 'start_from_bottom' );
367
368 ob_start();
369 include $this->view_path . '/fields/content-index.php';
370 if ( ! defined( 'AAP_VERSION' ) ) {
371 include ADVADS_ABSPATH . 'admin/views/upgrades/repeat-the-position.php';
372 }
373
374 do_action( 'advanced-ads-placement-post-content-position', $placement->get_slug(), $placement );
375
376 if ( ! extension_loaded( 'dom' ) ) :
377 ?>
378 <p>
379 <span class="advads-notice-inline advads-error">
380 <?php esc_html_e( 'Important Notice', 'advanced-ads' ); ?>:
381 </span>
382 <?php
383 printf(
384 /* translators: %s is a name of a module. */
385 esc_html__( 'Missing PHP extension could cause issues. Please ask your hosting provider to enable it: %s', 'advanced-ads' ),
386 'dom (php_xml)'
387 );
388 ?>
389 </p>
390 <?php
391 endif;
392
393 return ob_get_clean();
394 }
395 }
396