Version Description
Download this release
Release Info
Developer | wpautoterms |
Plugin | Auto Terms of Service and Privacy Policy |
Version | 2.1.7 |
Comparing to | |
See all releases |
Code changes from version 2.1.6 to 2.1.7
- README.txt +5 -1
- auto-terms-of-service-privacy-policy.php +1 -1
- includes/admin/admin.php +1 -3
- includes/admin/menu.php +1 -1
- includes/api/agreement.php +4 -4
- includes/api/license.php +1 -1
- includes/api/query.php +17 -33
- includes/api/response.php +25 -32
- includes/countries.php +3 -3
- includes/cpt/cpt.php +17 -37
- includes/upgrade.php +2 -0
- includes/util.php +0 -16
README.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: gdpr, privacy policy, terms and conditions, terms of service, terms of use
|
|
4 |
Requires at least: 4.2
|
5 |
Tested up to: 4.9.7
|
6 |
Requires PHP: 5.3
|
7 |
-
Stable tag: 2.1.
|
8 |
License: GPL version 3 or any later version
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -113,6 +113,10 @@ Installing the plugin is easy. Just follow these steps:
|
|
113 |
|
114 |
== Changelog ==
|
115 |
|
|
|
|
|
|
|
|
|
116 |
= Version 2.1.6 =
|
117 |
* Aug 26, 2018
|
118 |
* Bugfix for headers already sent in admin pages
|
4 |
Requires at least: 4.2
|
5 |
Tested up to: 4.9.7
|
6 |
Requires PHP: 5.3
|
7 |
+
Stable tag: 2.1.7
|
8 |
License: GPL version 3 or any later version
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
113 |
|
114 |
== Changelog ==
|
115 |
|
116 |
+
= Version 2.1.7 =
|
117 |
+
* Sep 3, 2018
|
118 |
+
* Bugfix for user roles capabilities
|
119 |
+
|
120 |
= Version 2.1.6 =
|
121 |
* Aug 26, 2018
|
122 |
* Bugfix for headers already sent in admin pages
|
auto-terms-of-service-privacy-policy.php
CHANGED
@@ -5,7 +5,7 @@ Plugin URI: https://wpautoterms.com
|
|
5 |
Description: Create Privacy Policy (Simple or GDPR), Terms & Conditions, Disclaimers and more. Compliance Kits to help you be compliant with the law.
|
6 |
Author: WP AutoTerms
|
7 |
Author URI: https://wpautoterms.com
|
8 |
-
Version: 2.1.
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: wpautoterms
|
11 |
Domain Path: /languages
|
5 |
Description: Create Privacy Policy (Simple or GDPR), Terms & Conditions, Disclaimers and more. Compliance Kits to help you be compliant with the law.
|
6 |
Author: WP AutoTerms
|
7 |
Author URI: https://wpautoterms.com
|
8 |
+
Version: 2.1.7
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: wpautoterms
|
11 |
Domain Path: /languages
|
includes/admin/admin.php
CHANGED
@@ -18,7 +18,6 @@ use wpautoterms\Wpautoterms;
|
|
18 |
|
19 |
define( 'WPAUTOTERMS_API_KEY_HEADER', 'X-WpAutoTerms-ApiKey' );
|
20 |
|
21 |
-
// TODO: refactor, extract classes with less responsibilities
|
22 |
abstract class Admin {
|
23 |
/**
|
24 |
* @var License
|
@@ -41,7 +40,6 @@ abstract class Admin {
|
|
41 |
new Upgrade();
|
42 |
}
|
43 |
|
44 |
-
|
45 |
public static function action_init() {
|
46 |
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
|
47 |
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
|
@@ -60,7 +58,7 @@ abstract class Admin {
|
|
60 |
static::$_warning_action->set_option_name( 'settings_warning_disable' );
|
61 |
|
62 |
Admin_Columns::init();
|
63 |
-
Menu::init( static::$_license
|
64 |
static::$_license->check();
|
65 |
}
|
66 |
|
18 |
|
19 |
define( 'WPAUTOTERMS_API_KEY_HEADER', 'X-WpAutoTerms-ApiKey' );
|
20 |
|
|
|
21 |
abstract class Admin {
|
22 |
/**
|
23 |
* @var License
|
40 |
new Upgrade();
|
41 |
}
|
42 |
|
|
|
43 |
public static function action_init() {
|
44 |
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
|
45 |
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) );
|
58 |
static::$_warning_action->set_option_name( 'settings_warning_disable' );
|
59 |
|
60 |
Admin_Columns::init();
|
61 |
+
Menu::init( static::$_license );
|
62 |
static::$_license->check();
|
63 |
}
|
64 |
|
includes/admin/menu.php
CHANGED
@@ -52,7 +52,7 @@ abstract class Menu {
|
|
52 |
);
|
53 |
}
|
54 |
|
55 |
-
public static function init( api\License $license
|
56 |
$ls = new License_Settings( static::PAGE_LICENSE_SETTINGS, __( 'License Settings', WPAUTOTERMS_SLUG ),
|
57 |
__( 'License', WPAUTOTERMS_SLUG ) );
|
58 |
$ls->set_license( $license );
|
52 |
);
|
53 |
}
|
54 |
|
55 |
+
public static function init( api\License $license ) {
|
56 |
$ls = new License_Settings( static::PAGE_LICENSE_SETTINGS, __( 'License Settings', WPAUTOTERMS_SLUG ),
|
57 |
__( 'License', WPAUTOTERMS_SLUG ) );
|
58 |
$ls->set_license( $license );
|
includes/api/agreement.php
CHANGED
@@ -21,7 +21,7 @@ class Agreement {
|
|
21 |
protected $_license;
|
22 |
|
23 |
const _EP_AGREEMENT = 'agreement/v1/text/';
|
24 |
-
const _EP_WIZARD = 'agreement/v1/wizard
|
25 |
|
26 |
const _RESP_TEXT = 'html';
|
27 |
|
@@ -73,7 +73,7 @@ class Agreement {
|
|
73 |
$args['country'] = Options::get_option( Options::COUNTRY );
|
74 |
$args['state'] = Options::get_option( Options::STATE );
|
75 |
}
|
76 |
-
$headers = array( WPAUTOTERMS_API_KEY_HEADER
|
77 |
$resp = $this->_query->post_json( static::_EP_AGREEMENT . $agreement_id . '/', $args, $headers );
|
78 |
$json = $resp->json();
|
79 |
if ( ! $resp->has_error() && isset( $json[ static::_RESP_TEXT ] ) ) {
|
@@ -95,14 +95,14 @@ class Agreement {
|
|
95 |
$params[ $k ] = $v;
|
96 |
}
|
97 |
}
|
98 |
-
$headers = array( WPAUTOTERMS_API_KEY_HEADER
|
99 |
$data = array(
|
100 |
'name' => $agreement_id,
|
101 |
'country' => Options::get_option( Options::COUNTRY ),
|
102 |
'state' => Options::get_option( Options::STATE ),
|
103 |
'lang' => 'en',
|
104 |
);
|
105 |
-
$resp = $this->_query->get(
|
106 |
$json = $resp->json();
|
107 |
if ( ! $resp->has_error() && isset( $json[ static::_RESP_TEXT ] ) ) {
|
108 |
return $json[ static::_RESP_TEXT ];
|
21 |
protected $_license;
|
22 |
|
23 |
const _EP_AGREEMENT = 'agreement/v1/text/';
|
24 |
+
const _EP_WIZARD = 'agreement/v1/wizard/%s/%s';
|
25 |
|
26 |
const _RESP_TEXT = 'html';
|
27 |
|
73 |
$args['country'] = Options::get_option( Options::COUNTRY );
|
74 |
$args['state'] = Options::get_option( Options::STATE );
|
75 |
}
|
76 |
+
$headers = array( WPAUTOTERMS_API_KEY_HEADER => $this->_license->api_key() );
|
77 |
$resp = $this->_query->post_json( static::_EP_AGREEMENT . $agreement_id . '/', $args, $headers );
|
78 |
$json = $resp->json();
|
79 |
if ( ! $resp->has_error() && isset( $json[ static::_RESP_TEXT ] ) ) {
|
95 |
$params[ $k ] = $v;
|
96 |
}
|
97 |
}
|
98 |
+
$headers = array( WPAUTOTERMS_API_KEY_HEADER => $this->_license->api_key() );
|
99 |
$data = array(
|
100 |
'name' => $agreement_id,
|
101 |
'country' => Options::get_option( Options::COUNTRY ),
|
102 |
'state' => Options::get_option( Options::STATE ),
|
103 |
'lang' => 'en',
|
104 |
);
|
105 |
+
$resp = $this->_query->get( sprintf( static::_EP_WIZARD, $data['name'], $data['lang'] ), $params, $headers );
|
106 |
$json = $resp->json();
|
107 |
if ( ! $resp->has_error() && isset( $json[ static::_RESP_TEXT ] ) ) {
|
108 |
return $json[ static::_RESP_TEXT ];
|
includes/api/license.php
CHANGED
@@ -63,7 +63,7 @@ class License {
|
|
63 |
if ( empty( $key ) ) {
|
64 |
return;
|
65 |
}
|
66 |
-
$headers = array( WPAUTOTERMS_API_KEY_HEADER
|
67 |
$resp = $this->_query->get( static::_EP_STATUS, array(), $headers );
|
68 |
$json = $resp->json();
|
69 |
if ( ! $resp->has_error() && isset( $json[ static::_RESP_STATUS ] ) &&
|
63 |
if ( empty( $key ) ) {
|
64 |
return;
|
65 |
}
|
66 |
+
$headers = array( WPAUTOTERMS_API_KEY_HEADER => $key );
|
67 |
$resp = $this->_query->get( static::_EP_STATUS, array(), $headers );
|
68 |
$json = $resp->json();
|
69 |
if ( ! $resp->has_error() && isset( $json[ static::_RESP_STATUS ] ) &&
|
includes/api/query.php
CHANGED
@@ -19,22 +19,16 @@ class Query {
|
|
19 |
* @return Response
|
20 |
*/
|
21 |
public function get( $ep, $params = array(), $headers = false ) {
|
22 |
-
$
|
23 |
-
return urlencode( $x ) . '=' . urlencode( $params[ $x ] );
|
24 |
-
}, array_keys( $params ) );
|
25 |
-
$suffix = empty( $params ) ? '' : '?' . join( '&', $params );
|
26 |
-
$url = $this->_base_url . $ep . $suffix;
|
27 |
$all_headers = array(
|
28 |
-
'Referer
|
29 |
-
'X-WP-Locale
|
30 |
);
|
31 |
if ( $headers ) {
|
32 |
$all_headers = array_merge( $headers, $all_headers );
|
33 |
}
|
34 |
-
$curl = curl_init( $url );
|
35 |
-
curl_setopt( $curl, CURLOPT_HTTPHEADER, $all_headers );
|
36 |
|
37 |
-
return $this->_exec( $
|
38 |
}
|
39 |
|
40 |
/**
|
@@ -47,37 +41,27 @@ class Query {
|
|
47 |
public function post_json( $ep, $params, $headers = false ) {
|
48 |
$data = json_encode( $params );
|
49 |
$url = $this->_base_url . $ep;
|
50 |
-
$curl = curl_init( $url );
|
51 |
$all_headers = array(
|
52 |
-
'Content-Type
|
53 |
-
'Content-Length
|
54 |
-
'Referer
|
55 |
-
'X-WP-Locale
|
56 |
);
|
57 |
if ( $headers ) {
|
58 |
$all_headers = array_merge( $headers, $all_headers );
|
59 |
}
|
60 |
-
curl_setopt( $curl, CURLOPT_POST, true );
|
61 |
-
curl_setopt( $curl, CURLOPT_POSTFIELDS, $data );
|
62 |
-
curl_setopt( $curl, CURLOPT_HTTPHEADER, $all_headers );
|
63 |
|
64 |
-
return $this->_exec( $
|
|
|
|
|
|
|
65 |
}
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
protected function _exec( $curl ) {
|
73 |
-
$vs = null;
|
74 |
-
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
75 |
-
curl_setopt( $curl, CURLOPT_HEADER, false );
|
76 |
-
$resp = new Response( $curl, $this->_verbose );
|
77 |
-
$resp->response = curl_exec( $curl );
|
78 |
-
$resp->_done();
|
79 |
-
curl_close( $curl );
|
80 |
|
81 |
-
return $resp;
|
82 |
}
|
83 |
}
|
19 |
* @return Response
|
20 |
*/
|
21 |
public function get( $ep, $params = array(), $headers = false ) {
|
22 |
+
$url = $this->_base_url . $ep;
|
|
|
|
|
|
|
|
|
23 |
$all_headers = array(
|
24 |
+
'Referer' => get_site_url(),
|
25 |
+
'X-WP-Locale' => get_locale()
|
26 |
);
|
27 |
if ( $headers ) {
|
28 |
$all_headers = array_merge( $headers, $all_headers );
|
29 |
}
|
|
|
|
|
30 |
|
31 |
+
return $this->_exec( wp_remote_get( $url, array( 'headers' => $all_headers, 'body' => $params ) ), $url );
|
32 |
}
|
33 |
|
34 |
/**
|
41 |
public function post_json( $ep, $params, $headers = false ) {
|
42 |
$data = json_encode( $params );
|
43 |
$url = $this->_base_url . $ep;
|
|
|
44 |
$all_headers = array(
|
45 |
+
'Content-Type' => 'application/json',
|
46 |
+
'Content-Length' => strlen( $data ),
|
47 |
+
'Referer' => get_site_url(),
|
48 |
+
'X-WP-Locale' => get_locale()
|
49 |
);
|
50 |
if ( $headers ) {
|
51 |
$all_headers = array_merge( $headers, $all_headers );
|
52 |
}
|
|
|
|
|
|
|
53 |
|
54 |
+
return $this->_exec( wp_remote_post( $url, array(
|
55 |
+
'headers' => $all_headers,
|
56 |
+
'body' => $data
|
57 |
+
) ), $url );
|
58 |
}
|
59 |
|
60 |
+
protected function _exec( $resp, $url ) {
|
61 |
+
$ret = new Response( $resp, $url, $this->_verbose );
|
62 |
+
$ret->_done();
|
63 |
+
|
64 |
+
return $ret;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
|
|
66 |
}
|
67 |
}
|
includes/api/response.php
CHANGED
@@ -6,57 +6,50 @@ class Response {
|
|
6 |
const HTTP_OK = 200;
|
7 |
const HTTP_LIMIT = 429;
|
8 |
|
9 |
-
const HEADER_RETRY_AFTER = 'retry-after
|
10 |
|
11 |
const MESSAGE_KEY = 'message';
|
12 |
|
13 |
public $code;
|
14 |
-
public $response;
|
15 |
public $error;
|
16 |
public $error_info = '';
|
17 |
public $url;
|
18 |
public $delay;
|
19 |
-
|
|
|
|
|
|
|
20 |
protected $_verbose;
|
21 |
protected $_vs;
|
22 |
public $headers = array();
|
23 |
protected $_json;
|
24 |
|
25 |
-
public function __construct( $
|
26 |
-
$this->
|
27 |
$this->_verbose = $verbose;
|
28 |
-
|
29 |
-
if ( $this->_verbose ) {
|
30 |
-
curl_setopt( $this->_curl, CURLOPT_VERBOSE, true );
|
31 |
-
$this->_vs = fopen( 'php://temp', 'w+' );
|
32 |
-
curl_setopt( $this->_curl, CURLOPT_STDERR, $this->_vs );
|
33 |
-
}
|
34 |
-
$this->url = curl_getinfo( $this->_curl, CURLINFO_EFFECTIVE_URL );
|
35 |
-
}
|
36 |
-
|
37 |
-
public function _handle_header( $curl, $header ) {
|
38 |
-
$this->headers[] = $header;
|
39 |
-
$l = strlen( static::HEADER_RETRY_AFTER );
|
40 |
-
if ( 0 == strncasecmp( $header, static::HEADER_RETRY_AFTER, $l ) ) {
|
41 |
-
$this->delay = intval( substr( $header, $l ) );
|
42 |
-
}
|
43 |
-
|
44 |
-
return strlen( $header );
|
45 |
}
|
46 |
|
47 |
public function _done() {
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
$this->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
}
|
57 |
|
58 |
public function has_error() {
|
59 |
-
return
|
60 |
}
|
61 |
|
62 |
/**
|
@@ -67,7 +60,7 @@ class Response {
|
|
67 |
return array();
|
68 |
}
|
69 |
if ( $this->_json === null ) {
|
70 |
-
$this->_json = json_decode( $this->
|
71 |
}
|
72 |
|
73 |
return $this->_json;
|
@@ -81,7 +74,7 @@ class Response {
|
|
81 |
if ( $json !== null && isset( $json[ static::MESSAGE_KEY ] ) ) {
|
82 |
$error = $json[ static::MESSAGE_KEY ];
|
83 |
} else {
|
84 |
-
if ( $this->code ==
|
85 |
$error = __( 'Too much requests. Please, wait.', WPAUTOTERMS_SLUG );
|
86 |
} else {
|
87 |
$error = sprintf( __( 'Server response code: %s', WPAUTOTERMS_SLUG ), $this->code );
|
6 |
const HTTP_OK = 200;
|
7 |
const HTTP_LIMIT = 429;
|
8 |
|
9 |
+
const HEADER_RETRY_AFTER = 'retry-after';
|
10 |
|
11 |
const MESSAGE_KEY = 'message';
|
12 |
|
13 |
public $code;
|
|
|
14 |
public $error;
|
15 |
public $error_info = '';
|
16 |
public $url;
|
17 |
public $delay;
|
18 |
+
/**
|
19 |
+
* @var array|\WP_Error
|
20 |
+
*/
|
21 |
+
protected $_response;
|
22 |
protected $_verbose;
|
23 |
protected $_vs;
|
24 |
public $headers = array();
|
25 |
protected $_json;
|
26 |
|
27 |
+
public function __construct( $response, $url, $verbose = false ) {
|
28 |
+
$this->_response = $response;
|
29 |
$this->_verbose = $verbose;
|
30 |
+
$this->url = $url;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
32 |
|
33 |
public function _done() {
|
34 |
+
if ( $this->has_error() ) {
|
35 |
+
$this->code = __( 'unknown', WPAUTOTERMS_SLUG );
|
36 |
+
$this->error = join( '; ', $this->_response->get_error_codes() );
|
37 |
+
$this->error_info = join( '; ', $this->_response->get_error_messages() );
|
38 |
+
} else {
|
39 |
+
$this->code = $this->_response['response']['code'];
|
40 |
+
$this->error = $this->_response['response']['code'];
|
41 |
+
$this->error_info = $this->_response['response']['message'];
|
42 |
+
if ( $this->code == \WP_Http::TOO_MANY_REQUESTS ) {
|
43 |
+
$retry = $this->_response['http_response']->get_response_object()->headers->getValues( static::HEADER_RETRY_AFTER );
|
44 |
+
if ( ! empty( $retry ) ) {
|
45 |
+
$this->delay = intval( $retry );
|
46 |
+
}
|
47 |
+
}
|
48 |
}
|
49 |
}
|
50 |
|
51 |
public function has_error() {
|
52 |
+
return is_wp_error( $this->_response );
|
53 |
}
|
54 |
|
55 |
/**
|
60 |
return array();
|
61 |
}
|
62 |
if ( $this->_json === null ) {
|
63 |
+
$this->_json = json_decode( $this->_response['body'], true );
|
64 |
}
|
65 |
|
66 |
return $this->_json;
|
74 |
if ( $json !== null && isset( $json[ static::MESSAGE_KEY ] ) ) {
|
75 |
$error = $json[ static::MESSAGE_KEY ];
|
76 |
} else {
|
77 |
+
if ( $this->code == \WP_Http::TOO_MANY_REQUESTS ) {
|
78 |
$error = __( 'Too much requests. Please, wait.', WPAUTOTERMS_SLUG );
|
79 |
} else {
|
80 |
$error = sprintf( __( 'Server response code: %s', WPAUTOTERMS_SLUG ), $this->code );
|
includes/countries.php
CHANGED
@@ -7,8 +7,8 @@ use wpautoterms\admin\Options;
|
|
7 |
include_once WPAUTOTERMS_PLUGIN_DIR . 'data/countries.php';
|
8 |
|
9 |
abstract class Countries {
|
10 |
-
const LOCALE_PATH = 'js/data/translations/
|
11 |
-
const LOCALE_PATH_PHP = 'data/translations/
|
12 |
|
13 |
const DEFAULT_LOCALE = 'en';
|
14 |
|
@@ -27,7 +27,7 @@ abstract class Countries {
|
|
27 |
}
|
28 |
$template = WPAUTOTERMS_PLUGIN_DIR . $template;
|
29 |
$files = array_map( function ( $x ) use ( $template ) {
|
30 |
-
return
|
31 |
}, $locales );
|
32 |
|
33 |
$file = Util::first_existing( $files );
|
7 |
include_once WPAUTOTERMS_PLUGIN_DIR . 'data/countries.php';
|
8 |
|
9 |
abstract class Countries {
|
10 |
+
const LOCALE_PATH = 'js/data/translations/%s/strings.js';
|
11 |
+
const LOCALE_PATH_PHP = 'data/translations/%s/countries.php';
|
12 |
|
13 |
const DEFAULT_LOCALE = 'en';
|
14 |
|
27 |
}
|
28 |
$template = WPAUTOTERMS_PLUGIN_DIR . $template;
|
29 |
$files = array_map( function ( $x ) use ( $template ) {
|
30 |
+
return sprintf( $template, $x );
|
31 |
}, $locales );
|
32 |
|
33 |
$file = Util::first_existing( $files );
|
includes/cpt/cpt.php
CHANGED
@@ -15,8 +15,12 @@ define( 'WPAUTOTERMS_CAP_PLURAL', WPAUTOTERMS_SLUG . '_pages' );
|
|
15 |
abstract class CPT {
|
16 |
|
17 |
static function init() {
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
add_filter( 'theme_' . WPAUTOTERMS_CPT . '_templates', array( __CLASS__, 'filter_templates' ), 10, 2 );
|
21 |
}
|
22 |
|
@@ -96,50 +100,26 @@ abstract class CPT {
|
|
96 |
}
|
97 |
|
98 |
static function add_caps() {
|
99 |
-
|
100 |
-
global $wp_roles;
|
101 |
-
if ( ! isset( $wp_roles ) ) {
|
102 |
-
$wp_roles = new \WP_Roles;
|
103 |
-
}
|
104 |
|
105 |
$default_caps = static::get_default_caps();
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
110 |
} else {
|
111 |
$caps = $default_caps['subscriber'];
|
112 |
}
|
113 |
-
|
114 |
foreach ( $caps as $cap => $grant ) {
|
115 |
-
|
116 |
-
|
117 |
-
$wp_roles->add_cap( $role, $cap, $grant );
|
118 |
}
|
119 |
-
|
120 |
-
}
|
121 |
-
}
|
122 |
-
}
|
123 |
-
|
124 |
-
static function map_meta_cap( $caps, $cap, $userID, $args = null ) {
|
125 |
-
|
126 |
-
$cpt = get_post_type_object( WPAUTOTERMS_CPT );
|
127 |
-
if ( ! $cpt ) {
|
128 |
-
return $caps;
|
129 |
-
}
|
130 |
-
|
131 |
-
/*
|
132 |
-
switch ( $cap ) {
|
133 |
-
case 'edit_' . static::CAP_SINGULAR:
|
134 |
-
if ( false ) { // deny condition
|
135 |
-
$caps[] = 'do_not_allow';
|
136 |
}
|
137 |
-
break;
|
138 |
}
|
139 |
-
*/
|
140 |
-
|
141 |
-
return $caps;
|
142 |
-
|
143 |
}
|
144 |
|
145 |
/**
|
15 |
abstract class CPT {
|
16 |
|
17 |
static function init() {
|
18 |
+
$wp_roles = wp_roles();
|
19 |
+
if ( ! $wp_roles->use_db ) {
|
20 |
+
add_action( 'init', array( __CLASS__, 'add_caps' ), 0 );
|
21 |
+
} else {
|
22 |
+
add_action( 'update_option_' . $wp_roles->role_key, array( __CLASS__, 'add_caps' ) );
|
23 |
+
}
|
24 |
add_filter( 'theme_' . WPAUTOTERMS_CPT . '_templates', array( __CLASS__, 'filter_templates' ), 10, 2 );
|
25 |
}
|
26 |
|
100 |
}
|
101 |
|
102 |
static function add_caps() {
|
103 |
+
$wp_roles = wp_roles();
|
|
|
|
|
|
|
|
|
104 |
|
105 |
$default_caps = static::get_default_caps();
|
106 |
+
/**
|
107 |
+
* @var $role \WP_Role
|
108 |
+
*/
|
109 |
+
foreach ( $wp_roles->role_objects as $role ) {
|
110 |
+
$role_name = $role->name;
|
111 |
+
if ( array_key_exists( $role_name, $default_caps ) ) {
|
112 |
+
$caps = $default_caps[ $role_name ];
|
113 |
} else {
|
114 |
$caps = $default_caps['subscriber'];
|
115 |
}
|
116 |
+
$mo = $role->has_cap( 'manage_options' );
|
117 |
foreach ( $caps as $cap => $grant ) {
|
118 |
+
if ( ! isset( $wp_roles->roles[ $role_name ]['capabilities'][ $cap ] ) ) {
|
119 |
+
$wp_roles->add_cap( $role_name, $cap, $grant || $mo );
|
|
|
120 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
|
|
|
|
|
|
123 |
}
|
124 |
|
125 |
/**
|
includes/upgrade.php
CHANGED
@@ -6,6 +6,7 @@ use wpautoterms\admin\Menu;
|
|
6 |
use wpautoterms\admin\Options;
|
7 |
use wpautoterms\admin\page\Legacy_Settings;
|
8 |
use wpautoterms\admin\page\Settings_Base;
|
|
|
9 |
|
10 |
class Upgrade {
|
11 |
public function __construct() {
|
@@ -28,6 +29,7 @@ class Upgrade {
|
|
28 |
}
|
29 |
}
|
30 |
flush_rewrite_rules();
|
|
|
31 |
update_option( WPAUTOTERMS_OPTION_PREFIX . WPAUTOTERMS_OPTION_ACTIVATED, true );
|
32 |
}
|
33 |
$version = get_option( WPAUTOTERMS_OPTION_PREFIX . Menu::VERSION );
|
6 |
use wpautoterms\admin\Options;
|
7 |
use wpautoterms\admin\page\Legacy_Settings;
|
8 |
use wpautoterms\admin\page\Settings_Base;
|
9 |
+
use wpautoterms\cpt\CPT;
|
10 |
|
11 |
class Upgrade {
|
12 |
public function __construct() {
|
29 |
}
|
30 |
}
|
31 |
flush_rewrite_rules();
|
32 |
+
CPT::add_caps();
|
33 |
update_option( WPAUTOTERMS_OPTION_PREFIX . WPAUTOTERMS_OPTION_ACTIVATED, true );
|
34 |
}
|
35 |
$version = get_option( WPAUTOTERMS_OPTION_PREFIX . Menu::VERSION );
|
includes/util.php
CHANGED
@@ -3,22 +3,6 @@
|
|
3 |
namespace wpautoterms;
|
4 |
|
5 |
abstract class Util {
|
6 |
-
/**
|
7 |
-
* @param $template string - format string with named arguments, e.g. '{arg1} some text {arg2}, again {arg1}, {{preserve braces}}'
|
8 |
-
* @param $args - associative array of arguments
|
9 |
-
*
|
10 |
-
* @return string
|
11 |
-
*/
|
12 |
-
public static function format( $template, $args ) {
|
13 |
-
$ret = explode( '{{', $template );
|
14 |
-
foreach ( $args as $k => $v ) {
|
15 |
-
$ret = array_map( function ( $x ) use ( $k, $v ) {
|
16 |
-
return str_replace( '{' . $k . '}', $v, $x );
|
17 |
-
}, $ret );
|
18 |
-
}
|
19 |
-
|
20 |
-
return str_replace( '}}', '}', implode( '{', $ret ) );
|
21 |
-
}
|
22 |
|
23 |
public static function first_existing( $files ) {
|
24 |
foreach ( $files as $file ) {
|
3 |
namespace wpautoterms;
|
4 |
|
5 |
abstract class Util {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
public static function first_existing( $files ) {
|
8 |
foreach ( $files as $file ) {
|