1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Queue updates for the WooUpdater |
5
|
|
|
*/ |
6
|
|
|
if ( ! function_exists( 'woothemes_queue_update' ) ) { |
7
|
|
|
function woothemes_queue_update( $file, $file_id, $product_id ) { |
8
|
|
|
global $woothemes_queued_updates; |
9
|
|
|
|
10
|
|
|
if ( ! isset( $woothemes_queued_updates ) ) |
11
|
|
|
$woothemes_queued_updates = array(); |
12
|
|
|
|
13
|
|
|
$plugin = new stdClass(); |
14
|
|
|
$plugin->file = $file; |
15
|
|
|
$plugin->file_id = $file_id; |
16
|
|
|
$plugin->product_id = $product_id; |
17
|
|
|
|
18
|
|
|
$woothemes_queued_updates[] = $plugin; |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Load installer for the WooThemes Updater. |
24
|
|
|
* @return $api Object |
|
|
|
|
25
|
|
|
*/ |
26
|
|
|
if ( ! class_exists( 'WooThemes_Updater' ) && ! function_exists( 'woothemes_updater_install' ) ) { |
27
|
|
|
function woothemes_updater_install( $api, $action, $args ) { |
28
|
|
|
$download_url = 'http://woodojo.s3.amazonaws.com/downloads/woothemes-updater/woothemes-updater.zip'; |
29
|
|
|
|
30
|
|
|
if ( 'plugin_information' != $action || |
31
|
|
|
false !== $api || |
32
|
|
|
! isset( $args->slug ) || |
33
|
|
|
'woothemes-updater' != $args->slug |
34
|
|
|
) return $api; |
35
|
|
|
|
36
|
|
|
$api = new stdClass(); |
37
|
|
|
$api->name = 'WooThemes Updater'; |
38
|
|
|
$api->version = ''; |
39
|
|
|
$api->download_link = esc_url( $download_url ); |
40
|
|
|
return $api; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
add_filter( 'plugins_api', 'woothemes_updater_install', 10, 3 ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* WooUpdater Installation Prompts |
48
|
|
|
*/ |
49
|
|
|
if ( ! class_exists( 'WooThemes_Updater' ) && ! function_exists( 'woothemes_updater_notice' ) ) { |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Display a notice if the "WooThemes Updater" plugin hasn't been installed. |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
function woothemes_updater_notice() { |
56
|
|
|
$active_plugins = apply_filters( 'active_plugins', get_option('active_plugins' ) ); |
57
|
|
|
if ( in_array( 'woothemes-updater/woothemes-updater.php', $active_plugins ) ) return; |
58
|
|
|
|
59
|
|
|
$slug = 'woothemes-updater'; |
60
|
|
|
$install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug ); |
61
|
|
|
$activate_url = 'plugins.php?action=activate&plugin=' . urlencode( 'woothemes-updater/woothemes-updater.php' ) . '&plugin_status=all&paged=1&s&_wpnonce=' . urlencode( wp_create_nonce( 'activate-plugin_woothemes-updater/woothemes-updater.php' ) ); |
62
|
|
|
|
63
|
|
|
$message = '<a href="' . esc_url( $install_url ) . '">Install the WooThemes Updater plugin</a> to get updates for your WooThemes plugins.'; |
64
|
|
|
$is_downloaded = false; |
|
|
|
|
65
|
|
|
$plugins = array_keys( get_plugins() ); |
66
|
|
|
foreach ( $plugins as $plugin ) { |
67
|
|
|
if ( strpos( $plugin, 'woothemes-updater.php' ) !== false ) { |
68
|
|
|
$is_downloaded = true; |
|
|
|
|
69
|
|
|
$message = '<a href="' . esc_url( admin_url( $activate_url ) ) . '">Activate the WooThemes Updater plugin</a> to get updates for your WooThemes plugins.'; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
echo '<div class="updated fade"><p>' . $message . '</p></div>' . "\n"; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
add_action( 'admin_notices', 'woothemes_updater_notice' ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Check if WooCommerce version is greater than the one specified |
80
|
|
|
* |
81
|
|
|
* @param $version Version to check against |
82
|
|
|
* @return @boolean |
|
|
|
|
83
|
|
|
*/ |
84
|
|
|
if( ! function_exists( 'sensei_check_woocommerce_version' ) ) { |
85
|
|
|
function sensei_check_woocommerce_version( $version = '2.1' ) { |
86
|
|
|
if ( Sensei_WC::is_woocommerce_active() ) { |
87
|
|
|
global $woocommerce; |
88
|
|
|
if( version_compare( $woocommerce->version, $version, ">=" ) ) { |
89
|
|
|
return true; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
return false; |
93
|
|
|
} |
94
|
|
|
} |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.