|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Loads Admin Page Framework loader plugin components. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Admin Page Framework Loader |
|
6
|
|
|
* @copyright Copyright (c) 2015, <Michael Uno> |
|
7
|
|
|
* @author Michael Uno |
|
8
|
|
|
* @authorurl http://michaeluno.jp |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Performs an action. |
|
14
|
|
|
* |
|
15
|
|
|
* @since 3.5.2 |
|
16
|
|
|
*/ |
|
17
|
|
|
class AdminPageFrameworkLoader_Event_Action_GetDevelopmentVersion { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Stores the url of the text that has the development version number. |
|
21
|
|
|
*/ |
|
22
|
|
|
public $sVersionTextURL = 'https://raw.githubusercontent.com/michaeluno/admin-page-framework/dev/admin-page-framework-loader.php'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Performs the action. |
|
26
|
|
|
* |
|
27
|
|
|
* @since 3.6.2 |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct( $sActionName ) { |
|
30
|
|
|
add_action( |
|
31
|
|
|
$sActionName, |
|
32
|
|
|
array( $this, 'replyToDoAction' ) |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @callback action admin_page_framework_loader_action_get_development_version |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
public function replyToDoAction() { |
|
41
|
|
|
AdminPageFramework_WPUtility::setTransient( |
|
42
|
|
|
AdminPageFrameworkLoader_Registry::TRANSIENT_PREFIX . 'devver', |
|
43
|
|
|
$this->___getVersion(), // data - if an error occurs, an empty string will be given |
|
44
|
|
|
604800 // for one week |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
/** |
|
48
|
|
|
* Extracts the version number from the page contents. |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
private function ___getVersion() { |
|
53
|
|
|
|
|
54
|
|
|
$_oUtil = new AdminPageFramework_WPUtility; |
|
55
|
|
|
$_aHeaders = $_oUtil->getScriptData( |
|
56
|
|
|
$this->___getPageBody(), |
|
57
|
|
|
'', /// context |
|
58
|
|
|
array( 'version' => 'Version' ) |
|
59
|
|
|
); |
|
60
|
|
|
return $_oUtil->getElement( |
|
61
|
|
|
$_aHeaders, // subject array |
|
62
|
|
|
'version', // dimensional keys |
|
63
|
|
|
'' // default |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
/** |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
private function ___getPageBody() { |
|
|
|
|
|
|
71
|
|
|
$_mResponse = wp_remote_get( |
|
72
|
|
|
$this->sVersionTextURL, |
|
73
|
|
|
array( |
|
74
|
|
|
// 3.7 or later, it should be true |
|
75
|
|
|
'sslverify' => version_compare( $GLOBALS[ 'wp_version' ], '3.7', '>=' ) |
|
76
|
|
|
) |
|
77
|
|
|
); |
|
78
|
|
|
if ( is_wp_error( $_mResponse ) ) { |
|
79
|
|
|
return ''; |
|
80
|
|
|
} |
|
81
|
|
|
return wp_remote_retrieve_body( $_mResponse ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: