-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalnp-beta-tester.php
741 lines (629 loc) · 23.7 KB
/
alnp-beta-tester.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
<?php
/**
* Plugin Name: Auto Load Next Post: Beta Tester
* Plugin URI: https://github.com/autoloadnextpost/alnp-beta-tester
* Version: 3.0.0
* Description: Run bleeding edge versions of Auto Load Next Post from the GitHub repo. This will replace your installed version of Auto Load Next Post with the latest tagged prerelease on GitHub - use with caution, and not on production sites. You have been warned.
* Author: Auto Load Next Post
* Author URI: https://autoloadnextpost.com
* Developer: Sébastien Dumont
* Developer URI: https://sebastiendumont.com
* GitHub Plugin URI: https://github.com/autoloadnextpost/alnp-beta-tester
*
* Text Domain: alnp-beta-tester
* Domain Path: /languages/
*
* Requires at least: 4.5
* Tested up to: 5.2
*
* Based on WP_GitHub_Updater by Joachim Kudish.
* Forked from WooCommerce Beta Tester by Mike Jolley and Claudio Sanches.
*
* Copyright: © 2019 Sébastien Dumont
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package Auto Load Next Post: Beta Tester
* @author Sébastien Dumont
* @copyright Copyright © 2019, Sébastien Dumont
* @license GNU General Public License v3.0 http://www.gnu.org/licenses/gpl-3.0.html
*/
if ( ! class_exists( 'ALNP_Beta_Tester' ) ) {
class ALNP_Beta_Tester {
/**
* Plugin Configuration
*
* @access private
* @since 1.0.0
*/
private $config = array();
/**
* GitHub Data
*
* @access protected
* @static
* @since 1.0.0
*/
protected static $_instance = null;
/**
* Plugin Version
*
* @access private
* @static
* @since 2.0.0
*/
private static $version = '3.0.0';
/**
* Main Instance
*
* @access public
* @static
* @since 1.0.0
* @return ALNP_Beta_Tester - Main instance
*/
public static function instance() {
return self::$_instance = is_null( self::$_instance ) ? new self() : self::$_instance;
}
/**
* Cloning is forbidden.
*
* @access public
* @since 2.0.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cloning this object is forbidden.', 'alnp-beta-tester' ), self::$version );
}
/**
* Unserializing instances of this class is forbidden.
*
* @access public
* @since 2.0.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'alnp-beta-tester' ), self::$version );
}
/**
* Constructor
*
* @access public
* @static
* @since 1.0.0
* @version 3.0.0
*/
public function __construct() {
$this->config = array(
'plugin_file' => 'auto-load-next-post/auto-load-next-post.php',
'slug' => 'auto-load-next-post',
'proper_folder_name' => 'auto-load-next-post',
'api_url' => 'https://api.github.com/repos/autoloadnextpost/auto-load-next-post',
'requires' => '4.5',
'tested' => '5.2.3',
'requires_php' => '5.6'
);
add_action( 'plugin_loaded', array( $this, 'flush_update_cache' ) );
add_action( 'init', array( $this, 'check_alnp_installed' ) );
add_action( 'init', array( $this, 'load_text_domain' ), 0 );
} // END __construct()
/**
* Run these filters once Auto Load Next Post is installed and active.
*
* @access public
* @return void
* @since 2.0.2
*/
public function alnp_active() {
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'api_check' ) );
add_filter( 'plugins_api', array( $this, 'get_plugin_info' ), 10, 3 );
add_filter( 'upgrader_source_selection', array( $this, 'upgrader_source_selection' ), 10, 3 );
// Auto update Auto Load Next Post.
add_filter( 'auto_update_plugin', array( $this, 'auto_update_alnp' ), 100, 2 );
} // END alnp_active()
/**
* Load the plugin text domain once the plugin has initialized.
*
* @access public
* @since 2.0.0
* @return void
*/
public function load_text_domain() {
load_plugin_textdomain( 'alnp-beta-tester', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
} // END load_text_domain()
/**
* Run once the plugin has loaded to flush the update cache.
*
* @access public
* @static
* @since 2.0.0
*/
public static function flush_update_cache() {
delete_site_transient( 'update_plugins' ); // Clear all plugin update data
delete_site_transient( 'auto_load_next_post_latest_tag' ); // Previous beta tester value
} // END flush_update_cache()
/**
* Checks if Auto Load Next Post is installed before running filters for the WordPress updater.
*
* @access public
* @since 2.0.0
* @return bool|void
*/
public function check_alnp_installed() {
if ( ! defined( 'AUTO_LOAD_NEXT_POST_VERSION' ) ) {
add_action( 'admin_notices', array( $this, 'alnp_not_installed' ) );
return false;
}
// Auto Load Next Post is active.
$this->alnp_active();
} // END check_alnp_installed()
/**
* Auto Load Next Post is Not Installed Notice.
*
* @access public
* @since 2.0.0
* @version 2.0.2
* @global string $pagenow
* @return void
*/
public function alnp_not_installed() {
global $pagenow;
if ( $pagenow == 'update.php' ) {
return false;
}
echo '<div class="notice notice-error">';
echo '<p>' . sprintf( __( '%1$s requires %2$s%3$s%4$s to be installed and activated in order to serve updates from GitHub.', 'alnp-beta-tester' ), esc_html__( 'Auto Load Next Post: Beta Tester', 'alnp-beta-tester' ), '<strong>', '</strong>', esc_html__( 'Auto Load Next Post', 'alnp-beta-tester' ) ) . '</p>';
echo '<p>';
if ( ! is_plugin_active( 'auto-load-next-post/auto-load-next-post.php' ) && current_user_can( 'activate_plugin', 'auto-load-next-post/auto-load-next-post.php' ) ) :
echo '<a href="' . esc_url( wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=auto-load-next-post/auto-load-next-post.php&plugin_status=active' ), 'activate-plugin_auto-load-next-post/auto-load-next-post.php' ) ) . '" class="button button-primary">' . sprintf( esc_html__( 'Activate %s', 'alnp-beta-tester' ), esc_html__( 'Auto Load Next Post', 'alnp-beta-tester' ) ) . '</a>';
else :
if ( current_user_can( 'install_plugins' ) ) {
$url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=auto-load-next-post' ), 'install-plugin_auto-load-next-post' );
} else {
$url = 'https://wordpress.org/plugins/auto-load-next-post/';
}
echo '<a href="' . esc_url( $url ) . '" class="button button-primary">' . sprintf( esc_html__( 'Install %s', 'alnp-beta-tester' ), esc_html__( 'Auto Load Next Post', 'alnp-beta-tester' ) ) . '</a>';
endif;
if ( current_user_can( 'deactivate_plugin', 'alnp-beta-tester/alnp-beta-tester.php' ) ) :
echo '<a href="' . esc_url( wp_nonce_url( 'plugins.php?action=deactivate&plugin=alnp-beta-tester/alnp-beta-tester.php&plugin_status=inactive', 'deactivate-plugin_alnp-beta-tester/alnp-beta-tester.php' ) ) . '" class="button button-secondary">' . sprintf( esc_html__( 'Turn off %s plugin', 'alnp-beta-tester' ), esc_html__( 'Auto Load Next Post: Beta Tester', 'alnp-beta-tester' ) ) . '</a>';
endif;
echo '</p>';
echo '</div>';
} // END alnp_not_installed()
/**
* Enable auto updates for Auto Load Next Post.
*
* @access public
* @since 2.0.2
* @version 3.0.0
* @param bool $should_update Should this auto update.
* @param object $plugin Plugin being checked.
* @return bool
*/
public function auto_update_alnp( $should_update, $plugin ) {
if ( ! isset( $plugin->slug ) ) {
return $should_update;
}
if ( 'auto-load-next-post' === $plugin->slug ) {
$should_update = true;
}
return $should_update;
} // END auto_update_alnp()
/**
* Update the required plugin data arguments.
*
* @access public
* @since 1.0.0
* @version 3.0.0
* @return array
*/
public function set_update_args() {
$plugin_data = $this->get_plugin_data();
$this->config['plugin_name'] = 'Auto Load Next Post ' . $this->get_latest_prerelease();
$this->config['description'] = $this->get_description();
$this->config['version'] = $plugin_data['Version'];
$this->config['author'] = $plugin_data['Author'];
$this->config['homepage'] = $plugin_data['PluginURI'];
$this->config['new_version'] = str_replace( 'v', '', $this->get_latest_prerelease() );
$this->config['last_updated'] = $this->get_date();
$this->config['changelog'] = $this->get_changelog();
$this->config['zip_name'] = $this->get_latest_prerelease();
$this->config['zip_url'] = 'https://github.com/autoloadnextpost/auto-load-next-post/archive/' . $this->config['zip_name'] . '.zip';
} // END set_update_args()
/**
* Check wether or not the transients need to be overruled
* and API needs to be called for every single page load.
*
* @access public
* @since 1.0.0
* @return bool overrule or not
*/
public function overrule_transients() {
return ( defined( 'ALNP_BETA_TESTER_FORCE_UPDATE' ) && ALNP_BETA_TESTER_FORCE_UPDATE );
} // END overrule_transients()
/**
* Get New Version from GitHub.
*
* @access public
* @since 1.0.0
* @version 2.0.0
* @return int $tagged_version the version number
*/
public function get_latest_prerelease() {
$tagged_version = get_site_transient( md5( $this->config['slug'] ) . '_latest_tag' );
if ( $this->overrule_transients() || empty( $tagged_version ) ) {
$raw_response = wp_remote_get( trailingslashit( $this->config['api_url'] ) . 'releases' );
if ( is_wp_error( $raw_response ) ) {
return false;
}
$releases = json_decode( $raw_response['body'] );
$tagged_version = false;
if ( is_array( $releases ) ) {
foreach ( $releases as $release ) {
// If the release is a pre-release then return the tagged version.
if ( $release->prerelease ) {
$tagged_version = $release->tag_name;
break;
}
}
}
// Refresh every 6 hours.
if ( ! empty( $tagged_version ) ) {
set_site_transient( md5( $this->config['slug'] ) . '_latest_tag', $tagged_version, 60*60*6 );
}
}
return $tagged_version;
} // END get_latest_prerelease()
/**
* Get Published date of New Version from GitHub.
*
* @access public
* @since 2.0.2
* @return string $published_date of the latest prerelease
*/
public function get_latest_prerelease_date() {
$published_date = get_site_transient( md5( $this->config['slug'] ) . '_latest_published_date' );
if ( $this->overrule_transients() || empty( $published_date ) ) {
$raw_response = wp_remote_get( trailingslashit( $this->config['api_url'] ) . 'releases' );
if ( is_wp_error( $raw_response ) ) {
return false;
}
$releases = json_decode( $raw_response['body'] );
$published_date = false;
if ( is_array( $releases ) ) {
foreach ( $releases as $release ) {
// If the release is a pre-release then return the published date.
if ( $release->prerelease ) {
$published_date = $release->published_at;
break;
}
}
}
// Refresh every 6 hours.
if ( ! empty( $published_date ) ) {
set_site_transient( md5( $this->config['slug'] ) . '_latest_published_date', $published_date, 60 * 60 * 6 );
}
}
return $published_date;
} // END get_latest_prerelease_date()
/**
* Get Changelog of New Version from GitHub.
*
* @access public
* @since 2.0.1
* @version 2.0.2
* @return string $changelog of the latest prerelease
*/
public function get_latest_prerelease_changelog() {
$changelog = get_site_transient( md5( $this->config['slug'] ) . '_latest_changelog' );
if ( $this->overrule_transients() || empty( $changelog ) ) {
$raw_response = wp_remote_get( trailingslashit( $this->config['api_url'] ) . 'releases' );
if ( is_wp_error( $raw_response ) ) {
return false;
}
$releases = json_decode( $raw_response['body'] );
$changelog = false;
if ( is_array( $releases ) ) {
foreach ( $releases as $release ) {
// If the release is a pre-release then return the body.
if ( $release->prerelease ) {
if ( ! class_exists( 'Parsedown' ) ) {
include_once( 'parsedown.php' );
}
$Parsedown = new Parsedown();
$changelog = $Parsedown->text( $release->body );
break;
}
}
}
// Refresh every 6 hours.
if ( ! empty( $changelog ) ) {
set_site_transient( md5( $this->config['slug'] ) . '_latest_changelog', $changelog, 60*60*6 );
}
}
return $changelog;
} // END get_latest_prerelease_changelog()
/**
* Get GitHub Data from the specified repository.
*
* @access public
* @since 1.0.0
* @return array $github_data the data
*/
public function get_github_data() {
if ( ! empty( $this->github_data ) ) {
$github_data = $this->github_data;
} else {
$github_data = get_site_transient( md5( $this->config['slug'] ) . '_github_data' );
if ( $this->overrule_transients() || ( ! isset( $github_data ) || ! $github_data || '' == $github_data ) ) {
$github_data = wp_remote_get( $this->config['api_url'] );
if ( is_wp_error( $github_data ) ) {
return false;
}
$github_data = json_decode( $github_data['body'] );
// refresh every 6 hours
set_site_transient( md5( $this->config['slug'] ) . '_github_data', $github_data, 60*60*6 );
}
// Store the data in this class instance for future calls
$this->github_data = $github_data;
}
return $github_data;
} // END get_github_data()
/**
* Get update date.
*
* @access public
* @since 1.0.0
* @version 2.0.2
* @return string $_date the date
*/
public function get_date() {
$_date = $this->get_latest_prerelease_date();
return ! empty( $_date ) ? date( 'Y-m-d', strtotime( $_date ) ) : false;
} // END get_date()
/**
* Get plugin description.
*
* @access public
* @since 1.0.0
* @return string $_description the description
*/
public function get_description() {
$_description = $this->get_github_data();
return ! empty( $_description->description ) ? $_description->description : false;
} // END get_description()
/**
* Get plugin changelog.
*
* @access public
* @since 2.0.1
* @return string $_changelog the changelog of the release
*/
public function get_changelog() {
$_changelog = $this->get_latest_prerelease_changelog();
return ! empty( $_changelog ) ? $_changelog : false;
} // END get_changelog()
/**
* Get Plugin data.
*
* @access public
* @since 1.0.0
* @return object $data the data
*/
public function get_plugin_data() {
return get_plugin_data( WP_PLUGIN_DIR . '/' . $this->config['plugin_file'] );
} // END get_plugin_data()
/**
* Hook into the plugin update check and connect to GitHub.
*
* @access public
* @since 1.0.0
* @version 3.0.0
* @param object $transient the plugin data transient
* @return object $transient updated plugin data transient
*/
public function api_check( $transient ) {
// If no plugins have been checked then return its value without hacking it.
if ( empty( $transient->checked ) ) {
return $transient;
}
/**
* Clear our transient if we have debug enabled and overruled the transients.
* This will allow the API to check fresh every time.
*
* DEV NOTE: If api checked to many times in a short amount of time,
* GitHub will block you from accessing the API for 1 hour.
*/
if ( WP_DEBUG && $this->overrule_transients() ) {
delete_site_transient( md5( $this->config['slug'] ) . '_latest_tag' );
delete_site_transient( md5( $this->config['slug'] ) . '_latest_changelog' );
}
// Update tags.
$this->set_update_args();
// Check the version and decide if it's new.
$update = version_compare( $this->config['new_version'], $this->config['version'], '>' );
if ( ! $update ) {
return $transient;
}
// Filename.
$filename = $this->config['plugin_file'];
$data = array(
'id' => $this->config['slug'],
'slug' => $this->config['slug'],
'plugin' => $filename,
'new_version' => $this->config['new_version'],
'tested' => $this->config['tested'],
'requires_php' => $this->config['requires_php'],
'url' => $this->config['homepage'],
'icons' => array(
'2x' => esc_url( 'https://raw.githubusercontent.com/autoloadnextpost/auto-load-next-post/master/.wordpress-org/icon-256x256.png' ),
'1x' => esc_url( 'https://raw.githubusercontent.com/autoloadnextpost/auto-load-next-post/master/.wordpress-org/icon-128x128.png' ),
),
'banners' => array(
'low' => esc_url( 'https://raw.githubusercontent.com/autoloadnextpost/auto-load-next-post/master/.wordpress-org/banner-772x250.png' ),
'high' => esc_url( 'https://raw.githubusercontent.com/autoloadnextpost/auto-load-next-post/master/.wordpress-org/banner-1544x500.png' )
),
'package' => $this->config['zip_url'],
'zip_url' => $this->config['zip_url']
);
// Check if its a beta release or a release candidate.
$is_beta_rc = ( $this->is_beta_version( $this->config['new_version'] ) || $this->is_rc_version( $this->config['new_version'] ) );
// Only set the updater to download if its a beta or pre-release version and is newer.
if ( $is_beta_rc ) {
$transient->response[ $filename ] = (object) $data;
unset( $transient->no_update[ $filename ] );
} else {
$transient->no_update[ $filename ] = (object) $data;
unset( $transient->response[ $filename ] );
}
return $transient;
} // END api_check()
/**
* Filters the Plugin Installation API response results.
*
* @access public
* @since 1.0.0
* @version 3.0.0
* @param object|WP_Error $response Response object or WP_Error.
* @param string $action The type of information being requested from the Plugin Installation API.
* @param object $args Plugin API arguments.
* @return object $response The plugin results.
*/
public function get_plugin_info( $response, $action, $args ) {
// Check that we are getting plugin information.
if ( 'plugin_information' !== $action ) {
return $response;
}
// Check if this call for the API is for the right plugin.
if ( ! isset( $args->slug ) || $args->slug != $this->config['slug'] ) {
return $response;
}
// Update tags
$this->set_update_args();
// New Version
$new_version = $this->config['new_version'];
// If the new version is no different than the one installed then just return response.
if ( version_compare( $this->config['version'], $new_version, '=' ) ) {
return $response;
}
// Prepare warning!
$warning = '';
if ( $this->is_stable_version( $new_version ) ) {
$warning = sprintf( __( '%1$s%3$sThis is a stable release%3$s%2$s', 'alnp-beta-tester' ), '<h1>', '</h1>', '<span>⚠</span>' );
}
if ( $this->is_beta_version( $new_version ) ) {
$warning = sprintf( __( '%1$s%3$sThis is a beta release%3$s%2$s', 'alnp-beta-tester' ), '<h1>', '</h1>', '<span>⚠</span>' );
}
if ( $this->is_rc_version( $new_version ) ) {
$warning = sprintf( __( '%1$s%3$sThis is a pre-release%3$s%2$s', 'alnp-beta-tester' ), '<h1>', '</h1>', '<span>⚠</span>' );
}
// Update the results to return.
$response->name = $this->config['plugin_name'];
$response->plugin_name = $this->config['plugin_name'];
$response->version = $new_version;
$response->author = $this->config['author'];
$response->author_homepage = 'https://autoloadnextpost.com';
$response->homepage = $this->config['homepage'];
$response->requires = $this->config['requires'];
$response->tested = $this->config['tested'];
$response->requires_php = $this->config['requires_php'];
$response->last_updated = $this->config['last_updated'];
$response->slug = $this->config['slug'];
$response->plugin = $this->config['slug'];
// Sections
$response->sections = array(
'description' => $this->config['description'],
'changelog' => $this->config['changelog']
);
$response->download_link = $this->config['zip_url'];
$download_counter = wp_remote_get( 'https://autoloadnextpost.com/download/counter/dl-counter.php' );
if ( ! is_wp_error( $download_counter ) ) {
$response->downloaded = wp_remote_retrieve_body( $download_counter );
}
$response->contributors = array(
'autoloadnextpost' => array(
'display_name' => 'Auto Load Next Post',
'profile' => esc_url( 'https://autoloadnextpost.com' ),
'avatar' => get_avatar_url( '[email protected]', array(
'size' => '36',
) ),
),
'sebd86' => array(
'display_name' => 'Sébastien Dumont',
'profile' => esc_url( 'https://sebastiendumont.com' ),
'avatar' => get_avatar_url( '[email protected]', array(
'size' => '36',
) ),
),
);
// Add WordPress dot org banners for recognition.
$response->banners = array(
'low' => 'https://raw.githubusercontent.com/autoloadnextpost/auto-load-next-post/master/.wordpress-org/banner-772x250.png',
'high' => 'https://raw.githubusercontent.com/autoloadnextpost/auto-load-next-post/master/.wordpress-org/banner-1544x500.png'
);
// Apply warning to all sections if any.
foreach ( $response->sections as $key => $section ) {
$response->sections[ $key ] = $warning . $section;
}
return $response;
} // END get_plugin_info()
/**
* Rename the downloaded zip file.
*
* @access public
* @since 1.0.0
* @version 3.0.0
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
* @param string $source File source location.
* @param string $remote_source Remote file source location.
* @param WP_Upgrader $upgrader WP_Upgrader instance.
* @return file|WP_Error
*/
public function upgrader_source_selection( $source, $remote_source, $upgrader ) {
global $wp_filesystem;
if ( strstr( $source, '/auto-load-next-post-' ) ) {
$corrected_source = trailingslashit( $remote_source ) . trailingslashit( $this->config[ 'proper_folder_name' ] );
if ( $wp_filesystem->move( $source, $corrected_source, true ) ) {
return $corrected_source;
} else {
return new WP_Error( 'alnp_updater_source_selection', __( 'Unable to move source of update.', 'alnp-beta-tester' ), 500 );
}
}
return $source;
} // END upgrader_source_selection()
/**
* Return true if version string is a beta version.
*
* @access protected
* @static
* @since 2.0.2
* @param string $version_str Version string.
* @return bool
*/
protected static function is_beta_version( $version_str ) {
return strpos( $version_str, 'beta' ) !== false;
} // END is_beta_version()
/**
* Return true if version string is a Release Candidate.
*
* @access protected
* @static
* @since 2.0.2
* @param string $version_str Version string.
* @return bool
*/
protected static function is_rc_version( $version_str ) {
return strpos( $version_str, 'rc' ) !== false;
} // END is_rc_version()
/**
* Return true if version string is a stable version.
*
* @access protected
* @static
* @since 2.0.2
* @param string $version_str Version string.
* @return bool
*/
protected static function is_stable_version( $version_str ) {
return ! self::is_beta_version( $version_str ) && ! self::is_rc_version( $version_str );
} // END is_stable_version()
} // END class
} // END if class exists
return ALNP_Beta_Tester::instance();