@@ -16,33 +16,33 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Related_Entities_Cloud_Widget extends Wordlift_Widget { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Create an {@link Wordlift_Related_Entities_Cloud_Widget} instance. |
|
| 21 | - * |
|
| 22 | - * @since 3.11.0 |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 25 | - parent::__construct( |
|
| 26 | - 'wl_related_entities_cloud', |
|
| 27 | - __( 'WordLift Entities Cloud', 'wordlift' ), |
|
| 28 | - array( |
|
| 29 | - 'classname' => 'wl_related_entities_cloud', |
|
| 30 | - 'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ), |
|
| 31 | - ) |
|
| 32 | - ); |
|
| 33 | - |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @inheritdoc |
|
| 38 | - */ |
|
| 39 | - public function form( $instance ) { |
|
| 40 | - $title_id = $this->get_field_id( 'title' ); |
|
| 41 | - $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
| 42 | - ?> |
|
| 19 | + /** |
|
| 20 | + * Create an {@link Wordlift_Related_Entities_Cloud_Widget} instance. |
|
| 21 | + * |
|
| 22 | + * @since 3.11.0 |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | + parent::__construct( |
|
| 26 | + 'wl_related_entities_cloud', |
|
| 27 | + __( 'WordLift Entities Cloud', 'wordlift' ), |
|
| 28 | + array( |
|
| 29 | + 'classname' => 'wl_related_entities_cloud', |
|
| 30 | + 'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ), |
|
| 31 | + ) |
|
| 32 | + ); |
|
| 33 | + |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @inheritdoc |
|
| 38 | + */ |
|
| 39 | + public function form( $instance ) { |
|
| 40 | + $title_id = $this->get_field_id( 'title' ); |
|
| 41 | + $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
| 42 | + ?> |
|
| 43 | 43 | |
| 44 | 44 | <p><label for="<?php echo esc_attr( $title_id ); ?>"><?php |
| 45 | - esc_html_e( 'Title:' ); ?></label> |
|
| 45 | + esc_html_e( 'Title:' ); ?></label> |
|
| 46 | 46 | <input type="text" class="widefat" |
| 47 | 47 | id="<?php echo esc_attr( $title_id ); ?>" |
| 48 | 48 | name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" |
@@ -51,46 +51,46 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | <?php |
| 53 | 53 | |
| 54 | - return 'wl_related_entities_cloud_form'; |
|
| 55 | - } |
|
| 54 | + return 'wl_related_entities_cloud_form'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @inheritdoc |
|
| 59 | - */ |
|
| 60 | - public function update( $new_instance, $old_instance ) { |
|
| 57 | + /** |
|
| 58 | + * @inheritdoc |
|
| 59 | + */ |
|
| 60 | + public function update( $new_instance, $old_instance ) { |
|
| 61 | 61 | |
| 62 | - return array( 'title' => sanitize_text_field( $new_instance['title'] ) ); |
|
| 63 | - } |
|
| 62 | + return array( 'title' => sanitize_text_field( $new_instance['title'] ) ); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @inheritdoc |
|
| 67 | - */ |
|
| 68 | - public function widget( $args, $instance ) { |
|
| 65 | + /** |
|
| 66 | + * @inheritdoc |
|
| 67 | + */ |
|
| 68 | + public function widget( $args, $instance ) { |
|
| 69 | 69 | |
| 70 | - /* |
|
| 70 | + /* |
|
| 71 | 71 | * Use the shortcode to calculate the HTML required to show the cloud |
| 72 | 72 | * if there is no such html do not render the widget at all. |
| 73 | 73 | */ |
| 74 | - $cloud_html = do_shortcode( '[wl_cloud]' ); |
|
| 75 | - if ( empty( $cloud_html ) ) { |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 74 | + $cloud_html = do_shortcode( '[wl_cloud]' ); |
|
| 75 | + if ( empty( $cloud_html ) ) { |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - // The widget title. |
|
| 80 | - $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title']; |
|
| 79 | + // The widget title. |
|
| 80 | + $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title']; |
|
| 81 | 81 | |
| 82 | - // Standard filter all widgets should apply |
|
| 83 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
| 82 | + // Standard filter all widgets should apply |
|
| 83 | + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
| 84 | 84 | |
| 85 | - echo $args['before_widget']; |
|
| 85 | + echo $args['before_widget']; |
|
| 86 | 86 | |
| 87 | - if ( $title ) { |
|
| 88 | - echo $args['before_title'] . $title . $args['after_title']; |
|
| 89 | - } |
|
| 87 | + if ( $title ) { |
|
| 88 | + echo $args['before_title'] . $title . $args['after_title']; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - echo $cloud_html; |
|
| 92 | - echo $args['after_widget']; |
|
| 91 | + echo $cloud_html; |
|
| 92 | + echo $args['after_widget']; |
|
| 93 | 93 | |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | } |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | public function __construct() { |
| 25 | 25 | parent::__construct( |
| 26 | 26 | 'wl_related_entities_cloud', |
| 27 | - __( 'WordLift Entities Cloud', 'wordlift' ), |
|
| 27 | + __('WordLift Entities Cloud', 'wordlift'), |
|
| 28 | 28 | array( |
| 29 | 29 | 'classname' => 'wl_related_entities_cloud', |
| 30 | - 'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ), |
|
| 30 | + 'description' => __('Display entities related to the current post/entity in a tag cloud.', 'wordlift'), |
|
| 31 | 31 | ) |
| 32 | 32 | ); |
| 33 | 33 | |
@@ -36,17 +36,17 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @inheritdoc |
| 38 | 38 | */ |
| 39 | - public function form( $instance ) { |
|
| 40 | - $title_id = $this->get_field_id( 'title' ); |
|
| 41 | - $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
| 39 | + public function form($instance) { |
|
| 40 | + $title_id = $this->get_field_id('title'); |
|
| 41 | + $instance['title'] = ! empty($instance['title']) ? esc_attr($instance['title']) : ''; |
|
| 42 | 42 | ?> |
| 43 | 43 | |
| 44 | - <p><label for="<?php echo esc_attr( $title_id ); ?>"><?php |
|
| 45 | - esc_html_e( 'Title:' ); ?></label> |
|
| 44 | + <p><label for="<?php echo esc_attr($title_id); ?>"><?php |
|
| 45 | + esc_html_e('Title:'); ?></label> |
|
| 46 | 46 | <input type="text" class="widefat" |
| 47 | - id="<?php echo esc_attr( $title_id ); ?>" |
|
| 48 | - name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" |
|
| 49 | - value="<?php echo esc_attr( $instance['title'] ); ?>" /> |
|
| 47 | + id="<?php echo esc_attr($title_id); ?>" |
|
| 48 | + name="<?php echo esc_attr($this->get_field_name('title')); ?>" |
|
| 49 | + value="<?php echo esc_attr($instance['title']); ?>" /> |
|
| 50 | 50 | </p> |
| 51 | 51 | |
| 52 | 52 | <?php |
@@ -57,35 +57,35 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @inheritdoc |
| 59 | 59 | */ |
| 60 | - public function update( $new_instance, $old_instance ) { |
|
| 60 | + public function update($new_instance, $old_instance) { |
|
| 61 | 61 | |
| 62 | - return array( 'title' => sanitize_text_field( $new_instance['title'] ) ); |
|
| 62 | + return array('title' => sanitize_text_field($new_instance['title'])); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * @inheritdoc |
| 67 | 67 | */ |
| 68 | - public function widget( $args, $instance ) { |
|
| 68 | + public function widget($args, $instance) { |
|
| 69 | 69 | |
| 70 | 70 | /* |
| 71 | 71 | * Use the shortcode to calculate the HTML required to show the cloud |
| 72 | 72 | * if there is no such html do not render the widget at all. |
| 73 | 73 | */ |
| 74 | - $cloud_html = do_shortcode( '[wl_cloud]' ); |
|
| 75 | - if ( empty( $cloud_html ) ) { |
|
| 74 | + $cloud_html = do_shortcode('[wl_cloud]'); |
|
| 75 | + if (empty($cloud_html)) { |
|
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // The widget title. |
| 80 | - $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title']; |
|
| 80 | + $title = empty($instance['title']) ? __('Related Entities', 'wordlift') : $instance['title']; |
|
| 81 | 81 | |
| 82 | 82 | // Standard filter all widgets should apply |
| 83 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
| 83 | + $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
|
| 84 | 84 | |
| 85 | 85 | echo $args['before_widget']; |
| 86 | 86 | |
| 87 | - if ( $title ) { |
|
| 88 | - echo $args['before_title'] . $title . $args['after_title']; |
|
| 87 | + if ($title) { |
|
| 88 | + echo $args['before_title'].$title.$args['after_title']; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | echo $cloud_html; |
@@ -7,174 +7,174 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Topic_Taxonomy_Service { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * The Log service. |
|
| 12 | - * |
|
| 13 | - * @since 3.5.0 |
|
| 14 | - * @access private |
|
| 15 | - * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 16 | - */ |
|
| 17 | - private $log_service; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Taxonomy name. |
|
| 21 | - * |
|
| 22 | - * @since 3.5.0 |
|
| 23 | - */ |
|
| 24 | - const TAXONOMY_NAME = 'wl_topic'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Taxonomy object type. |
|
| 28 | - * |
|
| 29 | - * @since 3.5.0 |
|
| 30 | - */ |
|
| 31 | - const TAXONOMY_OBJECT_TYPE = 'post'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Taxonomy slug. |
|
| 35 | - * |
|
| 36 | - * @since 3.5.0 |
|
| 37 | - */ |
|
| 38 | - const TAXONOMY_SLUG = 'wl_topic'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * A singleton instance of the Wordlift_Topic_Taxonomy_Service service. |
|
| 42 | - * |
|
| 43 | - * @since 3.5.0 |
|
| 44 | - * @access private |
|
| 45 | - * @var \Wordlift_Topic_Taxonomy_Service $instance A singleton instance of Wordlift_Topic_Taxonomy_Service. |
|
| 46 | - */ |
|
| 47 | - private static $instance; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Create a Wordlift_Topic_Taxonomy_Service instance. |
|
| 51 | - * |
|
| 52 | - * @since 3.5.0 |
|
| 53 | - * |
|
| 54 | - */ |
|
| 55 | - public function __construct() { |
|
| 56 | - |
|
| 57 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' ); |
|
| 58 | - |
|
| 59 | - // Set the singleton instance. |
|
| 60 | - self::$instance = $this; |
|
| 61 | - |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the singleton instance of the Entity service. |
|
| 66 | - * |
|
| 67 | - * @since 3.5.0 |
|
| 68 | - * @return Wordlift_Topic_Taxonomy_Service |
|
| 69 | - */ |
|
| 70 | - public static function get_instance() { |
|
| 71 | - |
|
| 72 | - return self::$instance; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Just register the topic taxonomy. |
|
| 77 | - * |
|
| 78 | - * @since 3.5.0 |
|
| 79 | - * |
|
| 80 | - */ |
|
| 81 | - public function init() { |
|
| 82 | - |
|
| 83 | - // See https://codex.wordpress.org/Function_Reference/register_taxonomy |
|
| 84 | - $labels = array( |
|
| 85 | - 'name' => _x( 'Topics', 'taxonomy general name', 'wordlift' ), |
|
| 86 | - 'singular_name' => _x( 'Topic', 'taxonomy singular name', 'wordlift' ), |
|
| 87 | - 'search_items' => __( 'Search Topics', 'wordlift' ), |
|
| 88 | - 'all_items' => __( 'All Topics', 'wordlift' ), |
|
| 89 | - 'parent_item' => __( 'Parent Topic', 'wordlift' ), |
|
| 90 | - 'parent_item_colon' => __( 'Parent Topic:', 'wordlift' ), |
|
| 91 | - 'edit_item' => __( 'Edit Topic', 'wordlift' ), |
|
| 92 | - 'update_item' => __( 'Update Topic', 'wordlift' ), |
|
| 93 | - 'add_new_item' => __( 'Add New Topic', 'wordlift' ), |
|
| 94 | - 'new_item_name' => __( 'New Topic', 'wordlift' ), |
|
| 95 | - 'menu_name' => __( 'Topics', 'wordlift' ), |
|
| 96 | - ); |
|
| 97 | - |
|
| 98 | - $capabilities = array( |
|
| 99 | - 'manage_terms' => null, |
|
| 100 | - 'edit_terms' => null, |
|
| 101 | - 'delete_terms' => null, |
|
| 102 | - 'assign_terms' => 'edit_posts', |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - $args = array( |
|
| 106 | - 'labels' => $labels, |
|
| 107 | - 'capabilities' => $capabilities, |
|
| 108 | - 'hierarchical' => true, |
|
| 109 | - 'show_admin_column' => false, |
|
| 110 | - 'show_ui' => false, |
|
| 111 | - 'rewrite' => array( |
|
| 112 | - 'slug' => self::TAXONOMY_SLUG, |
|
| 113 | - ), |
|
| 114 | - ); |
|
| 115 | - |
|
| 116 | - // Register taxonomy |
|
| 117 | - register_taxonomy( |
|
| 118 | - self::TAXONOMY_NAME, self::TAXONOMY_OBJECT_TYPE, $args |
|
| 119 | - ); |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get or create a taxonomy term from a given entity topic. |
|
| 125 | - * |
|
| 126 | - * @since 3.5.0 |
|
| 127 | - * |
|
| 128 | - */ |
|
| 129 | - public function get_or_create_term_from_topic_entity( $topic ) { |
|
| 130 | - |
|
| 131 | - // Define taxonomy term slug |
|
| 132 | - $term_slug = sanitize_title( $topic->post_title ); |
|
| 133 | - // Look for an existing taxonomy term with a given slug |
|
| 134 | - if ( $term = get_term_by( 'slug', $term_slug, self::TAXONOMY_NAME ) ) { |
|
| 135 | - return (int) $term->term_id; |
|
| 136 | - } |
|
| 137 | - // Otherwise create a new term and return it |
|
| 138 | - $result = wp_insert_term( |
|
| 139 | - $topic->post_title, |
|
| 140 | - self::TAXONOMY_NAME, |
|
| 141 | - array( |
|
| 142 | - 'slug' => $term_slug, |
|
| 143 | - 'description' => $topic->post_content, |
|
| 144 | - ) |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - return (int) $result['term_id']; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Set a topic for a given post. |
|
| 152 | - * |
|
| 153 | - * @since 3.5.0 |
|
| 154 | - * |
|
| 155 | - */ |
|
| 156 | - public function set_topic_for( $post_id, $topic_id ) { |
|
| 157 | - // Retrieve the topic entity post |
|
| 158 | - $topic_entity_post = get_post( $topic_id ); |
|
| 159 | - // If current topic does not exist in db false is returned |
|
| 160 | - if ( null === $topic_entity_post ) { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - // Create the proper taxonomy term if needed |
|
| 164 | - $term_id = $this->get_or_create_term_from_topic_entity( $topic_entity_post ); |
|
| 165 | - // Link the term to the current post |
|
| 166 | - wp_set_post_terms( $post_id, $term_id, self::TAXONOMY_NAME, false ); |
|
| 167 | - return true; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Unlink any topic for a given post. |
|
| 172 | - * |
|
| 173 | - * @since 3.5.0 |
|
| 174 | - * |
|
| 175 | - */ |
|
| 176 | - public function unlink_topic_for( $post_id ) { |
|
| 177 | - wp_delete_object_term_relationships( $post_id, self::TAXONOMY_NAME ); |
|
| 178 | - } |
|
| 10 | + /** |
|
| 11 | + * The Log service. |
|
| 12 | + * |
|
| 13 | + * @since 3.5.0 |
|
| 14 | + * @access private |
|
| 15 | + * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 16 | + */ |
|
| 17 | + private $log_service; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Taxonomy name. |
|
| 21 | + * |
|
| 22 | + * @since 3.5.0 |
|
| 23 | + */ |
|
| 24 | + const TAXONOMY_NAME = 'wl_topic'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Taxonomy object type. |
|
| 28 | + * |
|
| 29 | + * @since 3.5.0 |
|
| 30 | + */ |
|
| 31 | + const TAXONOMY_OBJECT_TYPE = 'post'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Taxonomy slug. |
|
| 35 | + * |
|
| 36 | + * @since 3.5.0 |
|
| 37 | + */ |
|
| 38 | + const TAXONOMY_SLUG = 'wl_topic'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * A singleton instance of the Wordlift_Topic_Taxonomy_Service service. |
|
| 42 | + * |
|
| 43 | + * @since 3.5.0 |
|
| 44 | + * @access private |
|
| 45 | + * @var \Wordlift_Topic_Taxonomy_Service $instance A singleton instance of Wordlift_Topic_Taxonomy_Service. |
|
| 46 | + */ |
|
| 47 | + private static $instance; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Create a Wordlift_Topic_Taxonomy_Service instance. |
|
| 51 | + * |
|
| 52 | + * @since 3.5.0 |
|
| 53 | + * |
|
| 54 | + */ |
|
| 55 | + public function __construct() { |
|
| 56 | + |
|
| 57 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' ); |
|
| 58 | + |
|
| 59 | + // Set the singleton instance. |
|
| 60 | + self::$instance = $this; |
|
| 61 | + |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the singleton instance of the Entity service. |
|
| 66 | + * |
|
| 67 | + * @since 3.5.0 |
|
| 68 | + * @return Wordlift_Topic_Taxonomy_Service |
|
| 69 | + */ |
|
| 70 | + public static function get_instance() { |
|
| 71 | + |
|
| 72 | + return self::$instance; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Just register the topic taxonomy. |
|
| 77 | + * |
|
| 78 | + * @since 3.5.0 |
|
| 79 | + * |
|
| 80 | + */ |
|
| 81 | + public function init() { |
|
| 82 | + |
|
| 83 | + // See https://codex.wordpress.org/Function_Reference/register_taxonomy |
|
| 84 | + $labels = array( |
|
| 85 | + 'name' => _x( 'Topics', 'taxonomy general name', 'wordlift' ), |
|
| 86 | + 'singular_name' => _x( 'Topic', 'taxonomy singular name', 'wordlift' ), |
|
| 87 | + 'search_items' => __( 'Search Topics', 'wordlift' ), |
|
| 88 | + 'all_items' => __( 'All Topics', 'wordlift' ), |
|
| 89 | + 'parent_item' => __( 'Parent Topic', 'wordlift' ), |
|
| 90 | + 'parent_item_colon' => __( 'Parent Topic:', 'wordlift' ), |
|
| 91 | + 'edit_item' => __( 'Edit Topic', 'wordlift' ), |
|
| 92 | + 'update_item' => __( 'Update Topic', 'wordlift' ), |
|
| 93 | + 'add_new_item' => __( 'Add New Topic', 'wordlift' ), |
|
| 94 | + 'new_item_name' => __( 'New Topic', 'wordlift' ), |
|
| 95 | + 'menu_name' => __( 'Topics', 'wordlift' ), |
|
| 96 | + ); |
|
| 97 | + |
|
| 98 | + $capabilities = array( |
|
| 99 | + 'manage_terms' => null, |
|
| 100 | + 'edit_terms' => null, |
|
| 101 | + 'delete_terms' => null, |
|
| 102 | + 'assign_terms' => 'edit_posts', |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + $args = array( |
|
| 106 | + 'labels' => $labels, |
|
| 107 | + 'capabilities' => $capabilities, |
|
| 108 | + 'hierarchical' => true, |
|
| 109 | + 'show_admin_column' => false, |
|
| 110 | + 'show_ui' => false, |
|
| 111 | + 'rewrite' => array( |
|
| 112 | + 'slug' => self::TAXONOMY_SLUG, |
|
| 113 | + ), |
|
| 114 | + ); |
|
| 115 | + |
|
| 116 | + // Register taxonomy |
|
| 117 | + register_taxonomy( |
|
| 118 | + self::TAXONOMY_NAME, self::TAXONOMY_OBJECT_TYPE, $args |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get or create a taxonomy term from a given entity topic. |
|
| 125 | + * |
|
| 126 | + * @since 3.5.0 |
|
| 127 | + * |
|
| 128 | + */ |
|
| 129 | + public function get_or_create_term_from_topic_entity( $topic ) { |
|
| 130 | + |
|
| 131 | + // Define taxonomy term slug |
|
| 132 | + $term_slug = sanitize_title( $topic->post_title ); |
|
| 133 | + // Look for an existing taxonomy term with a given slug |
|
| 134 | + if ( $term = get_term_by( 'slug', $term_slug, self::TAXONOMY_NAME ) ) { |
|
| 135 | + return (int) $term->term_id; |
|
| 136 | + } |
|
| 137 | + // Otherwise create a new term and return it |
|
| 138 | + $result = wp_insert_term( |
|
| 139 | + $topic->post_title, |
|
| 140 | + self::TAXONOMY_NAME, |
|
| 141 | + array( |
|
| 142 | + 'slug' => $term_slug, |
|
| 143 | + 'description' => $topic->post_content, |
|
| 144 | + ) |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + return (int) $result['term_id']; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Set a topic for a given post. |
|
| 152 | + * |
|
| 153 | + * @since 3.5.0 |
|
| 154 | + * |
|
| 155 | + */ |
|
| 156 | + public function set_topic_for( $post_id, $topic_id ) { |
|
| 157 | + // Retrieve the topic entity post |
|
| 158 | + $topic_entity_post = get_post( $topic_id ); |
|
| 159 | + // If current topic does not exist in db false is returned |
|
| 160 | + if ( null === $topic_entity_post ) { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + // Create the proper taxonomy term if needed |
|
| 164 | + $term_id = $this->get_or_create_term_from_topic_entity( $topic_entity_post ); |
|
| 165 | + // Link the term to the current post |
|
| 166 | + wp_set_post_terms( $post_id, $term_id, self::TAXONOMY_NAME, false ); |
|
| 167 | + return true; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Unlink any topic for a given post. |
|
| 172 | + * |
|
| 173 | + * @since 3.5.0 |
|
| 174 | + * |
|
| 175 | + */ |
|
| 176 | + public function unlink_topic_for( $post_id ) { |
|
| 177 | + wp_delete_object_term_relationships( $post_id, self::TAXONOMY_NAME ); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function __construct() { |
| 56 | 56 | |
| 57 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' ); |
|
| 57 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_Service'); |
|
| 58 | 58 | |
| 59 | 59 | // Set the singleton instance. |
| 60 | 60 | self::$instance = $this; |
@@ -82,17 +82,17 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | // See https://codex.wordpress.org/Function_Reference/register_taxonomy |
| 84 | 84 | $labels = array( |
| 85 | - 'name' => _x( 'Topics', 'taxonomy general name', 'wordlift' ), |
|
| 86 | - 'singular_name' => _x( 'Topic', 'taxonomy singular name', 'wordlift' ), |
|
| 87 | - 'search_items' => __( 'Search Topics', 'wordlift' ), |
|
| 88 | - 'all_items' => __( 'All Topics', 'wordlift' ), |
|
| 89 | - 'parent_item' => __( 'Parent Topic', 'wordlift' ), |
|
| 90 | - 'parent_item_colon' => __( 'Parent Topic:', 'wordlift' ), |
|
| 91 | - 'edit_item' => __( 'Edit Topic', 'wordlift' ), |
|
| 92 | - 'update_item' => __( 'Update Topic', 'wordlift' ), |
|
| 93 | - 'add_new_item' => __( 'Add New Topic', 'wordlift' ), |
|
| 94 | - 'new_item_name' => __( 'New Topic', 'wordlift' ), |
|
| 95 | - 'menu_name' => __( 'Topics', 'wordlift' ), |
|
| 85 | + 'name' => _x('Topics', 'taxonomy general name', 'wordlift'), |
|
| 86 | + 'singular_name' => _x('Topic', 'taxonomy singular name', 'wordlift'), |
|
| 87 | + 'search_items' => __('Search Topics', 'wordlift'), |
|
| 88 | + 'all_items' => __('All Topics', 'wordlift'), |
|
| 89 | + 'parent_item' => __('Parent Topic', 'wordlift'), |
|
| 90 | + 'parent_item_colon' => __('Parent Topic:', 'wordlift'), |
|
| 91 | + 'edit_item' => __('Edit Topic', 'wordlift'), |
|
| 92 | + 'update_item' => __('Update Topic', 'wordlift'), |
|
| 93 | + 'add_new_item' => __('Add New Topic', 'wordlift'), |
|
| 94 | + 'new_item_name' => __('New Topic', 'wordlift'), |
|
| 95 | + 'menu_name' => __('Topics', 'wordlift'), |
|
| 96 | 96 | ); |
| 97 | 97 | |
| 98 | 98 | $capabilities = array( |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | * @since 3.5.0 |
| 127 | 127 | * |
| 128 | 128 | */ |
| 129 | - public function get_or_create_term_from_topic_entity( $topic ) { |
|
| 129 | + public function get_or_create_term_from_topic_entity($topic) { |
|
| 130 | 130 | |
| 131 | 131 | // Define taxonomy term slug |
| 132 | - $term_slug = sanitize_title( $topic->post_title ); |
|
| 132 | + $term_slug = sanitize_title($topic->post_title); |
|
| 133 | 133 | // Look for an existing taxonomy term with a given slug |
| 134 | - if ( $term = get_term_by( 'slug', $term_slug, self::TAXONOMY_NAME ) ) { |
|
| 134 | + if ($term = get_term_by('slug', $term_slug, self::TAXONOMY_NAME)) { |
|
| 135 | 135 | return (int) $term->term_id; |
| 136 | 136 | } |
| 137 | 137 | // Otherwise create a new term and return it |
@@ -153,17 +153,17 @@ discard block |
||
| 153 | 153 | * @since 3.5.0 |
| 154 | 154 | * |
| 155 | 155 | */ |
| 156 | - public function set_topic_for( $post_id, $topic_id ) { |
|
| 156 | + public function set_topic_for($post_id, $topic_id) { |
|
| 157 | 157 | // Retrieve the topic entity post |
| 158 | - $topic_entity_post = get_post( $topic_id ); |
|
| 158 | + $topic_entity_post = get_post($topic_id); |
|
| 159 | 159 | // If current topic does not exist in db false is returned |
| 160 | - if ( null === $topic_entity_post ) { |
|
| 160 | + if (null === $topic_entity_post) { |
|
| 161 | 161 | return false; |
| 162 | 162 | } |
| 163 | 163 | // Create the proper taxonomy term if needed |
| 164 | - $term_id = $this->get_or_create_term_from_topic_entity( $topic_entity_post ); |
|
| 164 | + $term_id = $this->get_or_create_term_from_topic_entity($topic_entity_post); |
|
| 165 | 165 | // Link the term to the current post |
| 166 | - wp_set_post_terms( $post_id, $term_id, self::TAXONOMY_NAME, false ); |
|
| 166 | + wp_set_post_terms($post_id, $term_id, self::TAXONOMY_NAME, false); |
|
| 167 | 167 | return true; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * @since 3.5.0 |
| 174 | 174 | * |
| 175 | 175 | */ |
| 176 | - public function unlink_topic_for( $post_id ) { |
|
| 177 | - wp_delete_object_term_relationships( $post_id, self::TAXONOMY_NAME ); |
|
| 176 | + public function unlink_topic_for($post_id) { |
|
| 177 | + wp_delete_object_term_relationships($post_id, self::TAXONOMY_NAME); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | } |
@@ -16,20 +16,20 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_NewRelic_Adapter { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Tell NewRelic to ignore this "transaction" for the Apdex. |
|
| 21 | - * |
|
| 22 | - * @see https://github.com/insideout10/wordlift-plugin/issues/521 |
|
| 23 | - * |
|
| 24 | - * @since 3.11.3 |
|
| 25 | - */ |
|
| 26 | - static function ignore_apdex() { |
|
| 19 | + /** |
|
| 20 | + * Tell NewRelic to ignore this "transaction" for the Apdex. |
|
| 21 | + * |
|
| 22 | + * @see https://github.com/insideout10/wordlift-plugin/issues/521 |
|
| 23 | + * |
|
| 24 | + * @since 3.11.3 |
|
| 25 | + */ |
|
| 26 | + static function ignore_apdex() { |
|
| 27 | 27 | |
| 28 | - // Ensure PHP agent and the function are available. |
|
| 29 | - if ( extension_loaded( 'newrelic' ) && function_exists( 'newrelic_ignore_apdex' ) ) { |
|
| 30 | - newrelic_ignore_apdex(); |
|
| 31 | - } |
|
| 28 | + // Ensure PHP agent and the function are available. |
|
| 29 | + if ( extension_loaded( 'newrelic' ) && function_exists( 'newrelic_ignore_apdex' ) ) { |
|
| 30 | + newrelic_ignore_apdex(); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | static function ignore_apdex() { |
| 27 | 27 | |
| 28 | 28 | // Ensure PHP agent and the function are available. |
| 29 | - if ( extension_loaded( 'newrelic' ) && function_exists( 'newrelic_ignore_apdex' ) ) { |
|
| 29 | + if (extension_loaded('newrelic') && function_exists('newrelic_ignore_apdex')) { |
|
| 30 | 30 | newrelic_ignore_apdex(); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; |
|
| 16 | + exit; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -28,113 +28,113 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | class Wordlift_Admin_Entity_Taxonomy_List_Page { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Hook to `wl_entity_type_row_actions` to add an "action" link to Thread |
|
| 33 | - * SEO related settings for the term. |
|
| 34 | - * |
|
| 35 | - * @see https://developer.wordpress.org/reference/hooks/taxonomy_row_actions/ |
|
| 36 | - * |
|
| 37 | - * @since 3.11.0 |
|
| 38 | - * |
|
| 39 | - * @param array $actions An array of action links to be displayed. Default |
|
| 40 | - * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
| 41 | - * @param object $term Term object. |
|
| 42 | - * |
|
| 43 | - * @return array $actions An array of action links to be displayed. Default |
|
| 44 | - * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
| 45 | - */ |
|
| 46 | - function wl_entity_type_row_actions( $actions, $term ) { |
|
| 47 | - |
|
| 48 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id" ); |
|
| 49 | - $actions['wl-seo'] = '<a href="' . esc_url( $url ) . '">' . __( 'SEO Settings', 'wordlift' ) . '</a>'; |
|
| 50 | - |
|
| 51 | - // Hacks for pre 4.7 compatibility: |
|
| 52 | - // * remove the quick edit. |
|
| 53 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 54 | - // * remove the edit link. |
|
| 55 | - unset( $actions['edit'] ); |
|
| 56 | - |
|
| 57 | - return $actions; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Override the capabilities related to managing the entity type terms |
|
| 62 | - * for multisite super admin to prevent it from manipulating it in any |
|
| 63 | - * way. |
|
| 64 | - * |
|
| 65 | - * @since 3.12.0 |
|
| 66 | - * |
|
| 67 | - * @param array $caps The user's current capabilities. |
|
| 68 | - * @param string $cap Capability name. |
|
| 69 | - * @param int $user_id The user ID. |
|
| 70 | - * @param array $args Adds the context to the cap. Typically the object ID. |
|
| 71 | - * |
|
| 72 | - * @return array Array containing the do_not_allow capability for super admin |
|
| 73 | - * when editing and deleting entity type terms capabilities |
|
| 74 | - * are being "approved" |
|
| 75 | - */ |
|
| 76 | - function restrict_super_admin( $caps, $cap, $user_id, $args ) { |
|
| 77 | - |
|
| 78 | - switch ( $cap ) { |
|
| 79 | - case 'wl_entity_type_edit_term': |
|
| 80 | - case 'wl_entity_type_delete_term': |
|
| 81 | - $caps[] = 'do_not_allow'; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - return $caps; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Override the capabilities related to managing the entity type terms |
|
| 89 | - * required for WordPress < 4.7 to get access to the admin page. |
|
| 90 | - * |
|
| 91 | - * Before 4.7, WordPress checks whether the user has permission to access |
|
| 92 | - * the `edit-tags.php` page. So we need to provide temporary the permission |
|
| 93 | - * otherwise the user will get an `access not allowed` when trying to access |
|
| 94 | - * the page. |
|
| 95 | - * |
|
| 96 | - * @see https://github.com/insideout10/wordlift-plugin/issues/512 |
|
| 97 | - * |
|
| 98 | - * @since 3.12.0 |
|
| 99 | - * |
|
| 100 | - * @param array $caps The user's current capabilities. |
|
| 101 | - * @param string $cap Capability name. |
|
| 102 | - * @param int $user_id The user ID. |
|
| 103 | - * @param array $args Adds the context to the cap. Typically the object ID. |
|
| 104 | - * |
|
| 105 | - * @return array Array containing the manage_options capability |
|
| 106 | - */ |
|
| 107 | - function enable_admin_access_pre_47( $caps, $cap, $user_id, $args ) { |
|
| 108 | - |
|
| 109 | - // Bail out if we're not dealing with the `wl_entity_type_edit_term` |
|
| 110 | - // capability. |
|
| 111 | - if ( 'wl_entity_type_edit_term' !== $cap ) { |
|
| 112 | - return $caps; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); |
|
| 116 | - |
|
| 117 | - // Bail out if the `path` cannot be determined. |
|
| 118 | - if ( null === $path ) { |
|
| 119 | - return $caps; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Bail out if a specific term is being handled. |
|
| 123 | - if ( isset( $_REQUEST['action'] ) ) { |
|
| 124 | - return $caps; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Split the path and check if the page is the `edit-tags.php`. We can't |
|
| 128 | - // use WP's own function because this is called very early. |
|
| 129 | - $components = explode( '/', $path ); |
|
| 130 | - if ( 'edit-tags.php' !== $components[ count( $components ) - 1 ] ) { |
|
| 131 | - return $caps; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Give permission to the user. |
|
| 135 | - $mapped[] = 'manage_options'; |
|
| 136 | - |
|
| 137 | - return $mapped; |
|
| 138 | - } |
|
| 31 | + /** |
|
| 32 | + * Hook to `wl_entity_type_row_actions` to add an "action" link to Thread |
|
| 33 | + * SEO related settings for the term. |
|
| 34 | + * |
|
| 35 | + * @see https://developer.wordpress.org/reference/hooks/taxonomy_row_actions/ |
|
| 36 | + * |
|
| 37 | + * @since 3.11.0 |
|
| 38 | + * |
|
| 39 | + * @param array $actions An array of action links to be displayed. Default |
|
| 40 | + * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
| 41 | + * @param object $term Term object. |
|
| 42 | + * |
|
| 43 | + * @return array $actions An array of action links to be displayed. Default |
|
| 44 | + * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
|
| 45 | + */ |
|
| 46 | + function wl_entity_type_row_actions( $actions, $term ) { |
|
| 47 | + |
|
| 48 | + $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id" ); |
|
| 49 | + $actions['wl-seo'] = '<a href="' . esc_url( $url ) . '">' . __( 'SEO Settings', 'wordlift' ) . '</a>'; |
|
| 50 | + |
|
| 51 | + // Hacks for pre 4.7 compatibility: |
|
| 52 | + // * remove the quick edit. |
|
| 53 | + unset( $actions['inline hide-if-no-js'] ); |
|
| 54 | + // * remove the edit link. |
|
| 55 | + unset( $actions['edit'] ); |
|
| 56 | + |
|
| 57 | + return $actions; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Override the capabilities related to managing the entity type terms |
|
| 62 | + * for multisite super admin to prevent it from manipulating it in any |
|
| 63 | + * way. |
|
| 64 | + * |
|
| 65 | + * @since 3.12.0 |
|
| 66 | + * |
|
| 67 | + * @param array $caps The user's current capabilities. |
|
| 68 | + * @param string $cap Capability name. |
|
| 69 | + * @param int $user_id The user ID. |
|
| 70 | + * @param array $args Adds the context to the cap. Typically the object ID. |
|
| 71 | + * |
|
| 72 | + * @return array Array containing the do_not_allow capability for super admin |
|
| 73 | + * when editing and deleting entity type terms capabilities |
|
| 74 | + * are being "approved" |
|
| 75 | + */ |
|
| 76 | + function restrict_super_admin( $caps, $cap, $user_id, $args ) { |
|
| 77 | + |
|
| 78 | + switch ( $cap ) { |
|
| 79 | + case 'wl_entity_type_edit_term': |
|
| 80 | + case 'wl_entity_type_delete_term': |
|
| 81 | + $caps[] = 'do_not_allow'; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + return $caps; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Override the capabilities related to managing the entity type terms |
|
| 89 | + * required for WordPress < 4.7 to get access to the admin page. |
|
| 90 | + * |
|
| 91 | + * Before 4.7, WordPress checks whether the user has permission to access |
|
| 92 | + * the `edit-tags.php` page. So we need to provide temporary the permission |
|
| 93 | + * otherwise the user will get an `access not allowed` when trying to access |
|
| 94 | + * the page. |
|
| 95 | + * |
|
| 96 | + * @see https://github.com/insideout10/wordlift-plugin/issues/512 |
|
| 97 | + * |
|
| 98 | + * @since 3.12.0 |
|
| 99 | + * |
|
| 100 | + * @param array $caps The user's current capabilities. |
|
| 101 | + * @param string $cap Capability name. |
|
| 102 | + * @param int $user_id The user ID. |
|
| 103 | + * @param array $args Adds the context to the cap. Typically the object ID. |
|
| 104 | + * |
|
| 105 | + * @return array Array containing the manage_options capability |
|
| 106 | + */ |
|
| 107 | + function enable_admin_access_pre_47( $caps, $cap, $user_id, $args ) { |
|
| 108 | + |
|
| 109 | + // Bail out if we're not dealing with the `wl_entity_type_edit_term` |
|
| 110 | + // capability. |
|
| 111 | + if ( 'wl_entity_type_edit_term' !== $cap ) { |
|
| 112 | + return $caps; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); |
|
| 116 | + |
|
| 117 | + // Bail out if the `path` cannot be determined. |
|
| 118 | + if ( null === $path ) { |
|
| 119 | + return $caps; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Bail out if a specific term is being handled. |
|
| 123 | + if ( isset( $_REQUEST['action'] ) ) { |
|
| 124 | + return $caps; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Split the path and check if the page is the `edit-tags.php`. We can't |
|
| 128 | + // use WP's own function because this is called very early. |
|
| 129 | + $components = explode( '/', $path ); |
|
| 130 | + if ( 'edit-tags.php' !== $components[ count( $components ) - 1 ] ) { |
|
| 131 | + return $caps; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Give permission to the user. |
|
| 135 | + $mapped[] = 'manage_options'; |
|
| 136 | + |
|
| 137 | + return $mapped; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @since 3.11.0 |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -43,16 +43,16 @@ discard block |
||
| 43 | 43 | * @return array $actions An array of action links to be displayed. Default |
| 44 | 44 | * 'Edit', 'Quick Edit', 'Delete', and 'View'. |
| 45 | 45 | */ |
| 46 | - function wl_entity_type_row_actions( $actions, $term ) { |
|
| 46 | + function wl_entity_type_row_actions($actions, $term) { |
|
| 47 | 47 | |
| 48 | - $url = admin_url( "admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id" ); |
|
| 49 | - $actions['wl-seo'] = '<a href="' . esc_url( $url ) . '">' . __( 'SEO Settings', 'wordlift' ) . '</a>'; |
|
| 48 | + $url = admin_url("admin.php?page=wl_entity_type_settings&tag_ID=$term->term_id"); |
|
| 49 | + $actions['wl-seo'] = '<a href="'.esc_url($url).'">'.__('SEO Settings', 'wordlift').'</a>'; |
|
| 50 | 50 | |
| 51 | 51 | // Hacks for pre 4.7 compatibility: |
| 52 | 52 | // * remove the quick edit. |
| 53 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 53 | + unset($actions['inline hide-if-no-js']); |
|
| 54 | 54 | // * remove the edit link. |
| 55 | - unset( $actions['edit'] ); |
|
| 55 | + unset($actions['edit']); |
|
| 56 | 56 | |
| 57 | 57 | return $actions; |
| 58 | 58 | } |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | * when editing and deleting entity type terms capabilities |
| 74 | 74 | * are being "approved" |
| 75 | 75 | */ |
| 76 | - function restrict_super_admin( $caps, $cap, $user_id, $args ) { |
|
| 76 | + function restrict_super_admin($caps, $cap, $user_id, $args) { |
|
| 77 | 77 | |
| 78 | - switch ( $cap ) { |
|
| 78 | + switch ($cap) { |
|
| 79 | 79 | case 'wl_entity_type_edit_term': |
| 80 | 80 | case 'wl_entity_type_delete_term': |
| 81 | 81 | $caps[] = 'do_not_allow'; |
@@ -104,30 +104,30 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return array Array containing the manage_options capability |
| 106 | 106 | */ |
| 107 | - function enable_admin_access_pre_47( $caps, $cap, $user_id, $args ) { |
|
| 107 | + function enable_admin_access_pre_47($caps, $cap, $user_id, $args) { |
|
| 108 | 108 | |
| 109 | 109 | // Bail out if we're not dealing with the `wl_entity_type_edit_term` |
| 110 | 110 | // capability. |
| 111 | - if ( 'wl_entity_type_edit_term' !== $cap ) { |
|
| 111 | + if ('wl_entity_type_edit_term' !== $cap) { |
|
| 112 | 112 | return $caps; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); |
|
| 115 | + $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); |
|
| 116 | 116 | |
| 117 | 117 | // Bail out if the `path` cannot be determined. |
| 118 | - if ( null === $path ) { |
|
| 118 | + if (null === $path) { |
|
| 119 | 119 | return $caps; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Bail out if a specific term is being handled. |
| 123 | - if ( isset( $_REQUEST['action'] ) ) { |
|
| 123 | + if (isset($_REQUEST['action'])) { |
|
| 124 | 124 | return $caps; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // Split the path and check if the page is the `edit-tags.php`. We can't |
| 128 | 128 | // use WP's own function because this is called very early. |
| 129 | - $components = explode( '/', $path ); |
|
| 130 | - if ( 'edit-tags.php' !== $components[ count( $components ) - 1 ] ) { |
|
| 129 | + $components = explode('/', $path); |
|
| 130 | + if ('edit-tags.php' !== $components[count($components) - 1]) { |
|
| 131 | 131 | return $caps; |
| 132 | 132 | } |
| 133 | 133 | |
@@ -15,34 +15,34 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | function wl_prefixes_list() { |
| 17 | 17 | |
| 18 | - // If the parameter is false, default prefixes have never been installed. |
|
| 19 | - if ( false === ( $prefixes = get_option( 'wl_option_prefixes' ) ) ) { |
|
| 18 | + // If the parameter is false, default prefixes have never been installed. |
|
| 19 | + if ( false === ( $prefixes = get_option( 'wl_option_prefixes' ) ) ) { |
|
| 20 | 20 | |
| 21 | - $prefixes = array( |
|
| 22 | - array( |
|
| 23 | - 'prefix' => 'geo', |
|
| 24 | - 'namespace' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 25 | - ), |
|
| 26 | - array( |
|
| 27 | - 'prefix' => 'dct', |
|
| 28 | - 'namespace' => 'http://purl.org/dc/terms/', |
|
| 29 | - ), |
|
| 30 | - array( |
|
| 31 | - 'prefix' => 'rdfs', |
|
| 32 | - 'namespace' => 'http://www.w3.org/2000/01/rdf-schema#', |
|
| 33 | - ), |
|
| 34 | - array( |
|
| 35 | - 'prefix' => 'owl', |
|
| 36 | - 'namespace' => 'http://www.w3.org/2002/07/owl#', |
|
| 37 | - ), |
|
| 38 | - array( 'prefix' => 'schema', 'namespace' => 'http://schema.org/' ), |
|
| 39 | - array( |
|
| 40 | - 'prefix' => 'xsd', |
|
| 41 | - 'namespace' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 42 | - ), |
|
| 43 | - ); |
|
| 44 | - add_option( 'wl_option_prefixes', $prefixes ); |
|
| 45 | - } |
|
| 21 | + $prefixes = array( |
|
| 22 | + array( |
|
| 23 | + 'prefix' => 'geo', |
|
| 24 | + 'namespace' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
|
| 25 | + ), |
|
| 26 | + array( |
|
| 27 | + 'prefix' => 'dct', |
|
| 28 | + 'namespace' => 'http://purl.org/dc/terms/', |
|
| 29 | + ), |
|
| 30 | + array( |
|
| 31 | + 'prefix' => 'rdfs', |
|
| 32 | + 'namespace' => 'http://www.w3.org/2000/01/rdf-schema#', |
|
| 33 | + ), |
|
| 34 | + array( |
|
| 35 | + 'prefix' => 'owl', |
|
| 36 | + 'namespace' => 'http://www.w3.org/2002/07/owl#', |
|
| 37 | + ), |
|
| 38 | + array( 'prefix' => 'schema', 'namespace' => 'http://schema.org/' ), |
|
| 39 | + array( |
|
| 40 | + 'prefix' => 'xsd', |
|
| 41 | + 'namespace' => 'http://www.w3.org/2001/XMLSchema#', |
|
| 42 | + ), |
|
| 43 | + ); |
|
| 44 | + add_option( 'wl_option_prefixes', $prefixes ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $prefixes; |
|
| 47 | + return $prefixes; |
|
| 48 | 48 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | function wl_prefixes_list() { |
| 17 | 17 | |
| 18 | 18 | // If the parameter is false, default prefixes have never been installed. |
| 19 | - if ( false === ( $prefixes = get_option( 'wl_option_prefixes' ) ) ) { |
|
| 19 | + if (false === ($prefixes = get_option('wl_option_prefixes'))) { |
|
| 20 | 20 | |
| 21 | 21 | $prefixes = array( |
| 22 | 22 | array( |
@@ -35,13 +35,13 @@ discard block |
||
| 35 | 35 | 'prefix' => 'owl', |
| 36 | 36 | 'namespace' => 'http://www.w3.org/2002/07/owl#', |
| 37 | 37 | ), |
| 38 | - array( 'prefix' => 'schema', 'namespace' => 'http://schema.org/' ), |
|
| 38 | + array('prefix' => 'schema', 'namespace' => 'http://schema.org/'), |
|
| 39 | 39 | array( |
| 40 | 40 | 'prefix' => 'xsd', |
| 41 | 41 | 'namespace' => 'http://www.w3.org/2001/XMLSchema#', |
| 42 | 42 | ), |
| 43 | 43 | ); |
| 44 | - add_option( 'wl_option_prefixes', $prefixes ); |
|
| 44 | + add_option('wl_option_prefixes', $prefixes); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | return $prefixes; |
@@ -58,137 +58,137 @@ |
||
| 58 | 58 | // return sizeof( $results ); |
| 59 | 59 | // } |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * The {@link Wordlift_Entity_Service} instance. |
|
| 63 | - * |
|
| 64 | - * @since 3.12.2 |
|
| 65 | - * @access private |
|
| 66 | - * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
| 67 | - */ |
|
| 68 | - private $entity_service; |
|
| 69 | - /** |
|
| 70 | - * @var |
|
| 71 | - */ |
|
| 72 | - private $sparql_service; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Create a {@link Wordlift_Admin_Status_Page} instance. |
|
| 76 | - * |
|
| 77 | - * @since 3.12.2 |
|
| 78 | - * |
|
| 79 | - * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
| 80 | - * @param \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance. |
|
| 81 | - */ |
|
| 82 | - public function __construct( $entity_service, $sparql_service ) { |
|
| 83 | - |
|
| 84 | - $this->entity_service = $entity_service; |
|
| 85 | - $this->sparql_service = $sparql_service; |
|
| 86 | - |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Get the list of entity URIs. |
|
| 91 | - * |
|
| 92 | - * @since 3.12.2 |
|
| 93 | - * @return array An array of entity URIs. |
|
| 94 | - */ |
|
| 95 | - protected function get_entity_uris() { |
|
| 96 | - |
|
| 97 | - // Get the entity IDs. |
|
| 98 | - $ids = $this->entity_service->get( array( |
|
| 99 | - 'numberposts' => - 1, |
|
| 100 | - 'fields' => 'ids', |
|
| 101 | - 'post_status' => 'publish', |
|
| 102 | - ) ); |
|
| 103 | - |
|
| 104 | - // Create a reference to the entity service for the closure. |
|
| 105 | - $entity_service = $this->entity_service; |
|
| 106 | - |
|
| 107 | - // Combine IDs with URIs. |
|
| 108 | - return array_combine( $ids, array_map( function ( $item ) use ( $entity_service ) { |
|
| 109 | - return $entity_service->get_uri( $item ); |
|
| 110 | - }, $ids ) ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get the list of URIs in the Linked Data Cloud. |
|
| 115 | - * |
|
| 116 | - * @since 3.12.2 |
|
| 117 | - * @return array|null An array of URIs. |
|
| 118 | - */ |
|
| 119 | - protected function get_linked_data_uris() { |
|
| 120 | - |
|
| 121 | - // Prepare the query to get the URIs from the Linked Data Cloud. |
|
| 122 | - $query = Wordlift_Query_Builder::new_instance() |
|
| 123 | - ->select( 'DISTINCT ?s' ) |
|
| 124 | - ->statement( '?s', Wordlift_Query_Builder::RDFS_TYPE_URI, '?o' ) |
|
| 125 | - ->build(); |
|
| 126 | - |
|
| 127 | - // Execute the query. |
|
| 128 | - $response = $this->sparql_service->select( $query ); |
|
| 129 | - |
|
| 130 | - // If the response is an error, return null. |
|
| 131 | - if ( is_a( $response, 'WP_Error' ) ) { |
|
| 132 | - return null; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Split the response into single URIs. |
|
| 136 | - $uris = preg_split( "/(\r\n|\n|\r)/", $response['body'] ); |
|
| 137 | - |
|
| 138 | - // Remove the header. |
|
| 139 | - unset( $uris[0] ); |
|
| 140 | - |
|
| 141 | - // Finally return the URIs. |
|
| 142 | - return $uris; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Get the page title. Will be translated. |
|
| 147 | - * |
|
| 148 | - * @since 3.11.0 |
|
| 149 | - * |
|
| 150 | - * @return string The page title. |
|
| 151 | - */ |
|
| 152 | - function get_page_title() { |
|
| 153 | - |
|
| 154 | - return _x( 'Status Report', 'Page title', 'wordlift' ); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Get the menu title. Will be translated. |
|
| 159 | - * |
|
| 160 | - * @since 3.11.0 |
|
| 161 | - * |
|
| 162 | - * @return string The menu title. |
|
| 163 | - */ |
|
| 164 | - function get_menu_title() { |
|
| 165 | - |
|
| 166 | - return _x( 'Status Report', 'Menu title', 'wordlift' ); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Get the menu slug. |
|
| 171 | - * |
|
| 172 | - * @since 3.11.0 |
|
| 173 | - * |
|
| 174 | - * @return string The menu slug. |
|
| 175 | - */ |
|
| 176 | - function get_menu_slug() { |
|
| 177 | - |
|
| 178 | - return 'wl_status_report'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the partial file name, used in the {@link render} function. |
|
| 183 | - * |
|
| 184 | - * @since 3.11.0 |
|
| 185 | - * |
|
| 186 | - * @return string The partial file name. |
|
| 187 | - */ |
|
| 188 | - function get_partial_name() { |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - return 'wordlift-admin-status-page.php'; |
|
| 192 | - } |
|
| 61 | + /** |
|
| 62 | + * The {@link Wordlift_Entity_Service} instance. |
|
| 63 | + * |
|
| 64 | + * @since 3.12.2 |
|
| 65 | + * @access private |
|
| 66 | + * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
| 67 | + */ |
|
| 68 | + private $entity_service; |
|
| 69 | + /** |
|
| 70 | + * @var |
|
| 71 | + */ |
|
| 72 | + private $sparql_service; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Create a {@link Wordlift_Admin_Status_Page} instance. |
|
| 76 | + * |
|
| 77 | + * @since 3.12.2 |
|
| 78 | + * |
|
| 79 | + * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
| 80 | + * @param \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance. |
|
| 81 | + */ |
|
| 82 | + public function __construct( $entity_service, $sparql_service ) { |
|
| 83 | + |
|
| 84 | + $this->entity_service = $entity_service; |
|
| 85 | + $this->sparql_service = $sparql_service; |
|
| 86 | + |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Get the list of entity URIs. |
|
| 91 | + * |
|
| 92 | + * @since 3.12.2 |
|
| 93 | + * @return array An array of entity URIs. |
|
| 94 | + */ |
|
| 95 | + protected function get_entity_uris() { |
|
| 96 | + |
|
| 97 | + // Get the entity IDs. |
|
| 98 | + $ids = $this->entity_service->get( array( |
|
| 99 | + 'numberposts' => - 1, |
|
| 100 | + 'fields' => 'ids', |
|
| 101 | + 'post_status' => 'publish', |
|
| 102 | + ) ); |
|
| 103 | + |
|
| 104 | + // Create a reference to the entity service for the closure. |
|
| 105 | + $entity_service = $this->entity_service; |
|
| 106 | + |
|
| 107 | + // Combine IDs with URIs. |
|
| 108 | + return array_combine( $ids, array_map( function ( $item ) use ( $entity_service ) { |
|
| 109 | + return $entity_service->get_uri( $item ); |
|
| 110 | + }, $ids ) ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get the list of URIs in the Linked Data Cloud. |
|
| 115 | + * |
|
| 116 | + * @since 3.12.2 |
|
| 117 | + * @return array|null An array of URIs. |
|
| 118 | + */ |
|
| 119 | + protected function get_linked_data_uris() { |
|
| 120 | + |
|
| 121 | + // Prepare the query to get the URIs from the Linked Data Cloud. |
|
| 122 | + $query = Wordlift_Query_Builder::new_instance() |
|
| 123 | + ->select( 'DISTINCT ?s' ) |
|
| 124 | + ->statement( '?s', Wordlift_Query_Builder::RDFS_TYPE_URI, '?o' ) |
|
| 125 | + ->build(); |
|
| 126 | + |
|
| 127 | + // Execute the query. |
|
| 128 | + $response = $this->sparql_service->select( $query ); |
|
| 129 | + |
|
| 130 | + // If the response is an error, return null. |
|
| 131 | + if ( is_a( $response, 'WP_Error' ) ) { |
|
| 132 | + return null; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Split the response into single URIs. |
|
| 136 | + $uris = preg_split( "/(\r\n|\n|\r)/", $response['body'] ); |
|
| 137 | + |
|
| 138 | + // Remove the header. |
|
| 139 | + unset( $uris[0] ); |
|
| 140 | + |
|
| 141 | + // Finally return the URIs. |
|
| 142 | + return $uris; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Get the page title. Will be translated. |
|
| 147 | + * |
|
| 148 | + * @since 3.11.0 |
|
| 149 | + * |
|
| 150 | + * @return string The page title. |
|
| 151 | + */ |
|
| 152 | + function get_page_title() { |
|
| 153 | + |
|
| 154 | + return _x( 'Status Report', 'Page title', 'wordlift' ); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Get the menu title. Will be translated. |
|
| 159 | + * |
|
| 160 | + * @since 3.11.0 |
|
| 161 | + * |
|
| 162 | + * @return string The menu title. |
|
| 163 | + */ |
|
| 164 | + function get_menu_title() { |
|
| 165 | + |
|
| 166 | + return _x( 'Status Report', 'Menu title', 'wordlift' ); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Get the menu slug. |
|
| 171 | + * |
|
| 172 | + * @since 3.11.0 |
|
| 173 | + * |
|
| 174 | + * @return string The menu slug. |
|
| 175 | + */ |
|
| 176 | + function get_menu_slug() { |
|
| 177 | + |
|
| 178 | + return 'wl_status_report'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the partial file name, used in the {@link render} function. |
|
| 183 | + * |
|
| 184 | + * @since 3.11.0 |
|
| 185 | + * |
|
| 186 | + * @return string The partial file name. |
|
| 187 | + */ |
|
| 188 | + function get_partial_name() { |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + return 'wordlift-admin-status-page.php'; |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | 194 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
| 80 | 80 | * @param \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance. |
| 81 | 81 | */ |
| 82 | - public function __construct( $entity_service, $sparql_service ) { |
|
| 82 | + public function __construct($entity_service, $sparql_service) { |
|
| 83 | 83 | |
| 84 | 84 | $this->entity_service = $entity_service; |
| 85 | 85 | $this->sparql_service = $sparql_service; |
@@ -95,19 +95,19 @@ discard block |
||
| 95 | 95 | protected function get_entity_uris() { |
| 96 | 96 | |
| 97 | 97 | // Get the entity IDs. |
| 98 | - $ids = $this->entity_service->get( array( |
|
| 99 | - 'numberposts' => - 1, |
|
| 98 | + $ids = $this->entity_service->get(array( |
|
| 99 | + 'numberposts' => -1, |
|
| 100 | 100 | 'fields' => 'ids', |
| 101 | 101 | 'post_status' => 'publish', |
| 102 | - ) ); |
|
| 102 | + )); |
|
| 103 | 103 | |
| 104 | 104 | // Create a reference to the entity service for the closure. |
| 105 | 105 | $entity_service = $this->entity_service; |
| 106 | 106 | |
| 107 | 107 | // Combine IDs with URIs. |
| 108 | - return array_combine( $ids, array_map( function ( $item ) use ( $entity_service ) { |
|
| 109 | - return $entity_service->get_uri( $item ); |
|
| 110 | - }, $ids ) ); |
|
| 108 | + return array_combine($ids, array_map(function($item) use ($entity_service) { |
|
| 109 | + return $entity_service->get_uri($item); |
|
| 110 | + }, $ids)); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -120,23 +120,23 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | // Prepare the query to get the URIs from the Linked Data Cloud. |
| 122 | 122 | $query = Wordlift_Query_Builder::new_instance() |
| 123 | - ->select( 'DISTINCT ?s' ) |
|
| 124 | - ->statement( '?s', Wordlift_Query_Builder::RDFS_TYPE_URI, '?o' ) |
|
| 123 | + ->select('DISTINCT ?s') |
|
| 124 | + ->statement('?s', Wordlift_Query_Builder::RDFS_TYPE_URI, '?o') |
|
| 125 | 125 | ->build(); |
| 126 | 126 | |
| 127 | 127 | // Execute the query. |
| 128 | - $response = $this->sparql_service->select( $query ); |
|
| 128 | + $response = $this->sparql_service->select($query); |
|
| 129 | 129 | |
| 130 | 130 | // If the response is an error, return null. |
| 131 | - if ( is_a( $response, 'WP_Error' ) ) { |
|
| 131 | + if (is_a($response, 'WP_Error')) { |
|
| 132 | 132 | return null; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Split the response into single URIs. |
| 136 | - $uris = preg_split( "/(\r\n|\n|\r)/", $response['body'] ); |
|
| 136 | + $uris = preg_split("/(\r\n|\n|\r)/", $response['body']); |
|
| 137 | 137 | |
| 138 | 138 | // Remove the header. |
| 139 | - unset( $uris[0] ); |
|
| 139 | + unset($uris[0]); |
|
| 140 | 140 | |
| 141 | 141 | // Finally return the URIs. |
| 142 | 142 | return $uris; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | function get_page_title() { |
| 153 | 153 | |
| 154 | - return _x( 'Status Report', 'Page title', 'wordlift' ); |
|
| 154 | + return _x('Status Report', 'Page title', 'wordlift'); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | function get_menu_title() { |
| 165 | 165 | |
| 166 | - return _x( 'Status Report', 'Menu title', 'wordlift' ); |
|
| 166 | + return _x('Status Report', 'Menu title', 'wordlift'); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -111,7 +111,7 @@ |
||
| 111 | 111 | * Get the singleton instance of the Notice service. |
| 112 | 112 | * |
| 113 | 113 | * @since 3.14.0 |
| 114 | - * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
| 114 | + * @return Wordlift_Notice_Service The singleton instance of the settings page service. |
|
| 115 | 115 | */ |
| 116 | 116 | public static function get_instance() { |
| 117 | 117 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @param \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
| 104 | 104 | * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
| 105 | 105 | */ |
| 106 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
| 106 | + function __construct($configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element) { |
|
| 107 | 107 | |
| 108 | 108 | $this->configuration_service = $configuration_service; |
| 109 | 109 | $this->entity_service = $entity_service; |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | |
| 188 | 188 | // JavaScript required for the settings page. |
| 189 | 189 | // @todo: try to move to the `wordlift-admin.bundle.js`. |
| 190 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) ); |
|
| 191 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 190 | + wp_enqueue_script('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.js', array('wp-util')); |
|
| 191 | + wp_enqueue_style('wordlift-admin-settings-page', plugin_dir_url(dirname(__FILE__)).'admin/js/1/settings.css'); |
|
| 192 | 192 | |
| 193 | 193 | } |
| 194 | 194 | |
@@ -206,22 +206,22 @@ discard block |
||
| 206 | 206 | register_setting( |
| 207 | 207 | 'wl_general_settings', |
| 208 | 208 | 'wl_general_settings', |
| 209 | - array( $this, 'sanitize_callback' ) |
|
| 209 | + array($this, 'sanitize_callback') |
|
| 210 | 210 | ); |
| 211 | 211 | |
| 212 | 212 | // Add the general settings section. |
| 213 | 213 | add_settings_section( |
| 214 | 214 | 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
| 215 | - '', // Section header. |
|
| 216 | - '', // Callback used to render the description of the section. |
|
| 215 | + '', // Section header. |
|
| 216 | + '', // Callback used to render the description of the section. |
|
| 217 | 217 | 'wl_general_settings' // Page on which to add this section of options. |
| 218 | 218 | ); |
| 219 | 219 | |
| 220 | 220 | $key_args = array( |
| 221 | 221 | 'id' => 'wl-key', |
| 222 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 222 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::KEY.']', |
|
| 223 | 223 | 'value' => $this->configuration_service->get_key(), |
| 224 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 224 | + 'description' => __('Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift'), |
|
| 225 | 225 | ); |
| 226 | 226 | |
| 227 | 227 | // Before we were used to validate the key beforehand, but this means |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | // Add the `key` field. |
| 236 | 236 | add_settings_field( |
| 237 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 238 | - __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 237 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 238 | + __('WordLift Key', 'wordlift'), // The label to the left of the option interface element. |
|
| 239 | 239 | // The name of the function responsible for rendering the option interface. |
| 240 | - array( $this->input_element, 'render' ), |
|
| 241 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 242 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 240 | + array($this->input_element, 'render'), |
|
| 241 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 242 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 243 | 243 | $key_args // The array of arguments to pass to the callback. In this case, just a description. |
| 244 | 244 | ); |
| 245 | 245 | |
@@ -247,10 +247,10 @@ discard block |
||
| 247 | 247 | $entity_base_path_args = array( |
| 248 | 248 | // The array of arguments to pass to the callback. In this case, just a description. |
| 249 | 249 | 'id' => 'wl-entity-base-path', |
| 250 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 250 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY.']', |
|
| 251 | 251 | 'value' => $this->configuration_service->get_entity_base_path(), |
| 252 | 252 | /* translators: Placeholders: %s - a link to FAQ's page. */ |
| 253 | - 'description' => sprintf( __( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
| 253 | + 'description' => sprintf(__('All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift'), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary'), |
|
| 254 | 254 | ); |
| 255 | 255 | |
| 256 | 256 | // The following call is very heavy on large web sites and is always run |
@@ -259,94 +259,94 @@ discard block |
||
| 259 | 259 | // |
| 260 | 260 | // It is now replaced by a filter to add the `readonly` flag to the |
| 261 | 261 | // input element when this is actually rendered. |
| 262 | - add_filter( 'wl_admin_input_element_params', array( |
|
| 262 | + add_filter('wl_admin_input_element_params', array( |
|
| 263 | 263 | $this, |
| 264 | 264 | 'entity_path_input_element_params', |
| 265 | - ) ); |
|
| 265 | + )); |
|
| 266 | 266 | |
| 267 | 267 | // Add the `wl_entity_base_path` field. |
| 268 | 268 | add_settings_field( |
| 269 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 270 | - __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 269 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 270 | + __('Entity Base Path', 'wordlift'), // The label to the left of the option interface element |
|
| 271 | 271 | // The name of the function responsible for rendering the option interface |
| 272 | - array( $this->input_element, 'render', ), |
|
| 273 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 274 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 272 | + array($this->input_element, 'render',), |
|
| 273 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 274 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 275 | 275 | $entity_base_path_args |
| 276 | 276 | ); |
| 277 | 277 | |
| 278 | 278 | // Add the `language_name` field. |
| 279 | 279 | add_settings_field( |
| 280 | 280 | 'wl-site-language', |
| 281 | - __( 'Site Language', 'wordlift' ), |
|
| 282 | - array( $this->language_select_element, 'render' ), |
|
| 281 | + __('Site Language', 'wordlift'), |
|
| 282 | + array($this->language_select_element, 'render'), |
|
| 283 | 283 | 'wl_general_settings', |
| 284 | 284 | 'wl_general_settings_section', |
| 285 | 285 | array( |
| 286 | 286 | // The array of arguments to pass to the callback. In this case, just a description. |
| 287 | 287 | 'id' => 'wl-site-language', |
| 288 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 288 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LANGUAGE.']', |
|
| 289 | 289 | 'value' => $this->configuration_service->get_language_code(), |
| 290 | - 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 290 | + 'description' => __('Each WordLift Key can be used only in one language. Pick yours.', 'wordlift'), |
|
| 291 | 291 | ) |
| 292 | 292 | ); |
| 293 | 293 | |
| 294 | 294 | // Add the `country_code` field. |
| 295 | 295 | add_settings_field( |
| 296 | 296 | 'wl-country-code', |
| 297 | - _x( 'Country', 'wordlift' ), |
|
| 298 | - array( $this->country_select_element, 'render' ), |
|
| 297 | + _x('Country', 'wordlift'), |
|
| 298 | + array($this->country_select_element, 'render'), |
|
| 299 | 299 | 'wl_general_settings', |
| 300 | 300 | 'wl_general_settings_section', |
| 301 | 301 | array( |
| 302 | 302 | 'id' => 'wl-country-code', |
| 303 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
| 303 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::COUNTRY_CODE.']', |
|
| 304 | 304 | 'value' => $this->configuration_service->get_country_code(), |
| 305 | - 'description' => __( 'Please select a country.', 'wordlift' ), |
|
| 306 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 305 | + 'description' => __('Please select a country.', 'wordlift'), |
|
| 306 | + 'notice' => __('The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift'), |
|
| 307 | 307 | ) |
| 308 | 308 | ); |
| 309 | 309 | |
| 310 | 310 | // Add the `publisher` field. |
| 311 | 311 | add_settings_field( |
| 312 | 312 | 'wl-publisher-id', |
| 313 | - __( 'Publisher', 'wordlift' ), |
|
| 314 | - array( $this->publisher_element, 'render' ), |
|
| 313 | + __('Publisher', 'wordlift'), |
|
| 314 | + array($this->publisher_element, 'render'), |
|
| 315 | 315 | 'wl_general_settings', |
| 316 | 316 | 'wl_general_settings_section', |
| 317 | 317 | array( |
| 318 | 318 | 'id' => 'wl-publisher-id', |
| 319 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 319 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::PUBLISHER_ID.']', |
|
| 320 | 320 | ) |
| 321 | 321 | ); |
| 322 | 322 | |
| 323 | 323 | // Add the `link by default` field. |
| 324 | 324 | add_settings_field( |
| 325 | 325 | 'wl-link-by-default', |
| 326 | - __( 'Link by Default', 'wordlift' ), |
|
| 327 | - array( $this->radio_input_element, 'render' ), |
|
| 326 | + __('Link by Default', 'wordlift'), |
|
| 327 | + array($this->radio_input_element, 'render'), |
|
| 328 | 328 | 'wl_general_settings', |
| 329 | 329 | 'wl_general_settings_section', |
| 330 | 330 | array( |
| 331 | 331 | 'id' => 'wl-link-by-default', |
| 332 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 332 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::LINK_BY_DEFAULT.']', |
|
| 333 | 333 | 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
| 334 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 334 | + 'description' => __('Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift'), |
|
| 335 | 335 | ) |
| 336 | 336 | ); |
| 337 | 337 | |
| 338 | 338 | // Add the `diagnostic data` field. |
| 339 | 339 | add_settings_field( |
| 340 | 340 | 'wl-send-diagnostic', |
| 341 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 342 | - array( $this->radio_input_element, 'render' ), |
|
| 341 | + __('Send Diagnostic Data', 'wordlift'), |
|
| 342 | + array($this->radio_input_element, 'render'), |
|
| 343 | 343 | 'wl_general_settings', |
| 344 | 344 | 'wl_general_settings_section', |
| 345 | 345 | array( |
| 346 | 346 | 'id' => 'wl-send-diagnostic', |
| 347 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 347 | + 'name' => 'wl_general_settings['.Wordlift_Configuration_Service::SEND_DIAGNOSTIC.']', |
|
| 348 | 348 | 'value' => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no', |
| 349 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 349 | + 'description' => __('Whether to send diagnostic data or not.', 'wordlift'), |
|
| 350 | 350 | ) |
| 351 | 351 | ); |
| 352 | 352 | |
@@ -362,10 +362,10 @@ discard block |
||
| 362 | 362 | * |
| 363 | 363 | * @return array The updated array. |
| 364 | 364 | */ |
| 365 | - public function entity_path_input_element_params( $args ) { |
|
| 365 | + public function entity_path_input_element_params($args) { |
|
| 366 | 366 | |
| 367 | 367 | // Bail out if it's not the `wl-entity-base-path`). |
| 368 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 368 | + if ('wl-entity-base-path' !== $args['id']) { |
|
| 369 | 369 | return $args; |
| 370 | 370 | } |
| 371 | 371 | |
@@ -388,23 +388,23 @@ discard block |
||
| 388 | 388 | * |
| 389 | 389 | * @return array The sanitized input array. |
| 390 | 390 | */ |
| 391 | - function sanitize_callback( $input ) { |
|
| 391 | + function sanitize_callback($input) { |
|
| 392 | 392 | |
| 393 | 393 | // Validate the selected country. |
| 394 | 394 | $this->validate_country(); |
| 395 | 395 | |
| 396 | 396 | // Check whether a publisher name has been set. |
| 397 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 397 | + if (isset($_POST['wl_publisher']) && ! empty($_POST['wl_publisher']['name'])) { // WPCS: CSRF, input var, sanitization ok. |
|
| 398 | 398 | $name = $_POST['wl_publisher']['name']; // WPCS: CSRF, input var, sanitization ok. |
| 399 | 399 | $type = $_POST['wl_publisher']['type']; // WPCS: CSRF, input var, sanitization ok. |
| 400 | 400 | $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; // WPCS: CSRF, input var, sanitization ok. |
| 401 | 401 | |
| 402 | 402 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
| 403 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 403 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person'); |
|
| 404 | 404 | |
| 405 | 405 | // Create an entity for the publisher and assign it to the input |
| 406 | 406 | // parameter which WordPress automatically saves into the settings. |
| 407 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 407 | + $input['publisher_id'] = $this->entity_service->create($name, $type_uri, $thumbnail_id, 'publish'); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | return $input; |
@@ -419,8 +419,8 @@ discard block |
||
| 419 | 419 | |
| 420 | 420 | // Bail out if for some reason the country and language are not set. |
| 421 | 421 | if ( |
| 422 | - empty( $_POST['wl_general_settings']['site_language'] ) && // WPCS: CSRF, input var, sanitization ok. |
|
| 423 | - empty( $_POST['wl_general_settings']['country_code'] ) // WPCS: CSRF, input var, sanitization ok. |
|
| 422 | + empty($_POST['wl_general_settings']['site_language']) && // WPCS: CSRF, input var, sanitization ok. |
|
| 423 | + empty($_POST['wl_general_settings']['country_code']) // WPCS: CSRF, input var, sanitization ok. |
|
| 424 | 424 | ) { |
| 425 | 425 | return; |
| 426 | 426 | } |
@@ -433,14 +433,14 @@ discard block |
||
| 433 | 433 | // Check whether the chosen country has language limitations |
| 434 | 434 | // and whether the chosen language is supported for that country. |
| 435 | 435 | if ( |
| 436 | - ! empty( $codes[ $country ] ) && |
|
| 437 | - ! in_array( $language, $codes[ $country ] ) |
|
| 436 | + ! empty($codes[$country]) && |
|
| 437 | + ! in_array($language, $codes[$country]) |
|
| 438 | 438 | ) { |
| 439 | 439 | // Otherwise add an error. |
| 440 | 440 | add_settings_error( |
| 441 | 441 | 'wl-country-code', |
| 442 | - esc_attr( 'settings_updated' ), |
|
| 443 | - _x( 'The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift' ) |
|
| 442 | + esc_attr('settings_updated'), |
|
| 443 | + _x('The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift') |
|
| 444 | 444 | ); |
| 445 | 445 | } |
| 446 | 446 | } |
@@ -18,431 +18,431 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Settings_Page extends Wordlift_Admin_Page { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * A singleton instance of the Notice service. |
|
| 23 | - * |
|
| 24 | - * @since 3.2.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
| 27 | - */ |
|
| 28 | - private static $instance; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * A {@link Wordlift_Entity_Service} instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.11.0 |
|
| 34 | - * @access private |
|
| 35 | - * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 36 | - */ |
|
| 37 | - private $entity_service; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * A {@link Wordlift_Configuration_Service} instance. |
|
| 41 | - * |
|
| 42 | - * @since 3.11.0 |
|
| 43 | - * @access private |
|
| 44 | - * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 45 | - */ |
|
| 46 | - private $configuration_service; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 50 | - * |
|
| 51 | - * @since 3.11.0 |
|
| 52 | - * @access private |
|
| 53 | - * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 54 | - */ |
|
| 55 | - private $input_element; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 59 | - * |
|
| 60 | - * @since 3.13.0 |
|
| 61 | - * @access protected |
|
| 62 | - * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 63 | - */ |
|
| 64 | - private $radio_input_element; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 68 | - * |
|
| 69 | - * @since 3.11.0 |
|
| 70 | - * @access private |
|
| 71 | - * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 72 | - */ |
|
| 73 | - private $language_select_element; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 77 | - * |
|
| 78 | - * @since 3.18.0 |
|
| 79 | - * @access private |
|
| 80 | - * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 81 | - */ |
|
| 82 | - private $country_select_element; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 86 | - * |
|
| 87 | - * @since 3.11.0 |
|
| 88 | - * @access private |
|
| 89 | - * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 90 | - */ |
|
| 91 | - private $publisher_element; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 95 | - * |
|
| 96 | - * @since 3.11.0 |
|
| 97 | - * |
|
| 98 | - * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 99 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 100 | - * @param \Wordlift_Admin_Input_Element $input_element A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 101 | - * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 102 | - * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 103 | - * @param \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 104 | - * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 105 | - */ |
|
| 106 | - function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
| 107 | - |
|
| 108 | - $this->configuration_service = $configuration_service; |
|
| 109 | - $this->entity_service = $entity_service; |
|
| 110 | - |
|
| 111 | - // Set a reference to the UI elements. |
|
| 112 | - $this->input_element = $input_element; |
|
| 113 | - $this->radio_input_element = $radio_input_element; |
|
| 114 | - $this->language_select_element = $language_select_element; |
|
| 115 | - $this->country_select_element = $country_select_element; |
|
| 116 | - $this->publisher_element = $publisher_element; |
|
| 117 | - |
|
| 118 | - self::$instance = $this; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Get the singleton instance of the Notice service. |
|
| 123 | - * |
|
| 124 | - * @since 3.14.0 |
|
| 125 | - * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
| 126 | - */ |
|
| 127 | - public static function get_instance() { |
|
| 128 | - |
|
| 129 | - return self::$instance; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @inheritdoc |
|
| 134 | - */ |
|
| 135 | - function get_parent_slug() { |
|
| 136 | - |
|
| 137 | - return 'wl_admin_menu'; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @inheritdoc |
|
| 142 | - */ |
|
| 143 | - function get_capability() { |
|
| 144 | - |
|
| 145 | - return 'manage_options'; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @inheritdoc |
|
| 150 | - */ |
|
| 151 | - function get_page_title() { |
|
| 152 | - |
|
| 153 | - return 'WordLift Settings'; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @inheritdoc |
|
| 158 | - */ |
|
| 159 | - function get_menu_title() { |
|
| 160 | - |
|
| 161 | - return 'Settings'; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @inheritdoc |
|
| 166 | - */ |
|
| 167 | - function get_menu_slug() { |
|
| 168 | - |
|
| 169 | - return 'wl_configuration_admin_menu'; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @inheritdoc |
|
| 174 | - */ |
|
| 175 | - function get_partial_name() { |
|
| 176 | - |
|
| 177 | - return 'wordlift-admin-settings-page.php'; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @inheritdoc |
|
| 182 | - */ |
|
| 183 | - public function enqueue_scripts() { |
|
| 184 | - |
|
| 185 | - // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 186 | - wp_enqueue_media(); |
|
| 187 | - |
|
| 188 | - // JavaScript required for the settings page. |
|
| 189 | - // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 190 | - wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) ); |
|
| 191 | - wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 192 | - |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Configure all the configuration parameters. |
|
| 197 | - * |
|
| 198 | - * Called by the *admin_init* hook. |
|
| 199 | - * |
|
| 200 | - * @since 3.11.0 |
|
| 201 | - */ |
|
| 202 | - function admin_init() { |
|
| 203 | - |
|
| 204 | - // Register WordLift's general settings, providing our own sanitize callback |
|
| 205 | - // which will also check whether the user filled the WL Publisher form. |
|
| 206 | - register_setting( |
|
| 207 | - 'wl_general_settings', |
|
| 208 | - 'wl_general_settings', |
|
| 209 | - array( $this, 'sanitize_callback' ) |
|
| 210 | - ); |
|
| 211 | - |
|
| 212 | - // Add the general settings section. |
|
| 213 | - add_settings_section( |
|
| 214 | - 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 215 | - '', // Section header. |
|
| 216 | - '', // Callback used to render the description of the section. |
|
| 217 | - 'wl_general_settings' // Page on which to add this section of options. |
|
| 218 | - ); |
|
| 219 | - |
|
| 220 | - $key_args = array( |
|
| 221 | - 'id' => 'wl-key', |
|
| 222 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 223 | - 'value' => $this->configuration_service->get_key(), |
|
| 224 | - 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 225 | - ); |
|
| 226 | - |
|
| 227 | - // Before we were used to validate the key beforehand, but this means |
|
| 228 | - // an http call whenever a page is opened in the admin area. Therefore |
|
| 229 | - // we now leave the input `untouched`, leaving to the client to update |
|
| 230 | - // the `css_class`. |
|
| 231 | - // |
|
| 232 | - // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
| 233 | - $key_args['css_class'] = 'untouched'; |
|
| 234 | - |
|
| 235 | - // Add the `key` field. |
|
| 236 | - add_settings_field( |
|
| 237 | - 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 238 | - __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 239 | - // The name of the function responsible for rendering the option interface. |
|
| 240 | - array( $this->input_element, 'render' ), |
|
| 241 | - 'wl_general_settings', // The page on which this option will be displayed. |
|
| 242 | - 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 243 | - $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 244 | - ); |
|
| 245 | - |
|
| 246 | - // Entity Base Path input. |
|
| 247 | - $entity_base_path_args = array( |
|
| 248 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 249 | - 'id' => 'wl-entity-base-path', |
|
| 250 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 251 | - 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 252 | - /* translators: Placeholders: %s - a link to FAQ's page. */ |
|
| 253 | - 'description' => sprintf( __( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
| 254 | - ); |
|
| 255 | - |
|
| 256 | - // The following call is very heavy on large web sites and is always run |
|
| 257 | - // also when not needed: |
|
| 258 | - // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 259 | - // |
|
| 260 | - // It is now replaced by a filter to add the `readonly` flag to the |
|
| 261 | - // input element when this is actually rendered. |
|
| 262 | - add_filter( 'wl_admin_input_element_params', array( |
|
| 263 | - $this, |
|
| 264 | - 'entity_path_input_element_params', |
|
| 265 | - ) ); |
|
| 266 | - |
|
| 267 | - // Add the `wl_entity_base_path` field. |
|
| 268 | - add_settings_field( |
|
| 269 | - 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 270 | - __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 271 | - // The name of the function responsible for rendering the option interface |
|
| 272 | - array( $this->input_element, 'render', ), |
|
| 273 | - 'wl_general_settings', // The page on which this option will be displayed |
|
| 274 | - 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 275 | - $entity_base_path_args |
|
| 276 | - ); |
|
| 277 | - |
|
| 278 | - // Add the `language_name` field. |
|
| 279 | - add_settings_field( |
|
| 280 | - 'wl-site-language', |
|
| 281 | - __( 'Site Language', 'wordlift' ), |
|
| 282 | - array( $this->language_select_element, 'render' ), |
|
| 283 | - 'wl_general_settings', |
|
| 284 | - 'wl_general_settings_section', |
|
| 285 | - array( |
|
| 286 | - // The array of arguments to pass to the callback. In this case, just a description. |
|
| 287 | - 'id' => 'wl-site-language', |
|
| 288 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 289 | - 'value' => $this->configuration_service->get_language_code(), |
|
| 290 | - 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 291 | - ) |
|
| 292 | - ); |
|
| 293 | - |
|
| 294 | - // Add the `country_code` field. |
|
| 295 | - add_settings_field( |
|
| 296 | - 'wl-country-code', |
|
| 297 | - _x( 'Country', 'wordlift' ), |
|
| 298 | - array( $this->country_select_element, 'render' ), |
|
| 299 | - 'wl_general_settings', |
|
| 300 | - 'wl_general_settings_section', |
|
| 301 | - array( |
|
| 302 | - 'id' => 'wl-country-code', |
|
| 303 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
| 304 | - 'value' => $this->configuration_service->get_country_code(), |
|
| 305 | - 'description' => __( 'Please select a country.', 'wordlift' ), |
|
| 306 | - 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 307 | - ) |
|
| 308 | - ); |
|
| 309 | - |
|
| 310 | - // Add the `publisher` field. |
|
| 311 | - add_settings_field( |
|
| 312 | - 'wl-publisher-id', |
|
| 313 | - __( 'Publisher', 'wordlift' ), |
|
| 314 | - array( $this->publisher_element, 'render' ), |
|
| 315 | - 'wl_general_settings', |
|
| 316 | - 'wl_general_settings_section', |
|
| 317 | - array( |
|
| 318 | - 'id' => 'wl-publisher-id', |
|
| 319 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 320 | - ) |
|
| 321 | - ); |
|
| 322 | - |
|
| 323 | - // Add the `link by default` field. |
|
| 324 | - add_settings_field( |
|
| 325 | - 'wl-link-by-default', |
|
| 326 | - __( 'Link by Default', 'wordlift' ), |
|
| 327 | - array( $this->radio_input_element, 'render' ), |
|
| 328 | - 'wl_general_settings', |
|
| 329 | - 'wl_general_settings_section', |
|
| 330 | - array( |
|
| 331 | - 'id' => 'wl-link-by-default', |
|
| 332 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 333 | - 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 334 | - 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 335 | - ) |
|
| 336 | - ); |
|
| 337 | - |
|
| 338 | - // Add the `diagnostic data` field. |
|
| 339 | - add_settings_field( |
|
| 340 | - 'wl-send-diagnostic', |
|
| 341 | - __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 342 | - array( $this->radio_input_element, 'render' ), |
|
| 343 | - 'wl_general_settings', |
|
| 344 | - 'wl_general_settings_section', |
|
| 345 | - array( |
|
| 346 | - 'id' => 'wl-send-diagnostic', |
|
| 347 | - 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 348 | - 'value' => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no', |
|
| 349 | - 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 350 | - ) |
|
| 351 | - ); |
|
| 352 | - |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 357 | - * `readonly` flag to the `wl-entity-base-path` input. |
|
| 358 | - * |
|
| 359 | - * @since 3.17.0 |
|
| 360 | - * |
|
| 361 | - * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 362 | - * |
|
| 363 | - * @return array The updated array. |
|
| 364 | - */ |
|
| 365 | - public function entity_path_input_element_params( $args ) { |
|
| 366 | - |
|
| 367 | - // Bail out if it's not the `wl-entity-base-path`). |
|
| 368 | - if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 369 | - return $args; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // Set the readonly flag according to the entities count. |
|
| 373 | - $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 374 | - |
|
| 375 | - // Return the updated args. |
|
| 376 | - return $args; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Sanitize the configuration settings to be stored. |
|
| 381 | - * |
|
| 382 | - * If a new entity is being created for the publisher, create it and set The |
|
| 383 | - * publisher setting. |
|
| 384 | - * |
|
| 385 | - * @since 3.11.0 |
|
| 386 | - * |
|
| 387 | - * @param array $input The configuration settings array. |
|
| 388 | - * |
|
| 389 | - * @return array The sanitized input array. |
|
| 390 | - */ |
|
| 391 | - function sanitize_callback( $input ) { |
|
| 392 | - |
|
| 393 | - // Validate the selected country. |
|
| 394 | - $this->validate_country(); |
|
| 395 | - |
|
| 396 | - // Check whether a publisher name has been set. |
|
| 397 | - if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 398 | - $name = $_POST['wl_publisher']['name']; // WPCS: CSRF, input var, sanitization ok. |
|
| 399 | - $type = $_POST['wl_publisher']['type']; // WPCS: CSRF, input var, sanitization ok. |
|
| 400 | - $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; // WPCS: CSRF, input var, sanitization ok. |
|
| 401 | - |
|
| 402 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 403 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 404 | - |
|
| 405 | - // Create an entity for the publisher and assign it to the input |
|
| 406 | - // parameter which WordPress automatically saves into the settings. |
|
| 407 | - $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - return $input; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Check whether the currently selected country supports the site language. |
|
| 415 | - * |
|
| 416 | - * @since 3.18.0 |
|
| 417 | - */ |
|
| 418 | - private function validate_country() { |
|
| 419 | - |
|
| 420 | - // Bail out if for some reason the country and language are not set. |
|
| 421 | - if ( |
|
| 422 | - empty( $_POST['wl_general_settings']['site_language'] ) && // WPCS: CSRF, input var, sanitization ok. |
|
| 423 | - empty( $_POST['wl_general_settings']['country_code'] ) // WPCS: CSRF, input var, sanitization ok. |
|
| 424 | - ) { |
|
| 425 | - return; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - // Get the values. |
|
| 429 | - $language = $_POST['wl_general_settings']['site_language']; // WPCS: CSRF, input var, sanitization ok. |
|
| 430 | - $country = $_POST['wl_general_settings']['country_code']; // WPCS: CSRF, input var, sanitization ok. |
|
| 431 | - $codes = Wordlift_Countries::get_codes(); |
|
| 432 | - |
|
| 433 | - // Check whether the chosen country has language limitations |
|
| 434 | - // and whether the chosen language is supported for that country. |
|
| 435 | - if ( |
|
| 436 | - ! empty( $codes[ $country ] ) && |
|
| 437 | - ! in_array( $language, $codes[ $country ] ) |
|
| 438 | - ) { |
|
| 439 | - // Otherwise add an error. |
|
| 440 | - add_settings_error( |
|
| 441 | - 'wl-country-code', |
|
| 442 | - esc_attr( 'settings_updated' ), |
|
| 443 | - _x( 'The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift' ) |
|
| 444 | - ); |
|
| 445 | - } |
|
| 446 | - } |
|
| 21 | + /** |
|
| 22 | + * A singleton instance of the Notice service. |
|
| 23 | + * |
|
| 24 | + * @since 3.2.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
| 27 | + */ |
|
| 28 | + private static $instance; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * A {@link Wordlift_Entity_Service} instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.11.0 |
|
| 34 | + * @access private |
|
| 35 | + * @var \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 36 | + */ |
|
| 37 | + private $entity_service; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * A {@link Wordlift_Configuration_Service} instance. |
|
| 41 | + * |
|
| 42 | + * @since 3.11.0 |
|
| 43 | + * @access private |
|
| 44 | + * @var \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 45 | + */ |
|
| 46 | + private $configuration_service; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 50 | + * |
|
| 51 | + * @since 3.11.0 |
|
| 52 | + * @access private |
|
| 53 | + * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 54 | + */ |
|
| 55 | + private $input_element; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 59 | + * |
|
| 60 | + * @since 3.13.0 |
|
| 61 | + * @access protected |
|
| 62 | + * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 63 | + */ |
|
| 64 | + private $radio_input_element; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 68 | + * |
|
| 69 | + * @since 3.11.0 |
|
| 70 | + * @access private |
|
| 71 | + * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 72 | + */ |
|
| 73 | + private $language_select_element; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 77 | + * |
|
| 78 | + * @since 3.18.0 |
|
| 79 | + * @access private |
|
| 80 | + * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 81 | + */ |
|
| 82 | + private $country_select_element; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 86 | + * |
|
| 87 | + * @since 3.11.0 |
|
| 88 | + * @access private |
|
| 89 | + * @var \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 90 | + */ |
|
| 91 | + private $publisher_element; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
| 95 | + * |
|
| 96 | + * @since 3.11.0 |
|
| 97 | + * |
|
| 98 | + * @param \Wordlift_Configuration_Service $configuration_service A {@link Wordlift_Configuration_Service} instance. |
|
| 99 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 100 | + * @param \Wordlift_Admin_Input_Element $input_element A {@link Wordlift_Admin_Input_Element} element renderer. |
|
| 101 | + * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
| 102 | + * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
| 103 | + * @param \Wordlift_Admin_Publisher_Element $publisher_element A {@link Wordlift_Admin_Publisher_Element} element renderer. |
|
| 104 | + * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
| 105 | + */ |
|
| 106 | + function __construct( $configuration_service, $entity_service, $input_element, $language_select_element, $country_select_element, $publisher_element, $radio_input_element ) { |
|
| 107 | + |
|
| 108 | + $this->configuration_service = $configuration_service; |
|
| 109 | + $this->entity_service = $entity_service; |
|
| 110 | + |
|
| 111 | + // Set a reference to the UI elements. |
|
| 112 | + $this->input_element = $input_element; |
|
| 113 | + $this->radio_input_element = $radio_input_element; |
|
| 114 | + $this->language_select_element = $language_select_element; |
|
| 115 | + $this->country_select_element = $country_select_element; |
|
| 116 | + $this->publisher_element = $publisher_element; |
|
| 117 | + |
|
| 118 | + self::$instance = $this; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Get the singleton instance of the Notice service. |
|
| 123 | + * |
|
| 124 | + * @since 3.14.0 |
|
| 125 | + * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
| 126 | + */ |
|
| 127 | + public static function get_instance() { |
|
| 128 | + |
|
| 129 | + return self::$instance; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @inheritdoc |
|
| 134 | + */ |
|
| 135 | + function get_parent_slug() { |
|
| 136 | + |
|
| 137 | + return 'wl_admin_menu'; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @inheritdoc |
|
| 142 | + */ |
|
| 143 | + function get_capability() { |
|
| 144 | + |
|
| 145 | + return 'manage_options'; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @inheritdoc |
|
| 150 | + */ |
|
| 151 | + function get_page_title() { |
|
| 152 | + |
|
| 153 | + return 'WordLift Settings'; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @inheritdoc |
|
| 158 | + */ |
|
| 159 | + function get_menu_title() { |
|
| 160 | + |
|
| 161 | + return 'Settings'; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @inheritdoc |
|
| 166 | + */ |
|
| 167 | + function get_menu_slug() { |
|
| 168 | + |
|
| 169 | + return 'wl_configuration_admin_menu'; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @inheritdoc |
|
| 174 | + */ |
|
| 175 | + function get_partial_name() { |
|
| 176 | + |
|
| 177 | + return 'wordlift-admin-settings-page.php'; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @inheritdoc |
|
| 182 | + */ |
|
| 183 | + public function enqueue_scripts() { |
|
| 184 | + |
|
| 185 | + // Enqueue the media scripts to be used for the publisher's logo selection. |
|
| 186 | + wp_enqueue_media(); |
|
| 187 | + |
|
| 188 | + // JavaScript required for the settings page. |
|
| 189 | + // @todo: try to move to the `wordlift-admin.bundle.js`. |
|
| 190 | + wp_enqueue_script( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.js', array( 'wp-util' ) ); |
|
| 191 | + wp_enqueue_style( 'wordlift-admin-settings-page', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/settings.css' ); |
|
| 192 | + |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Configure all the configuration parameters. |
|
| 197 | + * |
|
| 198 | + * Called by the *admin_init* hook. |
|
| 199 | + * |
|
| 200 | + * @since 3.11.0 |
|
| 201 | + */ |
|
| 202 | + function admin_init() { |
|
| 203 | + |
|
| 204 | + // Register WordLift's general settings, providing our own sanitize callback |
|
| 205 | + // which will also check whether the user filled the WL Publisher form. |
|
| 206 | + register_setting( |
|
| 207 | + 'wl_general_settings', |
|
| 208 | + 'wl_general_settings', |
|
| 209 | + array( $this, 'sanitize_callback' ) |
|
| 210 | + ); |
|
| 211 | + |
|
| 212 | + // Add the general settings section. |
|
| 213 | + add_settings_section( |
|
| 214 | + 'wl_general_settings_section', // ID used to identify this section and with which to register options. |
|
| 215 | + '', // Section header. |
|
| 216 | + '', // Callback used to render the description of the section. |
|
| 217 | + 'wl_general_settings' // Page on which to add this section of options. |
|
| 218 | + ); |
|
| 219 | + |
|
| 220 | + $key_args = array( |
|
| 221 | + 'id' => 'wl-key', |
|
| 222 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::KEY . ']', |
|
| 223 | + 'value' => $this->configuration_service->get_key(), |
|
| 224 | + 'description' => __( 'Insert the <a href="https://www.wordlift.io/blogger">WordLift Key</a> you received via email.', 'wordlift' ), |
|
| 225 | + ); |
|
| 226 | + |
|
| 227 | + // Before we were used to validate the key beforehand, but this means |
|
| 228 | + // an http call whenever a page is opened in the admin area. Therefore |
|
| 229 | + // we now leave the input `untouched`, leaving to the client to update |
|
| 230 | + // the `css_class`. |
|
| 231 | + // |
|
| 232 | + // See https://github.com/insideout10/wordlift-plugin/issues/669. |
|
| 233 | + $key_args['css_class'] = 'untouched'; |
|
| 234 | + |
|
| 235 | + // Add the `key` field. |
|
| 236 | + add_settings_field( |
|
| 237 | + 'wl-key', // Element id used to identify the field throughout the theme. |
|
| 238 | + __( 'WordLift Key', 'wordlift' ), // The label to the left of the option interface element. |
|
| 239 | + // The name of the function responsible for rendering the option interface. |
|
| 240 | + array( $this->input_element, 'render' ), |
|
| 241 | + 'wl_general_settings', // The page on which this option will be displayed. |
|
| 242 | + 'wl_general_settings_section', // The name of the section to which this field belongs. |
|
| 243 | + $key_args // The array of arguments to pass to the callback. In this case, just a description. |
|
| 244 | + ); |
|
| 245 | + |
|
| 246 | + // Entity Base Path input. |
|
| 247 | + $entity_base_path_args = array( |
|
| 248 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 249 | + 'id' => 'wl-entity-base-path', |
|
| 250 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::ENTITY_BASE_PATH_KEY . ']', |
|
| 251 | + 'value' => $this->configuration_service->get_entity_base_path(), |
|
| 252 | + /* translators: Placeholders: %s - a link to FAQ's page. */ |
|
| 253 | + 'description' => sprintf( __( 'All new pages created with WordLift, will be stored inside your internal vocabulary. You can customize the url pattern of these pages in the field above. Check our <a href="%s">FAQs</a> if you need more info.', 'wordlift' ), 'https://wordlift.io/wordlift-user-faqs/#10-why-and-how-should-i-customize-the-url-of-the-entity-pages-created-in-my-vocabulary' ), |
|
| 254 | + ); |
|
| 255 | + |
|
| 256 | + // The following call is very heavy on large web sites and is always run |
|
| 257 | + // also when not needed: |
|
| 258 | + // $entity_base_path_args['readonly'] = 0 < $this->entity_service->count(); |
|
| 259 | + // |
|
| 260 | + // It is now replaced by a filter to add the `readonly` flag to the |
|
| 261 | + // input element when this is actually rendered. |
|
| 262 | + add_filter( 'wl_admin_input_element_params', array( |
|
| 263 | + $this, |
|
| 264 | + 'entity_path_input_element_params', |
|
| 265 | + ) ); |
|
| 266 | + |
|
| 267 | + // Add the `wl_entity_base_path` field. |
|
| 268 | + add_settings_field( |
|
| 269 | + 'wl-entity-base-path', // ID used to identify the field throughout the theme |
|
| 270 | + __( 'Entity Base Path', 'wordlift' ), // The label to the left of the option interface element |
|
| 271 | + // The name of the function responsible for rendering the option interface |
|
| 272 | + array( $this->input_element, 'render', ), |
|
| 273 | + 'wl_general_settings', // The page on which this option will be displayed |
|
| 274 | + 'wl_general_settings_section', // The name of the section to which this field belongs |
|
| 275 | + $entity_base_path_args |
|
| 276 | + ); |
|
| 277 | + |
|
| 278 | + // Add the `language_name` field. |
|
| 279 | + add_settings_field( |
|
| 280 | + 'wl-site-language', |
|
| 281 | + __( 'Site Language', 'wordlift' ), |
|
| 282 | + array( $this->language_select_element, 'render' ), |
|
| 283 | + 'wl_general_settings', |
|
| 284 | + 'wl_general_settings_section', |
|
| 285 | + array( |
|
| 286 | + // The array of arguments to pass to the callback. In this case, just a description. |
|
| 287 | + 'id' => 'wl-site-language', |
|
| 288 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LANGUAGE . ']', |
|
| 289 | + 'value' => $this->configuration_service->get_language_code(), |
|
| 290 | + 'description' => __( 'Each WordLift Key can be used only in one language. Pick yours.', 'wordlift' ), |
|
| 291 | + ) |
|
| 292 | + ); |
|
| 293 | + |
|
| 294 | + // Add the `country_code` field. |
|
| 295 | + add_settings_field( |
|
| 296 | + 'wl-country-code', |
|
| 297 | + _x( 'Country', 'wordlift' ), |
|
| 298 | + array( $this->country_select_element, 'render' ), |
|
| 299 | + 'wl_general_settings', |
|
| 300 | + 'wl_general_settings_section', |
|
| 301 | + array( |
|
| 302 | + 'id' => 'wl-country-code', |
|
| 303 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::COUNTRY_CODE . ']', |
|
| 304 | + 'value' => $this->configuration_service->get_country_code(), |
|
| 305 | + 'description' => __( 'Please select a country.', 'wordlift' ), |
|
| 306 | + 'notice' => __( 'The selected language is not supported in this country.</br>Please choose another country or language.', 'wordlift' ), |
|
| 307 | + ) |
|
| 308 | + ); |
|
| 309 | + |
|
| 310 | + // Add the `publisher` field. |
|
| 311 | + add_settings_field( |
|
| 312 | + 'wl-publisher-id', |
|
| 313 | + __( 'Publisher', 'wordlift' ), |
|
| 314 | + array( $this->publisher_element, 'render' ), |
|
| 315 | + 'wl_general_settings', |
|
| 316 | + 'wl_general_settings_section', |
|
| 317 | + array( |
|
| 318 | + 'id' => 'wl-publisher-id', |
|
| 319 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::PUBLISHER_ID . ']', |
|
| 320 | + ) |
|
| 321 | + ); |
|
| 322 | + |
|
| 323 | + // Add the `link by default` field. |
|
| 324 | + add_settings_field( |
|
| 325 | + 'wl-link-by-default', |
|
| 326 | + __( 'Link by Default', 'wordlift' ), |
|
| 327 | + array( $this->radio_input_element, 'render' ), |
|
| 328 | + 'wl_general_settings', |
|
| 329 | + 'wl_general_settings_section', |
|
| 330 | + array( |
|
| 331 | + 'id' => 'wl-link-by-default', |
|
| 332 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::LINK_BY_DEFAULT . ']', |
|
| 333 | + 'value' => $this->configuration_service->is_link_by_default() ? 'yes' : 'no', |
|
| 334 | + 'description' => __( 'Whether to link entities by default or not. This setting applies to all the entities.', 'wordlift' ), |
|
| 335 | + ) |
|
| 336 | + ); |
|
| 337 | + |
|
| 338 | + // Add the `diagnostic data` field. |
|
| 339 | + add_settings_field( |
|
| 340 | + 'wl-send-diagnostic', |
|
| 341 | + __( 'Send Diagnostic Data', 'wordlift' ), |
|
| 342 | + array( $this->radio_input_element, 'render' ), |
|
| 343 | + 'wl_general_settings', |
|
| 344 | + 'wl_general_settings_section', |
|
| 345 | + array( |
|
| 346 | + 'id' => 'wl-send-diagnostic', |
|
| 347 | + 'name' => 'wl_general_settings[' . Wordlift_Configuration_Service::SEND_DIAGNOSTIC . ']', |
|
| 348 | + 'value' => 'yes' === $this->configuration_service->get_diagnostic_preferences() ? 'yes' : 'no', |
|
| 349 | + 'description' => __( 'Whether to send diagnostic data or not.', 'wordlift' ), |
|
| 350 | + ) |
|
| 351 | + ); |
|
| 352 | + |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Filter the {@link Wordlift_Admin_Input_Element} in order to add the |
|
| 357 | + * `readonly` flag to the `wl-entity-base-path` input. |
|
| 358 | + * |
|
| 359 | + * @since 3.17.0 |
|
| 360 | + * |
|
| 361 | + * @param array $args An array of {@link Wordlift_Admin_Input_Element} parameters. |
|
| 362 | + * |
|
| 363 | + * @return array The updated array. |
|
| 364 | + */ |
|
| 365 | + public function entity_path_input_element_params( $args ) { |
|
| 366 | + |
|
| 367 | + // Bail out if it's not the `wl-entity-base-path`). |
|
| 368 | + if ( 'wl-entity-base-path' !== $args['id'] ) { |
|
| 369 | + return $args; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // Set the readonly flag according to the entities count. |
|
| 373 | + $args['readonly'] = 0 < $this->entity_service->count(); |
|
| 374 | + |
|
| 375 | + // Return the updated args. |
|
| 376 | + return $args; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Sanitize the configuration settings to be stored. |
|
| 381 | + * |
|
| 382 | + * If a new entity is being created for the publisher, create it and set The |
|
| 383 | + * publisher setting. |
|
| 384 | + * |
|
| 385 | + * @since 3.11.0 |
|
| 386 | + * |
|
| 387 | + * @param array $input The configuration settings array. |
|
| 388 | + * |
|
| 389 | + * @return array The sanitized input array. |
|
| 390 | + */ |
|
| 391 | + function sanitize_callback( $input ) { |
|
| 392 | + |
|
| 393 | + // Validate the selected country. |
|
| 394 | + $this->validate_country(); |
|
| 395 | + |
|
| 396 | + // Check whether a publisher name has been set. |
|
| 397 | + if ( isset( $_POST['wl_publisher'] ) && ! empty( $_POST['wl_publisher']['name'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 398 | + $name = $_POST['wl_publisher']['name']; // WPCS: CSRF, input var, sanitization ok. |
|
| 399 | + $type = $_POST['wl_publisher']['type']; // WPCS: CSRF, input var, sanitization ok. |
|
| 400 | + $thumbnail_id = $_POST['wl_publisher']['thumbnail_id'] ?: null; // WPCS: CSRF, input var, sanitization ok. |
|
| 401 | + |
|
| 402 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
| 403 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $type ? 'Organization' : 'Person' ); |
|
| 404 | + |
|
| 405 | + // Create an entity for the publisher and assign it to the input |
|
| 406 | + // parameter which WordPress automatically saves into the settings. |
|
| 407 | + $input['publisher_id'] = $this->entity_service->create( $name, $type_uri, $thumbnail_id, 'publish' ); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + return $input; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Check whether the currently selected country supports the site language. |
|
| 415 | + * |
|
| 416 | + * @since 3.18.0 |
|
| 417 | + */ |
|
| 418 | + private function validate_country() { |
|
| 419 | + |
|
| 420 | + // Bail out if for some reason the country and language are not set. |
|
| 421 | + if ( |
|
| 422 | + empty( $_POST['wl_general_settings']['site_language'] ) && // WPCS: CSRF, input var, sanitization ok. |
|
| 423 | + empty( $_POST['wl_general_settings']['country_code'] ) // WPCS: CSRF, input var, sanitization ok. |
|
| 424 | + ) { |
|
| 425 | + return; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + // Get the values. |
|
| 429 | + $language = $_POST['wl_general_settings']['site_language']; // WPCS: CSRF, input var, sanitization ok. |
|
| 430 | + $country = $_POST['wl_general_settings']['country_code']; // WPCS: CSRF, input var, sanitization ok. |
|
| 431 | + $codes = Wordlift_Countries::get_codes(); |
|
| 432 | + |
|
| 433 | + // Check whether the chosen country has language limitations |
|
| 434 | + // and whether the chosen language is supported for that country. |
|
| 435 | + if ( |
|
| 436 | + ! empty( $codes[ $country ] ) && |
|
| 437 | + ! in_array( $language, $codes[ $country ] ) |
|
| 438 | + ) { |
|
| 439 | + // Otherwise add an error. |
|
| 440 | + add_settings_error( |
|
| 441 | + 'wl-country-code', |
|
| 442 | + esc_attr( 'settings_updated' ), |
|
| 443 | + _x( 'The selected language is not supported for the currently chosen country. Please choose another country or language.', 'wordlift' ) |
|
| 444 | + ); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | 448 | } |
@@ -346,7 +346,7 @@ |
||
| 346 | 346 | * |
| 347 | 347 | * @param int $user_id The {@link WP_User} `id`. |
| 348 | 348 | * |
| 349 | - * @return int bool True if editing is denied otherwise false. |
|
| 349 | + * @return boolean bool True if editing is denied otherwise false. |
|
| 350 | 350 | */ |
| 351 | 351 | public function is_deny_editor_entity_create( $user_id ) { |
| 352 | 352 | |
@@ -19,477 +19,477 @@ |
||
| 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 | - * The singleton instance of the User service. |
|
| 54 | - * |
|
| 55 | - * @since 3.1.7 |
|
| 56 | - * @access private |
|
| 57 | - * @var \Wordlift_User_Service $user_service The singleton instance of the User service. |
|
| 58 | - */ |
|
| 59 | - private static $instance; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * The {@link Wordlift_Sparql_Service} instance. |
|
| 63 | - * |
|
| 64 | - * @since 3.18.0 |
|
| 65 | - * @access private |
|
| 66 | - * @var \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance. |
|
| 67 | - */ |
|
| 68 | - private $sparql_service; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * The Entity service. |
|
| 72 | - * |
|
| 73 | - * @since 3.18.0 |
|
| 74 | - * @access private |
|
| 75 | - * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 76 | - */ |
|
| 77 | - private $entity_service; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Create an instance of the User service. |
|
| 81 | - * |
|
| 82 | - * @since 3.1.7 |
|
| 83 | - * |
|
| 84 | - * @param \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance. |
|
| 85 | - * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
| 86 | - */ |
|
| 87 | - public function __construct( $sparql_service, $entity_service ) { |
|
| 88 | - |
|
| 89 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' ); |
|
| 90 | - |
|
| 91 | - self::$instance = $this; |
|
| 92 | - |
|
| 93 | - $this->sparql_service = $sparql_service; |
|
| 94 | - $this->entity_service = $entity_service; |
|
| 95 | - |
|
| 96 | - add_filter( 'user_has_cap', array( $this, 'has_cap' ), 10, 3 ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Get the singleton instance of the User service. |
|
| 101 | - * |
|
| 102 | - * @since 3.1.7 |
|
| 103 | - * @return \Wordlift_User_Service The singleton instance of the User service. |
|
| 104 | - */ |
|
| 105 | - public static function get_instance() { |
|
| 106 | - |
|
| 107 | - return self::$instance; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Get the URI for a user. |
|
| 112 | - * |
|
| 113 | - * @since 3.1.7 |
|
| 114 | - * |
|
| 115 | - * @param int $user_id The user id |
|
| 116 | - * |
|
| 117 | - * @return false|string The user's URI or false in case of failure. |
|
| 118 | - */ |
|
| 119 | - public function get_uri( $user_id ) { |
|
| 120 | - |
|
| 121 | - // Try to get the URI stored in the user's meta and return it if available. |
|
| 122 | - if ( false !== ( $user_uri = $this->_get_uri( $user_id ) ) ) { |
|
| 123 | - return $user_uri; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // Try to build an URI, return false in case of failure. |
|
| 127 | - if ( false === ( $user_uri = $this->_build_uri( $user_id ) ) ) { |
|
| 128 | - return false; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // Store the URI for future requests (we need a "permanent" URI). |
|
| 132 | - $this->_set_uri( $user_id, $user_uri ); |
|
| 133 | - |
|
| 134 | - return $user_uri; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Set the `id` of the entity representing a {@link WP_User}. |
|
| 139 | - * |
|
| 140 | - * If the `id` is set to 0 (or less) then the meta is deleted. |
|
| 141 | - * |
|
| 142 | - * @since 3.14.0 |
|
| 143 | - * |
|
| 144 | - * @param int $user_id The {@link WP_User}. |
|
| 145 | - * @param int $value The entity {@link WP_Post} `id`. |
|
| 146 | - * |
|
| 147 | - * @return bool|int Meta ID if the key didn't exist, true on successful update, false on failure. |
|
| 148 | - */ |
|
| 149 | - public function set_entity( $user_id, $value ) { |
|
| 150 | - |
|
| 151 | - return 0 < $value |
|
| 152 | - ? update_user_meta( $user_id, self::ENTITY_META_KEY, $value ) |
|
| 153 | - : delete_user_meta( $user_id, self::ENTITY_META_KEY ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Get the {@link WP_Post} `id` of the entity representing a {@link WP_User}. |
|
| 158 | - * |
|
| 159 | - * @since 3.14.0 |
|
| 160 | - * |
|
| 161 | - * @param int $user_id The {@link WP_User}'s `id`. |
|
| 162 | - * |
|
| 163 | - * @return string|false The entity {@link WP_Post} `id` or an empty string if not set or false if the object id is invalid |
|
| 164 | - */ |
|
| 165 | - public function get_entity( $user_id ) { |
|
| 166 | - |
|
| 167 | - return get_user_meta( $user_id, self::ENTITY_META_KEY, true ); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Get the user's URI stored in the user's meta. |
|
| 172 | - * |
|
| 173 | - * @since 3.1.7 |
|
| 174 | - * |
|
| 175 | - * @param int $user_id The user id. |
|
| 176 | - * |
|
| 177 | - * @return false|string The user's URI or false if not found. |
|
| 178 | - */ |
|
| 179 | - private function _get_uri( $user_id ) { |
|
| 180 | - |
|
| 181 | - $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true ); |
|
| 182 | - |
|
| 183 | - if ( empty( $user_uri ) ) { |
|
| 184 | - return false; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $user_uri; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Build an URI for a user. |
|
| 192 | - * |
|
| 193 | - * @since 3.1.7 |
|
| 194 | - * |
|
| 195 | - * @param int $user_id The user's id. |
|
| 196 | - * |
|
| 197 | - * @return false|string The user's URI or false in case of failure. |
|
| 198 | - */ |
|
| 199 | - private function _build_uri( $user_id ) { |
|
| 200 | - |
|
| 201 | - // Get the user, return false in case of failure. |
|
| 202 | - if ( false === ( $user = get_userdata( $user_id ) ) ) { |
|
| 203 | - return false; |
|
| 204 | - }; |
|
| 205 | - |
|
| 206 | - // If the nicename is not set, return a failure. |
|
| 207 | - if ( empty( $user->user_nicename ) ) { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return wl_configuration_get_redlink_dataset_uri() . "/user/$user->user_nicename"; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Store the URI in user's meta. |
|
| 216 | - * |
|
| 217 | - * @since 3.1.7 |
|
| 218 | - * |
|
| 219 | - * @param int $user_id The user's id. |
|
| 220 | - * @param string $user_uri The user's uri. |
|
| 221 | - * |
|
| 222 | - * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
|
| 223 | - */ |
|
| 224 | - private function _set_uri( $user_id, $user_uri ) { |
|
| 225 | - |
|
| 226 | - return update_user_meta( $user_id, self::URI_META_KEY, $user_uri ); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Mark an editor user as denied from editing entities. |
|
| 231 | - * Does nothing if the user is not an editor |
|
| 232 | - * |
|
| 233 | - * @since 3.14.0 |
|
| 234 | - * |
|
| 235 | - * @param integer $user_id The ID of the user |
|
| 236 | - */ |
|
| 237 | - public function deny_editor_entity_create( $user_id ) { |
|
| 238 | - |
|
| 239 | - // Bail out if the user is not an editor. |
|
| 240 | - if ( ! $this->is_editor( $user_id ) ) { |
|
| 241 | - return; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // The user explicitly do not have the capability. |
|
| 245 | - update_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes' ); |
|
| 246 | - |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Remove the "deny entity editing" mark from an editor user. |
|
| 251 | - * Does nothing if the user is not an editor |
|
| 252 | - * |
|
| 253 | - * @since 3.14.0 |
|
| 254 | - * |
|
| 255 | - * @param integer $user_id The ID of the user |
|
| 256 | - */ |
|
| 257 | - public function allow_editor_entity_create( $user_id ) { |
|
| 258 | - |
|
| 259 | - // Bail out if the user is not an editor. |
|
| 260 | - if ( ! $this->is_editor( $user_id ) ) { |
|
| 261 | - return; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // The user explicitly do not have the capability. |
|
| 265 | - delete_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY ); |
|
| 266 | - |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * Get whether the 'deny editor entity editing' flag is set. |
|
| 271 | - * |
|
| 272 | - * @since 3.14.0 |
|
| 273 | - * |
|
| 274 | - * @param int $user_id The {@link WP_User} `id`. |
|
| 275 | - * |
|
| 276 | - * @return int bool True if editing is denied otherwise false. |
|
| 277 | - */ |
|
| 278 | - public function is_deny_editor_entity_create( $user_id ) { |
|
| 279 | - |
|
| 280 | - return 'yes' === get_user_option( self::DENY_ENTITY_CREATE_META_KEY, $user_id ); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Check whether the {@link WP_User} with the specified `id` is an editor, |
|
| 285 | - * i.e. has the `editor` role. |
|
| 286 | - * |
|
| 287 | - * @since 3.14.0 |
|
| 288 | - * |
|
| 289 | - * @param int $user_id The {@link WP_User} `id`. |
|
| 290 | - * |
|
| 291 | - * @return bool True if the {@link WP_User} is an editor otherwise false. |
|
| 292 | - */ |
|
| 293 | - public function is_editor( $user_id ) { |
|
| 294 | - |
|
| 295 | - // Get the user. |
|
| 296 | - $user = get_user_by( 'id', $user_id ); |
|
| 297 | - |
|
| 298 | - // Return true, if the user is found and has the `editor` role. |
|
| 299 | - return is_a( $user, 'WP_User' ) && in_array( 'editor', (array) $user->roles ); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Check if an editor can create entities. |
|
| 304 | - * |
|
| 305 | - * @since 3.14.0 |
|
| 306 | - * |
|
| 307 | - * @param int $user_id The user id of the user being checked. |
|
| 308 | - * |
|
| 309 | - * @return bool false if it is an editor that is denied from edit entities, true otherwise. |
|
| 310 | - */ |
|
| 311 | - public function editor_can_create_entities( $user_id ) { |
|
| 312 | - |
|
| 313 | - // Return true if not an editor. |
|
| 314 | - if ( ! $this->is_editor( $user_id ) ) { |
|
| 315 | - return true; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - // Check if the user explicitly denied. |
|
| 319 | - return ! $this->is_deny_editor_entity_create( $user_id ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Filter capabilities of user. |
|
| 324 | - * |
|
| 325 | - * Deny the capability of managing and editing entities for some users. |
|
| 326 | - * |
|
| 327 | - * @since 3.14.0 |
|
| 328 | - * |
|
| 329 | - * @param array $allcaps All the capabilities of the user |
|
| 330 | - * @param array $cap [0] Required capability |
|
| 331 | - * @param array $args [0] Requested capability |
|
| 332 | - * [1] User ID |
|
| 333 | - * [2] Associated object ID |
|
| 334 | - * |
|
| 335 | - * @return array The capabilities array. |
|
| 336 | - */ |
|
| 337 | - public function has_cap( $allcaps, $cap, $args ) { |
|
| 338 | - /* |
|
| 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 | + * The singleton instance of the User service. |
|
| 54 | + * |
|
| 55 | + * @since 3.1.7 |
|
| 56 | + * @access private |
|
| 57 | + * @var \Wordlift_User_Service $user_service The singleton instance of the User service. |
|
| 58 | + */ |
|
| 59 | + private static $instance; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * The {@link Wordlift_Sparql_Service} instance. |
|
| 63 | + * |
|
| 64 | + * @since 3.18.0 |
|
| 65 | + * @access private |
|
| 66 | + * @var \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance. |
|
| 67 | + */ |
|
| 68 | + private $sparql_service; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * The Entity service. |
|
| 72 | + * |
|
| 73 | + * @since 3.18.0 |
|
| 74 | + * @access private |
|
| 75 | + * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 76 | + */ |
|
| 77 | + private $entity_service; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Create an instance of the User service. |
|
| 81 | + * |
|
| 82 | + * @since 3.1.7 |
|
| 83 | + * |
|
| 84 | + * @param \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance. |
|
| 85 | + * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
|
| 86 | + */ |
|
| 87 | + public function __construct( $sparql_service, $entity_service ) { |
|
| 88 | + |
|
| 89 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' ); |
|
| 90 | + |
|
| 91 | + self::$instance = $this; |
|
| 92 | + |
|
| 93 | + $this->sparql_service = $sparql_service; |
|
| 94 | + $this->entity_service = $entity_service; |
|
| 95 | + |
|
| 96 | + add_filter( 'user_has_cap', array( $this, 'has_cap' ), 10, 3 ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Get the singleton instance of the User service. |
|
| 101 | + * |
|
| 102 | + * @since 3.1.7 |
|
| 103 | + * @return \Wordlift_User_Service The singleton instance of the User service. |
|
| 104 | + */ |
|
| 105 | + public static function get_instance() { |
|
| 106 | + |
|
| 107 | + return self::$instance; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Get the URI for a user. |
|
| 112 | + * |
|
| 113 | + * @since 3.1.7 |
|
| 114 | + * |
|
| 115 | + * @param int $user_id The user id |
|
| 116 | + * |
|
| 117 | + * @return false|string The user's URI or false in case of failure. |
|
| 118 | + */ |
|
| 119 | + public function get_uri( $user_id ) { |
|
| 120 | + |
|
| 121 | + // Try to get the URI stored in the user's meta and return it if available. |
|
| 122 | + if ( false !== ( $user_uri = $this->_get_uri( $user_id ) ) ) { |
|
| 123 | + return $user_uri; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // Try to build an URI, return false in case of failure. |
|
| 127 | + if ( false === ( $user_uri = $this->_build_uri( $user_id ) ) ) { |
|
| 128 | + return false; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // Store the URI for future requests (we need a "permanent" URI). |
|
| 132 | + $this->_set_uri( $user_id, $user_uri ); |
|
| 133 | + |
|
| 134 | + return $user_uri; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Set the `id` of the entity representing a {@link WP_User}. |
|
| 139 | + * |
|
| 140 | + * If the `id` is set to 0 (or less) then the meta is deleted. |
|
| 141 | + * |
|
| 142 | + * @since 3.14.0 |
|
| 143 | + * |
|
| 144 | + * @param int $user_id The {@link WP_User}. |
|
| 145 | + * @param int $value The entity {@link WP_Post} `id`. |
|
| 146 | + * |
|
| 147 | + * @return bool|int Meta ID if the key didn't exist, true on successful update, false on failure. |
|
| 148 | + */ |
|
| 149 | + public function set_entity( $user_id, $value ) { |
|
| 150 | + |
|
| 151 | + return 0 < $value |
|
| 152 | + ? update_user_meta( $user_id, self::ENTITY_META_KEY, $value ) |
|
| 153 | + : delete_user_meta( $user_id, self::ENTITY_META_KEY ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Get the {@link WP_Post} `id` of the entity representing a {@link WP_User}. |
|
| 158 | + * |
|
| 159 | + * @since 3.14.0 |
|
| 160 | + * |
|
| 161 | + * @param int $user_id The {@link WP_User}'s `id`. |
|
| 162 | + * |
|
| 163 | + * @return string|false The entity {@link WP_Post} `id` or an empty string if not set or false if the object id is invalid |
|
| 164 | + */ |
|
| 165 | + public function get_entity( $user_id ) { |
|
| 166 | + |
|
| 167 | + return get_user_meta( $user_id, self::ENTITY_META_KEY, true ); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Get the user's URI stored in the user's meta. |
|
| 172 | + * |
|
| 173 | + * @since 3.1.7 |
|
| 174 | + * |
|
| 175 | + * @param int $user_id The user id. |
|
| 176 | + * |
|
| 177 | + * @return false|string The user's URI or false if not found. |
|
| 178 | + */ |
|
| 179 | + private function _get_uri( $user_id ) { |
|
| 180 | + |
|
| 181 | + $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true ); |
|
| 182 | + |
|
| 183 | + if ( empty( $user_uri ) ) { |
|
| 184 | + return false; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $user_uri; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Build an URI for a user. |
|
| 192 | + * |
|
| 193 | + * @since 3.1.7 |
|
| 194 | + * |
|
| 195 | + * @param int $user_id The user's id. |
|
| 196 | + * |
|
| 197 | + * @return false|string The user's URI or false in case of failure. |
|
| 198 | + */ |
|
| 199 | + private function _build_uri( $user_id ) { |
|
| 200 | + |
|
| 201 | + // Get the user, return false in case of failure. |
|
| 202 | + if ( false === ( $user = get_userdata( $user_id ) ) ) { |
|
| 203 | + return false; |
|
| 204 | + }; |
|
| 205 | + |
|
| 206 | + // If the nicename is not set, return a failure. |
|
| 207 | + if ( empty( $user->user_nicename ) ) { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return wl_configuration_get_redlink_dataset_uri() . "/user/$user->user_nicename"; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Store the URI in user's meta. |
|
| 216 | + * |
|
| 217 | + * @since 3.1.7 |
|
| 218 | + * |
|
| 219 | + * @param int $user_id The user's id. |
|
| 220 | + * @param string $user_uri The user's uri. |
|
| 221 | + * |
|
| 222 | + * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
|
| 223 | + */ |
|
| 224 | + private function _set_uri( $user_id, $user_uri ) { |
|
| 225 | + |
|
| 226 | + return update_user_meta( $user_id, self::URI_META_KEY, $user_uri ); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Mark an editor user as denied from editing entities. |
|
| 231 | + * Does nothing if the user is not an editor |
|
| 232 | + * |
|
| 233 | + * @since 3.14.0 |
|
| 234 | + * |
|
| 235 | + * @param integer $user_id The ID of the user |
|
| 236 | + */ |
|
| 237 | + public function deny_editor_entity_create( $user_id ) { |
|
| 238 | + |
|
| 239 | + // Bail out if the user is not an editor. |
|
| 240 | + if ( ! $this->is_editor( $user_id ) ) { |
|
| 241 | + return; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // The user explicitly do not have the capability. |
|
| 245 | + update_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes' ); |
|
| 246 | + |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Remove the "deny entity editing" mark from an editor user. |
|
| 251 | + * Does nothing if the user is not an editor |
|
| 252 | + * |
|
| 253 | + * @since 3.14.0 |
|
| 254 | + * |
|
| 255 | + * @param integer $user_id The ID of the user |
|
| 256 | + */ |
|
| 257 | + public function allow_editor_entity_create( $user_id ) { |
|
| 258 | + |
|
| 259 | + // Bail out if the user is not an editor. |
|
| 260 | + if ( ! $this->is_editor( $user_id ) ) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // The user explicitly do not have the capability. |
|
| 265 | + delete_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY ); |
|
| 266 | + |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * Get whether the 'deny editor entity editing' flag is set. |
|
| 271 | + * |
|
| 272 | + * @since 3.14.0 |
|
| 273 | + * |
|
| 274 | + * @param int $user_id The {@link WP_User} `id`. |
|
| 275 | + * |
|
| 276 | + * @return int bool True if editing is denied otherwise false. |
|
| 277 | + */ |
|
| 278 | + public function is_deny_editor_entity_create( $user_id ) { |
|
| 279 | + |
|
| 280 | + return 'yes' === get_user_option( self::DENY_ENTITY_CREATE_META_KEY, $user_id ); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Check whether the {@link WP_User} with the specified `id` is an editor, |
|
| 285 | + * i.e. has the `editor` role. |
|
| 286 | + * |
|
| 287 | + * @since 3.14.0 |
|
| 288 | + * |
|
| 289 | + * @param int $user_id The {@link WP_User} `id`. |
|
| 290 | + * |
|
| 291 | + * @return bool True if the {@link WP_User} is an editor otherwise false. |
|
| 292 | + */ |
|
| 293 | + public function is_editor( $user_id ) { |
|
| 294 | + |
|
| 295 | + // Get the user. |
|
| 296 | + $user = get_user_by( 'id', $user_id ); |
|
| 297 | + |
|
| 298 | + // Return true, if the user is found and has the `editor` role. |
|
| 299 | + return is_a( $user, 'WP_User' ) && in_array( 'editor', (array) $user->roles ); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Check if an editor can create entities. |
|
| 304 | + * |
|
| 305 | + * @since 3.14.0 |
|
| 306 | + * |
|
| 307 | + * @param int $user_id The user id of the user being checked. |
|
| 308 | + * |
|
| 309 | + * @return bool false if it is an editor that is denied from edit entities, true otherwise. |
|
| 310 | + */ |
|
| 311 | + public function editor_can_create_entities( $user_id ) { |
|
| 312 | + |
|
| 313 | + // Return true if not an editor. |
|
| 314 | + if ( ! $this->is_editor( $user_id ) ) { |
|
| 315 | + return true; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + // Check if the user explicitly denied. |
|
| 319 | + return ! $this->is_deny_editor_entity_create( $user_id ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Filter capabilities of user. |
|
| 324 | + * |
|
| 325 | + * Deny the capability of managing and editing entities for some users. |
|
| 326 | + * |
|
| 327 | + * @since 3.14.0 |
|
| 328 | + * |
|
| 329 | + * @param array $allcaps All the capabilities of the user |
|
| 330 | + * @param array $cap [0] Required capability |
|
| 331 | + * @param array $args [0] Requested capability |
|
| 332 | + * [1] User ID |
|
| 333 | + * [2] Associated object ID |
|
| 334 | + * |
|
| 335 | + * @return array The capabilities array. |
|
| 336 | + */ |
|
| 337 | + public function has_cap( $allcaps, $cap, $args ) { |
|
| 338 | + /* |
|
| 339 | 339 | * For entity management/editing related capabilities |
| 340 | 340 | * check that an editor was not explicitly denied (in user profile) |
| 341 | 341 | * the capability. |
| 342 | 342 | */ |
| 343 | 343 | |
| 344 | - /* |
|
| 344 | + /* |
|
| 345 | 345 | * Need protection against the case of edit_user and likes which do not |
| 346 | 346 | * require a capability, just request one. |
| 347 | 347 | */ |
| 348 | - if ( empty( $cap ) || ! isset( $cap[0] ) ) { |
|
| 349 | - return $allcaps; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - if ( |
|
| 353 | - ( 'edit_wordlift_entity' === $cap[0] ) || |
|
| 354 | - ( 'edit_wordlift_entities' === $cap[0] ) || |
|
| 355 | - ( 'edit_others_wordlift_entities' === $cap[0] ) || |
|
| 356 | - ( 'publish_wordlift_entities' === $cap[0] ) || |
|
| 357 | - ( 'read_private_wordlift_entities' === $cap[0] ) || |
|
| 358 | - ( 'delete_wordlift_entity' === $cap[0] ) || |
|
| 359 | - ( 'delete_wordlift_entities' === $cap[0] ) || |
|
| 360 | - ( 'delete_others_wordlift_entities' === $cap[0] ) || |
|
| 361 | - ( 'delete_published_wordlift_entities' === $cap[0] ) || |
|
| 362 | - ( 'delete_private_wordlift_entities' === $cap[0] ) |
|
| 363 | - ) { |
|
| 364 | - $user_id = $args[1]; |
|
| 365 | - |
|
| 366 | - if ( ! $this->editor_can_create_entities( $user_id ) ) { |
|
| 367 | - $allcaps[ $cap[0] ] = false; |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return $allcaps; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Hook on update user meta to check if the user author has changed. |
|
| 376 | - * If so we need to execute sparql query that will update all user posts author triple. |
|
| 377 | - * |
|
| 378 | - * @since 3.18.0 |
|
| 379 | - * |
|
| 380 | - * @param null $null |
|
| 381 | - * @param int $object_id The user ID. |
|
| 382 | - * @param string $meta_key The meta key name. |
|
| 383 | - * @param mixed $meta_value Meta value. |
|
| 384 | - * @param mixed $prev_value The previous metadata value. |
|
| 385 | - * |
|
| 386 | - * @return null Null if the `meta_key` is not `Wordlift_User_Service::ENTITY_META_KEY` |
|
| 387 | - * or if the author has not changed. |
|
| 388 | - */ |
|
| 389 | - public function update_user_metadata( $null, $object_id, $meta_key, $meta_value, $prev_value ) { |
|
| 390 | - // Bail if the meta key is not the author meta. |
|
| 391 | - if ( $meta_key !== Wordlift_User_Service::ENTITY_META_KEY ) { |
|
| 392 | - return null; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - // Check whether the user is associated with any of the existing publishers/ |
|
| 396 | - $entity_id = $this->get_entity( $object_id ); |
|
| 397 | - |
|
| 398 | - if ( false === $entity_id ) { |
|
| 399 | - // An error occurred. |
|
| 400 | - $this->log_service->error( "An error occurred: entity_id can't be false." ); |
|
| 401 | - |
|
| 402 | - return; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - // Get the old uri if the entity is set.. |
|
| 406 | - $old_uri = ! empty( $entity_id ) |
|
| 407 | - ? $this->entity_service->get_uri( $entity_id ) |
|
| 408 | - : $this->get_uri( $object_id ); |
|
| 409 | - |
|
| 410 | - // Get the new user uri's. |
|
| 411 | - $new_uri = $this->entity_service->get_uri( $meta_value ); |
|
| 412 | - |
|
| 413 | - // Bail if the uri is the same. |
|
| 414 | - if ( $old_uri === $new_uri ) { |
|
| 415 | - return null; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - $this->update_author( $old_uri, $new_uri ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Hook on delete user meta to execute sparql query |
|
| 423 | - * that will update all user posts author triple. |
|
| 424 | - * |
|
| 425 | - * @since 3.18.0 |
|
| 426 | - * |
|
| 427 | - * @param null $null |
|
| 428 | - * @param int $object_id The user ID. |
|
| 429 | - * @param string $meta_key The meta key name. |
|
| 430 | - * @param mixed $meta_value Meta value. |
|
| 431 | - * @param bool $delete_all Whether to delete the matching metadata entries |
|
| 432 | - * for all objects. |
|
| 433 | - * |
|
| 434 | - * @return null Null if the `meta_key` is not `Wordlift_User_Service::ENTITY_META_KEY` |
|
| 435 | - * or if the author has not changed. |
|
| 436 | - */ |
|
| 437 | - public function delete_user_metadata( $null, $object_id, $meta_key, $meta_value, $delete_all ) { |
|
| 438 | - // Bail if the meta key is not the author meta. |
|
| 439 | - if ( $meta_key !== Wordlift_User_Service::ENTITY_META_KEY ) { |
|
| 440 | - return null; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - // Check whether the user is associated with any of the existing publishers/ |
|
| 444 | - $entity_id = $this->get_entity( $object_id ); |
|
| 445 | - |
|
| 446 | - if ( false === $entity_id ) { |
|
| 447 | - // An error occurred. |
|
| 448 | - $this->log_service->error( "An error occurred: entity_id can't be false." ); |
|
| 449 | - |
|
| 450 | - return; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // Get the old uri if the entity is set. |
|
| 454 | - $old_uri = $this->entity_service->get_uri( $entity_id ); |
|
| 455 | - |
|
| 456 | - $new_uri = $this->get_uri( $object_id ); |
|
| 457 | - |
|
| 458 | - $this->update_author( $old_uri, $new_uri ); |
|
| 459 | - |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Update the schema:author when the user author is changed. |
|
| 464 | - * |
|
| 465 | - * @since 3.18.0 |
|
| 466 | - * |
|
| 467 | - * @param string $old_uri The old uri to remove. |
|
| 468 | - * @param string $new_uri The new uri to add. |
|
| 469 | - */ |
|
| 470 | - private function update_author( $old_uri, $new_uri ) { |
|
| 471 | - // Bail in case one of the uris is empty. |
|
| 472 | - if ( empty( $old_uri ) || empty( $new_uri ) ) { |
|
| 473 | - // An error occurred. |
|
| 474 | - $this->log_service->error( "An error occurred: old_uri and/or new_uri can't be null." ); |
|
| 475 | - |
|
| 476 | - return; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - // Build the update query. |
|
| 480 | - $query = sprintf( |
|
| 481 | - 'DELETE { ?s <%1$s> <%2$s> } INSERT { ?s <%1$s> <%3$s> } WHERE { ?s <%1$s> <%2$s> }', |
|
| 482 | - // Schema:author triple. |
|
| 483 | - $this->sparql_service->escape_uri( Wordlift_Query_Builder::SCHEMA_AUTHOR_URI ), |
|
| 484 | - // Old author uri to remove, |
|
| 485 | - $this->sparql_service->escape_uri( $old_uri ), |
|
| 486 | - // New author uri to add, |
|
| 487 | - $this->sparql_service->escape_uri( $new_uri ) |
|
| 488 | - ); |
|
| 489 | - |
|
| 490 | - // Execute the query and update the author. |
|
| 491 | - $this->sparql_service->execute( $query ); |
|
| 492 | - |
|
| 493 | - } |
|
| 348 | + if ( empty( $cap ) || ! isset( $cap[0] ) ) { |
|
| 349 | + return $allcaps; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + if ( |
|
| 353 | + ( 'edit_wordlift_entity' === $cap[0] ) || |
|
| 354 | + ( 'edit_wordlift_entities' === $cap[0] ) || |
|
| 355 | + ( 'edit_others_wordlift_entities' === $cap[0] ) || |
|
| 356 | + ( 'publish_wordlift_entities' === $cap[0] ) || |
|
| 357 | + ( 'read_private_wordlift_entities' === $cap[0] ) || |
|
| 358 | + ( 'delete_wordlift_entity' === $cap[0] ) || |
|
| 359 | + ( 'delete_wordlift_entities' === $cap[0] ) || |
|
| 360 | + ( 'delete_others_wordlift_entities' === $cap[0] ) || |
|
| 361 | + ( 'delete_published_wordlift_entities' === $cap[0] ) || |
|
| 362 | + ( 'delete_private_wordlift_entities' === $cap[0] ) |
|
| 363 | + ) { |
|
| 364 | + $user_id = $args[1]; |
|
| 365 | + |
|
| 366 | + if ( ! $this->editor_can_create_entities( $user_id ) ) { |
|
| 367 | + $allcaps[ $cap[0] ] = false; |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return $allcaps; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Hook on update user meta to check if the user author has changed. |
|
| 376 | + * If so we need to execute sparql query that will update all user posts author triple. |
|
| 377 | + * |
|
| 378 | + * @since 3.18.0 |
|
| 379 | + * |
|
| 380 | + * @param null $null |
|
| 381 | + * @param int $object_id The user ID. |
|
| 382 | + * @param string $meta_key The meta key name. |
|
| 383 | + * @param mixed $meta_value Meta value. |
|
| 384 | + * @param mixed $prev_value The previous metadata value. |
|
| 385 | + * |
|
| 386 | + * @return null Null if the `meta_key` is not `Wordlift_User_Service::ENTITY_META_KEY` |
|
| 387 | + * or if the author has not changed. |
|
| 388 | + */ |
|
| 389 | + public function update_user_metadata( $null, $object_id, $meta_key, $meta_value, $prev_value ) { |
|
| 390 | + // Bail if the meta key is not the author meta. |
|
| 391 | + if ( $meta_key !== Wordlift_User_Service::ENTITY_META_KEY ) { |
|
| 392 | + return null; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + // Check whether the user is associated with any of the existing publishers/ |
|
| 396 | + $entity_id = $this->get_entity( $object_id ); |
|
| 397 | + |
|
| 398 | + if ( false === $entity_id ) { |
|
| 399 | + // An error occurred. |
|
| 400 | + $this->log_service->error( "An error occurred: entity_id can't be false." ); |
|
| 401 | + |
|
| 402 | + return; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + // Get the old uri if the entity is set.. |
|
| 406 | + $old_uri = ! empty( $entity_id ) |
|
| 407 | + ? $this->entity_service->get_uri( $entity_id ) |
|
| 408 | + : $this->get_uri( $object_id ); |
|
| 409 | + |
|
| 410 | + // Get the new user uri's. |
|
| 411 | + $new_uri = $this->entity_service->get_uri( $meta_value ); |
|
| 412 | + |
|
| 413 | + // Bail if the uri is the same. |
|
| 414 | + if ( $old_uri === $new_uri ) { |
|
| 415 | + return null; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + $this->update_author( $old_uri, $new_uri ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Hook on delete user meta to execute sparql query |
|
| 423 | + * that will update all user posts author triple. |
|
| 424 | + * |
|
| 425 | + * @since 3.18.0 |
|
| 426 | + * |
|
| 427 | + * @param null $null |
|
| 428 | + * @param int $object_id The user ID. |
|
| 429 | + * @param string $meta_key The meta key name. |
|
| 430 | + * @param mixed $meta_value Meta value. |
|
| 431 | + * @param bool $delete_all Whether to delete the matching metadata entries |
|
| 432 | + * for all objects. |
|
| 433 | + * |
|
| 434 | + * @return null Null if the `meta_key` is not `Wordlift_User_Service::ENTITY_META_KEY` |
|
| 435 | + * or if the author has not changed. |
|
| 436 | + */ |
|
| 437 | + public function delete_user_metadata( $null, $object_id, $meta_key, $meta_value, $delete_all ) { |
|
| 438 | + // Bail if the meta key is not the author meta. |
|
| 439 | + if ( $meta_key !== Wordlift_User_Service::ENTITY_META_KEY ) { |
|
| 440 | + return null; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + // Check whether the user is associated with any of the existing publishers/ |
|
| 444 | + $entity_id = $this->get_entity( $object_id ); |
|
| 445 | + |
|
| 446 | + if ( false === $entity_id ) { |
|
| 447 | + // An error occurred. |
|
| 448 | + $this->log_service->error( "An error occurred: entity_id can't be false." ); |
|
| 449 | + |
|
| 450 | + return; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // Get the old uri if the entity is set. |
|
| 454 | + $old_uri = $this->entity_service->get_uri( $entity_id ); |
|
| 455 | + |
|
| 456 | + $new_uri = $this->get_uri( $object_id ); |
|
| 457 | + |
|
| 458 | + $this->update_author( $old_uri, $new_uri ); |
|
| 459 | + |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Update the schema:author when the user author is changed. |
|
| 464 | + * |
|
| 465 | + * @since 3.18.0 |
|
| 466 | + * |
|
| 467 | + * @param string $old_uri The old uri to remove. |
|
| 468 | + * @param string $new_uri The new uri to add. |
|
| 469 | + */ |
|
| 470 | + private function update_author( $old_uri, $new_uri ) { |
|
| 471 | + // Bail in case one of the uris is empty. |
|
| 472 | + if ( empty( $old_uri ) || empty( $new_uri ) ) { |
|
| 473 | + // An error occurred. |
|
| 474 | + $this->log_service->error( "An error occurred: old_uri and/or new_uri can't be null." ); |
|
| 475 | + |
|
| 476 | + return; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + // Build the update query. |
|
| 480 | + $query = sprintf( |
|
| 481 | + 'DELETE { ?s <%1$s> <%2$s> } INSERT { ?s <%1$s> <%3$s> } WHERE { ?s <%1$s> <%2$s> }', |
|
| 482 | + // Schema:author triple. |
|
| 483 | + $this->sparql_service->escape_uri( Wordlift_Query_Builder::SCHEMA_AUTHOR_URI ), |
|
| 484 | + // Old author uri to remove, |
|
| 485 | + $this->sparql_service->escape_uri( $old_uri ), |
|
| 486 | + // New author uri to add, |
|
| 487 | + $this->sparql_service->escape_uri( $new_uri ) |
|
| 488 | + ); |
|
| 489 | + |
|
| 490 | + // Execute the query and update the author. |
|
| 491 | + $this->sparql_service->execute( $query ); |
|
| 492 | + |
|
| 493 | + } |
|
| 494 | 494 | |
| 495 | 495 | } |
@@ -84,16 +84,16 @@ discard block |
||
| 84 | 84 | * @param \Wordlift_Sparql_Service $sparql_service The {@link Wordlift_Sparql_Service} instance. |
| 85 | 85 | * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance. |
| 86 | 86 | */ |
| 87 | - public function __construct( $sparql_service, $entity_service ) { |
|
| 87 | + public function __construct($sparql_service, $entity_service) { |
|
| 88 | 88 | |
| 89 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_User_Service' ); |
|
| 89 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_User_Service'); |
|
| 90 | 90 | |
| 91 | 91 | self::$instance = $this; |
| 92 | 92 | |
| 93 | 93 | $this->sparql_service = $sparql_service; |
| 94 | 94 | $this->entity_service = $entity_service; |
| 95 | 95 | |
| 96 | - add_filter( 'user_has_cap', array( $this, 'has_cap' ), 10, 3 ); |
|
| 96 | + add_filter('user_has_cap', array($this, 'has_cap'), 10, 3); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -116,20 +116,20 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @return false|string The user's URI or false in case of failure. |
| 118 | 118 | */ |
| 119 | - public function get_uri( $user_id ) { |
|
| 119 | + public function get_uri($user_id) { |
|
| 120 | 120 | |
| 121 | 121 | // Try to get the URI stored in the user's meta and return it if available. |
| 122 | - if ( false !== ( $user_uri = $this->_get_uri( $user_id ) ) ) { |
|
| 122 | + if (false !== ($user_uri = $this->_get_uri($user_id))) { |
|
| 123 | 123 | return $user_uri; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // Try to build an URI, return false in case of failure. |
| 127 | - if ( false === ( $user_uri = $this->_build_uri( $user_id ) ) ) { |
|
| 127 | + if (false === ($user_uri = $this->_build_uri($user_id))) { |
|
| 128 | 128 | return false; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Store the URI for future requests (we need a "permanent" URI). |
| 132 | - $this->_set_uri( $user_id, $user_uri ); |
|
| 132 | + $this->_set_uri($user_id, $user_uri); |
|
| 133 | 133 | |
| 134 | 134 | return $user_uri; |
| 135 | 135 | } |
@@ -146,11 +146,11 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @return bool|int Meta ID if the key didn't exist, true on successful update, false on failure. |
| 148 | 148 | */ |
| 149 | - public function set_entity( $user_id, $value ) { |
|
| 149 | + public function set_entity($user_id, $value) { |
|
| 150 | 150 | |
| 151 | 151 | return 0 < $value |
| 152 | - ? update_user_meta( $user_id, self::ENTITY_META_KEY, $value ) |
|
| 153 | - : delete_user_meta( $user_id, self::ENTITY_META_KEY ); |
|
| 152 | + ? update_user_meta($user_id, self::ENTITY_META_KEY, $value) |
|
| 153 | + : delete_user_meta($user_id, self::ENTITY_META_KEY); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | * |
| 163 | 163 | * @return string|false The entity {@link WP_Post} `id` or an empty string if not set or false if the object id is invalid |
| 164 | 164 | */ |
| 165 | - public function get_entity( $user_id ) { |
|
| 165 | + public function get_entity($user_id) { |
|
| 166 | 166 | |
| 167 | - return get_user_meta( $user_id, self::ENTITY_META_KEY, true ); |
|
| 167 | + return get_user_meta($user_id, self::ENTITY_META_KEY, true); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @return false|string The user's URI or false if not found. |
| 178 | 178 | */ |
| 179 | - private function _get_uri( $user_id ) { |
|
| 179 | + private function _get_uri($user_id) { |
|
| 180 | 180 | |
| 181 | - $user_uri = get_user_meta( $user_id, self::URI_META_KEY, true ); |
|
| 181 | + $user_uri = get_user_meta($user_id, self::URI_META_KEY, true); |
|
| 182 | 182 | |
| 183 | - if ( empty( $user_uri ) ) { |
|
| 183 | + if (empty($user_uri)) { |
|
| 184 | 184 | return false; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -196,19 +196,19 @@ discard block |
||
| 196 | 196 | * |
| 197 | 197 | * @return false|string The user's URI or false in case of failure. |
| 198 | 198 | */ |
| 199 | - private function _build_uri( $user_id ) { |
|
| 199 | + private function _build_uri($user_id) { |
|
| 200 | 200 | |
| 201 | 201 | // Get the user, return false in case of failure. |
| 202 | - if ( false === ( $user = get_userdata( $user_id ) ) ) { |
|
| 202 | + if (false === ($user = get_userdata($user_id))) { |
|
| 203 | 203 | return false; |
| 204 | 204 | }; |
| 205 | 205 | |
| 206 | 206 | // If the nicename is not set, return a failure. |
| 207 | - if ( empty( $user->user_nicename ) ) { |
|
| 207 | + if (empty($user->user_nicename)) { |
|
| 208 | 208 | return false; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - return wl_configuration_get_redlink_dataset_uri() . "/user/$user->user_nicename"; |
|
| 211 | + return wl_configuration_get_redlink_dataset_uri()."/user/$user->user_nicename"; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -221,9 +221,9 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. |
| 223 | 223 | */ |
| 224 | - private function _set_uri( $user_id, $user_uri ) { |
|
| 224 | + private function _set_uri($user_id, $user_uri) { |
|
| 225 | 225 | |
| 226 | - return update_user_meta( $user_id, self::URI_META_KEY, $user_uri ); |
|
| 226 | + return update_user_meta($user_id, self::URI_META_KEY, $user_uri); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -234,15 +234,15 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @param integer $user_id The ID of the user |
| 236 | 236 | */ |
| 237 | - public function deny_editor_entity_create( $user_id ) { |
|
| 237 | + public function deny_editor_entity_create($user_id) { |
|
| 238 | 238 | |
| 239 | 239 | // Bail out if the user is not an editor. |
| 240 | - if ( ! $this->is_editor( $user_id ) ) { |
|
| 240 | + if ( ! $this->is_editor($user_id)) { |
|
| 241 | 241 | return; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // The user explicitly do not have the capability. |
| 245 | - update_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes' ); |
|
| 245 | + update_user_option($user_id, self::DENY_ENTITY_CREATE_META_KEY, 'yes'); |
|
| 246 | 246 | |
| 247 | 247 | } |
| 248 | 248 | |
@@ -254,15 +254,15 @@ discard block |
||
| 254 | 254 | * |
| 255 | 255 | * @param integer $user_id The ID of the user |
| 256 | 256 | */ |
| 257 | - public function allow_editor_entity_create( $user_id ) { |
|
| 257 | + public function allow_editor_entity_create($user_id) { |
|
| 258 | 258 | |
| 259 | 259 | // Bail out if the user is not an editor. |
| 260 | - if ( ! $this->is_editor( $user_id ) ) { |
|
| 260 | + if ( ! $this->is_editor($user_id)) { |
|
| 261 | 261 | return; |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // The user explicitly do not have the capability. |
| 265 | - delete_user_option( $user_id, self::DENY_ENTITY_CREATE_META_KEY ); |
|
| 265 | + delete_user_option($user_id, self::DENY_ENTITY_CREATE_META_KEY); |
|
| 266 | 266 | |
| 267 | 267 | } |
| 268 | 268 | |
@@ -275,9 +275,9 @@ discard block |
||
| 275 | 275 | * |
| 276 | 276 | * @return int bool True if editing is denied otherwise false. |
| 277 | 277 | */ |
| 278 | - public function is_deny_editor_entity_create( $user_id ) { |
|
| 278 | + public function is_deny_editor_entity_create($user_id) { |
|
| 279 | 279 | |
| 280 | - return 'yes' === get_user_option( self::DENY_ENTITY_CREATE_META_KEY, $user_id ); |
|
| 280 | + return 'yes' === get_user_option(self::DENY_ENTITY_CREATE_META_KEY, $user_id); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -290,13 +290,13 @@ discard block |
||
| 290 | 290 | * |
| 291 | 291 | * @return bool True if the {@link WP_User} is an editor otherwise false. |
| 292 | 292 | */ |
| 293 | - public function is_editor( $user_id ) { |
|
| 293 | + public function is_editor($user_id) { |
|
| 294 | 294 | |
| 295 | 295 | // Get the user. |
| 296 | - $user = get_user_by( 'id', $user_id ); |
|
| 296 | + $user = get_user_by('id', $user_id); |
|
| 297 | 297 | |
| 298 | 298 | // Return true, if the user is found and has the `editor` role. |
| 299 | - return is_a( $user, 'WP_User' ) && in_array( 'editor', (array) $user->roles ); |
|
| 299 | + return is_a($user, 'WP_User') && in_array('editor', (array) $user->roles); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -308,15 +308,15 @@ discard block |
||
| 308 | 308 | * |
| 309 | 309 | * @return bool false if it is an editor that is denied from edit entities, true otherwise. |
| 310 | 310 | */ |
| 311 | - public function editor_can_create_entities( $user_id ) { |
|
| 311 | + public function editor_can_create_entities($user_id) { |
|
| 312 | 312 | |
| 313 | 313 | // Return true if not an editor. |
| 314 | - if ( ! $this->is_editor( $user_id ) ) { |
|
| 314 | + if ( ! $this->is_editor($user_id)) { |
|
| 315 | 315 | return true; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Check if the user explicitly denied. |
| 319 | - return ! $this->is_deny_editor_entity_create( $user_id ); |
|
| 319 | + return ! $this->is_deny_editor_entity_create($user_id); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | * |
| 335 | 335 | * @return array The capabilities array. |
| 336 | 336 | */ |
| 337 | - public function has_cap( $allcaps, $cap, $args ) { |
|
| 337 | + public function has_cap($allcaps, $cap, $args) { |
|
| 338 | 338 | /* |
| 339 | 339 | * For entity management/editing related capabilities |
| 340 | 340 | * check that an editor was not explicitly denied (in user profile) |
@@ -345,26 +345,26 @@ discard block |
||
| 345 | 345 | * Need protection against the case of edit_user and likes which do not |
| 346 | 346 | * require a capability, just request one. |
| 347 | 347 | */ |
| 348 | - if ( empty( $cap ) || ! isset( $cap[0] ) ) { |
|
| 348 | + if (empty($cap) || ! isset($cap[0])) { |
|
| 349 | 349 | return $allcaps; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | if ( |
| 353 | - ( 'edit_wordlift_entity' === $cap[0] ) || |
|
| 354 | - ( 'edit_wordlift_entities' === $cap[0] ) || |
|
| 355 | - ( 'edit_others_wordlift_entities' === $cap[0] ) || |
|
| 356 | - ( 'publish_wordlift_entities' === $cap[0] ) || |
|
| 357 | - ( 'read_private_wordlift_entities' === $cap[0] ) || |
|
| 358 | - ( 'delete_wordlift_entity' === $cap[0] ) || |
|
| 359 | - ( 'delete_wordlift_entities' === $cap[0] ) || |
|
| 360 | - ( 'delete_others_wordlift_entities' === $cap[0] ) || |
|
| 361 | - ( 'delete_published_wordlift_entities' === $cap[0] ) || |
|
| 362 | - ( 'delete_private_wordlift_entities' === $cap[0] ) |
|
| 353 | + ('edit_wordlift_entity' === $cap[0]) || |
|
| 354 | + ('edit_wordlift_entities' === $cap[0]) || |
|
| 355 | + ('edit_others_wordlift_entities' === $cap[0]) || |
|
| 356 | + ('publish_wordlift_entities' === $cap[0]) || |
|
| 357 | + ('read_private_wordlift_entities' === $cap[0]) || |
|
| 358 | + ('delete_wordlift_entity' === $cap[0]) || |
|
| 359 | + ('delete_wordlift_entities' === $cap[0]) || |
|
| 360 | + ('delete_others_wordlift_entities' === $cap[0]) || |
|
| 361 | + ('delete_published_wordlift_entities' === $cap[0]) || |
|
| 362 | + ('delete_private_wordlift_entities' === $cap[0]) |
|
| 363 | 363 | ) { |
| 364 | 364 | $user_id = $args[1]; |
| 365 | 365 | |
| 366 | - if ( ! $this->editor_can_create_entities( $user_id ) ) { |
|
| 367 | - $allcaps[ $cap[0] ] = false; |
|
| 366 | + if ( ! $this->editor_can_create_entities($user_id)) { |
|
| 367 | + $allcaps[$cap[0]] = false; |
|
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | |
@@ -386,36 +386,36 @@ discard block |
||
| 386 | 386 | * @return null Null if the `meta_key` is not `Wordlift_User_Service::ENTITY_META_KEY` |
| 387 | 387 | * or if the author has not changed. |
| 388 | 388 | */ |
| 389 | - public function update_user_metadata( $null, $object_id, $meta_key, $meta_value, $prev_value ) { |
|
| 389 | + public function update_user_metadata($null, $object_id, $meta_key, $meta_value, $prev_value) { |
|
| 390 | 390 | // Bail if the meta key is not the author meta. |
| 391 | - if ( $meta_key !== Wordlift_User_Service::ENTITY_META_KEY ) { |
|
| 391 | + if ($meta_key !== Wordlift_User_Service::ENTITY_META_KEY) { |
|
| 392 | 392 | return null; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | // Check whether the user is associated with any of the existing publishers/ |
| 396 | - $entity_id = $this->get_entity( $object_id ); |
|
| 396 | + $entity_id = $this->get_entity($object_id); |
|
| 397 | 397 | |
| 398 | - if ( false === $entity_id ) { |
|
| 398 | + if (false === $entity_id) { |
|
| 399 | 399 | // An error occurred. |
| 400 | - $this->log_service->error( "An error occurred: entity_id can't be false." ); |
|
| 400 | + $this->log_service->error("An error occurred: entity_id can't be false."); |
|
| 401 | 401 | |
| 402 | 402 | return; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // Get the old uri if the entity is set.. |
| 406 | - $old_uri = ! empty( $entity_id ) |
|
| 407 | - ? $this->entity_service->get_uri( $entity_id ) |
|
| 408 | - : $this->get_uri( $object_id ); |
|
| 406 | + $old_uri = ! empty($entity_id) |
|
| 407 | + ? $this->entity_service->get_uri($entity_id) |
|
| 408 | + : $this->get_uri($object_id); |
|
| 409 | 409 | |
| 410 | 410 | // Get the new user uri's. |
| 411 | - $new_uri = $this->entity_service->get_uri( $meta_value ); |
|
| 411 | + $new_uri = $this->entity_service->get_uri($meta_value); |
|
| 412 | 412 | |
| 413 | 413 | // Bail if the uri is the same. |
| 414 | - if ( $old_uri === $new_uri ) { |
|
| 414 | + if ($old_uri === $new_uri) { |
|
| 415 | 415 | return null; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - $this->update_author( $old_uri, $new_uri ); |
|
| 418 | + $this->update_author($old_uri, $new_uri); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |
@@ -434,28 +434,28 @@ discard block |
||
| 434 | 434 | * @return null Null if the `meta_key` is not `Wordlift_User_Service::ENTITY_META_KEY` |
| 435 | 435 | * or if the author has not changed. |
| 436 | 436 | */ |
| 437 | - public function delete_user_metadata( $null, $object_id, $meta_key, $meta_value, $delete_all ) { |
|
| 437 | + public function delete_user_metadata($null, $object_id, $meta_key, $meta_value, $delete_all) { |
|
| 438 | 438 | // Bail if the meta key is not the author meta. |
| 439 | - if ( $meta_key !== Wordlift_User_Service::ENTITY_META_KEY ) { |
|
| 439 | + if ($meta_key !== Wordlift_User_Service::ENTITY_META_KEY) { |
|
| 440 | 440 | return null; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | // Check whether the user is associated with any of the existing publishers/ |
| 444 | - $entity_id = $this->get_entity( $object_id ); |
|
| 444 | + $entity_id = $this->get_entity($object_id); |
|
| 445 | 445 | |
| 446 | - if ( false === $entity_id ) { |
|
| 446 | + if (false === $entity_id) { |
|
| 447 | 447 | // An error occurred. |
| 448 | - $this->log_service->error( "An error occurred: entity_id can't be false." ); |
|
| 448 | + $this->log_service->error("An error occurred: entity_id can't be false."); |
|
| 449 | 449 | |
| 450 | 450 | return; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | // Get the old uri if the entity is set. |
| 454 | - $old_uri = $this->entity_service->get_uri( $entity_id ); |
|
| 454 | + $old_uri = $this->entity_service->get_uri($entity_id); |
|
| 455 | 455 | |
| 456 | - $new_uri = $this->get_uri( $object_id ); |
|
| 456 | + $new_uri = $this->get_uri($object_id); |
|
| 457 | 457 | |
| 458 | - $this->update_author( $old_uri, $new_uri ); |
|
| 458 | + $this->update_author($old_uri, $new_uri); |
|
| 459 | 459 | |
| 460 | 460 | } |
| 461 | 461 | |
@@ -467,11 +467,11 @@ discard block |
||
| 467 | 467 | * @param string $old_uri The old uri to remove. |
| 468 | 468 | * @param string $new_uri The new uri to add. |
| 469 | 469 | */ |
| 470 | - private function update_author( $old_uri, $new_uri ) { |
|
| 470 | + private function update_author($old_uri, $new_uri) { |
|
| 471 | 471 | // Bail in case one of the uris is empty. |
| 472 | - if ( empty( $old_uri ) || empty( $new_uri ) ) { |
|
| 472 | + if (empty($old_uri) || empty($new_uri)) { |
|
| 473 | 473 | // An error occurred. |
| 474 | - $this->log_service->error( "An error occurred: old_uri and/or new_uri can't be null." ); |
|
| 474 | + $this->log_service->error("An error occurred: old_uri and/or new_uri can't be null."); |
|
| 475 | 475 | |
| 476 | 476 | return; |
| 477 | 477 | } |
@@ -480,15 +480,15 @@ discard block |
||
| 480 | 480 | $query = sprintf( |
| 481 | 481 | 'DELETE { ?s <%1$s> <%2$s> } INSERT { ?s <%1$s> <%3$s> } WHERE { ?s <%1$s> <%2$s> }', |
| 482 | 482 | // Schema:author triple. |
| 483 | - $this->sparql_service->escape_uri( Wordlift_Query_Builder::SCHEMA_AUTHOR_URI ), |
|
| 483 | + $this->sparql_service->escape_uri(Wordlift_Query_Builder::SCHEMA_AUTHOR_URI), |
|
| 484 | 484 | // Old author uri to remove, |
| 485 | - $this->sparql_service->escape_uri( $old_uri ), |
|
| 485 | + $this->sparql_service->escape_uri($old_uri), |
|
| 486 | 486 | // New author uri to add, |
| 487 | - $this->sparql_service->escape_uri( $new_uri ) |
|
| 487 | + $this->sparql_service->escape_uri($new_uri) |
|
| 488 | 488 | ); |
| 489 | 489 | |
| 490 | 490 | // Execute the query and update the author. |
| 491 | - $this->sparql_service->execute( $query ); |
|
| 491 | + $this->sparql_service->execute($query); |
|
| 492 | 492 | |
| 493 | 493 | } |
| 494 | 494 | |
@@ -18,75 +18,75 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_User_Profile_Page { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The {@link Wordlift_Admin_Person_Element} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.14.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Admin_Author_Element $plugin The person entity |
|
| 27 | - * selection element rendering the possible persons. |
|
| 28 | - */ |
|
| 29 | - private $author_element; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * The {@link Wordlift_User_Service} instance. |
|
| 33 | - * |
|
| 34 | - * @since 3.14.0 |
|
| 35 | - * @access private |
|
| 36 | - * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 37 | - */ |
|
| 38 | - private $user_service; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Create the {@link Wordlift_Admin_User_Profile_Page} instance. |
|
| 42 | - * |
|
| 43 | - * @since 3.14.0 |
|
| 44 | - * |
|
| 45 | - * @param \Wordlift_Admin_Author_Element $author_element The person entity selection |
|
| 46 | - * element rendering the possible persons. |
|
| 47 | - * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 48 | - */ |
|
| 49 | - function __construct( $author_element, $user_service ) { |
|
| 50 | - |
|
| 51 | - $this->author_element = $author_element; |
|
| 52 | - $this->user_service = $user_service; |
|
| 53 | - |
|
| 54 | - /* |
|
| 21 | + /** |
|
| 22 | + * The {@link Wordlift_Admin_Person_Element} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.14.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Admin_Author_Element $plugin The person entity |
|
| 27 | + * selection element rendering the possible persons. |
|
| 28 | + */ |
|
| 29 | + private $author_element; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * The {@link Wordlift_User_Service} instance. |
|
| 33 | + * |
|
| 34 | + * @since 3.14.0 |
|
| 35 | + * @access private |
|
| 36 | + * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 37 | + */ |
|
| 38 | + private $user_service; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Create the {@link Wordlift_Admin_User_Profile_Page} instance. |
|
| 42 | + * |
|
| 43 | + * @since 3.14.0 |
|
| 44 | + * |
|
| 45 | + * @param \Wordlift_Admin_Author_Element $author_element The person entity selection |
|
| 46 | + * element rendering the possible persons. |
|
| 47 | + * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 48 | + */ |
|
| 49 | + function __construct( $author_element, $user_service ) { |
|
| 50 | + |
|
| 51 | + $this->author_element = $author_element; |
|
| 52 | + $this->user_service = $user_service; |
|
| 53 | + |
|
| 54 | + /* |
|
| 55 | 55 | * When an admin (or similar permissions) edits his own profile a |
| 56 | 56 | * different action than the usual is being triggered. |
| 57 | 57 | * It is too early in the wordpress boot to do user capabilities filtering |
| 58 | 58 | * here and it is deferred to the handler. |
| 59 | 59 | */ |
| 60 | - add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 61 | - add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 62 | - add_action( 'edit_user_profile_update', array( |
|
| 63 | - $this, |
|
| 64 | - 'edit_user_profile_update', |
|
| 65 | - ) ); |
|
| 66 | - add_action( 'personal_options_update', array( |
|
| 67 | - $this, |
|
| 68 | - 'edit_user_profile_update', |
|
| 69 | - ) ); |
|
| 70 | - |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Add a WordLift section in the user profile which lets |
|
| 75 | - * the admin to associate a wordpress user with a person entity. |
|
| 76 | - * |
|
| 77 | - * @since 3.14.0 |
|
| 78 | - * |
|
| 79 | - * @param WP_User $user The current WP_User object of the user being edited. |
|
| 80 | - */ |
|
| 81 | - public function edit_user_profile( $user ) { |
|
| 82 | - |
|
| 83 | - // In case it is a user editing his own profile, make sure he has admin |
|
| 84 | - // like capabilities. |
|
| 85 | - if ( ! current_user_can( 'edit_users' ) ) { |
|
| 86 | - return; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - ?> |
|
| 60 | + add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 61 | + add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 62 | + add_action( 'edit_user_profile_update', array( |
|
| 63 | + $this, |
|
| 64 | + 'edit_user_profile_update', |
|
| 65 | + ) ); |
|
| 66 | + add_action( 'personal_options_update', array( |
|
| 67 | + $this, |
|
| 68 | + 'edit_user_profile_update', |
|
| 69 | + ) ); |
|
| 70 | + |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Add a WordLift section in the user profile which lets |
|
| 75 | + * the admin to associate a wordpress user with a person entity. |
|
| 76 | + * |
|
| 77 | + * @since 3.14.0 |
|
| 78 | + * |
|
| 79 | + * @param WP_User $user The current WP_User object of the user being edited. |
|
| 80 | + */ |
|
| 81 | + public function edit_user_profile( $user ) { |
|
| 82 | + |
|
| 83 | + // In case it is a user editing his own profile, make sure he has admin |
|
| 84 | + // like capabilities. |
|
| 85 | + if ( ! current_user_can( 'edit_users' ) ) { |
|
| 86 | + return; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + ?> |
|
| 90 | 90 | <h2><?php esc_html_e( 'WordLift', 'wordlift' ); ?></h2> |
| 91 | 91 | |
| 92 | 92 | <table class="form-table"> |
@@ -96,12 +96,12 @@ discard block |
||
| 96 | 96 | </th> |
| 97 | 97 | <td> |
| 98 | 98 | <?php |
| 99 | - $this->author_element->render( array( |
|
| 100 | - 'id' => 'wl_person', |
|
| 101 | - 'name' => 'wl_person', |
|
| 102 | - 'current_entity' => $this->user_service->get_entity( $user->ID ), |
|
| 103 | - ) ); |
|
| 104 | - ?> |
|
| 99 | + $this->author_element->render( array( |
|
| 100 | + 'id' => 'wl_person', |
|
| 101 | + 'name' => 'wl_person', |
|
| 102 | + 'current_entity' => $this->user_service->get_entity( $user->ID ), |
|
| 103 | + ) ); |
|
| 104 | + ?> |
|
| 105 | 105 | <p class="description"><?php _e( 'The entity, person or organization, from the vocabulary to associate with this author.', 'wordlift' ); ?></p> |
| 106 | 106 | </td> |
| 107 | 107 | </tr> |
@@ -119,54 +119,54 @@ discard block |
||
| 119 | 119 | <?php } ?> |
| 120 | 120 | </table> |
| 121 | 121 | <?php |
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Handle storing the person entity associated with the user. |
|
| 126 | - * |
|
| 127 | - * @since 3.14.0 |
|
| 128 | - * |
|
| 129 | - * @param int $user_id The user id of the user being saved. |
|
| 130 | - */ |
|
| 131 | - public function edit_user_profile_update( $user_id ) { |
|
| 132 | - |
|
| 133 | - // In case it is a user editing his own profile, make sure he has admin |
|
| 134 | - // like capabilities. |
|
| 135 | - if ( ! current_user_can( 'edit_users' ) ) { |
|
| 136 | - return; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // Link an entity to the user. |
|
| 140 | - $this->link_entity( $user_id, $_POST ); |
|
| 141 | - |
|
| 142 | - // Deny and enable the edit entity capability |
|
| 143 | - if ( isset( $_POST['wl_can_create_entities'] ) ) { |
|
| 144 | - // User has capability so remove the deny indication if present. |
|
| 145 | - $this->user_service->allow_editor_entity_create( $user_id ); |
|
| 146 | - } else { |
|
| 147 | - $this->user_service->deny_editor_entity_create( $user_id ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Link an entity (specified in the `$_POST` array) to the {@link WP_User} |
|
| 154 | - * with the specified `id`. |
|
| 155 | - * |
|
| 156 | - * @since 3.14.0 |
|
| 157 | - * |
|
| 158 | - * @param int $user_id The {@link WP_User} `id`. |
|
| 159 | - * @param array $post The `$_POST` array. |
|
| 160 | - */ |
|
| 161 | - private function link_entity( $user_id, $post ) { |
|
| 162 | - |
|
| 163 | - // Bail out if the `wl_person` parameter isn't set. |
|
| 164 | - if ( ! isset( $post['wl_person'] ) || ! is_numeric( $post['wl_person'] ) ) { |
|
| 165 | - return; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $this->user_service->set_entity( $user_id, intval( $post['wl_person'] ) ); |
|
| 169 | - |
|
| 170 | - } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Handle storing the person entity associated with the user. |
|
| 126 | + * |
|
| 127 | + * @since 3.14.0 |
|
| 128 | + * |
|
| 129 | + * @param int $user_id The user id of the user being saved. |
|
| 130 | + */ |
|
| 131 | + public function edit_user_profile_update( $user_id ) { |
|
| 132 | + |
|
| 133 | + // In case it is a user editing his own profile, make sure he has admin |
|
| 134 | + // like capabilities. |
|
| 135 | + if ( ! current_user_can( 'edit_users' ) ) { |
|
| 136 | + return; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // Link an entity to the user. |
|
| 140 | + $this->link_entity( $user_id, $_POST ); |
|
| 141 | + |
|
| 142 | + // Deny and enable the edit entity capability |
|
| 143 | + if ( isset( $_POST['wl_can_create_entities'] ) ) { |
|
| 144 | + // User has capability so remove the deny indication if present. |
|
| 145 | + $this->user_service->allow_editor_entity_create( $user_id ); |
|
| 146 | + } else { |
|
| 147 | + $this->user_service->deny_editor_entity_create( $user_id ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Link an entity (specified in the `$_POST` array) to the {@link WP_User} |
|
| 154 | + * with the specified `id`. |
|
| 155 | + * |
|
| 156 | + * @since 3.14.0 |
|
| 157 | + * |
|
| 158 | + * @param int $user_id The {@link WP_User} `id`. |
|
| 159 | + * @param array $post The `$_POST` array. |
|
| 160 | + */ |
|
| 161 | + private function link_entity( $user_id, $post ) { |
|
| 162 | + |
|
| 163 | + // Bail out if the `wl_person` parameter isn't set. |
|
| 164 | + if ( ! isset( $post['wl_person'] ) || ! is_numeric( $post['wl_person'] ) ) { |
|
| 165 | + return; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $this->user_service->set_entity( $user_id, intval( $post['wl_person'] ) ); |
|
| 169 | + |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | 172 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * element rendering the possible persons. |
| 47 | 47 | * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
| 48 | 48 | */ |
| 49 | - function __construct( $author_element, $user_service ) { |
|
| 49 | + function __construct($author_element, $user_service) { |
|
| 50 | 50 | |
| 51 | 51 | $this->author_element = $author_element; |
| 52 | 52 | $this->user_service = $user_service; |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | * It is too early in the wordpress boot to do user capabilities filtering |
| 58 | 58 | * here and it is deferred to the handler. |
| 59 | 59 | */ |
| 60 | - add_action( 'show_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 61 | - add_action( 'edit_user_profile', array( $this, 'edit_user_profile' ) ); |
|
| 62 | - add_action( 'edit_user_profile_update', array( |
|
| 60 | + add_action('show_user_profile', array($this, 'edit_user_profile')); |
|
| 61 | + add_action('edit_user_profile', array($this, 'edit_user_profile')); |
|
| 62 | + add_action('edit_user_profile_update', array( |
|
| 63 | 63 | $this, |
| 64 | 64 | 'edit_user_profile_update', |
| 65 | - ) ); |
|
| 66 | - add_action( 'personal_options_update', array( |
|
| 65 | + )); |
|
| 66 | + add_action('personal_options_update', array( |
|
| 67 | 67 | $this, |
| 68 | 68 | 'edit_user_profile_update', |
| 69 | - ) ); |
|
| 69 | + )); |
|
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
@@ -78,43 +78,43 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param WP_User $user The current WP_User object of the user being edited. |
| 80 | 80 | */ |
| 81 | - public function edit_user_profile( $user ) { |
|
| 81 | + public function edit_user_profile($user) { |
|
| 82 | 82 | |
| 83 | 83 | // In case it is a user editing his own profile, make sure he has admin |
| 84 | 84 | // like capabilities. |
| 85 | - if ( ! current_user_can( 'edit_users' ) ) { |
|
| 85 | + if ( ! current_user_can('edit_users')) { |
|
| 86 | 86 | return; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | ?> |
| 90 | - <h2><?php esc_html_e( 'WordLift', 'wordlift' ); ?></h2> |
|
| 90 | + <h2><?php esc_html_e('WordLift', 'wordlift'); ?></h2> |
|
| 91 | 91 | |
| 92 | 92 | <table class="form-table"> |
| 93 | 93 | <tr class="user-description-wrap"> |
| 94 | 94 | <th><label |
| 95 | - for="wl_person"><?php _e( 'Author from the vocabulary', 'wordlift' ); ?></label> |
|
| 95 | + for="wl_person"><?php _e('Author from the vocabulary', 'wordlift'); ?></label> |
|
| 96 | 96 | </th> |
| 97 | 97 | <td> |
| 98 | 98 | <?php |
| 99 | - $this->author_element->render( array( |
|
| 99 | + $this->author_element->render(array( |
|
| 100 | 100 | 'id' => 'wl_person', |
| 101 | 101 | 'name' => 'wl_person', |
| 102 | - 'current_entity' => $this->user_service->get_entity( $user->ID ), |
|
| 103 | - ) ); |
|
| 102 | + 'current_entity' => $this->user_service->get_entity($user->ID), |
|
| 103 | + )); |
|
| 104 | 104 | ?> |
| 105 | - <p class="description"><?php _e( 'The entity, person or organization, from the vocabulary to associate with this author.', 'wordlift' ); ?></p> |
|
| 105 | + <p class="description"><?php _e('The entity, person or organization, from the vocabulary to associate with this author.', 'wordlift'); ?></p> |
|
| 106 | 106 | </td> |
| 107 | 107 | </tr> |
| 108 | - <?php if ( $this->user_service->is_editor( $user->ID ) ) { ?> |
|
| 108 | + <?php if ($this->user_service->is_editor($user->ID)) { ?> |
|
| 109 | 109 | <tr> |
| 110 | 110 | <th> |
| 111 | 111 | <label |
| 112 | - for="wl_can_create_entities"><?php esc_html_e( 'Can create new entities', 'wordlift' ) ?></label> |
|
| 112 | + for="wl_can_create_entities"><?php esc_html_e('Can create new entities', 'wordlift') ?></label> |
|
| 113 | 113 | </th> |
| 114 | 114 | <td> |
| 115 | 115 | <input id="wl_can_create_entities" |
| 116 | 116 | name="wl_can_create_entities" |
| 117 | - type="checkbox" <?php checked( $this->user_service->editor_can_create_entities( $user->ID ) ) ?> |
|
| 117 | + type="checkbox" <?php checked($this->user_service->editor_can_create_entities($user->ID)) ?> |
|
| 118 | 118 | </td> |
| 119 | 119 | <?php } ?> |
| 120 | 120 | </table> |
@@ -128,23 +128,23 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @param int $user_id The user id of the user being saved. |
| 130 | 130 | */ |
| 131 | - public function edit_user_profile_update( $user_id ) { |
|
| 131 | + public function edit_user_profile_update($user_id) { |
|
| 132 | 132 | |
| 133 | 133 | // In case it is a user editing his own profile, make sure he has admin |
| 134 | 134 | // like capabilities. |
| 135 | - if ( ! current_user_can( 'edit_users' ) ) { |
|
| 135 | + if ( ! current_user_can('edit_users')) { |
|
| 136 | 136 | return; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Link an entity to the user. |
| 140 | - $this->link_entity( $user_id, $_POST ); |
|
| 140 | + $this->link_entity($user_id, $_POST); |
|
| 141 | 141 | |
| 142 | 142 | // Deny and enable the edit entity capability |
| 143 | - if ( isset( $_POST['wl_can_create_entities'] ) ) { |
|
| 143 | + if (isset($_POST['wl_can_create_entities'])) { |
|
| 144 | 144 | // User has capability so remove the deny indication if present. |
| 145 | - $this->user_service->allow_editor_entity_create( $user_id ); |
|
| 145 | + $this->user_service->allow_editor_entity_create($user_id); |
|
| 146 | 146 | } else { |
| 147 | - $this->user_service->deny_editor_entity_create( $user_id ); |
|
| 147 | + $this->user_service->deny_editor_entity_create($user_id); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | } |
@@ -158,14 +158,14 @@ discard block |
||
| 158 | 158 | * @param int $user_id The {@link WP_User} `id`. |
| 159 | 159 | * @param array $post The `$_POST` array. |
| 160 | 160 | */ |
| 161 | - private function link_entity( $user_id, $post ) { |
|
| 161 | + private function link_entity($user_id, $post) { |
|
| 162 | 162 | |
| 163 | 163 | // Bail out if the `wl_person` parameter isn't set. |
| 164 | - if ( ! isset( $post['wl_person'] ) || ! is_numeric( $post['wl_person'] ) ) { |
|
| 164 | + if ( ! isset($post['wl_person']) || ! is_numeric($post['wl_person'])) { |
|
| 165 | 165 | return; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $this->user_service->set_entity( $user_id, intval( $post['wl_person'] ) ); |
|
| 168 | + $this->user_service->set_entity($user_id, intval($post['wl_person'])); |
|
| 169 | 169 | |
| 170 | 170 | } |
| 171 | 171 | |