@@ -14,167 +14,167 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Wordlift_Entity_Type_Taxonomy_Service { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The WordPress taxonomy name. |
|
| 19 | - * |
|
| 20 | - * @since 1.0.0 |
|
| 21 | - */ |
|
| 22 | - const TAXONOMY_NAME = 'wl_entity_type'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Register the taxonomies. |
|
| 26 | - * |
|
| 27 | - * @since 3.23.6 we hook to `wp_get_object_terms` to ensure that a term is returned when a post is queries for the |
|
| 28 | - * `wl_entity_type` taxonomy. |
|
| 29 | - * @since 3.18.0 |
|
| 30 | - */ |
|
| 31 | - public function init() { |
|
| 32 | - |
|
| 33 | - $labels = array( |
|
| 34 | - 'name' => _x( 'Entity Types', 'taxonomy general name', 'wordlift' ), |
|
| 35 | - 'singular_name' => _x( 'Entity Type', 'taxonomy singular name', 'wordlift' ), |
|
| 36 | - 'search_items' => __( 'Search Entity Types', 'wordlift' ), |
|
| 37 | - 'all_items' => __( 'All Entity Types', 'wordlift' ), |
|
| 38 | - 'parent_item' => __( 'Parent Entity Type', 'wordlift' ), |
|
| 39 | - 'parent_item_colon' => __( 'Parent Entity Type:', 'wordlift' ), |
|
| 40 | - 'edit_item' => __( 'Edit Entity Type', 'wordlift' ), |
|
| 41 | - 'update_item' => __( 'Update Entity Type', 'wordlift' ), |
|
| 42 | - 'add_new_item' => __( 'Add New Entity Type', 'wordlift' ), |
|
| 43 | - 'new_item_name' => __( 'New Entity Type', 'wordlift' ), |
|
| 44 | - 'menu_name' => __( 'Entity Types', 'wordlift' ), |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - // Take away GUI for taxonomy editing. |
|
| 48 | - // TODO: read capabilities when editing of the WL <-> schema.org mapping is possible. |
|
| 49 | - $capabilities = array( |
|
| 50 | - // We enable editors to change the title/description of terms: |
|
| 51 | - // |
|
| 52 | - // @see https://github.com/insideout10/wordlift-plugin/issues/398. |
|
| 53 | - 'manage_terms' => 'manage_options', |
|
| 54 | - 'edit_terms' => 'wl_entity_type_edit_term', |
|
| 55 | - 'delete_terms' => 'wl_entity_type_delete_term', |
|
| 56 | - 'assign_terms' => 'edit_posts', |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - $args = array( |
|
| 60 | - 'labels' => $labels, |
|
| 61 | - 'capabilities' => $capabilities, |
|
| 62 | - 'hierarchical' => true, |
|
| 63 | - 'show_admin_column' => apply_filters( 'wl_feature__enable__entity-types-taxonomy', true ), |
|
| 64 | - 'show_in_rest' => apply_filters( 'wl_feature__enable__entity-types-taxonomy', true ), |
|
| 65 | - 'show_in_quick_edit' => false, |
|
| 66 | - 'publicly_queryable' => false |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - /* |
|
| 17 | + /** |
|
| 18 | + * The WordPress taxonomy name. |
|
| 19 | + * |
|
| 20 | + * @since 1.0.0 |
|
| 21 | + */ |
|
| 22 | + const TAXONOMY_NAME = 'wl_entity_type'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Register the taxonomies. |
|
| 26 | + * |
|
| 27 | + * @since 3.23.6 we hook to `wp_get_object_terms` to ensure that a term is returned when a post is queries for the |
|
| 28 | + * `wl_entity_type` taxonomy. |
|
| 29 | + * @since 3.18.0 |
|
| 30 | + */ |
|
| 31 | + public function init() { |
|
| 32 | + |
|
| 33 | + $labels = array( |
|
| 34 | + 'name' => _x( 'Entity Types', 'taxonomy general name', 'wordlift' ), |
|
| 35 | + 'singular_name' => _x( 'Entity Type', 'taxonomy singular name', 'wordlift' ), |
|
| 36 | + 'search_items' => __( 'Search Entity Types', 'wordlift' ), |
|
| 37 | + 'all_items' => __( 'All Entity Types', 'wordlift' ), |
|
| 38 | + 'parent_item' => __( 'Parent Entity Type', 'wordlift' ), |
|
| 39 | + 'parent_item_colon' => __( 'Parent Entity Type:', 'wordlift' ), |
|
| 40 | + 'edit_item' => __( 'Edit Entity Type', 'wordlift' ), |
|
| 41 | + 'update_item' => __( 'Update Entity Type', 'wordlift' ), |
|
| 42 | + 'add_new_item' => __( 'Add New Entity Type', 'wordlift' ), |
|
| 43 | + 'new_item_name' => __( 'New Entity Type', 'wordlift' ), |
|
| 44 | + 'menu_name' => __( 'Entity Types', 'wordlift' ), |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + // Take away GUI for taxonomy editing. |
|
| 48 | + // TODO: read capabilities when editing of the WL <-> schema.org mapping is possible. |
|
| 49 | + $capabilities = array( |
|
| 50 | + // We enable editors to change the title/description of terms: |
|
| 51 | + // |
|
| 52 | + // @see https://github.com/insideout10/wordlift-plugin/issues/398. |
|
| 53 | + 'manage_terms' => 'manage_options', |
|
| 54 | + 'edit_terms' => 'wl_entity_type_edit_term', |
|
| 55 | + 'delete_terms' => 'wl_entity_type_delete_term', |
|
| 56 | + 'assign_terms' => 'edit_posts', |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + $args = array( |
|
| 60 | + 'labels' => $labels, |
|
| 61 | + 'capabilities' => $capabilities, |
|
| 62 | + 'hierarchical' => true, |
|
| 63 | + 'show_admin_column' => apply_filters( 'wl_feature__enable__entity-types-taxonomy', true ), |
|
| 64 | + 'show_in_rest' => apply_filters( 'wl_feature__enable__entity-types-taxonomy', true ), |
|
| 65 | + 'show_in_quick_edit' => false, |
|
| 66 | + 'publicly_queryable' => false |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + /* |
|
| 70 | 70 | * If `All Entity Types` is enabled, use the new metabox. |
| 71 | 71 | * |
| 72 | 72 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 73 | 73 | * @since 3.20.0 |
| 74 | 74 | */ |
| 75 | - if ( WL_ALL_ENTITY_TYPES ) { |
|
| 76 | - $args['meta_box_cb'] = apply_filters( 'wl_feature__enable__entity-types-taxonomy', true ) ? array( 'Wordlift_Admin_Schemaorg_Taxonomy_Metabox', 'render' ) : false; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - register_taxonomy( |
|
| 80 | - self::TAXONOMY_NAME, // Taxonomy name. |
|
| 81 | - Wordlift_Entity_Service::valid_entity_post_types(), // Taxonomy post types. |
|
| 82 | - $args // Taxonomy args. |
|
| 83 | - ); |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Register meta wl_entities_gutenberg for use in Gutenberg |
|
| 87 | - */ |
|
| 88 | - register_meta( 'post', 'wl_entities_gutenberg', array( |
|
| 89 | - 'show_in_rest' => true, |
|
| 90 | - 'single' => true, |
|
| 91 | - 'type' => 'string', |
|
| 92 | - ) ); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Register meta _wl_alt_label for use in Gutenberg |
|
| 96 | - */ |
|
| 97 | - register_meta( 'post', Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, array( |
|
| 98 | - 'object_subtype' => '', |
|
| 99 | - 'show_in_rest' => true, |
|
| 100 | - 'single' => false, |
|
| 101 | - 'type' => 'string', |
|
| 102 | - 'auth_callback' => function () { |
|
| 103 | - return current_user_can( 'edit_posts' ); |
|
| 104 | - } |
|
| 105 | - ) ); |
|
| 106 | - |
|
| 107 | - // Add filter to change the metabox CSS class. |
|
| 108 | - add_filter( 'postbox_classes_entity_wl_entity_typediv', 'wl_admin_metaboxes_add_css_class' ); |
|
| 109 | - |
|
| 110 | - // Add a filter to preset the object term if none is set. |
|
| 111 | - // |
|
| 112 | - // DO NOT hook to `wp_get_object_terms`, because `wp_get_object_terms` returns imploded values for SQL queries. |
|
| 113 | - // |
|
| 114 | - // @see https://github.com/insideout10/wordlift-plugin/issues/995 |
|
| 115 | - // @since 3.23.6 |
|
| 116 | - add_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 10, 4 ); |
|
| 117 | - |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Hook to the `get_object_terms` filter. |
|
| 122 | - * |
|
| 123 | - * We check if our taxonomy is requested and whether a term has been returned. If no term has been returned we |
|
| 124 | - * preset `Article` for posts/pages and 'Thing' for everything else and we query the terms again. |
|
| 125 | - * |
|
| 126 | - * @param array $terms Array of terms for the given object or objects. |
|
| 127 | - * @param int[] $object_ids Array of object IDs for which terms were retrieved. |
|
| 128 | - * @param string[] $taxonomies Array of taxonomy names from which terms were retrieved. |
|
| 129 | - * @param array $args Array of arguments for retrieving terms for the given |
|
| 130 | - * object(s). See get_object_terms() for details. |
|
| 131 | - * |
|
| 132 | - * @return array|WP_Error |
|
| 133 | - * @since 3.23.6 |
|
| 134 | - */ |
|
| 135 | - public function get_object_terms( $terms, $object_ids, $taxonomies, $args ) { |
|
| 136 | - // Get our entity type. |
|
| 137 | - $entity_type = self::TAXONOMY_NAME; |
|
| 138 | - |
|
| 139 | - // Check if this is a query for our entity type, that no terms have been found and that we have an article |
|
| 140 | - // term to preset in case. |
|
| 141 | - if ( ! taxonomy_exists( $entity_type ) |
|
| 142 | - || array( $entity_type ) !== (array) $taxonomies |
|
| 143 | - || ! empty( $terms ) |
|
| 144 | - || ! term_exists( 'article', $entity_type ) |
|
| 145 | - || ! term_exists( 'thing', $entity_type ) ) { |
|
| 146 | - |
|
| 147 | - // Return the input value. |
|
| 148 | - return $terms; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Avoid nested calls in case of issues. |
|
| 152 | - remove_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 10 ); |
|
| 153 | - |
|
| 154 | - // Set the default term for all the queried object. |
|
| 155 | - foreach ( (array) $object_ids as $object_id ) { |
|
| 156 | - $post_type = get_post_type( $object_id ); |
|
| 157 | - if ( Wordlift_Entity_Type_Service::is_valid_entity_post_type( $post_type ) ) { |
|
| 158 | - // Set the term to article for posts and pages, or to thing for everything else. |
|
| 159 | - $uris = Wordlift_Entity_Type_Adapter::get_entity_types( $post_type ); |
|
| 160 | - foreach ( $uris as $uri ) { |
|
| 161 | - // set the uri based on post type. |
|
| 162 | - if ( $uri === 'http://schema.org/Article' || $uri === 'http://schema.org/Thing' ) { |
|
| 163 | - $uri = Wordlift_Entity_Service::TYPE_NAME === $post_type ? |
|
| 164 | - 'http://schema.org/Thing' : 'http://schema.org/Article'; |
|
| 165 | - } |
|
| 166 | - Wordlift_Entity_Type_Service::get_instance()->set( $object_id, $uri ); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // Finally return the object terms. |
|
| 172 | - $terms = wp_get_object_terms( $object_ids, $taxonomies, $args ); |
|
| 173 | - |
|
| 174 | - // Re-enable nested calls in case of issues. |
|
| 175 | - add_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 10, 4 ); |
|
| 176 | - |
|
| 177 | - return $terms; |
|
| 178 | - } |
|
| 75 | + if ( WL_ALL_ENTITY_TYPES ) { |
|
| 76 | + $args['meta_box_cb'] = apply_filters( 'wl_feature__enable__entity-types-taxonomy', true ) ? array( 'Wordlift_Admin_Schemaorg_Taxonomy_Metabox', 'render' ) : false; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + register_taxonomy( |
|
| 80 | + self::TAXONOMY_NAME, // Taxonomy name. |
|
| 81 | + Wordlift_Entity_Service::valid_entity_post_types(), // Taxonomy post types. |
|
| 82 | + $args // Taxonomy args. |
|
| 83 | + ); |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Register meta wl_entities_gutenberg for use in Gutenberg |
|
| 87 | + */ |
|
| 88 | + register_meta( 'post', 'wl_entities_gutenberg', array( |
|
| 89 | + 'show_in_rest' => true, |
|
| 90 | + 'single' => true, |
|
| 91 | + 'type' => 'string', |
|
| 92 | + ) ); |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Register meta _wl_alt_label for use in Gutenberg |
|
| 96 | + */ |
|
| 97 | + register_meta( 'post', Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, array( |
|
| 98 | + 'object_subtype' => '', |
|
| 99 | + 'show_in_rest' => true, |
|
| 100 | + 'single' => false, |
|
| 101 | + 'type' => 'string', |
|
| 102 | + 'auth_callback' => function () { |
|
| 103 | + return current_user_can( 'edit_posts' ); |
|
| 104 | + } |
|
| 105 | + ) ); |
|
| 106 | + |
|
| 107 | + // Add filter to change the metabox CSS class. |
|
| 108 | + add_filter( 'postbox_classes_entity_wl_entity_typediv', 'wl_admin_metaboxes_add_css_class' ); |
|
| 109 | + |
|
| 110 | + // Add a filter to preset the object term if none is set. |
|
| 111 | + // |
|
| 112 | + // DO NOT hook to `wp_get_object_terms`, because `wp_get_object_terms` returns imploded values for SQL queries. |
|
| 113 | + // |
|
| 114 | + // @see https://github.com/insideout10/wordlift-plugin/issues/995 |
|
| 115 | + // @since 3.23.6 |
|
| 116 | + add_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 10, 4 ); |
|
| 117 | + |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Hook to the `get_object_terms` filter. |
|
| 122 | + * |
|
| 123 | + * We check if our taxonomy is requested and whether a term has been returned. If no term has been returned we |
|
| 124 | + * preset `Article` for posts/pages and 'Thing' for everything else and we query the terms again. |
|
| 125 | + * |
|
| 126 | + * @param array $terms Array of terms for the given object or objects. |
|
| 127 | + * @param int[] $object_ids Array of object IDs for which terms were retrieved. |
|
| 128 | + * @param string[] $taxonomies Array of taxonomy names from which terms were retrieved. |
|
| 129 | + * @param array $args Array of arguments for retrieving terms for the given |
|
| 130 | + * object(s). See get_object_terms() for details. |
|
| 131 | + * |
|
| 132 | + * @return array|WP_Error |
|
| 133 | + * @since 3.23.6 |
|
| 134 | + */ |
|
| 135 | + public function get_object_terms( $terms, $object_ids, $taxonomies, $args ) { |
|
| 136 | + // Get our entity type. |
|
| 137 | + $entity_type = self::TAXONOMY_NAME; |
|
| 138 | + |
|
| 139 | + // Check if this is a query for our entity type, that no terms have been found and that we have an article |
|
| 140 | + // term to preset in case. |
|
| 141 | + if ( ! taxonomy_exists( $entity_type ) |
|
| 142 | + || array( $entity_type ) !== (array) $taxonomies |
|
| 143 | + || ! empty( $terms ) |
|
| 144 | + || ! term_exists( 'article', $entity_type ) |
|
| 145 | + || ! term_exists( 'thing', $entity_type ) ) { |
|
| 146 | + |
|
| 147 | + // Return the input value. |
|
| 148 | + return $terms; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Avoid nested calls in case of issues. |
|
| 152 | + remove_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 10 ); |
|
| 153 | + |
|
| 154 | + // Set the default term for all the queried object. |
|
| 155 | + foreach ( (array) $object_ids as $object_id ) { |
|
| 156 | + $post_type = get_post_type( $object_id ); |
|
| 157 | + if ( Wordlift_Entity_Type_Service::is_valid_entity_post_type( $post_type ) ) { |
|
| 158 | + // Set the term to article for posts and pages, or to thing for everything else. |
|
| 159 | + $uris = Wordlift_Entity_Type_Adapter::get_entity_types( $post_type ); |
|
| 160 | + foreach ( $uris as $uri ) { |
|
| 161 | + // set the uri based on post type. |
|
| 162 | + if ( $uri === 'http://schema.org/Article' || $uri === 'http://schema.org/Thing' ) { |
|
| 163 | + $uri = Wordlift_Entity_Service::TYPE_NAME === $post_type ? |
|
| 164 | + 'http://schema.org/Thing' : 'http://schema.org/Article'; |
|
| 165 | + } |
|
| 166 | + Wordlift_Entity_Type_Service::get_instance()->set( $object_id, $uri ); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // Finally return the object terms. |
|
| 172 | + $terms = wp_get_object_terms( $object_ids, $taxonomies, $args ); |
|
| 173 | + |
|
| 174 | + // Re-enable nested calls in case of issues. |
|
| 175 | + add_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 10, 4 ); |
|
| 176 | + |
|
| 177 | + return $terms; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | } |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | public function init() { |
| 32 | 32 | |
| 33 | 33 | $labels = array( |
| 34 | - 'name' => _x( 'Entity Types', 'taxonomy general name', 'wordlift' ), |
|
| 35 | - 'singular_name' => _x( 'Entity Type', 'taxonomy singular name', 'wordlift' ), |
|
| 36 | - 'search_items' => __( 'Search Entity Types', 'wordlift' ), |
|
| 37 | - 'all_items' => __( 'All Entity Types', 'wordlift' ), |
|
| 38 | - 'parent_item' => __( 'Parent Entity Type', 'wordlift' ), |
|
| 39 | - 'parent_item_colon' => __( 'Parent Entity Type:', 'wordlift' ), |
|
| 40 | - 'edit_item' => __( 'Edit Entity Type', 'wordlift' ), |
|
| 41 | - 'update_item' => __( 'Update Entity Type', 'wordlift' ), |
|
| 42 | - 'add_new_item' => __( 'Add New Entity Type', 'wordlift' ), |
|
| 43 | - 'new_item_name' => __( 'New Entity Type', 'wordlift' ), |
|
| 44 | - 'menu_name' => __( 'Entity Types', 'wordlift' ), |
|
| 34 | + 'name' => _x('Entity Types', 'taxonomy general name', 'wordlift'), |
|
| 35 | + 'singular_name' => _x('Entity Type', 'taxonomy singular name', 'wordlift'), |
|
| 36 | + 'search_items' => __('Search Entity Types', 'wordlift'), |
|
| 37 | + 'all_items' => __('All Entity Types', 'wordlift'), |
|
| 38 | + 'parent_item' => __('Parent Entity Type', 'wordlift'), |
|
| 39 | + 'parent_item_colon' => __('Parent Entity Type:', 'wordlift'), |
|
| 40 | + 'edit_item' => __('Edit Entity Type', 'wordlift'), |
|
| 41 | + 'update_item' => __('Update Entity Type', 'wordlift'), |
|
| 42 | + 'add_new_item' => __('Add New Entity Type', 'wordlift'), |
|
| 43 | + 'new_item_name' => __('New Entity Type', 'wordlift'), |
|
| 44 | + 'menu_name' => __('Entity Types', 'wordlift'), |
|
| 45 | 45 | ); |
| 46 | 46 | |
| 47 | 47 | // Take away GUI for taxonomy editing. |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | 'labels' => $labels, |
| 61 | 61 | 'capabilities' => $capabilities, |
| 62 | 62 | 'hierarchical' => true, |
| 63 | - 'show_admin_column' => apply_filters( 'wl_feature__enable__entity-types-taxonomy', true ), |
|
| 64 | - 'show_in_rest' => apply_filters( 'wl_feature__enable__entity-types-taxonomy', true ), |
|
| 63 | + 'show_admin_column' => apply_filters('wl_feature__enable__entity-types-taxonomy', true), |
|
| 64 | + 'show_in_rest' => apply_filters('wl_feature__enable__entity-types-taxonomy', true), |
|
| 65 | 65 | 'show_in_quick_edit' => false, |
| 66 | 66 | 'publicly_queryable' => false |
| 67 | 67 | ); |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 73 | 73 | * @since 3.20.0 |
| 74 | 74 | */ |
| 75 | - if ( WL_ALL_ENTITY_TYPES ) { |
|
| 76 | - $args['meta_box_cb'] = apply_filters( 'wl_feature__enable__entity-types-taxonomy', true ) ? array( 'Wordlift_Admin_Schemaorg_Taxonomy_Metabox', 'render' ) : false; |
|
| 75 | + if (WL_ALL_ENTITY_TYPES) { |
|
| 76 | + $args['meta_box_cb'] = apply_filters('wl_feature__enable__entity-types-taxonomy', true) ? array('Wordlift_Admin_Schemaorg_Taxonomy_Metabox', 'render') : false; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | register_taxonomy( |
@@ -85,27 +85,27 @@ discard block |
||
| 85 | 85 | /** |
| 86 | 86 | * Register meta wl_entities_gutenberg for use in Gutenberg |
| 87 | 87 | */ |
| 88 | - register_meta( 'post', 'wl_entities_gutenberg', array( |
|
| 88 | + register_meta('post', 'wl_entities_gutenberg', array( |
|
| 89 | 89 | 'show_in_rest' => true, |
| 90 | 90 | 'single' => true, |
| 91 | 91 | 'type' => 'string', |
| 92 | - ) ); |
|
| 92 | + )); |
|
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * Register meta _wl_alt_label for use in Gutenberg |
| 96 | 96 | */ |
| 97 | - register_meta( 'post', Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, array( |
|
| 97 | + register_meta('post', Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, array( |
|
| 98 | 98 | 'object_subtype' => '', |
| 99 | 99 | 'show_in_rest' => true, |
| 100 | 100 | 'single' => false, |
| 101 | 101 | 'type' => 'string', |
| 102 | - 'auth_callback' => function () { |
|
| 103 | - return current_user_can( 'edit_posts' ); |
|
| 102 | + 'auth_callback' => function() { |
|
| 103 | + return current_user_can('edit_posts'); |
|
| 104 | 104 | } |
| 105 | - ) ); |
|
| 105 | + )); |
|
| 106 | 106 | |
| 107 | 107 | // Add filter to change the metabox CSS class. |
| 108 | - add_filter( 'postbox_classes_entity_wl_entity_typediv', 'wl_admin_metaboxes_add_css_class' ); |
|
| 108 | + add_filter('postbox_classes_entity_wl_entity_typediv', 'wl_admin_metaboxes_add_css_class'); |
|
| 109 | 109 | |
| 110 | 110 | // Add a filter to preset the object term if none is set. |
| 111 | 111 | // |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | // |
| 114 | 114 | // @see https://github.com/insideout10/wordlift-plugin/issues/995 |
| 115 | 115 | // @since 3.23.6 |
| 116 | - add_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 10, 4 ); |
|
| 116 | + add_filter('get_object_terms', array($this, 'get_object_terms'), 10, 4); |
|
| 117 | 117 | |
| 118 | 118 | } |
| 119 | 119 | |
@@ -132,47 +132,47 @@ discard block |
||
| 132 | 132 | * @return array|WP_Error |
| 133 | 133 | * @since 3.23.6 |
| 134 | 134 | */ |
| 135 | - public function get_object_terms( $terms, $object_ids, $taxonomies, $args ) { |
|
| 135 | + public function get_object_terms($terms, $object_ids, $taxonomies, $args) { |
|
| 136 | 136 | // Get our entity type. |
| 137 | 137 | $entity_type = self::TAXONOMY_NAME; |
| 138 | 138 | |
| 139 | 139 | // Check if this is a query for our entity type, that no terms have been found and that we have an article |
| 140 | 140 | // term to preset in case. |
| 141 | - if ( ! taxonomy_exists( $entity_type ) |
|
| 142 | - || array( $entity_type ) !== (array) $taxonomies |
|
| 143 | - || ! empty( $terms ) |
|
| 144 | - || ! term_exists( 'article', $entity_type ) |
|
| 145 | - || ! term_exists( 'thing', $entity_type ) ) { |
|
| 141 | + if ( ! taxonomy_exists($entity_type) |
|
| 142 | + || array($entity_type) !== (array) $taxonomies |
|
| 143 | + || ! empty($terms) |
|
| 144 | + || ! term_exists('article', $entity_type) |
|
| 145 | + || ! term_exists('thing', $entity_type)) { |
|
| 146 | 146 | |
| 147 | 147 | // Return the input value. |
| 148 | 148 | return $terms; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Avoid nested calls in case of issues. |
| 152 | - remove_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 10 ); |
|
| 152 | + remove_filter('get_object_terms', array($this, 'get_object_terms'), 10); |
|
| 153 | 153 | |
| 154 | 154 | // Set the default term for all the queried object. |
| 155 | - foreach ( (array) $object_ids as $object_id ) { |
|
| 156 | - $post_type = get_post_type( $object_id ); |
|
| 157 | - if ( Wordlift_Entity_Type_Service::is_valid_entity_post_type( $post_type ) ) { |
|
| 155 | + foreach ((array) $object_ids as $object_id) { |
|
| 156 | + $post_type = get_post_type($object_id); |
|
| 157 | + if (Wordlift_Entity_Type_Service::is_valid_entity_post_type($post_type)) { |
|
| 158 | 158 | // Set the term to article for posts and pages, or to thing for everything else. |
| 159 | - $uris = Wordlift_Entity_Type_Adapter::get_entity_types( $post_type ); |
|
| 160 | - foreach ( $uris as $uri ) { |
|
| 159 | + $uris = Wordlift_Entity_Type_Adapter::get_entity_types($post_type); |
|
| 160 | + foreach ($uris as $uri) { |
|
| 161 | 161 | // set the uri based on post type. |
| 162 | - if ( $uri === 'http://schema.org/Article' || $uri === 'http://schema.org/Thing' ) { |
|
| 162 | + if ($uri === 'http://schema.org/Article' || $uri === 'http://schema.org/Thing') { |
|
| 163 | 163 | $uri = Wordlift_Entity_Service::TYPE_NAME === $post_type ? |
| 164 | 164 | 'http://schema.org/Thing' : 'http://schema.org/Article'; |
| 165 | 165 | } |
| 166 | - Wordlift_Entity_Type_Service::get_instance()->set( $object_id, $uri ); |
|
| 166 | + Wordlift_Entity_Type_Service::get_instance()->set($object_id, $uri); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // Finally return the object terms. |
| 172 | - $terms = wp_get_object_terms( $object_ids, $taxonomies, $args ); |
|
| 172 | + $terms = wp_get_object_terms($object_ids, $taxonomies, $args); |
|
| 173 | 173 | |
| 174 | 174 | // Re-enable nested calls in case of issues. |
| 175 | - add_filter( 'get_object_terms', array( $this, 'get_object_terms' ), 10, 4 ); |
|
| 175 | + add_filter('get_object_terms', array($this, 'get_object_terms'), 10, 4); |
|
| 176 | 176 | |
| 177 | 177 | return $terms; |
| 178 | 178 | } |