-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-wefoster-updater-fallback.php
769 lines (660 loc) · 22.6 KB
/
class-wefoster-updater-fallback.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
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
<?php
/**
* WeFoster Updater Fallback Class
*
* This class provides fallback logic when the WeFoster Dashboard plugin is
* not active. Require this class to register plugins and themes, and display
* a notice to install or activate the dashboard plugin which will handle the
* actual updating.
*
* NOTE: Adding your product should happen BEFORE the 'init' hook! So use 'plugins_loaded'
* for plugins and 'after_setup_theme' for themes.
*
* Example for a PLUGIN:
*
* <?php
* function wefoster_update_my_plugin() {
* // Load fallback file when without WeFoster Dashboard
* if ( ! function_exists( 'wefoster' ) ) {
* require_once( '{...}/class-wefoster-updater-fallback.php' );
* }
*
* // Add plugin to the updatable queue
* wefoster_updater()->add_plugin( __FILE__ );
* }
* add_function( 'plugins_loaded', 'wefoster_update_my_plugin' );
* ?>
*
* Example for a THEME:
*
* <?php
* function wefoster_update_my_theme() {
* // Load fallback file when without WeFoster Dashboard
* if ( ! function_exists( 'wefoster' ) ) {
* require_once( '{...}/class-wefoster-updater-fallback.php' );
* }
*
* // Add theme to the updatable queue
* wefoster_updater()->add_theme( 'my-theme' );
* }
* add_function( 'after_setup_theme', 'wefoster_update_my_theme' );
* ?>
*
* @package WeFoster Plugin or Theme
* @subpackage Updater
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'WeFoster_Updater' ) && ! class_exists( 'WeFoster_Updater_Fallback' ) ) :
/**
* The WeFoster Updater Fallback Class
*
* @since 1.0.0
*/
final class WeFoster_Updater_Fallback {
/**
* Holds the updatable plugins
*
* @since 1.0.0
* @var array
*/
private $plugins = array();
/**
* Holds the updatable themes
*
* @since 1.0.0
* @var array
*/
private $themes = array();
/**
* Transient key name
*
* @since 1.0.0
* @var string
*/
private $key = '_wefoster_updater_fallback';
/**
* The plugin basename of the WeFoster Dashboard
*
* @since 1.0.0
* @var string
*/
private $wfdb_base = 'wefoster-dashboard/wefoster-dashboard.php';
/**
* Holds whether the WeFoster Dashboard is installed
*
* Call with WeFoster_Updater_Fallback::is_wfdb_installed().
*
* @since 1.0.0
* @var null|bool
*/
private $is_wfdb_installed = null;
/**
* Setup and return the WeFoster Updater Fallback instance
*
* @since 1.0.0
*
* @uses WeFoster_Updater_Fallback::setup_actions()
* @return The single class instance
*/
public static function instance() {
static $instance = null;
if ( null === $instance ) {
$instance = new WeFoster_Updater_Fallback;
$instance->setup_actions();
}
return $instance;
}
/**
* Dummy constructor not to be used
*
* @see WeFoster_Updater_Fallback::instance()
*
* @since 1.0.0
*/
private function __construct() { /* Nothing to do here */ }
/**
* Setup actions and filters
*
* @since 1.0.0
*/
private function setup_actions() {
// Only run in the admin
if ( ! is_admin() )
return;
// Display admin notice
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
add_action( 'network_admin_notices', array( $this, 'admin_notice' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'notice_styles' ), 99 );
add_action( 'admin_print_footer_scripts', array( $this, 'notice_scripts' ), 99 );
// Ajax
add_action( 'wp_ajax_wefoster_updater_fallback_hide_notice', array( $this, 'ajax_hide_notice' ) );
// Display product status
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 );
add_filter( 'theme_row_meta', array( $this, 'theme_row_meta' ), 10, 4 );
// WFDB installation
add_action( 'update-custom_install-wefoster-dashboard', array( $this, 'install_wfdb' ) );
}
/**
* Add a plugin to the updater collection
*
* Use this method to register your plugin for updates with WeFoster
*
* @since 1.0.0
*
* @uses get_plugin_data()
*
* @param string $plugin_file Path to the main plugin file
* @return string|WP_Error Plugin slug or error instance when something went wrong
*/
public function add_plugin( $plugin_file ) {
// Bail when the plugin is not found
if ( ! file_exists( $plugin_file ) ) {
return new WP_Error( 'file_not_found', __( 'The plugin file could not be found.', 'wefoster' ) );
}
// Make sure we can use `get_plugin_data()`
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// Get the plugin data
$plugin = (object) get_plugin_data( $plugin_file );
// Bail when the plugin headers are corrupt
if ( empty( $plugin->Name ) || empty( $plugin->Version ) ) {
return new WP_Error( 'plugin_not_found', __( 'The file does not contain valid plugin headers.', 'wefoster' ) );
}
// Define plugin paths
$plugin->file = $plugin_file;
$plugin->basename = plugin_basename( $plugin_file );
$plugin->slug = $this->get_plugin_slug( $plugin->basename );
// Add plugin to the collection
$this->plugins[ $plugin->slug ] = $plugin;
ksort( $this->plugins );
return $plugin->slug;
}
/**
* Add a theme to the updater collection
*
* Use this method to register your theme for updates with WeFoster.
*
* @since 1.0.0
*
* @uses wp_get_theme()
*
* @param string $stylesheet Directory name of the theme
* @return string|WP_Error Theme stylesheet or error instance when something went wrong
*/
public function add_theme( $stylesheet ) {
// Get the theme data
$theme = wp_get_theme( $stylesheet );
// Bail when the theme is not found
if ( $theme->errors() ) {
return $theme->errors();
}
// Add theme to the collection
$this->themes[ $theme->stylesheet ] = $theme;
ksort( $this->themes );
return $theme->stylesheet;
}
/**
* Return the folder name of the plugin
*
* @since 1.0.0
*
* @param string $file Plugin file name
* @return string Plugin folder name
*/
public function get_plugin_slug( $file ) {
return substr( $file, 0, strpos( $file, '/' ) );
}
/** Admin Notice ****************************************************/
/**
* Return whether the WeFoster Dashboard is installed on the current site
*
* @since 1.0.0
*
* @uses get_plugins()
* @uses WeFoster_Updater_Fallback::get_plugin_slug()
* @return bool The WeFoster Dashboard is installed
*/
private function is_wfdb_installed() {
// Define when not done yet
if ( null === $this->is_wfdb_installed ) {
// Find WeFoster Dashboard in present plugins
$this->is_wfdb_installed = (bool) get_plugins( '/' . $this->get_plugin_slug( $this->wfdb_base ) );
}
return $this->is_wfdb_installed;
}
/**
* Return the url for activating the WeFoster Dashboard
*
* @since 1.0.0
*
* @return string Activation url
*/
public function get_wfdb_activation_url() {
return wp_nonce_url( add_query_arg( array(
'action' => 'activate',
'plugin' => $this->wfdb_base,
), self_admin_url( 'plugins.php' ) ),
'activate-plugin_' . $this->wfdb_base
);
}
/**
* Return the url for installing the WeFoster Dashboard
*
* @since 1.0.0
*
* @return string Installation url
*/
public function get_wfdb_installation_url() {
return wp_nonce_url( add_query_arg( array(
'action' => 'install-wefoster-dashboard'
), self_admin_url( 'update.php' ) ),
'install-plugin_' . $this->wfdb_base
);
}
/**
* Display an admin notice to require WeFoster Dashboard for updates
*
* @since 1.0.0
*
* @uses WeFoster_Updater_Fallback::display_notice()
* @uses WeFoster_Updater_Fallback::is_wfdb_installed()
* @uses WeFoster_Updater_Fallback::get_wfdb_activation_url()
* @uses WeFoster_Updater_Fallback::get_wfdb_installation_url()
* @uses WeFoster_Updater_Fallback::get_product_names()
* @uses WeFoster_Updater_Fallback::get_products_for_notices()
*/
public function admin_notice() {
// Bail when user is not capable or transient is valid
if ( ! current_user_can( 'install_plugins' ) )
return;
// Bail when there is nothing to display
if ( ! $this->display_notice() )
return;
// Request to activate the WeFoster Dashboard
if ( $this->is_wfdb_installed() ) {
$message = __( 'Please activate the WeFoster Dashboard plugin so we can verify your License Keys and you can get access to support and updates.', 'wefoster' );
$action = __( 'Activate WeFoster Dashboard plugin', 'wefoster' );
$class = 'activate';
$url = $this->get_wfdb_activation_url();
// Request to install the WeFoster Dashboard
} else {
$message = __( 'Please install the WeFoster Dashboard plugin so we can verify your License Keys and you can get access to support and updates.', 'wefoster' );
$action = __( 'Install WeFoster Dashboard plugin', 'wefoster' );
$class = 'install';
$url = $this->get_wfdb_installation_url();
}
// Print single message for all WeFoster plugins to the screen ?>
<div class="notice wefoster-notice is-dismissible">
<h2><?php printf( esc_html__( 'Thank you for purchasing %s!', 'wefoster' ), $this->get_product_names( $this->get_products_for_notices() ) ); ?></h2>
<p><?php echo esc_html( $message ); ?></p>
<a href="<?php echo esc_url( $url ); ?>" class="nag-action <?php echo $class; ?>"><?php echo esc_html( $action ); ?></a>
</div>
<?php
}
/**
* Enqueue styles for the admin notices
*
* @since 1.0.0
*
* @uses WeFoster_Updater_Fallback::display_notice()
* @uses wp_add_inline_style()
*/
public function notice_styles() {
// Bail when we're not showing any notices
if ( ! $this->display_notice() )
return;
$css = "
.wefoster-notice {
padding: 20px 20px 60px;
color: #fff;
font-weight: bold;
font-size: 120%;
background: #414951 url( 'http://cdn.wefoster.co/dashboard/background.png' ) no-repeat;
background-size: cover;
background-position: bottom 0 right 0;
border: 0; /* reset default notice border */
border-bottom: 10px solid #44c0a9;
border-radius: 4px;
}
.wefoster-notice h2,
.wefoster-notice p {
color: #fff;
font-size: 100%; /* overwrite wp-admin's <p> */
}
.wefoster-notice .nag-action {
display: inline-block;
position: absolute;
bottom: 0;
left: 20px;
padding: 12px 15px;
background-color: #44c0a9;
border-radius: 4px 4px 0 0;
color: #fff;
font-size: 80%;
letter-spacing: 0.5px;
text-transform: uppercase;
text-decoration: none;
}
";
wp_add_inline_style( 'wp-admin', $css );
}
/**
* Print scripts for the admin notices
*
* @since 1.0.0
*
* @uses WeFoster_Updater_Fallback::display_notice()
*/
public function notice_scripts() {
// Bail when we're not showing any notices
if ( ! $this->display_notice() )
return;
?>
<script>
jQuery(document).ready( function( $ ) {
$( '.wefoster-notice .notice-dismiss' ).on( 'click.wp-dismiss-notice', function( event ) {
event.preventDefault();
// Run the hide-notice Ajax logic when dismissing
$.ajax( ajaxurl, {
type: 'POST',
data: {
action: 'wefoster_updater_fallback_hide_notice',
_wpnonce: '<?php echo wp_create_nonce(); ?>'
}
});
});
});
</script>
<?php
}
/**
* Return the products who's notices have not been dismissed
*
* @since 1.0.0
*
* @uses get_site_transient()
* @return array Noticeable products
*/
public function get_products_for_notices() {
// Get dismissed notice products
$dismissed = wp_parse_args( (array) get_site_transient( $this->key ), array( 'plugins' => array(), 'themes' => array() ) );
// Define product collection
$products = array(
'plugins' => array_diff( array_keys( $this->plugins ), $dismissed['plugins'] ),
'themes' => array_diff( array_keys( $this->themes ), $dismissed['themes'] )
);
// Return empty array when no products found
if ( ! array_filter( $products ) ) {
$products = array();
}
return $products;
}
/**
* Return whether notices are to be displayed on the current admin page
*
* @since 1.0.0
*
* @uses WeFoster_Updater_Fallback::get_products_for_notices()
* @uses get_current_screen()
* @return bool Display notices
*/
public function display_notice() {
$has_notices = (bool) $this->get_products_for_notices();
$is_display_page = is_admin() && ! in_array( get_current_screen()->id, array( 'update', 'update-network' ) );
return $has_notices && $is_display_page;
}
/**
* Return plugin names
*
* @since 1.0.0
*
* @param array $products Products with plugins and themes.
* @param bool $concat Optional. Whether to concat the names in a single line.
* @return array|string Plugin names or line of names
*/
public function get_product_names( $products = array(), $concat = true ) {
$names = array();
$plugins = isset( $products['plugins'] ) ? (array) $products['plugins'] : array();
$themes = isset( $products['themes'] ) ? (array) $products['themes'] : array();
if ( ! $plugins && ! $themes ) {
$products = false;
}
// Plugins
foreach ( $this->plugins as $plugin ) {
if ( ! $products || in_array( $plugin->slug, $plugins ) ) {
$names[] = $plugin->Name;
}
}
// Themes
foreach ( $this->themes as $theme ) {
if ( ! $products || in_array( $theme->stylesheet, $themes ) ) {
$names[] = $theme->name;
}
}
if ( $concat ) {
if ( 1 < count( $names ) ) {
$last = array_pop( $names );
/* translators: 1. Comma separated list of names 2. Last name in the list */
$names = sprintf( __( '%1$s and %2$s', 'wefoster' ), implode( ', ', $names ), $last );
} else {
$names = reset( $names );
}
}
return $names;
}
/**
* Run AJAX logic to hide the admin notice for some time
*
* @since 1.0.0
*
* @uses check_ajax_referer()
* @uses set_site_transient()
*/
public function ajax_hide_notice() {
check_ajax_referer();
// Define product collection
$products = array(
'plugins' => array_keys( $this->plugins ),
'themes' => array_keys( $this->themes )
);
// Update transient to not nag for the coming week
set_site_transient( $this->key, $products, WEEK_IN_SECONDS );
}
/** Product Status **************************************************/
/**
* Append the WeFoster Dashboard notification to the plugin meta
*
* @since 1.0.0
*
* @param array $meta Plugin meta
* @param string $file Plugin name
* @param array $data Plugin data
* @param string $status Plugin status
* @return array Plugin meta
*/
public function plugin_row_meta( $meta, $file, $data, $status ) {
// Add meta when this is one of our plugins and only for capable users
if ( in_array( $this->get_plugin_slug( $file ), array_keys( $this->plugins ) ) && current_user_can( 'install_plugins' ) ) {
// Only where license information matters
if ( ( is_multisite() && is_network_admin() ) || ! is_multisite() ) {
$meta['wefoster'] = $this->is_wfdb_installed()
? sprintf( __( '<a href="%s">Activate the WeFoster Dashboard plugin</a> to register your License Key', 'wefoster' ), $this->get_wfdb_activation_url() )
: sprintf( __( '<a href="%s">Install the WeFoster Dashboard plugin</a> to register your License Key', 'wefoster' ), $this->get_wfdb_installation_url() );
}
}
return $meta;
}
/**
* Append the WeFoster Dashboard notification to the theme meta
*
* This is used only in Multisite.
*
* @see wp-admin/includes/class-wp-ms-themes-list-table.php
*
* @since 1.0.0
*
* @param array $meta Theme meta
* @param string $stylesheet Directory name of the theme
* @param array $theme WP_Theme object
* @param string $status Theme status
* @return array Theme meta
*/
public function theme_row_meta( $meta, $stylesheet, $theme, $status ) {
// Add meta when this is one of our themes and only for capable users
if ( in_array( $stylesheet, array_keys( $this->themes ) ) && current_user_can( 'install_themes' ) ) {
// Only where license information matters
if ( ( is_multisite() && is_network_admin() ) || ! is_multisite() ) {
$meta['wefoster'] = $this->is_wfdb_installed()
? sprintf( __( '<a href="%s">Activate the WeFoster Dashboard plugin</a> to register your License Key', 'wefoster' ), $this->get_wfdb_activation_url() )
: sprintf( __( '<a href="%s">Install the WeFoster Dashboard plugin</a> to register your License Key', 'wefoster' ), $this->get_wfdb_installation_url() );
}
}
return $meta;
}
/**
* TODO: Find a way to display Install/Activate notice for themes in a single site.
*/
/** Install Dashboard ***********************************************/
/**
* Install the WeFoster Dashboard plugin from a remote repository
*
* @since 1.0.0
*
* @see wp-admin/update.php
*
* @uses WeFoster_Updater_Fallback::get_plugin_slug()
* @uses wp_remote_get()
* @uses Plugin_Upgrader::install()
*/
public function install_wfdb() {
// Bail when the user is not capable
if ( ! current_user_can( 'install_plugins' ) )
wp_die( __( 'You do not have sufficient permissions to install plugins on this site.' ) );
check_admin_referer( 'install-plugin_' . $this->wfdb_base );
// Define the download repo location
$plugin = $this->get_plugin_slug( $this->wfdb_base );
$repo = trailingslashit( 'https://api.github.com/repos/wefoster/' . $plugin );
/**
* We use tags to test the connection/existence of the dashboard repo.
* NOTE: GitHub limits 60 anonymous API requests per hour, so this could
* return invalid when the user's IP already has hit its limit.
*/
$request = wp_remote_get( $repo . 'tags' );
// Process the request result
if ( is_wp_error( $request ) || in_array( wp_remote_retrieve_response_code( $request ), array( '', 404 ) ) ) {
wp_die( new WP_Error( 'plugins_api_failed', sprintf( __( 'An unexpected error occurred. The download location of the WeFoster Dashboard plugin could not be reached. If you continue to have problems, please try the <a href="%s">support documentation</a>.', 'wefoster' ), 'https://help.wefoster.co' ) . '</p><p>' . sprintf( '<a href="%s">%s</a>', wp_get_referer(), __( 'Return to the previous page', 'wefoster' ) ) ) );
} else {
$tags = (array) json_decode( wp_remote_retrieve_body( $request ) );
if ( ! $tags ) {
wp_die( new WP_Error( 'plugins_api_failed', sprintf( __( 'An unexpected error occurred. Something may be wrong with GitHub.com or this server’s configuration. If you continue to have problems, please try the <a href="%s">support documentation</a>.', 'wefoster' ), 'https://help.wefoster.co' ) . '</p><p>' . sprintf( '<a href="%s">%s</a>', wp_get_referer(), __( 'Return to the previous page', 'wefoster' ) ) ) );
}
}
// Define download details
$api = (object) array(
'name' => 'WeFoster Dashboard',
'version' => reset( $tags )->name,
'per_page' => 24, // Default
'locale' => get_locale(),
'external' => true,
'download_link' => $repo . 'zipball/master',
);
$title = __( 'Plugin Install' );
$parent_file = 'plugins.php';
$submenu_file = 'plugin-install.php';
require_once( ABSPATH . 'wp-admin/admin-header.php' );
$title = sprintf( __( 'Installing Plugin: %s' ), $api->name . ' ' . $api->version );
$nonce = 'install-plugin_' . $this->wfdb_base;
$url = 'update.php?action=install-wefoster-dashboard';
if ( isset( $_GET['from'] ) ) {
$url .= '&from=' . urlencode( stripslashes( $_GET['from'] ) );
}
// Hook filters
add_filter( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 3 );
add_filter( 'install_plugin_complete_actions', array( $this, 'install_complete_actions' ), 10, 3 );
// Do the installation
$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
$upgrader->install( $api->download_link );
// Unhook filters
remove_filter( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 3 );
remove_filter( 'install_plugin_complete_actions', array( $this, 'install_complete_actions' ), 10, 3 );
include( ABSPATH . 'wp-admin/admin-footer.php' );
}
/**
* Run logic to ensure the correct install directory name is used
*
* When downloading the plugin zip folder from GitHub, the plugin folder
* is named {owner}-{repo}-{tag-hash}. That's not good ofcourse, so here
* we rename the folder to just the proper {repo} name.
*
* @since 1.0.0
*
* @uses WP_Filesystem::move()
*
* @param bool $response
* @param array $hook_extra
* @param array $result
* @return bool Install response
*/
public function upgrader_post_install( $response, $hook_extra, $result ) {
global $wp_filesystem;
// Bail when the response was invalid
if ( is_wp_error( $response ) || ! $response )
return $response;
// Define correct plugin directory
$destination = WP_PLUGIN_DIR . '/' . $this->get_plugin_slug( $this->wfdb_base );
// Rename the plugin folder
$wp_filesystem->move( $result['destination'], $destination );
$result['destination'] = $destination;
$result['clear_destination'] = true;
return $result;
}
/**
* Modify the post-install actions
*
* @since 1.0.0
*
* @see Plugin_Installer_Skin::after()
*
* @param array $actions
* @param object $api
* @param string $plugin_file
* @return array Actions
*/
public function install_complete_actions( $actions, $api, $plugin_file ) {
// Define correct plugin file name
$plugin_file = $this->wfdb_base;
// Redefine activation link
$actions['activate_plugin'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" title="' . esc_attr__( 'Activate this plugin' ) . '" target="_parent">' . __( 'Activate Plugin' ) . '</a>';
if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
$actions['network_activate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=activate&networkwide=1&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) . '" title="' . esc_attr__( 'Activate this plugin for all sites in this network' ) . '" target="_parent">' . __( 'Network Activate' ) . '</a>';
unset( $actions['activate_plugin'] );
}
return $actions;
}
}
/**
* Return the single WeFoster Updater Fallback instance
*
* Provides fallback logic for the same function in the WeFoster Dashboard plugin.
* To register a plugin or theme for WeFoster updates use this function like you
* would a global variable, except without needing to declare the global.
*
* Example:
*
* <?php
* // Add Plugin
* wefoster_updater()->add_plugin( __FILE__ );
*
* // Add Theme
* wefoster_updater()->add_theme( 'my-theme' );
* ?>
*
* @since 1.0.0
*
* @uses WeFoster_Updater_Fallback
* @return The single class instance
*/
function wefoster_updater() {
return WeFoster_Updater_Fallback::instance();
}
endif; // class_exists