1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Admin actions |
4
|
|
|
* |
5
|
|
|
* @package PrintCenter\Admin\Actions |
6
|
|
|
* @since 1.0.0 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
// Exit if accessed directly |
11
|
|
|
if( ! defined( 'ABSPATH' ) ) { |
12
|
|
|
exit; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Process all actions sent via POST and GET by looking for the 'printcenter-action' |
18
|
|
|
* request and running do_action() to call the function |
19
|
|
|
* |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
function printcenter_process_actions() { |
24
|
|
|
if( isset( $_POST['printcenter-action'] ) ) { |
25
|
|
|
do_action( 'printcenter_' . $_POST['printcenter-action'], $_POST ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if( isset( $_GET['printcenter-action'] ) ) { |
29
|
|
|
do_action( 'printcenter_' . $_GET['printcenter-action'], $_GET ); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
add_action( 'init', 'printcenter_process_actions' ); |
33
|
|
|
add_action( 'admin_init', 'printcenter_process_actions' ); |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Register this site for plugin updates |
38
|
|
|
* |
39
|
|
|
* @since 1.0.0 |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
function printcenter_register_site() { |
43
|
|
|
if( ! current_user_can( 'update_plugins' ) ) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$license = get_option( 'printcenter_license', false ); |
48
|
|
|
|
49
|
|
|
if( $license != 'valid' ) { |
50
|
|
|
$api_params = array( |
51
|
|
|
'edd_action' => 'activate_license', |
52
|
|
|
'license' => '98731c11ef37695fa07a7b0151e0a00e', |
53
|
|
|
'item_name' => 'PrintCenter', |
54
|
|
|
'url' => home_url() |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
// Call the API |
58
|
|
|
$response = wp_remote_post( 'https://section214.com', array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
59
|
|
|
|
60
|
|
|
if( is_wp_error( $response ) ) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Decode the license data |
65
|
|
|
$license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
66
|
|
|
|
67
|
|
|
update_option( 'printcenter_license', $license_data->license ); |
68
|
|
|
delete_transient( 'printcenter_license' ); |
69
|
|
|
} |
70
|
|
|
} |
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.