@@ -18,53 +18,53 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Post_Meta_Uri_Storage extends Wordlift_Post_Meta_Storage { |
20 | 20 | |
21 | - /** |
|
22 | - * The {@link Wordlift_Entity_Service} instance. |
|
23 | - * |
|
24 | - * @since 3.15.0 |
|
25 | - * @access private |
|
26 | - * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
27 | - */ |
|
28 | - private $entity_service; |
|
21 | + /** |
|
22 | + * The {@link Wordlift_Entity_Service} instance. |
|
23 | + * |
|
24 | + * @since 3.15.0 |
|
25 | + * @access private |
|
26 | + * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
27 | + */ |
|
28 | + private $entity_service; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Create a {@link Wordlift_Post_Meta_Uri_Storage} instance. |
|
32 | - * |
|
33 | - * @since 3.15.0 |
|
34 | - * |
|
35 | - * @param string $meta_key The meta key to read data from. |
|
36 | - * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
37 | - */ |
|
38 | - public function __construct( $meta_key, $entity_service ) { |
|
39 | - parent::__construct( $meta_key ); |
|
30 | + /** |
|
31 | + * Create a {@link Wordlift_Post_Meta_Uri_Storage} instance. |
|
32 | + * |
|
33 | + * @since 3.15.0 |
|
34 | + * |
|
35 | + * @param string $meta_key The meta key to read data from. |
|
36 | + * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
37 | + */ |
|
38 | + public function __construct( $meta_key, $entity_service ) { |
|
39 | + parent::__construct( $meta_key ); |
|
40 | 40 | |
41 | - $this->entity_service = $entity_service; |
|
41 | + $this->entity_service = $entity_service; |
|
42 | 42 | |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get the value for the specified meta key. |
|
47 | - * |
|
48 | - * The value is expected to be an entity post, for which the URI is loaded |
|
49 | - * and returned. |
|
50 | - * |
|
51 | - * @since 3.15.0 |
|
52 | - * |
|
53 | - * @param int $post_id The {@link WP_Post}'s id. |
|
54 | - * |
|
55 | - * @return array An array of URIs (or an empty array if nothing is set). |
|
56 | - */ |
|
57 | - public function get( $post_id ) { |
|
58 | - $values = parent::get( $post_id ); |
|
45 | + /** |
|
46 | + * Get the value for the specified meta key. |
|
47 | + * |
|
48 | + * The value is expected to be an entity post, for which the URI is loaded |
|
49 | + * and returned. |
|
50 | + * |
|
51 | + * @since 3.15.0 |
|
52 | + * |
|
53 | + * @param int $post_id The {@link WP_Post}'s id. |
|
54 | + * |
|
55 | + * @return array An array of URIs (or an empty array if nothing is set). |
|
56 | + */ |
|
57 | + public function get( $post_id ) { |
|
58 | + $values = parent::get( $post_id ); |
|
59 | 59 | |
60 | - $entity_service = $this->entity_service; |
|
60 | + $entity_service = $this->entity_service; |
|
61 | 61 | |
62 | - return array_map( |
|
63 | - function ( $item ) use ( $entity_service ) { |
|
64 | - return $entity_service->get_uri( $item ); |
|
65 | - }, |
|
66 | - $values |
|
67 | - ); |
|
68 | - } |
|
62 | + return array_map( |
|
63 | + function ( $item ) use ( $entity_service ) { |
|
64 | + return $entity_service->get_uri( $item ); |
|
65 | + }, |
|
66 | + $values |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * @param string $meta_key The meta key to read data from. |
36 | 36 | * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
37 | 37 | */ |
38 | - public function __construct( $meta_key, $entity_service ) { |
|
39 | - parent::__construct( $meta_key ); |
|
38 | + public function __construct($meta_key, $entity_service) { |
|
39 | + parent::__construct($meta_key); |
|
40 | 40 | |
41 | 41 | $this->entity_service = $entity_service; |
42 | 42 | |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return array An array of URIs (or an empty array if nothing is set). |
56 | 56 | */ |
57 | - public function get( $post_id ) { |
|
58 | - $values = parent::get( $post_id ); |
|
57 | + public function get($post_id) { |
|
58 | + $values = parent::get($post_id); |
|
59 | 59 | |
60 | 60 | $entity_service = $this->entity_service; |
61 | 61 | |
62 | 62 | return array_map( |
63 | - function ( $item ) use ( $entity_service ) { |
|
64 | - return $entity_service->get_uri( $item ); |
|
63 | + function($item) use ($entity_service) { |
|
64 | + return $entity_service->get_uri($item); |
|
65 | 65 | }, |
66 | 66 | $values |
67 | 67 | ); |
@@ -18,52 +18,52 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Post_Taxonomy_Storage extends Wordlift_Storage { |
20 | 20 | |
21 | - /** |
|
22 | - * The taxonomy name. |
|
23 | - * |
|
24 | - * @since 3.15.0 |
|
25 | - * @access private |
|
26 | - * @var string $taxonomy The taxonomy name. |
|
27 | - */ |
|
28 | - private $taxonomy; |
|
21 | + /** |
|
22 | + * The taxonomy name. |
|
23 | + * |
|
24 | + * @since 3.15.0 |
|
25 | + * @access private |
|
26 | + * @var string $taxonomy The taxonomy name. |
|
27 | + */ |
|
28 | + private $taxonomy; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Create a {@link Wordlift_Post_Taxonomy_Storage} with the specified |
|
32 | - * taxonomy name. |
|
33 | - * |
|
34 | - * @since 3.15.0 |
|
35 | - * |
|
36 | - * @param string $taxonomy The taxonomy name. |
|
37 | - */ |
|
38 | - public function __construct( $taxonomy ) { |
|
30 | + /** |
|
31 | + * Create a {@link Wordlift_Post_Taxonomy_Storage} with the specified |
|
32 | + * taxonomy name. |
|
33 | + * |
|
34 | + * @since 3.15.0 |
|
35 | + * |
|
36 | + * @param string $taxonomy The taxonomy name. |
|
37 | + */ |
|
38 | + public function __construct( $taxonomy ) { |
|
39 | 39 | |
40 | - $this->taxonomy = $taxonomy; |
|
41 | - } |
|
40 | + $this->taxonomy = $taxonomy; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Get the taxonomy's terms associated with the specified {@link WP_Post}. |
|
45 | - * |
|
46 | - * @since 3.15.0 |
|
47 | - * |
|
48 | - * @param int $post_id The {@link WP_Post}'s id. |
|
49 | - * |
|
50 | - * @return array|WP_Error An array of terms or {@link WP_Error} in case of error. |
|
51 | - */ |
|
52 | - public function get( $post_id ) { |
|
43 | + /** |
|
44 | + * Get the taxonomy's terms associated with the specified {@link WP_Post}. |
|
45 | + * |
|
46 | + * @since 3.15.0 |
|
47 | + * |
|
48 | + * @param int $post_id The {@link WP_Post}'s id. |
|
49 | + * |
|
50 | + * @return array|WP_Error An array of terms or {@link WP_Error} in case of error. |
|
51 | + */ |
|
52 | + public function get( $post_id ) { |
|
53 | 53 | |
54 | - return wp_get_post_terms( |
|
55 | - $post_id, |
|
56 | - $this->taxonomy, |
|
57 | - array( |
|
58 | - 'hide_empty' => false, |
|
59 | - // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'. |
|
60 | - // An issue has been opened with the AAM plugin author as well. |
|
61 | - // |
|
62 | - // see https://github.com/insideout10/wordlift-plugin/issues/334 |
|
63 | - // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863 |
|
64 | - 'fields' => 'all', |
|
65 | - ) |
|
66 | - ); |
|
67 | - } |
|
54 | + return wp_get_post_terms( |
|
55 | + $post_id, |
|
56 | + $this->taxonomy, |
|
57 | + array( |
|
58 | + 'hide_empty' => false, |
|
59 | + // Because of #334 (and the AAM plugin) we changed fields from 'id=>slug' to 'all'. |
|
60 | + // An issue has been opened with the AAM plugin author as well. |
|
61 | + // |
|
62 | + // see https://github.com/insideout10/wordlift-plugin/issues/334 |
|
63 | + // see https://wordpress.org/support/topic/idslug-not-working-anymore?replies=1#post-8806863 |
|
64 | + 'fields' => 'all', |
|
65 | + ) |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param string $taxonomy The taxonomy name. |
37 | 37 | */ |
38 | - public function __construct( $taxonomy ) { |
|
38 | + public function __construct($taxonomy) { |
|
39 | 39 | |
40 | 40 | $this->taxonomy = $taxonomy; |
41 | 41 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @return array|WP_Error An array of terms or {@link WP_Error} in case of error. |
51 | 51 | */ |
52 | - public function get( $post_id ) { |
|
52 | + public function get($post_id) { |
|
53 | 53 | |
54 | 54 | return wp_get_post_terms( |
55 | 55 | $post_id, |
@@ -18,37 +18,37 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Post_Schema_Class_Storage extends Wordlift_Storage { |
20 | 20 | |
21 | - /** |
|
22 | - * Get the schema class for the specified {@link WP_Post}. |
|
23 | - * |
|
24 | - * @since 3.15.0 |
|
25 | - * |
|
26 | - * @param int $post_id The {@link WP_Post}'s id. |
|
27 | - * |
|
28 | - * @return string|array An array of schema classes. |
|
29 | - */ |
|
30 | - public function get( $post_id ) { |
|
31 | - |
|
32 | - // Get the type names (CamelCase). |
|
33 | - $names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id ); |
|
34 | - |
|
35 | - // If we don't find any type use the legacy function to get the URI. |
|
36 | - if ( empty( $names ) ) { |
|
37 | - $type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id ); |
|
38 | - |
|
39 | - return $type['uri']; |
|
40 | - } |
|
41 | - |
|
42 | - // Prepend the `schema.org` base URI. |
|
43 | - $uris = array_map( |
|
44 | - function ( $item ) { |
|
45 | - return "http://schema.org/$item"; |
|
46 | - }, |
|
47 | - $names |
|
48 | - ); |
|
49 | - |
|
50 | - // Finally return the schema uri. |
|
51 | - return 1 === count( $uris ) ? $uris[0] : $uris; |
|
52 | - } |
|
21 | + /** |
|
22 | + * Get the schema class for the specified {@link WP_Post}. |
|
23 | + * |
|
24 | + * @since 3.15.0 |
|
25 | + * |
|
26 | + * @param int $post_id The {@link WP_Post}'s id. |
|
27 | + * |
|
28 | + * @return string|array An array of schema classes. |
|
29 | + */ |
|
30 | + public function get( $post_id ) { |
|
31 | + |
|
32 | + // Get the type names (CamelCase). |
|
33 | + $names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id ); |
|
34 | + |
|
35 | + // If we don't find any type use the legacy function to get the URI. |
|
36 | + if ( empty( $names ) ) { |
|
37 | + $type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id ); |
|
38 | + |
|
39 | + return $type['uri']; |
|
40 | + } |
|
41 | + |
|
42 | + // Prepend the `schema.org` base URI. |
|
43 | + $uris = array_map( |
|
44 | + function ( $item ) { |
|
45 | + return "http://schema.org/$item"; |
|
46 | + }, |
|
47 | + $names |
|
48 | + ); |
|
49 | + |
|
50 | + // Finally return the schema uri. |
|
51 | + return 1 === count( $uris ) ? $uris[0] : $uris; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | } |
@@ -27,28 +27,28 @@ |
||
27 | 27 | * |
28 | 28 | * @return string|array An array of schema classes. |
29 | 29 | */ |
30 | - public function get( $post_id ) { |
|
30 | + public function get($post_id) { |
|
31 | 31 | |
32 | 32 | // Get the type names (CamelCase). |
33 | - $names = Wordlift_Entity_Type_Service::get_instance()->get_names( $post_id ); |
|
33 | + $names = Wordlift_Entity_Type_Service::get_instance()->get_names($post_id); |
|
34 | 34 | |
35 | 35 | // If we don't find any type use the legacy function to get the URI. |
36 | - if ( empty( $names ) ) { |
|
37 | - $type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id ); |
|
36 | + if (empty($names)) { |
|
37 | + $type = Wordlift_Entity_Type_Service::get_instance()->get($post_id); |
|
38 | 38 | |
39 | 39 | return $type['uri']; |
40 | 40 | } |
41 | 41 | |
42 | 42 | // Prepend the `schema.org` base URI. |
43 | 43 | $uris = array_map( |
44 | - function ( $item ) { |
|
44 | + function($item) { |
|
45 | 45 | return "http://schema.org/$item"; |
46 | 46 | }, |
47 | 47 | $names |
48 | 48 | ); |
49 | 49 | |
50 | 50 | // Finally return the schema uri. |
51 | - return 1 === count( $uris ) ? $uris[0] : $uris; |
|
51 | + return 1 === count($uris) ? $uris[0] : $uris; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -21,56 +21,56 @@ |
||
21 | 21 | */ |
22 | 22 | class Wordlift_Post_Related_Storage extends Wordlift_Storage { |
23 | 23 | |
24 | - /** |
|
25 | - * The {@link Wordlift_Entity_Service} instance. |
|
26 | - * |
|
27 | - * @since 3.15.0 |
|
28 | - * @access private |
|
29 | - * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
30 | - */ |
|
31 | - private $entity_service; |
|
24 | + /** |
|
25 | + * The {@link Wordlift_Entity_Service} instance. |
|
26 | + * |
|
27 | + * @since 3.15.0 |
|
28 | + * @access private |
|
29 | + * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
30 | + */ |
|
31 | + private $entity_service; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Create a {@link Wordlift_Post_Related_Storage} instance. |
|
35 | - * |
|
36 | - * @since 3.15.0 |
|
37 | - * |
|
38 | - * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
39 | - */ |
|
40 | - public function __construct( $entity_service ) { |
|
33 | + /** |
|
34 | + * Create a {@link Wordlift_Post_Related_Storage} instance. |
|
35 | + * |
|
36 | + * @since 3.15.0 |
|
37 | + * |
|
38 | + * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
39 | + */ |
|
40 | + public function __construct( $entity_service ) { |
|
41 | 41 | |
42 | - $this->entity_service = $entity_service; |
|
42 | + $this->entity_service = $entity_service; |
|
43 | 43 | |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the property value. |
|
48 | - * |
|
49 | - * There is no filter for entities or posts, the returned data here can |
|
50 | - * be used for `relations` and `references` according to the client. |
|
51 | - * |
|
52 | - * @since 3.15.0 |
|
53 | - * |
|
54 | - * @param int $post_id The {@link WP_Post}'s id. |
|
55 | - * |
|
56 | - * @return array|string|null A single string, or an array of values or null |
|
57 | - * if the property isn't recognized. |
|
58 | - */ |
|
59 | - public function get( $post_id ) { |
|
46 | + /** |
|
47 | + * Get the property value. |
|
48 | + * |
|
49 | + * There is no filter for entities or posts, the returned data here can |
|
50 | + * be used for `relations` and `references` according to the client. |
|
51 | + * |
|
52 | + * @since 3.15.0 |
|
53 | + * |
|
54 | + * @param int $post_id The {@link WP_Post}'s id. |
|
55 | + * |
|
56 | + * @return array|string|null A single string, or an array of values or null |
|
57 | + * if the property isn't recognized. |
|
58 | + */ |
|
59 | + public function get( $post_id ) { |
|
60 | 60 | |
61 | - // get related entities. |
|
62 | - $related = wl_core_get_related_entity_ids( $post_id ); |
|
61 | + // get related entities. |
|
62 | + $related = wl_core_get_related_entity_ids( $post_id ); |
|
63 | 63 | |
64 | - // A reference to the entity service. |
|
65 | - $entity_service = $this->entity_service; |
|
64 | + // A reference to the entity service. |
|
65 | + $entity_service = $this->entity_service; |
|
66 | 66 | |
67 | - // Map the related posts' ids to URIs. |
|
68 | - return array_map( |
|
69 | - function ( $item ) use ( $entity_service ) { |
|
70 | - return $entity_service->get_uri( $item ); |
|
71 | - }, |
|
72 | - $related |
|
73 | - ); |
|
74 | - } |
|
67 | + // Map the related posts' ids to URIs. |
|
68 | + return array_map( |
|
69 | + function ( $item ) use ( $entity_service ) { |
|
70 | + return $entity_service->get_uri( $item ); |
|
71 | + }, |
|
72 | + $related |
|
73 | + ); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
39 | 39 | */ |
40 | - public function __construct( $entity_service ) { |
|
40 | + public function __construct($entity_service) { |
|
41 | 41 | |
42 | 42 | $this->entity_service = $entity_service; |
43 | 43 | |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | * @return array|string|null A single string, or an array of values or null |
57 | 57 | * if the property isn't recognized. |
58 | 58 | */ |
59 | - public function get( $post_id ) { |
|
59 | + public function get($post_id) { |
|
60 | 60 | |
61 | 61 | // get related entities. |
62 | - $related = wl_core_get_related_entity_ids( $post_id ); |
|
62 | + $related = wl_core_get_related_entity_ids($post_id); |
|
63 | 63 | |
64 | 64 | // A reference to the entity service. |
65 | 65 | $entity_service = $this->entity_service; |
66 | 66 | |
67 | 67 | // Map the related posts' ids to URIs. |
68 | 68 | return array_map( |
69 | - function ( $item ) use ( $entity_service ) { |
|
70 | - return $entity_service->get_uri( $item ); |
|
69 | + function($item) use ($entity_service) { |
|
70 | + return $entity_service->get_uri($item); |
|
71 | 71 | }, |
72 | 72 | $related |
73 | 73 | ); |
@@ -14,77 +14,77 @@ |
||
14 | 14 | */ |
15 | 15 | class Wordlift_Tinymce_Adapter { |
16 | 16 | |
17 | - /** |
|
18 | - * The {@link Wordlift} plugin instance. |
|
19 | - * |
|
20 | - * @since 3.12.0 |
|
21 | - * @access private |
|
22 | - * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
23 | - */ |
|
24 | - private $plugin; |
|
17 | + /** |
|
18 | + * The {@link Wordlift} plugin instance. |
|
19 | + * |
|
20 | + * @since 3.12.0 |
|
21 | + * @access private |
|
22 | + * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
23 | + */ |
|
24 | + private $plugin; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Wordlift_Tinymce_Adapter constructor. |
|
28 | - * |
|
29 | - * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
30 | - */ |
|
31 | - public function __construct( $plugin ) { |
|
26 | + /** |
|
27 | + * Wordlift_Tinymce_Adapter constructor. |
|
28 | + * |
|
29 | + * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
30 | + */ |
|
31 | + public function __construct( $plugin ) { |
|
32 | 32 | |
33 | - $this->plugin = $plugin; |
|
33 | + $this->plugin = $plugin; |
|
34 | 34 | |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Load the TinyMCE plugin. This method is called by the WP mce_external_plugins hook. |
|
39 | - * |
|
40 | - * @param array $plugins The existing plugins array. |
|
41 | - * |
|
42 | - * @return array The modified plugins array. |
|
43 | - * @since 3.12.0 |
|
44 | - */ |
|
45 | - public function mce_external_plugins( $plugins ) { |
|
37 | + /** |
|
38 | + * Load the TinyMCE plugin. This method is called by the WP mce_external_plugins hook. |
|
39 | + * |
|
40 | + * @param array $plugins The existing plugins array. |
|
41 | + * |
|
42 | + * @return array The modified plugins array. |
|
43 | + * @since 3.12.0 |
|
44 | + */ |
|
45 | + public function mce_external_plugins( $plugins ) { |
|
46 | 46 | |
47 | - /** |
|
48 | - * Bail out if you are on Media Library |
|
49 | - * |
|
50 | - * @since 3.27.1 |
|
51 | - * |
|
52 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1122 |
|
53 | - */ |
|
54 | - if ( isset( get_current_screen()->base ) && get_current_screen()->base === 'upload' ) { |
|
55 | - return $plugins; |
|
56 | - } |
|
47 | + /** |
|
48 | + * Bail out if you are on Media Library |
|
49 | + * |
|
50 | + * @since 3.27.1 |
|
51 | + * |
|
52 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1122 |
|
53 | + */ |
|
54 | + if ( isset( get_current_screen()->base ) && get_current_screen()->base === 'upload' ) { |
|
55 | + return $plugins; |
|
56 | + } |
|
57 | 57 | |
58 | - /* |
|
58 | + /* |
|
59 | 59 | * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box. |
60 | 60 | * |
61 | 61 | * @since 3.20.3 |
62 | 62 | * |
63 | 63 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
64 | 64 | */ |
65 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
66 | - return $plugins; |
|
67 | - } |
|
65 | + if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
66 | + return $plugins; |
|
67 | + } |
|
68 | 68 | |
69 | - // Get WordLift's version as a cache killer. |
|
70 | - $version = $this->plugin->get_version(); |
|
69 | + // Get WordLift's version as a cache killer. |
|
70 | + $version = $this->plugin->get_version(); |
|
71 | 71 | |
72 | - // User can edit? |
|
73 | - $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); |
|
72 | + // User can edit? |
|
73 | + $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); |
|
74 | 74 | |
75 | - // If user can't edit or rich editing isn't enabled, bail out. |
|
76 | - if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) { |
|
77 | - return $plugins; |
|
78 | - } |
|
75 | + // If user can't edit or rich editing isn't enabled, bail out. |
|
76 | + if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) { |
|
77 | + return $plugins; |
|
78 | + } |
|
79 | 79 | |
80 | - // Add our own JavaScript file to TinyMCE's extensions. |
|
81 | - // DO NOT use the minified version, it'll yield errors with AngularJS. |
|
82 | - $plugins['wordlift'] = plugin_dir_url( __DIR__ ) . 'js/wordlift-reloaded.js?ver=' . $version; |
|
83 | - $plugins['wl_shortcodes'] = plugin_dir_url( __DIR__ ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version; |
|
84 | - $plugins['wl_tinymce'] = plugin_dir_url( __DIR__ ) . 'admin/js/1/tinymce.js?ver=' . $version; |
|
85 | - $plugins['wl_tinymce_2'] = plugin_dir_url( __DIR__ ) . 'js/dist/tiny-mce.js?ver=' . $version; |
|
80 | + // Add our own JavaScript file to TinyMCE's extensions. |
|
81 | + // DO NOT use the minified version, it'll yield errors with AngularJS. |
|
82 | + $plugins['wordlift'] = plugin_dir_url( __DIR__ ) . 'js/wordlift-reloaded.js?ver=' . $version; |
|
83 | + $plugins['wl_shortcodes'] = plugin_dir_url( __DIR__ ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version; |
|
84 | + $plugins['wl_tinymce'] = plugin_dir_url( __DIR__ ) . 'admin/js/1/tinymce.js?ver=' . $version; |
|
85 | + $plugins['wl_tinymce_2'] = plugin_dir_url( __DIR__ ) . 'js/dist/tiny-mce.js?ver=' . $version; |
|
86 | 86 | |
87 | - return $plugins; |
|
88 | - } |
|
87 | + return $plugins; |
|
88 | + } |
|
89 | 89 | |
90 | 90 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
30 | 30 | */ |
31 | - public function __construct( $plugin ) { |
|
31 | + public function __construct($plugin) { |
|
32 | 32 | |
33 | 33 | $this->plugin = $plugin; |
34 | 34 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @return array The modified plugins array. |
43 | 43 | * @since 3.12.0 |
44 | 44 | */ |
45 | - public function mce_external_plugins( $plugins ) { |
|
45 | + public function mce_external_plugins($plugins) { |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Bail out if you are on Media Library |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @see https://github.com/insideout10/wordlift-plugin/issues/1122 |
53 | 53 | */ |
54 | - if ( isset( get_current_screen()->base ) && get_current_screen()->base === 'upload' ) { |
|
54 | + if (isset(get_current_screen()->base) && get_current_screen()->base === 'upload') { |
|
55 | 55 | return $plugins; |
56 | 56 | } |
57 | 57 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
64 | 64 | */ |
65 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
65 | + if ( ! apply_filters('wl_can_see_classification_box', true)) { |
|
66 | 66 | return $plugins; |
67 | 67 | } |
68 | 68 | |
@@ -70,19 +70,19 @@ discard block |
||
70 | 70 | $version = $this->plugin->get_version(); |
71 | 71 | |
72 | 72 | // User can edit? |
73 | - $can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ); |
|
73 | + $can_edit = current_user_can('edit_posts') || current_user_can('edit_pages'); |
|
74 | 74 | |
75 | 75 | // If user can't edit or rich editing isn't enabled, bail out. |
76 | - if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) { |
|
76 | + if ( ! $can_edit || ! get_user_option('rich_editing')) { |
|
77 | 77 | return $plugins; |
78 | 78 | } |
79 | 79 | |
80 | 80 | // Add our own JavaScript file to TinyMCE's extensions. |
81 | 81 | // DO NOT use the minified version, it'll yield errors with AngularJS. |
82 | - $plugins['wordlift'] = plugin_dir_url( __DIR__ ) . 'js/wordlift-reloaded.js?ver=' . $version; |
|
83 | - $plugins['wl_shortcodes'] = plugin_dir_url( __DIR__ ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version; |
|
84 | - $plugins['wl_tinymce'] = plugin_dir_url( __DIR__ ) . 'admin/js/1/tinymce.js?ver=' . $version; |
|
85 | - $plugins['wl_tinymce_2'] = plugin_dir_url( __DIR__ ) . 'js/dist/tiny-mce.js?ver=' . $version; |
|
82 | + $plugins['wordlift'] = plugin_dir_url(__DIR__).'js/wordlift-reloaded.js?ver='.$version; |
|
83 | + $plugins['wl_shortcodes'] = plugin_dir_url(__DIR__).'admin/js/wordlift_shortcode_tinymce_plugin.js?ver='.$version; |
|
84 | + $plugins['wl_tinymce'] = plugin_dir_url(__DIR__).'admin/js/1/tinymce.js?ver='.$version; |
|
85 | + $plugins['wl_tinymce_2'] = plugin_dir_url(__DIR__).'js/dist/tiny-mce.js?ver='.$version; |
|
86 | 86 | |
87 | 87 | return $plugins; |
88 | 88 | } |
@@ -14,118 +14,118 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class Wordlift_Property_Service { |
16 | 16 | |
17 | - protected static $instance; |
|
18 | - |
|
19 | - public function __construct() { |
|
20 | - |
|
21 | - static::$instance = $this; |
|
22 | - } |
|
23 | - |
|
24 | - /** |
|
25 | - * Get the field singleton. |
|
26 | - * |
|
27 | - * @since 3.6.0 |
|
28 | - * @return \Wordlift_Schema_Url_Property_Service The singleton instance. |
|
29 | - */ |
|
30 | - public static function get_instance() { |
|
31 | - |
|
32 | - return static::$instance; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Get the value for the specified post/entity. |
|
37 | - * |
|
38 | - * @since 3.6.0 |
|
39 | - * |
|
40 | - * @param int $post_id The post id. |
|
41 | - * |
|
42 | - * @return mixed |
|
43 | - */ |
|
44 | - abstract public function get( $post_id ); |
|
45 | - |
|
46 | - /** |
|
47 | - * Sanitize the provided value. |
|
48 | - * |
|
49 | - * @since 3.6.0 |
|
50 | - * |
|
51 | - * @param mixed $value The value to sanitize. |
|
52 | - * |
|
53 | - * @return mixed|NULL The sanitized value or NULL avoid saving this value (see {@link Wl_Metabox_Field}). |
|
54 | - */ |
|
55 | - abstract public function sanitize( $value ); |
|
56 | - |
|
57 | - /** |
|
58 | - * The RDF predicate for the property. |
|
59 | - * |
|
60 | - * @since 3.6.0 |
|
61 | - * @return string The RDF predicate. |
|
62 | - */ |
|
63 | - abstract public function get_rdf_predicate(); |
|
64 | - |
|
65 | - /** |
|
66 | - * The RDF data type. |
|
67 | - * |
|
68 | - * @since 3.6.0 |
|
69 | - * @return string The RDF data type. |
|
70 | - */ |
|
71 | - abstract public function get_rdf_data_type(); |
|
72 | - |
|
73 | - /** |
|
74 | - * The internal data type. |
|
75 | - * |
|
76 | - * @since 3.6.0 |
|
77 | - * @return string The internal data type. |
|
78 | - */ |
|
79 | - abstract public function get_data_type(); |
|
80 | - |
|
81 | - /** |
|
82 | - * The cardinality. |
|
83 | - * |
|
84 | - * @since 3.6.0 |
|
85 | - * @return mixed The cardinality. |
|
86 | - */ |
|
87 | - abstract public function get_cardinality(); |
|
88 | - |
|
89 | - /** |
|
90 | - * The metabox field class name. |
|
91 | - * |
|
92 | - * @since 3.6.0 |
|
93 | - * @return string The metabox field class name. |
|
94 | - */ |
|
95 | - abstract public function get_metabox_class(); |
|
96 | - |
|
97 | - /** |
|
98 | - * The untranslated metabox field label. |
|
99 | - * |
|
100 | - * @since 3.6.0 |
|
101 | - * @return string The untranslated metabox field label. |
|
102 | - */ |
|
103 | - abstract public function get_metabox_label(); |
|
104 | - |
|
105 | - /** |
|
106 | - * The definition of the property returned as a compatible array. |
|
107 | - * |
|
108 | - * @deprecated |
|
109 | - * |
|
110 | - * @since 3.6.0 |
|
111 | - * @return array An array of property definitions. |
|
112 | - */ |
|
113 | - public function get_compat_definition() { |
|
114 | - |
|
115 | - return array( |
|
116 | - 'type' => $this->get_data_type(), |
|
117 | - 'predicate' => $this->get_rdf_predicate(), |
|
118 | - 'export_type' => $this->get_rdf_data_type(), |
|
119 | - 'constraints' => array( |
|
120 | - 'cardinality' => $this->get_cardinality(), |
|
121 | - ), |
|
122 | - // Use the standard metabox for these URI (the URI metabox creates local entities). |
|
123 | - 'metabox' => array( |
|
124 | - 'class' => $this->get_metabox_class(), |
|
125 | - 'label' => $this->get_metabox_label(), |
|
126 | - ), |
|
127 | - 'sanitize' => array( $this, 'sanitize' ), |
|
128 | - ); |
|
129 | - } |
|
17 | + protected static $instance; |
|
18 | + |
|
19 | + public function __construct() { |
|
20 | + |
|
21 | + static::$instance = $this; |
|
22 | + } |
|
23 | + |
|
24 | + /** |
|
25 | + * Get the field singleton. |
|
26 | + * |
|
27 | + * @since 3.6.0 |
|
28 | + * @return \Wordlift_Schema_Url_Property_Service The singleton instance. |
|
29 | + */ |
|
30 | + public static function get_instance() { |
|
31 | + |
|
32 | + return static::$instance; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Get the value for the specified post/entity. |
|
37 | + * |
|
38 | + * @since 3.6.0 |
|
39 | + * |
|
40 | + * @param int $post_id The post id. |
|
41 | + * |
|
42 | + * @return mixed |
|
43 | + */ |
|
44 | + abstract public function get( $post_id ); |
|
45 | + |
|
46 | + /** |
|
47 | + * Sanitize the provided value. |
|
48 | + * |
|
49 | + * @since 3.6.0 |
|
50 | + * |
|
51 | + * @param mixed $value The value to sanitize. |
|
52 | + * |
|
53 | + * @return mixed|NULL The sanitized value or NULL avoid saving this value (see {@link Wl_Metabox_Field}). |
|
54 | + */ |
|
55 | + abstract public function sanitize( $value ); |
|
56 | + |
|
57 | + /** |
|
58 | + * The RDF predicate for the property. |
|
59 | + * |
|
60 | + * @since 3.6.0 |
|
61 | + * @return string The RDF predicate. |
|
62 | + */ |
|
63 | + abstract public function get_rdf_predicate(); |
|
64 | + |
|
65 | + /** |
|
66 | + * The RDF data type. |
|
67 | + * |
|
68 | + * @since 3.6.0 |
|
69 | + * @return string The RDF data type. |
|
70 | + */ |
|
71 | + abstract public function get_rdf_data_type(); |
|
72 | + |
|
73 | + /** |
|
74 | + * The internal data type. |
|
75 | + * |
|
76 | + * @since 3.6.0 |
|
77 | + * @return string The internal data type. |
|
78 | + */ |
|
79 | + abstract public function get_data_type(); |
|
80 | + |
|
81 | + /** |
|
82 | + * The cardinality. |
|
83 | + * |
|
84 | + * @since 3.6.0 |
|
85 | + * @return mixed The cardinality. |
|
86 | + */ |
|
87 | + abstract public function get_cardinality(); |
|
88 | + |
|
89 | + /** |
|
90 | + * The metabox field class name. |
|
91 | + * |
|
92 | + * @since 3.6.0 |
|
93 | + * @return string The metabox field class name. |
|
94 | + */ |
|
95 | + abstract public function get_metabox_class(); |
|
96 | + |
|
97 | + /** |
|
98 | + * The untranslated metabox field label. |
|
99 | + * |
|
100 | + * @since 3.6.0 |
|
101 | + * @return string The untranslated metabox field label. |
|
102 | + */ |
|
103 | + abstract public function get_metabox_label(); |
|
104 | + |
|
105 | + /** |
|
106 | + * The definition of the property returned as a compatible array. |
|
107 | + * |
|
108 | + * @deprecated |
|
109 | + * |
|
110 | + * @since 3.6.0 |
|
111 | + * @return array An array of property definitions. |
|
112 | + */ |
|
113 | + public function get_compat_definition() { |
|
114 | + |
|
115 | + return array( |
|
116 | + 'type' => $this->get_data_type(), |
|
117 | + 'predicate' => $this->get_rdf_predicate(), |
|
118 | + 'export_type' => $this->get_rdf_data_type(), |
|
119 | + 'constraints' => array( |
|
120 | + 'cardinality' => $this->get_cardinality(), |
|
121 | + ), |
|
122 | + // Use the standard metabox for these URI (the URI metabox creates local entities). |
|
123 | + 'metabox' => array( |
|
124 | + 'class' => $this->get_metabox_class(), |
|
125 | + 'label' => $this->get_metabox_label(), |
|
126 | + ), |
|
127 | + 'sanitize' => array( $this, 'sanitize' ), |
|
128 | + ); |
|
129 | + } |
|
130 | 130 | |
131 | 131 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return mixed |
43 | 43 | */ |
44 | - abstract public function get( $post_id ); |
|
44 | + abstract public function get($post_id); |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * Sanitize the provided value. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return mixed|NULL The sanitized value or NULL avoid saving this value (see {@link Wl_Metabox_Field}). |
54 | 54 | */ |
55 | - abstract public function sanitize( $value ); |
|
55 | + abstract public function sanitize($value); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * The RDF predicate for the property. |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | 'class' => $this->get_metabox_class(), |
125 | 125 | 'label' => $this->get_metabox_label(), |
126 | 126 | ), |
127 | - 'sanitize' => array( $this, 'sanitize' ), |
|
127 | + 'sanitize' => array($this, 'sanitize'), |
|
128 | 128 | ); |
129 | 129 | } |
130 | 130 |
@@ -19,336 +19,336 @@ |
||
19 | 19 | */ |
20 | 20 | class Wordlift_User_Service { |
21 | 21 | |
22 | - /** |
|
23 | - * The meta key where the user's URI is stored. |
|
24 | - * |
|
25 | - * @since 3.1.7 |
|
26 | - */ |
|
27 | - const URI_META_KEY = '_wl_uri'; |
|
28 | - |
|
29 | - /** |
|
30 | - * The user meta key where the deny entity edit flag is stored. |
|
31 | - * |
|
32 | - * @since 3.14.0 |
|
33 | - */ |
|
34 | - const DENY_ENTITY_CREATE_META_KEY = '_wl_deny_entity_create'; |
|
35 | - |
|
36 | - /** |
|
37 | - * The meta key holding the entity id representing a {@link WP_User}. |
|
38 | - * |
|
39 | - * @since 3.14.0 |
|
40 | - */ |
|
41 | - const ENTITY_META_KEY = '_wl_entity'; |
|
42 | - |
|
43 | - /** |
|
44 | - * The Log service. |
|
45 | - * |
|
46 | - * @since 3.1.7 |
|
47 | - * @access private |
|
48 | - * @var \Wordlift_Log_Service $log_service The Log service. |
|
49 | - */ |
|
50 | - private $log_service; |
|
51 | - |
|
52 | - /** |
|
53 | - * Create an instance of the User service. |
|
54 | - * |
|
55 | - * @since 3.1.7 |
|
56 | - */ |
|
57 | - protected function __construct() { |
|
58 | - |
|
59 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' ); |
|
60 | - |
|
61 | - add_filter( 'user_has_cap', array( $this, 'has_cap' ), 10, 3 ); |
|
62 | - |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * The singleton instance of the User service. |
|
67 | - * |
|
68 | - * @since 3.1.7 |
|
69 | - * @access private |
|
70 | - * @var \Wordlift_User_Service $user_service The singleton instance of the User service. |
|
71 | - */ |
|
72 | - private static $instance = null; |
|
73 | - |
|
74 | - /** |
|
75 | - * Get the singleton instance of the User service. |
|
76 | - * |
|
77 | - * @return \Wordlift_User_Service The singleton instance of the User service. |
|
78 | - * @since 3.1.7 |
|
79 | - */ |
|
80 | - public static function get_instance() { |
|
81 | - |
|
82 | - if ( ! isset( self::$instance ) ) { |
|
83 | - self::$instance = new self(); |
|
84 | - } |
|
85 | - |
|
86 | - return self::$instance; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Get the URI for a user. |
|
91 | - * |
|
92 | - * @param int $user_id The user id |
|
93 | - * |
|
94 | - * @return false|string The user's URI or false in case of failure. |
|
95 | - * @since 3.1.7 |
|
96 | - */ |
|
97 | - public function get_uri( $user_id ) { |
|
98 | - |
|
99 | - // Try to get the URI stored in the user's meta and return it if available. |
|
100 | - $dataset_uri = wl_configuration_get_redlink_dataset_uri(); |
|
101 | - $user_uri = $this->_get_uri( $user_id ); |
|
102 | - if ( ! empty( $dataset_uri ) && ! empty( $user_uri ) && 0 === strpos( $user_uri, $dataset_uri ) ) { |
|
103 | - return $user_uri; |
|
104 | - } |
|
105 | - |
|
106 | - // Try to build an URI, return false in case of failure. |
|
107 | - $user_uri = $this->_build_uri( $user_id ); |
|
108 | - if ( false === $user_uri ) { |
|
109 | - return false; |
|
110 | - } |
|
111 | - |
|
112 | - // Store the URI for future requests (we need a "permanent" URI). |
|
113 | - $this->_set_uri( $user_id, $user_uri ); |
|
114 | - |
|
115 | - return $user_uri; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Set the `id` of the entity representing a {@link WP_User}. |
|
120 | - * |
|
121 | - * If the `id` is set to 0 (or less) then the meta is deleted. |
|
122 | - * |
|
123 | - * @param int $user_id The {@link WP_User}. |
|
124 | - * @param int $value The entity {@link WP_Post} `id`. |
|
125 | - * |
|
126 | - * @return bool|int Meta ID if the key didn't exist, true on successful update, false on failure. |
|
127 | - * @since 3.14.0 |
|
128 | - */ |
|
129 | - public function set_entity( $user_id, $value ) { |
|
130 | - |
|
131 | - return 0 < $value |
|
132 | - ? update_user_meta( $user_id, self::ENTITY_META_KEY, $value ) |
|
133 | - : delete_user_meta( $user_id, self::ENTITY_META_KEY ); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Get the {@link WP_Post} `id` of the entity representing a {@link WP_User}. |
|
138 | - * |
|
139 | - * @param int $user_id The {@link WP_User}'s `id`. |
|
140 | - * |
|
141 | - * @return string|false The entity {@link WP_Post} `id` or an empty string if not set or false if the object id is invalid |
|
142 | - * @since 3.14.0 |
|
143 | - */ |
|
144 | - public function get_entity( $user_id ) { |
|
145 | - |
|
146 | - return get_user_meta( $user_id, self::ENTITY_META_KEY, true ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Get the user's URI stored in the user's meta. |
|
151 | - * |
|
152 | - * @param int $user_id The user id. |
|
153 | - * |
|
154 | - * @return false|string The user's URI or false if not found. |
|
155 | - * @since 3.1.7 |
|
156 | - */ |
|
157 | - // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
|
158 | - private function _get_uri( $user_id ) { |
|
159 | - |
|
160 | - $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true ); |
|
161 | - |
|
162 | - if ( empty( $user_uri ) ) { |
|
163 | - return false; |
|
164 | - } |
|
165 | - |
|
166 | - return $user_uri; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Build an URI for a user. |
|
171 | - * |
|
172 | - * @param int $user_id The user's id. |
|
173 | - * |
|
174 | - * @return false|string The user's URI or false in case of failure. |
|
175 | - * @since 3.1.7 |
|
176 | - */ |
|
177 | - // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
|
178 | - private function _build_uri( $user_id ) { |
|
179 | - |
|
180 | - // Get the user, return false in case of failure. |
|
181 | - $user = get_userdata( $user_id ); |
|
182 | - if ( false === $user ) { |
|
183 | - return false; |
|
184 | - }; |
|
185 | - |
|
186 | - // If the nicename is not set, return a failure. |
|
187 | - if ( empty( $user->user_nicename ) ) { |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @since 3.27.7 changed `user` to `author` to avoid potential clashes with CPTs ( `author` is reserved |
|
193 | - * https://developer.wordpress.org/reference/functions/register_post_type/#reserved-post-types ) |
|
194 | - */ |
|
195 | - return untrailingslashit( wl_configuration_get_redlink_dataset_uri() ) . "/author/$user->user_nicename"; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Store the URI in user's meta. |
|
200 | - * |
|
201 | - * @param int $user_id The user's id. |
|
202 | - * @param string $user_uri The user's uri. |
|
203 | - * |
|
204 | - * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
|
205 | - * @since 3.1.7 |
|
206 | - */ |
|
207 | - // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
|
208 | - private function _set_uri( $user_id, $user_uri ) { |
|
209 | - |
|
210 | - return update_user_meta( $user_id, self::URI_META_KEY, $user_uri ); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Mark an editor user as denied from editing entities. |
|
215 | - * Does nothing if the user is not an editor |
|
216 | - * |
|
217 | - * @param integer $user_id The ID of the user |
|
218 | - * |
|
219 | - * @since 3.14.0 |
|
220 | - */ |
|
221 | - public function deny_editor_entity_create( $user_id ) { |
|
222 | - |
|
223 | - // Bail out if the user is not an editor. |
|
224 | - if ( ! $this->is_editor( $user_id ) ) { |
|
225 | - return; |
|
226 | - } |
|
227 | - |
|
228 | - // The user explicitly do not have the capability. |
|
229 | - update_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes' ); |
|
230 | - |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Remove the "deny entity editing" mark from an editor user. |
|
235 | - * Does nothing if the user is not an editor |
|
236 | - * |
|
237 | - * @param integer $user_id The ID of the user |
|
238 | - * |
|
239 | - * @since 3.14.0 |
|
240 | - */ |
|
241 | - public function allow_editor_entity_create( $user_id ) { |
|
242 | - |
|
243 | - // Bail out if the user is not an editor. |
|
244 | - if ( ! $this->is_editor( $user_id ) ) { |
|
245 | - return; |
|
246 | - } |
|
247 | - |
|
248 | - // The user explicitly do not have the capability. |
|
249 | - delete_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY ); |
|
250 | - |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Get whether the 'deny editor entity editing' flag is set. |
|
255 | - * |
|
256 | - * @param int $user_id The {@link WP_User} `id`. |
|
257 | - * |
|
258 | - * @return int bool True if editing is denied otherwise false. |
|
259 | - * @since 3.14.0 |
|
260 | - */ |
|
261 | - public function is_deny_editor_entity_create( $user_id ) { |
|
262 | - |
|
263 | - return 'yes' === get_user_option( self::DENY_ENTITY_CREATE_META_KEY, $user_id ); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Check whether the {@link WP_User} with the specified `id` is an editor, |
|
268 | - * i.e. has the `editor` role. |
|
269 | - * |
|
270 | - * @param int $user_id The {@link WP_User} `id`. |
|
271 | - * |
|
272 | - * @return bool True if the {@link WP_User} is an editor otherwise false. |
|
273 | - * @since 3.14.0 |
|
274 | - */ |
|
275 | - public function is_editor( $user_id ) { |
|
276 | - |
|
277 | - // Get the user. |
|
278 | - $user = get_user_by( 'id', $user_id ); |
|
279 | - |
|
280 | - // Return true, if the user is found and has the `editor` role. |
|
281 | - return is_a( $user, 'WP_User' ) && in_array( 'editor', (array) $user->roles, true ); |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Check if an editor can create entities. |
|
286 | - * |
|
287 | - * @param int $user_id The user id of the user being checked. |
|
288 | - * |
|
289 | - * @return bool false if it is an editor that is denied from edit entities, true otherwise. |
|
290 | - * @since 3.14.0 |
|
291 | - */ |
|
292 | - public function editor_can_create_entities( $user_id ) { |
|
293 | - |
|
294 | - // Return true if not an editor. |
|
295 | - if ( ! $this->is_editor( $user_id ) ) { |
|
296 | - return true; |
|
297 | - } |
|
298 | - |
|
299 | - // Check if the user explicitly denied. |
|
300 | - return ! $this->is_deny_editor_entity_create( $user_id ); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Filter capabilities of user. |
|
305 | - * |
|
306 | - * Deny the capability of managing and editing entities for some users. |
|
307 | - * |
|
308 | - * @param array $allcaps All the capabilities of the user |
|
309 | - * @param array $cap [0] Required capability |
|
310 | - * @param array $args [0] Requested capability |
|
311 | - * [1] User ID |
|
312 | - * [2] Associated object ID |
|
313 | - * |
|
314 | - * @return array The capabilities array. |
|
315 | - * @since 3.14.0 |
|
316 | - */ |
|
317 | - public function has_cap( $allcaps, $cap, $args ) { |
|
318 | - /* |
|
22 | + /** |
|
23 | + * The meta key where the user's URI is stored. |
|
24 | + * |
|
25 | + * @since 3.1.7 |
|
26 | + */ |
|
27 | + const URI_META_KEY = '_wl_uri'; |
|
28 | + |
|
29 | + /** |
|
30 | + * The user meta key where the deny entity edit flag is stored. |
|
31 | + * |
|
32 | + * @since 3.14.0 |
|
33 | + */ |
|
34 | + const DENY_ENTITY_CREATE_META_KEY = '_wl_deny_entity_create'; |
|
35 | + |
|
36 | + /** |
|
37 | + * The meta key holding the entity id representing a {@link WP_User}. |
|
38 | + * |
|
39 | + * @since 3.14.0 |
|
40 | + */ |
|
41 | + const ENTITY_META_KEY = '_wl_entity'; |
|
42 | + |
|
43 | + /** |
|
44 | + * The Log service. |
|
45 | + * |
|
46 | + * @since 3.1.7 |
|
47 | + * @access private |
|
48 | + * @var \Wordlift_Log_Service $log_service The Log service. |
|
49 | + */ |
|
50 | + private $log_service; |
|
51 | + |
|
52 | + /** |
|
53 | + * Create an instance of the User service. |
|
54 | + * |
|
55 | + * @since 3.1.7 |
|
56 | + */ |
|
57 | + protected function __construct() { |
|
58 | + |
|
59 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' ); |
|
60 | + |
|
61 | + add_filter( 'user_has_cap', array( $this, 'has_cap' ), 10, 3 ); |
|
62 | + |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * The singleton instance of the User service. |
|
67 | + * |
|
68 | + * @since 3.1.7 |
|
69 | + * @access private |
|
70 | + * @var \Wordlift_User_Service $user_service The singleton instance of the User service. |
|
71 | + */ |
|
72 | + private static $instance = null; |
|
73 | + |
|
74 | + /** |
|
75 | + * Get the singleton instance of the User service. |
|
76 | + * |
|
77 | + * @return \Wordlift_User_Service The singleton instance of the User service. |
|
78 | + * @since 3.1.7 |
|
79 | + */ |
|
80 | + public static function get_instance() { |
|
81 | + |
|
82 | + if ( ! isset( self::$instance ) ) { |
|
83 | + self::$instance = new self(); |
|
84 | + } |
|
85 | + |
|
86 | + return self::$instance; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Get the URI for a user. |
|
91 | + * |
|
92 | + * @param int $user_id The user id |
|
93 | + * |
|
94 | + * @return false|string The user's URI or false in case of failure. |
|
95 | + * @since 3.1.7 |
|
96 | + */ |
|
97 | + public function get_uri( $user_id ) { |
|
98 | + |
|
99 | + // Try to get the URI stored in the user's meta and return it if available. |
|
100 | + $dataset_uri = wl_configuration_get_redlink_dataset_uri(); |
|
101 | + $user_uri = $this->_get_uri( $user_id ); |
|
102 | + if ( ! empty( $dataset_uri ) && ! empty( $user_uri ) && 0 === strpos( $user_uri, $dataset_uri ) ) { |
|
103 | + return $user_uri; |
|
104 | + } |
|
105 | + |
|
106 | + // Try to build an URI, return false in case of failure. |
|
107 | + $user_uri = $this->_build_uri( $user_id ); |
|
108 | + if ( false === $user_uri ) { |
|
109 | + return false; |
|
110 | + } |
|
111 | + |
|
112 | + // Store the URI for future requests (we need a "permanent" URI). |
|
113 | + $this->_set_uri( $user_id, $user_uri ); |
|
114 | + |
|
115 | + return $user_uri; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Set the `id` of the entity representing a {@link WP_User}. |
|
120 | + * |
|
121 | + * If the `id` is set to 0 (or less) then the meta is deleted. |
|
122 | + * |
|
123 | + * @param int $user_id The {@link WP_User}. |
|
124 | + * @param int $value The entity {@link WP_Post} `id`. |
|
125 | + * |
|
126 | + * @return bool|int Meta ID if the key didn't exist, true on successful update, false on failure. |
|
127 | + * @since 3.14.0 |
|
128 | + */ |
|
129 | + public function set_entity( $user_id, $value ) { |
|
130 | + |
|
131 | + return 0 < $value |
|
132 | + ? update_user_meta( $user_id, self::ENTITY_META_KEY, $value ) |
|
133 | + : delete_user_meta( $user_id, self::ENTITY_META_KEY ); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Get the {@link WP_Post} `id` of the entity representing a {@link WP_User}. |
|
138 | + * |
|
139 | + * @param int $user_id The {@link WP_User}'s `id`. |
|
140 | + * |
|
141 | + * @return string|false The entity {@link WP_Post} `id` or an empty string if not set or false if the object id is invalid |
|
142 | + * @since 3.14.0 |
|
143 | + */ |
|
144 | + public function get_entity( $user_id ) { |
|
145 | + |
|
146 | + return get_user_meta( $user_id, self::ENTITY_META_KEY, true ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Get the user's URI stored in the user's meta. |
|
151 | + * |
|
152 | + * @param int $user_id The user id. |
|
153 | + * |
|
154 | + * @return false|string The user's URI or false if not found. |
|
155 | + * @since 3.1.7 |
|
156 | + */ |
|
157 | + // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
|
158 | + private function _get_uri( $user_id ) { |
|
159 | + |
|
160 | + $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true ); |
|
161 | + |
|
162 | + if ( empty( $user_uri ) ) { |
|
163 | + return false; |
|
164 | + } |
|
165 | + |
|
166 | + return $user_uri; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Build an URI for a user. |
|
171 | + * |
|
172 | + * @param int $user_id The user's id. |
|
173 | + * |
|
174 | + * @return false|string The user's URI or false in case of failure. |
|
175 | + * @since 3.1.7 |
|
176 | + */ |
|
177 | + // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
|
178 | + private function _build_uri( $user_id ) { |
|
179 | + |
|
180 | + // Get the user, return false in case of failure. |
|
181 | + $user = get_userdata( $user_id ); |
|
182 | + if ( false === $user ) { |
|
183 | + return false; |
|
184 | + }; |
|
185 | + |
|
186 | + // If the nicename is not set, return a failure. |
|
187 | + if ( empty( $user->user_nicename ) ) { |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @since 3.27.7 changed `user` to `author` to avoid potential clashes with CPTs ( `author` is reserved |
|
193 | + * https://developer.wordpress.org/reference/functions/register_post_type/#reserved-post-types ) |
|
194 | + */ |
|
195 | + return untrailingslashit( wl_configuration_get_redlink_dataset_uri() ) . "/author/$user->user_nicename"; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Store the URI in user's meta. |
|
200 | + * |
|
201 | + * @param int $user_id The user's id. |
|
202 | + * @param string $user_uri The user's uri. |
|
203 | + * |
|
204 | + * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
|
205 | + * @since 3.1.7 |
|
206 | + */ |
|
207 | + // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
|
208 | + private function _set_uri( $user_id, $user_uri ) { |
|
209 | + |
|
210 | + return update_user_meta( $user_id, self::URI_META_KEY, $user_uri ); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Mark an editor user as denied from editing entities. |
|
215 | + * Does nothing if the user is not an editor |
|
216 | + * |
|
217 | + * @param integer $user_id The ID of the user |
|
218 | + * |
|
219 | + * @since 3.14.0 |
|
220 | + */ |
|
221 | + public function deny_editor_entity_create( $user_id ) { |
|
222 | + |
|
223 | + // Bail out if the user is not an editor. |
|
224 | + if ( ! $this->is_editor( $user_id ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | + |
|
228 | + // The user explicitly do not have the capability. |
|
229 | + update_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes' ); |
|
230 | + |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Remove the "deny entity editing" mark from an editor user. |
|
235 | + * Does nothing if the user is not an editor |
|
236 | + * |
|
237 | + * @param integer $user_id The ID of the user |
|
238 | + * |
|
239 | + * @since 3.14.0 |
|
240 | + */ |
|
241 | + public function allow_editor_entity_create( $user_id ) { |
|
242 | + |
|
243 | + // Bail out if the user is not an editor. |
|
244 | + if ( ! $this->is_editor( $user_id ) ) { |
|
245 | + return; |
|
246 | + } |
|
247 | + |
|
248 | + // The user explicitly do not have the capability. |
|
249 | + delete_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY ); |
|
250 | + |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Get whether the 'deny editor entity editing' flag is set. |
|
255 | + * |
|
256 | + * @param int $user_id The {@link WP_User} `id`. |
|
257 | + * |
|
258 | + * @return int bool True if editing is denied otherwise false. |
|
259 | + * @since 3.14.0 |
|
260 | + */ |
|
261 | + public function is_deny_editor_entity_create( $user_id ) { |
|
262 | + |
|
263 | + return 'yes' === get_user_option( self::DENY_ENTITY_CREATE_META_KEY, $user_id ); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Check whether the {@link WP_User} with the specified `id` is an editor, |
|
268 | + * i.e. has the `editor` role. |
|
269 | + * |
|
270 | + * @param int $user_id The {@link WP_User} `id`. |
|
271 | + * |
|
272 | + * @return bool True if the {@link WP_User} is an editor otherwise false. |
|
273 | + * @since 3.14.0 |
|
274 | + */ |
|
275 | + public function is_editor( $user_id ) { |
|
276 | + |
|
277 | + // Get the user. |
|
278 | + $user = get_user_by( 'id', $user_id ); |
|
279 | + |
|
280 | + // Return true, if the user is found and has the `editor` role. |
|
281 | + return is_a( $user, 'WP_User' ) && in_array( 'editor', (array) $user->roles, true ); |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Check if an editor can create entities. |
|
286 | + * |
|
287 | + * @param int $user_id The user id of the user being checked. |
|
288 | + * |
|
289 | + * @return bool false if it is an editor that is denied from edit entities, true otherwise. |
|
290 | + * @since 3.14.0 |
|
291 | + */ |
|
292 | + public function editor_can_create_entities( $user_id ) { |
|
293 | + |
|
294 | + // Return true if not an editor. |
|
295 | + if ( ! $this->is_editor( $user_id ) ) { |
|
296 | + return true; |
|
297 | + } |
|
298 | + |
|
299 | + // Check if the user explicitly denied. |
|
300 | + return ! $this->is_deny_editor_entity_create( $user_id ); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Filter capabilities of user. |
|
305 | + * |
|
306 | + * Deny the capability of managing and editing entities for some users. |
|
307 | + * |
|
308 | + * @param array $allcaps All the capabilities of the user |
|
309 | + * @param array $cap [0] Required capability |
|
310 | + * @param array $args [0] Requested capability |
|
311 | + * [1] User ID |
|
312 | + * [2] Associated object ID |
|
313 | + * |
|
314 | + * @return array The capabilities array. |
|
315 | + * @since 3.14.0 |
|
316 | + */ |
|
317 | + public function has_cap( $allcaps, $cap, $args ) { |
|
318 | + /* |
|
319 | 319 | * For entity management/editing related capabilities |
320 | 320 | * check that an editor was not explicitly denied (in user profile) |
321 | 321 | * the capability. |
322 | 322 | */ |
323 | 323 | |
324 | - /* |
|
324 | + /* |
|
325 | 325 | * Need protection against the case of edit_user and likes which do not |
326 | 326 | * require a capability, just request one. |
327 | 327 | */ |
328 | - if ( empty( $cap ) || ! isset( $cap[0] ) ) { |
|
329 | - return $allcaps; |
|
330 | - } |
|
331 | - |
|
332 | - if ( |
|
333 | - ( 'edit_wordlift_entity' === $cap[0] ) || |
|
334 | - ( 'edit_wordlift_entities' === $cap[0] ) || |
|
335 | - ( 'edit_others_wordlift_entities' === $cap[0] ) || |
|
336 | - ( 'publish_wordlift_entities' === $cap[0] ) || |
|
337 | - ( 'read_private_wordlift_entities' === $cap[0] ) || |
|
338 | - ( 'delete_wordlift_entity' === $cap[0] ) || |
|
339 | - ( 'delete_wordlift_entities' === $cap[0] ) || |
|
340 | - ( 'delete_others_wordlift_entities' === $cap[0] ) || |
|
341 | - ( 'delete_published_wordlift_entities' === $cap[0] ) || |
|
342 | - ( 'delete_private_wordlift_entities' === $cap[0] ) |
|
343 | - ) { |
|
344 | - $user_id = $args[1]; |
|
345 | - |
|
346 | - if ( ! $this->editor_can_create_entities( $user_id ) ) { |
|
347 | - $allcaps[ $cap[0] ] = false; |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - return $allcaps; |
|
352 | - } |
|
328 | + if ( empty( $cap ) || ! isset( $cap[0] ) ) { |
|
329 | + return $allcaps; |
|
330 | + } |
|
331 | + |
|
332 | + if ( |
|
333 | + ( 'edit_wordlift_entity' === $cap[0] ) || |
|
334 | + ( 'edit_wordlift_entities' === $cap[0] ) || |
|
335 | + ( 'edit_others_wordlift_entities' === $cap[0] ) || |
|
336 | + ( 'publish_wordlift_entities' === $cap[0] ) || |
|
337 | + ( 'read_private_wordlift_entities' === $cap[0] ) || |
|
338 | + ( 'delete_wordlift_entity' === $cap[0] ) || |
|
339 | + ( 'delete_wordlift_entities' === $cap[0] ) || |
|
340 | + ( 'delete_others_wordlift_entities' === $cap[0] ) || |
|
341 | + ( 'delete_published_wordlift_entities' === $cap[0] ) || |
|
342 | + ( 'delete_private_wordlift_entities' === $cap[0] ) |
|
343 | + ) { |
|
344 | + $user_id = $args[1]; |
|
345 | + |
|
346 | + if ( ! $this->editor_can_create_entities( $user_id ) ) { |
|
347 | + $allcaps[ $cap[0] ] = false; |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + return $allcaps; |
|
352 | + } |
|
353 | 353 | |
354 | 354 | } |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | */ |
57 | 57 | protected function __construct() { |
58 | 58 | |
59 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' ); |
|
59 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_User_Service'); |
|
60 | 60 | |
61 | - add_filter( 'user_has_cap', array( $this, 'has_cap' ), 10, 3 ); |
|
61 | + add_filter('user_has_cap', array($this, 'has_cap'), 10, 3); |
|
62 | 62 | |
63 | 63 | } |
64 | 64 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public static function get_instance() { |
81 | 81 | |
82 | - if ( ! isset( self::$instance ) ) { |
|
82 | + if ( ! isset(self::$instance)) { |
|
83 | 83 | self::$instance = new self(); |
84 | 84 | } |
85 | 85 | |
@@ -94,23 +94,23 @@ discard block |
||
94 | 94 | * @return false|string The user's URI or false in case of failure. |
95 | 95 | * @since 3.1.7 |
96 | 96 | */ |
97 | - public function get_uri( $user_id ) { |
|
97 | + public function get_uri($user_id) { |
|
98 | 98 | |
99 | 99 | // Try to get the URI stored in the user's meta and return it if available. |
100 | 100 | $dataset_uri = wl_configuration_get_redlink_dataset_uri(); |
101 | - $user_uri = $this->_get_uri( $user_id ); |
|
102 | - if ( ! empty( $dataset_uri ) && ! empty( $user_uri ) && 0 === strpos( $user_uri, $dataset_uri ) ) { |
|
101 | + $user_uri = $this->_get_uri($user_id); |
|
102 | + if ( ! empty($dataset_uri) && ! empty($user_uri) && 0 === strpos($user_uri, $dataset_uri)) { |
|
103 | 103 | return $user_uri; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Try to build an URI, return false in case of failure. |
107 | - $user_uri = $this->_build_uri( $user_id ); |
|
108 | - if ( false === $user_uri ) { |
|
107 | + $user_uri = $this->_build_uri($user_id); |
|
108 | + if (false === $user_uri) { |
|
109 | 109 | return false; |
110 | 110 | } |
111 | 111 | |
112 | 112 | // Store the URI for future requests (we need a "permanent" URI). |
113 | - $this->_set_uri( $user_id, $user_uri ); |
|
113 | + $this->_set_uri($user_id, $user_uri); |
|
114 | 114 | |
115 | 115 | return $user_uri; |
116 | 116 | } |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | * @return bool|int Meta ID if the key didn't exist, true on successful update, false on failure. |
127 | 127 | * @since 3.14.0 |
128 | 128 | */ |
129 | - public function set_entity( $user_id, $value ) { |
|
129 | + public function set_entity($user_id, $value) { |
|
130 | 130 | |
131 | 131 | return 0 < $value |
132 | - ? update_user_meta( $user_id, self::ENTITY_META_KEY, $value ) |
|
133 | - : delete_user_meta( $user_id, self::ENTITY_META_KEY ); |
|
132 | + ? update_user_meta($user_id, self::ENTITY_META_KEY, $value) |
|
133 | + : delete_user_meta($user_id, self::ENTITY_META_KEY); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @return string|false The entity {@link WP_Post} `id` or an empty string if not set or false if the object id is invalid |
142 | 142 | * @since 3.14.0 |
143 | 143 | */ |
144 | - public function get_entity( $user_id ) { |
|
144 | + public function get_entity($user_id) { |
|
145 | 145 | |
146 | - return get_user_meta( $user_id, self::ENTITY_META_KEY, true ); |
|
146 | + return get_user_meta($user_id, self::ENTITY_META_KEY, true); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | * @since 3.1.7 |
156 | 156 | */ |
157 | 157 | // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
158 | - private function _get_uri( $user_id ) { |
|
158 | + private function _get_uri($user_id) { |
|
159 | 159 | |
160 | - $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true ); |
|
160 | + $user_uri = get_user_meta($user_id, self::URI_META_KEY, true); |
|
161 | 161 | |
162 | - if ( empty( $user_uri ) ) { |
|
162 | + if (empty($user_uri)) { |
|
163 | 163 | return false; |
164 | 164 | } |
165 | 165 | |
@@ -175,16 +175,16 @@ discard block |
||
175 | 175 | * @since 3.1.7 |
176 | 176 | */ |
177 | 177 | // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
178 | - private function _build_uri( $user_id ) { |
|
178 | + private function _build_uri($user_id) { |
|
179 | 179 | |
180 | 180 | // Get the user, return false in case of failure. |
181 | - $user = get_userdata( $user_id ); |
|
182 | - if ( false === $user ) { |
|
181 | + $user = get_userdata($user_id); |
|
182 | + if (false === $user) { |
|
183 | 183 | return false; |
184 | 184 | }; |
185 | 185 | |
186 | 186 | // If the nicename is not set, return a failure. |
187 | - if ( empty( $user->user_nicename ) ) { |
|
187 | + if (empty($user->user_nicename)) { |
|
188 | 188 | return false; |
189 | 189 | } |
190 | 190 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @since 3.27.7 changed `user` to `author` to avoid potential clashes with CPTs ( `author` is reserved |
193 | 193 | * https://developer.wordpress.org/reference/functions/register_post_type/#reserved-post-types ) |
194 | 194 | */ |
195 | - return untrailingslashit( wl_configuration_get_redlink_dataset_uri() ) . "/author/$user->user_nicename"; |
|
195 | + return untrailingslashit(wl_configuration_get_redlink_dataset_uri())."/author/$user->user_nicename"; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | * @since 3.1.7 |
206 | 206 | */ |
207 | 207 | // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore |
208 | - private function _set_uri( $user_id, $user_uri ) { |
|
208 | + private function _set_uri($user_id, $user_uri) { |
|
209 | 209 | |
210 | - return update_user_meta( $user_id, self::URI_META_KEY, $user_uri ); |
|
210 | + return update_user_meta($user_id, self::URI_META_KEY, $user_uri); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -218,15 +218,15 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @since 3.14.0 |
220 | 220 | */ |
221 | - public function deny_editor_entity_create( $user_id ) { |
|
221 | + public function deny_editor_entity_create($user_id) { |
|
222 | 222 | |
223 | 223 | // Bail out if the user is not an editor. |
224 | - if ( ! $this->is_editor( $user_id ) ) { |
|
224 | + if ( ! $this->is_editor($user_id)) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | 228 | // The user explicitly do not have the capability. |
229 | - update_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes' ); |
|
229 | + update_user_option($user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes'); |
|
230 | 230 | |
231 | 231 | } |
232 | 232 | |
@@ -238,15 +238,15 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @since 3.14.0 |
240 | 240 | */ |
241 | - public function allow_editor_entity_create( $user_id ) { |
|
241 | + public function allow_editor_entity_create($user_id) { |
|
242 | 242 | |
243 | 243 | // Bail out if the user is not an editor. |
244 | - if ( ! $this->is_editor( $user_id ) ) { |
|
244 | + if ( ! $this->is_editor($user_id)) { |
|
245 | 245 | return; |
246 | 246 | } |
247 | 247 | |
248 | 248 | // The user explicitly do not have the capability. |
249 | - delete_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY ); |
|
249 | + delete_user_option($user_id, self::DENY_ENTITY_CREATE_META_KEY); |
|
250 | 250 | |
251 | 251 | } |
252 | 252 | |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | * @return int bool True if editing is denied otherwise false. |
259 | 259 | * @since 3.14.0 |
260 | 260 | */ |
261 | - public function is_deny_editor_entity_create( $user_id ) { |
|
261 | + public function is_deny_editor_entity_create($user_id) { |
|
262 | 262 | |
263 | - return 'yes' === get_user_option( self::DENY_ENTITY_CREATE_META_KEY, $user_id ); |
|
263 | + return 'yes' === get_user_option(self::DENY_ENTITY_CREATE_META_KEY, $user_id); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -272,13 +272,13 @@ discard block |
||
272 | 272 | * @return bool True if the {@link WP_User} is an editor otherwise false. |
273 | 273 | * @since 3.14.0 |
274 | 274 | */ |
275 | - public function is_editor( $user_id ) { |
|
275 | + public function is_editor($user_id) { |
|
276 | 276 | |
277 | 277 | // Get the user. |
278 | - $user = get_user_by( 'id', $user_id ); |
|
278 | + $user = get_user_by('id', $user_id); |
|
279 | 279 | |
280 | 280 | // Return true, if the user is found and has the `editor` role. |
281 | - return is_a( $user, 'WP_User' ) && in_array( 'editor', (array) $user->roles, true ); |
|
281 | + return is_a($user, 'WP_User') && in_array('editor', (array) $user->roles, true); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -289,15 +289,15 @@ discard block |
||
289 | 289 | * @return bool false if it is an editor that is denied from edit entities, true otherwise. |
290 | 290 | * @since 3.14.0 |
291 | 291 | */ |
292 | - public function editor_can_create_entities( $user_id ) { |
|
292 | + public function editor_can_create_entities($user_id) { |
|
293 | 293 | |
294 | 294 | // Return true if not an editor. |
295 | - if ( ! $this->is_editor( $user_id ) ) { |
|
295 | + if ( ! $this->is_editor($user_id)) { |
|
296 | 296 | return true; |
297 | 297 | } |
298 | 298 | |
299 | 299 | // Check if the user explicitly denied. |
300 | - return ! $this->is_deny_editor_entity_create( $user_id ); |
|
300 | + return ! $this->is_deny_editor_entity_create($user_id); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | * @return array The capabilities array. |
315 | 315 | * @since 3.14.0 |
316 | 316 | */ |
317 | - public function has_cap( $allcaps, $cap, $args ) { |
|
317 | + public function has_cap($allcaps, $cap, $args) { |
|
318 | 318 | /* |
319 | 319 | * For entity management/editing related capabilities |
320 | 320 | * check that an editor was not explicitly denied (in user profile) |
@@ -325,26 +325,26 @@ discard block |
||
325 | 325 | * Need protection against the case of edit_user and likes which do not |
326 | 326 | * require a capability, just request one. |
327 | 327 | */ |
328 | - if ( empty( $cap ) || ! isset( $cap[0] ) ) { |
|
328 | + if (empty($cap) || ! isset($cap[0])) { |
|
329 | 329 | return $allcaps; |
330 | 330 | } |
331 | 331 | |
332 | 332 | if ( |
333 | - ( 'edit_wordlift_entity' === $cap[0] ) || |
|
334 | - ( 'edit_wordlift_entities' === $cap[0] ) || |
|
335 | - ( 'edit_others_wordlift_entities' === $cap[0] ) || |
|
336 | - ( 'publish_wordlift_entities' === $cap[0] ) || |
|
337 | - ( 'read_private_wordlift_entities' === $cap[0] ) || |
|
338 | - ( 'delete_wordlift_entity' === $cap[0] ) || |
|
339 | - ( 'delete_wordlift_entities' === $cap[0] ) || |
|
340 | - ( 'delete_others_wordlift_entities' === $cap[0] ) || |
|
341 | - ( 'delete_published_wordlift_entities' === $cap[0] ) || |
|
342 | - ( 'delete_private_wordlift_entities' === $cap[0] ) |
|
333 | + ('edit_wordlift_entity' === $cap[0]) || |
|
334 | + ('edit_wordlift_entities' === $cap[0]) || |
|
335 | + ('edit_others_wordlift_entities' === $cap[0]) || |
|
336 | + ('publish_wordlift_entities' === $cap[0]) || |
|
337 | + ('read_private_wordlift_entities' === $cap[0]) || |
|
338 | + ('delete_wordlift_entity' === $cap[0]) || |
|
339 | + ('delete_wordlift_entities' === $cap[0]) || |
|
340 | + ('delete_others_wordlift_entities' === $cap[0]) || |
|
341 | + ('delete_published_wordlift_entities' === $cap[0]) || |
|
342 | + ('delete_private_wordlift_entities' === $cap[0]) |
|
343 | 343 | ) { |
344 | 344 | $user_id = $args[1]; |
345 | 345 | |
346 | - if ( ! $this->editor_can_create_entities( $user_id ) ) { |
|
347 | - $allcaps[ $cap[0] ] = false; |
|
346 | + if ( ! $this->editor_can_create_entities($user_id)) { |
|
347 | + $allcaps[$cap[0]] = false; |
|
348 | 348 | } |
349 | 349 | } |
350 | 350 |
@@ -17,59 +17,59 @@ |
||
17 | 17 | */ |
18 | 18 | class Wordlift_Sample_Data_Ajax_Adapter { |
19 | 19 | |
20 | - /** |
|
21 | - * The {@link Wordlift_Sample_Data_Service} instance. |
|
22 | - * |
|
23 | - * @since 3.12.0 |
|
24 | - * @access private |
|
25 | - * @var \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
|
26 | - */ |
|
27 | - private $sample_data_service; |
|
20 | + /** |
|
21 | + * The {@link Wordlift_Sample_Data_Service} instance. |
|
22 | + * |
|
23 | + * @since 3.12.0 |
|
24 | + * @access private |
|
25 | + * @var \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
|
26 | + */ |
|
27 | + private $sample_data_service; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Create a {@link Wordlift_Sample_Data_Ajax_Adapter} instance. |
|
31 | - * |
|
32 | - * @since 3.12.0 |
|
33 | - * |
|
34 | - * @param \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
|
35 | - */ |
|
36 | - public function __construct( $sample_data_service ) { |
|
29 | + /** |
|
30 | + * Create a {@link Wordlift_Sample_Data_Ajax_Adapter} instance. |
|
31 | + * |
|
32 | + * @since 3.12.0 |
|
33 | + * |
|
34 | + * @param \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
|
35 | + */ |
|
36 | + public function __construct( $sample_data_service ) { |
|
37 | 37 | |
38 | - $this->sample_data_service = $sample_data_service; |
|
38 | + $this->sample_data_service = $sample_data_service; |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Handle the `wl_sample_data_create` ajax action. |
|
44 | - * |
|
45 | - * @since 3.12.0 |
|
46 | - */ |
|
47 | - public function create() { |
|
42 | + /** |
|
43 | + * Handle the `wl_sample_data_create` ajax action. |
|
44 | + * |
|
45 | + * @since 3.12.0 |
|
46 | + */ |
|
47 | + public function create() { |
|
48 | 48 | |
49 | - // Clean any potential garbage before us. |
|
50 | - ob_clean(); |
|
49 | + // Clean any potential garbage before us. |
|
50 | + ob_clean(); |
|
51 | 51 | |
52 | - // Create the sample data. |
|
53 | - $this->sample_data_service->create(); |
|
52 | + // Create the sample data. |
|
53 | + $this->sample_data_service->create(); |
|
54 | 54 | |
55 | - // Send success. |
|
56 | - wp_send_json_success(); |
|
55 | + // Send success. |
|
56 | + wp_send_json_success(); |
|
57 | 57 | |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - public function delete() { |
|
60 | + public function delete() { |
|
61 | 61 | |
62 | - // Clean any potential garbage before us. |
|
63 | - ob_clean(); |
|
62 | + // Clean any potential garbage before us. |
|
63 | + ob_clean(); |
|
64 | 64 | |
65 | - // Create the sample data. |
|
66 | - $this->sample_data_service->delete(); |
|
65 | + // Create the sample data. |
|
66 | + $this->sample_data_service->delete(); |
|
67 | 67 | |
68 | - // Send success. |
|
69 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
70 | - @header( 'Content-Disposition: inline' ); |
|
71 | - wp_send_json_success(); |
|
68 | + // Send success. |
|
69 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
70 | + @header( 'Content-Disposition: inline' ); |
|
71 | + wp_send_json_success(); |
|
72 | 72 | |
73 | - } |
|
73 | + } |
|
74 | 74 | |
75 | 75 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @param \Wordlift_Sample_Data_Service $sample_data_service The {@link Wordlift_Sample_Data_Service} instance. |
35 | 35 | */ |
36 | - public function __construct( $sample_data_service ) { |
|
36 | + public function __construct($sample_data_service) { |
|
37 | 37 | |
38 | 38 | $this->sample_data_service = $sample_data_service; |
39 | 39 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | // Send success. |
69 | 69 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
70 | - @header( 'Content-Disposition: inline' ); |
|
70 | + @header('Content-Disposition: inline'); |
|
71 | 71 | wp_send_json_success(); |
72 | 72 | |
73 | 73 | } |
@@ -26,38 +26,38 @@ |
||
26 | 26 | */ |
27 | 27 | class Wordlift_I18n { |
28 | 28 | |
29 | - /** |
|
30 | - * The domain specified for this plugin. |
|
31 | - * |
|
32 | - * @since 1.0.0 |
|
33 | - * @access private |
|
34 | - * @var string $domain The domain identifier for this plugin. |
|
35 | - */ |
|
36 | - private $domain; |
|
37 | - |
|
38 | - /** |
|
39 | - * Load the plugin text domain for translation. |
|
40 | - * |
|
41 | - * @since 1.0.0 |
|
42 | - */ |
|
43 | - public function load_plugin_textdomain() { |
|
44 | - |
|
45 | - load_plugin_textdomain( |
|
46 | - $this->domain, |
|
47 | - false, |
|
48 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
49 | - ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Set the domain equal to that of the specified domain. |
|
55 | - * |
|
56 | - * @since 1.0.0 |
|
57 | - * @param string $domain The domain that represents the locale of this plugin. |
|
58 | - */ |
|
59 | - public function set_domain( $domain ) { |
|
60 | - $this->domain = $domain; |
|
61 | - } |
|
29 | + /** |
|
30 | + * The domain specified for this plugin. |
|
31 | + * |
|
32 | + * @since 1.0.0 |
|
33 | + * @access private |
|
34 | + * @var string $domain The domain identifier for this plugin. |
|
35 | + */ |
|
36 | + private $domain; |
|
37 | + |
|
38 | + /** |
|
39 | + * Load the plugin text domain for translation. |
|
40 | + * |
|
41 | + * @since 1.0.0 |
|
42 | + */ |
|
43 | + public function load_plugin_textdomain() { |
|
44 | + |
|
45 | + load_plugin_textdomain( |
|
46 | + $this->domain, |
|
47 | + false, |
|
48 | + dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
49 | + ); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Set the domain equal to that of the specified domain. |
|
55 | + * |
|
56 | + * @since 1.0.0 |
|
57 | + * @param string $domain The domain that represents the locale of this plugin. |
|
58 | + */ |
|
59 | + public function set_domain( $domain ) { |
|
60 | + $this->domain = $domain; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | load_plugin_textdomain( |
46 | 46 | $this->domain, |
47 | 47 | false, |
48 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
48 | + dirname(dirname(plugin_basename(__FILE__))).'/languages/' |
|
49 | 49 | ); |
50 | 50 | |
51 | 51 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @since 1.0.0 |
57 | 57 | * @param string $domain The domain that represents the locale of this plugin. |
58 | 58 | */ |
59 | - public function set_domain( $domain ) { |
|
59 | + public function set_domain($domain) { |
|
60 | 60 | $this->domain = $domain; |
61 | 61 | } |
62 | 62 |