PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.10.8
Advanced Ads – Ad Manager & AdSense v1.10.8
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 7 years ago ad-ajax.php 8 years ago ad-debug.php 8 years ago ad-model.php 8 years ago ad-select.php 9 years ago ad.php 7 years ago ad_ajax_callbacks.php 7 years ago ad_group.php 7 years ago ad_placements.php 7 years ago ad_type_abstract.php 8 years ago ad_type_content.php 8 years ago ad_type_dummy.php 8 years ago ad_type_group.php 8 years ago ad_type_image.php 7 years ago ad_type_plain.php 8 years ago checks.php 7 years ago compatibility.php 7 years ago display-conditions.php 7 years ago filesystem.php 8 years ago frontend_checks.php 7 years ago plugin.php 7 years ago upgrades.php 9 years ago utils.php 7 years ago visitor-conditions.php 7 years ago widget.php 7 years ago
upgrades.php
268 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 // the 'advanced_ads_edit_ads' capability was added to POST_TYPE_SLUG post type in this version
17 if ( ! isset( $internal_options['version'] ) || version_compare( $internal_options['version'], '1.7.2', '<' ) ) {
18 Advanced_Ads_Plugin::get_instance()->create_capabilities();
19 }
20
21 // suppress version update?
22 $suppress_version_number_update = false;
23
24 // don’t upgrade if no previous version existed
25 if( ! empty( $internal_options['version'] ) ) {
26 if ( version_compare( $internal_options['version'], '1.7' ) == -1 ) {
27 // run with wp_loaded action, because WP_Query is needed and some plugins inject data that is not yet initialized
28 add_action( 'wp_loaded', array( $this, 'upgrade_1_7') );
29 }
30
31 if ( version_compare( $internal_options['version'], '1.7.4' ) == -1 ) {
32 // upgrate version number only after this ran through, because of the used filter only available in admin
33 if( ! is_admin() ){
34 $suppress_version_number_update = true;
35 // run with wp_loaded action, because Upgrades are checked in the plugins_loaded hook
36 } else {
37 add_action( 'wp_loaded', array( $this, 'upgrade_1_7_4') );
38 }
39 }
40 }
41
42 // update version notices – if this doesn’t happen here, the upgrade might run multiple times and destroy updated data
43 if( ! $suppress_version_number_update ){
44 Advanced_Ads_Admin_Notices::get_instance()->update_version_number();
45 }
46 }
47
48 /**
49 * upgrade data to version 1.7
50 * rewrite existing display conditions
51 */
52 public function upgrade_1_7(){
53
54 // get all ads, regardless of the publish status
55 $args['post_status'] = 'any';
56 $args['suppress_filters'] = true; // needed to remove issue with a broken plugin from the repository
57 $ads = Advanced_Ads::get_instance()->get_model()->get_ads( $args );
58
59 // iterate through ads
60 // error_log(print_r($ads, true));
61 error_log(print_r('–– STARTING ADVANCED ADS data upgrade to version 1.7 ––', true));
62 foreach( $ads as $_ad ){
63 // ad options
64 $option_key = Advanced_Ads_Ad::$options_meta_field;
65 if( !isset( $_ad->ID ) || ! $option_key ){
66 continue;
67 }
68 $options = get_post_meta( $_ad->ID, $option_key, true );
69 // rewrite display conditions
70 if( ! isset( $options['conditions'] ) ){
71 continue;
72 }
73
74 error_log(print_r('AD ID: ' . $_ad->ID, true));
75 error_log(print_r('OLD CONDITIONS', true));
76 error_log(print_r($options['conditions'], true));
77
78 $old_conditions = $options['conditions'];
79
80 // check if conditions are disabled
81 if( ! isset( $old_conditions['enabled'] ) || ! $old_conditions['enabled'] ){
82 $new_conditions = '';
83 } else {
84 $new_conditions = array();
85
86 // rewrite general conditions
87 $old_general_conditions = array(
88 'is_front_page',
89 'is_singular',
90 'is_archive',
91 'is_search',
92 'is_404',
93 'is_attachment',
94 'is_main_query'
95 );
96 $general = array();
97 foreach( $old_general_conditions as $_general_condition ){
98 if( isset( $old_conditions[ $_general_condition ] ) && $old_conditions[ $_general_condition ] ) {
99 $general[] = $_general_condition;
100 }
101 }
102 // move general conditions into display conditions
103 // only, if the number of conditions in the previous setting is lower, because only that means there is an active limitation
104 // not sure if allowing an empty array is logical, but some users might have set this up to hide an ad
105 if( count( $general ) < count( $old_general_conditions ) ){
106 $new_conditions[] = array(
107 'type' => 'general',
108 'value' => $general
109 );
110 }
111
112 // rewrite post types condition
113 if( isset( $old_conditions[ 'posttypes' ]['include'] )
114 && ( !isset ( $old_conditions[ 'posttypes' ]['all'] )
115 || ! $old_conditions[ 'posttypes' ]['all'] ) ) {
116 if ( is_string( $old_conditions[ 'posttypes' ]['include']) ) {
117 $old_conditions[ 'posttypes' ]['include'] = explode( ',', $old_conditions[ 'posttypes' ]['include'] );
118 }
119 $new_conditions[] = array(
120 'type' => 'posttypes',
121 'value' => $old_conditions[ 'posttypes' ]['include']
122 );
123 }
124
125 /**
126 * rewrite category ids and category archive ids
127 *
128 * the problem is that before there was no connection between term ids and taxonomy, now, each taxonomy has its own condition
129 */
130 // check, if there are even such options set
131 if( ( isset( $old_conditions[ 'categoryids' ] )
132 && ( !isset ( $old_conditions[ 'categoryids' ]['all'] )
133 || ! $old_conditions[ 'categoryids' ]['all'] ) )
134 || ( isset( $old_conditions[ 'categoryarchiveids' ] )
135 && ( !isset ( $old_conditions[ 'categoryarchiveids' ]['all'] )
136 || ! $old_conditions[ 'categoryarchiveids' ]['all'] ) ))
137 {
138
139 // get all taxonomies
140 $taxonomies = get_taxonomies( array('public' => true, 'publicly_queryable' => true), 'objects', 'or' );
141 $taxonomy_terms = array();
142 foreach ( $taxonomies as $_tax ) {
143 if( $_tax->name === 'advanced_ads_groups' ){
144 continue;
145 }
146 // get all terms
147 $terms = get_terms( $_tax->name, array('hide_empty' => false, 'number' => 0, 'fields' => 'ids' ) );
148 if ( is_wp_error( $terms ) || ! count( $terms ) ){
149 continue;
150 } else {
151 $taxonomy_terms[ $_tax->name ] = $terms;
152 }
153
154 // get terms that are in all terms and in active terms
155 if( isset( $old_conditions[ 'categoryids' ] )
156 && ( !isset ( $old_conditions[ 'categoryids' ]['all'] )
157 || ! $old_conditions[ 'categoryids' ]['all'] ) )
158 {
159 // honor "include" option first
160 if( isset ( $old_conditions[ 'categoryids' ]['include'] ) && count( $old_conditions[ 'categoryids' ]['include'] )
161 && $same_values = array_intersect($terms, $old_conditions[ 'categoryids' ]['include']) ){
162 $new_conditions[] = array(
163 'type' => 'taxonomy_' . $_tax->name ,
164 'operator' => 'is',
165 'value' => $same_values
166 );
167 } elseif ( isset ( $old_conditions[ 'categoryids' ]['exclude'] ) && count( $old_conditions[ 'categoryids' ]['exclude'] )
168 && $same_values = array_intersect($terms, $old_conditions[ 'categoryids' ]['exclude']) ){
169 $new_conditions[] = array(
170 'type' => 'taxonomy_' . $_tax->name ,
171 'operator' => 'is_not',
172 'value' => $same_values
173 );
174 }
175 }
176
177 // get terms that are in all terms and in active terms
178 if( isset( $old_conditions[ 'categoryarchiveids' ] )
179 && ( !isset ( $old_conditions[ 'categoryarchiveids' ]['all'] )
180 || ! $old_conditions[ 'categoryarchiveids' ]['all'] ) )
181 {
182 // honor "include" option first
183 if( isset ( $old_conditions[ 'categoryarchiveids' ]['include'] ) && count( $old_conditions[ 'categoryarchiveids' ]['include'] )
184 && $same_values = array_intersect($terms, $old_conditions[ 'categoryarchiveids' ]['include']) ){
185 $new_conditions[] = array(
186 'type' => 'archive_' . $_tax->name ,
187 'operator' => 'is',
188 'value' => $same_values
189 );
190 } elseif ( isset ( $old_conditions[ 'categoryarchiveids' ]['exclude'] ) && count( $old_conditions[ 'categoryarchiveids' ]['exclude'] )
191 && $same_values = array_intersect($terms, $old_conditions[ 'categoryarchiveids' ]['exclude']) ){
192 $new_conditions[] = array(
193 'type' => 'archive_' . $_tax->name ,
194 'operator' => 'is_not',
195 'value' => $same_values
196 );
197 }
198 }
199 }
200 }
201
202 // rewrite single post ids
203 if( isset ( $old_conditions[ 'postids' ]['ids'] )
204 && isset ( $old_conditions[ 'postids' ]['method'] )
205 && $old_conditions[ 'postids' ]['method']
206 && ( !isset ( $old_conditions[ 'postids' ]['all'] )
207 || ! $old_conditions[ 'postids' ]['all'] ) ) {
208 $operator = ( $old_conditions[ 'postids' ]['method'] === 'exclude' ) ? 'is_not' : 'is';
209 if ( is_string( $old_conditions[ 'postids' ]['ids']) ) {
210 $old_conditions[ 'postids' ]['ids'] = explode( ',', $old_conditions[ 'postids' ]['ids'] );
211 }
212 $new_conditions[] = array(
213 'type' => 'postids',
214 'operator' => $operator,
215 'value' => $old_conditions[ 'postids' ]['ids']
216 );
217 }
218 }
219
220 error_log(print_r('NEW CONDITIONS', true));
221 error_log(print_r($new_conditions, true));
222
223 $options['conditions'] = $new_conditions;
224
225 // save conditions
226 update_post_meta( $_ad->ID, $option_key, $options );
227 }
228
229 error_log(print_r('up to 1.7', true));
230 }
231
232 /**
233 * upgrades for version 1.7.4
234 * reactivate active add-on licenses, needed only once after upgrade of the plugin shop
235 */
236 public function upgrade_1_7_4(){
237
238 // ignore, if not main blog
239 if( is_multisite() && ! is_main_site() ){
240 return;
241 }
242
243 $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
244
245 // return if no add-ons found
246 if( $add_ons === array() ) {
247 return;
248 }
249
250 error_log(print_r('–– STARTING ADVANCED ADS 1.7.4 upgrade ––', true));
251 foreach( $add_ons as $_add_on_key => $_add_on ){
252
253 // check status
254 if(Advanced_Ads_Admin_Licenses::get_instance()->get_license_status( $_add_on['options_slug'] ) !== 'valid' ) {
255 continue;
256 }
257
258 // retrieve our license key from the DB
259 $licenses = get_option(ADVADS_SLUG . '-licenses', array());
260 $license_key = isset($licenses[$_add_on_key]) ? $licenses[$_add_on_key] : '';
261
262 $result = Advanced_Ads_Admin::get_instance()->activate_license( $_add_on_key, $_add_on['name'], $_add_on['options_slug'], $license_key );
263 error_log( sprintf( 'Register license key for %s: %s', $_add_on['name'], $result ) );
264
265 }
266 }
267
268 }