EDD_SL_Plugin_Updater.php
5 years ago
ad-ajax.php
5 years ago
ad-debug.php
6 years ago
ad-health-notices.php
6 years ago
ad-model.php
5 years ago
ad-select.php
9 years ago
ad.php
5 years ago
ad_ajax_callbacks.php
5 years ago
ad_group.php
5 years ago
ad_placements.php
5 years ago
ad_type_abstract.php
5 years ago
ad_type_content.php
5 years ago
ad_type_dummy.php
5 years ago
ad_type_group.php
5 years ago
ad_type_image.php
5 years ago
ad_type_plain.php
5 years ago
checks.php
5 years ago
compatibility.php
5 years ago
display-conditions.php
5 years ago
filesystem.php
8 years ago
frontend-notices.php
6 years ago
frontend_checks.php
5 years ago
plugin.php
5 years ago
upgrades.php
6 years ago
utils.php
5 years ago
visitor-conditions.php
6 years ago
widget.php
6 years ago
ad_type_group.php
114 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Advanced Ads Plain Ad Type |
| 4 | * |
| 5 | * @package Advanced_Ads |
| 6 | * @author Thomas Maier <support@wpadvancedads.com> |
| 7 | * @license GPL-2.0+ |
| 8 | * @link https://wpadvancedads.com |
| 9 | * @copyright 2014-2016 Thomas Maier, Advanced Ads GmbH |
| 10 | * |
| 11 | * Class containing information about the plain text/code ad type |
| 12 | * |
| 13 | * see ad-type-content.php for a better sample on ad type |
| 14 | * |
| 15 | * @since 1.7.1.1 |
| 16 | * |
| 17 | */ |
| 18 | class Advanced_Ads_Ad_Type_Group extends Advanced_Ads_Ad_Type_Abstract{ |
| 19 | |
| 20 | /** |
| 21 | * ID - internal type of the ad type |
| 22 | * |
| 23 | */ |
| 24 | public $ID = 'group'; |
| 25 | |
| 26 | /** |
| 27 | * Set basic attributes |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | $this->title = __( 'Ad Group', 'advanced-ads' ); |
| 31 | $this->description = __( 'Choose an existing ad group. Use this type when you want to assign the same display and visitor conditions to all ads in that group.', 'advanced-ads' ); |
| 32 | $this->parameters = array( |
| 33 | 'group_id' => 0 |
| 34 | ); |
| 35 | |
| 36 | // on save, remove the group in which the ad is itself to prevent infinite loops |
| 37 | add_action( 'save_post_advanced_ads', array($this, 'remove_from_ad_group'), 1 ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * When saving the ad, remove it from the ad group, if this is the group assigned as ad content |
| 42 | * see also: /admin/includes/class-ad-groups-list.php::update_groups() |
| 43 | * |
| 44 | * @param integer $post_id ID of the post. |
| 45 | */ |
| 46 | public function remove_from_ad_group( $post_id ){ |
| 47 | |
| 48 | // phpcs:disable WordPress.Security.NonceVerification.Missing -- nonce is verified before calling the hook |
| 49 | if( ! isset( $_POST['post_type'] ) || $_POST['post_type'] !== Advanced_Ads::POST_TYPE_SLUG ){ |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | if( isset( $_POST[ 'advanced_ad' ]['output']['group_id'] ) ){ |
| 54 | $group_id = (int) $_POST['advanced_ad']['output']['group_id']; |
| 55 | if( isset( $_POST['tax_input']['advanced_ads_groups'] ) ){ |
| 56 | if(( $key = array_search( $group_id, $_POST['tax_input']['advanced_ads_groups'])) !== false ) { |
| 57 | $res = wp_remove_object_terms( $post_id, $group_id, Advanced_Ads::AD_GROUP_TAXONOMY ); |
| 58 | unset( $_POST['tax_input']['advanced_ads_groups'][$key] ); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | // phpcs:enable |
| 63 | } |
| 64 | |
| 65 | |
| 66 | /** |
| 67 | * Output for the ad parameters metabox |
| 68 | * |
| 69 | * this will be loaded using ajax when changing the ad type radio buttons |
| 70 | * echo the output right away here |
| 71 | * name parameters must be in the "advanced_ads" array |
| 72 | * |
| 73 | * @param obj $ad ad object |
| 74 | */ |
| 75 | public function render_parameters($ad){ |
| 76 | |
| 77 | $group_id = ( isset( $ad->output['group_id'] ) ) ? $ad->output['group_id'] : ''; |
| 78 | |
| 79 | $select = array(); |
| 80 | $model = Advanced_Ads::get_instance()->get_model(); |
| 81 | |
| 82 | // load all ad groups |
| 83 | $groups = $model->get_ad_groups(); |
| 84 | |
| 85 | if( ! is_array( $groups ) || ! count( $groups ) ){ |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | ?><label for="advads-group-id" class="label"><?php _e('ad group', 'advanced-ads'); ?></label><div><select name="advanced_ad[output][group_id]" id="advads-group-id"><?php |
| 90 | |
| 91 | foreach ( $groups as $_group ) { |
| 92 | ?><option value="<?php echo $_group->term_id; ?>" <?php selected( $_group->term_id, $group_id ); ?>><?php echo $_group->name; ?></option><?php |
| 93 | } |
| 94 | |
| 95 | ?></select></div><hr/><?php |
| 96 | |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Prepare the ads frontend output |
| 101 | * |
| 102 | * @param obj $ad ad object |
| 103 | * @return str $content ad content prepared for frontend output |
| 104 | */ |
| 105 | public function prepare_output($ad){ |
| 106 | $group_id = ( isset( $ad->output['group_id'] ) ) ? absint( $ad->output['group_id'] ) : 0; |
| 107 | |
| 108 | if( $group_id ){ |
| 109 | return get_ad_group( $group_id, $ad->args ); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | } |
| 114 |