PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.7
Advanced Ads – Ad Manager & AdSense v1.7
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 / classes / upgrades.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 10 years ago ad-ajax.php 10 years ago ad-model.php 11 years ago ad-select.php 10 years ago ad.php 10 years ago ad_ajax_callbacks.php 10 years ago ad_group.php 10 years ago ad_placements.php 10 years ago ad_type_abstract.php 11 years ago ad_type_content.php 10 years ago ad_type_image.php 10 years ago ad_type_plain.php 10 years ago checks.php 10 years ago display-conditions.php 10 years ago plugin.php 10 years ago upgrades.php 10 years ago visitor-conditions.php 10 years ago widget.php 10 years ago
upgrades.php
213 lines
1 <?php
2
3 /**
4 * Upgrade logic from older data to new one
5 *
6 * the version number itself is changed in /admin/includes/class-notices.php::register_version_notices()
7 *
8 * @since 1.7
9 */
10 class Advanced_Ads_Upgrades {
11
12 public function __construct(){
13
14 $internal_options = Advanced_Ads_Plugin::get_instance()->internal_options();
15
16 // don’t upgrade if no previous version existed
17 if( empty( $internal_options['version'] ) ) {
18 return;
19 }
20
21 if ( version_compare( $internal_options['version'], '1.7' ) == -1 ) {
22 $this->upgrade_1_7();
23 }
24
25 // update version notices – if this doesn’t happen here, the upgrade might run multiple times and destroy updated data
26 Advanced_Ads_Admin_Notices::get_instance()->register_version_notices();
27 }
28
29 /**
30 * upgrade data to version 1.7
31 * rewrite existing display conditions
32 */
33 public function upgrade_1_7(){
34
35 // get all ads, regardless of the publish status
36 $args['post_status'] = 'any';
37 $args['suppress_filters'] = true; // needed to remove issue with a broken plugin from the repository
38 $ads = Advanced_Ads::get_instance()->get_model()->get_ads( $args );
39
40 // iterate through ads
41 // error_log(print_r($ads, true));
42 error_log(print_r('–– STARTING ADVANCED ADS data upgrade to version 1.7 ––', true));
43 foreach( $ads as $_ad ){
44 // ad options
45 $option_key = Advanced_Ads_Ad::$options_meta_field;
46 if( !isset( $_ad->ID ) || ! $option_key ){
47 continue;
48 }
49 $options = get_post_meta( $_ad->ID, $option_key, true );
50 // rewrite display conditions
51 if( ! isset( $options['conditions'] ) ){
52 continue;
53 }
54
55 error_log(print_r('AD ID: ' . $_ad->ID, true));
56 error_log(print_r('OLD CONDITIONS', true));
57 error_log(print_r($options['conditions'], true));
58
59 $old_conditions = $options['conditions'];
60
61 // check if conditions are disabled
62 if( ! isset( $old_conditions['enabled'] ) || ! $old_conditions['enabled'] ){
63 $new_conditions = '';
64 } else {
65 $new_conditions = array();
66
67 // rewrite general conditions
68 $old_general_conditions = array(
69 'is_front_page',
70 'is_singular',
71 'is_archive',
72 'is_search',
73 'is_404',
74 'is_attachment',
75 'is_main_query'
76 );
77 $general = array();
78 foreach( $old_general_conditions as $_general_condition ){
79 if( isset( $old_conditions[ $_general_condition ] ) && $old_conditions[ $_general_condition ] ) {
80 $general[] = $_general_condition;
81 }
82 }
83 // move general conditions into display conditions
84 // only, if the number of conditions in the previous setting is lower, because only that means there is an active limitation
85 // not sure if allowing an empty array is logical, but some users might have set this up to hide an ad
86 if( count( $general ) < count( $old_general_conditions ) ){
87 $new_conditions[] = array(
88 'type' => 'general',
89 'value' => $general
90 );
91 }
92
93 // rewrite post types condition
94 if( isset( $old_conditions[ 'posttypes' ]['include'] )
95 && ( !isset ( $old_conditions[ 'posttypes' ]['all'] )
96 || ! $old_conditions[ 'posttypes' ]['all'] ) ) {
97 if ( is_string( $old_conditions[ 'posttypes' ]['include']) ) {
98 $old_conditions[ 'posttypes' ]['include'] = explode( ',', $old_conditions[ 'posttypes' ]['include'] );
99 }
100 $new_conditions[] = array(
101 'type' => 'posttypes',
102 'value' => $old_conditions[ 'posttypes' ]['include']
103 );
104 }
105
106 /**
107 * rewrite category ids and category archive ids
108 *
109 * the problem is that before there was no connection between term ids and taxonomy, now, each taxonomy has its own condition
110 */
111 // check, if there are even such options set
112 if( ( isset( $old_conditions[ 'categoryids' ] )
113 && ( !isset ( $old_conditions[ 'categoryids' ]['all'] )
114 || ! $old_conditions[ 'categoryids' ]['all'] ) )
115 || ( isset( $old_conditions[ 'categoryarchiveids' ] )
116 && ( !isset ( $old_conditions[ 'categoryarchiveids' ]['all'] )
117 || ! $old_conditions[ 'categoryarchiveids' ]['all'] ) ))
118 {
119
120 // get all taxonomies
121 $taxonomies = get_taxonomies( array('public' => true, 'publicly_queryable' => true), 'objects', 'or' );
122 $taxonomy_terms = array();
123 foreach ( $taxonomies as $_tax ) {
124 if( $_tax->name === 'advanced_ads_groups' ){
125 continue;
126 }
127 // get all terms
128 $terms = get_terms( $_tax->name, array('hide_empty' => false, 'number' => 0, 'fields' => 'ids' ) );
129 if ( is_wp_error( $terms ) || ! count( $terms ) ){
130 continue;
131 } else {
132 $taxonomy_terms[ $_tax->name ] = $terms;
133 }
134
135 // get terms that are in all terms and in active terms
136 if( isset( $old_conditions[ 'categoryids' ] )
137 && ( !isset ( $old_conditions[ 'categoryids' ]['all'] )
138 || ! $old_conditions[ 'categoryids' ]['all'] ) )
139 {
140 // honor "include" option first
141 if( isset ( $old_conditions[ 'categoryids' ]['include'] ) && count( $old_conditions[ 'categoryids' ]['include'] )
142 && $same_values = array_intersect($terms, $old_conditions[ 'categoryids' ]['include']) ){
143 $new_conditions[] = array(
144 'type' => 'taxonomy_' . $_tax->name ,
145 'operator' => 'is',
146 'value' => $same_values
147 );
148 } elseif ( isset ( $old_conditions[ 'categoryids' ]['exclude'] ) && count( $old_conditions[ 'categoryids' ]['exclude'] )
149 && $same_values = array_intersect($terms, $old_conditions[ 'categoryids' ]['exclude']) ){
150 $new_conditions[] = array(
151 'type' => 'taxonomy_' . $_tax->name ,
152 'operator' => 'is_not',
153 'value' => $same_values
154 );
155 }
156 }
157
158 // get terms that are in all terms and in active terms
159 if( isset( $old_conditions[ 'categoryarchiveids' ] )
160 && ( !isset ( $old_conditions[ 'categoryarchiveids' ]['all'] )
161 || ! $old_conditions[ 'categoryarchiveids' ]['all'] ) )
162 {
163 // honor "include" option first
164 if( isset ( $old_conditions[ 'categoryarchiveids' ]['include'] ) && count( $old_conditions[ 'categoryarchiveids' ]['include'] )
165 && $same_values = array_intersect($terms, $old_conditions[ 'categoryarchiveids' ]['include']) ){
166 $new_conditions[] = array(
167 'type' => 'archive_' . $_tax->name ,
168 'operator' => 'is',
169 'value' => $same_values
170 );
171 } elseif ( isset ( $old_conditions[ 'categoryarchiveids' ]['exclude'] ) && count( $old_conditions[ 'categoryarchiveids' ]['exclude'] )
172 && $same_values = array_intersect($terms, $old_conditions[ 'categoryarchiveids' ]['exclude']) ){
173 $new_conditions[] = array(
174 'type' => 'archive_' . $_tax->name ,
175 'operator' => 'is_not',
176 'value' => $same_values
177 );
178 }
179 }
180 }
181 }
182
183 // rewrite single post ids
184 if( isset ( $old_conditions[ 'postids' ]['ids'] )
185 && isset ( $old_conditions[ 'postids' ]['method'] )
186 && $old_conditions[ 'postids' ]['method']
187 && ( !isset ( $old_conditions[ 'postids' ]['all'] )
188 || ! $old_conditions[ 'postids' ]['all'] ) ) {
189 $operator = ( $old_conditions[ 'postids' ]['method'] === 'exclude' ) ? 'is_not' : 'is';
190 if ( is_string( $old_conditions[ 'postids' ]['ids']) ) {
191 $old_conditions[ 'postids' ]['ids'] = explode( ',', $old_conditions[ 'postids' ]['ids'] );
192 }
193 $new_conditions[] = array(
194 'type' => 'postids',
195 'operator' => $operator,
196 'value' => $old_conditions[ 'postids' ]['ids']
197 );
198 }
199 }
200
201 error_log(print_r('NEW CONDITIONS', true));
202 error_log(print_r($new_conditions, true));
203
204 $options['conditions'] = $new_conditions;
205
206 // save conditions
207 update_post_meta( $_ad->ID, $option_key, $options );
208 }
209
210 error_log(print_r('up to 1.7', true));
211 }
212
213 }