PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | lib/class-wp-rest-icons-controller-gutenberg.php +39 -2 23.7.2 → 24.1.0 View file →
@@ -96,11 +96,13 @@
96 96 * @param WP_REST_Request $request Full details about the request.
97 97 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
98 98 */
99 99 public function get_items( $request ) {
100 - $collection = $request->get_param( 'collection' );
100 + $collection = $request->get_param( 'collection' );
101 + $collections_registry = WP_Icon_Collections_Registry::get_instance();
102 + $registered_collection = null !== $collection ? $collections_registry->get_registered( $collection ) : null;
101 103
102 - if ( null !== $collection && ! WP_Icon_Collections_Registry::get_instance()->is_registered( $collection ) ) {
104 + if ( null !== $collection && ( null === $registered_collection || ! $registered_collection['public'] ) ) {
103 105 return new WP_Error(
104 106 'rest_icon_collection_not_found',
105 107 sprintf(
106 108 /* translators: %s: Icon collection slug. */
@@ -118,13 +120,48 @@
118 120 foreach ( $icons as $icon ) {
119 121 if ( null !== $collection && ( ! isset( $icon['collection'] ) || $icon['collection'] !== $collection ) ) {
120 122 continue;
121 123 }
124 + $icon_collection = $collections_registry->get_registered( $icon['collection'] );
125 + if ( null === $icon_collection || ! $icon_collection['public'] ) {
126 + continue;
127 + }
122 128 $prepared_icon = $this->prepare_item_for_response( $icon, $request );
123 129 $response[] = $this->prepare_response_for_collection( $prepared_icon );
124 130 }
125 131
126 132 return rest_ensure_response( $response );
133 + }
134 +
135 + /**
136 + * Retrieves a specific icon from the registry.
137 + *
138 + * Icons belonging to non-public collections are reported as not found.
139 + *
140 + * @param string $name Icon name.
141 + * @return array|WP_Error Icon data on success, or WP_Error object on failure.
142 + */
143 + public function get_icon( $name ) {
144 + $icon = parent::get_icon( $name );
145 +
146 + if ( is_wp_error( $icon ) ) {
147 + return $icon;
148 + }
149 +
150 + $collection = WP_Icon_Collections_Registry::get_instance()->get_registered( $icon['collection'] );
151 + if ( null === $collection || ! $collection['public'] ) {
152 + return new WP_Error(
153 + 'rest_icon_not_found',
154 + sprintf(
155 + // translators: %s is the name of any user-provided name
156 + __( 'Icon not found: "%s".', 'gutenberg' ),
157 + $name
158 + ),
159 + array( 'status' => 404 )
160 + );
161 + }
162 +
163 + return $icon;
127 164 }
128 165
129 166 /**
130 167 * Prepare a raw icon before it gets output in a REST API response.