@@ -5,135 +5,135 @@ discard block |
||
5 | 5 | */ |
6 | 6 | // Exit if accessed directly. |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | class MonsterInsights_GA_IO extends MonsterInsights_GA_Lib_IO_Abstract { |
11 | - const TIMEOUT = "timeout"; |
|
12 | - private $options = array(); |
|
11 | + const TIMEOUT = "timeout"; |
|
12 | + private $options = array(); |
|
13 | 13 | |
14 | - private static $ENTITY_HTTP_METHODS = array( "POST" => null, "PUT" => null, "DELETE" => null ); |
|
15 | - private static $HOP_BY_HOP = array( |
|
16 | - 'connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', |
|
17 | - 'te', 'trailers', 'transfer-encoding', 'upgrade' ); |
|
18 | - |
|
19 | - /** |
|
20 | - * Execute a apiHttpRequest |
|
21 | - * |
|
22 | - * @param Yoast_Google_HttpRequest $request the http request to be executed |
|
23 | - * |
|
24 | - * @return Yoast_Google_HttpRequest http request with the response http code, response |
|
25 | - * headers and response body filled in |
|
26 | - */ |
|
27 | - public function executeRequest( MonsterInsights_GA_Lib_Http_Request $request ) { |
|
28 | - |
|
29 | - // First, check to see if we have a valid cached version. |
|
30 | - $cached = $this->getCachedRequest( $request ); |
|
31 | - if ( $cached !== false ) { |
|
32 | - if ( ! $this->checkMustRevaliadateCachedRequest( $cached, $request ) ) { |
|
33 | - return $cached; |
|
34 | - } |
|
35 | - } |
|
36 | - |
|
37 | - if ( array_key_exists( $request->getRequestMethod(), self::$ENTITY_HTTP_METHODS ) ) { |
|
38 | - $request = $this->processEntityRequest( $request ); |
|
39 | - } |
|
40 | - |
|
41 | - $params = array( |
|
42 | - 'user-agent' => $request->getUserAgent(), |
|
43 | - 'timeout' => 30, |
|
44 | - 'sslverify' => false, |
|
45 | - ); |
|
46 | - |
|
47 | - $curl_version = $this->get_curl_version(); |
|
48 | - if ( $curl_version !== false ) { // @todo fix this |
|
49 | - if ( version_compare( $curl_version, '7.19.0', '<=' ) && version_compare( $curl_version, '7.19.8', '>' ) ) { |
|
50 | - add_filter( 'http_api_transports', array( $this, 'filter_curl_from_transports' ) ); |
|
51 | - } |
|
52 | - } |
|
53 | - |
|
54 | - if ( $request->getPostBody() ) { |
|
55 | - $params['body'] = $request->getPostBody(); |
|
56 | - } |
|
57 | - |
|
58 | - $requestHeaders = $request->getRequestHeaders(); |
|
59 | - if ( $requestHeaders && is_array( $requestHeaders ) ) { |
|
60 | - $params['headers'] = $requestHeaders; |
|
61 | - } |
|
62 | - |
|
63 | - // There might be some problems with decompressing, so we prevent this by setting the param to false |
|
64 | - $params['decompress'] = false; |
|
65 | - |
|
66 | - |
|
67 | - switch ( $request->getRequestMethod() ) { |
|
68 | - case 'POST' : |
|
69 | - $response = wp_remote_post( $request->getUrl(), $params ); |
|
70 | - break; |
|
71 | - |
|
72 | - case 'GET' : |
|
73 | - $response = wp_remote_get( $request->getUrl(), $params ); |
|
74 | - break; |
|
75 | - case 'DELETE' : |
|
76 | - $params['method'] = 'DELETE'; |
|
77 | - $response = wp_remote_get( $request->getUrl(), $params ); |
|
78 | - break; |
|
79 | - } |
|
80 | - |
|
81 | - $responseBody = wp_remote_retrieve_body( $response ); |
|
82 | - $respHttpCode = wp_remote_retrieve_response_code( $response ); |
|
83 | - $responseHeaders = wp_remote_retrieve_headers( $response ); |
|
14 | + private static $ENTITY_HTTP_METHODS = array( "POST" => null, "PUT" => null, "DELETE" => null ); |
|
15 | + private static $HOP_BY_HOP = array( |
|
16 | + 'connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', |
|
17 | + 'te', 'trailers', 'transfer-encoding', 'upgrade' ); |
|
18 | + |
|
19 | + /** |
|
20 | + * Execute a apiHttpRequest |
|
21 | + * |
|
22 | + * @param Yoast_Google_HttpRequest $request the http request to be executed |
|
23 | + * |
|
24 | + * @return Yoast_Google_HttpRequest http request with the response http code, response |
|
25 | + * headers and response body filled in |
|
26 | + */ |
|
27 | + public function executeRequest( MonsterInsights_GA_Lib_Http_Request $request ) { |
|
28 | + |
|
29 | + // First, check to see if we have a valid cached version. |
|
30 | + $cached = $this->getCachedRequest( $request ); |
|
31 | + if ( $cached !== false ) { |
|
32 | + if ( ! $this->checkMustRevaliadateCachedRequest( $cached, $request ) ) { |
|
33 | + return $cached; |
|
34 | + } |
|
35 | + } |
|
36 | + |
|
37 | + if ( array_key_exists( $request->getRequestMethod(), self::$ENTITY_HTTP_METHODS ) ) { |
|
38 | + $request = $this->processEntityRequest( $request ); |
|
39 | + } |
|
40 | + |
|
41 | + $params = array( |
|
42 | + 'user-agent' => $request->getUserAgent(), |
|
43 | + 'timeout' => 30, |
|
44 | + 'sslverify' => false, |
|
45 | + ); |
|
46 | + |
|
47 | + $curl_version = $this->get_curl_version(); |
|
48 | + if ( $curl_version !== false ) { // @todo fix this |
|
49 | + if ( version_compare( $curl_version, '7.19.0', '<=' ) && version_compare( $curl_version, '7.19.8', '>' ) ) { |
|
50 | + add_filter( 'http_api_transports', array( $this, 'filter_curl_from_transports' ) ); |
|
51 | + } |
|
52 | + } |
|
53 | + |
|
54 | + if ( $request->getPostBody() ) { |
|
55 | + $params['body'] = $request->getPostBody(); |
|
56 | + } |
|
57 | + |
|
58 | + $requestHeaders = $request->getRequestHeaders(); |
|
59 | + if ( $requestHeaders && is_array( $requestHeaders ) ) { |
|
60 | + $params['headers'] = $requestHeaders; |
|
61 | + } |
|
62 | + |
|
63 | + // There might be some problems with decompressing, so we prevent this by setting the param to false |
|
64 | + $params['decompress'] = false; |
|
65 | + |
|
66 | + |
|
67 | + switch ( $request->getRequestMethod() ) { |
|
68 | + case 'POST' : |
|
69 | + $response = wp_remote_post( $request->getUrl(), $params ); |
|
70 | + break; |
|
71 | + |
|
72 | + case 'GET' : |
|
73 | + $response = wp_remote_get( $request->getUrl(), $params ); |
|
74 | + break; |
|
75 | + case 'DELETE' : |
|
76 | + $params['method'] = 'DELETE'; |
|
77 | + $response = wp_remote_get( $request->getUrl(), $params ); |
|
78 | + break; |
|
79 | + } |
|
80 | + |
|
81 | + $responseBody = wp_remote_retrieve_body( $response ); |
|
82 | + $respHttpCode = wp_remote_retrieve_response_code( $response ); |
|
83 | + $responseHeaders = wp_remote_retrieve_headers( $response ); |
|
84 | 84 | |
85 | 85 | |
86 | - $this->client->getLogger()->debug( |
|
87 | - 'Stream response', |
|
88 | - array( |
|
89 | - 'code' => $respHttpCode, |
|
90 | - 'headers' => $responseHeaders, |
|
91 | - 'body' => $responseBody, |
|
92 | - ) |
|
93 | - ); |
|
94 | - |
|
95 | - // And finally return it |
|
96 | - return array( $responseBody, $responseHeaders, $respHttpCode ); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Remove Curl from the transport |
|
101 | - * |
|
102 | - * @param $transports |
|
103 | - * |
|
104 | - * @return mixed |
|
105 | - */ |
|
106 | - public function filter_curl_from_transports( $transports ) { |
|
107 | - unset( $transports['curl'] ); |
|
108 | - |
|
109 | - return $transports; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Set options that update default behavior. |
|
114 | - * |
|
115 | - * @param array $optParams Multiple options used by a session. |
|
116 | - */ |
|
86 | + $this->client->getLogger()->debug( |
|
87 | + 'Stream response', |
|
88 | + array( |
|
89 | + 'code' => $respHttpCode, |
|
90 | + 'headers' => $responseHeaders, |
|
91 | + 'body' => $responseBody, |
|
92 | + ) |
|
93 | + ); |
|
94 | + |
|
95 | + // And finally return it |
|
96 | + return array( $responseBody, $responseHeaders, $respHttpCode ); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Remove Curl from the transport |
|
101 | + * |
|
102 | + * @param $transports |
|
103 | + * |
|
104 | + * @return mixed |
|
105 | + */ |
|
106 | + public function filter_curl_from_transports( $transports ) { |
|
107 | + unset( $transports['curl'] ); |
|
108 | + |
|
109 | + return $transports; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Set options that update default behavior. |
|
114 | + * |
|
115 | + * @param array $optParams Multiple options used by a session. |
|
116 | + */ |
|
117 | 117 | public function setOptions($options) { |
118 | - $this->options = $options + $this->options; |
|
118 | + $this->options = $options + $this->options; |
|
119 | 119 | } |
120 | 120 | |
121 | - /** |
|
122 | - * Get the current curl verison if curl is installed |
|
123 | - * |
|
124 | - * @return bool|string |
|
125 | - */ |
|
126 | - public function get_curl_version() { |
|
127 | - if ( function_exists( 'curl_version' ) ) { |
|
128 | - $curl = curl_version(); |
|
121 | + /** |
|
122 | + * Get the current curl verison if curl is installed |
|
123 | + * |
|
124 | + * @return bool|string |
|
125 | + */ |
|
126 | + public function get_curl_version() { |
|
127 | + if ( function_exists( 'curl_version' ) ) { |
|
128 | + $curl = curl_version(); |
|
129 | 129 | |
130 | - if ( isset( $curl['version'] ) ) { |
|
131 | - return $curl['version']; |
|
132 | - } |
|
133 | - } |
|
130 | + if ( isset( $curl['version'] ) ) { |
|
131 | + return $curl['version']; |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | - return false; |
|
136 | - } |
|
135 | + return false; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | /** |
139 | 139 | * Set the maximum request time in seconds. |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function setTimeout($timeout) |
143 | 143 | { |
144 | - $this->options[self::TIMEOUT] = $timeout; |
|
144 | + $this->options[self::TIMEOUT] = $timeout; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function getTimeout() |
152 | 152 | { |
153 | - return $this->options[self::TIMEOUT]; |
|
153 | + return $this->options[self::TIMEOUT]; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | protected function needsQuirk() |
164 | 164 | { |
165 | - return false; |
|
165 | + return false; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | } |
169 | 169 | \ No newline at end of file |
@@ -4,14 +4,14 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | // Exit if accessed directly. |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if ( ! defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | class MonsterInsights_GA_IO extends MonsterInsights_GA_Lib_IO_Abstract { |
11 | 11 | const TIMEOUT = "timeout"; |
12 | 12 | private $options = array(); |
13 | 13 | |
14 | - private static $ENTITY_HTTP_METHODS = array( "POST" => null, "PUT" => null, "DELETE" => null ); |
|
14 | + private static $ENTITY_HTTP_METHODS = array("POST" => null, "PUT" => null, "DELETE" => null); |
|
15 | 15 | private static $HOP_BY_HOP = array( |
16 | 16 | 'connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', |
17 | 17 | 'te', 'trailers', 'transfer-encoding', 'upgrade' ); |
@@ -24,18 +24,18 @@ discard block |
||
24 | 24 | * @return Yoast_Google_HttpRequest http request with the response http code, response |
25 | 25 | * headers and response body filled in |
26 | 26 | */ |
27 | - public function executeRequest( MonsterInsights_GA_Lib_Http_Request $request ) { |
|
27 | + public function executeRequest(MonsterInsights_GA_Lib_Http_Request $request) { |
|
28 | 28 | |
29 | 29 | // First, check to see if we have a valid cached version. |
30 | - $cached = $this->getCachedRequest( $request ); |
|
31 | - if ( $cached !== false ) { |
|
32 | - if ( ! $this->checkMustRevaliadateCachedRequest( $cached, $request ) ) { |
|
30 | + $cached = $this->getCachedRequest($request); |
|
31 | + if ($cached !== false) { |
|
32 | + if ( ! $this->checkMustRevaliadateCachedRequest($cached, $request)) { |
|
33 | 33 | return $cached; |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | - if ( array_key_exists( $request->getRequestMethod(), self::$ENTITY_HTTP_METHODS ) ) { |
|
38 | - $request = $this->processEntityRequest( $request ); |
|
37 | + if (array_key_exists($request->getRequestMethod(), self::$ENTITY_HTTP_METHODS)) { |
|
38 | + $request = $this->processEntityRequest($request); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | $params = array( |
@@ -45,18 +45,18 @@ discard block |
||
45 | 45 | ); |
46 | 46 | |
47 | 47 | $curl_version = $this->get_curl_version(); |
48 | - if ( $curl_version !== false ) { // @todo fix this |
|
49 | - if ( version_compare( $curl_version, '7.19.0', '<=' ) && version_compare( $curl_version, '7.19.8', '>' ) ) { |
|
50 | - add_filter( 'http_api_transports', array( $this, 'filter_curl_from_transports' ) ); |
|
48 | + if ($curl_version !== false) { // @todo fix this |
|
49 | + if (version_compare($curl_version, '7.19.0', '<=') && version_compare($curl_version, '7.19.8', '>')) { |
|
50 | + add_filter('http_api_transports', array($this, 'filter_curl_from_transports')); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | - if ( $request->getPostBody() ) { |
|
54 | + if ($request->getPostBody()) { |
|
55 | 55 | $params['body'] = $request->getPostBody(); |
56 | 56 | } |
57 | 57 | |
58 | 58 | $requestHeaders = $request->getRequestHeaders(); |
59 | - if ( $requestHeaders && is_array( $requestHeaders ) ) { |
|
59 | + if ($requestHeaders && is_array($requestHeaders)) { |
|
60 | 60 | $params['headers'] = $requestHeaders; |
61 | 61 | } |
62 | 62 | |
@@ -64,23 +64,23 @@ discard block |
||
64 | 64 | $params['decompress'] = false; |
65 | 65 | |
66 | 66 | |
67 | - switch ( $request->getRequestMethod() ) { |
|
67 | + switch ($request->getRequestMethod()) { |
|
68 | 68 | case 'POST' : |
69 | - $response = wp_remote_post( $request->getUrl(), $params ); |
|
69 | + $response = wp_remote_post($request->getUrl(), $params); |
|
70 | 70 | break; |
71 | 71 | |
72 | 72 | case 'GET' : |
73 | - $response = wp_remote_get( $request->getUrl(), $params ); |
|
73 | + $response = wp_remote_get($request->getUrl(), $params); |
|
74 | 74 | break; |
75 | 75 | case 'DELETE' : |
76 | 76 | $params['method'] = 'DELETE'; |
77 | - $response = wp_remote_get( $request->getUrl(), $params ); |
|
77 | + $response = wp_remote_get($request->getUrl(), $params); |
|
78 | 78 | break; |
79 | 79 | } |
80 | 80 | |
81 | - $responseBody = wp_remote_retrieve_body( $response ); |
|
82 | - $respHttpCode = wp_remote_retrieve_response_code( $response ); |
|
83 | - $responseHeaders = wp_remote_retrieve_headers( $response ); |
|
81 | + $responseBody = wp_remote_retrieve_body($response); |
|
82 | + $respHttpCode = wp_remote_retrieve_response_code($response); |
|
83 | + $responseHeaders = wp_remote_retrieve_headers($response); |
|
84 | 84 | |
85 | 85 | |
86 | 86 | $this->client->getLogger()->debug( |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | ); |
94 | 94 | |
95 | 95 | // And finally return it |
96 | - return array( $responseBody, $responseHeaders, $respHttpCode ); |
|
96 | + return array($responseBody, $responseHeaders, $respHttpCode); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return mixed |
105 | 105 | */ |
106 | - public function filter_curl_from_transports( $transports ) { |
|
107 | - unset( $transports['curl'] ); |
|
106 | + public function filter_curl_from_transports($transports) { |
|
107 | + unset($transports['curl']); |
|
108 | 108 | |
109 | 109 | return $transports; |
110 | 110 | } |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | * @return bool|string |
125 | 125 | */ |
126 | 126 | public function get_curl_version() { |
127 | - if ( function_exists( 'curl_version' ) ) { |
|
127 | + if (function_exists('curl_version')) { |
|
128 | 128 | $curl = curl_version(); |
129 | 129 | |
130 | - if ( isset( $curl['version'] ) ) { |
|
130 | + if (isset($curl['version'])) { |
|
131 | 131 | return $curl['version']; |
132 | 132 | } |
133 | 133 | } |
@@ -4,21 +4,21 @@ |
||
4 | 4 | */ |
5 | 5 | // Exit if accessed directly. |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | class MonsterInsights_GA_Logger extends MonsterInsights_GA_Lib_Logger_Abstract { |
10 | 10 | |
11 | - /** |
|
12 | - * {@inheritdoc} |
|
13 | - */ |
|
14 | - public function shouldHandle( $level ) { |
|
15 | - return true; // always log errors |
|
16 | - } |
|
11 | + /** |
|
12 | + * {@inheritdoc} |
|
13 | + */ |
|
14 | + public function shouldHandle( $level ) { |
|
15 | + return true; // always log errors |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * {@inheritdoc} |
|
20 | - */ |
|
21 | - protected function write( $message ) { |
|
22 | - // @todo log to option in future |
|
23 | - } |
|
18 | + /** |
|
19 | + * {@inheritdoc} |
|
20 | + */ |
|
21 | + protected function write( $message ) { |
|
22 | + // @todo log to option in future |
|
23 | + } |
|
24 | 24 | } |
25 | 25 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Future logger that will log to `monsterinsights_logs` |
4 | 4 | */ |
5 | 5 | // Exit if accessed directly. |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if ( ! defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | class MonsterInsights_GA_Logger extends MonsterInsights_GA_Lib_Logger_Abstract { |
@@ -11,14 +11,14 @@ discard block |
||
11 | 11 | /** |
12 | 12 | * {@inheritdoc} |
13 | 13 | */ |
14 | - public function shouldHandle( $level ) { |
|
14 | + public function shouldHandle($level) { |
|
15 | 15 | return true; // always log errors |
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
19 | 19 | * {@inheritdoc} |
20 | 20 | */ |
21 | - protected function write( $message ) { |
|
21 | + protected function write($message) { |
|
22 | 22 | // @todo log to option in future |
23 | 23 | } |
24 | 24 | } |
25 | 25 | \ No newline at end of file |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | //Nothing to see here |
3 | 3 | |
4 | -header( 'HTTP/1.0 403 Forbidden' ); |
|
5 | 4 | \ No newline at end of file |
5 | +header('HTTP/1.0 403 Forbidden'); |
|
6 | 6 | \ No newline at end of file |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | //Nothing to see here |
3 | 3 | |
4 | -header( 'HTTP/1.0 403 Forbidden' ); |
|
5 | 4 | \ No newline at end of file |
5 | +header('HTTP/1.0 403 Forbidden'); |
|
6 | 6 | \ No newline at end of file |
@@ -1,81 +1,81 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! class_exists( 'AM_Deactivation_Survey' ) ) { |
3 | - /** |
|
4 | - * Awesome Motive Deactivation Survey. |
|
5 | - * |
|
6 | - * This prompts the user for more details when they deactivate the plugin. |
|
7 | - * |
|
8 | - * @version 1.1.0 |
|
9 | - * @package AwesomeMotive |
|
10 | - * @author Jared Atchison |
|
11 | - * @license GPL-2.0+ |
|
12 | - * @copyright Copyright (c) 2017 |
|
13 | - */ |
|
14 | - class AM_Deactivation_Survey { |
|
3 | + /** |
|
4 | + * Awesome Motive Deactivation Survey. |
|
5 | + * |
|
6 | + * This prompts the user for more details when they deactivate the plugin. |
|
7 | + * |
|
8 | + * @version 1.1.0 |
|
9 | + * @package AwesomeMotive |
|
10 | + * @author Jared Atchison |
|
11 | + * @license GPL-2.0+ |
|
12 | + * @copyright Copyright (c) 2017 |
|
13 | + */ |
|
14 | + class AM_Deactivation_Survey { |
|
15 | 15 | |
16 | - /** |
|
17 | - * The API URL we are calling. |
|
18 | - * |
|
19 | - * @since 1.0.0 |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $api_url = 'https://api.awesomemotive.com/v1/deactivation-survey/'; |
|
16 | + /** |
|
17 | + * The API URL we are calling. |
|
18 | + * |
|
19 | + * @since 1.0.0 |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $api_url = 'https://api.awesomemotive.com/v1/deactivation-survey/'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Name for this plugin. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - public $name; |
|
24 | + /** |
|
25 | + * Name for this plugin. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + public $name; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Unique slug for this plugin. |
|
34 | - * |
|
35 | - * @since 1.0.0 |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - public $plugin; |
|
32 | + /** |
|
33 | + * Unique slug for this plugin. |
|
34 | + * |
|
35 | + * @since 1.0.0 |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + public $plugin; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Primary class constructor. |
|
42 | - * |
|
43 | - * @since 1.0.0 |
|
44 | - * @param string $name Plugin name. |
|
45 | - * @param string $plugin Plugin slug. |
|
46 | - */ |
|
47 | - public function __construct( $name = '', $plugin = '' ) { |
|
40 | + /** |
|
41 | + * Primary class constructor. |
|
42 | + * |
|
43 | + * @since 1.0.0 |
|
44 | + * @param string $name Plugin name. |
|
45 | + * @param string $plugin Plugin slug. |
|
46 | + */ |
|
47 | + public function __construct( $name = '', $plugin = '' ) { |
|
48 | 48 | |
49 | - $this->name = $name; |
|
50 | - $this->plugin = $plugin; |
|
49 | + $this->name = $name; |
|
50 | + $this->plugin = $plugin; |
|
51 | 51 | |
52 | - add_action( 'admin_print_scripts', array( $this, 'js' ), 20 ); |
|
53 | - add_action( 'admin_print_scripts', array( $this, 'css' ) ); |
|
54 | - add_action( 'admin_footer', array( $this, 'modal' ) ); |
|
55 | - } |
|
52 | + add_action( 'admin_print_scripts', array( $this, 'js' ), 20 ); |
|
53 | + add_action( 'admin_print_scripts', array( $this, 'css' ) ); |
|
54 | + add_action( 'admin_footer', array( $this, 'modal' ) ); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Checks if current admin screen is the plugins page. |
|
59 | - * |
|
60 | - * @since 1.0.0 |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public function is_plugin_page() { |
|
57 | + /** |
|
58 | + * Checks if current admin screen is the plugins page. |
|
59 | + * |
|
60 | + * @since 1.0.0 |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public function is_plugin_page() { |
|
64 | 64 | |
65 | - return ( in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ) ); |
|
66 | - } |
|
65 | + return ( in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ) ); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Survey javascript. |
|
70 | - * |
|
71 | - * @since 1.0.0 |
|
72 | - */ |
|
73 | - public function js() { |
|
68 | + /** |
|
69 | + * Survey javascript. |
|
70 | + * |
|
71 | + * @since 1.0.0 |
|
72 | + */ |
|
73 | + public function js() { |
|
74 | 74 | |
75 | - if ( ! $this->is_plugin_page() ) { |
|
76 | - return; |
|
77 | - } |
|
78 | - ?> |
|
75 | + if ( ! $this->is_plugin_page() ) { |
|
76 | + return; |
|
77 | + } |
|
78 | + ?> |
|
79 | 79 | <script type="text/javascript"> |
80 | 80 | jQuery(function($){ |
81 | 81 | var $deactivateLink = $('#the-list').find('[data-slug="<?php echo $this->plugin; ?>"] span.deactivate a'), |
@@ -131,19 +131,19 @@ discard block |
||
131 | 131 | }); |
132 | 132 | </script> |
133 | 133 | <?php |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Survey CSS. |
|
138 | - * |
|
139 | - * @since 1.0.0 |
|
140 | - */ |
|
141 | - public function css() { |
|
136 | + /** |
|
137 | + * Survey CSS. |
|
138 | + * |
|
139 | + * @since 1.0.0 |
|
140 | + */ |
|
141 | + public function css() { |
|
142 | 142 | |
143 | - if ( ! $this->is_plugin_page() ) { |
|
144 | - return; |
|
145 | - } |
|
146 | - ?> |
|
143 | + if ( ! $this->is_plugin_page() ) { |
|
144 | + return; |
|
145 | + } |
|
146 | + ?> |
|
147 | 147 | <style type="text/css"> |
148 | 148 | .am-deactivate-survey-modal { |
149 | 149 | display: none; |
@@ -215,39 +215,39 @@ discard block |
||
215 | 215 | } |
216 | 216 | </style> |
217 | 217 | <?php |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * Survey modal. |
|
222 | - * |
|
223 | - * @since 1.0.0 |
|
224 | - */ |
|
225 | - public function modal() { |
|
220 | + /** |
|
221 | + * Survey modal. |
|
222 | + * |
|
223 | + * @since 1.0.0 |
|
224 | + */ |
|
225 | + public function modal() { |
|
226 | 226 | |
227 | - if ( ! $this->is_plugin_page() ) { |
|
228 | - return; |
|
229 | - } |
|
227 | + if ( ! $this->is_plugin_page() ) { |
|
228 | + return; |
|
229 | + } |
|
230 | 230 | |
231 | - $options = array( |
|
232 | - 1 => array( |
|
233 | - 'title' => esc_html__( 'I no longer need the plugin', 'google-analytics-for-wordpress' ), |
|
234 | - ), |
|
235 | - 2 => array( |
|
236 | - 'title' => esc_html__( 'I\'m switching to a different plugin', 'google-analytics-for-wordpress' ), |
|
237 | - 'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ), |
|
238 | - ), |
|
239 | - 3 => array( |
|
240 | - 'title' => esc_html__( 'I couldn\'t get the plugin to work', 'google-analytics-for-wordpress' ), |
|
241 | - ), |
|
242 | - 4 => array( |
|
243 | - 'title' => esc_html__( 'It\'s a temporary deactivation', 'google-analytics-for-wordpress' ), |
|
244 | - ), |
|
245 | - 5 => array( |
|
246 | - 'title' => esc_html__( 'Other', 'google-analytics-for-wordpress' ), |
|
247 | - 'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ), |
|
248 | - ), |
|
249 | - ); |
|
250 | - ?> |
|
231 | + $options = array( |
|
232 | + 1 => array( |
|
233 | + 'title' => esc_html__( 'I no longer need the plugin', 'google-analytics-for-wordpress' ), |
|
234 | + ), |
|
235 | + 2 => array( |
|
236 | + 'title' => esc_html__( 'I\'m switching to a different plugin', 'google-analytics-for-wordpress' ), |
|
237 | + 'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ), |
|
238 | + ), |
|
239 | + 3 => array( |
|
240 | + 'title' => esc_html__( 'I couldn\'t get the plugin to work', 'google-analytics-for-wordpress' ), |
|
241 | + ), |
|
242 | + 4 => array( |
|
243 | + 'title' => esc_html__( 'It\'s a temporary deactivation', 'google-analytics-for-wordpress' ), |
|
244 | + ), |
|
245 | + 5 => array( |
|
246 | + 'title' => esc_html__( 'Other', 'google-analytics-for-wordpress' ), |
|
247 | + 'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ), |
|
248 | + ), |
|
249 | + ); |
|
250 | + ?> |
|
251 | 251 | <div class="am-deactivate-survey-modal" id="am-deactivate-survey-<?php echo $this->plugin; ?>"> |
252 | 252 | <div class="am-deactivate-survey-wrap"> |
253 | 253 | <form class="am-deactivate-survey" method="post"> |
@@ -274,6 +274,6 @@ discard block |
||
274 | 274 | </div> |
275 | 275 | </div> |
276 | 276 | <?php |
277 | - } |
|
278 | - } |
|
277 | + } |
|
278 | + } |
|
279 | 279 | } // End if(). |
280 | 280 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! class_exists( 'AM_Deactivation_Survey' ) ) { |
|
2 | +if ( ! class_exists('AM_Deactivation_Survey')) { |
|
3 | 3 | /** |
4 | 4 | * Awesome Motive Deactivation Survey. |
5 | 5 | * |
@@ -44,14 +44,14 @@ discard block |
||
44 | 44 | * @param string $name Plugin name. |
45 | 45 | * @param string $plugin Plugin slug. |
46 | 46 | */ |
47 | - public function __construct( $name = '', $plugin = '' ) { |
|
47 | + public function __construct($name = '', $plugin = '') { |
|
48 | 48 | |
49 | 49 | $this->name = $name; |
50 | 50 | $this->plugin = $plugin; |
51 | 51 | |
52 | - add_action( 'admin_print_scripts', array( $this, 'js' ), 20 ); |
|
53 | - add_action( 'admin_print_scripts', array( $this, 'css' ) ); |
|
54 | - add_action( 'admin_footer', array( $this, 'modal' ) ); |
|
52 | + add_action('admin_print_scripts', array($this, 'js'), 20); |
|
53 | + add_action('admin_print_scripts', array($this, 'css')); |
|
54 | + add_action('admin_footer', array($this, 'modal')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function is_plugin_page() { |
64 | 64 | |
65 | - return ( in_array( get_current_screen()->id, array( 'plugins', 'plugins-network' ), true ) ); |
|
65 | + return (in_array(get_current_screen()->id, array('plugins', 'plugins-network'), true)); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function js() { |
74 | 74 | |
75 | - if ( ! $this->is_plugin_page() ) { |
|
75 | + if ( ! $this->is_plugin_page()) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | 78 | ?> |
@@ -105,15 +105,15 @@ discard block |
||
105 | 105 | $form.submit(function(event) { |
106 | 106 | event.preventDefault(); |
107 | 107 | if (! $form.find('input[type=radio]:checked').val()) { |
108 | - $form.find('.am-deactivate-survey-footer').prepend('<span class="error"><?php echo esc_js( __( 'Please select an option', 'google-analytics-for-wordpress' ) ); ?></span>'); |
|
108 | + $form.find('.am-deactivate-survey-footer').prepend('<span class="error"><?php echo esc_js(__('Please select an option', 'google-analytics-for-wordpress')); ?></span>'); |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | var data = { |
112 | 112 | code: $form.find('.selected input[type=radio]').val(), |
113 | 113 | reason: $form.find('.selected .am-deactivate-survey-option-reason').text(), |
114 | 114 | details: $form.find('.selected input[type=text]').val(), |
115 | - site: '<?php echo esc_url( home_url() ); ?>', |
|
116 | - plugin: '<?php echo sanitize_key( $this->name ); ?>' |
|
115 | + site: '<?php echo esc_url(home_url()); ?>', |
|
116 | + plugin: '<?php echo sanitize_key($this->name); ?>' |
|
117 | 117 | } |
118 | 118 | var submitSurvey = $.post('<?php echo $this->api_url; ?>', data); |
119 | 119 | submitSurvey.always(function() { |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function css() { |
142 | 142 | |
143 | - if ( ! $this->is_plugin_page() ) { |
|
143 | + if ( ! $this->is_plugin_page()) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | ?> |
@@ -224,51 +224,51 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public function modal() { |
226 | 226 | |
227 | - if ( ! $this->is_plugin_page() ) { |
|
227 | + if ( ! $this->is_plugin_page()) { |
|
228 | 228 | return; |
229 | 229 | } |
230 | 230 | |
231 | 231 | $options = array( |
232 | 232 | 1 => array( |
233 | - 'title' => esc_html__( 'I no longer need the plugin', 'google-analytics-for-wordpress' ), |
|
233 | + 'title' => esc_html__('I no longer need the plugin', 'google-analytics-for-wordpress'), |
|
234 | 234 | ), |
235 | 235 | 2 => array( |
236 | - 'title' => esc_html__( 'I\'m switching to a different plugin', 'google-analytics-for-wordpress' ), |
|
237 | - 'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ), |
|
236 | + 'title' => esc_html__('I\'m switching to a different plugin', 'google-analytics-for-wordpress'), |
|
237 | + 'details' => esc_html__('Please share which plugin', 'google-analytics-for-wordpress'), |
|
238 | 238 | ), |
239 | 239 | 3 => array( |
240 | - 'title' => esc_html__( 'I couldn\'t get the plugin to work', 'google-analytics-for-wordpress' ), |
|
240 | + 'title' => esc_html__('I couldn\'t get the plugin to work', 'google-analytics-for-wordpress'), |
|
241 | 241 | ), |
242 | 242 | 4 => array( |
243 | - 'title' => esc_html__( 'It\'s a temporary deactivation', 'google-analytics-for-wordpress' ), |
|
243 | + 'title' => esc_html__('It\'s a temporary deactivation', 'google-analytics-for-wordpress'), |
|
244 | 244 | ), |
245 | 245 | 5 => array( |
246 | - 'title' => esc_html__( 'Other', 'google-analytics-for-wordpress' ), |
|
247 | - 'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ), |
|
246 | + 'title' => esc_html__('Other', 'google-analytics-for-wordpress'), |
|
247 | + 'details' => esc_html__('Please share the reason', 'google-analytics-for-wordpress'), |
|
248 | 248 | ), |
249 | 249 | ); |
250 | 250 | ?> |
251 | 251 | <div class="am-deactivate-survey-modal" id="am-deactivate-survey-<?php echo $this->plugin; ?>"> |
252 | 252 | <div class="am-deactivate-survey-wrap"> |
253 | 253 | <form class="am-deactivate-survey" method="post"> |
254 | - <span class="am-deactivate-survey-title"><span class="dashicons dashicons-testimonial"></span><?php echo ' ' . esc_html__( 'Quick Feedback', 'google-analytics-for-wordpress' ); ?></span> |
|
255 | - <span class="am-deactivate-survey-desc"><?php echo sprintf( esc_html__('If you have a moment, please share why you are deactivating %s:', 'google-analytics-for-wordpress' ), $this->name ); ?></span> |
|
254 | + <span class="am-deactivate-survey-title"><span class="dashicons dashicons-testimonial"></span><?php echo ' ' . esc_html__('Quick Feedback', 'google-analytics-for-wordpress'); ?></span> |
|
255 | + <span class="am-deactivate-survey-desc"><?php echo sprintf(esc_html__('If you have a moment, please share why you are deactivating %s:', 'google-analytics-for-wordpress'), $this->name); ?></span> |
|
256 | 256 | <div class="am-deactivate-survey-options"> |
257 | - <?php foreach ( $options as $id => $option ) : ?> |
|
257 | + <?php foreach ($options as $id => $option) : ?> |
|
258 | 258 | <div class="am-deactivate-survey-option"> |
259 | 259 | <label for="am-deactivate-survey-option-<?php echo $this->plugin; ?>-<?php echo $id; ?>" class="am-deactivate-survey-option-label"> |
260 | 260 | <input id="am-deactivate-survey-option-<?php echo $this->plugin; ?>-<?php echo $id; ?>" class="am-deactivate-survey-option-input" type="radio" name="code" value="<?php echo $id; ?>" /> |
261 | 261 | <span class="am-deactivate-survey-option-reason"><?php echo $option['title']; ?></span> |
262 | 262 | </label> |
263 | - <?php if ( ! empty( $option['details'] ) ) : ?> |
|
263 | + <?php if ( ! empty($option['details'])) : ?> |
|
264 | 264 | <input class="am-deactivate-survey-option-details" type="text" placeholder="<?php echo $option['details']; ?>" /> |
265 | 265 | <?php endif; ?> |
266 | 266 | </div> |
267 | 267 | <?php endforeach; ?> |
268 | 268 | </div> |
269 | 269 | <div class="am-deactivate-survey-footer"> |
270 | - <button type="submit" class="am-deactivate-survey-submit button button-primary button-large"><?php echo sprintf( esc_html__('Submit %s Deactivate', 'google-analytics-for-wordpress' ), '&' ); ?></button> |
|
271 | - <a href="#" class="am-deactivate-survey-deactivate"><?php echo sprintf( esc_html__('Skip %s Deactivate', 'google-analytics-for-wordpress' ), '&' ); ?></a> |
|
270 | + <button type="submit" class="am-deactivate-survey-submit button button-primary button-large"><?php echo sprintf(esc_html__('Submit %s Deactivate', 'google-analytics-for-wordpress'), '&'); ?></button> |
|
271 | + <a href="#" class="am-deactivate-survey-deactivate"><?php echo sprintf(esc_html__('Skip %s Deactivate', 'google-analytics-for-wordpress'), '&'); ?></a> |
|
272 | 272 | </div> |
273 | 273 | </form> |
274 | 274 | </div> |
@@ -1,257 +1,257 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! class_exists( 'AM_Notification' ) ) { |
3 | - /** |
|
4 | - * Awesome Motive Notifications |
|
5 | - * |
|
6 | - * This creates a custom post type (if it doesn't exist) and calls the API to |
|
7 | - * retrieve notifications for this product. |
|
8 | - * |
|
9 | - * @package AwesomeMotive |
|
10 | - * @author Benjamin Rojas |
|
11 | - * @license GPL-2.0+ |
|
12 | - * @copyright Copyright (c) 2017, Retyp LLC |
|
13 | - * @version 1.0.0 |
|
14 | - */ |
|
15 | - class AM_Notification { |
|
16 | - /** |
|
17 | - * The api url we are calling. |
|
18 | - * |
|
19 | - * @since 1.0.0 |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $api_url = 'https://api.awesomemotive.com/v1/notification/'; |
|
24 | - |
|
25 | - /** |
|
26 | - * A unique slug for this plugin. |
|
27 | - * (Not the WordPress plugin slug) |
|
28 | - * |
|
29 | - * @since 1.0.0 |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - public $plugin; |
|
34 | - |
|
35 | - /** |
|
36 | - * The current plugin version. |
|
37 | - * |
|
38 | - * @since 1.0.0 |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - public $plugin_version; |
|
43 | - |
|
44 | - /** |
|
45 | - * The list of installed plugins. |
|
46 | - * |
|
47 | - * @since 1.0.0 |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - public $plugin_list = array(); |
|
52 | - |
|
53 | - /** |
|
54 | - * The list of installed themes. |
|
55 | - * |
|
56 | - * @since 1.0.0 |
|
57 | - * |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - public $theme_list = array(); |
|
61 | - |
|
62 | - /** |
|
63 | - * Construct. |
|
64 | - * |
|
65 | - * @since 1.0.0 |
|
66 | - * |
|
67 | - * @param string $plugin The plugin slug. |
|
68 | - * @param string $version The version of the plugin. |
|
69 | - */ |
|
70 | - public function __construct( $plugin = '', $version = 0 ) { |
|
71 | - $this->plugin = $plugin; |
|
72 | - $this->plugin_version = $version; |
|
73 | - |
|
74 | - add_action( 'init', array( $this, 'custom_post_type' ) ); |
|
75 | - add_action( 'init', array( $this, 'get_remote_notifications' ), 100 ); |
|
76 | - add_action( 'admin_notices', array( $this, 'display_notifications' ) ); |
|
77 | - add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) ); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Registers a custom post type. |
|
82 | - * |
|
83 | - * @since 1.0.0 |
|
84 | - */ |
|
85 | - public function custom_post_type() { |
|
86 | - register_post_type( 'amn_' . $this->plugin, array( |
|
87 | - 'supports' => false |
|
88 | - ) ); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Retrieve the remote notifications if the time has expired. |
|
93 | - * |
|
94 | - * @since 1.0.0 |
|
95 | - */ |
|
96 | - public function get_remote_notifications() { |
|
97 | - $last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) ); |
|
98 | - |
|
99 | - if ( $last_checked < strtotime( 'today midnight' ) ) { |
|
100 | - |
|
101 | - $plugin_notifications = $this->get_plugin_notifications( 1 ); |
|
102 | - |
|
103 | - $notification_id = null; |
|
104 | - if ( ! empty( $plugin_notifications) ) { |
|
105 | - // Unset it from the array. |
|
106 | - $notification = $plugin_notifications[0]; |
|
107 | - $notification_id = get_post_meta( $notification->ID, 'notification_id', true ); |
|
108 | - } |
|
109 | - |
|
110 | - $response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array( |
|
111 | - 'sslverify' => false, |
|
112 | - 'body' => array( |
|
113 | - 'slug' => $this->plugin, |
|
114 | - 'version' => $this->plugin_version, |
|
115 | - 'last_notification' => $notification_id, |
|
116 | - 'plugins' => $this->get_plugins_list(), |
|
117 | - 'themes' => $this->get_themes_list() |
|
118 | - ) |
|
119 | - ) ) ); |
|
120 | - |
|
121 | - $data = json_decode( $response ); |
|
122 | - |
|
123 | - if ( ! empty( $data->id ) ) { |
|
124 | - |
|
125 | - $notifications = array(); |
|
126 | - foreach ( (array) $data->slugs as $slug ) { |
|
127 | - $notifications = array_merge( $notifications, (array) get_posts( array( |
|
128 | - 'post_type' => 'amn_' . $slug, |
|
129 | - 'post_status' => 'all', |
|
130 | - 'meta_key' => 'notification_id', |
|
131 | - 'meta_value' => $data->id |
|
132 | - ) ) ); |
|
133 | - } |
|
134 | - |
|
135 | - if ( empty( $notifications ) ) { |
|
136 | - |
|
137 | - $new_notification_id = wp_insert_post( array( |
|
138 | - 'post_content' => $data->content, |
|
139 | - 'post_type' => 'amn_' . $this->plugin |
|
140 | - ) ); |
|
141 | - |
|
142 | - update_post_meta( $new_notification_id, 'notification_id', $data->id ); |
|
143 | - update_post_meta( $new_notification_id, 'type', $data->type ); |
|
144 | - update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 ); |
|
145 | - update_post_meta( $new_notification_id, 'location', wp_json_encode( $data->location ) ); |
|
146 | - update_post_meta( $new_notification_id, 'plugins', wp_json_encode( $data->plugins ) ); |
|
147 | - update_post_meta( $new_notification_id, 'theme', $data->theme ); |
|
148 | - update_post_meta( $new_notification_id, 'version', $data->version ); |
|
149 | - update_post_meta( $new_notification_id, 'viewed', 0 ); |
|
150 | - } |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - // Set the option now so we can't run this again until after 24 hours. |
|
155 | - update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) ); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Get local plugin notifications that have already been set. |
|
161 | - * |
|
162 | - * @since 1.0.0 |
|
163 | - * |
|
164 | - * @param integer $limit Set the limit for how many posts to retrieve. |
|
165 | - * @param array $args Any top-level arguments to add to the array. |
|
166 | - * @return object WP_Posts that match the query. |
|
167 | - */ |
|
168 | - public function get_plugin_notifications( $limit = -1, $args = array() ) { |
|
169 | - return get_posts( array( |
|
170 | - 'showposts' => $limit, |
|
171 | - 'post_type' => 'amn_' . $this->plugin |
|
172 | - ) + $args ); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Retrieve a list of plugins that are currently installed. |
|
177 | - * |
|
178 | - * @since 1.0.0 |
|
179 | - * |
|
180 | - * @return array An array of plugins that are currently installed. |
|
181 | - */ |
|
182 | - public function get_plugins_list() { |
|
183 | - if ( ! empty( $this->plugin_list ) ) { |
|
184 | - return $this->plugin_list; |
|
185 | - } |
|
186 | - |
|
187 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
188 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
189 | - } |
|
190 | - |
|
191 | - $plugins = get_plugins(); |
|
192 | - |
|
193 | - foreach ( $plugins as $slug => $plugin ) { |
|
194 | - $this->plugin_list[ $slug ] = array( |
|
195 | - 'slug' => $slug, |
|
196 | - 'name' => $plugin['Name'], |
|
197 | - 'version' => $plugin['Version'], |
|
198 | - 'active' => is_plugin_active( $slug ) |
|
199 | - ); |
|
200 | - } |
|
201 | - |
|
202 | - return $this->plugin_list; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Retrieve a list of themes that are currently installed. |
|
207 | - * |
|
208 | - * @since 1.0.0 |
|
209 | - * |
|
210 | - * @return array An array of themes that are currently installed. |
|
211 | - */ |
|
212 | - public function get_themes_list() { |
|
213 | - if ( ! empty( $this->theme_list ) ) { |
|
214 | - return $this->theme_list; |
|
215 | - } |
|
216 | - |
|
217 | - $themes = wp_get_themes(); |
|
218 | - |
|
219 | - foreach ( $themes as $slug => $theme ) { |
|
220 | - $this->theme_list[ $slug ] = array( |
|
221 | - 'slug' => $slug, |
|
222 | - 'name' => $theme->Name, |
|
223 | - 'version' => $theme->Version, |
|
224 | - 'active' => (string) wp_get_theme() == $theme->Name |
|
225 | - ); |
|
226 | - } |
|
227 | - |
|
228 | - return $this->theme_list; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Display any notifications that should be displayed. |
|
233 | - * |
|
234 | - * @since 1.0.0 |
|
235 | - */ |
|
236 | - public function display_notifications() { |
|
237 | - |
|
238 | - if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) { |
|
239 | - return; |
|
240 | - } |
|
241 | - |
|
242 | - $plugin_notifications = $this->get_plugin_notifications( -1, array( |
|
243 | - 'post_status' => 'all', |
|
244 | - 'meta_key' => 'viewed', |
|
245 | - 'meta_value' => '0' |
|
246 | - ) ); |
|
247 | - |
|
248 | - $plugin_notifications = $this->validate_notifications( $plugin_notifications ); |
|
249 | - |
|
250 | - if ( ! empty( $plugin_notifications ) ) { |
|
251 | - foreach ( $plugin_notifications as $notification ) { |
|
252 | - $dismissable = get_post_meta( $notification->ID, 'dismissable', true ); |
|
253 | - $type = get_post_meta( $notification->ID, 'type', true ); |
|
254 | - ?> |
|
3 | + /** |
|
4 | + * Awesome Motive Notifications |
|
5 | + * |
|
6 | + * This creates a custom post type (if it doesn't exist) and calls the API to |
|
7 | + * retrieve notifications for this product. |
|
8 | + * |
|
9 | + * @package AwesomeMotive |
|
10 | + * @author Benjamin Rojas |
|
11 | + * @license GPL-2.0+ |
|
12 | + * @copyright Copyright (c) 2017, Retyp LLC |
|
13 | + * @version 1.0.0 |
|
14 | + */ |
|
15 | + class AM_Notification { |
|
16 | + /** |
|
17 | + * The api url we are calling. |
|
18 | + * |
|
19 | + * @since 1.0.0 |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $api_url = 'https://api.awesomemotive.com/v1/notification/'; |
|
24 | + |
|
25 | + /** |
|
26 | + * A unique slug for this plugin. |
|
27 | + * (Not the WordPress plugin slug) |
|
28 | + * |
|
29 | + * @since 1.0.0 |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + public $plugin; |
|
34 | + |
|
35 | + /** |
|
36 | + * The current plugin version. |
|
37 | + * |
|
38 | + * @since 1.0.0 |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + public $plugin_version; |
|
43 | + |
|
44 | + /** |
|
45 | + * The list of installed plugins. |
|
46 | + * |
|
47 | + * @since 1.0.0 |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + public $plugin_list = array(); |
|
52 | + |
|
53 | + /** |
|
54 | + * The list of installed themes. |
|
55 | + * |
|
56 | + * @since 1.0.0 |
|
57 | + * |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + public $theme_list = array(); |
|
61 | + |
|
62 | + /** |
|
63 | + * Construct. |
|
64 | + * |
|
65 | + * @since 1.0.0 |
|
66 | + * |
|
67 | + * @param string $plugin The plugin slug. |
|
68 | + * @param string $version The version of the plugin. |
|
69 | + */ |
|
70 | + public function __construct( $plugin = '', $version = 0 ) { |
|
71 | + $this->plugin = $plugin; |
|
72 | + $this->plugin_version = $version; |
|
73 | + |
|
74 | + add_action( 'init', array( $this, 'custom_post_type' ) ); |
|
75 | + add_action( 'init', array( $this, 'get_remote_notifications' ), 100 ); |
|
76 | + add_action( 'admin_notices', array( $this, 'display_notifications' ) ); |
|
77 | + add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) ); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Registers a custom post type. |
|
82 | + * |
|
83 | + * @since 1.0.0 |
|
84 | + */ |
|
85 | + public function custom_post_type() { |
|
86 | + register_post_type( 'amn_' . $this->plugin, array( |
|
87 | + 'supports' => false |
|
88 | + ) ); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Retrieve the remote notifications if the time has expired. |
|
93 | + * |
|
94 | + * @since 1.0.0 |
|
95 | + */ |
|
96 | + public function get_remote_notifications() { |
|
97 | + $last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) ); |
|
98 | + |
|
99 | + if ( $last_checked < strtotime( 'today midnight' ) ) { |
|
100 | + |
|
101 | + $plugin_notifications = $this->get_plugin_notifications( 1 ); |
|
102 | + |
|
103 | + $notification_id = null; |
|
104 | + if ( ! empty( $plugin_notifications) ) { |
|
105 | + // Unset it from the array. |
|
106 | + $notification = $plugin_notifications[0]; |
|
107 | + $notification_id = get_post_meta( $notification->ID, 'notification_id', true ); |
|
108 | + } |
|
109 | + |
|
110 | + $response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array( |
|
111 | + 'sslverify' => false, |
|
112 | + 'body' => array( |
|
113 | + 'slug' => $this->plugin, |
|
114 | + 'version' => $this->plugin_version, |
|
115 | + 'last_notification' => $notification_id, |
|
116 | + 'plugins' => $this->get_plugins_list(), |
|
117 | + 'themes' => $this->get_themes_list() |
|
118 | + ) |
|
119 | + ) ) ); |
|
120 | + |
|
121 | + $data = json_decode( $response ); |
|
122 | + |
|
123 | + if ( ! empty( $data->id ) ) { |
|
124 | + |
|
125 | + $notifications = array(); |
|
126 | + foreach ( (array) $data->slugs as $slug ) { |
|
127 | + $notifications = array_merge( $notifications, (array) get_posts( array( |
|
128 | + 'post_type' => 'amn_' . $slug, |
|
129 | + 'post_status' => 'all', |
|
130 | + 'meta_key' => 'notification_id', |
|
131 | + 'meta_value' => $data->id |
|
132 | + ) ) ); |
|
133 | + } |
|
134 | + |
|
135 | + if ( empty( $notifications ) ) { |
|
136 | + |
|
137 | + $new_notification_id = wp_insert_post( array( |
|
138 | + 'post_content' => $data->content, |
|
139 | + 'post_type' => 'amn_' . $this->plugin |
|
140 | + ) ); |
|
141 | + |
|
142 | + update_post_meta( $new_notification_id, 'notification_id', $data->id ); |
|
143 | + update_post_meta( $new_notification_id, 'type', $data->type ); |
|
144 | + update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 ); |
|
145 | + update_post_meta( $new_notification_id, 'location', wp_json_encode( $data->location ) ); |
|
146 | + update_post_meta( $new_notification_id, 'plugins', wp_json_encode( $data->plugins ) ); |
|
147 | + update_post_meta( $new_notification_id, 'theme', $data->theme ); |
|
148 | + update_post_meta( $new_notification_id, 'version', $data->version ); |
|
149 | + update_post_meta( $new_notification_id, 'viewed', 0 ); |
|
150 | + } |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + // Set the option now so we can't run this again until after 24 hours. |
|
155 | + update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) ); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Get local plugin notifications that have already been set. |
|
161 | + * |
|
162 | + * @since 1.0.0 |
|
163 | + * |
|
164 | + * @param integer $limit Set the limit for how many posts to retrieve. |
|
165 | + * @param array $args Any top-level arguments to add to the array. |
|
166 | + * @return object WP_Posts that match the query. |
|
167 | + */ |
|
168 | + public function get_plugin_notifications( $limit = -1, $args = array() ) { |
|
169 | + return get_posts( array( |
|
170 | + 'showposts' => $limit, |
|
171 | + 'post_type' => 'amn_' . $this->plugin |
|
172 | + ) + $args ); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Retrieve a list of plugins that are currently installed. |
|
177 | + * |
|
178 | + * @since 1.0.0 |
|
179 | + * |
|
180 | + * @return array An array of plugins that are currently installed. |
|
181 | + */ |
|
182 | + public function get_plugins_list() { |
|
183 | + if ( ! empty( $this->plugin_list ) ) { |
|
184 | + return $this->plugin_list; |
|
185 | + } |
|
186 | + |
|
187 | + if ( ! function_exists( 'get_plugins' ) ) { |
|
188 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
189 | + } |
|
190 | + |
|
191 | + $plugins = get_plugins(); |
|
192 | + |
|
193 | + foreach ( $plugins as $slug => $plugin ) { |
|
194 | + $this->plugin_list[ $slug ] = array( |
|
195 | + 'slug' => $slug, |
|
196 | + 'name' => $plugin['Name'], |
|
197 | + 'version' => $plugin['Version'], |
|
198 | + 'active' => is_plugin_active( $slug ) |
|
199 | + ); |
|
200 | + } |
|
201 | + |
|
202 | + return $this->plugin_list; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Retrieve a list of themes that are currently installed. |
|
207 | + * |
|
208 | + * @since 1.0.0 |
|
209 | + * |
|
210 | + * @return array An array of themes that are currently installed. |
|
211 | + */ |
|
212 | + public function get_themes_list() { |
|
213 | + if ( ! empty( $this->theme_list ) ) { |
|
214 | + return $this->theme_list; |
|
215 | + } |
|
216 | + |
|
217 | + $themes = wp_get_themes(); |
|
218 | + |
|
219 | + foreach ( $themes as $slug => $theme ) { |
|
220 | + $this->theme_list[ $slug ] = array( |
|
221 | + 'slug' => $slug, |
|
222 | + 'name' => $theme->Name, |
|
223 | + 'version' => $theme->Version, |
|
224 | + 'active' => (string) wp_get_theme() == $theme->Name |
|
225 | + ); |
|
226 | + } |
|
227 | + |
|
228 | + return $this->theme_list; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Display any notifications that should be displayed. |
|
233 | + * |
|
234 | + * @since 1.0.0 |
|
235 | + */ |
|
236 | + public function display_notifications() { |
|
237 | + |
|
238 | + if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) { |
|
239 | + return; |
|
240 | + } |
|
241 | + |
|
242 | + $plugin_notifications = $this->get_plugin_notifications( -1, array( |
|
243 | + 'post_status' => 'all', |
|
244 | + 'meta_key' => 'viewed', |
|
245 | + 'meta_value' => '0' |
|
246 | + ) ); |
|
247 | + |
|
248 | + $plugin_notifications = $this->validate_notifications( $plugin_notifications ); |
|
249 | + |
|
250 | + if ( ! empty( $plugin_notifications ) ) { |
|
251 | + foreach ( $plugin_notifications as $notification ) { |
|
252 | + $dismissable = get_post_meta( $notification->ID, 'dismissable', true ); |
|
253 | + $type = get_post_meta( $notification->ID, 'type', true ); |
|
254 | + ?> |
|
255 | 255 | <div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>"> |
256 | 256 | <?php echo $notification->post_content; ?> |
257 | 257 | </div> |
@@ -266,88 +266,88 @@ discard block |
||
266 | 266 | }); |
267 | 267 | </script> |
268 | 268 | <?php } |
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Validate the notifications before displaying them. |
|
274 | - * |
|
275 | - * @since 1.0.0 |
|
276 | - * |
|
277 | - * @param array $plugin_notifications An array of plugin notifications. |
|
278 | - * @return array A filtered array of plugin notifications. |
|
279 | - */ |
|
280 | - public function validate_notifications( $plugin_notifications ) { |
|
281 | - global $pagenow; |
|
282 | - foreach ( $plugin_notifications as $key => $notification ) { |
|
283 | - // Location validation. |
|
284 | - $location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) ); |
|
285 | - $continue = false; |
|
286 | - if ( ! in_array( 'everywhere', $location ) ) { |
|
287 | - if ( in_array( 'index.php', $location ) && 'index.php' == $pagenow ) { |
|
288 | - $continue = true; |
|
289 | - } |
|
290 | - |
|
291 | - if ( in_array( 'plugins.php', $location ) && 'plugins.php' == $pagenow ) { |
|
292 | - $continue = true; |
|
293 | - } |
|
294 | - |
|
295 | - if ( ! $continue ) { |
|
296 | - unset( $plugin_notifications[ $key ] ); |
|
297 | - } |
|
298 | - } |
|
299 | - |
|
300 | - // Plugin validation (OR conditional) |
|
301 | - $plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) ); |
|
302 | - $continue = false; |
|
303 | - if ( ! empty( $plugins ) ) { |
|
304 | - foreach ( $plugins as $plugin ) { |
|
305 | - if ( is_plugin_active( $plugin ) ) { |
|
306 | - $continue = true; |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - if ( ! $continue ) { |
|
311 | - unset( $plugin_notifications[ $key ] ); |
|
312 | - } |
|
313 | - } |
|
314 | - |
|
315 | - // Theme validation. |
|
316 | - $theme = get_post_meta( $notification->ID, 'theme', true ); |
|
317 | - $continue = (string) wp_get_theme() == $theme; |
|
318 | - |
|
319 | - if ( ! empty( $theme ) && ! $continue ) { |
|
320 | - unset( $plugin_notifications[ $key ] ); |
|
321 | - } |
|
322 | - |
|
323 | - // Version validation. |
|
324 | - $version = get_post_meta( $notification->ID, 'version', true ); |
|
325 | - $continue = false; |
|
326 | - if ( ! empty( $version ) ) { |
|
327 | - if ( version_compare( $this->plugin_version, $version, '<=' ) ) { |
|
328 | - $continue = true; |
|
329 | - } |
|
330 | - |
|
331 | - if ( ! $continue ) { |
|
332 | - unset( $plugin_notifications[ $key ] ); |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - } |
|
337 | - |
|
338 | - return $plugin_notifications; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Dismiss the notification via AJAX. |
|
343 | - * |
|
344 | - * @since 1.0.0 |
|
345 | - */ |
|
346 | - public function dismiss_notification() { |
|
347 | - $notification_id = intval( $_POST['notification_id'] ); |
|
348 | - update_post_meta( $notification_id, 'viewed', 1 ); |
|
349 | - die; |
|
350 | - } |
|
351 | - |
|
352 | - } |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Validate the notifications before displaying them. |
|
274 | + * |
|
275 | + * @since 1.0.0 |
|
276 | + * |
|
277 | + * @param array $plugin_notifications An array of plugin notifications. |
|
278 | + * @return array A filtered array of plugin notifications. |
|
279 | + */ |
|
280 | + public function validate_notifications( $plugin_notifications ) { |
|
281 | + global $pagenow; |
|
282 | + foreach ( $plugin_notifications as $key => $notification ) { |
|
283 | + // Location validation. |
|
284 | + $location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) ); |
|
285 | + $continue = false; |
|
286 | + if ( ! in_array( 'everywhere', $location ) ) { |
|
287 | + if ( in_array( 'index.php', $location ) && 'index.php' == $pagenow ) { |
|
288 | + $continue = true; |
|
289 | + } |
|
290 | + |
|
291 | + if ( in_array( 'plugins.php', $location ) && 'plugins.php' == $pagenow ) { |
|
292 | + $continue = true; |
|
293 | + } |
|
294 | + |
|
295 | + if ( ! $continue ) { |
|
296 | + unset( $plugin_notifications[ $key ] ); |
|
297 | + } |
|
298 | + } |
|
299 | + |
|
300 | + // Plugin validation (OR conditional) |
|
301 | + $plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) ); |
|
302 | + $continue = false; |
|
303 | + if ( ! empty( $plugins ) ) { |
|
304 | + foreach ( $plugins as $plugin ) { |
|
305 | + if ( is_plugin_active( $plugin ) ) { |
|
306 | + $continue = true; |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + if ( ! $continue ) { |
|
311 | + unset( $plugin_notifications[ $key ] ); |
|
312 | + } |
|
313 | + } |
|
314 | + |
|
315 | + // Theme validation. |
|
316 | + $theme = get_post_meta( $notification->ID, 'theme', true ); |
|
317 | + $continue = (string) wp_get_theme() == $theme; |
|
318 | + |
|
319 | + if ( ! empty( $theme ) && ! $continue ) { |
|
320 | + unset( $plugin_notifications[ $key ] ); |
|
321 | + } |
|
322 | + |
|
323 | + // Version validation. |
|
324 | + $version = get_post_meta( $notification->ID, 'version', true ); |
|
325 | + $continue = false; |
|
326 | + if ( ! empty( $version ) ) { |
|
327 | + if ( version_compare( $this->plugin_version, $version, '<=' ) ) { |
|
328 | + $continue = true; |
|
329 | + } |
|
330 | + |
|
331 | + if ( ! $continue ) { |
|
332 | + unset( $plugin_notifications[ $key ] ); |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + } |
|
337 | + |
|
338 | + return $plugin_notifications; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Dismiss the notification via AJAX. |
|
343 | + * |
|
344 | + * @since 1.0.0 |
|
345 | + */ |
|
346 | + public function dismiss_notification() { |
|
347 | + $notification_id = intval( $_POST['notification_id'] ); |
|
348 | + update_post_meta( $notification_id, 'viewed', 1 ); |
|
349 | + die; |
|
350 | + } |
|
351 | + |
|
352 | + } |
|
353 | 353 | } |
354 | 354 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! class_exists( 'AM_Notification' ) ) { |
|
2 | +if ( ! class_exists('AM_Notification')) { |
|
3 | 3 | /** |
4 | 4 | * Awesome Motive Notifications |
5 | 5 | * |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | * @param string $plugin The plugin slug. |
68 | 68 | * @param string $version The version of the plugin. |
69 | 69 | */ |
70 | - public function __construct( $plugin = '', $version = 0 ) { |
|
70 | + public function __construct($plugin = '', $version = 0) { |
|
71 | 71 | $this->plugin = $plugin; |
72 | 72 | $this->plugin_version = $version; |
73 | 73 | |
74 | - add_action( 'init', array( $this, 'custom_post_type' ) ); |
|
75 | - add_action( 'init', array( $this, 'get_remote_notifications' ), 100 ); |
|
76 | - add_action( 'admin_notices', array( $this, 'display_notifications' ) ); |
|
77 | - add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) ); |
|
74 | + add_action('init', array($this, 'custom_post_type')); |
|
75 | + add_action('init', array($this, 'get_remote_notifications'), 100); |
|
76 | + add_action('admin_notices', array($this, 'display_notifications')); |
|
77 | + add_action('wp_ajax_am_notification_dismiss', array($this, 'dismiss_notification')); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @since 1.0.0 |
84 | 84 | */ |
85 | 85 | public function custom_post_type() { |
86 | - register_post_type( 'amn_' . $this->plugin, array( |
|
86 | + register_post_type('amn_' . $this->plugin, array( |
|
87 | 87 | 'supports' => false |
88 | - ) ); |
|
88 | + )); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -94,20 +94,20 @@ discard block |
||
94 | 94 | * @since 1.0.0 |
95 | 95 | */ |
96 | 96 | public function get_remote_notifications() { |
97 | - $last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) ); |
|
97 | + $last_checked = get_option('_amn_' . $this->plugin . '_last_checked', strtotime('-1 week')); |
|
98 | 98 | |
99 | - if ( $last_checked < strtotime( 'today midnight' ) ) { |
|
99 | + if ($last_checked < strtotime('today midnight')) { |
|
100 | 100 | |
101 | - $plugin_notifications = $this->get_plugin_notifications( 1 ); |
|
101 | + $plugin_notifications = $this->get_plugin_notifications(1); |
|
102 | 102 | |
103 | 103 | $notification_id = null; |
104 | - if ( ! empty( $plugin_notifications) ) { |
|
104 | + if ( ! empty($plugin_notifications)) { |
|
105 | 105 | // Unset it from the array. |
106 | 106 | $notification = $plugin_notifications[0]; |
107 | - $notification_id = get_post_meta( $notification->ID, 'notification_id', true ); |
|
107 | + $notification_id = get_post_meta($notification->ID, 'notification_id', true); |
|
108 | 108 | } |
109 | 109 | |
110 | - $response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array( |
|
110 | + $response = wp_remote_retrieve_body(wp_remote_post($this->api_url, array( |
|
111 | 111 | 'sslverify' => false, |
112 | 112 | 'body' => array( |
113 | 113 | 'slug' => $this->plugin, |
@@ -116,43 +116,43 @@ discard block |
||
116 | 116 | 'plugins' => $this->get_plugins_list(), |
117 | 117 | 'themes' => $this->get_themes_list() |
118 | 118 | ) |
119 | - ) ) ); |
|
119 | + ))); |
|
120 | 120 | |
121 | - $data = json_decode( $response ); |
|
121 | + $data = json_decode($response); |
|
122 | 122 | |
123 | - if ( ! empty( $data->id ) ) { |
|
123 | + if ( ! empty($data->id)) { |
|
124 | 124 | |
125 | 125 | $notifications = array(); |
126 | - foreach ( (array) $data->slugs as $slug ) { |
|
127 | - $notifications = array_merge( $notifications, (array) get_posts( array( |
|
126 | + foreach ((array) $data->slugs as $slug) { |
|
127 | + $notifications = array_merge($notifications, (array) get_posts(array( |
|
128 | 128 | 'post_type' => 'amn_' . $slug, |
129 | 129 | 'post_status' => 'all', |
130 | 130 | 'meta_key' => 'notification_id', |
131 | 131 | 'meta_value' => $data->id |
132 | - ) ) ); |
|
132 | + ))); |
|
133 | 133 | } |
134 | 134 | |
135 | - if ( empty( $notifications ) ) { |
|
135 | + if (empty($notifications)) { |
|
136 | 136 | |
137 | - $new_notification_id = wp_insert_post( array( |
|
137 | + $new_notification_id = wp_insert_post(array( |
|
138 | 138 | 'post_content' => $data->content, |
139 | 139 | 'post_type' => 'amn_' . $this->plugin |
140 | - ) ); |
|
141 | - |
|
142 | - update_post_meta( $new_notification_id, 'notification_id', $data->id ); |
|
143 | - update_post_meta( $new_notification_id, 'type', $data->type ); |
|
144 | - update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 ); |
|
145 | - update_post_meta( $new_notification_id, 'location', wp_json_encode( $data->location ) ); |
|
146 | - update_post_meta( $new_notification_id, 'plugins', wp_json_encode( $data->plugins ) ); |
|
147 | - update_post_meta( $new_notification_id, 'theme', $data->theme ); |
|
148 | - update_post_meta( $new_notification_id, 'version', $data->version ); |
|
149 | - update_post_meta( $new_notification_id, 'viewed', 0 ); |
|
140 | + )); |
|
141 | + |
|
142 | + update_post_meta($new_notification_id, 'notification_id', $data->id); |
|
143 | + update_post_meta($new_notification_id, 'type', $data->type); |
|
144 | + update_post_meta($new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0); |
|
145 | + update_post_meta($new_notification_id, 'location', wp_json_encode($data->location)); |
|
146 | + update_post_meta($new_notification_id, 'plugins', wp_json_encode($data->plugins)); |
|
147 | + update_post_meta($new_notification_id, 'theme', $data->theme); |
|
148 | + update_post_meta($new_notification_id, 'version', $data->version); |
|
149 | + update_post_meta($new_notification_id, 'viewed', 0); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | } |
153 | 153 | |
154 | 154 | // Set the option now so we can't run this again until after 24 hours. |
155 | - update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) ); |
|
155 | + update_option('_amn_' . $this->plugin . '_last_checked', strtotime('today midnight')); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | * @param array $args Any top-level arguments to add to the array. |
166 | 166 | * @return object WP_Posts that match the query. |
167 | 167 | */ |
168 | - public function get_plugin_notifications( $limit = -1, $args = array() ) { |
|
169 | - return get_posts( array( |
|
168 | + public function get_plugin_notifications($limit = -1, $args = array()) { |
|
169 | + return get_posts(array( |
|
170 | 170 | 'showposts' => $limit, |
171 | 171 | 'post_type' => 'amn_' . $this->plugin |
172 | - ) + $args ); |
|
172 | + ) + $args); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -180,22 +180,22 @@ discard block |
||
180 | 180 | * @return array An array of plugins that are currently installed. |
181 | 181 | */ |
182 | 182 | public function get_plugins_list() { |
183 | - if ( ! empty( $this->plugin_list ) ) { |
|
183 | + if ( ! empty($this->plugin_list)) { |
|
184 | 184 | return $this->plugin_list; |
185 | 185 | } |
186 | 186 | |
187 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
187 | + if ( ! function_exists('get_plugins')) { |
|
188 | 188 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
189 | 189 | } |
190 | 190 | |
191 | 191 | $plugins = get_plugins(); |
192 | 192 | |
193 | - foreach ( $plugins as $slug => $plugin ) { |
|
194 | - $this->plugin_list[ $slug ] = array( |
|
193 | + foreach ($plugins as $slug => $plugin) { |
|
194 | + $this->plugin_list[$slug] = array( |
|
195 | 195 | 'slug' => $slug, |
196 | 196 | 'name' => $plugin['Name'], |
197 | 197 | 'version' => $plugin['Version'], |
198 | - 'active' => is_plugin_active( $slug ) |
|
198 | + 'active' => is_plugin_active($slug) |
|
199 | 199 | ); |
200 | 200 | } |
201 | 201 | |
@@ -210,14 +210,14 @@ discard block |
||
210 | 210 | * @return array An array of themes that are currently installed. |
211 | 211 | */ |
212 | 212 | public function get_themes_list() { |
213 | - if ( ! empty( $this->theme_list ) ) { |
|
213 | + if ( ! empty($this->theme_list)) { |
|
214 | 214 | return $this->theme_list; |
215 | 215 | } |
216 | 216 | |
217 | 217 | $themes = wp_get_themes(); |
218 | 218 | |
219 | - foreach ( $themes as $slug => $theme ) { |
|
220 | - $this->theme_list[ $slug ] = array( |
|
219 | + foreach ($themes as $slug => $theme) { |
|
220 | + $this->theme_list[$slug] = array( |
|
221 | 221 | 'slug' => $slug, |
222 | 222 | 'name' => $theme->Name, |
223 | 223 | 'version' => $theme->Version, |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | */ |
236 | 236 | public function display_notifications() { |
237 | 237 | |
238 | - if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) { |
|
238 | + if ( ! current_user_can(apply_filters('am_notifications_display', 'manage_options'))) { |
|
239 | 239 | return; |
240 | 240 | } |
241 | 241 | |
@@ -245,12 +245,12 @@ discard block |
||
245 | 245 | 'meta_value' => '0' |
246 | 246 | ) ); |
247 | 247 | |
248 | - $plugin_notifications = $this->validate_notifications( $plugin_notifications ); |
|
248 | + $plugin_notifications = $this->validate_notifications($plugin_notifications); |
|
249 | 249 | |
250 | - if ( ! empty( $plugin_notifications ) ) { |
|
251 | - foreach ( $plugin_notifications as $notification ) { |
|
252 | - $dismissable = get_post_meta( $notification->ID, 'dismissable', true ); |
|
253 | - $type = get_post_meta( $notification->ID, 'type', true ); |
|
250 | + if ( ! empty($plugin_notifications)) { |
|
251 | + foreach ($plugin_notifications as $notification) { |
|
252 | + $dismissable = get_post_meta($notification->ID, 'dismissable', true); |
|
253 | + $type = get_post_meta($notification->ID, 'type', true); |
|
254 | 254 | ?> |
255 | 255 | <div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>"> |
256 | 256 | <?php echo $notification->post_content; ?> |
@@ -277,59 +277,59 @@ discard block |
||
277 | 277 | * @param array $plugin_notifications An array of plugin notifications. |
278 | 278 | * @return array A filtered array of plugin notifications. |
279 | 279 | */ |
280 | - public function validate_notifications( $plugin_notifications ) { |
|
280 | + public function validate_notifications($plugin_notifications) { |
|
281 | 281 | global $pagenow; |
282 | - foreach ( $plugin_notifications as $key => $notification ) { |
|
282 | + foreach ($plugin_notifications as $key => $notification) { |
|
283 | 283 | // Location validation. |
284 | - $location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) ); |
|
284 | + $location = (array) json_decode(get_post_meta($notification->ID, 'location', true)); |
|
285 | 285 | $continue = false; |
286 | - if ( ! in_array( 'everywhere', $location ) ) { |
|
287 | - if ( in_array( 'index.php', $location ) && 'index.php' == $pagenow ) { |
|
286 | + if ( ! in_array('everywhere', $location)) { |
|
287 | + if (in_array('index.php', $location) && 'index.php' == $pagenow) { |
|
288 | 288 | $continue = true; |
289 | 289 | } |
290 | 290 | |
291 | - if ( in_array( 'plugins.php', $location ) && 'plugins.php' == $pagenow ) { |
|
291 | + if (in_array('plugins.php', $location) && 'plugins.php' == $pagenow) { |
|
292 | 292 | $continue = true; |
293 | 293 | } |
294 | 294 | |
295 | - if ( ! $continue ) { |
|
296 | - unset( $plugin_notifications[ $key ] ); |
|
295 | + if ( ! $continue) { |
|
296 | + unset($plugin_notifications[$key]); |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
300 | 300 | // Plugin validation (OR conditional) |
301 | - $plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) ); |
|
301 | + $plugins = (array) json_decode(get_post_meta($notification->ID, 'plugins', true)); |
|
302 | 302 | $continue = false; |
303 | - if ( ! empty( $plugins ) ) { |
|
304 | - foreach ( $plugins as $plugin ) { |
|
305 | - if ( is_plugin_active( $plugin ) ) { |
|
303 | + if ( ! empty($plugins)) { |
|
304 | + foreach ($plugins as $plugin) { |
|
305 | + if (is_plugin_active($plugin)) { |
|
306 | 306 | $continue = true; |
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | - if ( ! $continue ) { |
|
311 | - unset( $plugin_notifications[ $key ] ); |
|
310 | + if ( ! $continue) { |
|
311 | + unset($plugin_notifications[$key]); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | |
315 | 315 | // Theme validation. |
316 | - $theme = get_post_meta( $notification->ID, 'theme', true ); |
|
316 | + $theme = get_post_meta($notification->ID, 'theme', true); |
|
317 | 317 | $continue = (string) wp_get_theme() == $theme; |
318 | 318 | |
319 | - if ( ! empty( $theme ) && ! $continue ) { |
|
320 | - unset( $plugin_notifications[ $key ] ); |
|
319 | + if ( ! empty($theme) && ! $continue) { |
|
320 | + unset($plugin_notifications[$key]); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | // Version validation. |
324 | - $version = get_post_meta( $notification->ID, 'version', true ); |
|
324 | + $version = get_post_meta($notification->ID, 'version', true); |
|
325 | 325 | $continue = false; |
326 | - if ( ! empty( $version ) ) { |
|
327 | - if ( version_compare( $this->plugin_version, $version, '<=' ) ) { |
|
326 | + if ( ! empty($version)) { |
|
327 | + if (version_compare($this->plugin_version, $version, '<=')) { |
|
328 | 328 | $continue = true; |
329 | 329 | } |
330 | 330 | |
331 | - if ( ! $continue ) { |
|
332 | - unset( $plugin_notifications[ $key ] ); |
|
331 | + if ( ! $continue) { |
|
332 | + unset($plugin_notifications[$key]); |
|
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
@@ -344,8 +344,8 @@ discard block |
||
344 | 344 | * @since 1.0.0 |
345 | 345 | */ |
346 | 346 | public function dismiss_notification() { |
347 | - $notification_id = intval( $_POST['notification_id'] ); |
|
348 | - update_post_meta( $notification_id, 'viewed', 1 ); |
|
347 | + $notification_id = intval($_POST['notification_id']); |
|
348 | + update_post_meta($notification_id, 'viewed', 1); |
|
349 | 349 | die; |
350 | 350 | } |
351 | 351 |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | //Nothing to see here |
3 | 3 | |
4 | -header( 'HTTP/1.0 403 Forbidden' ); |
|
5 | 4 | \ No newline at end of file |
5 | +header('HTTP/1.0 403 Forbidden'); |
|
6 | 6 | \ No newline at end of file |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | //Nothing to see here |
3 | 3 | |
4 | -header( 'HTTP/1.0 403 Forbidden' ); |
|
5 | 4 | \ No newline at end of file |
5 | +header('HTTP/1.0 403 Forbidden'); |
|
6 | 6 | \ No newline at end of file |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | //Nothing to see here |
3 | 3 | |
4 | -header( 'HTTP/1.0 403 Forbidden' ); |
|
5 | 4 | \ No newline at end of file |
5 | +header('HTTP/1.0 403 Forbidden'); |
|
6 | 6 | \ No newline at end of file |