actions.php ➔ printcenter_process_actions()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 0
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 12
rs 9.6666
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 12.

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.

Loading history...
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
}