form.php
119 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Advanced Ads – form to edit ad groups in the admin |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * |
| 8 | * @var AdvancedAds\Abstracts\Group $group Group instance. |
| 9 | * @var string $this ->type_error Contains an error message if the group type is missing. |
| 10 | */ |
| 11 | |
| 12 | use AdvancedAds\Admin\Upgrades; |
| 13 | use AdvancedAds\Utilities\WordPress; |
| 14 | |
| 15 | $group_types = wp_advads_get_group_types(); |
| 16 | $group_id = $group->get_id(); |
| 17 | ?> |
| 18 | <div class="advads-ad-group-form"> |
| 19 | <form name="update-group" method="post"> |
| 20 | <input type="hidden" name="nonce" value="<?php echo esc_attr( wp_create_nonce( 'advads-update-group' ) ); ?>"> |
| 21 | <?php |
| 22 | echo $group->get_hints_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 23 | |
| 24 | ob_start(); |
| 25 | ?> |
| 26 | <input type="hidden" class="advads-group-id" name="advads-groups[<?php echo esc_attr( $group_id ); ?>][id]" value="<?php echo esc_attr( $group_id ); ?>"/> |
| 27 | <input type="text" name="advads-groups[<?php echo esc_attr( $group_id ); ?>][name]" value="<?php echo esc_attr( $group->get_name() ); ?>"/> |
| 28 | <?php |
| 29 | $option_content = ob_get_clean(); |
| 30 | |
| 31 | WordPress::render_option( |
| 32 | 'group-name static', |
| 33 | __( 'Name', 'advanced-ads' ), |
| 34 | $option_content |
| 35 | ); |
| 36 | |
| 37 | ob_start(); |
| 38 | ?> |
| 39 | <div class="advads-ad-group-type"> |
| 40 | <?php if ( $this->type_error ) : ?> |
| 41 | <p class="advads-notice-inline advads-error"><?php echo esc_html( $this->type_error ); ?></p> |
| 42 | <?php |
| 43 | endif; |
| 44 | foreach ( $group_types as $group_type ) : |
| 45 | if ( $group_type->is_premium() ) { |
| 46 | continue; |
| 47 | } |
| 48 | ?> |
| 49 | <label title="<?php echo esc_html( $group_type->get_description() ); ?>"> |
| 50 | <input type="radio" name="advads-groups[<?php echo esc_attr( $group_id ); ?>][type]" value="<?php echo esc_attr( $group_type->get_id() ); ?>" <?php checked( $group->get_type(), $group_type->get_id() ); ?>/> |
| 51 | <?php echo esc_html( $group_type->get_title() ); ?> |
| 52 | </label> |
| 53 | <?php endforeach; ?> |
| 54 | |
| 55 | <?php |
| 56 | foreach ( $group_types as $group_type ) : |
| 57 | if ( ! $group_type->is_premium() ) { |
| 58 | continue; |
| 59 | } |
| 60 | ?> |
| 61 | <label title="<?php echo esc_html( $group_type->get_description() ); ?>"> |
| 62 | <input type="radio" name="advads-groups[<?php echo esc_attr( $group_id ); ?>][type]" value="<?php echo esc_attr( $group_type->get_id() ); ?>" disabled/> |
| 63 | <?php echo esc_html( $group_type->get_title() ); ?> |
| 64 | </label> |
| 65 | <?php endforeach; ?> |
| 66 | |
| 67 | <?php if ( wp_advads()->groups->types->has_premium() ) : ?> |
| 68 | <label> |
| 69 | <?php Upgrades::upgrade_link( __( 'Get all group types with All Access', 'advanced-ads' ), 'https://wpadvancedads.com/add-ons/all-access/', 'upgrades-pro-groups' ); ?> |
| 70 | </label> |
| 71 | <?php endif; ?> |
| 72 | </div> |
| 73 | <?php |
| 74 | $option_content = ob_get_clean(); |
| 75 | |
| 76 | WordPress::render_option( |
| 77 | 'group-type static', |
| 78 | esc_attr__( 'Type', 'advanced-ads' ), |
| 79 | $option_content |
| 80 | ); |
| 81 | |
| 82 | ob_start(); |
| 83 | ?> |
| 84 | <select name="advads-groups[<?php echo esc_attr( $group_id ); ?>][ad_count]"> |
| 85 | <?php |
| 86 | $sorted_ads_count = count( $group->get_sorted_ads() ); |
| 87 | $max_ads = $sorted_ads_count >= 10 ? $sorted_ads_count + 2 : 10; |
| 88 | for ( $i = 1; $i <= $max_ads; $i++ ) : |
| 89 | ?> |
| 90 | <option <?php selected( $group->get_ad_count(), $i ); ?>><?php echo esc_html( $i ); ?></option> |
| 91 | <?php |
| 92 | endfor; |
| 93 | ?> |
| 94 | <option <?php selected( $group->get_ad_count(), 'all' ); ?> value="all"><?php echo esc_attr_x( 'all', 'option to display all ads in an ad groups', 'advanced-ads' ); ?></option> |
| 95 | </select> |
| 96 | <?php |
| 97 | $option_content = ob_get_clean(); |
| 98 | |
| 99 | WordPress::render_option( |
| 100 | 'group-number advads-group-type-default advads-group-type-ordered', |
| 101 | esc_attr__( 'Visible ads', 'advanced-ads' ), |
| 102 | $option_content, |
| 103 | esc_attr__( 'Number of ads that are visible at the same time', 'advanced-ads' ) |
| 104 | ); |
| 105 | |
| 106 | do_action( 'advanced-ads-group-form-options', $group ); |
| 107 | |
| 108 | ob_start(); |
| 109 | require 'list-row-option-ads.php'; |
| 110 | $option_content = ob_get_clean(); |
| 111 | WordPress::render_option( |
| 112 | 'group-ads static', |
| 113 | esc_attr__( 'Ads', 'advanced-ads' ), |
| 114 | $option_content |
| 115 | ); |
| 116 | ?> |
| 117 | </form> |
| 118 | </div> |
| 119 |