code
stringlengths
2.5k
150k
kind
stringclasses
1 value
wordpress WP_REST_Posts_Controller::create_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Posts\_Controller::create\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error =========================================================================================================== Checks if a given request has access to create a post. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has access to create items, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php/) ``` public function create_item_permissions_check( $request ) { if ( ! empty( $request['id'] ) ) { return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) ); } $post_type = get_post_type_object( $this->post_type ); if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) { return new WP_Error( 'rest_cannot_edit_others', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); } if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) && ! current_user_can( $post_type->cap->publish_posts ) ) { return new WP_Error( 'rest_cannot_assign_sticky', __( 'Sorry, you are not allowed to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); } if ( ! current_user_can( $post_type->cap->create_posts ) ) { return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create posts as this user.' ), array( 'status' => rest_authorization_required_code() ) ); } if ( ! $this->check_assign_terms_permission( $request ) ) { return new WP_Error( 'rest_cannot_assign_term', __( 'Sorry, you are not allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::check\_assign\_terms\_permission()](check_assign_terms_permission) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks whether current user can assign all terms sent with the current request. | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_current\_user\_id()](../../functions/get_current_user_id) wp-includes/user.php | Gets the current user’s ID. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Attachments\_Controller::create\_item\_permissions\_check()](../wp_rest_attachments_controller/create_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php | Checks if a given request has access to create an attachment. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Posts_Controller::delete_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Posts\_Controller::delete\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ===================================================================================================== Deletes a single post. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php/) ``` public function delete_item( $request ) { $post = $this->get_post( $request['id'] ); if ( is_wp_error( $post ) ) { return $post; } $id = $post->ID; $force = (bool) $request['force']; $supports_trash = ( EMPTY_TRASH_DAYS > 0 ); if ( 'attachment' === $post->post_type ) { $supports_trash = $supports_trash && MEDIA_TRASH; } /** * Filters whether a post is trashable. * * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug. * * Possible hook names include: * * - `rest_post_trashable` * - `rest_page_trashable` * - `rest_attachment_trashable` * * Pass false to disable Trash support for the post. * * @since 4.7.0 * * @param bool $supports_trash Whether the post type support trashing. * @param WP_Post $post The Post object being considered for trashing support. */ $supports_trash = apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post ); if ( ! $this->check_delete_permission( $post ) ) { return new WP_Error( 'rest_user_cannot_delete_post', __( 'Sorry, you are not allowed to delete this post.' ), array( 'status' => rest_authorization_required_code() ) ); } $request->set_param( 'context', 'edit' ); // If we're forcing, then delete permanently. if ( $force ) { $previous = $this->prepare_item_for_response( $post, $request ); $result = wp_delete_post( $id, true ); $response = new WP_REST_Response(); $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data(), ) ); } else { // If we don't support trashing for this type, error out. if ( ! $supports_trash ) { return new WP_Error( 'rest_trash_not_supported', /* translators: %s: force=true */ sprintf( __( "The post does not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); } // Otherwise, only trash if we haven't already. if ( 'trash' === $post->post_status ) { return new WP_Error( 'rest_already_trashed', __( 'The post has already been deleted.' ), array( 'status' => 410 ) ); } // (Note that internally this falls through to `wp_delete_post()` // if the Trash is disabled.) $result = wp_trash_post( $id ); $post = get_post( $id ); $response = $this->prepare_item_for_response( $post, $request ); } if ( ! $result ) { return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); } /** * Fires immediately after a single post is deleted or trashed via the REST API. * * They dynamic portion of the hook name, `$this->post_type`, refers to the post type slug. * * Possible hook names include: * * - `rest_delete_post` * - `rest_delete_page` * - `rest_delete_attachment` * * @since 4.7.0 * * @param WP_Post $post The deleted or trashed post. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. */ do_action( "rest_delete_{$this->post_type}", $post, $response, $request ); return $response; } ``` [do\_action( "rest\_delete\_{$this->post\_type}", WP\_Post $post, WP\_REST\_Response $response, WP\_REST\_Request $request )](../../hooks/rest_delete_this-post_type) Fires immediately after a single post is deleted or trashed via the REST API. [apply\_filters( "rest\_{$this->post\_type}\_trashable", bool $supports\_trash, WP\_Post $post )](../../hooks/rest_this-post_type_trashable) Filters whether a post is trashable. | Uses | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::get\_post()](get_post) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Gets the post, if the ID is valid. | | [WP\_REST\_Posts\_Controller::check\_delete\_permission()](check_delete_permission) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks if a post can be deleted. | | [WP\_REST\_Posts\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares a single post output for response. | | [wp\_delete\_post()](../../functions/wp_delete_post) wp-includes/post.php | Trashes or deletes a post or page. | | [wp\_trash\_post()](../../functions/wp_trash_post) wp-includes/post.php | Moves a post or page to the Trash | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Posts_Controller::get_item_schema(): array WP\_REST\_Posts\_Controller::get\_item\_schema(): array ======================================================= Retrieves the post’s schema, conforming to JSON Schema. array Item schema data. File: `wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => $this->post_type, 'type' => 'object', // Base properties for every Post. 'properties' => array( 'date' => array( 'description' => __( "The date the post was published, in the site's timezone." ), 'type' => array( 'string', 'null' ), 'format' => 'date-time', 'context' => array( 'view', 'edit', 'embed' ), ), 'date_gmt' => array( 'description' => __( 'The date the post was published, as GMT.' ), 'type' => array( 'string', 'null' ), 'format' => 'date-time', 'context' => array( 'view', 'edit' ), ), 'guid' => array( 'description' => __( 'The globally unique identifier for the post.' ), 'type' => 'object', 'context' => array( 'view', 'edit' ), 'readonly' => true, 'properties' => array( 'raw' => array( 'description' => __( 'GUID for the post, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), 'readonly' => true, ), 'rendered' => array( 'description' => __( 'GUID for the post, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), ), ), 'id' => array( 'description' => __( 'Unique identifier for the post.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'link' => array( 'description' => __( 'URL to the post.' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'modified' => array( 'description' => __( "The date the post was last modified, in the site's timezone." ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'modified_gmt' => array( 'description' => __( 'The date the post was last modified, as GMT.' ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'slug' => array( 'description' => __( 'An alphanumeric identifier for the post unique to its type.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => array( $this, 'sanitize_slug' ), ), ), 'status' => array( 'description' => __( 'A named status for the post.' ), 'type' => 'string', 'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ), 'context' => array( 'view', 'edit' ), 'arg_options' => array( 'validate_callback' => array( $this, 'check_status' ), ), ), 'type' => array( 'description' => __( 'Type of post.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'password' => array( 'description' => __( 'A password to protect access to the content and excerpt.' ), 'type' => 'string', 'context' => array( 'edit' ), ), ), ); $post_type_obj = get_post_type_object( $this->post_type ); if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) { $schema['properties']['permalink_template'] = array( 'description' => __( 'Permalink template for the post.' ), 'type' => 'string', 'context' => array( 'edit' ), 'readonly' => true, ); $schema['properties']['generated_slug'] = array( 'description' => __( 'Slug automatically generated from the post title.' ), 'type' => 'string', 'context' => array( 'edit' ), 'readonly' => true, ); } if ( $post_type_obj->hierarchical ) { $schema['properties']['parent'] = array( 'description' => __( 'The ID for the parent of the post.' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), ); } $post_type_attributes = array( 'title', 'editor', 'author', 'excerpt', 'thumbnail', 'comments', 'revisions', 'page-attributes', 'post-formats', 'custom-fields', ); $fixed_schemas = array( 'post' => array( 'title', 'editor', 'author', 'excerpt', 'thumbnail', 'comments', 'revisions', 'post-formats', 'custom-fields', ), 'page' => array( 'title', 'editor', 'author', 'excerpt', 'thumbnail', 'comments', 'revisions', 'page-attributes', 'custom-fields', ), 'attachment' => array( 'title', 'author', 'comments', 'revisions', 'custom-fields', ), ); foreach ( $post_type_attributes as $attribute ) { if ( isset( $fixed_schemas[ $this->post_type ] ) && ! in_array( $attribute, $fixed_schemas[ $this->post_type ], true ) ) { continue; } elseif ( ! isset( $fixed_schemas[ $this->post_type ] ) && ! post_type_supports( $this->post_type, $attribute ) ) { continue; } switch ( $attribute ) { case 'title': $schema['properties']['title'] = array( 'description' => __( 'The title for the post.' ), 'type' => 'object', 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database(). 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database(). ), 'properties' => array( 'raw' => array( 'description' => __( 'Title for the post, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), ), 'rendered' => array( 'description' => __( 'HTML title for the post, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), ), ); break; case 'editor': $schema['properties']['content'] = array( 'description' => __( 'The content for the post.' ), 'type' => 'object', 'context' => array( 'view', 'edit' ), 'arg_options' => array( 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database(). 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database(). ), 'properties' => array( 'raw' => array( 'description' => __( 'Content for the post, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), ), 'rendered' => array( 'description' => __( 'HTML content for the post, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'block_version' => array( 'description' => __( 'Version of the content block format used by the post.' ), 'type' => 'integer', 'context' => array( 'edit' ), 'readonly' => true, ), 'protected' => array( 'description' => __( 'Whether the content is protected with a password.' ), 'type' => 'boolean', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), ), ); break; case 'author': $schema['properties']['author'] = array( 'description' => __( 'The ID for the author of the post.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), ); break; case 'excerpt': $schema['properties']['excerpt'] = array( 'description' => __( 'The excerpt for the post.' ), 'type' => 'object', 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database(). 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database(). ), 'properties' => array( 'raw' => array( 'description' => __( 'Excerpt for the post, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), ), 'rendered' => array( 'description' => __( 'HTML excerpt for the post, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'protected' => array( 'description' => __( 'Whether the excerpt is protected with a password.' ), 'type' => 'boolean', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), ), ); break; case 'thumbnail': $schema['properties']['featured_media'] = array( 'description' => __( 'The ID of the featured media for the post.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), ); break; case 'comments': $schema['properties']['comment_status'] = array( 'description' => __( 'Whether or not comments are open on the post.' ), 'type' => 'string', 'enum' => array( 'open', 'closed' ), 'context' => array( 'view', 'edit' ), ); $schema['properties']['ping_status'] = array( 'description' => __( 'Whether or not the post can be pinged.' ), 'type' => 'string', 'enum' => array( 'open', 'closed' ), 'context' => array( 'view', 'edit' ), ); break; case 'page-attributes': $schema['properties']['menu_order'] = array( 'description' => __( 'The order of the post in relation to other posts.' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), ); break; case 'post-formats': // Get the native post formats and remove the array keys. $formats = array_values( get_post_format_slugs() ); $schema['properties']['format'] = array( 'description' => __( 'The format for the post.' ), 'type' => 'string', 'enum' => $formats, 'context' => array( 'view', 'edit' ), ); break; case 'custom-fields': $schema['properties']['meta'] = $this->meta->get_field_schema(); break; } } if ( 'post' === $this->post_type ) { $schema['properties']['sticky'] = array( 'description' => __( 'Whether or not the post should be treated as sticky.' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), ); } $schema['properties']['template'] = array( 'description' => __( 'The theme file to use to display the post.' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'arg_options' => array( 'validate_callback' => array( $this, 'check_template' ), ), ); $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $taxonomy ) { $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; if ( array_key_exists( $base, $schema['properties'] ) ) { $taxonomy_field_name_with_conflict = ! empty( $taxonomy->rest_base ) ? 'rest_base' : 'name'; _doing_it_wrong( 'register_taxonomy', sprintf( /* translators: 1: The taxonomy name, 2: The property name, either 'rest_base' or 'name', 3: The conflicting value. */ __( 'The "%1$s" taxonomy "%2$s" property (%3$s) conflicts with an existing property on the REST API Posts Controller. Specify a custom "rest_base" when registering the taxonomy to avoid this error.' ), $taxonomy->name, $taxonomy_field_name_with_conflict, $base ), '5.4.0' ); } $schema['properties'][ $base ] = array( /* translators: %s: Taxonomy name. */ 'description' => sprintf( __( 'The terms assigned to the post in the %s taxonomy.' ), $taxonomy->name ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'context' => array( 'view', 'edit' ), ); } $schema_links = $this->get_schema_links(); if ( $schema_links ) { $schema['links'] = $schema_links; } // Take a snapshot of which fields are in the schema pre-filtering. $schema_fields = array_keys( $schema['properties'] ); /** * Filters the post's schema. * * The dynamic portion of the filter, `$this->post_type`, refers to the * post type slug for the controller. * * Possible hook names include: * * - `rest_post_item_schema` * - `rest_page_item_schema` * - `rest_attachment_item_schema` * * @since 5.4.0 * * @param array $schema Item schema data. */ $schema = apply_filters( "rest_{$this->post_type}_item_schema", $schema ); // Emit a _doing_it_wrong warning if user tries to add new properties using this filter. $new_fields = array_diff( array_keys( $schema['properties'] ), $schema_fields ); if ( count( $new_fields ) > 0 ) { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: register_rest_field */ __( 'Please use %s to add new schema properties.' ), 'register_rest_field' ), '5.4.0' ); } $this->schema = $schema; return $this->add_additional_fields_schema( $this->schema ); } ``` [apply\_filters( "rest\_{$this->post\_type}\_item\_schema", array $schema )](../../hooks/rest_this-post_type_item_schema) Filters the post’s schema. | Uses | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::get\_schema\_links()](get_schema_links) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves Link Description Objects that should be added to the Schema for the posts collection. | | [is\_post\_type\_viewable()](../../functions/is_post_type_viewable) wp-includes/post.php | Determines whether a post type is considered “viewable”. | | [wp\_list\_filter()](../../functions/wp_list_filter) wp-includes/functions.php | Filters a list of objects, based on a set of key => value arguments. | | [get\_object\_taxonomies()](../../functions/get_object_taxonomies) wp-includes/taxonomy.php | Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name. | | [post\_type\_supports()](../../functions/post_type_supports) wp-includes/post.php | Checks a post type’s support for a given feature. | | [get\_post\_stati()](../../functions/get_post_stati) wp-includes/post.php | Gets a list of post statuses. | | [get\_post\_format\_slugs()](../../functions/get_post_format_slugs) wp-includes/post-formats.php | Retrieves the array of post format slugs. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_doing\_it\_wrong()](../../functions/_doing_it_wrong) wp-includes/functions.php | Marks something as being incorrectly called. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | Used By | Description | | --- | --- | | [WP\_REST\_Blocks\_Controller::get\_item\_schema()](../wp_rest_blocks_controller/get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php | Retrieves the block’s schema, conforming to JSON Schema. | | [WP\_REST\_Attachments\_Controller::get\_item\_schema()](../wp_rest_attachments_controller/get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php | Retrieves the attachment’s schema, conforming to JSON Schema. | | [WP\_REST\_Posts\_Controller::prepare\_item\_for\_database()](prepare_item_for_database) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares a single post for create or update. | | [WP\_REST\_Posts\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Creates a single post. | | [WP\_REST\_Posts\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Updates a single post. | | [WP\_REST\_Posts\_Controller::register\_routes()](register_routes) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Registers the routes for posts. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |
programming_docs
wordpress WP_REST_Posts_Controller::check_status( string $status, WP_REST_Request $request, string $param ): true|WP_Error WP\_REST\_Posts\_Controller::check\_status( string $status, WP\_REST\_Request $request, string $param ): true|WP\_Error ======================================================================================================================= Checks whether the status is valid for the given post. Allows for sending an update request with the current status, even if that status would not be acceptable. `$status` string Required The provided status. `$request` [WP\_REST\_Request](../wp_rest_request) Required The request object. `$param` string Required The parameter name. true|[WP\_Error](../wp_error) True if the status is valid, or [WP\_Error](../wp_error) if not. File: `wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php/) ``` public function check_status( $status, $request, $param ) { if ( $request['id'] ) { $post = $this->get_post( $request['id'] ); if ( ! is_wp_error( $post ) && $post->post_status === $status ) { return true; } } $args = $request->get_attributes()['args'][ $param ]; return rest_validate_value_from_schema( $status, $args, $param ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::get\_post()](get_post) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Gets the post, if the ID is valid. | | [rest\_validate\_value\_from\_schema()](../../functions/rest_validate_value_from_schema) wp-includes/rest-api.php | Validate a value based on a schema. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Posts_Controller::get_available_actions( WP_Post $post, WP_REST_Request $request ): array WP\_REST\_Posts\_Controller::get\_available\_actions( WP\_Post $post, WP\_REST\_Request $request ): array ========================================================================================================= Gets the link relations available for the post and current user. `$post` [WP\_Post](../wp_post) Required Post object. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request object. array List of link relations. File: `wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php/) ``` protected function get_available_actions( $post, $request ) { if ( 'edit' !== $request['context'] ) { return array(); } $rels = array(); $post_type = get_post_type_object( $post->post_type ); if ( 'attachment' !== $this->post_type && current_user_can( $post_type->cap->publish_posts ) ) { $rels[] = 'https://api.w.org/action-publish'; } if ( current_user_can( 'unfiltered_html' ) ) { $rels[] = 'https://api.w.org/action-unfiltered-html'; } if ( 'post' === $post_type->name ) { if ( current_user_can( $post_type->cap->edit_others_posts ) && current_user_can( $post_type->cap->publish_posts ) ) { $rels[] = 'https://api.w.org/action-sticky'; } } if ( post_type_supports( $post_type->name, 'author' ) ) { if ( current_user_can( $post_type->cap->edit_others_posts ) ) { $rels[] = 'https://api.w.org/action-assign-author'; } } $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $tax ) { $tax_base = ! empty( $tax->rest_base ) ? $tax->rest_base : $tax->name; $create_cap = is_taxonomy_hierarchical( $tax->name ) ? $tax->cap->edit_terms : $tax->cap->assign_terms; if ( current_user_can( $create_cap ) ) { $rels[] = 'https://api.w.org/action-create-' . $tax_base; } if ( current_user_can( $tax->cap->assign_terms ) ) { $rels[] = 'https://api.w.org/action-assign-' . $tax_base; } } return $rels; } ``` | Uses | Description | | --- | --- | | [wp\_list\_filter()](../../functions/wp_list_filter) wp-includes/functions.php | Filters a list of objects, based on a set of key => value arguments. | | [get\_object\_taxonomies()](../../functions/get_object_taxonomies) wp-includes/taxonomy.php | Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name. | | [is\_taxonomy\_hierarchical()](../../functions/is_taxonomy_hierarchical) wp-includes/taxonomy.php | Determines whether the taxonomy object is hierarchical. | | [post\_type\_supports()](../../functions/post_type_supports) wp-includes/post.php | Checks a post type’s support for a given feature. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | Used By | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares a single post output for response. | | Version | Description | | --- | --- | | [4.9.8](https://developer.wordpress.org/reference/since/4.9.8/) | Introduced. | wordpress WP_REST_Posts_Controller::get_schema_links(): array WP\_REST\_Posts\_Controller::get\_schema\_links(): array ======================================================== Retrieves Link Description Objects that should be added to the Schema for the posts collection. array File: `wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php/) ``` protected function get_schema_links() { $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" ); $links = array(); if ( 'attachment' !== $this->post_type ) { $links[] = array( 'rel' => 'https://api.w.org/action-publish', 'title' => __( 'The current user can publish this post.' ), 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( 'status' => array( 'type' => 'string', 'enum' => array( 'publish', 'future' ), ), ), ), ); } $links[] = array( 'rel' => 'https://api.w.org/action-unfiltered-html', 'title' => __( 'The current user can post unfiltered HTML markup and JavaScript.' ), 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( 'content' => array( 'raw' => array( 'type' => 'string', ), ), ), ), ); if ( 'post' === $this->post_type ) { $links[] = array( 'rel' => 'https://api.w.org/action-sticky', 'title' => __( 'The current user can sticky this post.' ), 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( 'sticky' => array( 'type' => 'boolean', ), ), ), ); } if ( post_type_supports( $this->post_type, 'author' ) ) { $links[] = array( 'rel' => 'https://api.w.org/action-assign-author', 'title' => __( 'The current user can change the author on this post.' ), 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( 'author' => array( 'type' => 'integer', ), ), ), ); } $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $tax ) { $tax_base = ! empty( $tax->rest_base ) ? $tax->rest_base : $tax->name; /* translators: %s: Taxonomy name. */ $assign_title = sprintf( __( 'The current user can assign terms in the %s taxonomy.' ), $tax->name ); /* translators: %s: Taxonomy name. */ $create_title = sprintf( __( 'The current user can create terms in the %s taxonomy.' ), $tax->name ); $links[] = array( 'rel' => 'https://api.w.org/action-assign-' . $tax_base, 'title' => $assign_title, 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( $tax_base => array( 'type' => 'array', 'items' => array( 'type' => 'integer', ), ), ), ), ); $links[] = array( 'rel' => 'https://api.w.org/action-create-' . $tax_base, 'title' => $create_title, 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( $tax_base => array( 'type' => 'array', 'items' => array( 'type' => 'integer', ), ), ), ), ); } return $links; } ``` | Uses | Description | | --- | --- | | [wp\_list\_filter()](../../functions/wp_list_filter) wp-includes/functions.php | Filters a list of objects, based on a set of key => value arguments. | | [get\_object\_taxonomies()](../../functions/get_object_taxonomies) wp-includes/taxonomy.php | Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name. | | [post\_type\_supports()](../../functions/post_type_supports) wp-includes/post.php | Checks a post type’s support for a given feature. | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::get\_schema\_links()](../wp_rest_menu_items_controller/get_schema_links) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Retrieves Link Description Objects that should be added to the Schema for the posts collection. | | [WP\_REST\_Posts\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves the post’s schema, conforming to JSON Schema. | | Version | Description | | --- | --- | | [4.9.8](https://developer.wordpress.org/reference/since/4.9.8/) | Introduced. | wordpress WP_REST_Posts_Controller::prepare_tax_query( array $args, WP_REST_Request $request ): array WP\_REST\_Posts\_Controller::prepare\_tax\_query( array $args, WP\_REST\_Request $request ): array ================================================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Prepares the ‘tax\_query’ for a collection of posts. `$args` array Required [WP\_Query](../wp_query) arguments. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. array Updated query arguments. File: `wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php/) ``` private function prepare_tax_query( array $args, WP_REST_Request $request ) { $relation = $request['tax_relation']; if ( $relation ) { $args['tax_query'] = array( 'relation' => $relation ); } $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $taxonomy ) { $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; $tax_include = $request[ $base ]; $tax_exclude = $request[ $base . '_exclude' ]; if ( $tax_include ) { $terms = array(); $include_children = false; $operator = 'IN'; if ( rest_is_array( $tax_include ) ) { $terms = $tax_include; } elseif ( rest_is_object( $tax_include ) ) { $terms = empty( $tax_include['terms'] ) ? array() : $tax_include['terms']; $include_children = ! empty( $tax_include['include_children'] ); if ( isset( $tax_include['operator'] ) && 'AND' === $tax_include['operator'] ) { $operator = 'AND'; } } if ( $terms ) { $args['tax_query'][] = array( 'taxonomy' => $taxonomy->name, 'field' => 'term_id', 'terms' => $terms, 'include_children' => $include_children, 'operator' => $operator, ); } } if ( $tax_exclude ) { $terms = array(); $include_children = false; if ( rest_is_array( $tax_exclude ) ) { $terms = $tax_exclude; } elseif ( rest_is_object( $tax_exclude ) ) { $terms = empty( $tax_exclude['terms'] ) ? array() : $tax_exclude['terms']; $include_children = ! empty( $tax_exclude['include_children'] ); } if ( $terms ) { $args['tax_query'][] = array( 'taxonomy' => $taxonomy->name, 'field' => 'term_id', 'terms' => $terms, 'include_children' => $include_children, 'operator' => 'NOT IN', ); } } } return $args; } ``` | Uses | Description | | --- | --- | | [rest\_is\_object()](../../functions/rest_is_object) wp-includes/rest-api.php | Determines if a given value is object-like. | | [rest\_is\_array()](../../functions/rest_is_array) wp-includes/rest-api.php | Determines if a given value is array-like. | | [wp\_list\_filter()](../../functions/wp_list_filter) wp-includes/functions.php | Filters a list of objects, based on a set of key => value arguments. | | [get\_object\_taxonomies()](../../functions/get_object_taxonomies) wp-includes/taxonomy.php | Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name. | | Used By | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves a collection of posts. | | Version | Description | | --- | --- | | [5.7.0](https://developer.wordpress.org/reference/since/5.7.0/) | Introduced. | wordpress WP_REST_Posts_Controller::get_post( int $id ): WP_Post|WP_Error WP\_REST\_Posts\_Controller::get\_post( int $id ): WP\_Post|WP\_Error ===================================================================== Gets the post, if the ID is valid. `$id` int Required Supplied ID. [WP\_Post](../wp_post)|[WP\_Error](../wp_error) Post object if ID is valid, [WP\_Error](../wp_error) otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php/) ``` protected function get_post( $id ) { $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); if ( (int) $id <= 0 ) { return $error; } $post = get_post( (int) $id ); if ( empty( $post ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) { return $error; } return $post; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::check\_status()](check_status) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks whether the status is valid for the given post. | | [WP\_REST\_Posts\_Controller::prepare\_item\_for\_database()](prepare_item_for_database) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares a single post for create or update. | | [WP\_REST\_Posts\_Controller::update\_item\_permissions\_check()](update_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks if a given request has access to update a post. | | [WP\_REST\_Posts\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Updates a single post. | | [WP\_REST\_Posts\_Controller::delete\_item\_permissions\_check()](delete_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks if a given request has access to delete a post. | | [WP\_REST\_Posts\_Controller::delete\_item()](delete_item) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Deletes a single post. | | [WP\_REST\_Posts\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks if a given request has access to read a post. | | [WP\_REST\_Posts\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves a single post. | | Version | Description | | --- | --- | | [4.7.2](https://developer.wordpress.org/reference/since/4.7.2/) | Introduced. | wordpress WP_REST_Block_Renderer_Controller::get_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Block\_Renderer\_Controller::get\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ============================================================================================================ Returns block output from block’s registered render\_callback. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php/) ``` public function get_item( $request ) { global $post; $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0; if ( $post_id > 0 ) { $post = get_post( $post_id ); // Set up postdata since this will be needed if post_id was set. setup_postdata( $post ); } $registry = WP_Block_Type_Registry::get_instance(); $registered = $registry->get_registered( $request['name'] ); if ( null === $registered || ! $registered->is_dynamic() ) { return new WP_Error( 'block_invalid', __( 'Invalid block.' ), array( 'status' => 404, ) ); } $attributes = $request->get_param( 'attributes' ); // Create an array representation simulating the output of parse_blocks. $block = array( 'blockName' => $request['name'], 'attrs' => $attributes, 'innerHTML' => '', 'innerContent' => array(), ); // Render using render_block to ensure all relevant filters are used. $data = array( 'rendered' => render_block( $block ), ); return rest_ensure_response( $data ); } ``` | Uses | Description | | --- | --- | | [WP\_Block\_Type\_Registry::get\_instance()](../wp_block_type_registry/get_instance) wp-includes/class-wp-block-type-registry.php | Utility method to retrieve the main instance of the class. | | [render\_block()](../../functions/render_block) wp-includes/blocks.php | Renders a single block into a HTML string. | | [setup\_postdata()](../../functions/setup_postdata) wp-includes/query.php | Set up global post data. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. |
programming_docs
wordpress WP_REST_Block_Renderer_Controller::register_routes() WP\_REST\_Block\_Renderer\_Controller::register\_routes() ========================================================= Registers the necessary REST API routes, one for each dynamic block. * [register\_rest\_route()](../../functions/register_rest_route) File: `wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php/) ``` public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<name>[a-z0-9-]+/[a-z0-9-]+)', array( 'args' => array( 'name' => array( 'description' => __( 'Unique registered name for the block.' ), 'type' => 'string', ), ), array( 'methods' => array( WP_REST_Server::READABLE, WP_REST_Server::CREATABLE ), 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 'attributes' => array( 'description' => __( 'Attributes for the block.' ), 'type' => 'object', 'default' => array(), 'validate_callback' => static function ( $value, $request ) { $block = WP_Block_Type_Registry::get_instance()->get_registered( $request['name'] ); if ( ! $block ) { // This will get rejected in ::get_item(). return true; } $schema = array( 'type' => 'object', 'properties' => $block->get_attributes(), 'additionalProperties' => false, ); return rest_validate_value_from_schema( $value, $schema ); }, 'sanitize_callback' => static function ( $value, $request ) { $block = WP_Block_Type_Registry::get_instance()->get_registered( $request['name'] ); if ( ! $block ) { // This will get rejected in ::get_item(). return true; } $schema = array( 'type' => 'object', 'properties' => $block->get_attributes(), 'additionalProperties' => false, ); return rest_sanitize_value_from_schema( $value, $schema ); }, ), 'post_id' => array( 'description' => __( 'ID of the post context.' ), 'type' => 'integer', ), ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Block\_Type\_Registry::get\_instance()](../wp_block_type_registry/get_instance) wp-includes/class-wp-block-type-registry.php | Utility method to retrieve the main instance of the class. | | [rest\_sanitize\_value\_from\_schema()](../../functions/rest_sanitize_value_from_schema) wp-includes/rest-api.php | Sanitize a value based on a schema. | | [rest\_validate\_value\_from\_schema()](../../functions/rest_validate_value_from_schema) wp-includes/rest-api.php | Validate a value based on a schema. | | [register\_rest\_route()](../../functions/register_rest_route) wp-includes/rest-api.php | Registers a REST API route. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Block_Renderer_Controller::__construct() WP\_REST\_Block\_Renderer\_Controller::\_\_construct() ====================================================== Constructs the controller. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php/) ``` public function __construct() { $this->namespace = 'wp/v2'; $this->rest_base = 'block-renderer'; } ``` | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Block_Renderer_Controller::get_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Block\_Renderer\_Controller::get\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ================================================================================================================== Checks if a given request has access to read blocks. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request. true|[WP\_Error](../wp_error) True if the request has read access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php/) ``` public function get_item_permissions_check( $request ) { global $post; $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0; if ( $post_id > 0 ) { $post = get_post( $post_id ); if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { return new WP_Error( 'block_cannot_read', __( 'Sorry, you are not allowed to read blocks of this post.' ), array( 'status' => rest_authorization_required_code(), ) ); } } else { if ( ! current_user_can( 'edit_posts' ) ) { return new WP_Error( 'block_cannot_read', __( 'Sorry, you are not allowed to read blocks as this user.' ), array( 'status' => rest_authorization_required_code(), ) ); } } return true; } ``` | Uses | Description | | --- | --- | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Block_Renderer_Controller::get_item_schema(): array WP\_REST\_Block\_Renderer\_Controller::get\_item\_schema(): array ================================================================= Retrieves block’s output schema, conforming to JSON Schema. array Item schema data. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->schema; } $this->schema = array( '$schema' => 'http://json-schema.org/schema#', 'title' => 'rendered-block', 'type' => 'object', 'properties' => array( 'rendered' => array( 'description' => __( 'The rendered block.' ), 'type' => 'string', 'required' => true, 'context' => array( 'edit' ), ), ), ); return $this->schema; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_MatchesMapRegex::apply( string $subject, array $matches ): string WP\_MatchesMapRegex::apply( string $subject, array $matches ): string ===================================================================== Substitute substring matches in subject. static helper function to ease use `$subject` string Required subject `$matches` array Required data used for substitution string File: `wp-includes/class-wp-matchesmapregex.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-matchesmapregex.php/) ``` public static function apply( $subject, $matches ) { $oSelf = new WP_MatchesMapRegex( $subject, $matches ); return $oSelf->output; } ``` | Uses | Description | | --- | --- | | [WP\_MatchesMapRegex::\_\_construct()](__construct) wp-includes/class-wp-matchesmapregex.php | constructor | | Used By | Description | | --- | --- | | [WP::parse\_request()](../wp/parse_request) wp-includes/class-wp.php | Parses the request to find the correct WordPress query. | | [url\_to\_postid()](../../functions/url_to_postid) wp-includes/rewrite.php | Examines a URL and try to determine the post ID it represents. | wordpress WP_MatchesMapRegex::_map(): string WP\_MatchesMapRegex::\_map(): string ==================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. do the actual mapping string File: `wp-includes/class-wp-matchesmapregex.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-matchesmapregex.php/) ``` private function _map() { $callback = array( $this, 'callback' ); return preg_replace_callback( $this->_pattern, $callback, $this->_subject ); } ``` | Used By | Description | | --- | --- | | [WP\_MatchesMapRegex::\_\_construct()](__construct) wp-includes/class-wp-matchesmapregex.php | constructor | wordpress WP_MatchesMapRegex::callback( array $matches ): string WP\_MatchesMapRegex::callback( array $matches ): string ======================================================= preg\_replace\_callback hook `$matches` array Required preg\_replace regexp matches string File: `wp-includes/class-wp-matchesmapregex.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-matchesmapregex.php/) ``` public function callback( $matches ) { $index = (int) substr( $matches[0], 9, -1 ); return ( isset( $this->_matches[ $index ] ) ? urlencode( $this->_matches[ $index ] ) : '' ); } ``` wordpress WP_MatchesMapRegex::__construct( string $subject, array $matches ) WP\_MatchesMapRegex::\_\_construct( string $subject, array $matches ) ===================================================================== constructor `$subject` string Required subject if regex `$matches` array Required data to use in map File: `wp-includes/class-wp-matchesmapregex.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-matchesmapregex.php/) ``` public function __construct( $subject, $matches ) { $this->_subject = $subject; $this->_matches = $matches; $this->output = $this->_map(); } ``` | Uses | Description | | --- | --- | | [WP\_MatchesMapRegex::\_map()](_map) wp-includes/class-wp-matchesmapregex.php | do the actual mapping | | Used By | Description | | --- | --- | | [WP\_MatchesMapRegex::apply()](apply) wp-includes/class-wp-matchesmapregex.php | Substitute substring matches in subject. | wordpress WP_Theme_JSON::get_styles_for_block( array $block_metadata ): string WP\_Theme\_JSON::get\_styles\_for\_block( array $block\_metadata ): string ========================================================================== Gets the CSS rules for a particular block from theme.json. `$block_metadata` array Required Metadata about the block to get styles for. string Styles for the block. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_styles_for_block( $block_metadata ) { $node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() ); $use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments']; $selector = $block_metadata['selector']; $settings = _wp_array_get( $this->theme_json, array( 'settings' ) ); /* * Process style declarations for block support features the current * block contains selectors for. Values for a feature with a custom * selector are filtered from the theme.json node before it is * processed as normal. */ $feature_declarations = array(); if ( ! empty( $block_metadata['features'] ) ) { foreach ( $block_metadata['features'] as $feature_name => $feature_selector ) { if ( ! empty( $node[ $feature_name ] ) ) { // Create temporary node containing only the feature data // to leverage existing `compute_style_properties` function. $feature = array( $feature_name => $node[ $feature_name ] ); // Generate the feature's declarations only. $new_feature_declarations = static::compute_style_properties( $feature, $settings, null, $this->theme_json ); // Merge new declarations with any that already exist for // the feature selector. This may occur when multiple block // support features use the same custom selector. if ( isset( $feature_declarations[ $feature_selector ] ) ) { $feature_declarations[ $feature_selector ] = array_merge( $feature_declarations[ $feature_selector ], $new_feature_declarations ); } else { $feature_declarations[ $feature_selector ] = $new_feature_declarations; } // Remove the feature from the block's node now the // styles will be included under the feature level selector. unset( $node[ $feature_name ] ); } } } /* * Get a reference to element name from path. * $block_metadata['path'] = array( 'styles','elements','link' ); * Make sure that $block_metadata['path'] describes an element node, like [ 'styles', 'element', 'link' ]. * Skip non-element paths like just ['styles']. */ $is_processing_element = in_array( 'elements', $block_metadata['path'], true ); $current_element = $is_processing_element ? $block_metadata['path'][ count( $block_metadata['path'] ) - 1 ] : null; $element_pseudo_allowed = array(); if ( array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { $element_pseudo_allowed = static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ]; } /* * Check for allowed pseudo classes (e.g. ":hover") from the $selector ("a:hover"). * This also resets the array keys. */ $pseudo_matches = array_values( array_filter( $element_pseudo_allowed, function( $pseudo_selector ) use ( $selector ) { return str_contains( $selector, $pseudo_selector ); } ) ); $pseudo_selector = isset( $pseudo_matches[0] ) ? $pseudo_matches[0] : null; /* * If the current selector is a pseudo selector that's defined in the allow list for the current * element then compute the style properties for it. * Otherwise just compute the styles for the default selector as normal. */ if ( $pseudo_selector && isset( $node[ $pseudo_selector ] ) && array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) && in_array( $pseudo_selector, static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ], true ) ) { $declarations = static::compute_style_properties( $node[ $pseudo_selector ], $settings, null, $this->theme_json, $selector, $use_root_padding ); } else { $declarations = static::compute_style_properties( $node, $settings, null, $this->theme_json, $selector, $use_root_padding ); } $block_rules = ''; /* * 1. Separate the declarations that use the general selector * from the ones using the duotone selector. */ $declarations_duotone = array(); foreach ( $declarations as $index => $declaration ) { if ( 'filter' === $declaration['name'] ) { unset( $declarations[ $index ] ); $declarations_duotone[] = $declaration; } } // 2. Generate and append the rules that use the general selector. $block_rules .= static::to_ruleset( $selector, $declarations ); // 3. Generate and append the rules that use the duotone selector. if ( isset( $block_metadata['duotone'] ) && ! empty( $declarations_duotone ) ) { $selector_duotone = static::scope_selector( $block_metadata['selector'], $block_metadata['duotone'] ); $block_rules .= static::to_ruleset( $selector_duotone, $declarations_duotone ); } // 4. Generate Layout block gap styles. if ( static::ROOT_BLOCK_SELECTOR !== $selector && ! empty( $block_metadata['name'] ) ) { $block_rules .= $this->get_layout_styles( $block_metadata ); } // 5. Generate and append the feature level rulesets. foreach ( $feature_declarations as $feature_selector => $individual_feature_declarations ) { $block_rules .= static::to_ruleset( $feature_selector, $individual_feature_declarations ); } return $block_rules; } ``` | Uses | Description | | --- | --- | | [WP\_Theme\_JSON::get\_layout\_styles()](get_layout_styles) wp-includes/class-wp-theme-json.php | Gets the CSS layout rules for a particular block from theme.json layout definitions. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Theme_JSON::scope_selector( string $scope, string $selector ): string WP\_Theme\_JSON::scope\_selector( string $scope, string $selector ): string =========================================================================== Function that scopes a selector with another one. This works a bit like SCSS nesting except the `&amp;` operator isn’t supported. ``` $scope = '.a, .b .c'; $selector = '> .x, .y'; $merged = scope_selector( $scope, $selector ); // $merged is '.a > .x, .a .y, .b .c > .x, .b .c .y' ``` `$scope` string Required Selector to scope to. `$selector` string Required Original selector. string Scoped selector. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function scope_selector( $scope, $selector ) { $scopes = explode( ',', $scope ); $selectors = explode( ',', $selector ); $selectors_scoped = array(); foreach ( $scopes as $outer ) { foreach ( $selectors as $inner ) { $selectors_scoped[] = trim( $outer ) . ' ' . trim( $inner ); } } return implode( ', ', $selectors_scoped ); } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::get_metadata_boolean( array $data, bool|array $path, bool $default = false ): bool WP\_Theme\_JSON::get\_metadata\_boolean( array $data, bool|array $path, bool $default = false ): bool ===================================================================================================== For metadata values that can either be booleans or paths to booleans, gets the value. ``` $data = array( 'color' => array( 'defaultPalette' => true ) ); static::get_metadata_boolean( $data, false ); // => false static::get_metadata_boolean( $data, array( 'color', 'defaultPalette' ) ); // => true[/code] ``` `$data` array Required The data to inspect. `$path` bool|array Required Boolean or path to a boolean. `$default` bool Optional Default value if the referenced path is missing. Default: `false` bool Value of boolean metadata. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function get_metadata_boolean( $data, $path, $default = false ) { if ( is_bool( $path ) ) { return $path; } if ( is_array( $path ) ) { $value = _wp_array_get( $data, $path ); if ( null !== $value ) { return $value; } } return $default; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Introduced. |
programming_docs
wordpress WP_Theme_JSON::get_stylesheet( array $types = array('variables', 'styles', 'presets'), array $origins = null ): string WP\_Theme\_JSON::get\_stylesheet( array $types = array('variables', 'styles', 'presets'), array $origins = null ): string ========================================================================================================================= Returns the stylesheet that results of processing the theme.json structure this object represents. `$types` array Optional Types of styles to load. Will load all by default. It accepts: * `variables`: only the CSS Custom Properties for presets & custom ones. * `styles`: only the styles section in theme.json. * `presets`: only the classes for the presets. Default: `array('variables', 'styles', 'presets')` `$origins` array Optional A list of origins to include. By default it includes VALID\_ORIGINS. Default: `null` string The resulting stylesheet. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' ), $origins = null ) { if ( null === $origins ) { $origins = static::VALID_ORIGINS; } if ( is_string( $types ) ) { // Dispatch error and map old arguments to new ones. _deprecated_argument( __FUNCTION__, '5.9.0' ); if ( 'block_styles' === $types ) { $types = array( 'styles', 'presets' ); } elseif ( 'css_variables' === $types ) { $types = array( 'variables' ); } else { $types = array( 'variables', 'styles', 'presets' ); } } $blocks_metadata = static::get_blocks_metadata(); $style_nodes = static::get_style_nodes( $this->theme_json, $blocks_metadata ); $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata ); $stylesheet = ''; if ( in_array( 'variables', $types, true ) ) { $stylesheet .= $this->get_css_variables( $setting_nodes, $origins ); } if ( in_array( 'styles', $types, true ) ) { $root_block_key = array_search( static::ROOT_BLOCK_SELECTOR, array_column( $style_nodes, 'selector' ), true ); if ( false !== $root_block_key ) { $stylesheet .= $this->get_root_layout_rules( static::ROOT_BLOCK_SELECTOR, $style_nodes[ $root_block_key ] ); } $stylesheet .= $this->get_block_classes( $style_nodes ); } elseif ( in_array( 'base-layout-styles', $types, true ) ) { // Base layout styles are provided as part of `styles`, so only output separately if explicitly requested. // For backwards compatibility, the Columns block is explicitly included, to support a different default gap value. $base_styles_nodes = array( array( 'path' => array( 'styles' ), 'selector' => static::ROOT_BLOCK_SELECTOR, ), array( 'path' => array( 'styles', 'blocks', 'core/columns' ), 'selector' => '.wp-block-columns', 'name' => 'core/columns', ), ); foreach ( $base_styles_nodes as $base_style_node ) { $stylesheet .= $this->get_layout_styles( $base_style_node ); } } if ( in_array( 'presets', $types, true ) ) { $stylesheet .= $this->get_preset_classes( $setting_nodes, $origins ); } return $stylesheet; } ``` | Uses | Description | | --- | --- | | [WP\_Theme\_JSON::get\_root\_layout\_rules()](get_root_layout_rules) wp-includes/class-wp-theme-json.php | Outputs the CSS for layout rules on the root. | | [WP\_Theme\_JSON::get\_layout\_styles()](get_layout_styles) wp-includes/class-wp-theme-json.php | Gets the CSS layout rules for a particular block from theme.json layout definitions. | | [WP\_Theme\_JSON::get\_block\_classes()](get_block_classes) wp-includes/class-wp-theme-json.php | Converts each style section into a list of rulesets containing the block styles to be appended to the stylesheet. | | [WP\_Theme\_JSON::get\_preset\_classes()](get_preset_classes) wp-includes/class-wp-theme-json.php | Creates new rulesets as classes for each preset value such as: | | [WP\_Theme\_JSON::get\_css\_variables()](get_css_variables) wp-includes/class-wp-theme-json.php | Converts each styles section into a list of rulesets to be appended to the stylesheet. | | [\_deprecated\_argument()](../../functions/_deprecated_argument) wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Removed the `$type` parameter`, added the`$types`and`$origins` parameters. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_default_slugs( array $data, array $node_path ): array WP\_Theme\_JSON::get\_default\_slugs( array $data, array $node\_path ): array ============================================================================= Returns the default slugs for all the presets in an associative array whose keys are the preset paths and the leafs is the list of slugs. For example: array( ‘color’ => array( ‘palette’ => array( ‘slug-1’, ‘slug-2’ ), ‘gradients’ => array( ‘slug-3’, ‘slug-4’ ), ), ) `$data` array Required A theme.json like structure. `$node_path` array Required The path to inspect. It's `'settings'` by default. array File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function get_default_slugs( $data, $node_path ) { $slugs = array(); foreach ( static::PRESETS_METADATA as $metadata ) { $path = array_merge( $node_path, $metadata['path'], array( 'default' ) ); $preset = _wp_array_get( $data, $path, null ); if ( ! isset( $preset ) ) { continue; } $slugs_for_preset = array(); foreach ( $preset as $item ) { if ( isset( $item['slug'] ) ) { $slugs_for_preset[] = $item['slug']; } } _wp_array_set( $slugs, $metadata['path'], $slugs_for_preset ); } return $slugs; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_set()](../../functions/_wp_array_set) wp-includes/functions.php | Sets an array in depth based on a path of keys. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::get_settings_slugs( array $settings, array $preset_metadata, array $origins = null ): array WP\_Theme\_JSON::get\_settings\_slugs( array $settings, array $preset\_metadata, array $origins = null ): array =============================================================================================================== Similar to get\_settings\_values\_by\_slug, but doesn’t compute the value. `$settings` array Required Settings to process. `$preset_metadata` array Required One of the PRESETS\_METADATA values. `$origins` array Optional List of origins to process. Default: `null` array Array of presets where the key and value are both the slug. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function get_settings_slugs( $settings, $preset_metadata, $origins = null ) { if ( null === $origins ) { $origins = static::VALID_ORIGINS; } $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); $result = array(); foreach ( $origins as $origin ) { if ( ! isset( $preset_per_origin[ $origin ] ) ) { continue; } foreach ( $preset_per_origin[ $origin ] as $preset ) { $slug = _wp_to_kebab_case( $preset['slug'] ); // Use the array as a set so we don't get duplicates. $result[ $slug ] = $slug; } } return $result; } ``` | Uses | Description | | --- | --- | | [\_wp\_to\_kebab\_case()](../../functions/_wp_to_kebab_case) wp-includes/functions.php | This function is trying to replicate what lodash’s kebabCase (JS library) does in the client. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::merge( WP_Theme_JSON $incoming ) WP\_Theme\_JSON::merge( WP\_Theme\_JSON $incoming ) =================================================== Merges new incoming data. `$incoming` [WP\_Theme\_JSON](../wp_theme_json) Required Data to merge. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function merge( $incoming ) { $incoming_data = $incoming->get_raw_data(); $this->theme_json = array_replace_recursive( $this->theme_json, $incoming_data ); /* * The array_replace_recursive algorithm merges at the leaf level, * but we don't want leaf arrays to be merged, so we overwrite it. * * For leaf values that are sequential arrays it will use the numeric indexes for replacement. * We rather replace the existing with the incoming value, if it exists. * This is the case of spacing.units. * * For leaf values that are associative arrays it will merge them as expected. * This is also not the behavior we want for the current associative arrays (presets). * We rather replace the existing with the incoming value, if it exists. * This happens, for example, when we merge data from theme.json upon existing * theme supports or when we merge anything coming from the same source twice. * This is the case of color.palette, color.gradients, color.duotone, * typography.fontSizes, or typography.fontFamilies. * * Additionally, for some preset types, we also want to make sure the * values they introduce don't conflict with default values. We do so * by checking the incoming slugs for theme presets and compare them * with the equivalent default presets: if a slug is present as a default * we remove it from the theme presets. */ $nodes = static::get_setting_nodes( $incoming_data ); $slugs_global = static::get_default_slugs( $this->theme_json, array( 'settings' ) ); foreach ( $nodes as $node ) { $slugs_node = static::get_default_slugs( $this->theme_json, $node['path'] ); $slugs = array_merge_recursive( $slugs_global, $slugs_node ); // Replace the spacing.units. $path = array_merge( $node['path'], array( 'spacing', 'units' ) ); $content = _wp_array_get( $incoming_data, $path, null ); if ( isset( $content ) ) { _wp_array_set( $this->theme_json, $path, $content ); } // Replace the presets. foreach ( static::PRESETS_METADATA as $preset ) { $override_preset = ! static::get_metadata_boolean( $this->theme_json['settings'], $preset['prevent_override'], true ); foreach ( static::VALID_ORIGINS as $origin ) { $base_path = array_merge( $node['path'], $preset['path'] ); $path = array_merge( $base_path, array( $origin ) ); $content = _wp_array_get( $incoming_data, $path, null ); if ( ! isset( $content ) ) { continue; } if ( 'theme' === $origin && $preset['use_default_names'] ) { foreach ( $content as &$item ) { if ( ! array_key_exists( 'name', $item ) ) { $name = static::get_name_from_defaults( $item['slug'], $base_path ); if ( null !== $name ) { $item['name'] = $name; } } } } if ( ( 'theme' !== $origin ) || ( 'theme' === $origin && $override_preset ) ) { _wp_array_set( $this->theme_json, $path, $content ); } else { $slugs_for_preset = _wp_array_get( $slugs, $preset['path'], array() ); $content = static::filter_slugs( $content, $slugs_for_preset ); _wp_array_set( $this->theme_json, $path, $content ); } } } } } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_set()](../../functions/_wp_array_set) wp-includes/functions.php | Sets an array in depth based on a path of keys. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Duotone preset also has origins. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_block_nodes( array $theme_json ): array WP\_Theme\_JSON::get\_block\_nodes( array $theme\_json ): array =============================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. An internal method to get the block nodes from a theme.json file. `$theme_json` array Required The theme.json converted to an array. array The block nodes in theme.json. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` private static function get_block_nodes( $theme_json ) { $selectors = static::get_blocks_metadata(); $nodes = array(); if ( ! isset( $theme_json['styles'] ) ) { return $nodes; } // Blocks. if ( ! isset( $theme_json['styles']['blocks'] ) ) { return $nodes; } foreach ( $theme_json['styles']['blocks'] as $name => $node ) { $selector = null; if ( isset( $selectors[ $name ]['selector'] ) ) { $selector = $selectors[ $name ]['selector']; } $duotone_selector = null; if ( isset( $selectors[ $name ]['duotone'] ) ) { $duotone_selector = $selectors[ $name ]['duotone']; } $feature_selectors = null; if ( isset( $selectors[ $name ]['features'] ) ) { $feature_selectors = $selectors[ $name ]['features']; } $nodes[] = array( 'name' => $name, 'path' => array( 'styles', 'blocks', $name ), 'selector' => $selector, 'duotone' => $duotone_selector, 'features' => $feature_selectors, ); if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) { foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) { $nodes[] = array( 'path' => array( 'styles', 'blocks', $name, 'elements', $element ), 'selector' => $selectors[ $name ]['elements'][ $element ], ); // Handle any pseudo selectors for the element. if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) { $nodes[] = array( 'path' => array( 'styles', 'blocks', $name, 'elements', $element ), 'selector' => static::append_to_selector( $selectors[ $name ]['elements'][ $element ], $pseudo_selector ), ); } } } } } } return $nodes; } ``` | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Theme_JSON::get_setting_nodes( array $theme_json, array $selectors = array() ): array WP\_Theme\_JSON::get\_setting\_nodes( array $theme\_json, array $selectors = array() ): array ============================================================================================= Builds metadata for the setting nodes, which returns in the form of: [ [ ‘path’ => [‘path’, ‘to’, ‘some’, ‘node’ ], ‘selector’ => ‘CSS selector for some node’ ], [ ‘path’ => [ ‘path’, ‘to’, ‘other’, ‘node’ ], ‘selector’ => ‘CSS selector for other node’ ], ] `$theme_json` array Required The tree to extract setting nodes from. `$selectors` array Optional List of selectors per block. Default: `array()` array An array of setting nodes metadata. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function get_setting_nodes( $theme_json, $selectors = array() ) { $nodes = array(); if ( ! isset( $theme_json['settings'] ) ) { return $nodes; } // Top-level. $nodes[] = array( 'path' => array( 'settings' ), 'selector' => static::ROOT_BLOCK_SELECTOR, ); // Calculate paths for blocks. if ( ! isset( $theme_json['settings']['blocks'] ) ) { return $nodes; } foreach ( $theme_json['settings']['blocks'] as $name => $node ) { $selector = null; if ( isset( $selectors[ $name ]['selector'] ) ) { $selector = $selectors[ $name ]['selector']; } $nodes[] = array( 'path' => array( 'settings', 'blocks', $name ), 'selector' => $selector, ); } return $nodes; } ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_name_from_defaults( string $slug, array $base_path ): string|null WP\_Theme\_JSON::get\_name\_from\_defaults( string $slug, array $base\_path ): string|null ========================================================================================== Gets a `default`‘s preset name by a provided slug. `$slug` string Required The slug we want to find a match from default presets. `$base_path` array Required The path to inspect. It's `'settings'` by default. string|null File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected function get_name_from_defaults( $slug, $base_path ) { $path = array_merge( $base_path, array( 'default' ) ); $default_content = _wp_array_get( $this->theme_json, $path, null ); if ( ! $default_content ) { return null; } foreach ( $default_content as $item ) { if ( $slug === $item['slug'] ) { return $item['name']; } } return null; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::get_css_variables( array $nodes, array $origins ): string WP\_Theme\_JSON::get\_css\_variables( array $nodes, array $origins ): string ============================================================================ Converts each styles section into a list of rulesets to be appended to the stylesheet. These rulesets contain all the css variables (custom variables and preset variables). See glossary at <https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax> For each section this creates a new ruleset such as: ``` block-selector { --wp--preset--category--slug: value; --wp--custom--variable: value; } ``` `$nodes` array Required Nodes with settings. `$origins` array Required List of origins to process. string The new stylesheet. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected function get_css_variables( $nodes, $origins ) { $stylesheet = ''; foreach ( $nodes as $metadata ) { if ( null === $metadata['selector'] ) { continue; } $selector = $metadata['selector']; $node = _wp_array_get( $this->theme_json, $metadata['path'], array() ); $declarations = array_merge( static::compute_preset_vars( $node, $origins ), static::compute_theme_vars( $node ) ); $stylesheet .= static::to_ruleset( $selector, $declarations ); } return $stylesheet; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Used By | Description | | --- | --- | | [WP\_Theme\_JSON::get\_stylesheet()](get_stylesheet) wp-includes/class-wp-theme-json.php | Returns the stylesheet that results of processing the theme.json structure this object represents. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added the `$origins` parameter. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |
programming_docs
wordpress WP_Theme_JSON::get_svg_filters( array $origins ): string WP\_Theme\_JSON::get\_svg\_filters( array $origins ): string ============================================================ Converts all filter (duotone) presets into SVGs. `$origins` array Required List of origins to process. string SVG filters. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_svg_filters( $origins ) { $blocks_metadata = static::get_blocks_metadata(); $setting_nodes = static::get_setting_nodes( $this->theme_json, $blocks_metadata ); $filters = ''; foreach ( $setting_nodes as $metadata ) { $node = _wp_array_get( $this->theme_json, $metadata['path'], array() ); if ( empty( $node['color']['duotone'] ) ) { continue; } $duotone_presets = $node['color']['duotone']; foreach ( $origins as $origin ) { if ( ! isset( $duotone_presets[ $origin ] ) ) { continue; } foreach ( $duotone_presets[ $origin ] as $duotone_preset ) { $filters .= wp_get_duotone_filter_svg( $duotone_preset ); } } } return $filters; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [5.9.1](https://developer.wordpress.org/reference/since/5.9.1/) | Introduced. | wordpress WP_Theme_JSON::get_patterns(): string[] WP\_Theme\_JSON::get\_patterns(): string[] ========================================== Returns the current theme’s wanted patterns(slugs) to be registered from Pattern Directory. string[] File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_patterns() { if ( isset( $this->theme_json['patterns'] ) && is_array( $this->theme_json['patterns'] ) ) { return $this->theme_json['patterns']; } return array(); } ``` | Version | Description | | --- | --- | | [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Introduced. | wordpress WP_Theme_JSON::get_preset_classes( array $setting_nodes, array $origins ): string WP\_Theme\_JSON::get\_preset\_classes( array $setting\_nodes, array $origins ): string ====================================================================================== Creates new rulesets as classes for each preset value such as: .has-value-color { color: value; } .has-value-background-color { background-color: value; } .has-value-font-size { font-size: value; } .has-value-gradient-background { background: value; } p.has-value-gradient-background { background: value; } `$setting_nodes` array Required Nodes with settings. `$origins` array Required List of origins to process presets from. string The new stylesheet. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected function get_preset_classes( $setting_nodes, $origins ) { $preset_rules = ''; foreach ( $setting_nodes as $metadata ) { if ( null === $metadata['selector'] ) { continue; } $selector = $metadata['selector']; $node = _wp_array_get( $this->theme_json, $metadata['path'], array() ); $preset_rules .= static::compute_preset_classes( $node, $selector, $origins ); } return $preset_rules; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Used By | Description | | --- | --- | | [WP\_Theme\_JSON::get\_stylesheet()](get_stylesheet) wp-includes/class-wp-theme-json.php | Returns the stylesheet that results of processing the theme.json structure this object represents. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::sanitize( array $input, array $valid_block_names, array $valid_element_names ): array WP\_Theme\_JSON::sanitize( array $input, array $valid\_block\_names, array $valid\_element\_names ): array ========================================================================================================== Sanitizes the input according to the schemas. `$input` array Required Structure to sanitize. `$valid_block_names` array Required List of valid block names. `$valid_element_names` array Required List of valid element names. array The sanitized output. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function sanitize( $input, $valid_block_names, $valid_element_names ) { $output = array(); if ( ! is_array( $input ) ) { return $output; } // Preserve only the top most level keys. $output = array_intersect_key( $input, array_flip( static::VALID_TOP_LEVEL_KEYS ) ); /* * Remove any rules that are annotated as "top" in VALID_STYLES constant. * Some styles are only meant to be available at the top-level (e.g.: blockGap), * hence, the schema for blocks & elements should not have them. */ $styles_non_top_level = static::VALID_STYLES; foreach ( array_keys( $styles_non_top_level ) as $section ) { if ( array_key_exists( $section, $styles_non_top_level ) && is_array( $styles_non_top_level[ $section ] ) ) { foreach ( array_keys( $styles_non_top_level[ $section ] ) as $prop ) { if ( 'top' === $styles_non_top_level[ $section ][ $prop ] ) { unset( $styles_non_top_level[ $section ][ $prop ] ); } } } } // Build the schema based on valid block & element names. $schema = array(); $schema_styles_elements = array(); /* * Set allowed element pseudo selectors based on per element allow list. * Target data structure in schema: * e.g. * - top level elements: `$schema['styles']['elements']['link'][':hover']`. * - block level elements: `$schema['styles']['blocks']['core/button']['elements']['link'][':hover']`. */ foreach ( $valid_element_names as $element ) { $schema_styles_elements[ $element ] = $styles_non_top_level; if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { $schema_styles_elements[ $element ][ $pseudo_selector ] = $styles_non_top_level; } } } $schema_styles_blocks = array(); $schema_settings_blocks = array(); foreach ( $valid_block_names as $block ) { $schema_settings_blocks[ $block ] = static::VALID_SETTINGS; $schema_styles_blocks[ $block ] = $styles_non_top_level; $schema_styles_blocks[ $block ]['elements'] = $schema_styles_elements; } $schema['styles'] = static::VALID_STYLES; $schema['styles']['blocks'] = $schema_styles_blocks; $schema['styles']['elements'] = $schema_styles_elements; $schema['settings'] = static::VALID_SETTINGS; $schema['settings']['blocks'] = $schema_settings_blocks; // Remove anything that's not present in the schema. foreach ( array( 'styles', 'settings' ) as $subtree ) { if ( ! isset( $input[ $subtree ] ) ) { continue; } if ( ! is_array( $input[ $subtree ] ) ) { unset( $output[ $subtree ] ); continue; } $result = static::remove_keys_not_in_schema( $input[ $subtree ], $schema[ $subtree ] ); if ( empty( $result ) ) { unset( $output[ $subtree ] ); } else { $output[ $subtree ] = $result; } } return $output; } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added the `$valid_block_names` and `$valid_element_name` parameters. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_styles_block_nodes(): array WP\_Theme\_JSON::get\_styles\_block\_nodes(): array =================================================== A public helper to get the block nodes from a theme.json file. array The block nodes in theme.json. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_styles_block_nodes() { return static::get_block_nodes( $this->theme_json ); } ``` | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Theme_JSON::do_opt_in_into_settings( array $context ) WP\_Theme\_JSON::do\_opt\_in\_into\_settings( array $context ) ============================================================== Enables some settings. `$context` array Required The context to which the settings belong. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function do_opt_in_into_settings( &$context ) { foreach ( static::APPEARANCE_TOOLS_OPT_INS as $path ) { // Use "unset prop" as a marker instead of "null" because // "null" can be a valid value for some props (e.g. blockGap). if ( 'unset prop' === _wp_array_get( $context, $path, 'unset prop' ) ) { _wp_array_set( $context, $path, true ); } } unset( $context['appearanceTools'] ); } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_set()](../../functions/_wp_array_set) wp-includes/functions.php | Sets an array in depth based on a path of keys. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::remove_keys_not_in_schema( array $tree, array $schema ): array WP\_Theme\_JSON::remove\_keys\_not\_in\_schema( array $tree, array $schema ): array =================================================================================== Given a tree, removes the keys that are not present in the schema. It is recursive and modifies the input in-place. `$tree` array Required Input to process. `$schema` array Required Schema to adhere to. array The modified $tree. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function remove_keys_not_in_schema( $tree, $schema ) { $tree = array_intersect_key( $tree, $schema ); foreach ( $schema as $key => $data ) { if ( ! isset( $tree[ $key ] ) ) { continue; } if ( is_array( $schema[ $key ] ) && is_array( $tree[ $key ] ) ) { $tree[ $key ] = static::remove_keys_not_in_schema( $tree[ $key ], $schema[ $key ] ); if ( empty( $tree[ $key ] ) ) { unset( $tree[ $key ] ); } } elseif ( is_array( $schema[ $key ] ) && ! is_array( $tree[ $key ] ) ) { unset( $tree[ $key ] ); } } return $tree; } ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::set_spacing_sizes(): null|void WP\_Theme\_JSON::set\_spacing\_sizes(): null|void ================================================= Sets the spacingSizes array based on the spacingScale values from theme.json. null|void File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function set_spacing_sizes() { $spacing_scale = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'spacingScale' ), array() ); if ( ! is_numeric( $spacing_scale['steps'] ) || ! isset( $spacing_scale['mediumStep'] ) || ! isset( $spacing_scale['unit'] ) || ! isset( $spacing_scale['operator'] ) || ! isset( $spacing_scale['increment'] ) || ! isset( $spacing_scale['steps'] ) || ! is_numeric( $spacing_scale['increment'] ) || ! is_numeric( $spacing_scale['mediumStep'] ) || ( '+' !== $spacing_scale['operator'] && '*' !== $spacing_scale['operator'] ) ) { if ( ! empty( $spacing_scale ) ) { trigger_error( __( 'Some of the theme.json settings.spacing.spacingScale values are invalid' ), E_USER_NOTICE ); } return null; } // If theme authors want to prevent the generation of the core spacing scale they can set their theme.json spacingScale.steps to 0. if ( 0 === $spacing_scale['steps'] ) { return null; } $unit = '%' === $spacing_scale['unit'] ? '%' : sanitize_title( $spacing_scale['unit'] ); $current_step = $spacing_scale['mediumStep']; $steps_mid_point = round( $spacing_scale['steps'] / 2, 0 ); $x_small_count = null; $below_sizes = array(); $slug = 40; $remainder = 0; for ( $below_midpoint_count = $steps_mid_point - 1; $spacing_scale['steps'] > 1 && $slug > 0 && $below_midpoint_count > 0; $below_midpoint_count-- ) { if ( '+' === $spacing_scale['operator'] ) { $current_step -= $spacing_scale['increment']; } elseif ( $spacing_scale['increment'] > 1 ) { $current_step /= $spacing_scale['increment']; } else { $current_step *= $spacing_scale['increment']; } if ( $current_step <= 0 ) { $remainder = $below_midpoint_count; break; } $below_sizes[] = array( /* translators: %s: Digit to indicate multiple of sizing, eg. 2X-Small. */ 'name' => $below_midpoint_count === $steps_mid_point - 1 ? __( 'Small' ) : sprintf( __( '%sX-Small' ), (string) $x_small_count ), 'slug' => (string) $slug, 'size' => round( $current_step, 2 ) . $unit, ); if ( $below_midpoint_count === $steps_mid_point - 2 ) { $x_small_count = 2; } if ( $below_midpoint_count < $steps_mid_point - 2 ) { $x_small_count++; } $slug -= 10; } $below_sizes = array_reverse( $below_sizes ); $below_sizes[] = array( 'name' => __( 'Medium' ), 'slug' => '50', 'size' => $spacing_scale['mediumStep'] . $unit, ); $current_step = $spacing_scale['mediumStep']; $x_large_count = null; $above_sizes = array(); $slug = 60; $steps_above = ( $spacing_scale['steps'] - $steps_mid_point ) + $remainder; for ( $above_midpoint_count = 0; $above_midpoint_count < $steps_above; $above_midpoint_count++ ) { $current_step = '+' === $spacing_scale['operator'] ? $current_step + $spacing_scale['increment'] : ( $spacing_scale['increment'] >= 1 ? $current_step * $spacing_scale['increment'] : $current_step / $spacing_scale['increment'] ); $above_sizes[] = array( /* translators: %s: Digit to indicate multiple of sizing, eg. 2X-Large. */ 'name' => 0 === $above_midpoint_count ? __( 'Large' ) : sprintf( __( '%sX-Large' ), (string) $x_large_count ), 'slug' => (string) $slug, 'size' => round( $current_step, 2 ) . $unit, ); if ( 1 === $above_midpoint_count ) { $x_large_count = 2; } if ( $above_midpoint_count > 1 ) { $x_large_count++; } $slug += 10; } $spacing_sizes = array_merge( $below_sizes, $above_sizes ); // If there are 7 or less steps in the scale revert to numbers for labels instead of t-shirt sizes. if ( $spacing_scale['steps'] <= 7 ) { for ( $spacing_sizes_count = 0; $spacing_sizes_count < count( $spacing_sizes ); $spacing_sizes_count++ ) { $spacing_sizes[ $spacing_sizes_count ]['name'] = (string) ( $spacing_sizes_count + 1 ); } } _wp_array_set( $this->theme_json, array( 'settings', 'spacing', 'spacingSizes', 'default' ), $spacing_sizes ); } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_set()](../../functions/_wp_array_set) wp-includes/functions.php | Sets an array in depth based on a path of keys. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | [sanitize\_title()](../../functions/sanitize_title) wp-includes/formatting.php | Sanitizes a string into a slug, which can be used in URLs or HTML attributes. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Theme_JSON::maybe_opt_in_into_settings( array $theme_json ): array WP\_Theme\_JSON::maybe\_opt\_in\_into\_settings( array $theme\_json ): array ============================================================================ Enables some opt-in settings if theme declared support. `$theme_json` array Required A theme.json structure to modify. array The modified theme.json structure. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function maybe_opt_in_into_settings( $theme_json ) { $new_theme_json = $theme_json; if ( isset( $new_theme_json['settings']['appearanceTools'] ) && true === $new_theme_json['settings']['appearanceTools'] ) { static::do_opt_in_into_settings( $new_theme_json['settings'] ); } if ( isset( $new_theme_json['settings']['blocks'] ) && is_array( $new_theme_json['settings']['blocks'] ) ) { foreach ( $new_theme_json['settings']['blocks'] as &$block ) { if ( isset( $block['appearanceTools'] ) && ( true === $block['appearanceTools'] ) ) { static::do_opt_in_into_settings( $block ); } } } return $new_theme_json; } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::filter_slugs( array $node, array $slugs ): array WP\_Theme\_JSON::filter\_slugs( array $node, array $slugs ): array ================================================================== Removes the preset values whose slug is equal to any of given slugs. `$node` array Required The node with the presets to validate. `$slugs` array Required The slugs that should not be overridden. array The new node. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function filter_slugs( $node, $slugs ) { if ( empty( $slugs ) ) { return $node; } $new_node = array(); foreach ( $node as $value ) { if ( isset( $value['slug'] ) && ! in_array( $value['slug'], $slugs, true ) ) { $new_node[] = $value; } } return $new_node; } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::get_property_value( array $styles, array $path, array $theme_json = null ): string|array WP\_Theme\_JSON::get\_property\_value( array $styles, array $path, array $theme\_json = null ): string|array ============================================================================================================ Returns the style property for the given path. It also converts CSS Custom Property stored as "var:preset|color|secondary" to the form "–wp–preset–color–secondary". It also converts references to a path to the value stored at that location, e.g. { "ref": "style.color.background" } => "#fff". `$styles` array Required Styles subtree. `$path` array Required Which property to process. `$theme_json` array Optional Theme JSON array. Default: `null` string|array Style property value. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function get_property_value( $styles, $path, $theme_json = null ) { $value = _wp_array_get( $styles, $path, '' ); if ( '' === $value || null === $value ) { // No need to process the value further. return ''; } /* * This converts references to a path to the value at that path * where the values is an array with a "ref" key, pointing to a path. * For example: { "ref": "style.color.background" } => "#fff". */ if ( is_array( $value ) && array_key_exists( 'ref', $value ) ) { $value_path = explode( '.', $value['ref'] ); $ref_value = _wp_array_get( $theme_json, $value_path ); // Only use the ref value if we find anything. if ( ! empty( $ref_value ) && is_string( $ref_value ) ) { $value = $ref_value; } if ( is_array( $ref_value ) && array_key_exists( 'ref', $ref_value ) ) { $path_string = json_encode( $path ); $ref_value_string = json_encode( $ref_value ); _doing_it_wrong( 'get_property_value', sprintf( /* translators: 1: theme.json, 2: Value name, 3: Value path, 4: Another value name. */ __( 'Your %1$s file uses a dynamic value (%2$s) for the path at %3$s. However, the value at %3$s is also a dynamic value (pointing to %4$s) and pointing to another dynamic value is not supported. Please update %3$s to point directly to %4$s.' ), 'theme.json', $ref_value_string, $path_string, $ref_value['ref'] ), '6.1.0' ); } } if ( is_array( $value ) ) { return $value; } // Convert custom CSS properties. $prefix = 'var:'; $prefix_len = strlen( $prefix ); $token_in = '|'; $token_out = '--'; if ( 0 === strncmp( $value, $prefix, $prefix_len ) ) { $unwrapped_name = str_replace( $token_in, $token_out, substr( $value, $prefix_len ) ); $value = "var(--wp--$unwrapped_name)"; } return $value; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_doing\_it\_wrong()](../../functions/_doing_it_wrong) wp-includes/functions.php | Marks something as being incorrectly called. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added the `$theme_json` parameter. | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added support for values of array type, which are returned as is. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |
programming_docs
wordpress WP_Theme_JSON::is_safe_css_declaration( string $property_name, string $property_value ): bool WP\_Theme\_JSON::is\_safe\_css\_declaration( string $property\_name, string $property\_value ): bool ==================================================================================================== Checks that a declaration provided by the user is safe. `$property_name` string Required Property name in a CSS declaration, i.e. the `color` in `color: red`. `$property_value` string Required Value in a CSS declaration, i.e. the `red` in `color: red`. bool File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function is_safe_css_declaration( $property_name, $property_value ) { $style_to_validate = $property_name . ': ' . $property_value; $filtered = esc_html( safecss_filter_attr( $style_to_validate ) ); return ! empty( trim( $filtered ) ); } ``` | Uses | Description | | --- | --- | | [safecss\_filter\_attr()](../../functions/safecss_filter_attr) wp-includes/kses.php | Filters an inline style attribute and removes disallowed rules. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::get_layout_styles( array $block_metadata ): string WP\_Theme\_JSON::get\_layout\_styles( array $block\_metadata ): string ====================================================================== Gets the CSS layout rules for a particular block from theme.json layout definitions. `$block_metadata` array Required Metadata about the block to get styles for. string Layout styles for the block. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected function get_layout_styles( $block_metadata ) { $block_rules = ''; $block_type = null; // Skip outputting layout styles if explicitly disabled. if ( current_theme_supports( 'disable-layout-styles' ) ) { return $block_rules; } if ( isset( $block_metadata['name'] ) ) { $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_metadata['name'] ); if ( ! block_has_support( $block_type, array( '__experimentalLayout' ), false ) ) { return $block_rules; } } $selector = isset( $block_metadata['selector'] ) ? $block_metadata['selector'] : ''; $has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null; $has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support. $node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() ); $layout_definitions = _wp_array_get( $this->theme_json, array( 'settings', 'layout', 'definitions' ), array() ); $layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors. // Gap styles will only be output if the theme has block gap support, or supports a fallback gap. // Default layout gap styles will be skipped for themes that do not explicitly opt-in to blockGap with a `true` or `false` value. if ( $has_block_gap_support || $has_fallback_gap_support ) { $block_gap_value = null; // Use a fallback gap value if block gap support is not available. if ( ! $has_block_gap_support ) { $block_gap_value = static::ROOT_BLOCK_SELECTOR === $selector ? '0.5em' : null; if ( ! empty( $block_type ) ) { $block_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), null ); } } else { $block_gap_value = static::get_property_value( $node, array( 'spacing', 'blockGap' ) ); } // Support split row / column values and concatenate to a shorthand value. if ( is_array( $block_gap_value ) ) { if ( isset( $block_gap_value['top'] ) && isset( $block_gap_value['left'] ) ) { $gap_row = static::get_property_value( $node, array( 'spacing', 'blockGap', 'top' ) ); $gap_column = static::get_property_value( $node, array( 'spacing', 'blockGap', 'left' ) ); $block_gap_value = $gap_row === $gap_column ? $gap_row : $gap_row . ' ' . $gap_column; } else { // Skip outputting gap value if not all sides are provided. $block_gap_value = null; } } // If the block should have custom gap, add the gap styles. if ( null !== $block_gap_value && false !== $block_gap_value && '' !== $block_gap_value ) { foreach ( $layout_definitions as $layout_definition_key => $layout_definition ) { // Allow outputting fallback gap styles for flex layout type when block gap support isn't available. if ( ! $has_block_gap_support && 'flex' !== $layout_definition_key ) { continue; } $class_name = sanitize_title( _wp_array_get( $layout_definition, array( 'className' ), false ) ); $spacing_rules = _wp_array_get( $layout_definition, array( 'spacingStyles' ), array() ); if ( ! empty( $class_name ) && ! empty( $spacing_rules ) ) { foreach ( $spacing_rules as $spacing_rule ) { $declarations = array(); if ( isset( $spacing_rule['selector'] ) && preg_match( $layout_selector_pattern, $spacing_rule['selector'] ) && ! empty( $spacing_rule['rules'] ) ) { // Iterate over each of the styling rules and substitute non-string values such as `null` with the real `blockGap` value. foreach ( $spacing_rule['rules'] as $css_property => $css_value ) { $current_css_value = is_string( $css_value ) ? $css_value : $block_gap_value; if ( static::is_safe_css_declaration( $css_property, $current_css_value ) ) { $declarations[] = array( 'name' => $css_property, 'value' => $current_css_value, ); } } if ( ! $has_block_gap_support ) { // For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles. $format = static::ROOT_BLOCK_SELECTOR === $selector ? ':where(.%2$s%3$s)' : ':where(%1$s.%2$s%3$s)'; $layout_selector = sprintf( $format, $selector, $class_name, $spacing_rule['selector'] ); } else { $format = static::ROOT_BLOCK_SELECTOR === $selector ? '%s .%s%s' : '%s.%s%s'; $layout_selector = sprintf( $format, $selector, $class_name, $spacing_rule['selector'] ); } $block_rules .= static::to_ruleset( $layout_selector, $declarations ); } } } } } } // Output base styles. if ( static::ROOT_BLOCK_SELECTOR === $selector ) { $valid_display_modes = array( 'block', 'flex', 'grid' ); foreach ( $layout_definitions as $layout_definition ) { $class_name = sanitize_title( _wp_array_get( $layout_definition, array( 'className' ), false ) ); $base_style_rules = _wp_array_get( $layout_definition, array( 'baseStyles' ), array() ); if ( ! empty( $class_name ) && ! empty( $base_style_rules ) ) { // Output display mode. This requires special handling as `display` is not exposed in `safe_style_css_filter`. if ( ! empty( $layout_definition['displayMode'] ) && is_string( $layout_definition['displayMode'] ) && in_array( $layout_definition['displayMode'], $valid_display_modes, true ) ) { $layout_selector = sprintf( '%s .%s', $selector, $class_name ); $block_rules .= static::to_ruleset( $layout_selector, array( array( 'name' => 'display', 'value' => $layout_definition['displayMode'], ), ) ); } foreach ( $base_style_rules as $base_style_rule ) { $declarations = array(); if ( isset( $base_style_rule['selector'] ) && preg_match( $layout_selector_pattern, $base_style_rule['selector'] ) && ! empty( $base_style_rule['rules'] ) ) { foreach ( $base_style_rule['rules'] as $css_property => $css_value ) { if ( static::is_safe_css_declaration( $css_property, $css_value ) ) { $declarations[] = array( 'name' => $css_property, 'value' => $css_value, ); } } $layout_selector = sprintf( '%s .%s%s', $selector, $class_name, $base_style_rule['selector'] ); $block_rules .= static::to_ruleset( $layout_selector, $declarations ); } } } } } return $block_rules; } ``` | Uses | Description | | --- | --- | | [block\_has\_support()](../../functions/block_has_support) wp-includes/blocks.php | Checks whether the current block type supports the feature requested. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | [WP\_Block\_Type\_Registry::get\_instance()](../wp_block_type_registry/get_instance) wp-includes/class-wp-block-type-registry.php | Utility method to retrieve the main instance of the class. | | [sanitize\_title()](../../functions/sanitize_title) wp-includes/formatting.php | Sanitizes a string into a slug, which can be used in URLs or HTML attributes. | | [current\_theme\_supports()](../../functions/current_theme_supports) wp-includes/theme.php | Checks a theme’s support for a given feature. | | Used By | Description | | --- | --- | | [WP\_Theme\_JSON::get\_styles\_for\_block()](get_styles_for_block) wp-includes/class-wp-theme-json.php | Gets the CSS rules for a particular block from theme.json. | | [WP\_Theme\_JSON::get\_root\_layout\_rules()](get_root_layout_rules) wp-includes/class-wp-theme-json.php | Outputs the CSS for layout rules on the root. | | [WP\_Theme\_JSON::get\_stylesheet()](get_stylesheet) wp-includes/class-wp-theme-json.php | Returns the stylesheet that results of processing the theme.json structure this object represents. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Theme_JSON::get_template_parts(): array WP\_Theme\_JSON::get\_template\_parts(): array ============================================== Returns the template part data of active theme. array File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_template_parts() { $template_parts = array(); if ( ! isset( $this->theme_json['templateParts'] ) || ! is_array( $this->theme_json['templateParts'] ) ) { return $template_parts; } foreach ( $this->theme_json['templateParts'] as $item ) { if ( isset( $item['name'] ) ) { $template_parts[ $item['name'] ] = array( 'title' => isset( $item['title'] ) ? $item['title'] : '', 'area' => isset( $item['area'] ) ? $item['area'] : '', ); } } return $template_parts; } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::get_data(): array WP\_Theme\_JSON::get\_data(): array =================================== Returns a valid theme.json as provided by a theme. Unlike get\_raw\_data() this returns the presets flattened, as provided by a theme. This also uses appearanceTools instead of their opt-ins if all of them are true. array File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_data() { $output = $this->theme_json; $nodes = static::get_setting_nodes( $output ); /** * Flatten the theme & custom origins into a single one. * * For example, the following: * * { * "settings": { * "color": { * "palette": { * "theme": [ {} ], * "custom": [ {} ] * } * } * } * } * * will be converted to: * * { * "settings": { * "color": { * "palette": [ {} ] * } * } * } */ foreach ( $nodes as $node ) { foreach ( static::PRESETS_METADATA as $preset_metadata ) { $path = array_merge( $node['path'], $preset_metadata['path'] ); $preset = _wp_array_get( $output, $path, null ); if ( null === $preset ) { continue; } $items = array(); if ( isset( $preset['theme'] ) ) { foreach ( $preset['theme'] as $item ) { $slug = $item['slug']; unset( $item['slug'] ); $items[ $slug ] = $item; } } if ( isset( $preset['custom'] ) ) { foreach ( $preset['custom'] as $item ) { $slug = $item['slug']; unset( $item['slug'] ); $items[ $slug ] = $item; } } $flattened_preset = array(); foreach ( $items as $slug => $value ) { $flattened_preset[] = array_merge( array( 'slug' => (string) $slug ), $value ); } _wp_array_set( $output, $path, $flattened_preset ); } } // If all of the static::APPEARANCE_TOOLS_OPT_INS are true, // this code unsets them and sets 'appearanceTools' instead. foreach ( $nodes as $node ) { $all_opt_ins_are_set = true; foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) { $full_path = array_merge( $node['path'], $opt_in_path ); // Use "unset prop" as a marker instead of "null" because // "null" can be a valid value for some props (e.g. blockGap). $opt_in_value = _wp_array_get( $output, $full_path, 'unset prop' ); if ( 'unset prop' === $opt_in_value ) { $all_opt_ins_are_set = false; break; } } if ( $all_opt_ins_are_set ) { _wp_array_set( $output, array_merge( $node['path'], array( 'appearanceTools' ) ), true ); foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) { $full_path = array_merge( $node['path'], $opt_in_path ); // Use "unset prop" as a marker instead of "null" because // "null" can be a valid value for some props (e.g. blockGap). $opt_in_value = _wp_array_get( $output, $full_path, 'unset prop' ); if ( true !== $opt_in_value ) { continue; } // The following could be improved to be path independent. // At the moment it relies on a couple of assumptions: // // - all opt-ins having a path of size 2. // - there's two sources of settings: the top-level and the block-level. if ( ( 1 === count( $node['path'] ) ) && ( 'settings' === $node['path'][0] ) ) { // Top-level settings. unset( $output['settings'][ $opt_in_path[0] ][ $opt_in_path[1] ] ); if ( empty( $output['settings'][ $opt_in_path[0] ] ) ) { unset( $output['settings'][ $opt_in_path[0] ] ); } } elseif ( ( 3 === count( $node['path'] ) ) && ( 'settings' === $node['path'][0] ) && ( 'blocks' === $node['path'][1] ) ) { // Block-level settings. $block_name = $node['path'][2]; unset( $output['settings']['blocks'][ $block_name ][ $opt_in_path[0] ][ $opt_in_path[1] ] ); if ( empty( $output['settings']['blocks'][ $block_name ][ $opt_in_path[0] ] ) ) { unset( $output['settings']['blocks'][ $block_name ][ $opt_in_path[0] ] ); } } } } } wp_recursive_ksort( $output ); return $output; } ``` | Uses | Description | | --- | --- | | [wp\_recursive\_ksort()](../../functions/wp_recursive_ksort) wp-includes/functions.php | Sorts the keys of an array alphabetically. | | [\_wp\_array\_set()](../../functions/_wp_array_set) wp-includes/functions.php | Sets an array in depth based on a path of keys. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Introduced. | wordpress WP_Theme_JSON::flatten_tree( array $tree, string $prefix = '', string $token = '--' ): array WP\_Theme\_JSON::flatten\_tree( array $tree, string $prefix = '', string $token = '--' ): array =============================================================================================== Given a tree, it creates a flattened one by merging the keys and binding the leaf values to the new keys. It also transforms camelCase names into kebab-case and substitutes ‘/’ by ‘-‘. This is thought to be useful to generate CSS Custom Properties from a tree, although there’s nothing in the implementation of this function that requires that format. For example, assuming the given prefix is ‘–wp’ and the token is ‘–‘, for this input tree: ``` { 'some/property': 'value', 'nestedProperty': { 'sub-property': 'value' } } ``` it’ll return this output: ``` { '--wp--some-property': 'value', '--wp--nested-property--sub-property': 'value' } ``` `$tree` array Required Input tree to process. `$prefix` string Optional Prefix to prepend to each variable. Default: `''` `$token` string Optional Token to use between levels. Default `'--'`. Default: `'--'` array The flattened tree. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function flatten_tree( $tree, $prefix = '', $token = '--' ) { $result = array(); foreach ( $tree as $property => $value ) { $new_key = $prefix . str_replace( '/', '-', strtolower( _wp_to_kebab_case( $property ) ) ); if ( is_array( $value ) ) { $new_prefix = $new_key . $token; $result = array_merge( $result, static::flatten_tree( $value, $new_prefix, $token ) ); } else { $result[ $new_key ] = $value; } } return $result; } ``` | Uses | Description | | --- | --- | | [\_wp\_to\_kebab\_case()](../../functions/_wp_to_kebab_case) wp-includes/functions.php | This function is trying to replicate what lodash’s kebabCase (JS library) does in the client. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_element_class_name( string $element ): string WP\_Theme\_JSON::get\_element\_class\_name( string $element ): string ===================================================================== Returns a class name by an element name. `$element` string Required The name of the element. string The name of the class. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public static function get_element_class_name( $element ) { $class_name = ''; if ( array_key_exists( $element, static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES ) ) { $class_name = static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $element ]; } return $class_name; } ``` | Used By | Description | | --- | --- | | [wp\_theme\_get\_element\_class\_name()](../../functions/wp_theme_get_element_class_name) wp-includes/theme.php | Given an element name, returns a class name. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Theme_JSON::get_root_layout_rules( string $selector, array $block_metadata ): string WP\_Theme\_JSON::get\_root\_layout\_rules( string $selector, array $block\_metadata ): string ============================================================================================= Outputs the CSS for layout rules on the root. `$selector` string Required The root node selector. `$block_metadata` array Required The metadata for the root block. string The additional root rules CSS. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_root_layout_rules( $selector, $block_metadata ) { $css = ''; $settings = _wp_array_get( $this->theme_json, array( 'settings' ) ); $use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments']; /* * Reset default browser margin on the root body element. * This is set on the root selector **before** generating the ruleset * from the `theme.json`. This is to ensure that if the `theme.json` declares * `margin` in its `spacing` declaration for the `body` element then these * user-generated values take precedence in the CSS cascade. * @link https://github.com/WordPress/gutenberg/issues/36147. */ $css .= 'body { margin: 0;'; /* * If there are content and wide widths in theme.json, output them * as custom properties on the body element so all blocks can use them. */ if ( isset( $settings['layout']['contentSize'] ) || isset( $settings['layout']['wideSize'] ) ) { $content_size = isset( $settings['layout']['contentSize'] ) ? $settings['layout']['contentSize'] : $settings['layout']['wideSize']; $content_size = static::is_safe_css_declaration( 'max-width', $content_size ) ? $content_size : 'initial'; $wide_size = isset( $settings['layout']['wideSize'] ) ? $settings['layout']['wideSize'] : $settings['layout']['contentSize']; $wide_size = static::is_safe_css_declaration( 'max-width', $wide_size ) ? $wide_size : 'initial'; $css .= '--wp--style--global--content-size: ' . $content_size . ';'; $css .= '--wp--style--global--wide-size: ' . $wide_size . ';'; } $css .= ' }'; if ( $use_root_padding ) { // Top and bottom padding are applied to the outer block container. $css .= '.wp-site-blocks { padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom); }'; // Right and left padding are applied to the first container with `.has-global-padding` class. $css .= '.has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }'; // Nested containers with `.has-global-padding` class do not get padding. $css .= '.has-global-padding :where(.has-global-padding) { padding-right: 0; padding-left: 0; }'; // Alignfull children of the container with left and right padding have negative margins so they can still be full width. $css .= '.has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }'; // The above rule is negated for alignfull children of nested containers. $css .= '.has-global-padding :where(.has-global-padding) > .alignfull { margin-right: 0; margin-left: 0; }'; // Some of the children of alignfull blocks without content width should also get padding: text blocks and non-alignfull container blocks. $css .= '.has-global-padding > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }'; // The above rule also has to be negated for blocks inside nested `.has-global-padding` blocks. $css .= '.has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 0; }'; } $css .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }'; $css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }'; $css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }'; $block_gap_value = _wp_array_get( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ), '0.5em' ); $has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null; if ( $has_block_gap_support ) { $block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) ); $css .= '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }'; $css .= ".wp-site-blocks > * + * { margin-block-start: $block_gap_value; }"; // For backwards compatibility, ensure the legacy block gap CSS variable is still available. $css .= "$selector { --wp--style--block-gap: $block_gap_value; }"; } $css .= $this->get_layout_styles( $block_metadata ); return $css; } ``` | Uses | Description | | --- | --- | | [WP\_Theme\_JSON::get\_layout\_styles()](get_layout_styles) wp-includes/class-wp-theme-json.php | Gets the CSS layout rules for a particular block from theme.json layout definitions. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Used By | Description | | --- | --- | | [WP\_Theme\_JSON::get\_stylesheet()](get_stylesheet) wp-includes/class-wp-theme-json.php | Returns the stylesheet that results of processing the theme.json structure this object represents. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. |
programming_docs
wordpress WP_Theme_JSON::compute_preset_vars( array $settings, array $origins ): array WP\_Theme\_JSON::compute\_preset\_vars( array $settings, array $origins ): array ================================================================================ Given the block settings, extracts the CSS Custom Properties for the presets and adds them to the $declarations array following the format: array( ‘name’ => ‘property\_name’, ‘value’ => ‘property\_value, ) `$settings` array Required Settings to process. `$origins` array Required List of origins to process. array The modified $declarations. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function compute_preset_vars( $settings, $origins ) { $declarations = array(); foreach ( static::PRESETS_METADATA as $preset_metadata ) { $values_by_slug = static::get_settings_values_by_slug( $settings, $preset_metadata, $origins ); foreach ( $values_by_slug as $slug => $value ) { $declarations[] = array( 'name' => static::replace_slug_in_string( $preset_metadata['css_vars'], $slug ), 'value' => $value, ); } } return $declarations; } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added the `$origins` parameter. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::to_ruleset( string $selector, array $declarations ): string WP\_Theme\_JSON::to\_ruleset( string $selector, array $declarations ): string ============================================================================= Given a selector and a declaration list, creates the corresponding ruleset. `$selector` string Required CSS selector. `$declarations` array Required List of declarations. string The resulting CSS ruleset. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function to_ruleset( $selector, $declarations ) { if ( empty( $declarations ) ) { return ''; } $declaration_block = array_reduce( $declarations, static function ( $carry, $element ) { return $carry .= $element['name'] . ': ' . $element['value'] . ';'; }, '' ); return $selector . '{' . $declaration_block . '}'; } ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_block_classes( array $style_nodes ): string WP\_Theme\_JSON::get\_block\_classes( array $style\_nodes ): string =================================================================== Converts each style section into a list of rulesets containing the block styles to be appended to the stylesheet. See glossary at <https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax> For each section this creates a new ruleset such as: block-selector { style-property-one: value; } `$style_nodes` array Required Nodes with styles. string The new stylesheet. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected function get_block_classes( $style_nodes ) { $block_rules = ''; foreach ( $style_nodes as $metadata ) { if ( null === $metadata['selector'] ) { continue; } $block_rules .= static::get_styles_for_block( $metadata ); } return $block_rules; } ``` | Used By | Description | | --- | --- | | [WP\_Theme\_JSON::get\_stylesheet()](get_stylesheet) wp-includes/class-wp-theme-json.php | Returns the stylesheet that results of processing the theme.json structure this object represents. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Moved most internal logic to `get_styles_for_block()`. | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed from `get_block_styles()` to `get_block_classes()` and no longer returns preset classes. Removed the `$setting_nodes` parameter. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::compute_theme_vars( array $settings ): array WP\_Theme\_JSON::compute\_theme\_vars( array $settings ): array =============================================================== Given an array of settings, extracts the CSS Custom Properties for the custom values and adds them to the $declarations array following the format: array( ‘name’ => ‘property\_name’, ‘value’ => ‘property\_value, ) `$settings` array Required Settings to process. array The modified $declarations. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function compute_theme_vars( $settings ) { $declarations = array(); $custom_values = _wp_array_get( $settings, array( 'custom' ), array() ); $css_vars = static::flatten_tree( $custom_values ); foreach ( $css_vars as $key => $value ) { $declarations[] = array( 'name' => '--wp--custom--' . $key, 'value' => $value, ); } return $declarations; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_block_styles( array $style_nodes, array $setting_nodes ): string WP\_Theme\_JSON::get\_block\_styles( array $style\_nodes, array $setting\_nodes ): string ========================================================================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Converts each style section into a list of rulesets containing the block styles to be appended to the stylesheet. See glossary at <https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax> For each section this creates a new ruleset such as: block-selector { style-property-one: value; } Additionally, it’ll also create new rulesets as classes for each preset value such as: ``` .has-value-color { color: value; } .has-value-background-color { background-color: value; } .has-value-font-size { font-size: value; } .has-value-gradient-background { background: value; } p.has-value-gradient-background { background: value; } ``` `$style_nodes` array Required Nodes with styles. `$setting_nodes` array Required Nodes with settings. string The new stylesheet. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` /** * Enables some settings. * * @since 5.9.0 * * @param array $context The context to which the settings belong. */ protected static function do_opt_in_into_settings( &$context ) { foreach ( static::APPEARANCE_TOOLS_OPT_INS as $path ) { // Use "unset prop" as a marker instead of "null" because // "null" can be a valid value for some props (e.g. blockGap). if ( 'unset prop' === _wp_array_get( $context, $path, 'unset prop' ) ) { _wp_array_set( $context, $path, true ); } } unset( $context['appearanceTools'] ); } /** * Sanitizes the input according to the schemas. * * @since 5.8.0 * @since 5.9.0 Added the `$valid_block_names` and `$valid_element_name` parameters. * * @param array $input Structure to sanitize. ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_blocks_metadata(): array WP\_Theme\_JSON::get\_blocks\_metadata(): array =============================================== Returns the metadata for each block. Example: ``` { 'core/paragraph': { 'selector': 'p', 'elements': { 'link' => 'link selector', 'etc' => 'element selector' } }, 'core/heading': { 'selector': 'h1', 'elements': {} }, 'core/image': { 'selector': '.wp-block-image', 'duotone': 'img', 'elements': {} } } ``` array Block metadata. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function get_blocks_metadata() { $registry = WP_Block_Type_Registry::get_instance(); $blocks = $registry->get_all_registered(); // Is there metadata for all currently registered blocks? $blocks = array_diff_key( $blocks, static::$blocks_metadata ); if ( empty( $blocks ) ) { return static::$blocks_metadata; } foreach ( $blocks as $block_name => $block_type ) { if ( isset( $block_type->supports['__experimentalSelector'] ) && is_string( $block_type->supports['__experimentalSelector'] ) ) { static::$blocks_metadata[ $block_name ]['selector'] = $block_type->supports['__experimentalSelector']; } else { static::$blocks_metadata[ $block_name ]['selector'] = '.wp-block-' . str_replace( '/', '-', str_replace( 'core/', '', $block_name ) ); } if ( isset( $block_type->supports['color']['__experimentalDuotone'] ) && is_string( $block_type->supports['color']['__experimentalDuotone'] ) ) { static::$blocks_metadata[ $block_name ]['duotone'] = $block_type->supports['color']['__experimentalDuotone']; } // Generate block support feature level selectors if opted into // for the current block. $features = array(); foreach ( static::BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS as $key => $feature ) { if ( isset( $block_type->supports[ $key ]['__experimentalSelector'] ) && $block_type->supports[ $key ]['__experimentalSelector'] ) { $features[ $feature ] = static::scope_selector( static::$blocks_metadata[ $block_name ]['selector'], $block_type->supports[ $key ]['__experimentalSelector'] ); } } if ( ! empty( $features ) ) { static::$blocks_metadata[ $block_name ]['features'] = $features; } // Assign defaults, then overwrite those that the block sets by itself. // If the block selector is compounded, will append the element to each // individual block selector. $block_selectors = explode( ',', static::$blocks_metadata[ $block_name ]['selector'] ); foreach ( static::ELEMENTS as $el_name => $el_selector ) { $element_selector = array(); foreach ( $block_selectors as $selector ) { if ( $selector === $el_selector ) { $element_selector = array( $el_selector ); break; } $element_selector[] = static::append_to_selector( $el_selector, $selector . ' ', 'left' ); } static::$blocks_metadata[ $block_name ]['elements'][ $el_name ] = implode( ',', $element_selector ); } } return static::$blocks_metadata; } ``` | Uses | Description | | --- | --- | | [WP\_Block\_Type\_Registry::get\_instance()](../wp_block_type_registry/get_instance) wp-includes/class-wp-block-type-registry.php | Utility method to retrieve the main instance of the class. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added `features` key with block support feature level selectors. | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added `duotone` key with CSS selector. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::has_properties( array $metadata ): bool WP\_Theme\_JSON::has\_properties( array $metadata ): bool ========================================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Whether the metadata contains a key named properties. `$metadata` array Required Description of the style property. bool True if properties exists, false otherwise. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` } if ( in_array( 'presets', $types, true ) ) { $stylesheet .= $this->get_preset_classes( $setting_nodes, $origins ); } return $stylesheet; ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_settings(): array WP\_Theme\_JSON::get\_settings(): array ======================================= Returns the existing settings for each block. Example: ``` { 'root': { 'color': { 'custom': true } }, 'core/paragraph': { 'spacing': { 'customPadding': true } } } ``` array Settings per block. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_settings() { if ( ! isset( $this->theme_json['settings'] ) ) { return array(); } else { return $this->theme_json['settings']; } } ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_custom_templates(): array WP\_Theme\_JSON::get\_custom\_templates(): array ================================================ Returns the page templates of the active theme. array File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_custom_templates() { $custom_templates = array(); if ( ! isset( $this->theme_json['customTemplates'] ) || ! is_array( $this->theme_json['customTemplates'] ) ) { return $custom_templates; } foreach ( $this->theme_json['customTemplates'] as $item ) { if ( isset( $item['name'] ) ) { $custom_templates[ $item['name'] ] = array( 'title' => isset( $item['title'] ) ? $item['title'] : '', 'postTypes' => isset( $item['postTypes'] ) ? $item['postTypes'] : array( 'page' ), ); } } return $custom_templates; } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::compute_style_properties( array $styles, array $settings = array(), array $properties = null, array $theme_json = null, string $selector = null, boolean $use_root_padding = null ): array WP\_Theme\_JSON::compute\_style\_properties( array $styles, array $settings = array(), array $properties = null, array $theme\_json = null, string $selector = null, boolean $use\_root\_padding = null ): array ================================================================================================================================================================================================================ Given a styles array, it extracts the style properties and adds them to the $declarations array following the format: array( ‘name’ => ‘property\_name’, ‘value’ => ‘property\_value, ) `$styles` array Required Styles to process. `$settings` array Optional Theme settings. Default: `array()` `$properties` array Optional Properties metadata. Default: `null` `$theme_json` array Optional Theme JSON array. Default: `null` `$selector` string Optional The style block selector. Default: `null` `$use_root_padding` boolean Optional Whether to add custom properties at root level. Default: `null` array Returns the modified $declarations. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function compute_style_properties( $styles, $settings = array(), $properties = null, $theme_json = null, $selector = null, $use_root_padding = null ) { if ( null === $properties ) { $properties = static::PROPERTIES_METADATA; } $declarations = array(); if ( empty( $styles ) ) { return $declarations; } $root_variable_duplicates = array(); foreach ( $properties as $css_property => $value_path ) { $value = static::get_property_value( $styles, $value_path, $theme_json ); if ( str_starts_with( $css_property, '--wp--style--root--' ) && ( static::ROOT_BLOCK_SELECTOR !== $selector || ! $use_root_padding ) ) { continue; } // Root-level padding styles don't currently support strings with CSS shorthand values. // This may change: https://github.com/WordPress/gutenberg/issues/40132. if ( '--wp--style--root--padding' === $css_property && is_string( $value ) ) { continue; } if ( str_starts_with( $css_property, '--wp--style--root--' ) && $use_root_padding ) { $root_variable_duplicates[] = substr( $css_property, strlen( '--wp--style--root--' ) ); } // Look up protected properties, keyed by value path. // Skip protected properties that are explicitly set to `null`. if ( is_array( $value_path ) ) { $path_string = implode( '.', $value_path ); if ( array_key_exists( $path_string, static::PROTECTED_PROPERTIES ) && _wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null ) { continue; } } // Skip if empty and not "0" or value represents array of longhand values. $has_missing_value = empty( $value ) && ! is_numeric( $value ); if ( $has_missing_value || is_array( $value ) ) { continue; } // Calculates fluid typography rules where available. if ( 'font-size' === $css_property ) { /* * wp_get_typography_font_size_value() will check * if fluid typography has been activated and also * whether the incoming value can be converted to a fluid value. * Values that already have a clamp() function will not pass the test, * and therefore the original $value will be returned. */ $value = wp_get_typography_font_size_value( array( 'size' => $value ) ); } $declarations[] = array( 'name' => $css_property, 'value' => $value, ); } // If a variable value is added to the root, the corresponding property should be removed. foreach ( $root_variable_duplicates as $duplicate ) { $discard = array_search( $duplicate, array_column( $declarations, 'name' ), true ); if ( is_numeric( $discard ) ) { array_splice( $declarations, $discard, 1 ); } } return $declarations; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added `$theme_json`, `$selector`, and `$use_root_padding` parameters. | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added the `$settings` and `$properties` parameters. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_raw_data(): array WP\_Theme\_JSON::get\_raw\_data(): array ======================================== Returns the raw data. array Raw data. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function get_raw_data() { return $this->theme_json; } ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |
programming_docs
wordpress WP_Theme_JSON::__construct( array $theme_json = array(), string $origin = 'theme' ) WP\_Theme\_JSON::\_\_construct( array $theme\_json = array(), string $origin = 'theme' ) ======================================================================================== Constructor. `$theme_json` array Optional A structure that follows the theme.json schema. Default: `array()` `$origin` string Optional What source of data this object represents. One of `'default'`, `'theme'`, or `'custom'`. Default `'theme'`. Default: `'theme'` File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public function __construct( $theme_json = array(), $origin = 'theme' ) { if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) { $origin = 'theme'; } $this->theme_json = WP_Theme_JSON_Schema::migrate( $theme_json ); $valid_block_names = array_keys( static::get_blocks_metadata() ); $valid_element_names = array_keys( static::ELEMENTS ); $theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names ); $this->theme_json = static::maybe_opt_in_into_settings( $theme_json ); // Internally, presets are keyed by origin. $nodes = static::get_setting_nodes( $this->theme_json ); foreach ( $nodes as $node ) { foreach ( static::PRESETS_METADATA as $preset_metadata ) { $path = array_merge( $node['path'], $preset_metadata['path'] ); $preset = _wp_array_get( $this->theme_json, $path, null ); if ( null !== $preset ) { // If the preset is not already keyed by origin. if ( isset( $preset[0] ) || empty( $preset ) ) { _wp_array_set( $this->theme_json, $path, array( $origin => $preset ) ); } } } } } ``` | Uses | Description | | --- | --- | | [WP\_Theme\_JSON\_Schema::migrate()](../wp_theme_json_schema/migrate) wp-includes/class-wp-theme-json-schema.php | Function that migrates a given theme.json structure to the last version. | | [\_wp\_array\_set()](../../functions/_wp_array_set) wp-includes/functions.php | Sets an array in depth based on a path of keys. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Used By | Description | | --- | --- | | [WP\_Theme\_JSON\_Data::\_\_construct()](../wp_theme_json_data/__construct) wp-includes/class-wp-theme-json-data.php | Constructor. | | [WP\_Theme\_JSON\_Data::update\_with()](../wp_theme_json_data/update_with) wp-includes/class-wp-theme-json-data.php | Updates the theme.json with the the given data. | | [WP\_Theme\_JSON\_Resolver::get\_block\_data()](../wp_theme_json_resolver/get_block_data) wp-includes/class-wp-theme-json-resolver.php | Gets the styles for blocks from the block.json file. | | [WP\_Theme\_JSON\_Resolver::get\_style\_variations()](../wp_theme_json_resolver/get_style_variations) wp-includes/class-wp-theme-json-resolver.php | Returns the style variations defined by the theme. | | [WP\_Theme\_JSON\_Resolver::get\_user\_data()](../wp_theme_json_resolver/get_user_data) wp-includes/class-wp-theme-json-resolver.php | Returns the user’s origin config. | | [WP\_REST\_Global\_Styles\_Controller::prepare\_item\_for\_response()](../wp_rest_global_styles_controller/prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php | Prepare a global styles config output for response. | | [WP\_Theme\_JSON\_Resolver::get\_theme\_data()](../wp_theme_json_resolver/get_theme_data) wp-includes/class-wp-theme-json-resolver.php | Returns the theme’s data. | | [WP\_Theme\_JSON\_Resolver::get\_core\_data()](../wp_theme_json_resolver/get_core_data) wp-includes/class-wp-theme-json-resolver.php | Returns core’s origin config. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::should_override_preset( array $theme_json, array $path, bool|array $override ): boolean WP\_Theme\_JSON::should\_override\_preset( array $theme\_json, array $path, bool|array $override ): boolean =========================================================================================================== This method has been deprecated. Use [‘get\_metadata\_boolean’](../../hooks/get_metadata_boolean) instead. Determines whether a presets should be overridden or not. `$theme_json` array Required The theme.json like structure to inspect. `$path` array Required Path to inspect. `$override` bool|array Required Data to compute whether to override the preset. boolean File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function should_override_preset( $theme_json, $path, $override ) { _deprecated_function( __METHOD__, '6.0.0', 'get_metadata_boolean' ); if ( is_bool( $override ) ) { return $override; } /* * The relationship between whether to override the defaults * and whether the defaults are enabled is inverse: * * - If defaults are enabled => theme presets should not be overridden * - If defaults are disabled => theme presets should be overridden * * For example, a theme sets defaultPalette to false, * making the default palette hidden from the user. * In that case, we want all the theme presets to be present, * so they should override the defaults. */ if ( is_array( $override ) ) { $value = _wp_array_get( $theme_json, array_merge( $path, $override ) ); if ( isset( $value ) ) { return ! $value; } // Search the top-level key if none was found for this node. $value = _wp_array_get( $theme_json, array_merge( array( 'settings' ), $override ) ); if ( isset( $value ) ) { return ! $value; } return true; } } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Use ['get\_metadata\_boolean'](../../hooks/get_metadata_boolean) instead. | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::remove_insecure_styles( array $input ): array WP\_Theme\_JSON::remove\_insecure\_styles( array $input ): array ================================================================ Processes a style node and returns the same node without the insecure styles. `$input` array Required Node to process. array File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function remove_insecure_styles( $input ) { $output = array(); $declarations = static::compute_style_properties( $input ); foreach ( $declarations as $declaration ) { if ( static::is_safe_css_declaration( $declaration['name'], $declaration['value'] ) ) { $path = static::PROPERTIES_METADATA[ $declaration['name'] ]; // Check the value isn't an array before adding so as to not // double up shorthand and longhand styles. $value = _wp_array_get( $input, $path, array() ); if ( ! is_array( $value ) ) { _wp_array_set( $output, $path, $value ); } } } return $output; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_set()](../../functions/_wp_array_set) wp-includes/functions.php | Sets an array in depth based on a path of keys. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::get_merged_preset_by_slug( array $preset_per_origin, string $value_key ): array WP\_Theme\_JSON::get\_merged\_preset\_by\_slug( array $preset\_per\_origin, string $value\_key ): array ======================================================================================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Given an array of presets keyed by origin and the value key of the preset, it returns an array where each key is the preset slug and each value the preset value. `$preset_per_origin` array Required Array of presets keyed by origin. `$value_key` string Required The property of the preset that contains its value. array Array of presets where each key is a slug and each value is the preset value. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` * @since 5.8.0 * @since 6.1.0 Added append position. * * @param string $selector Original selector. * @param string $to_append Selector to append. * @param string $position A position sub-selector should be appended. Default 'right'. * @return string The new selector. */ protected static function append_to_selector( $selector, $to_append, $position = 'right' ) { $new_selectors = array(); $selectors = explode( ',', $selector ); foreach ( $selectors as $sel ) { $new_selectors[] = 'right' === $position ? $sel . $to_append : $to_append . $sel; } return implode( ',', $new_selectors ); } /** ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::get_settings_values_by_slug( array $settings, array $preset_metadata, array $origins ): array WP\_Theme\_JSON::get\_settings\_values\_by\_slug( array $settings, array $preset\_metadata, array $origins ): array =================================================================================================================== Gets preset values keyed by slugs based on settings and metadata. ``` $settings = array( 'typography' => array( 'fontFamilies' => array( array( 'slug' => 'sansSerif', 'fontFamily' => '"Helvetica Neue", sans-serif', ), array( 'slug' => 'serif', 'colors' => 'Georgia, serif', ) ), ), ); $meta = array( 'path' => array( 'typography', 'fontFamilies' ), 'value_key' => 'fontFamily', ); $values_by_slug = get_settings_values_by_slug(); // $values_by_slug === array( // 'sans-serif' => '"Helvetica Neue", sans-serif', // 'serif' => 'Georgia, serif', // ); ``` `$settings` array Required Settings to process. `$preset_metadata` array Required One of the PRESETS\_METADATA values. `$origins` array Required List of origins to process. array Array of presets where each key is a slug and each value is the preset value. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) { $preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() ); $result = array(); foreach ( $origins as $origin ) { if ( ! isset( $preset_per_origin[ $origin ] ) ) { continue; } foreach ( $preset_per_origin[ $origin ] as $preset ) { $slug = _wp_to_kebab_case( $preset['slug'] ); $value = ''; if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) { $value_key = $preset_metadata['value_key']; $value = $preset[ $value_key ]; } elseif ( isset( $preset_metadata['value_func'] ) && is_callable( $preset_metadata['value_func'] ) ) { $value_func = $preset_metadata['value_func']; $value = call_user_func( $value_func, $preset ); } else { // If we don't have a value, then don't add it to the result. continue; } $result[ $slug ] = $value; } } return $result; } ``` | Uses | Description | | --- | --- | | [\_wp\_to\_kebab\_case()](../../functions/_wp_to_kebab_case) wp-includes/functions.php | This function is trying to replicate what lodash’s kebabCase (JS library) does in the client. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::replace_slug_in_string( string $input, string $slug ): string WP\_Theme\_JSON::replace\_slug\_in\_string( string $input, string $slug ): string ================================================================================= Transforms a slug into a CSS Custom Property. `$input` string Required String to replace. `$slug` string Required The slug value to use to generate the custom property. string The CSS Custom Property. Something along the lines of `--wp--preset--color--black`. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function replace_slug_in_string( $input, $slug ) { return strtr( $input, array( '$slug' => $slug ) ); } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::get_from_editor_settings( array $settings ): array WP\_Theme\_JSON::get\_from\_editor\_settings( array $settings ): array ====================================================================== Transforms the given editor settings according the add\_theme\_support format to the theme.json format. `$settings` array Required Existing editor settings. array Config that adheres to the theme.json schema. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public static function get_from_editor_settings( $settings ) { $theme_settings = array( 'version' => static::LATEST_SCHEMA, 'settings' => array(), ); // Deprecated theme supports. if ( isset( $settings['disableCustomColors'] ) ) { if ( ! isset( $theme_settings['settings']['color'] ) ) { $theme_settings['settings']['color'] = array(); } $theme_settings['settings']['color']['custom'] = ! $settings['disableCustomColors']; } if ( isset( $settings['disableCustomGradients'] ) ) { if ( ! isset( $theme_settings['settings']['color'] ) ) { $theme_settings['settings']['color'] = array(); } $theme_settings['settings']['color']['customGradient'] = ! $settings['disableCustomGradients']; } if ( isset( $settings['disableCustomFontSizes'] ) ) { if ( ! isset( $theme_settings['settings']['typography'] ) ) { $theme_settings['settings']['typography'] = array(); } $theme_settings['settings']['typography']['customFontSize'] = ! $settings['disableCustomFontSizes']; } if ( isset( $settings['enableCustomLineHeight'] ) ) { if ( ! isset( $theme_settings['settings']['typography'] ) ) { $theme_settings['settings']['typography'] = array(); } $theme_settings['settings']['typography']['lineHeight'] = $settings['enableCustomLineHeight']; } if ( isset( $settings['enableCustomUnits'] ) ) { if ( ! isset( $theme_settings['settings']['spacing'] ) ) { $theme_settings['settings']['spacing'] = array(); } $theme_settings['settings']['spacing']['units'] = ( true === $settings['enableCustomUnits'] ) ? array( 'px', 'em', 'rem', 'vh', 'vw', '%' ) : $settings['enableCustomUnits']; } if ( isset( $settings['colors'] ) ) { if ( ! isset( $theme_settings['settings']['color'] ) ) { $theme_settings['settings']['color'] = array(); } $theme_settings['settings']['color']['palette'] = $settings['colors']; } if ( isset( $settings['gradients'] ) ) { if ( ! isset( $theme_settings['settings']['color'] ) ) { $theme_settings['settings']['color'] = array(); } $theme_settings['settings']['color']['gradients'] = $settings['gradients']; } if ( isset( $settings['fontSizes'] ) ) { $font_sizes = $settings['fontSizes']; // Back-compatibility for presets without units. foreach ( $font_sizes as $key => $font_size ) { if ( is_numeric( $font_size['size'] ) ) { $font_sizes[ $key ]['size'] = $font_size['size'] . 'px'; } } if ( ! isset( $theme_settings['settings']['typography'] ) ) { $theme_settings['settings']['typography'] = array(); } $theme_settings['settings']['typography']['fontSizes'] = $font_sizes; } if ( isset( $settings['enableCustomSpacing'] ) ) { if ( ! isset( $theme_settings['settings']['spacing'] ) ) { $theme_settings['settings']['spacing'] = array(); } $theme_settings['settings']['spacing']['padding'] = $settings['enableCustomSpacing']; } return $theme_settings; } ``` | Used By | Description | | --- | --- | | [WP\_Theme\_JSON\_Resolver::get\_theme\_data()](../wp_theme_json_resolver/get_theme_data) wp-includes/class-wp-theme-json-resolver.php | Returns the theme’s data. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::remove_insecure_settings( array $input ): array WP\_Theme\_JSON::remove\_insecure\_settings( array $input ): array ================================================================== Processes a setting node and returns the same node without the insecure settings. `$input` array Required Node to process. array File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function remove_insecure_settings( $input ) { $output = array(); foreach ( static::PRESETS_METADATA as $preset_metadata ) { foreach ( static::VALID_ORIGINS as $origin ) { $path_with_origin = array_merge( $preset_metadata['path'], array( $origin ) ); $presets = _wp_array_get( $input, $path_with_origin, null ); if ( null === $presets ) { continue; } $escaped_preset = array(); foreach ( $presets as $preset ) { if ( esc_attr( esc_html( $preset['name'] ) ) === $preset['name'] && sanitize_html_class( $preset['slug'] ) === $preset['slug'] ) { $value = null; if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) { $value = $preset[ $preset_metadata['value_key'] ]; } elseif ( isset( $preset_metadata['value_func'] ) && is_callable( $preset_metadata['value_func'] ) ) { $value = call_user_func( $preset_metadata['value_func'], $preset ); } $preset_is_valid = true; foreach ( $preset_metadata['properties'] as $property ) { if ( ! static::is_safe_css_declaration( $property, $value ) ) { $preset_is_valid = false; break; } } if ( $preset_is_valid ) { $escaped_preset[] = $preset; } } } if ( ! empty( $escaped_preset ) ) { _wp_array_set( $output, $path_with_origin, $escaped_preset ); } } } return $output; } ``` | Uses | Description | | --- | --- | | [\_wp\_array\_set()](../../functions/_wp_array_set) wp-includes/functions.php | Sets an array in depth based on a path of keys. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | [sanitize\_html\_class()](../../functions/sanitize_html_class) wp-includes/formatting.php | Sanitizes an HTML classname to ensure it only contains valid characters. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |
programming_docs
wordpress WP_Theme_JSON::compute_preset_classes( array $settings, string $selector, array $origins ): string WP\_Theme\_JSON::compute\_preset\_classes( array $settings, string $selector, array $origins ): string ====================================================================================================== Given a settings array, returns the generated rulesets for the preset classes. `$settings` array Required Settings to process. `$selector` string Required Selector wrapping the classes. `$origins` array Required List of origins to process. string The result of processing the presets. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function compute_preset_classes( $settings, $selector, $origins ) { if ( static::ROOT_BLOCK_SELECTOR === $selector ) { // Classes at the global level do not need any CSS prefixed, // and we don't want to increase its specificity. $selector = ''; } $stylesheet = ''; foreach ( static::PRESETS_METADATA as $preset_metadata ) { $slugs = static::get_settings_slugs( $settings, $preset_metadata, $origins ); foreach ( $preset_metadata['classes'] as $class => $property ) { foreach ( $slugs as $slug ) { $css_var = static::replace_slug_in_string( $preset_metadata['css_vars'], $slug ); $class_name = static::replace_slug_in_string( $class, $slug ); $stylesheet .= static::to_ruleset( static::append_to_selector( $selector, $class_name ), array( array( 'name' => $property, 'value' => 'var(' . $css_var . ') !important', ), ) ); } } } return $stylesheet; } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added the `$origins` parameter. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::remove_insecure_properties( array $theme_json ): array WP\_Theme\_JSON::remove\_insecure\_properties( array $theme\_json ): array ========================================================================== Removes insecure data from theme.json. `$theme_json` array Required Structure to sanitize. array Sanitized structure. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` public static function remove_insecure_properties( $theme_json ) { $sanitized = array(); $theme_json = WP_Theme_JSON_Schema::migrate( $theme_json ); $valid_block_names = array_keys( static::get_blocks_metadata() ); $valid_element_names = array_keys( static::ELEMENTS ); $theme_json = static::sanitize( $theme_json, $valid_block_names, $valid_element_names ); $blocks_metadata = static::get_blocks_metadata(); $style_nodes = static::get_style_nodes( $theme_json, $blocks_metadata ); foreach ( $style_nodes as $metadata ) { $input = _wp_array_get( $theme_json, $metadata['path'], array() ); if ( empty( $input ) ) { continue; } $output = static::remove_insecure_styles( $input ); /* * Get a reference to element name from path. * $metadata['path'] = array( 'styles', 'elements', 'link' ); */ $current_element = $metadata['path'][ count( $metadata['path'] ) - 1 ]; /* * $output is stripped of pseudo selectors. Re-add and process them * or insecure styles here. */ if ( array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] as $pseudo_selector ) { if ( isset( $input[ $pseudo_selector ] ) ) { $output[ $pseudo_selector ] = static::remove_insecure_styles( $input[ $pseudo_selector ] ); } } } if ( ! empty( $output ) ) { _wp_array_set( $sanitized, $metadata['path'], $output ); } } $setting_nodes = static::get_setting_nodes( $theme_json ); foreach ( $setting_nodes as $metadata ) { $input = _wp_array_get( $theme_json, $metadata['path'], array() ); if ( empty( $input ) ) { continue; } $output = static::remove_insecure_settings( $input ); if ( ! empty( $output ) ) { _wp_array_set( $sanitized, $metadata['path'], $output ); } } if ( empty( $sanitized['styles'] ) ) { unset( $theme_json['styles'] ); } else { $theme_json['styles'] = $sanitized['styles']; } if ( empty( $sanitized['settings'] ) ) { unset( $theme_json['settings'] ); } else { $theme_json['settings'] = $sanitized['settings']; } return $theme_json; } ``` | Uses | Description | | --- | --- | | [WP\_Theme\_JSON\_Schema::migrate()](../wp_theme_json_schema/migrate) wp-includes/class-wp-theme-json-schema.php | Function that migrates a given theme.json structure to the last version. | | [\_wp\_array\_set()](../../functions/_wp_array_set) wp-includes/functions.php | Sets an array in depth based on a path of keys. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | Used By | Description | | --- | --- | | [wp\_filter\_global\_styles\_post()](../../functions/wp_filter_global_styles_post) wp-includes/kses.php | Sanitizes global styles user content removing unsafe rules. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON::get_style_nodes( array $theme_json, array $selectors = array() ): array WP\_Theme\_JSON::get\_style\_nodes( array $theme\_json, array $selectors = array() ): array =========================================================================================== Builds metadata for the style nodes, which returns in the form of: [ [ ‘path’ => [ ‘path’, ‘to’, ‘some’, ‘node’ ], ‘selector’ => ‘CSS selector for some node’, ‘duotone’ => ‘CSS selector for duotone for some node’ ], [ ‘path’ => [‘path’, ‘to’, ‘other’, ‘node’ ], ‘selector’ => ‘CSS selector for other node’, ‘duotone’ => null ], ] `$theme_json` array Required The tree to extract style nodes from. `$selectors` array Optional List of selectors per block. Default: `array()` array An array of style nodes metadata. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function get_style_nodes( $theme_json, $selectors = array() ) { $nodes = array(); if ( ! isset( $theme_json['styles'] ) ) { return $nodes; } // Top-level. $nodes[] = array( 'path' => array( 'styles' ), 'selector' => static::ROOT_BLOCK_SELECTOR, ); if ( isset( $theme_json['styles']['elements'] ) ) { foreach ( self::ELEMENTS as $element => $selector ) { if ( ! isset( $theme_json['styles']['elements'][ $element ] ) ) { continue; } $nodes[] = array( 'path' => array( 'styles', 'elements', $element ), 'selector' => static::ELEMENTS[ $element ], ); // Handle any pseudo selectors for the element. if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { if ( isset( $theme_json['styles']['elements'][ $element ][ $pseudo_selector ] ) ) { $nodes[] = array( 'path' => array( 'styles', 'elements', $element ), 'selector' => static::append_to_selector( static::ELEMENTS[ $element ], $pseudo_selector ), ); } } } } } // Blocks. if ( ! isset( $theme_json['styles']['blocks'] ) ) { return $nodes; } $nodes = array_merge( $nodes, static::get_block_nodes( $theme_json ) ); /** * Filters the list of style nodes with metadata. * * This allows for things like loading block CSS independently. * * @since 6.1.0 * * @param array $nodes Style nodes with metadata. */ return apply_filters( 'wp_theme_json_get_style_nodes', $nodes ); } ``` [apply\_filters( 'wp\_theme\_json\_get\_style\_nodes', array $nodes )](../../hooks/wp_theme_json_get_style_nodes) Filters the list of style nodes with metadata. | Uses | Description | | --- | --- | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON::append_to_selector( string $selector, string $to_append, string $position = 'right' ): string WP\_Theme\_JSON::append\_to\_selector( string $selector, string $to\_append, string $position = 'right' ): string ================================================================================================================= Appends a sub-selector to an existing one. Given the compounded $selector "h1, h2, h3" and the $to\_append selector ".some-class" the result will be "h1.some-class, h2.some-class, h3.some-class". `$selector` string Required Original selector. `$to_append` string Required Selector to append. `$position` string Optional A position sub-selector should be appended. Default `'right'`. Default: `'right'` string The new selector. File: `wp-includes/class-wp-theme-json.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/) ``` protected static function append_to_selector( $selector, $to_append, $position = 'right' ) { $new_selectors = array(); $selectors = explode( ',', $selector ); foreach ( $selectors as $sel ) { $new_selectors[] = 'right' === $position ? $sel . $to_append : $to_append . $sel; } return implode( ',', $new_selectors ); } ``` | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added append position. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress POMO_FileReader::read( int $bytes ): string|false POMO\_FileReader::read( int $bytes ): string|false ================================================== `$bytes` int Required string|false Returns read string, otherwise false. File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function read( $bytes ) { return fread( $this->_f, $bytes ); } ``` wordpress POMO_FileReader::seekto( int $pos ): bool POMO\_FileReader::seekto( int $pos ): bool ========================================== `$pos` int Required bool File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function seekto( $pos ) { if ( -1 == fseek( $this->_f, $pos, SEEK_SET ) ) { return false; } $this->_pos = $pos; return true; } ``` wordpress POMO_FileReader::is_resource(): bool POMO\_FileReader::is\_resource(): bool ====================================== bool File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function is_resource() { return is_resource( $this->_f ); } ``` wordpress POMO_FileReader::feof(): bool POMO\_FileReader::feof(): bool ============================== bool File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function feof() { return feof( $this->_f ); } ``` wordpress POMO_FileReader::read_all(): string POMO\_FileReader::read\_all(): string ===================================== string File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function read_all() { return stream_get_contents( $this->_f ); } ``` wordpress POMO_FileReader::POMO_FileReader( $filename ) POMO\_FileReader::POMO\_FileReader( $filename ) =============================================== This method has been deprecated. Use [POMO\_FileReader::\_\_construct()](../pomo_filereader/__construct) instead. PHP4 constructor. * [POMO\_FileReader::\_\_construct()](../pomo_filereader/__construct) File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function POMO_FileReader( $filename ) { _deprecated_constructor( self::class, '5.4.0', static::class ); self::__construct( $filename ); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_constructor()](../../functions/_deprecated_constructor) wp-includes/functions.php | Marks a constructor as deprecated and informs when it has been used. | | [POMO\_FileReader::\_\_construct()](__construct) wp-includes/pomo/streams.php | | | Version | Description | | --- | --- | | [5.4.0](https://developer.wordpress.org/reference/since/5.4.0/) | Introduced. | wordpress POMO_FileReader::close(): bool POMO\_FileReader::close(): bool =============================== bool File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function close() { return fclose( $this->_f ); } ``` wordpress POMO_FileReader::__construct( string $filename ) POMO\_FileReader::\_\_construct( string $filename ) =================================================== `$filename` string Required File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function __construct( $filename ) { parent::__construct(); $this->_f = fopen( $filename, 'rb' ); } ``` | Uses | Description | | --- | --- | | [POMO\_Reader::\_\_construct()](../pomo_reader/__construct) wp-includes/pomo/streams.php | PHP5 constructor. | | Used By | Description | | --- | --- | | [POMO\_FileReader::POMO\_FileReader()](pomo_filereader) wp-includes/pomo/streams.php | PHP4 constructor. | | [MO::import\_from\_file()](../mo/import_from_file) wp-includes/pomo/mo.php | Fills up with the entries from MO file $filename | wordpress Bulk_Upgrader_Skin::reset() Bulk\_Upgrader\_Skin::reset() ============================= File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function reset() { $this->in_loop = false; $this->error = false; } ``` | Used By | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::after()](after) wp-admin/includes/class-bulk-upgrader-skin.php | | wordpress Bulk_Upgrader_Skin::feedback( string $feedback, mixed $args ) Bulk\_Upgrader\_Skin::feedback( string $feedback, mixed $args ) =============================================================== `$feedback` string Required Message data. `$args` mixed Optional text replacements. File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function feedback( $feedback, ...$args ) { if ( isset( $this->upgrader->strings[ $feedback ] ) ) { $feedback = $this->upgrader->strings[ $feedback ]; } if ( strpos( $feedback, '%' ) !== false ) { if ( $args ) { $args = array_map( 'strip_tags', $args ); $args = array_map( 'esc_html', $args ); $feedback = vsprintf( $feedback, $args ); } } if ( empty( $feedback ) ) { return; } if ( $this->in_loop ) { echo "$feedback<br />\n"; } else { echo "<p>$feedback</p>\n"; } } ``` | Used By | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::bulk\_header()](bulk_header) wp-admin/includes/class-bulk-upgrader-skin.php | | | [Bulk\_Upgrader\_Skin::bulk\_footer()](bulk_footer) wp-admin/includes/class-bulk-upgrader-skin.php | | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress Bulk_Upgrader_Skin::after( string $title = '' ) Bulk\_Upgrader\_Skin::after( string $title = '' ) ================================================= `$title` string Optional Default: `''` File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function after( $title = '' ) { echo '</p></div>'; if ( $this->error || ! $this->result ) { if ( $this->error ) { echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed_error'], $title, '<strong>' . $this->error . '</strong>' ) . '</p></div>'; } else { echo '<div class="error"><p>' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '</p></div>'; } echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();</script>'; } if ( $this->result && ! is_wp_error( $this->result ) ) { if ( ! $this->error ) { echo '<div class="updated js-update-details" data-update-details="progress-' . esc_attr( $this->upgrader->update_current ) . '">' . '<p>' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) . ' <button type="button" class="hide-if-no-js button-link js-update-details-toggle" aria-expanded="false">' . __( 'Show details.' ) . '</button>' . '</p></div>'; } echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>'; } $this->reset(); $this->flush_output(); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::reset()](reset) wp-admin/includes/class-bulk-upgrader-skin.php | | | [Bulk\_Upgrader\_Skin::flush\_output()](flush_output) wp-admin/includes/class-bulk-upgrader-skin.php | | | [esc\_js()](../../functions/esc_js) wp-includes/formatting.php | Escapes single quotes, `"`, , `&amp;`, and fixes line endings. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [Bulk\_Theme\_Upgrader\_Skin::after()](../bulk_theme_upgrader_skin/after) wp-admin/includes/class-bulk-theme-upgrader-skin.php | | | [Bulk\_Plugin\_Upgrader\_Skin::after()](../bulk_plugin_upgrader_skin/after) wp-admin/includes/class-bulk-plugin-upgrader-skin.php | | wordpress Bulk_Upgrader_Skin::__construct( array $args = array() ) Bulk\_Upgrader\_Skin::\_\_construct( array $args = array() ) ============================================================ `$args` array Optional Default: `array()` File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function __construct( $args = array() ) { $defaults = array( 'url' => '', 'nonce' => '', ); $args = wp_parse_args( $args, $defaults ); parent::__construct( $args ); } ``` | Uses | Description | | --- | --- | | [WP\_Upgrader\_Skin::\_\_construct()](../wp_upgrader_skin/__construct) wp-admin/includes/class-wp-upgrader-skin.php | Constructor. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | wordpress Bulk_Upgrader_Skin::footer() Bulk\_Upgrader\_Skin::footer() ============================== File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function footer() { // Nothing, This will be displayed within a iframe. } ```
programming_docs
wordpress Bulk_Upgrader_Skin::bulk_header() Bulk\_Upgrader\_Skin::bulk\_header() ==================================== File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function bulk_header() { $this->feedback( 'skin_upgrade_start' ); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::feedback()](feedback) wp-admin/includes/class-bulk-upgrader-skin.php | | wordpress Bulk_Upgrader_Skin::header() Bulk\_Upgrader\_Skin::header() ============================== File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function header() { // Nothing, This will be displayed within a iframe. } ``` wordpress Bulk_Upgrader_Skin::error( string|WP_Error $errors ) Bulk\_Upgrader\_Skin::error( string|WP\_Error $errors ) ======================================================= `$errors` string|[WP\_Error](../wp_error) Required Errors. File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function error( $errors ) { if ( is_string( $errors ) && isset( $this->upgrader->strings[ $errors ] ) ) { $this->error = $this->upgrader->strings[ $errors ]; } if ( is_wp_error( $errors ) ) { $messages = array(); foreach ( $errors->get_error_messages() as $emessage ) { if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) { $messages[] = $emessage . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ); } else { $messages[] = $emessage; } } $this->error = implode( ', ', $messages ); } echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();</script>'; } ``` | Uses | Description | | --- | --- | | [esc\_js()](../../functions/esc_js) wp-includes/formatting.php | Escapes single quotes, `"`, , `&amp;`, and fixes line endings. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress Bulk_Upgrader_Skin::add_strings() Bulk\_Upgrader\_Skin::add\_strings() ==================================== File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function add_strings() { $this->upgrader->strings['skin_upgrade_start'] = __( 'The update process is starting. This process may take a while on some hosts, so please be patient.' ); /* translators: 1: Title of an update, 2: Error message. */ $this->upgrader->strings['skin_update_failed_error'] = __( 'An error occurred while updating %1$s: %2$s' ); /* translators: %s: Title of an update. */ $this->upgrader->strings['skin_update_failed'] = __( 'The update of %s failed.' ); /* translators: %s: Title of an update. */ $this->upgrader->strings['skin_update_successful'] = __( '%s updated successfully.' ); $this->upgrader->strings['skin_upgrade_end'] = __( 'All updates have been completed.' ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [Bulk\_Theme\_Upgrader\_Skin::add\_strings()](../bulk_theme_upgrader_skin/add_strings) wp-admin/includes/class-bulk-theme-upgrader-skin.php | | | [Bulk\_Plugin\_Upgrader\_Skin::add\_strings()](../bulk_plugin_upgrader_skin/add_strings) wp-admin/includes/class-bulk-plugin-upgrader-skin.php | | wordpress Bulk_Upgrader_Skin::bulk_footer() Bulk\_Upgrader\_Skin::bulk\_footer() ==================================== File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function bulk_footer() { $this->feedback( 'skin_upgrade_end' ); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::feedback()](feedback) wp-admin/includes/class-bulk-upgrader-skin.php | | | Used By | Description | | --- | --- | | [Bulk\_Theme\_Upgrader\_Skin::bulk\_footer()](../bulk_theme_upgrader_skin/bulk_footer) wp-admin/includes/class-bulk-theme-upgrader-skin.php | | | [Bulk\_Plugin\_Upgrader\_Skin::bulk\_footer()](../bulk_plugin_upgrader_skin/bulk_footer) wp-admin/includes/class-bulk-plugin-upgrader-skin.php | | wordpress Bulk_Upgrader_Skin::before( string $title = '' ) Bulk\_Upgrader\_Skin::before( string $title = '' ) ================================================== `$title` string Optional Default: `''` File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function before( $title = '' ) { $this->in_loop = true; printf( '<h2>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h2>', $title, $this->upgrader->update_current, $this->upgrader->update_count ); echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");</script>'; // This progress messages div gets moved via JavaScript when clicking on "Show details.". echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr( $this->upgrader->update_current ) . '"><p>'; $this->flush_output(); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::flush\_output()](flush_output) wp-admin/includes/class-bulk-upgrader-skin.php | | | [esc\_js()](../../functions/esc_js) wp-includes/formatting.php | Escapes single quotes, `"`, , `&amp;`, and fixes line endings. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Used By | Description | | --- | --- | | [Bulk\_Theme\_Upgrader\_Skin::before()](../bulk_theme_upgrader_skin/before) wp-admin/includes/class-bulk-theme-upgrader-skin.php | | | [Bulk\_Plugin\_Upgrader\_Skin::before()](../bulk_plugin_upgrader_skin/before) wp-admin/includes/class-bulk-plugin-upgrader-skin.php | | wordpress Bulk_Upgrader_Skin::flush_output() Bulk\_Upgrader\_Skin::flush\_output() ===================================== File: `wp-admin/includes/class-bulk-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-upgrader-skin.php/) ``` public function flush_output() { wp_ob_end_flush_all(); flush(); } ``` | Uses | Description | | --- | --- | | [wp\_ob\_end\_flush\_all()](../../functions/wp_ob_end_flush_all) wp-includes/functions.php | Flushes all output buffers for PHP 5.2. | | Used By | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::before()](before) wp-admin/includes/class-bulk-upgrader-skin.php | | | [Bulk\_Upgrader\_Skin::after()](after) wp-admin/includes/class-bulk-upgrader-skin.php | | wordpress WP_Customize_Header_Image_Setting::update( mixed $value ) WP\_Customize\_Header\_Image\_Setting::update( mixed $value ) ============================================================= `$value` mixed Required The value to update. File: `wp-includes/customize/class-wp-customize-header-image-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-header-image-setting.php/) ``` public function update( $value ) { global $custom_image_header; // If _custom_header_background_just_in_time() fails to initialize $custom_image_header when not is_admin(). if ( empty( $custom_image_header ) ) { require_once ABSPATH . 'wp-admin/includes/class-custom-image-header.php'; $args = get_theme_support( 'custom-header' ); $admin_head_callback = isset( $args[0]['admin-head-callback'] ) ? $args[0]['admin-head-callback'] : null; $admin_preview_callback = isset( $args[0]['admin-preview-callback'] ) ? $args[0]['admin-preview-callback'] : null; $custom_image_header = new Custom_Image_Header( $admin_head_callback, $admin_preview_callback ); } // If the value doesn't exist (removed or random), // use the header_image value. if ( ! $value ) { $value = $this->manager->get_setting( 'header_image' )->post_value(); } if ( is_array( $value ) && isset( $value['choice'] ) ) { $custom_image_header->set_header_image( $value['choice'] ); } else { $custom_image_header->set_header_image( $value ); } } ``` | Uses | Description | | --- | --- | | [Custom\_Image\_Header::set\_header\_image()](../custom_image_header/set_header_image) wp-admin/includes/class-custom-image-header.php | Choose a header image, selected from existing uploaded and default headers, or provide an array of uploaded header data (either new, or from media library). | | [Custom\_Image\_Header::\_\_construct()](../custom_image_header/__construct) wp-admin/includes/class-custom-image-header.php | Constructor – Register administration header callback. | | [get\_theme\_support()](../../functions/get_theme_support) wp-includes/theme.php | Gets the theme support arguments passed when registering that support. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress Bulk_Plugin_Upgrader_Skin::after( string $title = '' ) Bulk\_Plugin\_Upgrader\_Skin::after( string $title = '' ) ========================================================= `$title` string Optional Default: `''` File: `wp-admin/includes/class-bulk-plugin-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-plugin-upgrader-skin.php/) ``` public function after( $title = '' ) { parent::after( $this->plugin_info['Title'] ); $this->decrement_update_count( 'plugin' ); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::after()](../bulk_upgrader_skin/after) wp-admin/includes/class-bulk-upgrader-skin.php | | wordpress Bulk_Plugin_Upgrader_Skin::add_strings() Bulk\_Plugin\_Upgrader\_Skin::add\_strings() ============================================ File: `wp-admin/includes/class-bulk-plugin-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-plugin-upgrader-skin.php/) ``` public function add_strings() { parent::add_strings(); /* translators: 1: Plugin name, 2: Number of the plugin, 3: Total number of plugins being updated. */ $this->upgrader->strings['skin_before_update_header'] = __( 'Updating Plugin %1$s (%2$d/%3$d)' ); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::add\_strings()](../bulk_upgrader_skin/add_strings) wp-admin/includes/class-bulk-upgrader-skin.php | | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | wordpress Bulk_Plugin_Upgrader_Skin::bulk_footer() Bulk\_Plugin\_Upgrader\_Skin::bulk\_footer() ============================================ File: `wp-admin/includes/class-bulk-plugin-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-plugin-upgrader-skin.php/) ``` public function bulk_footer() { parent::bulk_footer(); $update_actions = array( 'plugins_page' => sprintf( '<a href="%s" target="_parent">%s</a>', self_admin_url( 'plugins.php' ), __( 'Go to Plugins page' ) ), 'updates_page' => sprintf( '<a href="%s" target="_parent">%s</a>', self_admin_url( 'update-core.php' ), __( 'Go to WordPress Updates page' ) ), ); if ( ! current_user_can( 'activate_plugins' ) ) { unset( $update_actions['plugins_page'] ); } /** * Filters the list of action links available following bulk plugin updates. * * @since 3.0.0 * * @param string[] $update_actions Array of plugin action links. * @param array $plugin_info Array of information for the last-updated plugin. */ $update_actions = apply_filters( 'update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info ); if ( ! empty( $update_actions ) ) { $this->feedback( implode( ' | ', (array) $update_actions ) ); } } ``` [apply\_filters( 'update\_bulk\_plugins\_complete\_actions', string[] $update\_actions, array $plugin\_info )](../../hooks/update_bulk_plugins_complete_actions) Filters the list of action links available following bulk plugin updates. | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::bulk\_footer()](../bulk_upgrader_skin/bulk_footer) wp-admin/includes/class-bulk-upgrader-skin.php | | | [self\_admin\_url()](../../functions/self_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for either the current site or the network depending on context. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | wordpress Bulk_Plugin_Upgrader_Skin::before( string $title = '' ) Bulk\_Plugin\_Upgrader\_Skin::before( string $title = '' ) ========================================================== `$title` string Optional Default: `''` File: `wp-admin/includes/class-bulk-plugin-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-plugin-upgrader-skin.php/) ``` public function before( $title = '' ) { parent::before( $this->plugin_info['Title'] ); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::before()](../bulk_upgrader_skin/before) wp-admin/includes/class-bulk-upgrader-skin.php | | wordpress Requests_Response::is_redirect(): boolean Requests\_Response::is\_redirect(): boolean =========================================== Is the response a redirect? boolean True if redirect (3xx status), false if not. File: `wp-includes/Requests/Response.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/response.php/) ``` public function is_redirect() { $code = $this->status_code; return in_array($code, array(300, 301, 302, 303, 307), true) || $code > 307 && $code < 400; } ``` | Used By | Description | | --- | --- | | [Requests\_Response::throw\_for\_status()](throw_for_status) wp-includes/Requests/Response.php | Throws an exception if the request was not successful | wordpress Requests_Response::throw_for_status( boolean $allow_redirects = true ) Requests\_Response::throw\_for\_status( boolean $allow\_redirects = true ) ========================================================================== Throws an exception if the request was not successful `$allow_redirects` boolean Optional Set to false to throw on a 3xx as well Default: `true` File: `wp-includes/Requests/Response.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/response.php/) ``` public function throw_for_status($allow_redirects = true) { if ($this->is_redirect()) { if (!$allow_redirects) { throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this); } } elseif (!$this->success) { $exception = Requests_Exception_HTTP::get_class($this->status_code); throw new $exception(null, $this); } } ``` | Uses | Description | | --- | --- | | [Requests\_Exception\_HTTP::get\_class()](../requests_exception_http/get_class) wp-includes/Requests/Exception/HTTP.php | Get the correct exception class for a given error code | | [Requests\_Response::is\_redirect()](is_redirect) wp-includes/Requests/Response.php | Is the response a redirect? | | [Requests\_Exception::\_\_construct()](../requests_exception/__construct) wp-includes/Requests/Exception.php | Create a new exception | wordpress Requests_Response::__construct() Requests\_Response::\_\_construct() =================================== Constructor File: `wp-includes/Requests/Response.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/response.php/) ``` public function __construct() { $this->headers = new Requests_Response_Headers(); $this->cookies = new Requests_Cookie_Jar(); } ``` | Uses | Description | | --- | --- | | [Requests\_Cookie\_Jar::\_\_construct()](../requests_cookie_jar/__construct) wp-includes/Requests/Cookie/Jar.php | Create a new jar | | Used By | Description | | --- | --- | | [Requests::parse\_response()](../requests/parse_response) wp-includes/class-requests.php | HTTP response parser | wordpress WP_Customize_Media_Control::content_template() WP\_Customize\_Media\_Control::content\_template() ================================================== Render a JS template for the content of the media control. File: `wp-includes/customize/class-wp-customize-media-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-media-control.php/) ``` public function content_template() { ?> <# var descriptionId = _.uniqueId( 'customize-media-control-description-' ); var describedByAttr = data.description ? ' aria-describedby="' + descriptionId + '" ' : ''; #> <# if ( data.label ) { #> <span class="customize-control-title">{{ data.label }}</span> <# } #> <div class="customize-control-notifications-container"></div> <# if ( data.description ) { #> <span id="{{ descriptionId }}" class="description customize-control-description">{{{ data.description }}}</span> <# } #> <# if ( data.attachment && data.attachment.id ) { #> <div class="attachment-media-view attachment-media-view-{{ data.attachment.type }} {{ data.attachment.orientation }}"> <div class="thumbnail thumbnail-{{ data.attachment.type }}"> <# if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.medium ) { #> <img class="attachment-thumb" src="{{ data.attachment.sizes.medium.url }}" draggable="false" alt="" /> <# } else if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.full ) { #> <img class="attachment-thumb" src="{{ data.attachment.sizes.full.url }}" draggable="false" alt="" /> <# } else if ( 'audio' === data.attachment.type ) { #> <# if ( data.attachment.image && data.attachment.image.src && data.attachment.image.src !== data.attachment.icon ) { #> <img src="{{ data.attachment.image.src }}" class="thumbnail" draggable="false" alt="" /> <# } else { #> <img src="{{ data.attachment.icon }}" class="attachment-thumb type-icon" draggable="false" alt="" /> <# } #> <p class="attachment-meta attachment-meta-title">&#8220;{{ data.attachment.title }}&#8221;</p> <# if ( data.attachment.album || data.attachment.meta.album ) { #> <p class="attachment-meta"><em>{{ data.attachment.album || data.attachment.meta.album }}</em></p> <# } #> <# if ( data.attachment.artist || data.attachment.meta.artist ) { #> <p class="attachment-meta">{{ data.attachment.artist || data.attachment.meta.artist }}</p> <# } #> <audio style="visibility: hidden" controls class="wp-audio-shortcode" width="100%" preload="none"> <source type="{{ data.attachment.mime }}" src="{{ data.attachment.url }}" /> </audio> <# } else if ( 'video' === data.attachment.type ) { #> <div class="wp-media-wrapper wp-video"> <video controls="controls" class="wp-video-shortcode" preload="metadata" <# if ( data.attachment.image && data.attachment.image.src !== data.attachment.icon ) { #>poster="{{ data.attachment.image.src }}"<# } #>> <source type="{{ data.attachment.mime }}" src="{{ data.attachment.url }}" /> </video> </div> <# } else { #> <img class="attachment-thumb type-icon icon" src="{{ data.attachment.icon }}" draggable="false" alt="" /> <p class="attachment-title">{{ data.attachment.title }}</p> <# } #> </div> <div class="actions"> <# if ( data.canUpload ) { #> <button type="button" class="button remove-button">{{ data.button_labels.remove }}</button> <button type="button" class="button upload-button control-focus" {{{ describedByAttr }}}>{{ data.button_labels.change }}</button> <# } #> </div> </div> <# } else { #> <div class="attachment-media-view"> <# if ( data.canUpload ) { #> <button type="button" class="upload-button button-add-media" {{{ describedByAttr }}}>{{ data.button_labels.select }}</button> <# } #> <div class="actions"> <# if ( data.defaultAttachment ) { #> <button type="button" class="button default-button">{{ data.button_labels['default'] }}</button> <# } #> </div> </div> <# } #> <?php } ``` | Version | Description | | --- | --- | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Moved from [WP\_Customize\_Upload\_Control](../wp_customize_upload_control). | | [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | Introduced. |
programming_docs
wordpress WP_Customize_Media_Control::to_json() WP\_Customize\_Media\_Control::to\_json() ========================================= Refresh the parameters passed to the JavaScript via JSON. * [WP\_Customize\_Control::to\_json()](../wp_customize_control/to_json) File: `wp-includes/customize/class-wp-customize-media-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-media-control.php/) ``` public function to_json() { parent::to_json(); $this->json['label'] = html_entity_decode( $this->label, ENT_QUOTES, get_bloginfo( 'charset' ) ); $this->json['mime_type'] = $this->mime_type; $this->json['button_labels'] = $this->button_labels; $this->json['canUpload'] = current_user_can( 'upload_files' ); $value = $this->value(); if ( is_object( $this->setting ) ) { if ( $this->setting->default ) { // Fake an attachment model - needs all fields used by template. // Note that the default value must be a URL, NOT an attachment ID. $ext = substr( $this->setting->default, -3 ); $type = in_array( $ext, array( 'jpg', 'png', 'gif', 'bmp', 'webp' ), true ) ? 'image' : 'document'; $default_attachment = array( 'id' => 1, 'url' => $this->setting->default, 'type' => $type, 'icon' => wp_mime_type_icon( $type ), 'title' => wp_basename( $this->setting->default ), ); if ( 'image' === $type ) { $default_attachment['sizes'] = array( 'full' => array( 'url' => $this->setting->default ), ); } $this->json['defaultAttachment'] = $default_attachment; } if ( $value && $this->setting->default && $value === $this->setting->default ) { // Set the default as the attachment. $this->json['attachment'] = $this->json['defaultAttachment']; } elseif ( $value ) { $this->json['attachment'] = wp_prepare_attachment_for_js( $value ); } } } ``` | Uses | Description | | --- | --- | | [wp\_prepare\_attachment\_for\_js()](../../functions/wp_prepare_attachment_for_js) wp-includes/media.php | Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model. | | [wp\_mime\_type\_icon()](../../functions/wp_mime_type_icon) wp-includes/post.php | Retrieves the icon for a MIME type or attachment. | | [WP\_Customize\_Control::to\_json()](../wp_customize_control/to_json) wp-includes/class-wp-customize-control.php | Refresh the parameters passed to the JavaScript via JSON. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [wp\_basename()](../../functions/wp_basename) wp-includes/formatting.php | i18n-friendly version of basename(). | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | Used By | Description | | --- | --- | | [WP\_Customize\_Upload\_Control::to\_json()](../wp_customize_upload_control/to_json) wp-includes/customize/class-wp-customize-upload-control.php | Refresh the parameters passed to the JavaScript via JSON. | | Version | Description | | --- | --- | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Moved from [WP\_Customize\_Upload\_Control](../wp_customize_upload_control). | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Media_Control::get_default_button_labels(): string[] WP\_Customize\_Media\_Control::get\_default\_button\_labels(): string[] ======================================================================= Get default button labels. Provides an array of the default button labels based on the mime type of the current control. string[] An associative array of default button labels keyed by the button name. File: `wp-includes/customize/class-wp-customize-media-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-media-control.php/) ``` public function get_default_button_labels() { // Get just the mime type and strip the mime subtype if present. $mime_type = ! empty( $this->mime_type ) ? strtok( ltrim( $this->mime_type, '/' ), '/' ) : 'default'; switch ( $mime_type ) { case 'video': return array( 'select' => __( 'Select video' ), 'change' => __( 'Change video' ), 'default' => __( 'Default' ), 'remove' => __( 'Remove' ), 'placeholder' => __( 'No video selected' ), 'frame_title' => __( 'Select video' ), 'frame_button' => __( 'Choose video' ), ); case 'audio': return array( 'select' => __( 'Select audio' ), 'change' => __( 'Change audio' ), 'default' => __( 'Default' ), 'remove' => __( 'Remove' ), 'placeholder' => __( 'No audio selected' ), 'frame_title' => __( 'Select audio' ), 'frame_button' => __( 'Choose audio' ), ); case 'image': return array( 'select' => __( 'Select image' ), 'site_icon' => __( 'Select site icon' ), 'change' => __( 'Change image' ), 'default' => __( 'Default' ), 'remove' => __( 'Remove' ), 'placeholder' => __( 'No image selected' ), 'frame_title' => __( 'Select image' ), 'frame_button' => __( 'Choose image' ), ); default: return array( 'select' => __( 'Select file' ), 'change' => __( 'Change file' ), 'default' => __( 'Default' ), 'remove' => __( 'Remove' ), 'placeholder' => __( 'No file selected' ), 'frame_title' => __( 'Select file' ), 'frame_button' => __( 'Choose file' ), ); } // End switch(). } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_Customize\_Media\_Control::\_\_construct()](__construct) wp-includes/customize/class-wp-customize-media-control.php | Constructor. | | Version | Description | | --- | --- | | [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced. | wordpress WP_Customize_Media_Control::__construct( WP_Customize_Manager $manager, string $id, array $args = array() ) WP\_Customize\_Media\_Control::\_\_construct( WP\_Customize\_Manager $manager, string $id, array $args = array() ) ================================================================================================================== Constructor. * [WP\_Customize\_Control::\_\_construct()](../wp_customize_control/__construct) `$manager` [WP\_Customize\_Manager](../wp_customize_manager) Required Customizer bootstrap instance. `$id` string Required Control ID. `$args` array Optional Arguments to override class property defaults. See [WP\_Customize\_Control::\_\_construct()](../wp_customize_control/__construct) for information on accepted arguments. More Arguments from WP\_Customize\_Control::\_\_construct( ... $args ) Array of properties for the new Control object. * `instance_number`intOrder in which this instance was created in relation to other instances. * `manager`[WP\_Customize\_Manager](../wp_customize_manager)Customizer bootstrap instance. * `id`stringControl ID. * `settings`arrayAll settings tied to the control. If undefined, `$id` will be used. * `setting`stringThe primary setting for the control (if there is one). Default `'default'`. * `capability`stringCapability required to use this control. Normally this is empty and the capability is derived from `$settings`. * `priority`intOrder priority to load the control. Default 10. * `section`stringSection the control belongs to. * `label`stringLabel for the control. * `description`stringDescription for the control. * `choices`arrayList of choices for `'radio'` or `'select'` type controls, where values are the keys, and labels are the values. * `input_attrs`arrayList of custom input attributes for control output, where attribute names are the keys and values are the values. Not used for `'checkbox'`, `'radio'`, `'select'`, `'textarea'`, or `'dropdown-pages'` control types. * `allow_addition`boolShow UI for adding new content, currently only used for the dropdown-pages control. Default false. * `json`arrayDeprecated. Use [WP\_Customize\_Control::json()](../wp_customize_control/json) instead. * `type`stringControl type. Core controls include `'text'`, `'checkbox'`, `'textarea'`, `'radio'`, `'select'`, and `'dropdown-pages'`. Additional input types such as `'email'`, `'url'`, `'number'`, `'hidden'`, and `'date'` are supported implicitly. Default `'text'`. * `active_callback`callableActive callback. Default: `array()` File: `wp-includes/customize/class-wp-customize-media-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-media-control.php/) ``` public function __construct( $manager, $id, $args = array() ) { parent::__construct( $manager, $id, $args ); $this->button_labels = wp_parse_args( $this->button_labels, $this->get_default_button_labels() ); } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Media\_Control::get\_default\_button\_labels()](get_default_button_labels) wp-includes/customize/class-wp-customize-media-control.php | Get default button labels. | | [WP\_Customize\_Control::\_\_construct()](../wp_customize_control/__construct) wp-includes/class-wp-customize-control.php | Constructor. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Used By | Description | | --- | --- | | [WP\_Customize\_Manager::register\_controls()](../wp_customize_manager/register_controls) wp-includes/class-wp-customize-manager.php | Registers some default controls. | | Version | Description | | --- | --- | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Moved from [WP\_Customize\_Upload\_Control](../wp_customize_upload_control). | | [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | Introduced. | wordpress WP_Customize_Media_Control::render_content() WP\_Customize\_Media\_Control::render\_content() ================================================ Don’t render any content for this control from PHP. * [WP\_Customize\_Media\_Control::content\_template()](../wp_customize_media_control/content_template) File: `wp-includes/customize/class-wp-customize-media-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-media-control.php/) ``` public function render_content() {} ``` | Version | Description | | --- | --- | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Moved from [WP\_Customize\_Upload\_Control](../wp_customize_upload_control). | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Media_Control::enqueue() WP\_Customize\_Media\_Control::enqueue() ======================================== Enqueue control related scripts/styles. File: `wp-includes/customize/class-wp-customize-media-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-media-control.php/) ``` public function enqueue() { wp_enqueue_media(); } ``` | Uses | Description | | --- | --- | | [wp\_enqueue\_media()](../../functions/wp_enqueue_media) wp-includes/media.php | Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs. | | Version | Description | | --- | --- | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Moved from [WP\_Customize\_Upload\_Control](../wp_customize_upload_control). | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Dependencies::recurse_deps( string[] $queue, string $handle ): bool WP\_Dependencies::recurse\_deps( string[] $queue, string $handle ): bool ======================================================================== Recursively search the passed dependency tree for a handle. `$queue` string[] Required An array of queued [\_WP\_Dependency](../_wp_dependency) handles. `$handle` string Required Name of the item. Should be unique. bool Whether the handle is found after recursively searching the dependency tree. File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` protected function recurse_deps( $queue, $handle ) { if ( isset( $this->all_queued_deps ) ) { return isset( $this->all_queued_deps[ $handle ] ); } $all_deps = array_fill_keys( $queue, true ); $queues = array(); $done = array(); while ( $queue ) { foreach ( $queue as $queued ) { if ( ! isset( $done[ $queued ] ) && isset( $this->registered[ $queued ] ) ) { $deps = $this->registered[ $queued ]->deps; if ( $deps ) { $all_deps += array_fill_keys( $deps, true ); array_push( $queues, $deps ); } $done[ $queued ] = true; } } $queue = array_pop( $queues ); } $this->all_queued_deps = $all_deps; return isset( $this->all_queued_deps[ $handle ] ); } ``` | Used By | Description | | --- | --- | | [WP\_Dependencies::query()](query) wp-includes/class-wp-dependencies.php | Query the list for an item. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Dependencies::do_items( string|string[]|false $handles = false, int|false $group = false ): string[] WP\_Dependencies::do\_items( string|string[]|false $handles = false, int|false $group = false ): string[] ========================================================================================================= Processes the items and dependencies. Processes the items passed to it or the queue, and their dependencies. `$handles` string|string[]|false Optional Items to be processed: queue (false), single item (string), or multiple items (array of strings). Default: `false` `$group` int|false Optional Group level: level (int), no group (false). Default: `false` string[] Array of handles of items that have been processed. File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function do_items( $handles = false, $group = false ) { /* * If nothing is passed, print the queue. If a string is passed, * print that item. If an array is passed, print those items. */ $handles = false === $handles ? $this->queue : (array) $handles; $this->all_deps( $handles ); foreach ( $this->to_do as $key => $handle ) { if ( ! in_array( $handle, $this->done, true ) && isset( $this->registered[ $handle ] ) ) { /* * Attempt to process the item. If successful, * add the handle to the done array. * * Unset the item from the to_do array. */ if ( $this->do_item( $handle, $group ) ) { $this->done[] = $handle; } unset( $this->to_do[ $key ] ); } } return $this->done; } ``` | Uses | Description | | --- | --- | | [WP\_Dependencies::all\_deps()](all_deps) wp-includes/class-wp-dependencies.php | Determines dependencies. | | [WP\_Dependencies::do\_item()](do_item) wp-includes/class-wp-dependencies.php | Processes a dependency. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Added the `$group` parameter. | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Introduced. | wordpress WP_Dependencies::add( string $handle, string|false $src, string[] $deps = array(), string|bool|null $ver = false, mixed $args = null ): bool WP\_Dependencies::add( string $handle, string|false $src, string[] $deps = array(), string|bool|null $ver = false, mixed $args = null ): bool ============================================================================================================================================= Register an item. Registers the item if no item of that name already exists. `$handle` string Required Name of the item. Should be unique. `$src` string|false Required Full URL of the item, or path of the item relative to the WordPress root directory. If source is set to false, item is an alias of other items it depends on. `$deps` string[] Optional An array of registered item handles this item depends on. Default: `array()` `$ver` string|bool|null Optional String specifying item version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added. Default: `false` `$args` mixed Optional Custom property of the item. NOT the class property $args. Examples: $media, $in\_footer. Default: `null` bool Whether the item has been registered. True on success, false on failure. File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) { if ( isset( $this->registered[ $handle ] ) ) { return false; } $this->registered[ $handle ] = new _WP_Dependency( $handle, $src, $deps, $ver, $args ); // If the item was enqueued before the details were registered, enqueue it now. if ( array_key_exists( $handle, $this->queued_before_register ) ) { if ( ! is_null( $this->queued_before_register[ $handle ] ) ) { $this->enqueue( $handle . '?' . $this->queued_before_register[ $handle ] ); } else { $this->enqueue( $handle ); } unset( $this->queued_before_register[ $handle ] ); } return true; } ``` | Uses | Description | | --- | --- | | [\_WP\_Dependency::\_\_construct()](../_wp_dependency/__construct) wp-includes/class-wp-dependency.php | Setup dependencies. | | [WP\_Dependencies::enqueue()](../wp_dependencies/enqueue) wp-includes/class-wp-dependencies.php | Queue an item or items. | | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Moved from `WP_Scripts`. | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress WP_Dependencies::remove( string|string[] $handles ) WP\_Dependencies::remove( string|string[] $handles ) ==================================================== Un-register an item or items. `$handles` string|string[] Required Item handle (string) or item handles (array of strings). File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function remove( $handles ) { foreach ( (array) $handles as $handle ) { unset( $this->registered[ $handle ] ); } } ``` | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Moved from `WP_Scripts`. | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress WP_Dependencies::all_deps( string|string[] $handles, bool $recursion = false, int|false $group = false ): bool WP\_Dependencies::all\_deps( string|string[] $handles, bool $recursion = false, int|false $group = false ): bool ================================================================================================================ Determines dependencies. Recursively builds an array of items to process taking dependencies into account. Does NOT catch infinite loops. `$handles` string|string[] Required Item handle (string) or item handles (array of strings). `$recursion` bool Optional Internal flag that function is calling itself. Default: `false` `$group` int|false Optional Group level: level (int), no group (false). Default: `false` bool True on success, false on failure. File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function all_deps( $handles, $recursion = false, $group = false ) { $handles = (array) $handles; if ( ! $handles ) { return false; } foreach ( $handles as $handle ) { $handle_parts = explode( '?', $handle ); $handle = $handle_parts[0]; $queued = in_array( $handle, $this->to_do, true ); if ( in_array( $handle, $this->done, true ) ) { // Already done. continue; } $moved = $this->set_group( $handle, $recursion, $group ); $new_group = $this->groups[ $handle ]; if ( $queued && ! $moved ) { // Already queued and in the right group. continue; } $keep_going = true; if ( ! isset( $this->registered[ $handle ] ) ) { $keep_going = false; // Item doesn't exist. } elseif ( $this->registered[ $handle ]->deps && array_diff( $this->registered[ $handle ]->deps, array_keys( $this->registered ) ) ) { $keep_going = false; // Item requires dependencies that don't exist. } elseif ( $this->registered[ $handle ]->deps && ! $this->all_deps( $this->registered[ $handle ]->deps, true, $new_group ) ) { $keep_going = false; // Item requires dependencies that don't exist. } if ( ! $keep_going ) { // Either item or its dependencies don't exist. if ( $recursion ) { return false; // Abort this branch. } else { continue; // We're at the top level. Move on to the next one. } } if ( $queued ) { // Already grabbed it and its dependencies. continue; } if ( isset( $handle_parts[1] ) ) { $this->args[ $handle ] = $handle_parts[1]; } $this->to_do[] = $handle; } return true; } ``` | Uses | Description | | --- | --- | | [WP\_Dependencies::set\_group()](../wp_dependencies/set_group) wp-includes/class-wp-dependencies.php | Set item group, unless already in a lower group. | | [WP\_Dependencies::all\_deps()](../wp_dependencies/all_deps) wp-includes/class-wp-dependencies.php | Determines dependencies. | | Used By | Description | | --- | --- | | [WP\_Styles::all\_deps()](../wp_styles/all_deps) wp-includes/class-wp-styles.php | Determines style dependencies. | | [WP\_Dependencies::do\_items()](../wp_dependencies/do_items) wp-includes/class-wp-dependencies.php | Processes the items and dependencies. | | [WP\_Dependencies::all\_deps()](../wp_dependencies/all_deps) wp-includes/class-wp-dependencies.php | Determines dependencies. | | [WP\_Scripts::all\_deps()](../wp_scripts/all_deps) wp-includes/class-wp-scripts.php | Determines script dependencies. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Added the `$group` parameter. | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Moved from `WP_Scripts`. | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |
programming_docs
wordpress WP_Dependencies::dequeue( string|string[] $handles ) WP\_Dependencies::dequeue( string|string[] $handles ) ===================================================== Dequeue an item or items. Decodes handles and arguments, then dequeues handles and removes arguments from the class property $args. `$handles` string|string[] Required Item handle (string) or item handles (array of strings). File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function dequeue( $handles ) { foreach ( (array) $handles as $handle ) { $handle = explode( '?', $handle ); $key = array_search( $handle[0], $this->queue, true ); if ( false !== $key ) { // Reset all dependencies so they must be recalculated in recurse_deps(). $this->all_queued_deps = null; unset( $this->queue[ $key ] ); unset( $this->args[ $handle[0] ] ); } elseif ( array_key_exists( $handle[0], $this->queued_before_register ) ) { unset( $this->queued_before_register[ $handle[0] ] ); } } } ``` | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Moved from `WP_Scripts`. | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress WP_Dependencies::do_item( string $handle, int|false $group = false ): bool WP\_Dependencies::do\_item( string $handle, int|false $group = false ): bool ============================================================================ Processes a dependency. `$handle` string Required Name of the item. Should be unique. `$group` int|false Optional Group level: level (int), no group (false). Default: `false` bool True on success, false if not set. File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function do_item( $handle, $group = false ) { return isset( $this->registered[ $handle ] ); } ``` | Used By | Description | | --- | --- | | [WP\_Styles::do\_item()](../wp_styles/do_item) wp-includes/class-wp-styles.php | Processes a style dependency. | | [WP\_Dependencies::do\_items()](../wp_dependencies/do_items) wp-includes/class-wp-dependencies.php | Processes the items and dependencies. | | [WP\_Scripts::do\_item()](../wp_scripts/do_item) wp-includes/class-wp-scripts.php | Processes a script dependency. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Added the `$group` parameter. | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Introduced. | wordpress WP_Dependencies::add_data( string $handle, string $key, mixed $value ): bool WP\_Dependencies::add\_data( string $handle, string $key, mixed $value ): bool ============================================================================== Add extra item data. Adds data to a registered item. `$handle` string Required Name of the item. Should be unique. `$key` string Required The data key. `$value` mixed Required The data value. bool True on success, false on failure. File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function add_data( $handle, $key, $value ) { if ( ! isset( $this->registered[ $handle ] ) ) { return false; } return $this->registered[ $handle ]->add_data( $key, $value ); } ``` | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Introduced. | wordpress WP_Dependencies::get_data( string $handle, string $key ): mixed WP\_Dependencies::get\_data( string $handle, string $key ): mixed ================================================================= Get extra item data. Gets data associated with a registered item. `$handle` string Required Name of the item. Should be unique. `$key` string Required The data key. mixed Extra item data (string), false otherwise. File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function get_data( $handle, $key ) { if ( ! isset( $this->registered[ $handle ] ) ) { return false; } if ( ! isset( $this->registered[ $handle ]->extra[ $key ] ) ) { return false; } return $this->registered[ $handle ]->extra[ $key ]; } ``` | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Dependencies::query( string $handle, string $status = 'registered' ): bool|_WP_Dependency WP\_Dependencies::query( string $handle, string $status = 'registered' ): bool|\_WP\_Dependency =============================================================================================== Query the list for an item. `$handle` string Required Name of the item. Should be unique. `$status` string Optional Status of the item to query. Default `'registered'`. Default: `'registered'` bool|[\_WP\_Dependency](../_wp_dependency) Found, or object Item data. File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function query( $handle, $status = 'registered' ) { switch ( $status ) { case 'registered': case 'scripts': // Back compat. if ( isset( $this->registered[ $handle ] ) ) { return $this->registered[ $handle ]; } return false; case 'enqueued': case 'queue': // Back compat. if ( in_array( $handle, $this->queue, true ) ) { return true; } return $this->recurse_deps( $this->queue, $handle ); case 'to_do': case 'to_print': // Back compat. return in_array( $handle, $this->to_do, true ); case 'done': case 'printed': // Back compat. return in_array( $handle, $this->done, true ); } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Dependencies::recurse\_deps()](recurse_deps) wp-includes/class-wp-dependencies.php | Recursively search the passed dependency tree for a handle. | | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Moved from `WP_Scripts`. | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress WP_Dependencies::set_group( string $handle, bool $recursion, int|false $group ): bool WP\_Dependencies::set\_group( string $handle, bool $recursion, int|false $group ): bool ======================================================================================= Set item group, unless already in a lower group. `$handle` string Required Name of the item. Should be unique. `$recursion` bool Required Internal flag that calling function was called recursively. `$group` int|false Required Group level: level (int), no group (false). bool Not already in the group or a lower group. File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function set_group( $handle, $recursion, $group ) { $group = (int) $group; if ( isset( $this->groups[ $handle ] ) && $this->groups[ $handle ] <= $group ) { return false; } $this->groups[ $handle ] = $group; return true; } ``` | Used By | Description | | --- | --- | | [WP\_Dependencies::all\_deps()](all_deps) wp-includes/class-wp-dependencies.php | Determines dependencies. | | [WP\_Scripts::set\_group()](../wp_scripts/set_group) wp-includes/class-wp-scripts.php | Sets handle group. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Dependencies::enqueue( string|string[] $handles ) WP\_Dependencies::enqueue( string|string[] $handles ) ===================================================== Queue an item or items. Decodes handles and arguments, then queues handles and stores arguments in the class property $args. For example in extending classes, $args is appended to the item url as a query string. Note $args is NOT the $args property of items in the $registered array. `$handles` string|string[] Required Item handle (string) or item handles (array of strings). File: `wp-includes/class-wp-dependencies.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes_class-wp-dependencies-php-2/) ``` public function enqueue( $handles ) { foreach ( (array) $handles as $handle ) { $handle = explode( '?', $handle ); if ( ! in_array( $handle[0], $this->queue, true ) && isset( $this->registered[ $handle[0] ] ) ) { $this->queue[] = $handle[0]; // Reset all dependencies so they must be recalculated in recurse_deps(). $this->all_queued_deps = null; if ( isset( $handle[1] ) ) { $this->args[ $handle[0] ] = $handle[1]; } } elseif ( ! isset( $this->registered[ $handle[0] ] ) ) { $this->queued_before_register[ $handle[0] ] = null; // $args if ( isset( $handle[1] ) ) { $this->queued_before_register[ $handle[0] ] = $handle[1]; } } } } ``` | Used By | Description | | --- | --- | | [WP\_Dependencies::add()](../wp_dependencies/add) wp-includes/class-wp-dependencies.php | Register an item. | | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Moved from `WP_Scripts`. | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress WP_Customize_Nav_Menus_Panel::content_template() WP\_Customize\_Nav\_Menus\_Panel::content\_template() ===================================================== An Underscore (JS) template for this panel’s content (but not its container). Class variables for this panel class are available in the `data` JS object; export custom variables by overriding [WP\_Customize\_Panel::json()](../wp_customize_panel/json). * [WP\_Customize\_Panel::print\_template()](../wp_customize_panel/print_template) File: `wp-includes/customize/class-wp-customize-nav-menus-panel.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menus-panel.php/) ``` protected function content_template() { ?> <li class="panel-meta customize-info accordion-section <# if ( ! data.description ) { #> cannot-expand<# } #>"> <button type="button" class="customize-panel-back" tabindex="-1"> <span class="screen-reader-text"><?php _e( 'Back' ); ?></span> </button> <div class="accordion-section-title"> <span class="preview-notice"> <?php /* translators: %s: The site/panel title in the Customizer. */ printf( __( 'You are customizing %s' ), '<strong class="panel-title">{{ data.title }}</strong>' ); ?> </span> <button type="button" class="customize-help-toggle dashicons dashicons-editor-help" aria-expanded="false"> <span class="screen-reader-text"><?php _e( 'Help' ); ?></span> </button> <button type="button" class="customize-screen-options-toggle" aria-expanded="false"> <span class="screen-reader-text"><?php _e( 'Menu Options' ); ?></span> </button> </div> <# if ( data.description ) { #> <div class="description customize-panel-description">{{{ data.description }}}</div> <# } #> <div id="screen-options-wrap"> <?php $this->render_screen_options(); ?> </div> </li> <?php // NOTE: The following is a workaround for an inability to treat (and thus label) a list of sections as a whole. ?> <li class="customize-control-title customize-section-title-nav_menus-heading"><?php _e( 'Menus' ); ?></li> <?php } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus\_Panel::render\_screen\_options()](render_screen_options) wp-includes/customize/class-wp-customize-nav-menus-panel.php | Render screen options for Menus. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus_Panel::wp_nav_menu_manage_columns() WP\_Customize\_Nav\_Menus\_Panel::wp\_nav\_menu\_manage\_columns() ================================================================== This method has been deprecated. Deprecated in favor of [wp\_nav\_menu\_manage\_columns()](../../functions/wp_nav_menu_manage_columns) instead. Returns the advanced options for the nav menus page. Link title attribute added as it’s a relatively advanced concept for new users. File: `wp-includes/customize/class-wp-customize-nav-menus-panel.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menus-panel.php/) ``` public function wp_nav_menu_manage_columns() { _deprecated_function( __METHOD__, '4.5.0', 'wp_nav_menu_manage_columns' ); require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; return wp_nav_menu_manage_columns(); } ``` | Uses | Description | | --- | --- | | [wp\_nav\_menu\_manage\_columns()](../../functions/wp_nav_menu_manage_columns) wp-admin/includes/nav-menu.php | Returns the columns for the nav menus page. | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Deprecated in favor of [wp\_nav\_menu\_manage\_columns()](../../functions/wp_nav_menu_manage_columns) . | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus_Panel::check_capabilities(): bool WP\_Customize\_Nav\_Menus\_Panel::check\_capabilities(): bool ============================================================= Checks required user capabilities and whether the theme has the feature support required by the panel. bool False if theme doesn't support the panel or the user doesn't have the capability. File: `wp-includes/customize/class-wp-customize-nav-menus-panel.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menus-panel.php/) [View on Trac](https://core.trac.wordpress.org/browser/tags/6.1/src/wp-includes/customize/class-wp-customize-nav-menus-panel.php#L110) | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Customize_Nav_Menus_Panel::render_screen_options() WP\_Customize\_Nav\_Menus\_Panel::render\_screen\_options() =========================================================== Render screen options for Menus. File: `wp-includes/customize/class-wp-customize-nav-menus-panel.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menus-panel.php/) ``` public function render_screen_options() { // Adds the screen options. require_once ABSPATH . 'wp-admin/includes/nav-menu.php'; add_filter( 'manage_nav-menus_columns', 'wp_nav_menu_manage_columns' ); // Display screen options. $screen = WP_Screen::get( 'nav-menus.php' ); $screen->render_screen_options( array( 'wrap' => false ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Screen::get()](../wp_screen/get) wp-admin/includes/class-wp-screen.php | Fetches a screen object. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus\_Panel::content\_template()](content_template) wp-includes/customize/class-wp-customize-nav-menus-panel.php | An Underscore (JS) template for this panel’s content (but not its container). | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress POMO_Reader::is_resource(): true POMO\_Reader::is\_resource(): true ================================== true File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function is_resource() { return true; } ``` wordpress POMO_Reader::readint32array( int $count ): mixed POMO\_Reader::readint32array( int $count ): mixed ================================================= Reads an array of 32-bit Integers from the Stream `$count` int Required How many elements should be read mixed Array of integers or false if there isn't enough data or on error File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function readint32array( $count ) { $bytes = $this->read( 4 * $count ); if ( 4 * $count != $this->strlen( $bytes ) ) { return false; } $endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V'; return unpack( $endian_letter . $count, $bytes ); } ``` | Uses | Description | | --- | --- | | [POMO\_Reader::strlen()](strlen) wp-includes/pomo/streams.php | | wordpress POMO_Reader::readint32(): mixed POMO\_Reader::readint32(): mixed ================================ Reads a 32bit Integer from the Stream mixed The integer, corresponding to the next 32 bits from the stream of false if there are not enough bytes or on error File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function readint32() { $bytes = $this->read( 4 ); if ( 4 != $this->strlen( $bytes ) ) { return false; } $endian_letter = ( 'big' === $this->endian ) ? 'N' : 'V'; $int = unpack( $endian_letter, $bytes ); return reset( $int ); } ``` | Uses | Description | | --- | --- | | [POMO\_Reader::strlen()](strlen) wp-includes/pomo/streams.php | | wordpress POMO_Reader::POMO_Reader() POMO\_Reader::POMO\_Reader() ============================ This method has been deprecated. Use [POMO\_Reader::\_\_construct()](../pomo_reader/__construct) instead. PHP4 constructor. * [POMO\_Reader::\_\_construct()](../pomo_reader/__construct) File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function POMO_Reader() { _deprecated_constructor( self::class, '5.4.0', static::class ); self::__construct(); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_constructor()](../../functions/_deprecated_constructor) wp-includes/functions.php | Marks a constructor as deprecated and informs when it has been used. | | [POMO\_Reader::\_\_construct()](__construct) wp-includes/pomo/streams.php | PHP5 constructor. | | Version | Description | | --- | --- | | [5.4.0](https://developer.wordpress.org/reference/since/5.4.0/) | Introduced. | wordpress POMO_Reader::strlen( string $string ): int POMO\_Reader::strlen( string $string ): int =========================================== `$string` string Required int File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function strlen( $string ) { if ( $this->is_overloaded ) { return mb_strlen( $string, 'ascii' ); } else { return strlen( $string ); } } ``` | Used By | Description | | --- | --- | | [POMO\_Reader::readint32()](readint32) wp-includes/pomo/streams.php | Reads a 32bit Integer from the Stream | | [POMO\_Reader::readint32array()](readint32array) wp-includes/pomo/streams.php | Reads an array of 32-bit Integers from the Stream | | [POMO\_Reader::str\_split()](str_split) wp-includes/pomo/streams.php | |
programming_docs
wordpress POMO_Reader::close(): true POMO\_Reader::close(): true =========================== true File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function close() { return true; } ``` wordpress POMO_Reader::__construct() POMO\_Reader::\_\_construct() ============================= PHP5 constructor. File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function __construct() { if ( function_exists( 'mb_substr' ) && ( (int) ini_get( 'mbstring.func_overload' ) & 2 ) // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated ) { $this->is_overloaded = true; } else { $this->is_overloaded = false; } $this->_pos = 0; } ``` | Used By | Description | | --- | --- | | [POMO\_StringReader::\_\_construct()](../pomo_stringreader/__construct) wp-includes/pomo/streams.php | PHP5 constructor. | | [POMO\_FileReader::\_\_construct()](../pomo_filereader/__construct) wp-includes/pomo/streams.php | | | [POMO\_Reader::POMO\_Reader()](pomo_reader) wp-includes/pomo/streams.php | PHP4 constructor. | | [MO::export\_to\_file\_handle()](../mo/export_to_file_handle) wp-includes/pomo/mo.php | | wordpress POMO_Reader::substr( string $string, int $start, int $length ): string POMO\_Reader::substr( string $string, int $start, int $length ): string ======================================================================= `$string` string Required `$start` int Required `$length` int Required string File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function substr( $string, $start, $length ) { if ( $this->is_overloaded ) { return mb_substr( $string, $start, $length, 'ascii' ); } else { return substr( $string, $start, $length ); } } ``` | Used By | Description | | --- | --- | | [POMO\_Reader::str\_split()](str_split) wp-includes/pomo/streams.php | | wordpress POMO_Reader::str_split( string $string, int $chunk_size ): array POMO\_Reader::str\_split( string $string, int $chunk\_size ): array =================================================================== `$string` string Required `$chunk_size` int Required array File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function str_split( $string, $chunk_size ) { if ( ! function_exists( 'str_split' ) ) { $length = $this->strlen( $string ); $out = array(); for ( $i = 0; $i < $length; $i += $chunk_size ) { $out[] = $this->substr( $string, $i, $chunk_size ); } return $out; } else { return str_split( $string, $chunk_size ); } } ``` | Uses | Description | | --- | --- | | [POMO\_Reader::strlen()](strlen) wp-includes/pomo/streams.php | | | [POMO\_Reader::substr()](substr) wp-includes/pomo/streams.php | | wordpress POMO_Reader::setEndian( string $endian ) POMO\_Reader::setEndian( string $endian ) ========================================= Sets the endianness of the file. `$endian` string Required Set the endianness of the file. Accepts `'big'`, or `'little'`. File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function setEndian( $endian ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid $this->endian = $endian; } ``` wordpress POMO_Reader::pos(): int POMO\_Reader::pos(): int ======================== int File: `wp-includes/pomo/streams.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/streams.php/) ``` public function pos() { return $this->_pos; } ``` wordpress WP_Customize_Site_Icon_Control::content_template() WP\_Customize\_Site\_Icon\_Control::content\_template() ======================================================= Renders a JS template for the content of the site icon control. File: `wp-includes/customize/class-wp-customize-site-icon-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-site-icon-control.php/) ``` public function content_template() { ?> <# if ( data.label ) { #> <span class="customize-control-title">{{ data.label }}</span> <# } #> <# if ( data.description ) { #> <span class="description customize-control-description">{{{ data.description }}}</span> <# } #> <# if ( data.attachment && data.attachment.id ) { #> <div class="attachment-media-view"> <# if ( data.attachment.sizes ) { #> <div class="site-icon-preview wp-clearfix"> <div class="favicon-preview"> <img src="<?php echo esc_url( admin_url( 'images/' . ( is_rtl() ? 'browser-rtl.png' : 'browser.png' ) ) ); ?>" class="browser-preview" width="182" alt="" /> <div class="favicon"> <img src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as a browser icon' ); ?>" /> </div> <span class="browser-title" aria-hidden="true"><# print( '<?php echo esc_js( get_bloginfo( 'name' ) ); ?>' ) #></span> </div> <img class="app-icon-preview" src="{{ data.attachment.sizes.full ? data.attachment.sizes.full.url : data.attachment.url }}" alt="<?php esc_attr_e( 'Preview as an app icon' ); ?>" /> </div> <# } #> <div class="actions"> <# if ( data.canUpload ) { #> <button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button> <button type="button" class="button upload-button"><?php echo $this->button_labels['change']; ?></button> <# } #> </div> </div> <# } else { #> <div class="attachment-media-view"> <# if ( data.canUpload ) { #> <button type="button" class="upload-button button-add-media"><?php echo $this->button_labels['site_icon']; ?></button> <# } #> <div class="actions"> <# if ( data.defaultAttachment ) { #> <button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button> <# } #> </div> </div> <# } #> <?php } ``` | Uses | Description | | --- | --- | | [esc\_attr\_e()](../../functions/esc_attr_e) wp-includes/l10n.php | Displays translated text that has been escaped for safe use in an attribute. | | [esc\_js()](../../functions/esc_js) wp-includes/formatting.php | Escapes single quotes, `"`, , `&amp;`, and fixes line endings. | | [is\_rtl()](../../functions/is_rtl) wp-includes/l10n.php | Determines whether the current locale is right-to-left (RTL). | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Introduced. | wordpress WP_Customize_Site_Icon_Control::__construct( WP_Customize_Manager $manager, string $id, array $args = array() ) WP\_Customize\_Site\_Icon\_Control::\_\_construct( WP\_Customize\_Manager $manager, string $id, array $args = array() ) ======================================================================================================================= Constructor. * [WP\_Customize\_Control::\_\_construct()](../wp_customize_control/__construct) `$manager` [WP\_Customize\_Manager](../wp_customize_manager) Required Customizer bootstrap instance. `$id` string Required Control ID. `$args` array Optional Arguments to override class property defaults. See [WP\_Customize\_Control::\_\_construct()](../wp_customize_control/__construct) for information on accepted arguments. More Arguments from WP\_Customize\_Control::\_\_construct( ... $args ) Array of properties for the new Control object. * `instance_number`intOrder in which this instance was created in relation to other instances. * `manager`[WP\_Customize\_Manager](../wp_customize_manager)Customizer bootstrap instance. * `id`stringControl ID. * `settings`arrayAll settings tied to the control. If undefined, `$id` will be used. * `setting`stringThe primary setting for the control (if there is one). Default `'default'`. * `capability`stringCapability required to use this control. Normally this is empty and the capability is derived from `$settings`. * `priority`intOrder priority to load the control. Default 10. * `section`stringSection the control belongs to. * `label`stringLabel for the control. * `description`stringDescription for the control. * `choices`arrayList of choices for `'radio'` or `'select'` type controls, where values are the keys, and labels are the values. * `input_attrs`arrayList of custom input attributes for control output, where attribute names are the keys and values are the values. Not used for `'checkbox'`, `'radio'`, `'select'`, `'textarea'`, or `'dropdown-pages'` control types. * `allow_addition`boolShow UI for adding new content, currently only used for the dropdown-pages control. Default false. * `json`arrayDeprecated. Use [WP\_Customize\_Control::json()](../wp_customize_control/json) instead. * `type`stringControl type. Core controls include `'text'`, `'checkbox'`, `'textarea'`, `'radio'`, `'select'`, and `'dropdown-pages'`. Additional input types such as `'email'`, `'url'`, `'number'`, `'hidden'`, and `'date'` are supported implicitly. Default `'text'`. * `active_callback`callableActive callback. Default: `array()` File: `wp-includes/customize/class-wp-customize-site-icon-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-site-icon-control.php/) ``` public function __construct( $manager, $id, $args = array() ) { parent::__construct( $manager, $id, $args ); add_action( 'customize_controls_print_styles', 'wp_site_icon', 99 ); } ``` | Uses | Description | | --- | --- | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | Used By | Description | | --- | --- | | [WP\_Customize\_Manager::register\_controls()](../wp_customize_manager/register_controls) wp-includes/class-wp-customize-manager.php | Registers some default controls. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Sidebar_Block_Editor_Control::render_content() WP\_Sidebar\_Block\_Editor\_Control::render\_content() ====================================================== Render the widgets block editor container. File: `wp-includes/customize/class-wp-sidebar-block-editor-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-sidebar-block-editor-control.php/) ``` public function render_content() { // Render an empty control. The JavaScript in // @wordpress/customize-widgets will do the rest. } ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Post_Format_Search_Handler::search_items( WP_REST_Request $request ): array WP\_REST\_Post\_Format\_Search\_Handler::search\_items( WP\_REST\_Request $request ): array =========================================================================================== Searches the object type content for a given search request. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full REST request. array Associative array containing an `WP_REST_Search_Handler::RESULT_IDS` containing an array of found IDs and `WP_REST_Search_Handler::RESULT_TOTAL` containing the total count for the matching search results. File: `wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php/) ``` public function search_items( WP_REST_Request $request ) { $format_strings = get_post_format_strings(); $format_slugs = array_keys( $format_strings ); $query_args = array(); if ( ! empty( $request['search'] ) ) { $query_args['search'] = $request['search']; } /** * Filters the query arguments for a REST API search request. * * Enables adding extra arguments or setting defaults for a post format search request. * * @since 5.6.0 * * @param array $query_args Key value array of query var to query value. * @param WP_REST_Request $request The request used. */ $query_args = apply_filters( 'rest_post_format_search_query', $query_args, $request ); $found_ids = array(); foreach ( $format_slugs as $index => $format_slug ) { if ( ! empty( $query_args['search'] ) ) { $format_string = get_post_format_string( $format_slug ); $format_slug_match = stripos( $format_slug, $query_args['search'] ) !== false; $format_string_match = stripos( $format_string, $query_args['search'] ) !== false; if ( ! $format_slug_match && ! $format_string_match ) { continue; } } $format_link = get_post_format_link( $format_slug ); if ( $format_link ) { $found_ids[] = $format_slug; } } $page = (int) $request['page']; $per_page = (int) $request['per_page']; return array( self::RESULT_IDS => array_slice( $found_ids, ( $page - 1 ) * $per_page, $per_page ), self::RESULT_TOTAL => count( $found_ids ), ); } ``` [apply\_filters( 'rest\_post\_format\_search\_query', array $query\_args, WP\_REST\_Request $request )](../../hooks/rest_post_format_search_query) Filters the query arguments for a REST API search request. | Uses | Description | | --- | --- | | [stripos()](../../functions/stripos) wp-includes/class-pop3.php | | | [get\_post\_format\_strings()](../../functions/get_post_format_strings) wp-includes/post-formats.php | Returns an array of post format slugs to their translated and pretty display versions | | [get\_post\_format\_string()](../../functions/get_post_format_string) wp-includes/post-formats.php | Returns a pretty, translated version of a post format slug | | [get\_post\_format\_link()](../../functions/get_post_format_link) wp-includes/post-formats.php | Returns a link to a post format index. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Post_Format_Search_Handler::prepare_item( string $id, array $fields ): array WP\_REST\_Post\_Format\_Search\_Handler::prepare\_item( string $id, array $fields ): array ========================================================================================== Prepares the search result for a given ID. `$id` string Required Item ID, the post format slug. `$fields` array Required Fields to include for the item. array Associative array containing all fields for the item. File: `wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php/) ``` public function prepare_item( $id, array $fields ) { $data = array(); if ( in_array( WP_REST_Search_Controller::PROP_ID, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_ID ] = $id; } if ( in_array( WP_REST_Search_Controller::PROP_TITLE, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_TITLE ] = get_post_format_string( $id ); } if ( in_array( WP_REST_Search_Controller::PROP_URL, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_URL ] = get_post_format_link( $id ); } if ( in_array( WP_REST_Search_Controller::PROP_TYPE, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_TYPE ] = $this->type; } return $data; } ``` | Uses | Description | | --- | --- | | [get\_post\_format\_string()](../../functions/get_post_format_string) wp-includes/post-formats.php | Returns a pretty, translated version of a post format slug | | [get\_post\_format\_link()](../../functions/get_post_format_link) wp-includes/post-formats.php | Returns a link to a post format index. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Post_Format_Search_Handler::__construct() WP\_REST\_Post\_Format\_Search\_Handler::\_\_construct() ======================================================== Constructor. File: `wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php/) ``` public function __construct() { $this->type = 'post-format'; } ``` | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Post_Format_Search_Handler::prepare_item_links( string $id ): array WP\_REST\_Post\_Format\_Search\_Handler::prepare\_item\_links( string $id ): array ================================================================================== Prepares links for the search result. `$id` string Required Item ID, the post format slug. array Links for the given item. File: `wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-format-search-handler.php/) ``` public function prepare_item_links( $id ) { return array(); } ``` | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_Sitemaps_Renderer::render_index( array $sitemaps ) WP\_Sitemaps\_Renderer::render\_index( array $sitemaps ) ======================================================== Renders a sitemap index. `$sitemaps` array Required Array of sitemap URLs. File: `wp-includes/sitemaps/class-wp-sitemaps-renderer.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-renderer.php/) ``` public function render_index( $sitemaps ) { header( 'Content-type: application/xml; charset=UTF-8' ); $this->check_for_simple_xml_availability(); $index_xml = $this->get_sitemap_index_xml( $sitemaps ); if ( ! empty( $index_xml ) ) { // All output is escaped within get_sitemap_index_xml(). // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $index_xml; } } ``` | Uses | Description | | --- | --- | | [WP\_Sitemaps\_Renderer::check\_for\_simple\_xml\_availability()](check_for_simple_xml_availability) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Checks for the availability of the SimpleXML extension and errors if missing. | | [WP\_Sitemaps\_Renderer::get\_sitemap\_index\_xml()](get_sitemap_index_xml) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Gets XML for a sitemap index. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |
programming_docs
wordpress WP_Sitemaps_Renderer::get_sitemap_xml( array $url_list ): string|false WP\_Sitemaps\_Renderer::get\_sitemap\_xml( array $url\_list ): string|false =========================================================================== Gets XML for a sitemap. `$url_list` array Required Array of URLs for a sitemap. string|false A well-formed XML string for a sitemap index. False on error. File: `wp-includes/sitemaps/class-wp-sitemaps-renderer.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-renderer.php/) ``` public function get_sitemap_xml( $url_list ) { $urlset = new SimpleXMLElement( sprintf( '%1$s%2$s%3$s', '<?xml version="1.0" encoding="UTF-8" ?>', $this->stylesheet, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />' ) ); foreach ( $url_list as $url_item ) { $url = $urlset->addChild( 'url' ); // Add each element as a child node to the <url> entry. foreach ( $url_item as $name => $value ) { if ( 'loc' === $name ) { $url->addChild( $name, esc_url( $value ) ); } elseif ( in_array( $name, array( 'lastmod', 'changefreq', 'priority' ), true ) ) { $url->addChild( $name, esc_xml( $value ) ); } else { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: List of element names. */ __( 'Fields other than %s are not currently supported for sitemaps.' ), implode( ',', array( 'loc', 'lastmod', 'changefreq', 'priority' ) ) ), '5.5.0' ); } } } return $urlset->asXML(); } ``` | Uses | Description | | --- | --- | | [esc\_xml()](../../functions/esc_xml) wp-includes/formatting.php | Escaping for XML blocks. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [\_doing\_it\_wrong()](../../functions/_doing_it_wrong) wp-includes/functions.php | Marks something as being incorrectly called. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Renderer::render\_sitemap()](render_sitemap) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Renders a sitemap. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Renderer::render_sitemap( array $url_list ) WP\_Sitemaps\_Renderer::render\_sitemap( array $url\_list ) =========================================================== Renders a sitemap. `$url_list` array Required Array of URLs for a sitemap. File: `wp-includes/sitemaps/class-wp-sitemaps-renderer.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-renderer.php/) ``` public function render_sitemap( $url_list ) { header( 'Content-type: application/xml; charset=UTF-8' ); $this->check_for_simple_xml_availability(); $sitemap_xml = $this->get_sitemap_xml( $url_list ); if ( ! empty( $sitemap_xml ) ) { // All output is escaped within get_sitemap_xml(). // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $sitemap_xml; } } ``` | Uses | Description | | --- | --- | | [WP\_Sitemaps\_Renderer::check\_for\_simple\_xml\_availability()](check_for_simple_xml_availability) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Checks for the availability of the SimpleXML extension and errors if missing. | | [WP\_Sitemaps\_Renderer::get\_sitemap\_xml()](get_sitemap_xml) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Gets XML for a sitemap. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Renderer::get_sitemap_stylesheet_url(): string WP\_Sitemaps\_Renderer::get\_sitemap\_stylesheet\_url(): string =============================================================== Gets the URL for the sitemap stylesheet. string The sitemap stylesheet URL. File: `wp-includes/sitemaps/class-wp-sitemaps-renderer.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-renderer.php/) ``` public function get_sitemap_stylesheet_url() { global $wp_rewrite; $sitemap_url = home_url( '/wp-sitemap.xsl' ); if ( ! $wp_rewrite->using_permalinks() ) { $sitemap_url = home_url( '/?sitemap-stylesheet=sitemap' ); } /** * Filters the URL for the sitemap stylesheet. * * If a falsey value is returned, no stylesheet will be used and * the "raw" XML of the sitemap will be displayed. * * @since 5.5.0 * * @param string $sitemap_url Full URL for the sitemaps XSL file. */ return apply_filters( 'wp_sitemaps_stylesheet_url', $sitemap_url ); } ``` [apply\_filters( 'wp\_sitemaps\_stylesheet\_url', string $sitemap\_url )](../../hooks/wp_sitemaps_stylesheet_url) Filters the URL for the sitemap stylesheet. | Uses | Description | | --- | --- | | [WP\_Rewrite::using\_permalinks()](../wp_rewrite/using_permalinks) wp-includes/class-wp-rewrite.php | Determines whether permalinks are being used. | | [home\_url()](../../functions/home_url) wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Renderer::\_\_construct()](__construct) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | [WP\_Sitemaps\_Renderer](../wp_sitemaps_renderer) constructor. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Renderer::check_for_simple_xml_availability() WP\_Sitemaps\_Renderer::check\_for\_simple\_xml\_availability() =============================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Checks for the availability of the SimpleXML extension and errors if missing. File: `wp-includes/sitemaps/class-wp-sitemaps-renderer.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-renderer.php/) ``` private function check_for_simple_xml_availability() { if ( ! class_exists( 'SimpleXMLElement' ) ) { add_filter( 'wp_die_handler', static function () { return '_xml_wp_die_handler'; } ); wp_die( sprintf( /* translators: %s: SimpleXML */ esc_xml( __( 'Could not generate XML sitemap due to missing %s extension' ) ), 'SimpleXML' ), esc_xml( __( 'WordPress &rsaquo; Error' ) ), array( 'response' => 501, // "Not implemented". ) ); } } ``` | Uses | Description | | --- | --- | | [esc\_xml()](../../functions/esc_xml) wp-includes/formatting.php | Escaping for XML blocks. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_die()](../../functions/wp_die) wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Renderer::render\_index()](render_index) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Renders a sitemap index. | | [WP\_Sitemaps\_Renderer::render\_sitemap()](render_sitemap) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Renders a sitemap. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Renderer::get_sitemap_index_xml( array $sitemaps ): string|false WP\_Sitemaps\_Renderer::get\_sitemap\_index\_xml( array $sitemaps ): string|false ================================================================================= Gets XML for a sitemap index. `$sitemaps` array Required Array of sitemap URLs. string|false A well-formed XML string for a sitemap index. False on error. File: `wp-includes/sitemaps/class-wp-sitemaps-renderer.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-renderer.php/) ``` public function get_sitemap_index_xml( $sitemaps ) { $sitemap_index = new SimpleXMLElement( sprintf( '%1$s%2$s%3$s', '<?xml version="1.0" encoding="UTF-8" ?>', $this->stylesheet_index, '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />' ) ); foreach ( $sitemaps as $entry ) { $sitemap = $sitemap_index->addChild( 'sitemap' ); // Add each element as a child node to the <sitemap> entry. foreach ( $entry as $name => $value ) { if ( 'loc' === $name ) { $sitemap->addChild( $name, esc_url( $value ) ); } elseif ( 'lastmod' === $name ) { $sitemap->addChild( $name, esc_xml( $value ) ); } else { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: List of element names. */ __( 'Fields other than %s are not currently supported for the sitemap index.' ), implode( ',', array( 'loc', 'lastmod' ) ) ), '5.5.0' ); } } } return $sitemap_index->asXML(); } ``` | Uses | Description | | --- | --- | | [esc\_xml()](../../functions/esc_xml) wp-includes/formatting.php | Escaping for XML blocks. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [\_doing\_it\_wrong()](../../functions/_doing_it_wrong) wp-includes/functions.php | Marks something as being incorrectly called. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Renderer::render\_index()](render_index) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Renders a sitemap index. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Renderer::__construct() WP\_Sitemaps\_Renderer::\_\_construct() ======================================= [WP\_Sitemaps\_Renderer](../wp_sitemaps_renderer) constructor. File: `wp-includes/sitemaps/class-wp-sitemaps-renderer.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-renderer.php/) ``` public function __construct() { $stylesheet_url = $this->get_sitemap_stylesheet_url(); if ( $stylesheet_url ) { $this->stylesheet = '<?xml-stylesheet type="text/xsl" href="' . esc_url( $stylesheet_url ) . '" ?>'; } $stylesheet_index_url = $this->get_sitemap_index_stylesheet_url(); if ( $stylesheet_index_url ) { $this->stylesheet_index = '<?xml-stylesheet type="text/xsl" href="' . esc_url( $stylesheet_index_url ) . '" ?>'; } } ``` | Uses | Description | | --- | --- | | [WP\_Sitemaps\_Renderer::get\_sitemap\_index\_stylesheet\_url()](get_sitemap_index_stylesheet_url) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Gets the URL for the sitemap index stylesheet. | | [WP\_Sitemaps\_Renderer::get\_sitemap\_stylesheet\_url()](get_sitemap_stylesheet_url) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Gets the URL for the sitemap stylesheet. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | Used By | Description | | --- | --- | | [WP\_Sitemaps::\_\_construct()](../wp_sitemaps/__construct) wp-includes/sitemaps/class-wp-sitemaps.php | [WP\_Sitemaps](../wp_sitemaps) constructor. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Renderer::get_sitemap_index_stylesheet_url(): string WP\_Sitemaps\_Renderer::get\_sitemap\_index\_stylesheet\_url(): string ====================================================================== Gets the URL for the sitemap index stylesheet. string The sitemap index stylesheet URL. File: `wp-includes/sitemaps/class-wp-sitemaps-renderer.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-renderer.php/) ``` public function get_sitemap_index_stylesheet_url() { global $wp_rewrite; $sitemap_url = home_url( '/wp-sitemap-index.xsl' ); if ( ! $wp_rewrite->using_permalinks() ) { $sitemap_url = home_url( '/?sitemap-stylesheet=index' ); } /** * Filters the URL for the sitemap index stylesheet. * * If a falsey value is returned, no stylesheet will be used and * the "raw" XML of the sitemap index will be displayed. * * @since 5.5.0 * * @param string $sitemap_url Full URL for the sitemaps index XSL file. */ return apply_filters( 'wp_sitemaps_stylesheet_index_url', $sitemap_url ); } ``` [apply\_filters( 'wp\_sitemaps\_stylesheet\_index\_url', string $sitemap\_url )](../../hooks/wp_sitemaps_stylesheet_index_url) Filters the URL for the sitemap index stylesheet. | Uses | Description | | --- | --- | | [WP\_Rewrite::using\_permalinks()](../wp_rewrite/using_permalinks) wp-includes/class-wp-rewrite.php | Determines whether permalinks are being used. | | [home\_url()](../../functions/home_url) wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Renderer::\_\_construct()](__construct) wp-includes/sitemaps/class-wp-sitemaps-renderer.php | [WP\_Sitemaps\_Renderer](../wp_sitemaps_renderer) constructor. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Customize_Nav_Menu_Control::content_template() WP\_Customize\_Nav\_Menu\_Control::content\_template() ====================================================== JS/Underscore template for the control UI. File: `wp-includes/customize/class-wp-customize-nav-menu-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menu-control.php/) ``` public function content_template() { $add_items = __( 'Add Items' ); ?> <p class="new-menu-item-invitation"> <?php printf( /* translators: %s: "Add Items" button text. */ __( 'Time to add some links! Click &#8220;%s&#8221; to start putting pages, categories, and custom links in your menu. Add as many things as you would like.' ), $add_items ); ?> </p> <div class="customize-control-nav_menu-buttons"> <button type="button" class="button add-new-menu-item" aria-label="<?php esc_attr_e( 'Add or remove menu items' ); ?>" aria-expanded="false" aria-controls="available-menu-items"> <?php echo $add_items; ?> </button> <button type="button" class="button-link reorder-toggle" aria-label="<?php esc_attr_e( 'Reorder menu items' ); ?>" aria-describedby="reorder-items-desc-{{ data.menu_id }}"> <span class="reorder"><?php _e( 'Reorder' ); ?></span> <span class="reorder-done"><?php _e( 'Done' ); ?></span> </button> </div> <p class="screen-reader-text" id="reorder-items-desc-{{ data.menu_id }}"><?php _e( 'When in reorder mode, additional controls to reorder menu items will be available in the items list above.' ); ?></p> <?php } ``` | Uses | Description | | --- | --- | | [esc\_attr\_e()](../../functions/esc_attr_e) wp-includes/l10n.php | Displays translated text that has been escaped for safe use in an attribute. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menu_Control::json(): array WP\_Customize\_Nav\_Menu\_Control::json(): array ================================================ Return parameters for this control. array Exported parameters. File: `wp-includes/customize/class-wp-customize-nav-menu-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menu-control.php/) ``` public function json() { $exported = parent::json(); $exported['menu_id'] = $this->setting->term_id; return $exported; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Control::json()](../wp_customize_control/json) wp-includes/class-wp-customize-control.php | Get the data to export to the client via JSON. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menu_Control::render_content() WP\_Customize\_Nav\_Menu\_Control::render\_content() ==================================================== Don’t render the control’s content – it uses a JS template instead. File: `wp-includes/customize/class-wp-customize-nav-menu-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menu-control.php/) ``` public function render_content() {} ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Privacy_Data_Removal_Requests_Table::column_email( WP_User_Request $item ): string WP\_Privacy\_Data\_Removal\_Requests\_Table::column\_email( WP\_User\_Request $item ): string ============================================================================================= Actions column. `$item` [WP\_User\_Request](../wp_user_request) Required Item being shown. string Email column markup. File: `wp-admin/includes/user.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/user.php/) [View on Trac](https://core.trac.wordpress.org/browser/tags/6.1/src/wp-admin/includes/user.php#L1634) | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Privacy_Data_Removal_Requests_Table::__construct( $args ) WP\_Privacy\_Data\_Removal\_Requests\_Table::\_\_construct( $args ) =================================================================== File: `wp-admin/includes/deprecated.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/deprecated.php/) ``` function __construct( $args ) { _deprecated_function( __CLASS__, '5.3.0', 'WP_Privacy_Data_Removal_Requests_List_Table' ); if ( ! isset( $args['screen'] ) || $args['screen'] === 'remove_personal_data' ) { $args['screen'] = 'erase-personal-data'; } parent::__construct( $args ); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | wordpress WP_Privacy_Data_Removal_Requests_Table::column_next_steps( WP_User_Request $item ) WP\_Privacy\_Data\_Removal\_Requests\_Table::column\_next\_steps( WP\_User\_Request $item ) =========================================================================================== Next steps column. `$item` [WP\_User\_Request](../wp_user_request) Required Item being shown. File: `wp-admin/includes/user.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/user.php/) [View on Trac](https://core.trac.wordpress.org/browser/tags/6.1/src/wp-admin/includes/user.php#L1673) | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. |
programming_docs
wordpress WP_REST_User_Meta_Fields::get_meta_subtype(): string WP\_REST\_User\_Meta\_Fields::get\_meta\_subtype(): string ========================================================== Retrieves the user meta subtype. string `'user'` There are no subtypes. File: `wp-includes/rest-api/fields/class-wp-rest-user-meta-fields.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/fields/class-wp-rest-user-meta-fields.php/) ``` protected function get_meta_subtype() { return 'user'; } ``` | Version | Description | | --- | --- | | [4.9.8](https://developer.wordpress.org/reference/since/4.9.8/) | Introduced. | wordpress WP_REST_User_Meta_Fields::get_rest_field_type(): string WP\_REST\_User\_Meta\_Fields::get\_rest\_field\_type(): string ============================================================== Retrieves the type for [register\_rest\_field()](../../functions/register_rest_field) . string The user REST field type. File: `wp-includes/rest-api/fields/class-wp-rest-user-meta-fields.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/fields/class-wp-rest-user-meta-fields.php/) ``` public function get_rest_field_type() { return 'user'; } ``` | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_User_Meta_Fields::get_meta_type(): string WP\_REST\_User\_Meta\_Fields::get\_meta\_type(): string ======================================================= Retrieves the user meta type. string The user meta type. File: `wp-includes/rest-api/fields/class-wp-rest-user-meta-fields.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/fields/class-wp-rest-user-meta-fields.php/) ``` protected function get_meta_type() { return 'user'; } ``` | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Block_List::offsetGet( $index ) WP\_Block\_List::offsetGet( $index ) ==================================== File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function offsetGet( $index ) { $block = $this->blocks[ $index ]; if ( isset( $block ) && is_array( $block ) ) { $block = new WP_Block( $block, $this->available_context, $this->registry ); $this->blocks[ $index ] = $block; } return $block; } ``` | Uses | Description | | --- | --- | | [WP\_Block::\_\_construct()](../wp_block/__construct) wp-includes/class-wp-block.php | Constructor. | | Used By | Description | | --- | --- | | [WP\_Block\_List::current()](current) wp-includes/class-wp-block-list.php | | wordpress WP_Block_List::offsetUnset( $index ) WP\_Block\_List::offsetUnset( $index ) ====================================== File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function offsetUnset( $index ) { unset( $this->blocks[ $index ] ); } ``` wordpress WP_Block_List::offsetSet( $index, $value ) WP\_Block\_List::offsetSet( $index, $value ) ============================================ File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function offsetSet( $index, $value ) { if ( is_null( $index ) ) { $this->blocks[] = $value; } else { $this->blocks[ $index ] = $value; } } ``` wordpress WP_Block_List::current() WP\_Block\_List::current() ========================== File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function current() { return $this->offsetGet( $this->key() ); } ``` | Uses | Description | | --- | --- | | [WP\_Block\_List::key()](key) wp-includes/class-wp-block-list.php | | | [WP\_Block\_List::offsetGet()](offsetget) wp-includes/class-wp-block-list.php | | wordpress WP_Block_List::count() WP\_Block\_List::count() ======================== File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function count() { return count( $this->blocks ); } ``` wordpress WP_Block_List::valid() WP\_Block\_List::valid() ======================== File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function valid() { return null !== key( $this->blocks ); } ``` wordpress WP_Block_List::next() WP\_Block\_List::next() ======================= File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function next() { next( $this->blocks ); } ``` wordpress WP_Block_List::offsetExists( $index ) WP\_Block\_List::offsetExists( $index ) ======================================= File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function offsetExists( $index ) { return isset( $this->blocks[ $index ] ); } ``` wordpress WP_Block_List::key() WP\_Block\_List::key() ====================== File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function key() { return key( $this->blocks ); } ``` | Used By | Description | | --- | --- | | [WP\_Block\_List::current()](current) wp-includes/class-wp-block-list.php | | wordpress WP_Block_List::__construct( array[]|WP_Block[] $blocks, array $available_context = array(), WP_Block_Type_Registry $registry = null ) WP\_Block\_List::\_\_construct( array[]|WP\_Block[] $blocks, array $available\_context = array(), WP\_Block\_Type\_Registry $registry = null ) ============================================================================================================================================== Constructor. Populates object properties from the provided block instance argument. `$blocks` array[]|[WP\_Block](../wp_block)[] Required Array of parsed block data, or block instances. `$available_context` array Optional array of ancestry context values. Default: `array()` `$registry` [WP\_Block\_Type\_Registry](../wp_block_type_registry) Optional block type registry. Default: `null` File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function __construct( $blocks, $available_context = array(), $registry = null ) { if ( ! $registry instanceof WP_Block_Type_Registry ) { $registry = WP_Block_Type_Registry::get_instance(); } $this->blocks = $blocks; $this->available_context = $available_context; $this->registry = $registry; } ``` | Uses | Description | | --- | --- | | [WP\_Block\_Type\_Registry::get\_instance()](../wp_block_type_registry/get_instance) wp-includes/class-wp-block-type-registry.php | Utility method to retrieve the main instance of the class. | | Used By | Description | | --- | --- | | [WP\_Block::\_\_construct()](../wp_block/__construct) wp-includes/class-wp-block.php | Constructor. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Block_List::rewind() WP\_Block\_List::rewind() ========================= File: `wp-includes/class-wp-block-list.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-list.php/) ``` public function rewind() { reset( $this->blocks ); } ``` wordpress MO::make_entry( string $original, string $translation ): Translation_Entry MO::make\_entry( string $original, string $translation ): Translation\_Entry ============================================================================ Build a [Translation\_Entry](../translation_entry) from original string and translation strings, found in a MO file `$original` string Required original string to translate from MO file. Might contain 0x04 as context separator or 0x00 as singular/plural separator `$translation` string Required translation string from MO file. Might contain 0x00 as a plural translations separator [Translation\_Entry](../translation_entry) Entry instance. File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function &make_entry( $original, $translation ) { $entry = new Translation_Entry(); // Look for context, separated by \4. $parts = explode( "\4", $original ); if ( isset( $parts[1] ) ) { $original = $parts[1]; $entry->context = $parts[0]; } // Look for plural original. $parts = explode( "\0", $original ); $entry->singular = $parts[0]; if ( isset( $parts[1] ) ) { $entry->is_plural = true; $entry->plural = $parts[1]; } // Plural translations are also separated by \0. $entry->translations = explode( "\0", $translation ); return $entry; } ``` | Uses | Description | | --- | --- | | [Translation\_Entry::\_\_construct()](../translation_entry/__construct) wp-includes/pomo/entry.php | | | Used By | Description | | --- | --- | | [MO::import\_from\_reader()](import_from_reader) wp-includes/pomo/mo.php | | wordpress MO::import_from_reader( POMO_FileReader $reader ): bool MO::import\_from\_reader( POMO\_FileReader $reader ): bool ========================================================== `$reader` [POMO\_FileReader](../pomo_filereader) Required bool True if the import was successful, otherwise false. File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function import_from_reader( $reader ) { $endian_string = MO::get_byteorder( $reader->readint32() ); if ( false === $endian_string ) { return false; } $reader->setEndian( $endian_string ); $endian = ( 'big' === $endian_string ) ? 'N' : 'V'; $header = $reader->read( 24 ); if ( $reader->strlen( $header ) != 24 ) { return false; } // Parse header. $header = unpack( "{$endian}revision/{$endian}total/{$endian}originals_lengths_addr/{$endian}translations_lengths_addr/{$endian}hash_length/{$endian}hash_addr", $header ); if ( ! is_array( $header ) ) { return false; } // Support revision 0 of MO format specs, only. if ( 0 != $header['revision'] ) { return false; } // Seek to data blocks. $reader->seekto( $header['originals_lengths_addr'] ); // Read originals' indices. $originals_lengths_length = $header['translations_lengths_addr'] - $header['originals_lengths_addr']; if ( $originals_lengths_length != $header['total'] * 8 ) { return false; } $originals = $reader->read( $originals_lengths_length ); if ( $reader->strlen( $originals ) != $originals_lengths_length ) { return false; } // Read translations' indices. $translations_lengths_length = $header['hash_addr'] - $header['translations_lengths_addr']; if ( $translations_lengths_length != $header['total'] * 8 ) { return false; } $translations = $reader->read( $translations_lengths_length ); if ( $reader->strlen( $translations ) != $translations_lengths_length ) { return false; } // Transform raw data into set of indices. $originals = $reader->str_split( $originals, 8 ); $translations = $reader->str_split( $translations, 8 ); // Skip hash table. $strings_addr = $header['hash_addr'] + $header['hash_length'] * 4; $reader->seekto( $strings_addr ); $strings = $reader->read_all(); $reader->close(); for ( $i = 0; $i < $header['total']; $i++ ) { $o = unpack( "{$endian}length/{$endian}pos", $originals[ $i ] ); $t = unpack( "{$endian}length/{$endian}pos", $translations[ $i ] ); if ( ! $o || ! $t ) { return false; } // Adjust offset due to reading strings to separate space before. $o['pos'] -= $strings_addr; $t['pos'] -= $strings_addr; $original = $reader->substr( $strings, $o['pos'], $o['length'] ); $translation = $reader->substr( $strings, $t['pos'], $t['length'] ); if ( '' === $original ) { $this->set_headers( $this->make_headers( $translation ) ); } else { $entry = &$this->make_entry( $original, $translation ); $this->entries[ $entry->key() ] = &$entry; } } return true; } ``` | Uses | Description | | --- | --- | | [MO::get\_byteorder()](get_byteorder) wp-includes/pomo/mo.php | | | [MO::make\_entry()](make_entry) wp-includes/pomo/mo.php | Build a [Translation\_Entry](../translation_entry) from original string and translation strings, found in a MO file | | Used By | Description | | --- | --- | | [MO::import\_from\_file()](import_from_file) wp-includes/pomo/mo.php | Fills up with the entries from MO file $filename | wordpress MO::export_headers(): string MO::export\_headers(): string ============================= string File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function export_headers() { $exported = ''; foreach ( $this->headers as $header => $value ) { $exported .= "$header: $value\n"; } return $exported; } ``` | Used By | Description | | --- | --- | | [MO::export\_to\_file\_handle()](export_to_file_handle) wp-includes/pomo/mo.php | | wordpress MO::get_plural_forms_count(): int MO::get\_plural\_forms\_count(): int ==================================== int File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function get_plural_forms_count() { return $this->_nplurals; } ``` wordpress MO::get_byteorder( int $magic ): string|false MO::get\_byteorder( int $magic ): string|false ============================================== `$magic` int Required string|false File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function get_byteorder( $magic ) { // The magic is 0x950412de. // bug in PHP 5.0.2, see https://savannah.nongnu.org/bugs/?func=detailitem&item_id=10565 $magic_little = (int) - 1794895138; $magic_little_64 = (int) 2500072158; // 0xde120495 $magic_big = ( (int) - 569244523 ) & 0xFFFFFFFF; if ( $magic_little == $magic || $magic_little_64 == $magic ) { return 'little'; } elseif ( $magic_big == $magic ) { return 'big'; } else { return false; } } ``` | Used By | Description | | --- | --- | | [MO::import\_from\_reader()](import_from_reader) wp-includes/pomo/mo.php | | wordpress MO::export_to_file_handle( resource $fh ): true MO::export\_to\_file\_handle( resource $fh ): true ================================================== `$fh` resource Required true File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function export_to_file_handle( $fh ) { $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); ksort( $entries ); $magic = 0x950412de; $revision = 0; $total = count( $entries ) + 1; // All the headers are one entry. $originals_lengths_addr = 28; $translations_lengths_addr = $originals_lengths_addr + 8 * $total; $size_of_hash = 0; $hash_addr = $translations_lengths_addr + 8 * $total; $current_addr = $hash_addr; fwrite( $fh, pack( 'V*', $magic, $revision, $total, $originals_lengths_addr, $translations_lengths_addr, $size_of_hash, $hash_addr ) ); fseek( $fh, $originals_lengths_addr ); // Headers' msgid is an empty string. fwrite( $fh, pack( 'VV', 0, $current_addr ) ); $current_addr++; $originals_table = "\0"; $reader = new POMO_Reader(); foreach ( $entries as $entry ) { $originals_table .= $this->export_original( $entry ) . "\0"; $length = $reader->strlen( $this->export_original( $entry ) ); fwrite( $fh, pack( 'VV', $length, $current_addr ) ); $current_addr += $length + 1; // Account for the NULL byte after. } $exported_headers = $this->export_headers(); fwrite( $fh, pack( 'VV', $reader->strlen( $exported_headers ), $current_addr ) ); $current_addr += strlen( $exported_headers ) + 1; $translations_table = $exported_headers . "\0"; foreach ( $entries as $entry ) { $translations_table .= $this->export_translations( $entry ) . "\0"; $length = $reader->strlen( $this->export_translations( $entry ) ); fwrite( $fh, pack( 'VV', $length, $current_addr ) ); $current_addr += $length + 1; } fwrite( $fh, $originals_table ); fwrite( $fh, $translations_table ); return true; } ``` | Uses | Description | | --- | --- | | [POMO\_Reader::\_\_construct()](../pomo_reader/__construct) wp-includes/pomo/streams.php | PHP5 constructor. | | [MO::export\_original()](export_original) wp-includes/pomo/mo.php | | | [MO::export\_headers()](export_headers) wp-includes/pomo/mo.php | | | [MO::export\_translations()](export_translations) wp-includes/pomo/mo.php | | | Used By | Description | | --- | --- | | [MO::export\_to\_file()](export_to_file) wp-includes/pomo/mo.php | | | [MO::export()](export) wp-includes/pomo/mo.php | | wordpress MO::get_filename(): string MO::get\_filename(): string =========================== Returns the loaded MO file. string The loaded MO file. File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function get_filename() { return $this->filename; } ``` wordpress MO::import_from_file( string $filename ): bool MO::import\_from\_file( string $filename ): bool ================================================ Fills up with the entries from MO file $filename `$filename` string Required MO file to load bool True if the import from file was successful, otherwise false. File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function import_from_file( $filename ) { $reader = new POMO_FileReader( $filename ); if ( ! $reader->is_resource() ) { return false; } $this->filename = (string) $filename; return $this->import_from_reader( $reader ); } ``` | Uses | Description | | --- | --- | | [POMO\_FileReader::\_\_construct()](../pomo_filereader/__construct) wp-includes/pomo/streams.php | | | [MO::import\_from\_reader()](import_from_reader) wp-includes/pomo/mo.php | | | Used By | Description | | --- | --- | | [load\_textdomain()](../../functions/load_textdomain) wp-includes/l10n.php | Loads a .mo file into the text domain $domain. | wordpress MO::export_to_file( string $filename ): bool MO::export\_to\_file( string $filename ): bool ============================================== `$filename` string Required bool File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function export_to_file( $filename ) { $fh = fopen( $filename, 'wb' ); if ( ! $fh ) { return false; } $res = $this->export_to_file_handle( $fh ); fclose( $fh ); return $res; } ``` | Uses | Description | | --- | --- | | [MO::export\_to\_file\_handle()](export_to_file_handle) wp-includes/pomo/mo.php | |
programming_docs
wordpress MO::select_plural_form( int $count ): string MO::select\_plural\_form( int $count ): string ============================================== `$count` int Required string File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function select_plural_form( $count ) { return $this->gettext_select_plural_form( $count ); } ``` wordpress MO::is_entry_good_for_export( Translation_Entry $entry ): bool MO::is\_entry\_good\_for\_export( Translation\_Entry $entry ): bool =================================================================== `$entry` [Translation\_Entry](../translation_entry) Required bool File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function is_entry_good_for_export( $entry ) { if ( empty( $entry->translations ) ) { return false; } if ( ! array_filter( $entry->translations ) ) { return false; } return true; } ``` wordpress MO::export_original( Translation_Entry $entry ): string MO::export\_original( Translation\_Entry $entry ): string ========================================================= `$entry` [Translation\_Entry](../translation_entry) Required string File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function export_original( $entry ) { // TODO: Warnings for control characters. $exported = $entry->singular; if ( $entry->is_plural ) { $exported .= "\0" . $entry->plural; } if ( $entry->context ) { $exported = $entry->context . "\4" . $exported; } return $exported; } ``` | Used By | Description | | --- | --- | | [MO::export\_to\_file\_handle()](export_to_file_handle) wp-includes/pomo/mo.php | | wordpress MO::export(): string|false MO::export(): string|false ========================== string|false File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function export() { $tmp_fh = fopen( 'php://temp', 'r+' ); if ( ! $tmp_fh ) { return false; } $this->export_to_file_handle( $tmp_fh ); rewind( $tmp_fh ); return stream_get_contents( $tmp_fh ); } ``` | Uses | Description | | --- | --- | | [MO::export\_to\_file\_handle()](export_to_file_handle) wp-includes/pomo/mo.php | | wordpress MO::export_translations( Translation_Entry $entry ): string MO::export\_translations( Translation\_Entry $entry ): string ============================================================= `$entry` [Translation\_Entry](../translation_entry) Required string File: `wp-includes/pomo/mo.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/pomo/mo.php/) ``` public function export_translations( $entry ) { // TODO: Warnings for control characters. return $entry->is_plural ? implode( "\0", $entry->translations ) : $entry->translations[0]; } ``` | Used By | Description | | --- | --- | | [MO::export\_to\_file\_handle()](export_to_file_handle) wp-includes/pomo/mo.php | | wordpress WP_Query::is_comment_feed(): bool WP\_Query::is\_comment\_feed(): bool ==================================== Is the query for a comments feed? bool Whether the query is for a comments feed. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_comment_feed() { return (bool) $this->is_comment_feed; } ``` | Used By | Description | | --- | --- | | [get\_feed\_build\_date()](../../functions/get_feed_build_date) wp-includes/feed.php | Gets the UTC time of the most recently modified post from [WP\_Query](../wp_query). | | [is\_comment\_feed()](../../functions/is_comment_feed) wp-includes/query.php | Is the query for a comments feed? | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::parse_order( string $order ): string WP\_Query::parse\_order( string $order ): string ================================================ Parse an ‘order’ query variable and cast it to ASC or DESC as necessary. `$order` string Required The `'order'` query variable. string The sanitized `'order'` query variable. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` protected function parse_order( $order ) { if ( ! is_string( $order ) || empty( $order ) ) { return 'DESC'; } if ( 'ASC' === strtoupper( $order ) ) { return 'ASC'; } else { return 'DESC'; } } ``` | Used By | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Query::is_home(): bool WP\_Query::is\_home(): bool =========================== Is the query for the blog homepage? This is the page which shows the time based blog content of your site. Depends on the site’s "Front page displays" Reading Settings ‘show\_on\_front’ and ‘page\_for\_posts’. If you set a static page for the front page of your site, this function will return true only on the page you set as the "Posts page". * [WP\_Query::is\_front\_page()](../wp_query/is_front_page) bool Whether the query is for the blog homepage. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_home() { return (bool) $this->is_home; } ``` | Used By | Description | | --- | --- | | [WP\_Query::is\_front\_page()](is_front_page) wp-includes/class-wp-query.php | Is the query for the front page of the site? | | [is\_home()](../../functions/is_home) wp-includes/query.php | Determines whether the query is for the blog homepage. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_preview(): bool WP\_Query::is\_preview(): bool ============================== Is the query for a post or page preview? bool Whether the query is for a post or page preview. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_preview() { return (bool) $this->is_preview; } ``` | Used By | Description | | --- | --- | | [is\_preview()](../../functions/is_preview) wp-includes/query.php | Determines whether the query is for a post or page preview. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_category( int|string|int[]|string[] $category = '' ): bool WP\_Query::is\_category( int|string|int[]|string[] $category = '' ): bool ========================================================================= Is the query for an existing category archive page? If the $category parameter is specified, this function will additionally check if the query is for one of the categories specified. `$category` int|string|int[]|string[] Optional Category ID, name, slug, or array of such to check against. Default: `''` bool Whether the query is for an existing category archive page. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_category( $category = '' ) { if ( ! $this->is_category ) { return false; } if ( empty( $category ) ) { return true; } $cat_obj = $this->get_queried_object(); if ( ! $cat_obj ) { return false; } $category = array_map( 'strval', (array) $category ); if ( in_array( (string) $cat_obj->term_id, $category, true ) ) { return true; } elseif ( in_array( $cat_obj->name, $category, true ) ) { return true; } elseif ( in_array( $cat_obj->slug, $category, true ) ) { return true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | Used By | Description | | --- | --- | | [is\_category()](../../functions/is_category) wp-includes/query.php | Determines whether the query is for an existing category archive page. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::set_found_posts( array $q, string $limits ) WP\_Query::set\_found\_posts( array $q, string $limits ) ======================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Set up the amount of found posts and the number of pages (if limit clause was used) for the current query. `$q` array Required Query variables. `$limits` string Required LIMIT clauses of the query. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` private function set_found_posts( $q, $limits ) { global $wpdb; // Bail if posts is an empty array. Continue if posts is an empty string, // null, or false to accommodate caching plugins that fill posts later. if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) { return; } if ( ! empty( $limits ) ) { /** * Filters the query to run for retrieving the found posts. * * @since 2.1.0 * * @param string $found_posts_query The query to run to find the found posts. * @param WP_Query $query The WP_Query instance (passed by reference). */ $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ); $this->found_posts = (int) $wpdb->get_var( $found_posts_query ); } else { if ( is_array( $this->posts ) ) { $this->found_posts = count( $this->posts ); } else { if ( null === $this->posts ) { $this->found_posts = 0; } else { $this->found_posts = 1; } } } /** * Filters the number of found posts for the query. * * @since 2.1.0 * * @param int $found_posts The number of posts found. * @param WP_Query $query The WP_Query instance (passed by reference). */ $this->found_posts = (int) apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); if ( ! empty( $limits ) ) { $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); } } ``` [apply\_filters\_ref\_array( 'found\_posts', int $found\_posts, WP\_Query $query )](../../hooks/found_posts) Filters the number of found posts for the query. [apply\_filters\_ref\_array( 'found\_posts\_query', string $found\_posts\_query, WP\_Query $query )](../../hooks/found_posts_query) Filters the query to run for retrieving the found posts. | Uses | Description | | --- | --- | | [apply\_filters\_ref\_array()](../../functions/apply_filters_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook, specifying arguments in an array. | | [wpdb::get\_var()](../wpdb/get_var) wp-includes/class-wpdb.php | Retrieves one variable from the database. | | Used By | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | Version | Description | | --- | --- | | [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. | wordpress WP_Query::is_feed( string|string[] $feeds = '' ): bool WP\_Query::is\_feed( string|string[] $feeds = '' ): bool ======================================================== Is the query for a feed? `$feeds` string|string[] Optional Feed type or array of feed types to check against. Default: `''` bool Whether the query is for a feed. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_feed( $feeds = '' ) { if ( empty( $feeds ) || ! $this->is_feed ) { return (bool) $this->is_feed; } $qv = $this->get( 'feed' ); if ( 'feed' === $qv ) { $qv = get_default_feed(); } return in_array( $qv, (array) $feeds, true ); } ``` | Uses | Description | | --- | --- | | [WP\_Query::get()](get) wp-includes/class-wp-query.php | Retrieves the value of a query variable. | | [get\_default\_feed()](../../functions/get_default_feed) wp-includes/feed.php | Retrieves the default feed. | | Used By | Description | | --- | --- | | [WP\_Query::generate\_postdata()](generate_postdata) wp-includes/class-wp-query.php | Generate post data. | | [is\_feed()](../../functions/is_feed) wp-includes/query.php | Determines whether the query is for a feed. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::set_404() WP\_Query::set\_404() ===================== Sets the 404 property and saves whether query is feed. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function set_404() { $is_feed = $this->is_feed; $this->init_query_flags(); $this->is_404 = true; $this->is_feed = $is_feed; /** * Fires after a 404 is triggered. * * @since 5.5.0 * * @param WP_Query $query The WP_Query instance (passed by reference). */ do_action_ref_array( 'set_404', array( $this ) ); } ``` [do\_action\_ref\_array( 'set\_404', WP\_Query $query )](../../hooks/set_404) Fires after a 404 is triggered. | Uses | Description | | --- | --- | | [WP\_Query::init\_query\_flags()](init_query_flags) wp-includes/class-wp-query.php | Resets query flags to false. | | [do\_action\_ref\_array()](../../functions/do_action_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook, specifying arguments in an array. | | Used By | Description | | --- | --- | | [WP\_Sitemaps::render\_sitemaps()](../wp_sitemaps/render_sitemaps) wp-includes/sitemaps/class-wp-sitemaps.php | Renders sitemap templates based on rewrite rules. | | [WP::handle\_404()](../wp/handle_404) wp-includes/class-wp.php | Set the Headers for 404, if nothing is found for requested URL. | | [WP\_Query::parse\_query()](parse_query) wp-includes/class-wp-query.php | Parse a query string and set query type booleans. | | Version | Description | | --- | --- | | [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. | wordpress WP_Query::init() WP\_Query::init() ================= Initiates object properties and sets default values. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function init() { unset( $this->posts ); unset( $this->query ); $this->query_vars = array(); unset( $this->queried_object ); unset( $this->queried_object_id ); $this->post_count = 0; $this->current_post = -1; $this->in_the_loop = false; unset( $this->request ); unset( $this->post ); unset( $this->comments ); unset( $this->comment ); $this->comment_count = 0; $this->current_comment = -1; $this->found_posts = 0; $this->max_num_pages = 0; $this->max_num_comment_pages = 0; $this->init_query_flags(); } ``` | Uses | Description | | --- | --- | | [WP\_Query::init\_query\_flags()](init_query_flags) wp-includes/class-wp-query.php | Resets query flags to false. | | Used By | Description | | --- | --- | | [WP\_Query::query()](query) wp-includes/class-wp-query.php | Sets up the WordPress query by parsing query string. | | [WP\_Query::parse\_query()](parse_query) wp-includes/class-wp-query.php | Parse a query string and set query type booleans. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::parse_search_terms( string[] $terms ): string[] WP\_Query::parse\_search\_terms( string[] $terms ): string[] ============================================================ Check if the terms are suitable for searching. Uses an array of stopwords (terms) that are excluded from the separate term matching when searching for posts. The list of English stopwords is the approximate search engines list, and is translatable. `$terms` string[] Required Array of terms to check. string[] Terms that are not stopwords. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` protected function parse_search_terms( $terms ) { $strtolower = function_exists( 'mb_strtolower' ) ? 'mb_strtolower' : 'strtolower'; $checked = array(); $stopwords = $this->get_search_stopwords(); foreach ( $terms as $term ) { // Keep before/after spaces when term is for exact match. if ( preg_match( '/^".+"$/', $term ) ) { $term = trim( $term, "\"'" ); } else { $term = trim( $term, "\"' " ); } // Avoid single A-Z and single dashes. if ( ! $term || ( 1 === strlen( $term ) && preg_match( '/^[a-z\-]$/i', $term ) ) ) { continue; } if ( in_array( call_user_func( $strtolower, $term ), $stopwords, true ) ) { continue; } $checked[] = $term; } return $checked; } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_search\_stopwords()](get_search_stopwords) wp-includes/class-wp-query.php | Retrieve stopwords used when parsing search terms. | | Used By | Description | | --- | --- | | [WP\_Query::parse\_search()](parse_search) wp-includes/class-wp-query.php | Generates SQL for the WHERE clause based on passed search terms. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress WP_Query::get_queried_object_id(): int WP\_Query::get\_queried\_object\_id(): int ========================================== Retrieves the ID of the currently queried object. int File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function get_queried_object_id() { $this->get_queried_object(); if ( isset( $this->queried_object_id ) ) { return $this->queried_object_id; } return 0; } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | Used By | Description | | --- | --- | | [get\_queried\_object\_id()](../../functions/get_queried_object_id) wp-includes/query.php | Retrieves the ID of the currently queried object. | | [get\_body\_class()](../../functions/get_body_class) wp-includes/post-template.php | Retrieves an array of the class names for the body element. | | [redirect\_canonical()](../../functions/redirect_canonical) wp-includes/canonical.php | Redirects incoming links to the proper URL based on the site url. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |
programming_docs
wordpress WP_Query::is_page( int|string|int[]|string[] $page = '' ): bool WP\_Query::is\_page( int|string|int[]|string[] $page = '' ): bool ================================================================= Is the query for an existing single page? If the $page parameter is specified, this function will additionally check if the query is for one of the pages specified. * [WP\_Query::is\_single()](../wp_query/is_single) * [WP\_Query::is\_singular()](../wp_query/is_singular) `$page` int|string|int[]|string[] Optional Page ID, title, slug, path, or array of such to check against. Default: `''` bool Whether the query is for an existing single page. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_page( $page = '' ) { if ( ! $this->is_page ) { return false; } if ( empty( $page ) ) { return true; } $page_obj = $this->get_queried_object(); if ( ! $page_obj ) { return false; } $page = array_map( 'strval', (array) $page ); if ( in_array( (string) $page_obj->ID, $page, true ) ) { return true; } elseif ( in_array( $page_obj->post_title, $page, true ) ) { return true; } elseif ( in_array( $page_obj->post_name, $page, true ) ) { return true; } else { foreach ( $page as $pagepath ) { if ( ! strpos( $pagepath, '/' ) ) { continue; } $pagepath_obj = get_page_by_path( $pagepath ); if ( $pagepath_obj && ( $pagepath_obj->ID == $page_obj->ID ) ) { return true; } } } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | [get\_page\_by\_path()](../../functions/get_page_by_path) wp-includes/post.php | Retrieves a page given its path. | | Used By | Description | | --- | --- | | [WP\_Query::generate\_postdata()](generate_postdata) wp-includes/class-wp-query.php | Generate post data. | | [WP\_Query::is\_privacy\_policy()](is_privacy_policy) wp-includes/class-wp-query.php | Is the query for the Privacy Policy page? | | [WP::register\_globals()](../wp/register_globals) wp-includes/class-wp.php | Set up the WordPress Globals. | | [WP\_Query::is\_front\_page()](is_front_page) wp-includes/class-wp-query.php | Is the query for the front page of the site? | | [is\_page()](../../functions/is_page) wp-includes/query.php | Determines whether the query is for an existing single page. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::have_comments(): bool WP\_Query::have\_comments(): bool ================================= Whether there are more comments available. Automatically rewinds comments when finished. bool True if comments are available, false if no more comments. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function have_comments() { if ( $this->current_comment + 1 < $this->comment_count ) { return true; } elseif ( $this->current_comment + 1 == $this->comment_count ) { $this->rewind_comments(); } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Query::rewind\_comments()](rewind_comments) wp-includes/class-wp-query.php | Rewind the comments, resets the comment index and comment to first. | | Used By | Description | | --- | --- | | [have\_comments()](../../functions/have_comments) wp-includes/query.php | Determines whether current WordPress query has comments to loop over. | | Version | Description | | --- | --- | | [2.2.0](https://developer.wordpress.org/reference/since/2.2.0/) | Introduced. | wordpress WP_Query::the_comment() WP\_Query::the\_comment() ========================= Sets up the current comment. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function the_comment() { global $comment; $comment = $this->next_comment(); if ( 0 == $this->current_comment ) { /** * Fires once the comment loop is started. * * @since 2.2.0 */ do_action( 'comment_loop_start' ); } } ``` [do\_action( 'comment\_loop\_start' )](../../hooks/comment_loop_start) Fires once the comment loop is started. | Uses | Description | | --- | --- | | [WP\_Query::next\_comment()](next_comment) wp-includes/class-wp-query.php | Iterate current comment index and return [WP\_Comment](../wp_comment) object. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Used By | Description | | --- | --- | | [the\_comment()](../../functions/the_comment) wp-includes/query.php | Iterate comment index in the comment loop. | | Version | Description | | --- | --- | | [2.2.0](https://developer.wordpress.org/reference/since/2.2.0/) | Introduced. | wordpress WP_Query::is_time(): bool WP\_Query::is\_time(): bool =========================== Is the query for a specific time? bool Whether the query is for a specific time. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_time() { return (bool) $this->is_time; } ``` | Used By | Description | | --- | --- | | [is\_time()](../../functions/is_time) wp-includes/query.php | Determines whether the query is for a specific time. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_search(): bool WP\_Query::is\_search(): bool ============================= Is the query for a search? bool Whether the query is for a search. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_search() { return (bool) $this->is_search; } ``` | Used By | Description | | --- | --- | | [is\_search()](../../functions/is_search) wp-includes/query.php | Determines whether the query is for a search. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::rewind_comments() WP\_Query::rewind\_comments() ============================= Rewind the comments, resets the comment index and comment to first. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function rewind_comments() { $this->current_comment = -1; if ( $this->comment_count > 0 ) { $this->comment = $this->comments[0]; } } ``` | Used By | Description | | --- | --- | | [WP\_Query::have\_comments()](have_comments) wp-includes/class-wp-query.php | Whether there are more comments available. | | Version | Description | | --- | --- | | [2.2.0](https://developer.wordpress.org/reference/since/2.2.0/) | Introduced. | wordpress WP_Query::rewind_posts() WP\_Query::rewind\_posts() ========================== Rewind the posts and reset post index. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function rewind_posts() { $this->current_post = -1; if ( $this->post_count > 0 ) { $this->post = $this->posts[0]; } } ``` | Used By | Description | | --- | --- | | [WP\_Query::have\_posts()](have_posts) wp-includes/class-wp-query.php | Determines whether there are more posts available in the loop. | | [rewind\_posts()](../../functions/rewind_posts) wp-includes/query.php | Rewind the loop posts. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::is_attachment( int|string|int[]|string[] $attachment = '' ): bool WP\_Query::is\_attachment( int|string|int[]|string[] $attachment = '' ): bool ============================================================================= Is the query for an existing attachment page? `$attachment` int|string|int[]|string[] Optional Attachment ID, title, slug, or array of such to check against. Default: `''` bool Whether the query is for an existing attachment page. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_attachment( $attachment = '' ) { if ( ! $this->is_attachment ) { return false; } if ( empty( $attachment ) ) { return true; } $attachment = array_map( 'strval', (array) $attachment ); $post_obj = $this->get_queried_object(); if ( ! $post_obj ) { return false; } if ( in_array( (string) $post_obj->ID, $attachment, true ) ) { return true; } elseif ( in_array( $post_obj->post_title, $attachment, true ) ) { return true; } elseif ( in_array( $post_obj->post_name, $attachment, true ) ) { return true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | Used By | Description | | --- | --- | | [is\_attachment()](../../functions/is_attachment) wp-includes/query.php | Determines whether the query is for an existing attachment page. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_comments_popup(): false WP\_Query::is\_comments\_popup(): false ======================================= This method has been deprecated. Whether the current URL is within the comments popup window. false Always returns false. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_comments_popup() { _deprecated_function( __FUNCTION__, '4.5.0' ); return false; } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | This method has been deprecated. | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::lazyload_comment_meta( mixed $check, int $comment_id ): mixed WP\_Query::lazyload\_comment\_meta( mixed $check, int $comment\_id ): mixed =========================================================================== This method has been deprecated. See [wp\_queue\_comments\_for\_comment\_meta\_lazyload()](../../functions/wp_queue_comments_for_comment_meta_lazyload) instead. Lazyload comment meta for comments in the loop. `$check` mixed Required `$comment_id` int Required mixed File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function lazyload_comment_meta( $check, $comment_id ) { _deprecated_function( __METHOD__, '4.5.0' ); return $check; } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | See [wp\_queue\_comments\_for\_comment\_meta\_lazyload()](../../functions/wp_queue_comments_for_comment_meta_lazyload) . | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Query::parse_search_order( array $q ): string WP\_Query::parse\_search\_order( array $q ): string =================================================== Generates SQL for the ORDER BY condition based on passed search terms. `$q` array Required Query variables. string ORDER BY clause. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` protected function parse_search_order( &$q ) { global $wpdb; if ( $q['search_terms_count'] > 1 ) { $num_terms = count( $q['search_orderby_title'] ); // If the search terms contain negative queries, don't bother ordering by sentence matches. $like = ''; if ( ! preg_match( '/(?:\s|^)\-/', $q['s'] ) ) { $like = '%' . $wpdb->esc_like( $q['s'] ) . '%'; } $search_orderby = ''; // Sentence match in 'post_title'. if ( $like ) { $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_title LIKE %s THEN 1 ", $like ); } // Sanity limit, sort as sentence when more than 6 terms // (few searches are longer than 6 terms and most titles are not). if ( $num_terms < 7 ) { // All words in title. $search_orderby .= 'WHEN ' . implode( ' AND ', $q['search_orderby_title'] ) . ' THEN 2 '; // Any word in title, not needed when $num_terms == 1. if ( $num_terms > 1 ) { $search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 3 '; } } // Sentence match in 'post_content' and 'post_excerpt'. if ( $like ) { $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_excerpt LIKE %s THEN 4 ", $like ); $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_content LIKE %s THEN 5 ", $like ); } if ( $search_orderby ) { $search_orderby = '(CASE ' . $search_orderby . 'ELSE 6 END)'; } } else { // Single word or sentence search. $search_orderby = reset( $q['search_orderby_title'] ) . ' DESC'; } return $search_orderby; } ``` | Uses | Description | | --- | --- | | [wpdb::esc\_like()](../wpdb/esc_like) wp-includes/class-wpdb.php | First half of escaping for `LIKE` special characters `%` and `_` before preparing for SQL. | | [wpdb::prepare()](../wpdb/prepare) wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. | | Used By | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress WP_Query::__call( string $name, array $arguments ): mixed|false WP\_Query::\_\_call( string $name, array $arguments ): mixed|false ================================================================== Make private/protected methods readable for backward compatibility. `$name` string Required Method to call. `$arguments` array Required Arguments to pass when calling. mixed|false Return value of the callback, false otherwise. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function __call( $name, $arguments ) { if ( in_array( $name, $this->compat_methods, true ) ) { return $this->$name( ...$arguments ); } return false; } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Query::setup_postdata( WP_Post|object|int $post ): true WP\_Query::setup\_postdata( WP\_Post|object|int $post ): true ============================================================= Set up global post data. `$post` [WP\_Post](../wp_post)|object|int Required [WP\_Post](../wp_post) instance or Post ID/object. true True when finished. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function setup_postdata( $post ) { global $id, $authordata, $currentday, $currentmonth, $page, $pages, $multipage, $more, $numpages; if ( ! ( $post instanceof WP_Post ) ) { $post = get_post( $post ); } if ( ! $post ) { return; } $elements = $this->generate_postdata( $post ); if ( false === $elements ) { return; } $id = $elements['id']; $authordata = $elements['authordata']; $currentday = $elements['currentday']; $currentmonth = $elements['currentmonth']; $page = $elements['page']; $pages = $elements['pages']; $multipage = $elements['multipage']; $more = $elements['more']; $numpages = $elements['numpages']; /** * Fires once the post data has been set up. * * @since 2.8.0 * @since 4.1.0 Introduced `$query` parameter. * * @param WP_Post $post The Post object (passed by reference). * @param WP_Query $query The current Query object (passed by reference). */ do_action_ref_array( 'the_post', array( &$post, &$this ) ); return true; } ``` [do\_action\_ref\_array( 'the\_post', WP\_Post $post, WP\_Query $query )](../../hooks/the_post) Fires once the post data has been set up. | Uses | Description | | --- | --- | | [WP\_Query::generate\_postdata()](generate_postdata) wp-includes/class-wp-query.php | Generate post data. | | [do\_action\_ref\_array()](../../functions/do_action_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook, specifying arguments in an array. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Used By | Description | | --- | --- | | [WP\_Query::reset\_postdata()](reset_postdata) wp-includes/class-wp-query.php | After looping through a nested query, this function restores the $post global to the current post in this query. | | [WP\_Query::the\_post()](the_post) wp-includes/class-wp-query.php | Sets up the current post. | | [setup\_postdata()](../../functions/setup_postdata) wp-includes/query.php | Set up global post data. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Added the ability to pass a post ID to `$post`. | | [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | Introduced. | wordpress WP_Query::parse_orderby( string $orderby ): string|false WP\_Query::parse\_orderby( string $orderby ): string|false ========================================================== Converts the given orderby alias (if allowed) to a properly-prefixed value. `$orderby` string Required Alias for the field to order by. string|false Table-prefixed value to used in the ORDER clause. False otherwise. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` protected function parse_orderby( $orderby ) { global $wpdb; // Used to filter values. $allowed_keys = array( 'post_name', 'post_author', 'post_date', 'post_title', 'post_modified', 'post_parent', 'post_type', 'name', 'author', 'date', 'title', 'modified', 'parent', 'type', 'ID', 'menu_order', 'comment_count', 'rand', 'post__in', 'post_parent__in', 'post_name__in', ); $primary_meta_key = ''; $primary_meta_query = false; $meta_clauses = $this->meta_query->get_clauses(); if ( ! empty( $meta_clauses ) ) { $primary_meta_query = reset( $meta_clauses ); if ( ! empty( $primary_meta_query['key'] ) ) { $primary_meta_key = $primary_meta_query['key']; $allowed_keys[] = $primary_meta_key; } $allowed_keys[] = 'meta_value'; $allowed_keys[] = 'meta_value_num'; $allowed_keys = array_merge( $allowed_keys, array_keys( $meta_clauses ) ); } // If RAND() contains a seed value, sanitize and add to allowed keys. $rand_with_seed = false; if ( preg_match( '/RAND\(([0-9]+)\)/i', $orderby, $matches ) ) { $orderby = sprintf( 'RAND(%s)', (int) $matches[1] ); $allowed_keys[] = $orderby; $rand_with_seed = true; } if ( ! in_array( $orderby, $allowed_keys, true ) ) { return false; } $orderby_clause = ''; switch ( $orderby ) { case 'post_name': case 'post_author': case 'post_date': case 'post_title': case 'post_modified': case 'post_parent': case 'post_type': case 'ID': case 'menu_order': case 'comment_count': $orderby_clause = "{$wpdb->posts}.{$orderby}"; break; case 'rand': $orderby_clause = 'RAND()'; break; case $primary_meta_key: case 'meta_value': if ( ! empty( $primary_meta_query['type'] ) ) { $orderby_clause = "CAST({$primary_meta_query['alias']}.meta_value AS {$primary_meta_query['cast']})"; } else { $orderby_clause = "{$primary_meta_query['alias']}.meta_value"; } break; case 'meta_value_num': $orderby_clause = "{$primary_meta_query['alias']}.meta_value+0"; break; case 'post__in': if ( ! empty( $this->query_vars['post__in'] ) ) { $orderby_clause = "FIELD({$wpdb->posts}.ID," . implode( ',', array_map( 'absint', $this->query_vars['post__in'] ) ) . ')'; } break; case 'post_parent__in': if ( ! empty( $this->query_vars['post_parent__in'] ) ) { $orderby_clause = "FIELD( {$wpdb->posts}.post_parent," . implode( ', ', array_map( 'absint', $this->query_vars['post_parent__in'] ) ) . ' )'; } break; case 'post_name__in': if ( ! empty( $this->query_vars['post_name__in'] ) ) { $post_name__in = array_map( 'sanitize_title_for_query', $this->query_vars['post_name__in'] ); $post_name__in_string = "'" . implode( "','", $post_name__in ) . "'"; $orderby_clause = "FIELD( {$wpdb->posts}.post_name," . $post_name__in_string . ' )'; } break; default: if ( array_key_exists( $orderby, $meta_clauses ) ) { // $orderby corresponds to a meta_query clause. $meta_clause = $meta_clauses[ $orderby ]; $orderby_clause = "CAST({$meta_clause['alias']}.meta_value AS {$meta_clause['cast']})"; } elseif ( $rand_with_seed ) { $orderby_clause = $orderby; } else { // Default: order by post field. $orderby_clause = "{$wpdb->posts}.post_" . sanitize_key( $orderby ); } break; } return $orderby_clause; } ``` | Uses | Description | | --- | --- | | [sanitize\_key()](../../functions/sanitize_key) wp-includes/formatting.php | Sanitizes a string key. | | Used By | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. |
programming_docs
wordpress WP_Query::the_post() WP\_Query::the\_post() ====================== Sets up the current post. Retrieves the next post, sets up the post, sets the ‘in the loop’ property to true. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function the_post() { global $post; if ( ! $this->in_the_loop ) { update_post_author_caches( $this->posts ); } $this->in_the_loop = true; if ( -1 == $this->current_post ) { // Loop has just started. /** * Fires once the loop is started. * * @since 2.0.0 * * @param WP_Query $query The WP_Query instance (passed by reference). */ do_action_ref_array( 'loop_start', array( &$this ) ); } $post = $this->next_post(); $this->setup_postdata( $post ); } ``` [do\_action\_ref\_array( 'loop\_start', WP\_Query $query )](../../hooks/loop_start) Fires once the loop is started. | Uses | Description | | --- | --- | | [update\_post\_author\_caches()](../../functions/update_post_author_caches) wp-includes/post.php | Updates post author user caches for a list of post objects. | | [WP\_Query::setup\_postdata()](setup_postdata) wp-includes/class-wp-query.php | Set up global post data. | | [WP\_Query::next\_post()](next_post) wp-includes/class-wp-query.php | Set up the next post and iterate current post index. | | [do\_action\_ref\_array()](../../functions/do_action_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook, specifying arguments in an array. | | Used By | Description | | --- | --- | | [the\_post()](../../functions/the_post) wp-includes/query.php | Iterate the post index in the loop. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::__get( string $name ): mixed WP\_Query::\_\_get( string $name ): mixed ========================================= Make private properties readable for backward compatibility. `$name` string Required Property to get. mixed Property. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function __get( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { return $this->$name; } } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Query::get_queried_object(): WP_Term|WP_Post_Type|WP_Post|WP_User|null WP\_Query::get\_queried\_object(): WP\_Term|WP\_Post\_Type|WP\_Post|WP\_User|null ================================================================================= Retrieves the currently queried object. If queried object is not set, then the queried object will be set from the category, tag, taxonomy, posts page, single post, page, or author query variable. After it is set up, it will be returned. [WP\_Term](../wp_term)|[WP\_Post\_Type](../wp_post_type)|[WP\_Post](../wp_post)|[WP\_User](../wp_user)|null The queried object. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function get_queried_object() { if ( isset( $this->queried_object ) ) { return $this->queried_object; } $this->queried_object = null; $this->queried_object_id = null; if ( $this->is_category || $this->is_tag || $this->is_tax ) { if ( $this->is_category ) { $cat = $this->get( 'cat' ); $category_name = $this->get( 'category_name' ); if ( $cat ) { $term = get_term( $cat, 'category' ); } elseif ( $category_name ) { $term = get_term_by( 'slug', $category_name, 'category' ); } } elseif ( $this->is_tag ) { $tag_id = $this->get( 'tag_id' ); $tag = $this->get( 'tag' ); if ( $tag_id ) { $term = get_term( $tag_id, 'post_tag' ); } elseif ( $tag ) { $term = get_term_by( 'slug', $tag, 'post_tag' ); } } else { // For other tax queries, grab the first term from the first clause. if ( ! empty( $this->tax_query->queried_terms ) ) { $queried_taxonomies = array_keys( $this->tax_query->queried_terms ); $matched_taxonomy = reset( $queried_taxonomies ); $query = $this->tax_query->queried_terms[ $matched_taxonomy ]; if ( ! empty( $query['terms'] ) ) { if ( 'term_id' === $query['field'] ) { $term = get_term( reset( $query['terms'] ), $matched_taxonomy ); } else { $term = get_term_by( $query['field'], reset( $query['terms'] ), $matched_taxonomy ); } } } } if ( ! empty( $term ) && ! is_wp_error( $term ) ) { $this->queried_object = $term; $this->queried_object_id = (int) $term->term_id; if ( $this->is_category && 'category' === $this->queried_object->taxonomy ) { _make_cat_compat( $this->queried_object ); } } } elseif ( $this->is_post_type_archive ) { $post_type = $this->get( 'post_type' ); if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); } $this->queried_object = get_post_type_object( $post_type ); } elseif ( $this->is_posts_page ) { $page_for_posts = get_option( 'page_for_posts' ); $this->queried_object = get_post( $page_for_posts ); $this->queried_object_id = (int) $this->queried_object->ID; } elseif ( $this->is_singular && ! empty( $this->post ) ) { $this->queried_object = $this->post; $this->queried_object_id = (int) $this->post->ID; } elseif ( $this->is_author ) { $author = (int) $this->get( 'author' ); $author_name = $this->get( 'author_name' ); if ( $author ) { $this->queried_object_id = $author; } elseif ( $author_name ) { $user = get_user_by( 'slug', $author_name ); if ( $user ) { $this->queried_object_id = $user->ID; } } $this->queried_object = get_userdata( $this->queried_object_id ); } return $this->queried_object; } ``` | Uses | Description | | --- | --- | | [get\_user\_by()](../../functions/get_user_by) wp-includes/pluggable.php | Retrieves user info by a given field. | | [WP\_Query::get()](get) wp-includes/class-wp-query.php | Retrieves the value of a query variable. | | [\_make\_cat\_compat()](../../functions/_make_cat_compat) wp-includes/category.php | Updates category structure to old pre-2.3 from new taxonomy structure. | | [get\_term\_by()](../../functions/get_term_by) wp-includes/taxonomy.php | Gets all term data from database by term field and data. | | [get\_userdata()](../../functions/get_userdata) wp-includes/pluggable.php | Retrieves user info by user ID. | | [get\_term()](../../functions/get_term) wp-includes/taxonomy.php | Gets all term data from database by term ID. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [WP\_Query::is\_page()](is_page) wp-includes/class-wp-query.php | Is the query for an existing single page? | | [WP\_Query::is\_single()](is_single) wp-includes/class-wp-query.php | Is the query for an existing single post? | | [WP\_Query::is\_singular()](is_singular) wp-includes/class-wp-query.php | Is the query for an existing single post of any post type (post, attachment, page, custom post types)? | | [WP\_Query::get\_queried\_object\_id()](get_queried_object_id) wp-includes/class-wp-query.php | Retrieves the ID of the currently queried object. | | [WP\_Query::is\_attachment()](is_attachment) wp-includes/class-wp-query.php | Is the query for an existing attachment page? | | [WP\_Query::is\_author()](is_author) wp-includes/class-wp-query.php | Is the query for an existing author archive page? | | [WP\_Query::is\_category()](is_category) wp-includes/class-wp-query.php | Is the query for an existing category archive page? | | [WP\_Query::is\_tag()](is_tag) wp-includes/class-wp-query.php | Is the query for an existing tag archive page? | | [WP\_Query::is\_tax()](is_tax) wp-includes/class-wp-query.php | Is the query for an existing custom taxonomy archive page? | | [get\_queried\_object()](../../functions/get_queried_object) wp-includes/query.php | Retrieves the currently queried object. | | [\_wp\_menu\_item\_classes\_by\_context()](../../functions/_wp_menu_item_classes_by_context) wp-includes/nav-menu-template.php | Adds the class property classes for the current context, if applicable. | | [get\_body\_class()](../../functions/get_body_class) wp-includes/post-template.php | Retrieves an array of the class names for the body element. | | [redirect\_canonical()](../../functions/redirect_canonical) wp-includes/canonical.php | Redirects incoming links to the proper URL based on the site url. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::get_search_stopwords(): string[] WP\_Query::get\_search\_stopwords(): string[] ============================================= Retrieve stopwords used when parsing search terms. string[] Stopwords. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` protected function get_search_stopwords() { if ( isset( $this->stopwords ) ) { return $this->stopwords; } /* * translators: This is a comma-separated list of very common words that should be excluded from a search, * like a, an, and the. These are usually called "stopwords". You should not simply translate these individual * words into your language. Instead, look for and provide commonly accepted stopwords in your language. */ $words = explode( ',', _x( 'about,an,are,as,at,be,by,com,for,from,how,in,is,it,of,on,or,that,the,this,to,was,what,when,where,who,will,with,www', 'Comma-separated list of search stopwords in your language' ) ); $stopwords = array(); foreach ( $words as $word ) { $word = trim( $word, "\r\n\t " ); if ( $word ) { $stopwords[] = $word; } } /** * Filters stopwords used when parsing search terms. * * @since 3.7.0 * * @param string[] $stopwords Array of stopwords. */ $this->stopwords = apply_filters( 'wp_search_stopwords', $stopwords ); return $this->stopwords; } ``` [apply\_filters( 'wp\_search\_stopwords', string[] $stopwords )](../../hooks/wp_search_stopwords) Filters stopwords used when parsing search terms. | Uses | Description | | --- | --- | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Query::parse\_search\_terms()](parse_search_terms) wp-includes/class-wp-query.php | Check if the terms are suitable for searching. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress WP_Query::is_front_page(): bool WP\_Query::is\_front\_page(): bool ================================== Is the query for the front page of the site? This is for what is displayed at your site’s main URL. Depends on the site’s "Front page displays" Reading Settings ‘show\_on\_front’ and ‘page\_on\_front’. If you set a static page for the front page of your site, this function will return true when viewing that page. Otherwise the same as @see [WP\_Query::is\_home()](is_home) bool Whether the query is for the front page of the site. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_front_page() { // Most likely case. if ( 'posts' === get_option( 'show_on_front' ) && $this->is_home() ) { return true; } elseif ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) { return true; } else { return false; } } ``` | Uses | Description | | --- | --- | | [WP\_Query::is\_home()](is_home) wp-includes/class-wp-query.php | Is the query for the blog homepage? | | [WP\_Query::is\_page()](is_page) wp-includes/class-wp-query.php | Is the query for an existing single page? | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Used By | Description | | --- | --- | | [is\_front\_page()](../../functions/is_front_page) wp-includes/query.php | Determines whether the query is for the front page of the site. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_single( int|string|int[]|string[] $post = '' ): bool WP\_Query::is\_single( int|string|int[]|string[] $post = '' ): bool =================================================================== Is the query for an existing single post? Works for any post type excluding pages. If the $post parameter is specified, this function will additionally check if the query is for one of the Posts specified. * [WP\_Query::is\_page()](../wp_query/is_page) * [WP\_Query::is\_singular()](../wp_query/is_singular) `$post` int|string|int[]|string[] Optional Post ID, title, slug, path, or array of such to check against. Default: `''` bool Whether the query is for an existing single post. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_single( $post = '' ) { if ( ! $this->is_single ) { return false; } if ( empty( $post ) ) { return true; } $post_obj = $this->get_queried_object(); if ( ! $post_obj ) { return false; } $post = array_map( 'strval', (array) $post ); if ( in_array( (string) $post_obj->ID, $post, true ) ) { return true; } elseif ( in_array( $post_obj->post_title, $post, true ) ) { return true; } elseif ( in_array( $post_obj->post_name, $post, true ) ) { return true; } else { foreach ( $post as $postpath ) { if ( ! strpos( $postpath, '/' ) ) { continue; } $postpath_obj = get_page_by_path( $postpath, OBJECT, $post_obj->post_type ); if ( $postpath_obj && ( $postpath_obj->ID == $post_obj->ID ) ) { return true; } } } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | [get\_page\_by\_path()](../../functions/get_page_by_path) wp-includes/post.php | Retrieves a page given its path. | | Used By | Description | | --- | --- | | [WP\_Query::generate\_postdata()](generate_postdata) wp-includes/class-wp-query.php | Generate post data. | | [WP::register\_globals()](../wp/register_globals) wp-includes/class-wp.php | Set up the WordPress Globals. | | [is\_single()](../../functions/is_single) wp-includes/query.php | Determines whether the query is for an existing single post. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_favicon(): bool WP\_Query::is\_favicon(): bool ============================== Is the query for the favicon.ico file? bool Whether the query is for the favicon.ico file. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_favicon() { return (bool) $this->is_favicon; } ``` | Used By | Description | | --- | --- | | [is\_favicon()](../../functions/is_favicon) wp-includes/query.php | Is the query for the favicon.ico file? | | Version | Description | | --- | --- | | [5.4.0](https://developer.wordpress.org/reference/since/5.4.0/) | Introduced. | wordpress WP_Query::have_posts(): bool WP\_Query::have\_posts(): bool ============================== Determines whether there are more posts available in the loop. Calls the [‘loop\_end’](../../hooks/loop_end) action when the loop is complete. bool True if posts are available, false if end of the loop. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function have_posts() { if ( $this->current_post + 1 < $this->post_count ) { return true; } elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0 ) { /** * Fires once the loop has ended. * * @since 2.0.0 * * @param WP_Query $query The WP_Query instance (passed by reference). */ do_action_ref_array( 'loop_end', array( &$this ) ); // Do some cleaning up after the loop. $this->rewind_posts(); } elseif ( 0 === $this->post_count ) { /** * Fires if no results are found in a post query. * * @since 4.9.0 * * @param WP_Query $query The WP_Query instance. */ do_action( 'loop_no_results', $this ); } $this->in_the_loop = false; return false; } ``` [do\_action\_ref\_array( 'loop\_end', WP\_Query $query )](../../hooks/loop_end) Fires once the loop has ended. [do\_action( 'loop\_no\_results', WP\_Query $query )](../../hooks/loop_no_results) Fires if no results are found in a post query. | Uses | Description | | --- | --- | | [WP\_Query::rewind\_posts()](rewind_posts) wp-includes/class-wp-query.php | Rewind the posts and reset post index. | | [do\_action\_ref\_array()](../../functions/do_action_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook, specifying arguments in an array. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Used By | Description | | --- | --- | | [get\_feed\_build\_date()](../../functions/get_feed_build_date) wp-includes/feed.php | Gets the UTC time of the most recently modified post from [WP\_Query](../wp_query). | | [have\_posts()](../../functions/have_posts) wp-includes/query.php | Determines whether current WordPress query has posts to loop over. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::next_comment(): WP_Comment WP\_Query::next\_comment(): WP\_Comment ======================================= Iterate current comment index and return [WP\_Comment](../wp_comment) object. [WP\_Comment](../wp_comment) Comment object. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function next_comment() { $this->current_comment++; /** @var WP_Comment */ $this->comment = $this->comments[ $this->current_comment ]; return $this->comment; } ``` | Used By | Description | | --- | --- | | [WP\_Query::the\_comment()](the_comment) wp-includes/class-wp-query.php | Sets up the current comment. | | Version | Description | | --- | --- | | [2.2.0](https://developer.wordpress.org/reference/since/2.2.0/) | Introduced. | wordpress WP_Query::is_robots(): bool WP\_Query::is\_robots(): bool ============================= Is the query for the robots.txt file? bool Whether the query is for the robots.txt file. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_robots() { return (bool) $this->is_robots; } ``` | Used By | Description | | --- | --- | | [is\_robots()](../../functions/is_robots) wp-includes/query.php | Is the query for the robots.txt file? | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |
programming_docs
wordpress WP_Query::is_trackback(): bool WP\_Query::is\_trackback(): bool ================================ Is the query for a trackback endpoint call? bool Whether the query is for a trackback endpoint call. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_trackback() { return (bool) $this->is_trackback; } ``` | Used By | Description | | --- | --- | | [is\_trackback()](../../functions/is_trackback) wp-includes/query.php | Determines whether the query is for a trackback endpoint call. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::fill_query_vars( array $query_vars ): array WP\_Query::fill\_query\_vars( array $query\_vars ): array ========================================================= Fills in the query variables, which do not exist within the parameter. `$query_vars` array Required Defined query variables. array Complete query variables with undefined ones filled in empty. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function fill_query_vars( $query_vars ) { $keys = array( 'error', 'm', 'p', 'post_parent', 'subpost', 'subpost_id', 'attachment', 'attachment_id', 'name', 'pagename', 'page_id', 'second', 'minute', 'hour', 'day', 'monthnum', 'year', 'w', 'category_name', 'tag', 'cat', 'tag_id', 'author', 'author_name', 'feed', 'tb', 'paged', 'meta_key', 'meta_value', 'preview', 's', 'sentence', 'title', 'fields', 'menu_order', 'embed', ); foreach ( $keys as $key ) { if ( ! isset( $query_vars[ $key ] ) ) { $query_vars[ $key ] = ''; } } $array_keys = array( 'category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', 'post_name__in', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'post_parent__in', 'post_parent__not_in', 'author__in', 'author__not_in', ); foreach ( $array_keys as $key ) { if ( ! isset( $query_vars[ $key ] ) ) { $query_vars[ $key ] = array(); } } return $query_vars; } ``` | Used By | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | [WP\_Query::parse\_query()](parse_query) wp-includes/class-wp-query.php | Parse a query string and set query type booleans. | | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Removed the `comments_popup` public query variable. | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress WP_Query::__isset( string $name ): bool WP\_Query::\_\_isset( string $name ): bool ========================================== Make private properties checkable for backward compatibility. `$name` string Required Property to check if set. bool Whether the property is set. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function __isset( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { return isset( $this->$name ); } } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Query::is_year(): bool WP\_Query::is\_year(): bool =========================== Is the query for an existing year archive? bool Whether the query is for an existing year archive. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_year() { return (bool) $this->is_year; } ``` | Used By | Description | | --- | --- | | [is\_year()](../../functions/is_year) wp-includes/query.php | Determines whether the query is for an existing year archive. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::lazyload_term_meta( mixed $check, int $term_id ): mixed WP\_Query::lazyload\_term\_meta( mixed $check, int $term\_id ): mixed ===================================================================== This method has been deprecated. See [wp\_queue\_posts\_for\_term\_meta\_lazyload()](../../functions/wp_queue_posts_for_term_meta_lazyload) instead. Lazyload term meta for posts in the loop. `$check` mixed Required `$term_id` int Required mixed File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function lazyload_term_meta( $check, $term_id ) { _deprecated_function( __METHOD__, '4.5.0' ); return $check; } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | See [wp\_queue\_posts\_for\_term\_meta\_lazyload()](../../functions/wp_queue_posts_for_term_meta_lazyload) . | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Query::query( string|array $query ): WP_Post[]|int[] WP\_Query::query( string|array $query ): WP\_Post[]|int[] ========================================================= Sets up the WordPress query by parsing query string. * [WP\_Query::parse\_query()](../wp_query/parse_query): for all available arguments. `$query` string|array Required URL query string or array of query arguments. [WP\_Post](../wp_post)[]|int[] Array of post objects or post IDs. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function query( $query ) { $this->init(); $this->query = wp_parse_args( $query ); $this->query_vars = $this->query; return $this->get_posts(); } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | [WP\_Query::init()](init) wp-includes/class-wp-query.php | Initiates object properties and sets default values. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Used By | Description | | --- | --- | | [WP\_Query::\_\_construct()](__construct) wp-includes/class-wp-query.php | Constructor. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::is_tax( string|string[] $taxonomy = '', int|string|int[]|string[] $term = '' ): bool WP\_Query::is\_tax( string|string[] $taxonomy = '', int|string|int[]|string[] $term = '' ): bool ================================================================================================ Is the query for an existing custom taxonomy archive page? If the $taxonomy parameter is specified, this function will additionally check if the query is for that specific $taxonomy. If the $term parameter is specified in addition to the $taxonomy parameter, this function will additionally check if the query is for one of the terms specified. `$taxonomy` string|string[] Optional Taxonomy slug or slugs to check against. Default: `''` `$term` int|string|int[]|string[] Optional Term ID, name, slug, or array of such to check against. Default: `''` bool Whether the query is for an existing custom taxonomy archive page. True for custom taxonomy archive pages, false for built-in taxonomies (category and tag archives). File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_tax( $taxonomy = '', $term = '' ) { global $wp_taxonomies; if ( ! $this->is_tax ) { return false; } if ( empty( $taxonomy ) ) { return true; } $queried_object = $this->get_queried_object(); $tax_array = array_intersect( array_keys( $wp_taxonomies ), (array) $taxonomy ); $term_array = (array) $term; // Check that the taxonomy matches. if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array, true ) ) ) { return false; } // Only a taxonomy provided. if ( empty( $term ) ) { return true; } return isset( $queried_object->term_id ) && count( array_intersect( array( $queried_object->term_id, $queried_object->name, $queried_object->slug ), $term_array ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | Used By | Description | | --- | --- | | [is\_tax()](../../functions/is_tax) wp-includes/query.php | Determines whether the query is for an existing custom taxonomy archive page. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_main_query(): bool WP\_Query::is\_main\_query(): bool ================================== Is the query the main query? bool Whether the query is the main query. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_main_query() { global $wp_the_query; return $wp_the_query === $this; } ``` | Used By | Description | | --- | --- | | [\_resolve\_template\_for\_new\_post()](../../functions/_resolve_template_for_new_post) wp-includes/block-template.php | Sets the current [WP\_Query](../wp_query) to return auto-draft posts. | | [WP\_Query::parse\_query()](parse_query) wp-includes/class-wp-query.php | Parse a query string and set query type booleans. | | [WP\_Query::parse\_search()](parse_search) wp-includes/class-wp-query.php | Generates SQL for the WHERE clause based on passed search terms. | | [is\_main\_query()](../../functions/is_main_query) wp-includes/query.php | Determines whether the query is the main query. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Query::parse_query_vars() WP\_Query::parse\_query\_vars() =============================== Reparse the query vars. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function parse_query_vars() { $this->parse_query(); } ``` | Uses | Description | | --- | --- | | [WP\_Query::parse\_query()](parse_query) wp-includes/class-wp-query.php | Parse a query string and set query type booleans. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::init_query_flags() WP\_Query::init\_query\_flags() =============================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Resets query flags to false. The query flags are what page info WordPress was able to figure out. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` private function init_query_flags() { $this->is_single = false; $this->is_preview = false; $this->is_page = false; $this->is_archive = false; $this->is_date = false; $this->is_year = false; $this->is_month = false; $this->is_day = false; $this->is_time = false; $this->is_author = false; $this->is_category = false; $this->is_tag = false; $this->is_tax = false; $this->is_search = false; $this->is_feed = false; $this->is_comment_feed = false; $this->is_trackback = false; $this->is_home = false; $this->is_privacy_policy = false; $this->is_404 = false; $this->is_paged = false; $this->is_admin = false; $this->is_attachment = false; $this->is_singular = false; $this->is_robots = false; $this->is_favicon = false; $this->is_posts_page = false; $this->is_post_type_archive = false; } ``` | Used By | Description | | --- | --- | | [WP\_Query::set\_404()](set_404) wp-includes/class-wp-query.php | Sets the 404 property and saves whether query is feed. | | [WP\_Query::init()](init) wp-includes/class-wp-query.php | Initiates object properties and sets default values. | | Version | Description | | --- | --- | | [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. | wordpress WP_Query::parse_query( string|array $query = '' ) WP\_Query::parse\_query( string|array $query = '' ) =================================================== Parse a query string and set query type booleans. `$query` string|array Optional Array or string of Query parameters. * `attachment_id`intAttachment post ID. Used for `'attachment'` post\_type. * `author`int|stringAuthor ID, or comma-separated list of IDs. * `author_name`stringUser `'user_nicename'`. * `author__in`int[]An array of author IDs to query from. * `author__not_in`int[]An array of author IDs not to query from. * `cache_results`boolWhether to cache post information. Default true. * `cat`int|stringCategory ID or comma-separated list of IDs (this or any children). * `category__and`int[]An array of category IDs (AND in). * `category__in`int[]An array of category IDs (OR in, no children). * `category__not_in`int[]An array of category IDs (NOT in). * `category_name`stringUse category slug (not name, this or any children). * `comment_count`array|intFilter results by comment count. Provide an integer to match comment count exactly. Provide an array with integer `'value'` and `'compare'` operator (`'='`, `'!='`, `'>'`, `'>='`, `'<'`, `'<='` ) to compare against comment\_count in a specific way. * `comment_status`stringComment status. * `comments_per_page`intThe number of comments to return per page. Default `'comments_per_page'` option. * `date_query`arrayAn associative array of [WP\_Date\_Query](../wp_date_query) arguments. See [WP\_Date\_Query::\_\_construct()](../wp_date_query/__construct). * `day`intDay of the month. Accepts numbers 1-31. * `exact`boolWhether to search by exact keyword. Default false. * `fields`stringPost fields to query for. Accepts: + `''` Returns an array of complete post objects (`WP_Post[]`). + `'ids'` Returns an array of post IDs (`int[]`). + `'id=>parent'` Returns an associative array of parent post IDs, keyed by post ID (`int[]`). Default `''`. * `hour`intHour of the day. Accepts numbers 0-23. * `ignore_sticky_posts`int|boolWhether to ignore sticky posts or not. Setting this to false excludes stickies from `'post__in'`. Accepts `1|true`, `0|false`. Default false. * `m`intCombination YearMonth. Accepts any four-digit year and month numbers 01-12. * `meta_key`string|string[]Meta key or keys to filter by. * `meta_value`string|string[]Meta value or values to filter by. * `meta_compare`stringMySQL operator used for comparing the meta value. See [WP\_Meta\_Query::\_\_construct()](../wp_meta_query/__construct) for accepted values and default value. * `meta_compare_key`stringMySQL operator used for comparing the meta key. See [WP\_Meta\_Query::\_\_construct()](../wp_meta_query/__construct) for accepted values and default value. * `meta_type`stringMySQL data type that the meta\_value column will be CAST to for comparisons. See [WP\_Meta\_Query::\_\_construct()](../wp_meta_query/__construct) for accepted values and default value. * `meta_type_key`stringMySQL data type that the meta\_key column will be CAST to for comparisons. See [WP\_Meta\_Query::\_\_construct()](../wp_meta_query/__construct) for accepted values and default value. * `meta_query`arrayAn associative array of [WP\_Meta\_Query](../wp_meta_query) arguments. See [WP\_Meta\_Query::\_\_construct()](../wp_meta_query/__construct) for accepted values. * `menu_order`intThe menu order of the posts. * `minute`intMinute of the hour. Accepts numbers 0-59. * `monthnum`intThe two-digit month. Accepts numbers 1-12. * `name`stringPost slug. * `nopaging`boolShow all posts (true) or paginate (false). Default false. * `no_found_rows`boolWhether to skip counting the total rows found. Enabling can improve performance. Default false. * `offset`intThe number of posts to offset before retrieval. * `order`stringDesignates ascending or descending order of posts. Default `'DESC'`. Accepts `'ASC'`, `'DESC'`. * `orderby`string|arraySort retrieved posts by parameter. One or more options may be passed. To use `'meta_value'`, or `'meta_value_num'`, `'meta_key=keyname'` must be also be defined. To sort by a specific `$meta_query` clause, use that clause's array key. Accepts: + `'none'` + `'name'` + `'author'` + `'date'` + `'title'` + `'modified'` + `'menu_order'` + `'parent'` + `'ID'` + `'rand'` + `'relevance'` + `'RAND(x)'` (where `'x'` is an integer seed value) + `'comment_count'` + `'meta_value'` + `'meta_value_num'` + `'post__in'` + `'post_name__in'` + `'post_parent__in'` + The array keys of `$meta_query`. Default is `'date'`, except when a search is being performed, when the default is `'relevance'`. * `p`intPost ID. * `page`intShow the number of posts that would show up on page X of a static front page. * `paged`intThe number of the current page. * `page_id`intPage ID. * `pagename`stringPage slug. * `perm`stringShow posts if user has the appropriate capability. * `ping_status`stringPing status. * `post__in`int[]An array of post IDs to retrieve, sticky posts will be included. * `post__not_in`int[]An array of post IDs not to retrieve. Note: a string of comma- separated IDs will NOT work. * `post_mime_type`stringThe mime type of the post. Used for `'attachment'` post\_type. * `post_name__in`string[]An array of post slugs that results must match. * `post_parent`intPage ID to retrieve child pages for. Use 0 to only retrieve top-level pages. * `post_parent__in`int[]An array containing parent page IDs to query child pages from. * `post_parent__not_in`int[]An array containing parent page IDs not to query child pages from. * `post_type`string|string[]A post type slug (string) or array of post type slugs. Default `'any'` if using `'tax_query'`. * `post_status`string|string[]A post status (string) or array of post statuses. * `posts_per_page`intThe number of posts to query for. Use -1 to request all posts. * `posts_per_archive_page`intThe number of posts to query for by archive page. Overrides `'posts_per_page'` when [is\_archive()](../../functions/is_archive) , or [is\_search()](../../functions/is_search) are true. * `s`stringSearch keyword(s). Prepending a term with a hyphen will exclude posts matching that term. Eg, 'pillow -sofa' will return posts containing `'pillow'` but not `'sofa'`. The character used for exclusion can be modified using the the `'wp_query_search_exclusion_prefix'` filter. * `second`intSecond of the minute. Accepts numbers 0-59. * `sentence`boolWhether to search by phrase. Default false. * `suppress_filters`boolWhether to suppress filters. Default false. * `tag`stringTag slug. Comma-separated (either), Plus-separated (all). * `tag__and`int[]An array of tag IDs (AND in). * `tag__in`int[]An array of tag IDs (OR in). * `tag__not_in`int[]An array of tag IDs (NOT in). * `tag_id`intTag id or comma-separated list of IDs. * `tag_slug__and`string[]An array of tag slugs (AND in). * `tag_slug__in`string[]An array of tag slugs (OR in). unless `'ignore_sticky_posts'` is true. Note: a string of comma-separated IDs will NOT work. * `tax_query`arrayAn associative array of [WP\_Tax\_Query](../wp_tax_query) arguments. See [WP\_Tax\_Query::\_\_construct()](../wp_tax_query/__construct). * `title`stringPost title. * `update_post_meta_cache`boolWhether to update the post meta cache. Default true. * `update_post_term_cache`boolWhether to update the post term cache. Default true. * `update_menu_item_cache`boolWhether to update the menu item cache. Default false. * `lazy_load_term_meta`boolWhether to lazy-load term meta. Setting to false will disable cache priming for term meta, so that each [get\_term\_meta()](../../functions/get_term_meta) call will hit the database. Defaults to the value of `$update_post_term_cache`. * `w`intThe week number of the year. Accepts numbers 0-53. * `year`intThe four-digit year. Accepts any four-digit year. Default: `''` File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function parse_query( $query = '' ) { if ( ! empty( $query ) ) { $this->init(); $this->query = wp_parse_args( $query ); $this->query_vars = $this->query; } elseif ( ! isset( $this->query ) ) { $this->query = $this->query_vars; } $this->query_vars = $this->fill_query_vars( $this->query_vars ); $qv = &$this->query_vars; $this->query_vars_changed = true; if ( ! empty( $qv['robots'] ) ) { $this->is_robots = true; } elseif ( ! empty( $qv['favicon'] ) ) { $this->is_favicon = true; } if ( ! is_scalar( $qv['p'] ) || (int) $qv['p'] < 0 ) { $qv['p'] = 0; $qv['error'] = '404'; } else { $qv['p'] = (int) $qv['p']; } $qv['page_id'] = is_scalar( $qv['page_id'] ) ? absint( $qv['page_id'] ) : 0; $qv['year'] = is_scalar( $qv['year'] ) ? absint( $qv['year'] ) : 0; $qv['monthnum'] = is_scalar( $qv['monthnum'] ) ? absint( $qv['monthnum'] ) : 0; $qv['day'] = is_scalar( $qv['day'] ) ? absint( $qv['day'] ) : 0; $qv['w'] = is_scalar( $qv['w'] ) ? absint( $qv['w'] ) : 0; $qv['m'] = is_scalar( $qv['m'] ) ? preg_replace( '|[^0-9]|', '', $qv['m'] ) : ''; $qv['paged'] = is_scalar( $qv['paged'] ) ? absint( $qv['paged'] ) : 0; $qv['cat'] = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // Array or comma-separated list of positive or negative integers. $qv['author'] = is_scalar( $qv['author'] ) ? preg_replace( '|[^0-9,-]|', '', $qv['author'] ) : ''; // Comma-separated list of positive or negative integers. $qv['pagename'] = is_scalar( $qv['pagename'] ) ? trim( $qv['pagename'] ) : ''; $qv['name'] = is_scalar( $qv['name'] ) ? trim( $qv['name'] ) : ''; $qv['title'] = is_scalar( $qv['title'] ) ? trim( $qv['title'] ) : ''; if ( is_scalar( $qv['hour'] ) && '' !== $qv['hour'] ) { $qv['hour'] = absint( $qv['hour'] ); } else { $qv['hour'] = ''; } if ( is_scalar( $qv['minute'] ) && '' !== $qv['minute'] ) { $qv['minute'] = absint( $qv['minute'] ); } else { $qv['minute'] = ''; } if ( is_scalar( $qv['second'] ) && '' !== $qv['second'] ) { $qv['second'] = absint( $qv['second'] ); } else { $qv['second'] = ''; } if ( is_scalar( $qv['menu_order'] ) && '' !== $qv['menu_order'] ) { $qv['menu_order'] = absint( $qv['menu_order'] ); } else { $qv['menu_order'] = ''; } // Fairly large, potentially too large, upper bound for search string lengths. if ( ! is_scalar( $qv['s'] ) || ( ! empty( $qv['s'] ) && strlen( $qv['s'] ) > 1600 ) ) { $qv['s'] = ''; } // Compat. Map subpost to attachment. if ( is_scalar( $qv['subpost'] ) && '' != $qv['subpost'] ) { $qv['attachment'] = $qv['subpost']; } if ( is_scalar( $qv['subpost_id'] ) && '' != $qv['subpost_id'] ) { $qv['attachment_id'] = $qv['subpost_id']; } $qv['attachment_id'] = is_scalar( $qv['attachment_id'] ) ? absint( $qv['attachment_id'] ) : 0; if ( ( '' !== $qv['attachment'] ) || ! empty( $qv['attachment_id'] ) ) { $this->is_single = true; $this->is_attachment = true; } elseif ( '' !== $qv['name'] ) { $this->is_single = true; } elseif ( $qv['p'] ) { $this->is_single = true; } elseif ( '' !== $qv['pagename'] || ! empty( $qv['page_id'] ) ) { $this->is_page = true; $this->is_single = false; } else { // Look for archive queries. Dates, categories, authors, search, post type archives. if ( isset( $this->query['s'] ) ) { $this->is_search = true; } if ( '' !== $qv['second'] ) { $this->is_time = true; $this->is_date = true; } if ( '' !== $qv['minute'] ) { $this->is_time = true; $this->is_date = true; } if ( '' !== $qv['hour'] ) { $this->is_time = true; $this->is_date = true; } if ( $qv['day'] ) { if ( ! $this->is_date ) { $date = sprintf( '%04d-%02d-%02d', $qv['year'], $qv['monthnum'], $qv['day'] ); if ( $qv['monthnum'] && $qv['year'] && ! wp_checkdate( $qv['monthnum'], $qv['day'], $qv['year'], $date ) ) { $qv['error'] = '404'; } else { $this->is_day = true; $this->is_date = true; } } } if ( $qv['monthnum'] ) { if ( ! $this->is_date ) { if ( 12 < $qv['monthnum'] ) { $qv['error'] = '404'; } else { $this->is_month = true; $this->is_date = true; } } } if ( $qv['year'] ) { if ( ! $this->is_date ) { $this->is_year = true; $this->is_date = true; } } if ( $qv['m'] ) { $this->is_date = true; if ( strlen( $qv['m'] ) > 9 ) { $this->is_time = true; } elseif ( strlen( $qv['m'] ) > 7 ) { $this->is_day = true; } elseif ( strlen( $qv['m'] ) > 5 ) { $this->is_month = true; } else { $this->is_year = true; } } if ( $qv['w'] ) { $this->is_date = true; } $this->query_vars_hash = false; $this->parse_tax_query( $qv ); foreach ( $this->tax_query->queries as $tax_query ) { if ( ! is_array( $tax_query ) ) { continue; } if ( isset( $tax_query['operator'] ) && 'NOT IN' !== $tax_query['operator'] ) { switch ( $tax_query['taxonomy'] ) { case 'category': $this->is_category = true; break; case 'post_tag': $this->is_tag = true; break; default: $this->is_tax = true; } } } unset( $tax_query ); if ( empty( $qv['author'] ) || ( '0' == $qv['author'] ) ) { $this->is_author = false; } else { $this->is_author = true; } if ( '' !== $qv['author_name'] ) { $this->is_author = true; } if ( ! empty( $qv['post_type'] ) && ! is_array( $qv['post_type'] ) ) { $post_type_obj = get_post_type_object( $qv['post_type'] ); if ( ! empty( $post_type_obj->has_archive ) ) { $this->is_post_type_archive = true; } } if ( $this->is_post_type_archive || $this->is_date || $this->is_author || $this->is_category || $this->is_tag || $this->is_tax ) { $this->is_archive = true; } } if ( '' != $qv['feed'] ) { $this->is_feed = true; } if ( '' != $qv['embed'] ) { $this->is_embed = true; } if ( '' != $qv['tb'] ) { $this->is_trackback = true; } if ( '' != $qv['paged'] && ( (int) $qv['paged'] > 1 ) ) { $this->is_paged = true; } // If we're previewing inside the write screen. if ( '' != $qv['preview'] ) { $this->is_preview = true; } if ( is_admin() ) { $this->is_admin = true; } if ( false !== strpos( $qv['feed'], 'comments-' ) ) { $qv['feed'] = str_replace( 'comments-', '', $qv['feed'] ); $qv['withcomments'] = 1; } $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment; if ( $this->is_feed && ( ! empty( $qv['withcomments'] ) || ( empty( $qv['withoutcomments'] ) && $this->is_singular ) ) ) { $this->is_comment_feed = true; } if ( ! ( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || ( defined( 'REST_REQUEST' ) && REST_REQUEST && $this->is_main_query() ) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots || $this->is_favicon ) ) { $this->is_home = true; } // Correct `is_*` for 'page_on_front' and 'page_for_posts'. if ( $this->is_home && 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) { $_query = wp_parse_args( $this->query ); // 'pagename' can be set and empty depending on matched rewrite rules. Ignore an empty 'pagename'. if ( isset( $_query['pagename'] ) && '' === $_query['pagename'] ) { unset( $_query['pagename'] ); } unset( $_query['embed'] ); if ( empty( $_query ) || ! array_diff( array_keys( $_query ), array( 'preview', 'page', 'paged', 'cpage' ) ) ) { $this->is_page = true; $this->is_home = false; $qv['page_id'] = get_option( 'page_on_front' ); // Correct <!--nextpage--> for 'page_on_front'. if ( ! empty( $qv['paged'] ) ) { $qv['page'] = $qv['paged']; unset( $qv['paged'] ); } } } if ( '' !== $qv['pagename'] ) { $this->queried_object = get_page_by_path( $qv['pagename'] ); if ( $this->queried_object && 'attachment' === $this->queried_object->post_type ) { if ( preg_match( '/^[^%]*%(?:postname)%/', get_option( 'permalink_structure' ) ) ) { // See if we also have a post with the same slug. $post = get_page_by_path( $qv['pagename'], OBJECT, 'post' ); if ( $post ) { $this->queried_object = $post; $this->is_page = false; $this->is_single = true; } } } if ( ! empty( $this->queried_object ) ) { $this->queried_object_id = (int) $this->queried_object->ID; } else { unset( $this->queried_object ); } if ( 'page' === get_option( 'show_on_front' ) && isset( $this->queried_object_id ) && get_option( 'page_for_posts' ) == $this->queried_object_id ) { $this->is_page = false; $this->is_home = true; $this->is_posts_page = true; } if ( isset( $this->queried_object_id ) && get_option( 'wp_page_for_privacy_policy' ) == $this->queried_object_id ) { $this->is_privacy_policy = true; } } if ( $qv['page_id'] ) { if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) == $qv['page_id'] ) { $this->is_page = false; $this->is_home = true; $this->is_posts_page = true; } if ( get_option( 'wp_page_for_privacy_policy' ) == $qv['page_id'] ) { $this->is_privacy_policy = true; } } if ( ! empty( $qv['post_type'] ) ) { if ( is_array( $qv['post_type'] ) ) { $qv['post_type'] = array_map( 'sanitize_key', $qv['post_type'] ); } else { $qv['post_type'] = sanitize_key( $qv['post_type'] ); } } if ( ! empty( $qv['post_status'] ) ) { if ( is_array( $qv['post_status'] ) ) { $qv['post_status'] = array_map( 'sanitize_key', $qv['post_status'] ); } else { $qv['post_status'] = preg_replace( '|[^a-z0-9_,-]|', '', $qv['post_status'] ); } } if ( $this->is_posts_page && ( ! isset( $qv['withcomments'] ) || ! $qv['withcomments'] ) ) { $this->is_comment_feed = false; } $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment; // Done correcting `is_*` for 'page_on_front' and 'page_for_posts'. if ( '404' == $qv['error'] ) { $this->set_404(); } $this->is_embed = $this->is_embed && ( $this->is_singular || $this->is_404 ); $this->query_vars_hash = md5( serialize( $this->query_vars ) ); $this->query_vars_changed = false; /** * Fires after the main query vars have been parsed. * * @since 1.5.0 * * @param WP_Query $query The WP_Query instance (passed by reference). */ do_action_ref_array( 'parse_query', array( &$this ) ); } ``` [do\_action\_ref\_array( 'parse\_query', WP\_Query $query )](../../hooks/parse_query) Fires after the main query vars have been parsed. | Uses | Description | | --- | --- | | [WP\_Query::is\_main\_query()](is_main_query) wp-includes/class-wp-query.php | Is the query the main query? | | [WP\_Query::set\_404()](set_404) wp-includes/class-wp-query.php | Sets the 404 property and saves whether query is feed. | | [WP\_Query::init()](init) wp-includes/class-wp-query.php | Initiates object properties and sets default values. | | [WP\_Query::fill\_query\_vars()](fill_query_vars) wp-includes/class-wp-query.php | Fills in the query variables, which do not exist within the parameter. | | [WP\_Query::parse\_tax\_query()](parse_tax_query) wp-includes/class-wp-query.php | Parses various taxonomy related query vars. | | [wp\_checkdate()](../../functions/wp_checkdate) wp-includes/functions.php | Tests if the supplied date is valid for the Gregorian calendar. | | [do\_action\_ref\_array()](../../functions/do_action_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook, specifying arguments in an array. | | [get\_page\_by\_path()](../../functions/get_page_by_path) wp-includes/post.php | Retrieves a page given its path. | | [sanitize\_key()](../../functions/sanitize_key) wp-includes/formatting.php | Sanitizes a string key. | | [is\_admin()](../../functions/is_admin) wp-includes/load.php | Determines whether the current request is for an administrative interface page. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | Used By | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | [WP\_Query::parse\_query\_vars()](parse_query_vars) wp-includes/class-wp-query.php | Reparse the query vars. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced the `$update_menu_item_cache` parameter. | | [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced the `$meta_type_key` parameter. | | [5.1.0](https://developer.wordpress.org/reference/since/5.1.0/) | Introduced the `$meta_compare_key` parameter. | | [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced the `$comment_count` parameter. | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Added `'post_name__in'` support for `$orderby`. Introduced the `$lazy_load_term_meta` argument. | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Removed the `$comments_popup` parameter. Introduced the `$comment_status` and `$ping_status` parameters. Introduced `RAND(x)` syntax for `$orderby`, which allows an integer seed value to random sorts. | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced `$post_name__in` and `$title` parameters. `$s` was updated to support excluded search terms, by prepending a hyphen. | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Introduced the ability to order by specific clauses of a `$meta_query`, by passing the clause's array key to `$orderby`. | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |
programming_docs
wordpress WP_Query::next_post(): WP_Post WP\_Query::next\_post(): WP\_Post ================================= Set up the next post and iterate current post index. [WP\_Post](../wp_post) Next post. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function next_post() { $this->current_post++; /** @var WP_Post */ $this->post = $this->posts[ $this->current_post ]; return $this->post; } ``` | Used By | Description | | --- | --- | | [start\_wp()](../../functions/start_wp) wp-includes/deprecated.php | Sets up the WordPress Loop. | | [WP\_Query::the\_post()](the_post) wp-includes/class-wp-query.php | Sets up the current post. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::__construct( string|array $query = '' ) WP\_Query::\_\_construct( string|array $query = '' ) ==================================================== Constructor. Sets up the WordPress query, if parameter is not empty. * [WP\_Query::parse\_query()](../wp_query/parse_query): for all available arguments. `$query` string|array Optional URL query string or array of vars. Default: `''` File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function __construct( $query = '' ) { if ( ! empty( $query ) ) { $this->query( $query ); } } ``` | Uses | Description | | --- | --- | | [WP\_Query::query()](query) wp-includes/class-wp-query.php | Sets up the WordPress query by parsing query string. | | Used By | Description | | --- | --- | | [\_wp\_build\_title\_and\_description\_for\_single\_post\_type\_block\_template()](../../functions/_wp_build_title_and_description_for_single_post_type_block_template) wp-includes/block-template-utils.php | Builds the title and description of a post-specific template based on the underlying referenced post. | | [wp\_get\_latest\_revision\_id\_and\_total\_count()](../../functions/wp_get_latest_revision_id_and_total_count) wp-includes/revision.php | Returns the latest revision ID and count of revisions for a post. | | [WP\_Theme\_JSON\_Resolver::get\_user\_data\_from\_wp\_global\_styles()](../wp_theme_json_resolver/get_user_data_from_wp_global_styles) wp-includes/class-wp-theme-json-resolver.php | Returns the custom post type that contains the user’s origin config for the active theme or a void array if none are found. | | [wp\_filter\_wp\_template\_unique\_post\_slug()](../../functions/wp_filter_wp_template_unique_post_slug) wp-includes/theme-templates.php | Generates a unique slug for templates. | | [get\_block\_templates()](../../functions/get_block_templates) wp-includes/block-template-utils.php | Retrieves a list of unified template objects based on a query. | | [get\_block\_template()](../../functions/get_block_template) wp-includes/block-template-utils.php | Retrieves a single unified template object using its id. | | [WP\_Sitemaps\_Posts::get\_url\_list()](../wp_sitemaps_posts/get_url_list) wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php | Gets a URL list for a post type sitemap. | | [WP\_Sitemaps\_Posts::get\_max\_num\_pages()](../wp_sitemaps_posts/get_max_num_pages) wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php | Gets the max number of pages available for the object type. | | [WP\_REST\_Post\_Search\_Handler::search\_items()](../wp_rest_post_search_handler/search_items) wp-includes/rest-api/search/class-wp-rest-post-search-handler.php | Searches the object type content for a given search request. | | [wp\_create\_user\_request()](../../functions/wp_create_user_request) wp-includes/user.php | Creates and logs a user request to perform a specific action. | | [wp\_media\_personal\_data\_exporter()](../../functions/wp_media_personal_data_exporter) wp-includes/media.php | Finds and exports attachments associated with an email address. | | [WP\_Privacy\_Requests\_Table::prepare\_items()](../wp_privacy_requests_table/prepare_items) wp-admin/includes/class-wp-privacy-requests-table.php | Prepare items to output. | | [\_wp\_personal\_data\_cleanup\_requests()](../../functions/_wp_personal_data_cleanup_requests) wp-admin/includes/privacy-tools.php | Cleans up failed and expired requests before displaying the list table. | | [WP\_Embed::find\_oembed\_post\_id()](../wp_embed/find_oembed_post_id) wp-includes/class-wp-embed.php | Finds the oEmbed cache post ID for a given cache key. | | [WP\_Customize\_Manager::import\_theme\_starter\_content()](../wp_customize_manager/import_theme_starter_content) wp-includes/class-wp-customize-manager.php | Imports theme starter content into the customized state. | | [WP\_Customize\_Manager::find\_changeset\_post\_id()](../wp_customize_manager/find_changeset_post_id) wp-includes/class-wp-customize-manager.php | Finds the changeset post ID for a given changeset UUID. | | [wp\_get\_custom\_css\_post()](../../functions/wp_get_custom_css_post) wp-includes/theme.php | Fetches the `custom_css` post for a given theme. | | [WP\_REST\_Revisions\_Controller::get\_items()](../wp_rest_revisions_controller/get_items) wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php | Gets a collection of revisions. | | [WP\_REST\_Posts\_Controller::get\_items()](../wp_rest_posts_controller/get_items) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves a collection of posts. | | [WP\_Customize\_Nav\_Menus::search\_available\_items\_query()](../wp_customize_nav_menus/search_available_items_query) wp-includes/class-wp-customize-nav-menus.php | Performs post queries for available-item searching. | | [wp\_dashboard\_recent\_posts()](../../functions/wp_dashboard_recent_posts) wp-admin/includes/dashboard.php | Generates Publishing Soon and Recently Published sections. | | [wp\_ajax\_query\_attachments()](../../functions/wp_ajax_query_attachments) wp-admin/includes/ajax-actions.php | Ajax handler for querying attachments. | | [\_wp\_ajax\_menu\_quick\_search()](../../functions/_wp_ajax_menu_quick_search) wp-admin/includes/nav-menu.php | Prints the appropriate response to a menu quick search. | | [wp\_nav\_menu\_item\_post\_type\_meta\_box()](../../functions/wp_nav_menu_item_post_type_meta_box) wp-admin/includes/nav-menu.php | Displays a meta box for a post type menu item. | | [query\_posts()](../../functions/query_posts) wp-includes/query.php | Sets up The Loop with query parameters. | | [WP\_Widget\_Recent\_Posts::widget()](../wp_widget_recent_posts/widget) wp-includes/widgets/class-wp-widget-recent-posts.php | Outputs the content for the current Recent Posts widget instance. | | [get\_page\_by\_title()](../../functions/get_page_by_title) wp-includes/post.php | Retrieves a page given its title. | | [get\_posts()](../../functions/get_posts) wp-includes/post.php | Retrieves an array of the latest posts, or posts matching the given criteria. | | [url\_to\_postid()](../../functions/url_to_postid) wp-includes/rewrite.php | Examines a URL and try to determine the post ID it represents. | | [wp\_get\_associated\_nav\_menu\_items()](../../functions/wp_get_associated_nav_menu_items) wp-includes/nav-menu.php | Returns the menu items associated with a particular object. | | [\_WP\_Editors::wp\_link\_query()](../_wp_editors/wp_link_query) wp-includes/class-wp-editor.php | Performs post queries for internal linking. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::is_404(): bool WP\_Query::is\_404(): bool ========================== Is the query a 404 (returns no results)? bool Whether the query is a 404 error. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_404() { return (bool) $this->is_404; } ``` | Used By | Description | | --- | --- | | [is\_404()](../../functions/is_404) wp-includes/query.php | Determines whether the query has resulted in a 404 (returns no results). | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_month(): bool WP\_Query::is\_month(): bool ============================ Is the query for an existing month archive? bool Whether the query is for an existing month archive. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_month() { return (bool) $this->is_month; } ``` | Used By | Description | | --- | --- | | [is\_month()](../../functions/is_month) wp-includes/query.php | Determines whether the query is for an existing month archive. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_embed(): bool WP\_Query::is\_embed(): bool ============================ Is the query for an embedded post? bool Whether the query is for an embedded post. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_embed() { return (bool) $this->is_embed; } ``` | Used By | Description | | --- | --- | | [is\_embed()](../../functions/is_embed) wp-includes/query.php | Is the query for an embedded post? | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Query::is_date(): bool WP\_Query::is\_date(): bool =========================== Is the query for an existing date archive? bool Whether the query is for an existing date archive. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_date() { return (bool) $this->is_date; } ``` | Used By | Description | | --- | --- | | [is\_date()](../../functions/is_date) wp-includes/query.php | Determines whether the query is for an existing date archive. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_singular( string|string[] $post_types = '' ): bool WP\_Query::is\_singular( string|string[] $post\_types = '' ): bool ================================================================== Is the query for an existing single post of any post type (post, attachment, page, custom post types)? If the $post\_types parameter is specified, this function will additionally check if the query is for one of the Posts Types specified. * [WP\_Query::is\_page()](../wp_query/is_page) * [WP\_Query::is\_single()](../wp_query/is_single) `$post_types` string|string[] Optional Post type or array of post types to check against. Default: `''` bool Whether the query is for an existing single post or any of the given post types. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_singular( $post_types = '' ) { if ( empty( $post_types ) || ! $this->is_singular ) { return (bool) $this->is_singular; } $post_obj = $this->get_queried_object(); if ( ! $post_obj ) { return false; } return in_array( $post_obj->post_type, (array) $post_types, true ); } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | Used By | Description | | --- | --- | | [is\_singular()](../../functions/is_singular) wp-includes/query.php | Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types). | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::reset_postdata() WP\_Query::reset\_postdata() ============================ After looping through a nested query, this function restores the $post global to the current post in this query. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function reset_postdata() { if ( ! empty( $this->post ) ) { $GLOBALS['post'] = $this->post; $this->setup_postdata( $this->post ); } } ``` | Uses | Description | | --- | --- | | [WP\_Query::setup\_postdata()](setup_postdata) wp-includes/class-wp-query.php | Set up global post data. | | Used By | Description | | --- | --- | | [wp\_reset\_postdata()](../../functions/wp_reset_postdata) wp-includes/query.php | After looping through a separate query, this function restores the $post global to the current post in the main query. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress WP_Query::parse_tax_query( array $q ) WP\_Query::parse\_tax\_query( array $q ) ======================================== Parses various taxonomy related query vars. For BC, this method is not marked as protected. See [28987]. `$q` array Required The query variables. Passed by reference. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function parse_tax_query( &$q ) { if ( ! empty( $q['tax_query'] ) && is_array( $q['tax_query'] ) ) { $tax_query = $q['tax_query']; } else { $tax_query = array(); } if ( ! empty( $q['taxonomy'] ) && ! empty( $q['term'] ) ) { $tax_query[] = array( 'taxonomy' => $q['taxonomy'], 'terms' => array( $q['term'] ), 'field' => 'slug', ); } foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) { if ( 'post_tag' === $taxonomy ) { continue; // Handled further down in the $q['tag'] block. } if ( $t->query_var && ! empty( $q[ $t->query_var ] ) ) { $tax_query_defaults = array( 'taxonomy' => $taxonomy, 'field' => 'slug', ); if ( ! empty( $t->rewrite['hierarchical'] ) ) { $q[ $t->query_var ] = wp_basename( $q[ $t->query_var ] ); } $term = $q[ $t->query_var ]; if ( is_array( $term ) ) { $term = implode( ',', $term ); } if ( strpos( $term, '+' ) !== false ) { $terms = preg_split( '/[+]+/', $term ); foreach ( $terms as $term ) { $tax_query[] = array_merge( $tax_query_defaults, array( 'terms' => array( $term ), ) ); } } else { $tax_query[] = array_merge( $tax_query_defaults, array( 'terms' => preg_split( '/[,]+/', $term ), ) ); } } } // If query string 'cat' is an array, implode it. if ( is_array( $q['cat'] ) ) { $q['cat'] = implode( ',', $q['cat'] ); } // Category stuff. if ( ! empty( $q['cat'] ) && ! $this->is_singular ) { $cat_in = array(); $cat_not_in = array(); $cat_array = preg_split( '/[,\s]+/', urldecode( $q['cat'] ) ); $cat_array = array_map( 'intval', $cat_array ); $q['cat'] = implode( ',', $cat_array ); foreach ( $cat_array as $cat ) { if ( $cat > 0 ) { $cat_in[] = $cat; } elseif ( $cat < 0 ) { $cat_not_in[] = abs( $cat ); } } if ( ! empty( $cat_in ) ) { $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $cat_in, 'field' => 'term_id', 'include_children' => true, ); } if ( ! empty( $cat_not_in ) ) { $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $cat_not_in, 'field' => 'term_id', 'operator' => 'NOT IN', 'include_children' => true, ); } unset( $cat_array, $cat_in, $cat_not_in ); } if ( ! empty( $q['category__and'] ) && 1 === count( (array) $q['category__and'] ) ) { $q['category__and'] = (array) $q['category__and']; if ( ! isset( $q['category__in'] ) ) { $q['category__in'] = array(); } $q['category__in'][] = absint( reset( $q['category__and'] ) ); unset( $q['category__and'] ); } if ( ! empty( $q['category__in'] ) ) { $q['category__in'] = array_map( 'absint', array_unique( (array) $q['category__in'] ) ); $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $q['category__in'], 'field' => 'term_id', 'include_children' => false, ); } if ( ! empty( $q['category__not_in'] ) ) { $q['category__not_in'] = array_map( 'absint', array_unique( (array) $q['category__not_in'] ) ); $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $q['category__not_in'], 'operator' => 'NOT IN', 'include_children' => false, ); } if ( ! empty( $q['category__and'] ) ) { $q['category__and'] = array_map( 'absint', array_unique( (array) $q['category__and'] ) ); $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $q['category__and'], 'field' => 'term_id', 'operator' => 'AND', 'include_children' => false, ); } // If query string 'tag' is array, implode it. if ( is_array( $q['tag'] ) ) { $q['tag'] = implode( ',', $q['tag'] ); } // Tag stuff. if ( '' !== $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) { if ( strpos( $q['tag'], ',' ) !== false ) { $tags = preg_split( '/[,\r\n\t ]+/', $q['tag'] ); foreach ( (array) $tags as $tag ) { $tag = sanitize_term_field( 'slug', $tag, 0, 'post_tag', 'db' ); $q['tag_slug__in'][] = $tag; } } elseif ( preg_match( '/[+\r\n\t ]+/', $q['tag'] ) || ! empty( $q['cat'] ) ) { $tags = preg_split( '/[+\r\n\t ]+/', $q['tag'] ); foreach ( (array) $tags as $tag ) { $tag = sanitize_term_field( 'slug', $tag, 0, 'post_tag', 'db' ); $q['tag_slug__and'][] = $tag; } } else { $q['tag'] = sanitize_term_field( 'slug', $q['tag'], 0, 'post_tag', 'db' ); $q['tag_slug__in'][] = $q['tag']; } } if ( ! empty( $q['tag_id'] ) ) { $q['tag_id'] = absint( $q['tag_id'] ); $tax_query[] = array( 'taxonomy' => 'post_tag', 'terms' => $q['tag_id'], ); } if ( ! empty( $q['tag__in'] ) ) { $q['tag__in'] = array_map( 'absint', array_unique( (array) $q['tag__in'] ) ); $tax_query[] = array( 'taxonomy' => 'post_tag', 'terms' => $q['tag__in'], ); } if ( ! empty( $q['tag__not_in'] ) ) { $q['tag__not_in'] = array_map( 'absint', array_unique( (array) $q['tag__not_in'] ) ); $tax_query[] = array( 'taxonomy' => 'post_tag', 'terms' => $q['tag__not_in'], 'operator' => 'NOT IN', ); } if ( ! empty( $q['tag__and'] ) ) { $q['tag__and'] = array_map( 'absint', array_unique( (array) $q['tag__and'] ) ); $tax_query[] = array( 'taxonomy' => 'post_tag', 'terms' => $q['tag__and'], 'operator' => 'AND', ); } if ( ! empty( $q['tag_slug__in'] ) ) { $q['tag_slug__in'] = array_map( 'sanitize_title_for_query', array_unique( (array) $q['tag_slug__in'] ) ); $tax_query[] = array( 'taxonomy' => 'post_tag', 'terms' => $q['tag_slug__in'], 'field' => 'slug', ); } if ( ! empty( $q['tag_slug__and'] ) ) { $q['tag_slug__and'] = array_map( 'sanitize_title_for_query', array_unique( (array) $q['tag_slug__and'] ) ); $tax_query[] = array( 'taxonomy' => 'post_tag', 'terms' => $q['tag_slug__and'], 'field' => 'slug', 'operator' => 'AND', ); } $this->tax_query = new WP_Tax_Query( $tax_query ); /** * Fires after taxonomy-related query vars have been parsed. * * @since 3.7.0 * * @param WP_Query $query The WP_Query instance. */ do_action( 'parse_tax_query', $this ); } ``` [do\_action( 'parse\_tax\_query', WP\_Query $query )](../../hooks/parse_tax_query) Fires after taxonomy-related query vars have been parsed. | Uses | Description | | --- | --- | | [WP\_Tax\_Query::\_\_construct()](../wp_tax_query/__construct) wp-includes/class-wp-tax-query.php | Constructor. | | [sanitize\_term\_field()](../../functions/sanitize_term_field) wp-includes/taxonomy.php | Sanitizes the field value in the term based on the context. | | [get\_taxonomies()](../../functions/get_taxonomies) wp-includes/taxonomy.php | Retrieves a list of registered taxonomy names or objects. | | [wp\_basename()](../../functions/wp_basename) wp-includes/formatting.php | i18n-friendly version of basename(). | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Used By | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | [WP\_Query::parse\_query()](parse_query) wp-includes/class-wp-query.php | Parse a query string and set query type booleans. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |
programming_docs
wordpress WP_Query::set( string $query_var, mixed $value ) WP\_Query::set( string $query\_var, mixed $value ) ================================================== Sets the value of a query variable. `$query_var` string Required Query variable key. `$value` mixed Required Query variable value. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function set( $query_var, $value ) { $this->query_vars[ $query_var ] = $value; } ``` | Used By | Description | | --- | --- | | [\_resolve\_template\_for\_new\_post()](../../functions/_resolve_template_for_new_post) wp-includes/block-template.php | Sets the current [WP\_Query](../wp_query) to return auto-draft posts. | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | [set\_query\_var()](../../functions/set_query_var) wp-includes/query.php | Sets the value of a query variable in the [WP\_Query](../wp_query) class. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::is_post_type_archive( string|string[] $post_types = '' ): bool WP\_Query::is\_post\_type\_archive( string|string[] $post\_types = '' ): bool ============================================================================= Is the query for an existing post type archive page? `$post_types` string|string[] Optional Post type or array of posts types to check against. Default: `''` bool Whether the query is for an existing post type archive page. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_post_type_archive( $post_types = '' ) { if ( empty( $post_types ) || ! $this->is_post_type_archive ) { return (bool) $this->is_post_type_archive; } $post_type = $this->get( 'post_type' ); if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); } $post_type_object = get_post_type_object( $post_type ); if ( ! $post_type_object ) { return false; } return in_array( $post_type_object->name, (array) $post_types, true ); } ``` | Uses | Description | | --- | --- | | [WP\_Query::get()](get) wp-includes/class-wp-query.php | Retrieves the value of a query variable. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | Used By | Description | | --- | --- | | [is\_post\_type\_archive()](../../functions/is_post_type_archive) wp-includes/query.php | Determines whether the query is for an existing post type archive page. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_tag( int|string|int[]|string[] $tag = '' ): bool WP\_Query::is\_tag( int|string|int[]|string[] $tag = '' ): bool =============================================================== Is the query for an existing tag archive page? If the $tag parameter is specified, this function will additionally check if the query is for one of the tags specified. `$tag` int|string|int[]|string[] Optional Tag ID, name, slug, or array of such to check against. Default: `''` bool Whether the query is for an existing tag archive page. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_tag( $tag = '' ) { if ( ! $this->is_tag ) { return false; } if ( empty( $tag ) ) { return true; } $tag_obj = $this->get_queried_object(); if ( ! $tag_obj ) { return false; } $tag = array_map( 'strval', (array) $tag ); if ( in_array( (string) $tag_obj->term_id, $tag, true ) ) { return true; } elseif ( in_array( $tag_obj->name, $tag, true ) ) { return true; } elseif ( in_array( $tag_obj->slug, $tag, true ) ) { return true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | Used By | Description | | --- | --- | | [is\_tag()](../../functions/is_tag) wp-includes/query.php | Determines whether the query is for an existing tag archive page. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::get_posts(): WP_Post[]|int[] WP\_Query::get\_posts(): WP\_Post[]|int[] ========================================= Retrieves an array of posts based on query variables. There are a few filters and actions that can be used to modify the post database query. [WP\_Post](../wp_post)[]|int[] Array of post objects or post IDs. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function get_posts() { global $wpdb; $this->parse_query(); /** * Fires after the query variable object is created, but before the actual query is run. * * Note: If using conditional tags, use the method versions within the passed instance * (e.g. $this->is_main_query() instead of is_main_query()). This is because the functions * like is_main_query() test against the global $wp_query instance, not the passed one. * * @since 2.0.0 * * @param WP_Query $query The WP_Query instance (passed by reference). */ do_action_ref_array( 'pre_get_posts', array( &$this ) ); // Shorthand. $q = &$this->query_vars; // Fill again in case 'pre_get_posts' unset some vars. $q = $this->fill_query_vars( $q ); /** * Filters whether an attachment query should include filenames or not. * * @since 6.0.3 * * @param bool $allow_query_attachment_by_filename Whether or not to include filenames. */ $this->allow_query_attachment_by_filename = apply_filters( 'wp_allow_query_attachment_by_filename', false ); remove_all_filters( 'wp_allow_query_attachment_by_filename' ); // Parse meta query. $this->meta_query = new WP_Meta_Query(); $this->meta_query->parse_query_vars( $q ); // Set a flag if a 'pre_get_posts' hook changed the query vars. $hash = md5( serialize( $this->query_vars ) ); if ( $hash != $this->query_vars_hash ) { $this->query_vars_changed = true; $this->query_vars_hash = $hash; } unset( $hash ); // First let's clear some variables. $distinct = ''; $whichauthor = ''; $whichmimetype = ''; $where = ''; $limits = ''; $join = ''; $search = ''; $groupby = ''; $post_status_join = false; $page = 1; if ( isset( $q['caller_get_posts'] ) ) { _deprecated_argument( 'WP_Query', '3.1.0', sprintf( /* translators: 1: caller_get_posts, 2: ignore_sticky_posts */ __( '%1$s is deprecated. Use %2$s instead.' ), '<code>caller_get_posts</code>', '<code>ignore_sticky_posts</code>' ) ); if ( ! isset( $q['ignore_sticky_posts'] ) ) { $q['ignore_sticky_posts'] = $q['caller_get_posts']; } } if ( ! isset( $q['ignore_sticky_posts'] ) ) { $q['ignore_sticky_posts'] = false; } if ( ! isset( $q['suppress_filters'] ) ) { $q['suppress_filters'] = false; } if ( ! isset( $q['cache_results'] ) ) { $q['cache_results'] = true; } if ( ! isset( $q['update_post_term_cache'] ) ) { $q['update_post_term_cache'] = true; } if ( ! isset( $q['update_menu_item_cache'] ) ) { $q['update_menu_item_cache'] = false; } if ( ! isset( $q['lazy_load_term_meta'] ) ) { $q['lazy_load_term_meta'] = $q['update_post_term_cache']; } if ( ! isset( $q['update_post_meta_cache'] ) ) { $q['update_post_meta_cache'] = true; } if ( ! isset( $q['post_type'] ) ) { if ( $this->is_search ) { $q['post_type'] = 'any'; } else { $q['post_type'] = ''; } } $post_type = $q['post_type']; if ( empty( $q['posts_per_page'] ) ) { $q['posts_per_page'] = get_option( 'posts_per_page' ); } if ( isset( $q['showposts'] ) && $q['showposts'] ) { $q['showposts'] = (int) $q['showposts']; $q['posts_per_page'] = $q['showposts']; } if ( ( isset( $q['posts_per_archive_page'] ) && 0 != $q['posts_per_archive_page'] ) && ( $this->is_archive || $this->is_search ) ) { $q['posts_per_page'] = $q['posts_per_archive_page']; } if ( ! isset( $q['nopaging'] ) ) { if ( -1 == $q['posts_per_page'] ) { $q['nopaging'] = true; } else { $q['nopaging'] = false; } } if ( $this->is_feed ) { // This overrides 'posts_per_page'. if ( ! empty( $q['posts_per_rss'] ) ) { $q['posts_per_page'] = $q['posts_per_rss']; } else { $q['posts_per_page'] = get_option( 'posts_per_rss' ); } $q['nopaging'] = false; } $q['posts_per_page'] = (int) $q['posts_per_page']; if ( $q['posts_per_page'] < -1 ) { $q['posts_per_page'] = abs( $q['posts_per_page'] ); } elseif ( 0 == $q['posts_per_page'] ) { $q['posts_per_page'] = 1; } if ( ! isset( $q['comments_per_page'] ) || 0 == $q['comments_per_page'] ) { $q['comments_per_page'] = get_option( 'comments_per_page' ); } if ( $this->is_home && ( empty( $this->query ) || 'true' === $q['preview'] ) && ( 'page' === get_option( 'show_on_front' ) ) && get_option( 'page_on_front' ) ) { $this->is_page = true; $this->is_home = false; $q['page_id'] = get_option( 'page_on_front' ); } if ( isset( $q['page'] ) ) { $q['page'] = trim( $q['page'], '/' ); $q['page'] = absint( $q['page'] ); } // If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present. if ( isset( $q['no_found_rows'] ) ) { $q['no_found_rows'] = (bool) $q['no_found_rows']; } else { $q['no_found_rows'] = false; } switch ( $q['fields'] ) { case 'ids': $fields = "{$wpdb->posts}.ID"; break; case 'id=>parent': $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent"; break; default: $fields = "{$wpdb->posts}.*"; } if ( '' !== $q['menu_order'] ) { $where .= " AND {$wpdb->posts}.menu_order = " . $q['menu_order']; } // The "m" parameter is meant for months but accepts datetimes of varying specificity. if ( $q['m'] ) { $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr( $q['m'], 0, 4 ); if ( strlen( $q['m'] ) > 5 ) { $where .= " AND MONTH({$wpdb->posts}.post_date)=" . substr( $q['m'], 4, 2 ); } if ( strlen( $q['m'] ) > 7 ) { $where .= " AND DAYOFMONTH({$wpdb->posts}.post_date)=" . substr( $q['m'], 6, 2 ); } if ( strlen( $q['m'] ) > 9 ) { $where .= " AND HOUR({$wpdb->posts}.post_date)=" . substr( $q['m'], 8, 2 ); } if ( strlen( $q['m'] ) > 11 ) { $where .= " AND MINUTE({$wpdb->posts}.post_date)=" . substr( $q['m'], 10, 2 ); } if ( strlen( $q['m'] ) > 13 ) { $where .= " AND SECOND({$wpdb->posts}.post_date)=" . substr( $q['m'], 12, 2 ); } } // Handle the other individual date parameters. $date_parameters = array(); if ( '' !== $q['hour'] ) { $date_parameters['hour'] = $q['hour']; } if ( '' !== $q['minute'] ) { $date_parameters['minute'] = $q['minute']; } if ( '' !== $q['second'] ) { $date_parameters['second'] = $q['second']; } if ( $q['year'] ) { $date_parameters['year'] = $q['year']; } if ( $q['monthnum'] ) { $date_parameters['monthnum'] = $q['monthnum']; } if ( $q['w'] ) { $date_parameters['week'] = $q['w']; } if ( $q['day'] ) { $date_parameters['day'] = $q['day']; } if ( $date_parameters ) { $date_query = new WP_Date_Query( array( $date_parameters ) ); $where .= $date_query->get_sql(); } unset( $date_parameters, $date_query ); // Handle complex date queries. if ( ! empty( $q['date_query'] ) ) { $this->date_query = new WP_Date_Query( $q['date_query'] ); $where .= $this->date_query->get_sql(); } // If we've got a post_type AND it's not "any" post_type. if ( ! empty( $q['post_type'] ) && 'any' !== $q['post_type'] ) { foreach ( (array) $q['post_type'] as $_post_type ) { $ptype_obj = get_post_type_object( $_post_type ); if ( ! $ptype_obj || ! $ptype_obj->query_var || empty( $q[ $ptype_obj->query_var ] ) ) { continue; } if ( ! $ptype_obj->hierarchical ) { // Non-hierarchical post types can directly use 'name'. $q['name'] = $q[ $ptype_obj->query_var ]; } else { // Hierarchical post types will operate through 'pagename'. $q['pagename'] = $q[ $ptype_obj->query_var ]; $q['name'] = ''; } // Only one request for a slug is possible, this is why name & pagename are overwritten above. break; } // End foreach. unset( $ptype_obj ); } if ( '' !== $q['title'] ) { $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title = %s", stripslashes( $q['title'] ) ); } // Parameters related to 'post_name'. if ( '' !== $q['name'] ) { $q['name'] = sanitize_title_for_query( $q['name'] ); $where .= " AND {$wpdb->posts}.post_name = '" . $q['name'] . "'"; } elseif ( '' !== $q['pagename'] ) { if ( isset( $this->queried_object_id ) ) { $reqpage = $this->queried_object_id; } else { if ( 'page' !== $q['post_type'] ) { foreach ( (array) $q['post_type'] as $_post_type ) { $ptype_obj = get_post_type_object( $_post_type ); if ( ! $ptype_obj || ! $ptype_obj->hierarchical ) { continue; } $reqpage = get_page_by_path( $q['pagename'], OBJECT, $_post_type ); if ( $reqpage ) { break; } } unset( $ptype_obj ); } else { $reqpage = get_page_by_path( $q['pagename'] ); } if ( ! empty( $reqpage ) ) { $reqpage = $reqpage->ID; } else { $reqpage = 0; } } $page_for_posts = get_option( 'page_for_posts' ); if ( ( 'page' !== get_option( 'show_on_front' ) ) || empty( $page_for_posts ) || ( $reqpage != $page_for_posts ) ) { $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); $q['name'] = $q['pagename']; $where .= " AND ({$wpdb->posts}.ID = '$reqpage')"; $reqpage_obj = get_post( $reqpage ); if ( is_object( $reqpage_obj ) && 'attachment' === $reqpage_obj->post_type ) { $this->is_attachment = true; $post_type = 'attachment'; $q['post_type'] = 'attachment'; $this->is_page = true; $q['attachment_id'] = $reqpage; } } } elseif ( '' !== $q['attachment'] ) { $q['attachment'] = sanitize_title_for_query( wp_basename( $q['attachment'] ) ); $q['name'] = $q['attachment']; $where .= " AND {$wpdb->posts}.post_name = '" . $q['attachment'] . "'"; } elseif ( is_array( $q['post_name__in'] ) && ! empty( $q['post_name__in'] ) ) { $q['post_name__in'] = array_map( 'sanitize_title_for_query', $q['post_name__in'] ); $post_name__in = "'" . implode( "','", $q['post_name__in'] ) . "'"; $where .= " AND {$wpdb->posts}.post_name IN ($post_name__in)"; } // If an attachment is requested by number, let it supersede any post number. if ( $q['attachment_id'] ) { $q['p'] = absint( $q['attachment_id'] ); } // If a post number is specified, load that post. if ( $q['p'] ) { $where .= " AND {$wpdb->posts}.ID = " . $q['p']; } elseif ( $q['post__in'] ) { $post__in = implode( ',', array_map( 'absint', $q['post__in'] ) ); $where .= " AND {$wpdb->posts}.ID IN ($post__in)"; } elseif ( $q['post__not_in'] ) { $post__not_in = implode( ',', array_map( 'absint', $q['post__not_in'] ) ); $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; } if ( is_numeric( $q['post_parent'] ) ) { $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_parent = %d ", $q['post_parent'] ); } elseif ( $q['post_parent__in'] ) { $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) ); $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)"; } elseif ( $q['post_parent__not_in'] ) { $post_parent__not_in = implode( ',', array_map( 'absint', $q['post_parent__not_in'] ) ); $where .= " AND {$wpdb->posts}.post_parent NOT IN ($post_parent__not_in)"; } if ( $q['page_id'] ) { if ( ( 'page' !== get_option( 'show_on_front' ) ) || ( get_option( 'page_for_posts' ) != $q['page_id'] ) ) { $q['p'] = $q['page_id']; $where = " AND {$wpdb->posts}.ID = " . $q['page_id']; } } // If a search pattern is specified, load the posts that match. if ( strlen( $q['s'] ) ) { $search = $this->parse_search( $q ); } if ( ! $q['suppress_filters'] ) { /** * Filters the search SQL that is used in the WHERE clause of WP_Query. * * @since 3.0.0 * * @param string $search Search SQL for WHERE clause. * @param WP_Query $query The current WP_Query object. */ $search = apply_filters_ref_array( 'posts_search', array( $search, &$this ) ); } // Taxonomies. if ( ! $this->is_singular ) { $this->parse_tax_query( $q ); $clauses = $this->tax_query->get_sql( $wpdb->posts, 'ID' ); $join .= $clauses['join']; $where .= $clauses['where']; } if ( $this->is_tax ) { if ( empty( $post_type ) ) { // Do a fully inclusive search for currently registered post types of queried taxonomies. $post_type = array(); $taxonomies = array_keys( $this->tax_query->queried_terms ); foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) { $object_taxonomies = 'attachment' === $pt ? get_taxonomies_for_attachments() : get_object_taxonomies( $pt ); if ( array_intersect( $taxonomies, $object_taxonomies ) ) { $post_type[] = $pt; } } if ( ! $post_type ) { $post_type = 'any'; } elseif ( count( $post_type ) == 1 ) { $post_type = $post_type[0]; } $post_status_join = true; } elseif ( in_array( 'attachment', (array) $post_type, true ) ) { $post_status_join = true; } } /* * Ensure that 'taxonomy', 'term', 'term_id', 'cat', and * 'category_name' vars are set for backward compatibility. */ if ( ! empty( $this->tax_query->queried_terms ) ) { /* * Set 'taxonomy', 'term', and 'term_id' to the * first taxonomy other than 'post_tag' or 'category'. */ if ( ! isset( $q['taxonomy'] ) ) { foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) { if ( empty( $queried_items['terms'][0] ) ) { continue; } if ( ! in_array( $queried_taxonomy, array( 'category', 'post_tag' ), true ) ) { $q['taxonomy'] = $queried_taxonomy; if ( 'slug' === $queried_items['field'] ) { $q['term'] = $queried_items['terms'][0]; } else { $q['term_id'] = $queried_items['terms'][0]; } // Take the first one we find. break; } } } // 'cat', 'category_name', 'tag_id'. foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) { if ( empty( $queried_items['terms'][0] ) ) { continue; } if ( 'category' === $queried_taxonomy ) { $the_cat = get_term_by( $queried_items['field'], $queried_items['terms'][0], 'category' ); if ( $the_cat ) { $this->set( 'cat', $the_cat->term_id ); $this->set( 'category_name', $the_cat->slug ); } unset( $the_cat ); } if ( 'post_tag' === $queried_taxonomy ) { $the_tag = get_term_by( $queried_items['field'], $queried_items['terms'][0], 'post_tag' ); if ( $the_tag ) { $this->set( 'tag_id', $the_tag->term_id ); } unset( $the_tag ); } } } if ( ! empty( $this->tax_query->queries ) || ! empty( $this->meta_query->queries ) || ! empty( $this->allow_query_attachment_by_filename ) ) { $groupby = "{$wpdb->posts}.ID"; } // Author/user stuff. if ( ! empty( $q['author'] ) && '0' != $q['author'] ) { $q['author'] = addslashes_gpc( '' . urldecode( $q['author'] ) ); $authors = array_unique( array_map( 'intval', preg_split( '/[,\s]+/', $q['author'] ) ) ); foreach ( $authors as $author ) { $key = $author > 0 ? 'author__in' : 'author__not_in'; $q[ $key ][] = abs( $author ); } $q['author'] = implode( ',', $authors ); } if ( ! empty( $q['author__not_in'] ) ) { $author__not_in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__not_in'] ) ) ); $where .= " AND {$wpdb->posts}.post_author NOT IN ($author__not_in) "; } elseif ( ! empty( $q['author__in'] ) ) { $author__in = implode( ',', array_map( 'absint', array_unique( (array) $q['author__in'] ) ) ); $where .= " AND {$wpdb->posts}.post_author IN ($author__in) "; } // Author stuff for nice URLs. if ( '' !== $q['author_name'] ) { if ( strpos( $q['author_name'], '/' ) !== false ) { $q['author_name'] = explode( '/', $q['author_name'] ); if ( $q['author_name'][ count( $q['author_name'] ) - 1 ] ) { $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // No trailing slash. } else { $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 2 ]; // There was a trailing slash. } } $q['author_name'] = sanitize_title_for_query( $q['author_name'] ); $q['author'] = get_user_by( 'slug', $q['author_name'] ); if ( $q['author'] ) { $q['author'] = $q['author']->ID; } $whichauthor .= " AND ({$wpdb->posts}.post_author = " . absint( $q['author'] ) . ')'; } // Matching by comment count. if ( isset( $q['comment_count'] ) ) { // Numeric comment count is converted to array format. if ( is_numeric( $q['comment_count'] ) ) { $q['comment_count'] = array( 'value' => (int) $q['comment_count'], ); } if ( isset( $q['comment_count']['value'] ) ) { $q['comment_count'] = array_merge( array( 'compare' => '=', ), $q['comment_count'] ); // Fallback for invalid compare operators is '='. $compare_operators = array( '=', '!=', '>', '>=', '<', '<=' ); if ( ! in_array( $q['comment_count']['compare'], $compare_operators, true ) ) { $q['comment_count']['compare'] = '='; } $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_count {$q['comment_count']['compare']} %d", $q['comment_count']['value'] ); } } // MIME-Type stuff for attachment browsing. if ( isset( $q['post_mime_type'] ) && '' !== $q['post_mime_type'] ) { $whichmimetype = wp_post_mime_type_where( $q['post_mime_type'], $wpdb->posts ); } $where .= $search . $whichauthor . $whichmimetype; if ( ! empty( $this->allow_query_attachment_by_filename ) ) { $join .= " LEFT JOIN {$wpdb->postmeta} AS sq1 ON ( {$wpdb->posts}.ID = sq1.post_id AND sq1.meta_key = '_wp_attached_file' )"; } if ( ! empty( $this->meta_query->queries ) ) { $clauses = $this->meta_query->get_sql( 'post', $wpdb->posts, 'ID', $this ); $join .= $clauses['join']; $where .= $clauses['where']; } $rand = ( isset( $q['orderby'] ) && 'rand' === $q['orderby'] ); if ( ! isset( $q['order'] ) ) { $q['order'] = $rand ? '' : 'DESC'; } else { $q['order'] = $rand ? '' : $this->parse_order( $q['order'] ); } // These values of orderby should ignore the 'order' parameter. $force_asc = array( 'post__in', 'post_name__in', 'post_parent__in' ); if ( isset( $q['orderby'] ) && in_array( $q['orderby'], $force_asc, true ) ) { $q['order'] = ''; } // Order by. if ( empty( $q['orderby'] ) ) { /* * Boolean false or empty array blanks out ORDER BY, * while leaving the value unset or otherwise empty sets the default. */ if ( isset( $q['orderby'] ) && ( is_array( $q['orderby'] ) || false === $q['orderby'] ) ) { $orderby = ''; } else { $orderby = "{$wpdb->posts}.post_date " . $q['order']; } } elseif ( 'none' === $q['orderby'] ) { $orderby = ''; } else { $orderby_array = array(); if ( is_array( $q['orderby'] ) ) { foreach ( $q['orderby'] as $_orderby => $order ) { $orderby = addslashes_gpc( urldecode( $_orderby ) ); $parsed = $this->parse_orderby( $orderby ); if ( ! $parsed ) { continue; } $orderby_array[] = $parsed . ' ' . $this->parse_order( $order ); } $orderby = implode( ', ', $orderby_array ); } else { $q['orderby'] = urldecode( $q['orderby'] ); $q['orderby'] = addslashes_gpc( $q['orderby'] ); foreach ( explode( ' ', $q['orderby'] ) as $i => $orderby ) { $parsed = $this->parse_orderby( $orderby ); // Only allow certain values for safety. if ( ! $parsed ) { continue; } $orderby_array[] = $parsed; } $orderby = implode( ' ' . $q['order'] . ', ', $orderby_array ); if ( empty( $orderby ) ) { $orderby = "{$wpdb->posts}.post_date " . $q['order']; } elseif ( ! empty( $q['order'] ) ) { $orderby .= " {$q['order']}"; } } } // Order search results by relevance only when another "orderby" is not specified in the query. if ( ! empty( $q['s'] ) ) { $search_orderby = ''; if ( ! empty( $q['search_orderby_title'] ) && ( empty( $q['orderby'] ) && ! $this->is_feed ) || ( isset( $q['orderby'] ) && 'relevance' === $q['orderby'] ) ) { $search_orderby = $this->parse_search_order( $q ); } if ( ! $q['suppress_filters'] ) { /** * Filters the ORDER BY used when ordering search results. * * @since 3.7.0 * * @param string $search_orderby The ORDER BY clause. * @param WP_Query $query The current WP_Query instance. */ $search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this ); } if ( $search_orderby ) { $orderby = $orderby ? $search_orderby . ', ' . $orderby : $search_orderby; } } if ( is_array( $post_type ) && count( $post_type ) > 1 ) { $post_type_cap = 'multiple_post_type'; } else { if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); } $post_type_object = get_post_type_object( $post_type ); if ( empty( $post_type_object ) ) { $post_type_cap = $post_type; } } if ( isset( $q['post_password'] ) ) { $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_password = %s", $q['post_password'] ); if ( empty( $q['perm'] ) ) { $q['perm'] = 'readable'; } } elseif ( isset( $q['has_password'] ) ) { $where .= sprintf( " AND {$wpdb->posts}.post_password %s ''", $q['has_password'] ? '!=' : '=' ); } if ( ! empty( $q['comment_status'] ) ) { $where .= $wpdb->prepare( " AND {$wpdb->posts}.comment_status = %s ", $q['comment_status'] ); } if ( ! empty( $q['ping_status'] ) ) { $where .= $wpdb->prepare( " AND {$wpdb->posts}.ping_status = %s ", $q['ping_status'] ); } $skip_post_status = false; if ( 'any' === $post_type ) { $in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) ); if ( empty( $in_search_post_types ) ) { $post_type_where = ' AND 1=0 '; $skip_post_status = true; } else { $post_type_where = " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", array_map( 'esc_sql', $in_search_post_types ) ) . "')"; } } elseif ( ! empty( $post_type ) && is_array( $post_type ) ) { $post_type_where = " AND {$wpdb->posts}.post_type IN ('" . implode( "', '", esc_sql( $post_type ) ) . "')"; } elseif ( ! empty( $post_type ) ) { $post_type_where = $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", $post_type ); $post_type_object = get_post_type_object( $post_type ); } elseif ( $this->is_attachment ) { $post_type_where = " AND {$wpdb->posts}.post_type = 'attachment'"; $post_type_object = get_post_type_object( 'attachment' ); } elseif ( $this->is_page ) { $post_type_where = " AND {$wpdb->posts}.post_type = 'page'"; $post_type_object = get_post_type_object( 'page' ); } else { $post_type_where = " AND {$wpdb->posts}.post_type = 'post'"; $post_type_object = get_post_type_object( 'post' ); } $edit_cap = 'edit_post'; $read_cap = 'read_post'; if ( ! empty( $post_type_object ) ) { $edit_others_cap = $post_type_object->cap->edit_others_posts; $read_private_cap = $post_type_object->cap->read_private_posts; } else { $edit_others_cap = 'edit_others_' . $post_type_cap . 's'; $read_private_cap = 'read_private_' . $post_type_cap . 's'; } $user_id = get_current_user_id(); $q_status = array(); if ( $skip_post_status ) { $where .= $post_type_where; } elseif ( ! empty( $q['post_status'] ) ) { $where .= $post_type_where; $statuswheres = array(); $q_status = $q['post_status']; if ( ! is_array( $q_status ) ) { $q_status = explode( ',', $q_status ); } $r_status = array(); $p_status = array(); $e_status = array(); if ( in_array( 'any', $q_status, true ) ) { foreach ( get_post_stati( array( 'exclude_from_search' => true ) ) as $status ) { if ( ! in_array( $status, $q_status, true ) ) { $e_status[] = "{$wpdb->posts}.post_status <> '$status'"; } } } else { foreach ( get_post_stati() as $status ) { if ( in_array( $status, $q_status, true ) ) { if ( 'private' === $status ) { $p_status[] = "{$wpdb->posts}.post_status = '$status'"; } else { $r_status[] = "{$wpdb->posts}.post_status = '$status'"; } } } } if ( empty( $q['perm'] ) || 'readable' !== $q['perm'] ) { $r_status = array_merge( $r_status, $p_status ); unset( $p_status ); } if ( ! empty( $e_status ) ) { $statuswheres[] = '(' . implode( ' AND ', $e_status ) . ')'; } if ( ! empty( $r_status ) ) { if ( ! empty( $q['perm'] ) && 'editable' === $q['perm'] && ! current_user_can( $edit_others_cap ) ) { $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . implode( ' OR ', $r_status ) . '))'; } else { $statuswheres[] = '(' . implode( ' OR ', $r_status ) . ')'; } } if ( ! empty( $p_status ) ) { if ( ! empty( $q['perm'] ) && 'readable' === $q['perm'] && ! current_user_can( $read_private_cap ) ) { $statuswheres[] = "({$wpdb->posts}.post_author = $user_id " . 'AND (' . implode( ' OR ', $p_status ) . '))'; } else { $statuswheres[] = '(' . implode( ' OR ', $p_status ) . ')'; } } if ( $post_status_join ) { $join .= " LEFT JOIN {$wpdb->posts} AS p2 ON ({$wpdb->posts}.post_parent = p2.ID) "; foreach ( $statuswheres as $index => $statuswhere ) { $statuswheres[ $index ] = "($statuswhere OR ({$wpdb->posts}.post_status = 'inherit' AND " . str_replace( $wpdb->posts, 'p2', $statuswhere ) . '))'; } } $where_status = implode( ' OR ', $statuswheres ); if ( ! empty( $where_status ) ) { $where .= " AND ($where_status)"; } } elseif ( ! $this->is_singular ) { if ( 'any' === $post_type ) { $queried_post_types = get_post_types( array( 'exclude_from_search' => false ) ); } elseif ( is_array( $post_type ) ) { $queried_post_types = $post_type; } elseif ( ! empty( $post_type ) ) { $queried_post_types = array( $post_type ); } else { $queried_post_types = array( 'post' ); } if ( ! empty( $queried_post_types ) ) { $status_type_clauses = array(); foreach ( $queried_post_types as $queried_post_type ) { $queried_post_type_object = get_post_type_object( $queried_post_type ); $type_where = '(' . $wpdb->prepare( "{$wpdb->posts}.post_type = %s AND (", $queried_post_type ); // Public statuses. $public_statuses = get_post_stati( array( 'public' => true ) ); $status_clauses = array(); foreach ( $public_statuses as $public_status ) { $status_clauses[] = "{$wpdb->posts}.post_status = '$public_status'"; } $type_where .= implode( ' OR ', $status_clauses ); // Add protected states that should show in the admin all list. if ( $this->is_admin ) { $admin_all_statuses = get_post_stati( array( 'protected' => true, 'show_in_admin_all_list' => true, ) ); foreach ( $admin_all_statuses as $admin_all_status ) { $type_where .= " OR {$wpdb->posts}.post_status = '$admin_all_status'"; } } // Add private states that are visible to current user. if ( is_user_logged_in() && $queried_post_type_object instanceof WP_Post_Type ) { $read_private_cap = $queried_post_type_object->cap->read_private_posts; $private_statuses = get_post_stati( array( 'private' => true ) ); foreach ( $private_statuses as $private_status ) { $type_where .= current_user_can( $read_private_cap ) ? " \nOR {$wpdb->posts}.post_status = '$private_status'" : " \nOR ({$wpdb->posts}.post_author = $user_id AND {$wpdb->posts}.post_status = '$private_status')"; } } $type_where .= '))'; $status_type_clauses[] = $type_where; } if ( ! empty( $status_type_clauses ) ) { $where .= ' AND (' . implode( ' OR ', $status_type_clauses ) . ')'; } } else { $where .= ' AND 1=0 '; } } else { $where .= $post_type_where; } /* * Apply filters on where and join prior to paging so that any * manipulations to them are reflected in the paging by day queries. */ if ( ! $q['suppress_filters'] ) { /** * Filters the WHERE clause of the query. * * @since 1.5.0 * * @param string $where The WHERE clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $where = apply_filters_ref_array( 'posts_where', array( $where, &$this ) ); /** * Filters the JOIN clause of the query. * * @since 1.5.0 * * @param string $join The JOIN clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $join = apply_filters_ref_array( 'posts_join', array( $join, &$this ) ); } // Paging. if ( empty( $q['nopaging'] ) && ! $this->is_singular ) { $page = absint( $q['paged'] ); if ( ! $page ) { $page = 1; } // If 'offset' is provided, it takes precedence over 'paged'. if ( isset( $q['offset'] ) && is_numeric( $q['offset'] ) ) { $q['offset'] = absint( $q['offset'] ); $pgstrt = $q['offset'] . ', '; } else { $pgstrt = absint( ( $page - 1 ) * $q['posts_per_page'] ) . ', '; } $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; } // Comments feeds. if ( $this->is_comment_feed && ! $this->is_singular ) { if ( $this->is_archive || $this->is_search ) { $cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID ) $join "; $cwhere = "WHERE comment_approved = '1' $where"; $cgroupby = "{$wpdb->comments}.comment_id"; } else { // Other non-singular, e.g. front. $cjoin = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )"; $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'"; $cgroupby = ''; } if ( ! $q['suppress_filters'] ) { /** * Filters the JOIN clause of the comments feed query before sending. * * @since 2.2.0 * * @param string $cjoin The JOIN clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $cjoin = apply_filters_ref_array( 'comment_feed_join', array( $cjoin, &$this ) ); /** * Filters the WHERE clause of the comments feed query before sending. * * @since 2.2.0 * * @param string $cwhere The WHERE clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $cwhere = apply_filters_ref_array( 'comment_feed_where', array( $cwhere, &$this ) ); /** * Filters the GROUP BY clause of the comments feed query before sending. * * @since 2.2.0 * * @param string $cgroupby The GROUP BY clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( $cgroupby, &$this ) ); /** * Filters the ORDER BY clause of the comments feed query before sending. * * @since 2.8.0 * * @param string $corderby The ORDER BY clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); /** * Filters the LIMIT clause of the comments feed query before sending. * * @since 2.8.0 * * @param string $climits The JOIN clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) ); } $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; $climits = ( ! empty( $climits ) ) ? $climits : ''; $comments_request = "SELECT $distinct {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"; $key = md5( $comments_request ); $last_changed = wp_cache_get_last_changed( 'comment' ) . ':' . wp_cache_get_last_changed( 'posts' ); $cache_key = "comment_feed:$key:$last_changed"; $comment_ids = wp_cache_get( $cache_key, 'comment' ); if ( false === $comment_ids ) { $comment_ids = $wpdb->get_col( $comments_request ); wp_cache_add( $cache_key, $comment_ids, 'comment' ); } _prime_comment_caches( $comment_ids, false ); // Convert to WP_Comment. /** @var WP_Comment[] */ $this->comments = array_map( 'get_comment', $comment_ids ); $this->comment_count = count( $this->comments ); $post_ids = array(); foreach ( $this->comments as $comment ) { $post_ids[] = (int) $comment->comment_post_ID; } $post_ids = implode( ',', $post_ids ); $join = ''; if ( $post_ids ) { $where = "AND {$wpdb->posts}.ID IN ($post_ids) "; } else { $where = 'AND 0'; } } $pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' ); /* * Apply post-paging filters on where and join. Only plugins that * manipulate paging queries should use these hooks. */ if ( ! $q['suppress_filters'] ) { /** * Filters the WHERE clause of the query. * * Specifically for manipulating paging queries. * * @since 1.5.0 * * @param string $where The WHERE clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $where = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) ); /** * Filters the GROUP BY clause of the query. * * @since 2.0.0 * * @param string $groupby The GROUP BY clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $groupby = apply_filters_ref_array( 'posts_groupby', array( $groupby, &$this ) ); /** * Filters the JOIN clause of the query. * * Specifically for manipulating paging queries. * * @since 1.5.0 * * @param string $join The JOIN clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $join = apply_filters_ref_array( 'posts_join_paged', array( $join, &$this ) ); /** * Filters the ORDER BY clause of the query. * * @since 1.5.1 * * @param string $orderby The ORDER BY clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $orderby = apply_filters_ref_array( 'posts_orderby', array( $orderby, &$this ) ); /** * Filters the DISTINCT clause of the query. * * @since 2.1.0 * * @param string $distinct The DISTINCT clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $distinct = apply_filters_ref_array( 'posts_distinct', array( $distinct, &$this ) ); /** * Filters the LIMIT clause of the query. * * @since 2.1.0 * * @param string $limits The LIMIT clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $limits = apply_filters_ref_array( 'post_limits', array( $limits, &$this ) ); /** * Filters the SELECT clause of the query. * * @since 2.1.0 * * @param string $fields The SELECT clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) ); /** * Filters all query clauses at once, for convenience. * * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, * fields (SELECT), and LIMIT clauses. * * @since 3.1.0 * * @param string[] $clauses { * Associative array of the clauses for the query. * * @type string $where The WHERE clause of the query. * @type string $groupby The GROUP BY clause of the query. * @type string $join The JOIN clause of the query. * @type string $orderby The ORDER BY clause of the query. * @type string $distinct The DISTINCT clause of the query. * @type string $fields The SELECT clause of the query. * @type string $limits The LIMIT clause of the query. * } * @param WP_Query $query The WP_Query instance (passed by reference). */ $clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) ); $where = isset( $clauses['where'] ) ? $clauses['where'] : ''; $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : ''; $join = isset( $clauses['join'] ) ? $clauses['join'] : ''; $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : ''; $distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : ''; $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : ''; $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : ''; } /** * Fires to announce the query's current selection parameters. * * For use by caching plugins. * * @since 2.3.0 * * @param string $selection The assembled selection query. */ do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join ); /* * Filters again for the benefit of caching plugins. * Regular plugins should use the hooks above. */ if ( ! $q['suppress_filters'] ) { /** * Filters the WHERE clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $where The WHERE clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $where = apply_filters_ref_array( 'posts_where_request', array( $where, &$this ) ); /** * Filters the GROUP BY clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $groupby The GROUP BY clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $groupby = apply_filters_ref_array( 'posts_groupby_request', array( $groupby, &$this ) ); /** * Filters the JOIN clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $join The JOIN clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $join = apply_filters_ref_array( 'posts_join_request', array( $join, &$this ) ); /** * Filters the ORDER BY clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $orderby The ORDER BY clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $orderby = apply_filters_ref_array( 'posts_orderby_request', array( $orderby, &$this ) ); /** * Filters the DISTINCT clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $distinct The DISTINCT clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $distinct = apply_filters_ref_array( 'posts_distinct_request', array( $distinct, &$this ) ); /** * Filters the SELECT clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $fields The SELECT clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $fields = apply_filters_ref_array( 'posts_fields_request', array( $fields, &$this ) ); /** * Filters the LIMIT clause of the query. * * For use by caching plugins. * * @since 2.5.0 * * @param string $limits The LIMIT clause of the query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this ) ); /** * Filters all query clauses at once, for convenience. * * For use by caching plugins. * * Covers the WHERE, GROUP BY, JOIN, ORDER BY, DISTINCT, * fields (SELECT), and LIMIT clauses. * * @since 3.1.0 * * @param string[] $clauses { * Associative array of the clauses for the query. * * @type string $where The WHERE clause of the query. * @type string $groupby The GROUP BY clause of the query. * @type string $join The JOIN clause of the query. * @type string $orderby The ORDER BY clause of the query. * @type string $distinct The DISTINCT clause of the query. * @type string $fields The SELECT clause of the query. * @type string $limits The LIMIT clause of the query. * } * @param WP_Query $query The WP_Query instance (passed by reference). */ $clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) ); $where = isset( $clauses['where'] ) ? $clauses['where'] : ''; $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : ''; $join = isset( $clauses['join'] ) ? $clauses['join'] : ''; $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : ''; $distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : ''; $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : ''; $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : ''; } if ( ! empty( $groupby ) ) { $groupby = 'GROUP BY ' . $groupby; } if ( ! empty( $orderby ) ) { $orderby = 'ORDER BY ' . $orderby; } $found_rows = ''; if ( ! $q['no_found_rows'] && ! empty( $limits ) ) { $found_rows = 'SQL_CALC_FOUND_ROWS'; } $old_request = " SELECT $found_rows $distinct $fields FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits "; $this->request = $old_request; if ( ! $q['suppress_filters'] ) { /** * Filters the completed SQL query before sending. * * @since 2.0.0 * * @param string $request The complete SQL query. * @param WP_Query $query The WP_Query instance (passed by reference). */ $this->request = apply_filters_ref_array( 'posts_request', array( $this->request, &$this ) ); } /** * Filters the posts array before the query takes place. * * Return a non-null value to bypass WordPress' default post queries. * * Filtering functions that require pagination information are encouraged to set * the `found_posts` and `max_num_pages` properties of the WP_Query object, * passed to the filter by reference. If WP_Query does not perform a database * query, it will not have enough information to generate these values itself. * * @since 4.6.0 * * @param WP_Post[]|int[]|null $posts Return an array of post data to short-circuit WP's query, * or null to allow WP to run its normal queries. * @param WP_Query $query The WP_Query instance (passed by reference). */ $this->posts = apply_filters_ref_array( 'posts_pre_query', array( null, &$this ) ); /* * Ensure the ID database query is able to be cached. * * Random queries are expected to have unpredictable results and * cannot be cached. Note the space before `RAND` in the string * search, that to ensure against a collision with another * function. */ $id_query_is_cacheable = ! str_contains( strtoupper( $orderby ), ' RAND(' ); if ( $q['cache_results'] && $id_query_is_cacheable ) { $new_request = str_replace( $fields, "{$wpdb->posts}.*", $this->request ); $cache_key = $this->generate_cache_key( $q, $new_request ); $cache_found = false; if ( null === $this->posts ) { $cached_results = wp_cache_get( $cache_key, 'posts', false, $cache_found ); if ( $cached_results ) { if ( 'ids' === $q['fields'] ) { /** @var int[] */ $this->posts = array_map( 'intval', $cached_results['posts'] ); } else { _prime_post_caches( $cached_results['posts'], $q['update_post_term_cache'], $q['update_post_meta_cache'] ); /** @var WP_Post[] */ $this->posts = array_map( 'get_post', $cached_results['posts'] ); } $this->post_count = count( $this->posts ); $this->found_posts = $cached_results['found_posts']; $this->max_num_pages = $cached_results['max_num_pages']; if ( 'ids' === $q['fields'] ) { return $this->posts; } elseif ( 'id=>parent' === $q['fields'] ) { /** @var int[] */ $post_parents = array(); foreach ( $this->posts as $key => $post ) { $obj = new stdClass(); $obj->ID = (int) $post->ID; $obj->post_parent = (int) $post->post_parent; $this->posts[ $key ] = $obj; $post_parents[ $obj->ID ] = $obj->post_parent; } return $post_parents; } } } } if ( 'ids' === $q['fields'] ) { if ( null === $this->posts ) { $this->posts = $wpdb->get_col( $this->request ); } /** @var int[] */ $this->posts = array_map( 'intval', $this->posts ); $this->post_count = count( $this->posts ); $this->set_found_posts( $q, $limits ); if ( $q['cache_results'] && $id_query_is_cacheable ) { $cache_value = array( 'posts' => $this->posts, 'found_posts' => $this->found_posts, 'max_num_pages' => $this->max_num_pages, ); wp_cache_set( $cache_key, $cache_value, 'posts' ); } return $this->posts; } if ( 'id=>parent' === $q['fields'] ) { if ( null === $this->posts ) { $this->posts = $wpdb->get_results( $this->request ); } $this->post_count = count( $this->posts ); $this->set_found_posts( $q, $limits ); /** @var int[] */ $post_parents = array(); $post_ids = array(); foreach ( $this->posts as $key => $post ) { $this->posts[ $key ]->ID = (int) $post->ID; $this->posts[ $key ]->post_parent = (int) $post->post_parent; $post_parents[ (int) $post->ID ] = (int) $post->post_parent; $post_ids[] = (int) $post->ID; } if ( $q['cache_results'] && $id_query_is_cacheable ) { $cache_value = array( 'posts' => $post_ids, 'found_posts' => $this->found_posts, 'max_num_pages' => $this->max_num_pages, ); wp_cache_set( $cache_key, $cache_value, 'posts' ); } return $post_parents; } if ( null === $this->posts ) { $split_the_query = ( $old_request == $this->request && "{$wpdb->posts}.*" === $fields && ! empty( $limits ) && $q['posts_per_page'] < 500 ); /** * Filters whether to split the query. * * Splitting the query will cause it to fetch just the IDs of the found posts * (and then individually fetch each post by ID), rather than fetching every * complete row at once. One massive result vs. many small results. * * @since 3.4.0 * * @param bool $split_the_query Whether or not to split the query. * @param WP_Query $query The WP_Query instance. */ $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); if ( $split_the_query ) { // First get the IDs and then fill in the objects. $this->request = " SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits "; /** * Filters the Post IDs SQL request before sending. * * @since 3.4.0 * * @param string $request The post ID request. * @param WP_Query $query The WP_Query instance. */ $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); $post_ids = $wpdb->get_col( $this->request ); if ( $post_ids ) { $this->posts = $post_ids; $this->set_found_posts( $q, $limits ); _prime_post_caches( $post_ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); } else { $this->posts = array(); } } else { $this->posts = $wpdb->get_results( $this->request ); $this->set_found_posts( $q, $limits ); } } // Convert to WP_Post objects. if ( $this->posts ) { /** @var WP_Post[] */ $this->posts = array_map( 'get_post', $this->posts ); } if ( $q['cache_results'] && $id_query_is_cacheable && ! $cache_found ) { $post_ids = wp_list_pluck( $this->posts, 'ID' ); $cache_value = array( 'posts' => $post_ids, 'found_posts' => $this->found_posts, 'max_num_pages' => $this->max_num_pages, ); wp_cache_set( $cache_key, $cache_value, 'posts' ); } if ( ! $q['suppress_filters'] ) { /** * Filters the raw post results array, prior to status checks. * * @since 2.3.0 * * @param WP_Post[] $posts Array of post objects. * @param WP_Query $query The WP_Query instance (passed by reference). */ $this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) ); } if ( ! empty( $this->posts ) && $this->is_comment_feed && $this->is_singular ) { /** This filter is documented in wp-includes/query.php */ $cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) ); /** This filter is documented in wp-includes/query.php */ $cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) ); /** This filter is documented in wp-includes/query.php */ $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) ); $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; /** This filter is documented in wp-includes/query.php */ $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; /** This filter is documented in wp-includes/query.php */ $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) ); $comments_request = "SELECT {$wpdb->comments}.comment_ID FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"; $comment_key = md5( $comments_request ); $comment_last_changed = wp_cache_get_last_changed( 'comment' ); $comment_cache_key = "comment_feed:$comment_key:$comment_last_changed"; $comment_ids = wp_cache_get( $comment_cache_key, 'comment' ); if ( false === $comment_ids ) { $comment_ids = $wpdb->get_col( $comments_request ); wp_cache_add( $comment_cache_key, $comment_ids, 'comment' ); } _prime_comment_caches( $comment_ids, false ); // Convert to WP_Comment. /** @var WP_Comment[] */ $this->comments = array_map( 'get_comment', $comment_ids ); $this->comment_count = count( $this->comments ); } // Check post status to determine if post should be displayed. if ( ! empty( $this->posts ) && ( $this->is_single || $this->is_page ) ) { $status = get_post_status( $this->posts[0] ); if ( 'attachment' === $this->posts[0]->post_type && 0 === (int) $this->posts[0]->post_parent ) { $this->is_page = false; $this->is_single = true; $this->is_attachment = true; } // If the post_status was specifically requested, let it pass through. if ( ! in_array( $status, $q_status, true ) ) { $post_status_obj = get_post_status_object( $status ); if ( $post_status_obj && ! $post_status_obj->public ) { if ( ! is_user_logged_in() ) { // User must be logged in to view unpublished posts. $this->posts = array(); } else { if ( $post_status_obj->protected ) { // User must have edit permissions on the draft to preview. if ( ! current_user_can( $edit_cap, $this->posts[0]->ID ) ) { $this->posts = array(); } else { $this->is_preview = true; if ( 'future' !== $status ) { $this->posts[0]->post_date = current_time( 'mysql' ); } } } elseif ( $post_status_obj->private ) { if ( ! current_user_can( $read_cap, $this->posts[0]->ID ) ) { $this->posts = array(); } } else { $this->posts = array(); } } } elseif ( ! $post_status_obj ) { // Post status is not registered, assume it's not public. if ( ! current_user_can( $edit_cap, $this->posts[0]->ID ) ) { $this->posts = array(); } } } if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) ) { /** * Filters the single post for preview mode. * * @since 2.7.0 * * @param WP_Post $post_preview The Post object. * @param WP_Query $query The WP_Query instance (passed by reference). */ $this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) ); } } // Put sticky posts at the top of the posts array. $sticky_posts = get_option( 'sticky_posts' ); if ( $this->is_home && $page <= 1 && is_array( $sticky_posts ) && ! empty( $sticky_posts ) && ! $q['ignore_sticky_posts'] ) { $num_posts = count( $this->posts ); $sticky_offset = 0; // Loop over posts and relocate stickies to the front. for ( $i = 0; $i < $num_posts; $i++ ) { if ( in_array( $this->posts[ $i ]->ID, $sticky_posts, true ) ) { $sticky_post = $this->posts[ $i ]; // Remove sticky from current position. array_splice( $this->posts, $i, 1 ); // Move to front, after other stickies. array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); // Increment the sticky offset. The next sticky will be placed at this offset. $sticky_offset++; // Remove post from sticky posts array. $offset = array_search( $sticky_post->ID, $sticky_posts, true ); unset( $sticky_posts[ $offset ] ); } } // If any posts have been excluded specifically, Ignore those that are sticky. if ( ! empty( $sticky_posts ) && ! empty( $q['post__not_in'] ) ) { $sticky_posts = array_diff( $sticky_posts, $q['post__not_in'] ); } // Fetch sticky posts that weren't in the query results. if ( ! empty( $sticky_posts ) ) { $stickies = get_posts( array( 'post__in' => $sticky_posts, 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => count( $sticky_posts ), 'suppress_filters' => $q['suppress_filters'], 'cache_results' => $q['cache_results'], 'update_post_meta_cache' => $q['update_post_meta_cache'], 'update_post_term_cache' => $q['update_post_term_cache'], 'lazy_load_term_meta' => $q['lazy_load_term_meta'], ) ); foreach ( $stickies as $sticky_post ) { array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); $sticky_offset++; } } } // If comments have been fetched as part of the query, make sure comment meta lazy-loading is set up. if ( ! empty( $this->comments ) ) { wp_queue_comments_for_comment_meta_lazyload( $this->comments ); } if ( ! $q['suppress_filters'] ) { /** * Filters the array of retrieved posts after they've been fetched and * internally processed. * * @since 1.5.0 * * @param WP_Post[] $posts Array of post objects. * @param WP_Query $query The WP_Query instance (passed by reference). */ $this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) ); } // Ensure that any posts added/modified via one of the filters above are // of the type WP_Post and are filtered. if ( $this->posts ) { $this->post_count = count( $this->posts ); /** @var WP_Post[] */ $this->posts = array_map( 'get_post', $this->posts ); if ( $q['cache_results'] ) { $post_ids = wp_list_pluck( $this->posts, 'ID' ); _prime_post_caches( $post_ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); } /** @var WP_Post */ $this->post = reset( $this->posts ); } else { $this->post_count = 0; $this->posts = array(); } if ( ! empty( $this->posts ) && $q['update_menu_item_cache'] ) { update_menu_item_cache( $this->posts ); } if ( $q['lazy_load_term_meta'] ) { wp_queue_posts_for_term_meta_lazyload( $this->posts ); } return $this->posts; } ``` [apply\_filters\_ref\_array( 'comment\_feed\_groupby', string $cgroupby, WP\_Query $query )](../../hooks/comment_feed_groupby) Filters the GROUP BY clause of the comments feed query before sending. [apply\_filters\_ref\_array( 'comment\_feed\_join', string $cjoin, WP\_Query $query )](../../hooks/comment_feed_join) Filters the JOIN clause of the comments feed query before sending. [apply\_filters\_ref\_array( 'comment\_feed\_limits', string $climits, WP\_Query $query )](../../hooks/comment_feed_limits) Filters the LIMIT clause of the comments feed query before sending. [apply\_filters\_ref\_array( 'comment\_feed\_orderby', string $corderby, WP\_Query $query )](../../hooks/comment_feed_orderby) Filters the ORDER BY clause of the comments feed query before sending. [apply\_filters\_ref\_array( 'comment\_feed\_where', string $cwhere, WP\_Query $query )](../../hooks/comment_feed_where) Filters the WHERE clause of the comments feed query before sending. [apply\_filters\_ref\_array( 'posts\_clauses', string[] $clauses, WP\_Query $query )](../../hooks/posts_clauses) Filters all query clauses at once, for convenience. [apply\_filters\_ref\_array( 'posts\_clauses\_request', string[] $clauses, WP\_Query $query )](../../hooks/posts_clauses_request) Filters all query clauses at once, for convenience. [apply\_filters\_ref\_array( 'posts\_distinct', string $distinct, WP\_Query $query )](../../hooks/posts_distinct) Filters the DISTINCT clause of the query. [apply\_filters\_ref\_array( 'posts\_distinct\_request', string $distinct, WP\_Query $query )](../../hooks/posts_distinct_request) Filters the DISTINCT clause of the query. [apply\_filters\_ref\_array( 'posts\_fields', string $fields, WP\_Query $query )](../../hooks/posts_fields) Filters the SELECT clause of the query. [apply\_filters\_ref\_array( 'posts\_fields\_request', string $fields, WP\_Query $query )](../../hooks/posts_fields_request) Filters the SELECT clause of the query. [apply\_filters\_ref\_array( 'posts\_groupby', string $groupby, WP\_Query $query )](../../hooks/posts_groupby) Filters the GROUP BY clause of the query. [apply\_filters\_ref\_array( 'posts\_groupby\_request', string $groupby, WP\_Query $query )](../../hooks/posts_groupby_request) Filters the GROUP BY clause of the query. [apply\_filters\_ref\_array( 'posts\_join', string $join, WP\_Query $query )](../../hooks/posts_join) Filters the JOIN clause of the query. [apply\_filters\_ref\_array( 'posts\_join\_paged', string $join, WP\_Query $query )](../../hooks/posts_join_paged) Filters the JOIN clause of the query. [apply\_filters\_ref\_array( 'posts\_join\_request', string $join, WP\_Query $query )](../../hooks/posts_join_request) Filters the JOIN clause of the query. [apply\_filters\_ref\_array( 'posts\_orderby', string $orderby, WP\_Query $query )](../../hooks/posts_orderby) Filters the ORDER BY clause of the query. [apply\_filters\_ref\_array( 'posts\_orderby\_request', string $orderby, WP\_Query $query )](../../hooks/posts_orderby_request) Filters the ORDER BY clause of the query. [apply\_filters\_ref\_array( 'posts\_pre\_query', WP\_Post[]|int[]|null $posts, WP\_Query $query )](../../hooks/posts_pre_query) Filters the posts array before the query takes place. [apply\_filters\_ref\_array( 'posts\_request', string $request, WP\_Query $query )](../../hooks/posts_request) Filters the completed SQL query before sending. [apply\_filters( 'posts\_request\_ids', string $request, WP\_Query $query )](../../hooks/posts_request_ids) Filters the Post IDs SQL request before sending. [apply\_filters\_ref\_array( 'posts\_results', WP\_Post[] $posts, WP\_Query $query )](../../hooks/posts_results) Filters the raw post results array, prior to status checks. [apply\_filters\_ref\_array( 'posts\_search', string $search, WP\_Query $query )](../../hooks/posts_search) Filters the search SQL that is used in the WHERE clause of [WP\_Query](../wp_query). [apply\_filters( 'posts\_search\_orderby', string $search\_orderby, WP\_Query $query )](../../hooks/posts_search_orderby) Filters the ORDER BY used when ordering search results. [do\_action( 'posts\_selection', string $selection )](../../hooks/posts_selection) Fires to announce the query’s current selection parameters. [apply\_filters\_ref\_array( 'posts\_where', string $where, WP\_Query $query )](../../hooks/posts_where) Filters the WHERE clause of the query. [apply\_filters\_ref\_array( 'posts\_where\_paged', string $where, WP\_Query $query )](../../hooks/posts_where_paged) Filters the WHERE clause of the query. [apply\_filters\_ref\_array( 'posts\_where\_request', string $where, WP\_Query $query )](../../hooks/posts_where_request) Filters the WHERE clause of the query. [apply\_filters\_ref\_array( 'post\_limits', string $limits, WP\_Query $query )](../../hooks/post_limits) Filters the LIMIT clause of the query. [apply\_filters\_ref\_array( 'post\_limits\_request', string $limits, WP\_Query $query )](../../hooks/post_limits_request) Filters the LIMIT clause of the query. [do\_action\_ref\_array( 'pre\_get\_posts', WP\_Query $query )](../../hooks/pre_get_posts) Fires after the query variable object is created, but before the actual query is run. [apply\_filters( 'split\_the\_query', bool $split\_the\_query, WP\_Query $query )](../../hooks/split_the_query) Filters whether to split the query. [apply\_filters\_ref\_array( 'the\_posts', WP\_Post[] $posts, WP\_Query $query )](../../hooks/the_posts) Filters the array of retrieved posts after they’ve been fetched and internally processed. [apply\_filters\_ref\_array( 'the\_preview', WP\_Post $post\_preview, WP\_Query $query )](../../hooks/the_preview) Filters the single post for preview mode. [apply\_filters( 'wp\_allow\_query\_attachment\_by\_filename', bool $allow\_query\_attachment\_by\_filename )](../../hooks/wp_allow_query_attachment_by_filename) Filters whether an attachment query should include filenames or not. | Uses | Description | | --- | --- | | [update\_menu\_item\_cache()](../../functions/update_menu_item_cache) wp-includes/nav-menu.php | Updates post and term caches for all linked objects for a list of menu items. | | [remove\_all\_filters()](../../functions/remove_all_filters) wp-includes/plugin.php | Removes all of the callback functions from a filter hook. | | [WP\_Query::parse\_search\_order()](parse_search_order) wp-includes/class-wp-query.php | Generates SQL for the ORDER BY condition based on passed search terms. | | [WP\_Query::generate\_cache\_key()](generate_cache_key) wp-includes/class-wp-query.php | Generate cache key. | | [wp\_list\_pluck()](../../functions/wp_list_pluck) wp-includes/functions.php | Plucks a certain field out of each object or array in an array. | | [current\_time()](../../functions/current_time) wp-includes/functions.php | Retrieves the current time based on specified type. | | [get\_term\_by()](../../functions/get_term_by) wp-includes/taxonomy.php | Gets all term data from database by term field and data. | | [get\_object\_taxonomies()](../../functions/get_object_taxonomies) wp-includes/taxonomy.php | Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name. | | [WP\_Date\_Query::\_\_construct()](../wp_date_query/__construct) wp-includes/class-wp-date-query.php | Constructor. | | [do\_action\_ref\_array()](../../functions/do_action_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook, specifying arguments in an array. | | [apply\_filters\_ref\_array()](../../functions/apply_filters_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook, specifying arguments in an array. | | [WP\_Query::parse\_search()](parse_search) wp-includes/class-wp-query.php | Generates SQL for the WHERE clause based on passed search terms. | | [get\_taxonomies\_for\_attachments()](../../functions/get_taxonomies_for_attachments) wp-includes/media.php | Retrieves all of the taxonomies that are registered for attachments. | | [\_prime\_post\_caches()](../../functions/_prime_post_caches) wp-includes/post.php | Adds any posts from the given IDs to the cache that do not already exist in cache. | | [get\_page\_by\_path()](../../functions/get_page_by_path) wp-includes/post.php | Retrieves a page given its path. | | [wp\_post\_mime\_type\_where()](../../functions/wp_post_mime_type_where) wp-includes/post.php | Converts MIME types into SQL. | | [get\_posts()](../../functions/get_posts) wp-includes/post.php | Retrieves an array of the latest posts, or posts matching the given criteria. | | [get\_post\_stati()](../../functions/get_post_stati) wp-includes/post.php | Gets a list of post statuses. | | [get\_post\_status()](../../functions/get_post_status) wp-includes/post.php | Retrieves the post status based on the post ID. | | [get\_post\_status\_object()](../../functions/get_post_status_object) wp-includes/post.php | Retrieves a post status object by name. | | [wpdb::get\_col()](../wpdb/get_col) wp-includes/class-wpdb.php | Retrieves one column from the database. | | [WP\_Query::parse\_tax\_query()](parse_tax_query) wp-includes/class-wp-query.php | Parses various taxonomy related query vars. | | [WP\_Meta\_Query::\_\_construct()](../wp_meta_query/__construct) wp-includes/class-wp-meta-query.php | Constructor. | | [WP\_Query::fill\_query\_vars()](fill_query_vars) wp-includes/class-wp-query.php | Fills in the query variables, which do not exist within the parameter. | | [WP\_Query::parse\_order()](parse_order) wp-includes/class-wp-query.php | Parse an ‘order’ query variable and cast it to ASC or DESC as necessary. | | [wp\_cache\_add()](../../functions/wp_cache_add) wp-includes/cache.php | Adds data to the cache, if the cache key doesn’t already exist. | | [WP\_Query::parse\_query()](parse_query) wp-includes/class-wp-query.php | Parse a query string and set query type booleans. | | [\_prime\_comment\_caches()](../../functions/_prime_comment_caches) wp-includes/comment.php | Adds any comments from the given IDs to the cache that do not already exist in cache. | | [wp\_cache\_set()](../../functions/wp_cache_set) wp-includes/cache.php | Saves the data to the cache. | | [wp\_queue\_posts\_for\_term\_meta\_lazyload()](../../functions/wp_queue_posts_for_term_meta_lazyload) wp-includes/post.php | Queues posts for lazy-loading of term meta. | | [wp\_queue\_comments\_for\_comment\_meta\_lazyload()](../../functions/wp_queue_comments_for_comment_meta_lazyload) wp-includes/comment.php | Queues comments for metadata lazy-loading. | | [wp\_cache\_get\_last\_changed()](../../functions/wp_cache_get_last_changed) wp-includes/functions.php | Gets last changed date for the specified cache group. | | [esc\_sql()](../../functions/esc_sql) wp-includes/formatting.php | Escapes data for use in a MySQL query. | | [addslashes\_gpc()](../../functions/addslashes_gpc) wp-includes/formatting.php | Adds slashes to a string or recursively adds slashes to strings within an array. | | [sanitize\_title\_for\_query()](../../functions/sanitize_title_for_query) wp-includes/formatting.php | Sanitizes a title with the ‘query’ context. | | [get\_user\_by()](../../functions/get_user_by) wp-includes/pluggable.php | Retrieves user info by a given field. | | [WP\_Query::set\_found\_posts()](set_found_posts) wp-includes/class-wp-query.php | Set up the amount of found posts and the number of pages (if limit clause was used) for the current query. | | [WP\_Query::set()](set) wp-includes/class-wp-query.php | Sets the value of a query variable. | | [WP\_Query::parse\_orderby()](parse_orderby) wp-includes/class-wp-query.php | Converts the given orderby alias (if allowed) to a properly-prefixed value. | | [wpdb::get\_results()](../wpdb/get_results) wp-includes/class-wpdb.php | Retrieves an entire SQL result set from the database (i.e., many rows). | | [get\_post\_types()](../../functions/get_post_types) wp-includes/post.php | Gets a list of all registered post type objects. | | [wpdb::prepare()](../wpdb/prepare) wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | [get\_current\_user\_id()](../../functions/get_current_user_id) wp-includes/user.php | Gets the current user’s ID. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [wp\_cache\_get()](../../functions/wp_cache_get) wp-includes/cache.php | Retrieves the cache contents from the cache by key and group. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [wp\_basename()](../../functions/wp_basename) wp-includes/formatting.php | i18n-friendly version of basename(). | | [is\_user\_logged\_in()](../../functions/is_user_logged_in) wp-includes/pluggable.php | Determines whether the current visitor is a logged in user. | | [\_deprecated\_argument()](../../functions/_deprecated_argument) wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | Used By | Description | | --- | --- | | [WP\_Query::query()](query) wp-includes/class-wp-query.php | Sets up the WordPress query by parsing query string. | | Version | Description | | --- | --- | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |
programming_docs
wordpress WP_Query::get( string $query_var, mixed $default_value = '' ): mixed WP\_Query::get( string $query\_var, mixed $default\_value = '' ): mixed ======================================================================= Retrieves the value of a query variable. `$query_var` string Required Query variable key. `$default_value` mixed Optional Value to return if the query variable is not set. Default: `''` mixed Contents of the query variable. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function get( $query_var, $default_value = '' ) { if ( isset( $this->query_vars[ $query_var ] ) ) { return $this->query_vars[ $query_var ]; } return $default_value; } ``` | Used By | Description | | --- | --- | | [WP\_Query::generate\_postdata()](generate_postdata) wp-includes/class-wp-query.php | Generate post data. | | [WP\_Query::is\_feed()](is_feed) wp-includes/class-wp-query.php | Is the query for a feed? | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | [WP\_Query::is\_post\_type\_archive()](is_post_type_archive) wp-includes/class-wp-query.php | Is the query for an existing post type archive page? | | [get\_query\_var()](../../functions/get_query_var) wp-includes/query.php | Retrieves the value of a query variable in the [WP\_Query](../wp_query) class. | | [get\_body\_class()](../../functions/get_body_class) wp-includes/post-template.php | Retrieves an array of the class names for the body element. | | Version | Description | | --- | --- | | [3.9.0](https://developer.wordpress.org/reference/since/3.9.0/) | The `$default_value` argument was introduced. | | [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. | wordpress WP_Query::generate_cache_key( array $args, string $sql ): string WP\_Query::generate\_cache\_key( array $args, string $sql ): string =================================================================== Generate cache key. `$args` array Required Query arguments. `$sql` string Required SQL statement. string Cache key. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` protected function generate_cache_key( array $args, $sql ) { global $wpdb; unset( $args['cache_results'], $args['fields'], $args['lazy_load_term_meta'], $args['update_post_meta_cache'], $args['update_post_term_cache'], $args['update_menu_item_cache'], $args['suppress_filters'] ); $placeholder = $wpdb->placeholder_escape(); array_walk_recursive( $args, /* * Replace wpdb placeholders with the string used in the database * query to avoid unreachable cache keys. This is necessary because * the placeholder is randomly generated in each request. * * $value is passed by reference to allow it to be modified. * array_walk_recursive() does not return an array. */ function ( &$value ) use ( $wpdb, $placeholder ) { if ( is_string( $value ) && str_contains( $value, $placeholder ) ) { $value = $wpdb->remove_placeholder_escape( $value ); } } ); // Replace wpdb placeholder in the SQL statement used by the cache key. $sql = $wpdb->remove_placeholder_escape( $sql ); $key = md5( serialize( $args ) . $sql ); $last_changed = wp_cache_get_last_changed( 'posts' ); if ( ! empty( $this->tax_query->queries ) ) { $last_changed .= wp_cache_get_last_changed( 'terms' ); } return "wp_query:$key:$last_changed"; } ``` | Uses | Description | | --- | --- | | [wpdb::remove\_placeholder\_escape()](../wpdb/remove_placeholder_escape) wp-includes/class-wpdb.php | Removes the placeholder escape strings from a query. | | [wpdb::placeholder\_escape()](../wpdb/placeholder_escape) wp-includes/class-wpdb.php | Generates and returns a placeholder escape string for use in queries returned by ::prepare(). | | [wp\_cache\_get\_last\_changed()](../../functions/wp_cache_get_last_changed) wp-includes/functions.php | Gets last changed date for the specified cache group. | | Used By | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Query::generate_postdata( WP_Post|object|int $post ): array|false WP\_Query::generate\_postdata( WP\_Post|object|int $post ): array|false ======================================================================= Generate post data. `$post` [WP\_Post](../wp_post)|object|int Required [WP\_Post](../wp_post) instance or Post ID/object. array|false Elements of post or false on failure. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function generate_postdata( $post ) { if ( ! ( $post instanceof WP_Post ) ) { $post = get_post( $post ); } if ( ! $post ) { return false; } $id = (int) $post->ID; $authordata = get_userdata( $post->post_author ); $currentday = mysql2date( 'd.m.y', $post->post_date, false ); $currentmonth = mysql2date( 'm', $post->post_date, false ); $numpages = 1; $multipage = 0; $page = $this->get( 'page' ); if ( ! $page ) { $page = 1; } /* * Force full post content when viewing the permalink for the $post, * or when on an RSS feed. Otherwise respect the 'more' tag. */ if ( get_queried_object_id() === $post->ID && ( $this->is_page() || $this->is_single() ) ) { $more = 1; } elseif ( $this->is_feed() ) { $more = 1; } else { $more = 0; } $content = $post->post_content; if ( false !== strpos( $content, '<!--nextpage-->' ) ) { $content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content ); $content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content ); $content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content ); // Remove the nextpage block delimiters, to avoid invalid block structures in the split content. $content = str_replace( '<!-- wp:nextpage -->', '', $content ); $content = str_replace( '<!-- /wp:nextpage -->', '', $content ); // Ignore nextpage at the beginning of the content. if ( 0 === strpos( $content, '<!--nextpage-->' ) ) { $content = substr( $content, 15 ); } $pages = explode( '<!--nextpage-->', $content ); } else { $pages = array( $post->post_content ); } /** * Filters the "pages" derived from splitting the post content. * * "Pages" are determined by splitting the post content based on the presence * of `<!-- nextpage -->` tags. * * @since 4.4.0 * * @param string[] $pages Array of "pages" from the post content split by `<!-- nextpage -->` tags. * @param WP_Post $post Current post object. */ $pages = apply_filters( 'content_pagination', $pages, $post ); $numpages = count( $pages ); if ( $numpages > 1 ) { if ( $page > 1 ) { $more = 1; } $multipage = 1; } else { $multipage = 0; } $elements = compact( 'id', 'authordata', 'currentday', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages' ); return $elements; } ``` [apply\_filters( 'content\_pagination', string[] $pages, WP\_Post $post )](../../hooks/content_pagination) Filters the “pages” derived from splitting the post content. | Uses | Description | | --- | --- | | [WP\_Query::is\_page()](is_page) wp-includes/class-wp-query.php | Is the query for an existing single page? | | [WP\_Query::is\_single()](is_single) wp-includes/class-wp-query.php | Is the query for an existing single post? | | [WP\_Query::is\_feed()](is_feed) wp-includes/class-wp-query.php | Is the query for a feed? | | [WP\_Query::get()](get) wp-includes/class-wp-query.php | Retrieves the value of a query variable. | | [get\_queried\_object\_id()](../../functions/get_queried_object_id) wp-includes/query.php | Retrieves the ID of the currently queried object. | | [mysql2date()](../../functions/mysql2date) wp-includes/functions.php | Converts given MySQL date string into a different format. | | [get\_userdata()](../../functions/get_userdata) wp-includes/pluggable.php | Retrieves user info by user ID. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Used By | Description | | --- | --- | | [generate\_postdata()](../../functions/generate_postdata) wp-includes/query.php | Generates post data. | | [WP\_Query::setup\_postdata()](setup_postdata) wp-includes/class-wp-query.php | Set up global post data. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Query::is_day(): bool WP\_Query::is\_day(): bool ========================== Is the query for an existing day archive? bool Whether the query is for an existing day archive. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_day() { return (bool) $this->is_day; } ``` | Used By | Description | | --- | --- | | [is\_day()](../../functions/is_day) wp-includes/query.php | Determines whether the query is for an existing day archive. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_archive(): bool WP\_Query::is\_archive(): bool ============================== Is the query for an existing archive page? Archive pages include category, tag, author, date, custom post type, and custom taxonomy based archives. * [WP\_Query::is\_category()](../wp_query/is_category) * [WP\_Query::is\_tag()](../wp_query/is_tag) * [WP\_Query::is\_author()](../wp_query/is_author) * [WP\_Query::is\_date()](../wp_query/is_date) * [WP\_Query::is\_post\_type\_archive()](../wp_query/is_post_type_archive) * [WP\_Query::is\_tax()](../wp_query/is_tax) bool Whether the query is for an existing archive page. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_archive() { return (bool) $this->is_archive; } ``` | Used By | Description | | --- | --- | | [is\_archive()](../../functions/is_archive) wp-includes/query.php | Determines whether the query is for an existing archive page. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::parse_search( array $q ): string WP\_Query::parse\_search( array $q ): string ============================================ Generates SQL for the WHERE clause based on passed search terms. `$q` array Required Query variables. string WHERE clause. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` protected function parse_search( &$q ) { global $wpdb; $search = ''; // Added slashes screw with quote grouping when done early, so done later. $q['s'] = stripslashes( $q['s'] ); if ( empty( $_GET['s'] ) && $this->is_main_query() ) { $q['s'] = urldecode( $q['s'] ); } // There are no line breaks in <input /> fields. $q['s'] = str_replace( array( "\r", "\n" ), '', $q['s'] ); $q['search_terms_count'] = 1; if ( ! empty( $q['sentence'] ) ) { $q['search_terms'] = array( $q['s'] ); } else { if ( preg_match_all( '/".*?("|$)|((?<=[\t ",+])|^)[^\t ",+]+/', $q['s'], $matches ) ) { $q['search_terms_count'] = count( $matches[0] ); $q['search_terms'] = $this->parse_search_terms( $matches[0] ); // If the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence. if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ) { $q['search_terms'] = array( $q['s'] ); } } else { $q['search_terms'] = array( $q['s'] ); } } $n = ! empty( $q['exact'] ) ? '' : '%'; $searchand = ''; $q['search_orderby_title'] = array(); /** * Filters the prefix that indicates that a search term should be excluded from results. * * @since 4.7.0 * * @param string $exclusion_prefix The prefix. Default '-'. Returning * an empty value disables exclusions. */ $exclusion_prefix = apply_filters( 'wp_query_search_exclusion_prefix', '-' ); foreach ( $q['search_terms'] as $term ) { // If there is an $exclusion_prefix, terms prefixed with it should be excluded. $exclude = $exclusion_prefix && ( substr( $term, 0, 1 ) === $exclusion_prefix ); if ( $exclude ) { $like_op = 'NOT LIKE'; $andor_op = 'AND'; $term = substr( $term, 1 ); } else { $like_op = 'LIKE'; $andor_op = 'OR'; } if ( $n && ! $exclude ) { $like = '%' . $wpdb->esc_like( $term ) . '%'; $q['search_orderby_title'][] = $wpdb->prepare( "{$wpdb->posts}.post_title LIKE %s", $like ); } $like = $n . $wpdb->esc_like( $term ) . $n; if ( ! empty( $this->allow_query_attachment_by_filename ) ) { $search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s) $andor_op (sq1.meta_value $like_op %s))", $like, $like, $like, $like ); } else { $search .= $wpdb->prepare( "{$searchand}(({$wpdb->posts}.post_title $like_op %s) $andor_op ({$wpdb->posts}.post_excerpt $like_op %s) $andor_op ({$wpdb->posts}.post_content $like_op %s))", $like, $like, $like ); } $searchand = ' AND '; } if ( ! empty( $search ) ) { $search = " AND ({$search}) "; if ( ! is_user_logged_in() ) { $search .= " AND ({$wpdb->posts}.post_password = '') "; } } return $search; } ``` [apply\_filters( 'wp\_query\_search\_exclusion\_prefix', string $exclusion\_prefix )](../../hooks/wp_query_search_exclusion_prefix) Filters the prefix that indicates that a search term should be excluded from results. | Uses | Description | | --- | --- | | [wpdb::esc\_like()](../wpdb/esc_like) wp-includes/class-wpdb.php | First half of escaping for `LIKE` special characters `%` and `_` before preparing for SQL. | | [WP\_Query::is\_main\_query()](is_main_query) wp-includes/class-wp-query.php | Is the query the main query? | | [WP\_Query::parse\_search\_terms()](parse_search_terms) wp-includes/class-wp-query.php | Check if the terms are suitable for searching. | | [is\_user\_logged\_in()](../../functions/is_user_logged_in) wp-includes/pluggable.php | Determines whether the current visitor is a logged in user. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [wpdb::prepare()](../wpdb/prepare) wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. | | Used By | Description | | --- | --- | | [WP\_Query::get\_posts()](get_posts) wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress WP_Query::is_privacy_policy(): bool WP\_Query::is\_privacy\_policy(): bool ====================================== Is the query for the Privacy Policy page? This is the page which shows the Privacy Policy content of your site. Depends on the site’s "Change your Privacy Policy page" Privacy Settings ‘wp\_page\_for\_privacy\_policy’. This function will return true only on the page you set as the "Privacy Policy page". bool Whether the query is for the Privacy Policy page. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_privacy_policy() { if ( get_option( 'wp_page_for_privacy_policy' ) && $this->is_page( get_option( 'wp_page_for_privacy_policy' ) ) ) { return true; } else { return false; } } ``` | Uses | Description | | --- | --- | | [WP\_Query::is\_page()](is_page) wp-includes/class-wp-query.php | Is the query for an existing single page? | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Used By | Description | | --- | --- | | [is\_privacy\_policy()](../../functions/is_privacy_policy) wp-includes/query.php | Determines whether the query is for the Privacy Policy page. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Query::is_author( int|string|int[]|string[] $author = '' ): bool WP\_Query::is\_author( int|string|int[]|string[] $author = '' ): bool ===================================================================== Is the query for an existing author archive page? If the $author parameter is specified, this function will additionally check if the query is for one of the authors specified. `$author` int|string|int[]|string[] Optional User ID, nickname, nicename, or array of such to check against. Default: `''` bool Whether the query is for an existing author archive page. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_author( $author = '' ) { if ( ! $this->is_author ) { return false; } if ( empty( $author ) ) { return true; } $author_obj = $this->get_queried_object(); if ( ! $author_obj ) { return false; } $author = array_map( 'strval', (array) $author ); if ( in_array( (string) $author_obj->ID, $author, true ) ) { return true; } elseif ( in_array( $author_obj->nickname, $author, true ) ) { return true; } elseif ( in_array( $author_obj->user_nicename, $author, true ) ) { return true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Query::get\_queried\_object()](get_queried_object) wp-includes/class-wp-query.php | Retrieves the currently queried object. | | Used By | Description | | --- | --- | | [WP::register\_globals()](../wp/register_globals) wp-includes/class-wp.php | Set up the WordPress Globals. | | [is\_author()](../../functions/is_author) wp-includes/query.php | Determines whether the query is for an existing author archive page. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Query::is_paged(): bool WP\_Query::is\_paged(): bool ============================ Is the query for a paged result and not for the first page? bool Whether the query is for a paged result. File: `wp-includes/class-wp-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/) ``` public function is_paged() { return (bool) $this->is_paged; } ``` | Used By | Description | | --- | --- | | [is\_paged()](../../functions/is_paged) wp-includes/query.php | Determines whether the query is for a paged result and not for the first page. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress Requests_Transport_fsockopen::accept_encoding(): string Requests\_Transport\_fsockopen::accept\_encoding(): string ========================================================== Retrieve the encodings we can accept string Accept-Encoding header value File: `wp-includes/Requests/Transport/fsockopen.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/transport/fsockopen.php/) ``` protected static function accept_encoding() { $type = array(); if (function_exists('gzinflate')) { $type[] = 'deflate;q=1.0'; } if (function_exists('gzuncompress')) { $type[] = 'compress;q=0.5'; } $type[] = 'gzip;q=0.5'; return implode(', ', $type); } ``` | Used By | Description | | --- | --- | | [Requests\_Transport\_fsockopen::request()](request) wp-includes/Requests/Transport/fsockopen.php | Perform a request |
programming_docs
wordpress Requests_Transport_fsockopen::request_multiple( array $requests, array $options ): array Requests\_Transport\_fsockopen::request\_multiple( array $requests, array $options ): array =========================================================================================== Send multiple requests simultaneously `$requests` array Required Request data (array of `'url'`, `'headers'`, `'data'`, `'options'`) as per [Requests\_Transport::request](../requests_transport/request) `$options` array Required Global options, see [Requests::response()](../requests/response) for documentation array Array of [Requests\_Response](../requests_response) objects (may contain [Requests\_Exception](../requests_exception) or string responses as well) File: `wp-includes/Requests/Transport/fsockopen.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/transport/fsockopen.php/) ``` public function request_multiple($requests, $options) { $responses = array(); $class = get_class($this); foreach ($requests as $id => $request) { try { $handler = new $class(); $responses[$id] = $handler->request($request['url'], $request['headers'], $request['data'], $request['options']); $request['options']['hooks']->dispatch('transport.internal.parse_response', array(&$responses[$id], $request)); } catch (Requests_Exception $e) { $responses[$id] = $e; } if (!is_string($responses[$id])) { $request['options']['hooks']->dispatch('multiple.request.complete', array(&$responses[$id], $id)); } } return $responses; } ``` wordpress Requests_Transport_fsockopen::verify_certificate_from_context( string $host, resource $context ): bool Requests\_Transport\_fsockopen::verify\_certificate\_from\_context( string $host, resource $context ): bool =========================================================================================================== Verify the certificate against common name and subject alternative names Unfortunately, PHP doesn’t check the certificate against the alternative names, leading things like ‘<https://www.github.com/>‘ to be invalid. Instead * <https://tools.ietf.org/html/rfc2818#section-3.1>: RFC2818, Section 3.1 `$host` string Required Host name to verify against `$context` resource Required Stream context bool File: `wp-includes/Requests/Transport/fsockopen.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/transport/fsockopen.php/) ``` public function verify_certificate_from_context($host, $context) { $meta = stream_context_get_options($context); // If we don't have SSL options, then we couldn't make the connection at // all if (empty($meta) || empty($meta['ssl']) || empty($meta['ssl']['peer_certificate'])) { throw new Requests_Exception(rtrim($this->connect_error), 'ssl.connect_error'); } $cert = openssl_x509_parse($meta['ssl']['peer_certificate']); return Requests_SSL::verify_certificate($host, $cert); } ``` | Uses | Description | | --- | --- | | [Requests\_Exception::\_\_construct()](../requests_exception/__construct) wp-includes/Requests/Exception.php | Create a new exception | | [Requests\_SSL::verify\_certificate()](../requests_ssl/verify_certificate) wp-includes/Requests/SSL.php | Verify the certificate against common name and subject alternative names | | Used By | Description | | --- | --- | | [Requests\_Transport\_fsockopen::request()](request) wp-includes/Requests/Transport/fsockopen.php | Perform a request | wordpress Requests_Transport_fsockopen::format_get( array $url_parts, array|object $data ): string Requests\_Transport\_fsockopen::format\_get( array $url\_parts, array|object $data ): string ============================================================================================ Format a URL given GET data `$url_parts` array Required `$data` array|object Required Data to build query using, see <https://secure.php.net/http_build_query> string URL with data File: `wp-includes/Requests/Transport/fsockopen.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/transport/fsockopen.php/) ``` protected static function format_get($url_parts, $data) { if (!empty($data)) { if (empty($url_parts['query'])) { $url_parts['query'] = ''; } $url_parts['query'] .= '&' . http_build_query($data, '', '&'); $url_parts['query'] = trim($url_parts['query'], '&'); } if (isset($url_parts['path'])) { if (isset($url_parts['query'])) { $get = $url_parts['path'] . '?' . $url_parts['query']; } else { $get = $url_parts['path']; } } else { $get = '/'; } return $get; } ``` | Used By | Description | | --- | --- | | [Requests\_Transport\_fsockopen::request()](request) wp-includes/Requests/Transport/fsockopen.php | Perform a request | wordpress Requests_Transport_fsockopen::test( $capabilities = array() ): boolean Requests\_Transport\_fsockopen::test( $capabilities = array() ): boolean ======================================================================== Whether this transport is valid boolean True if the transport is valid, false otherwise. File: `wp-includes/Requests/Transport/fsockopen.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/transport/fsockopen.php/) ``` public static function test($capabilities = array()) { if (!function_exists('fsockopen')) { return false; } // If needed, check that streams support SSL if (isset($capabilities['ssl']) && $capabilities['ssl']) { if (!extension_loaded('openssl') || !function_exists('openssl_x509_parse')) { return false; } // Currently broken, thanks to https://github.com/facebook/hhvm/issues/2156 if (defined('HHVM_VERSION')) { return false; } } return true; } ``` wordpress Requests_Transport_fsockopen::connect_error_handler( int $errno, string $errstr ) Requests\_Transport\_fsockopen::connect\_error\_handler( int $errno, string $errstr ) ===================================================================================== Error handler for stream\_socket\_client() `$errno` int Required Error number (e.g. E\_WARNING) `$errstr` string Required Error message File: `wp-includes/Requests/Transport/fsockopen.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/transport/fsockopen.php/) ``` public function connect_error_handler($errno, $errstr) { // Double-check we can handle it if (($errno & E_WARNING) === 0 && ($errno & E_NOTICE) === 0) { // Return false to indicate the default error handler should engage return false; } $this->connect_error .= $errstr . "\n"; return true; } ``` wordpress Requests_Transport_fsockopen::request( string $url, array $headers = array(), string|array $data = array(), array $options = array() ): string Requests\_Transport\_fsockopen::request( string $url, array $headers = array(), string|array $data = array(), array $options = array() ): string ================================================================================================================================================ Perform a request `$url` string Required URL to request `$headers` array Optional Associative array of request headers Default: `array()` `$data` string|array Optional Data to send either as the POST body, or as parameters in the URL for a GET/HEAD Default: `array()` `$options` array Optional Request options, see [Requests::response()](../requests/response) for documentation Default: `array()` string Raw HTTP result File: `wp-includes/Requests/Transport/fsockopen.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/transport/fsockopen.php/) ``` public function request($url, $headers = array(), $data = array(), $options = array()) { $options['hooks']->dispatch('fsockopen.before_request'); $url_parts = parse_url($url); if (empty($url_parts)) { throw new Requests_Exception('Invalid URL.', 'invalidurl', $url); } $host = $url_parts['host']; $context = stream_context_create(); $verifyname = false; $case_insensitive_headers = new Requests_Utility_CaseInsensitiveDictionary($headers); // HTTPS support if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') { $remote_socket = 'ssl://' . $host; if (!isset($url_parts['port'])) { $url_parts['port'] = 443; } $context_options = array( 'verify_peer' => true, 'capture_peer_cert' => true, ); $verifyname = true; // SNI, if enabled (OpenSSL >=0.9.8j) // phpcs:ignore PHPCompatibility.Constants.NewConstants.openssl_tlsext_server_nameFound if (defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME) { $context_options['SNI_enabled'] = true; if (isset($options['verifyname']) && $options['verifyname'] === false) { $context_options['SNI_enabled'] = false; } } if (isset($options['verify'])) { if ($options['verify'] === false) { $context_options['verify_peer'] = false; $context_options['verify_peer_name'] = false; $verifyname = false; } elseif (is_string($options['verify'])) { $context_options['cafile'] = $options['verify']; } } if (isset($options['verifyname']) && $options['verifyname'] === false) { $context_options['verify_peer_name'] = false; $verifyname = false; } stream_context_set_option($context, array('ssl' => $context_options)); } else { $remote_socket = 'tcp://' . $host; } $this->max_bytes = $options['max_bytes']; if (!isset($url_parts['port'])) { $url_parts['port'] = 80; } $remote_socket .= ':' . $url_parts['port']; // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler set_error_handler(array($this, 'connect_error_handler'), E_WARNING | E_NOTICE); $options['hooks']->dispatch('fsockopen.remote_socket', array(&$remote_socket)); $socket = stream_socket_client($remote_socket, $errno, $errstr, ceil($options['connect_timeout']), STREAM_CLIENT_CONNECT, $context); restore_error_handler(); if ($verifyname && !$this->verify_certificate_from_context($host, $context)) { throw new Requests_Exception('SSL certificate did not match the requested domain name', 'ssl.no_match'); } if (!$socket) { if ($errno === 0) { // Connection issue throw new Requests_Exception(rtrim($this->connect_error), 'fsockopen.connect_error'); } throw new Requests_Exception($errstr, 'fsockopenerror', null, $errno); } $data_format = $options['data_format']; if ($data_format === 'query') { $path = self::format_get($url_parts, $data); $data = ''; } else { $path = self::format_get($url_parts, array()); } $options['hooks']->dispatch('fsockopen.remote_host_path', array(&$path, $url)); $request_body = ''; $out = sprintf("%s %s HTTP/%.1F\r\n", $options['type'], $path, $options['protocol_version']); if ($options['type'] !== Requests::TRACE) { if (is_array($data)) { $request_body = http_build_query($data, '', '&'); } else { $request_body = $data; } // Always include Content-length on POST requests to prevent // 411 errors from some servers when the body is empty. if (!empty($data) || $options['type'] === Requests::POST) { if (!isset($case_insensitive_headers['Content-Length'])) { $headers['Content-Length'] = strlen($request_body); } if (!isset($case_insensitive_headers['Content-Type'])) { $headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; } } } if (!isset($case_insensitive_headers['Host'])) { $out .= sprintf('Host: %s', $url_parts['host']); if ((strtolower($url_parts['scheme']) === 'http' && $url_parts['port'] !== 80) || (strtolower($url_parts['scheme']) === 'https' && $url_parts['port'] !== 443)) { $out .= ':' . $url_parts['port']; } $out .= "\r\n"; } if (!isset($case_insensitive_headers['User-Agent'])) { $out .= sprintf("User-Agent: %s\r\n", $options['useragent']); } $accept_encoding = $this->accept_encoding(); if (!isset($case_insensitive_headers['Accept-Encoding']) && !empty($accept_encoding)) { $out .= sprintf("Accept-Encoding: %s\r\n", $accept_encoding); } $headers = Requests::flatten($headers); if (!empty($headers)) { $out .= implode("\r\n", $headers) . "\r\n"; } $options['hooks']->dispatch('fsockopen.after_headers', array(&$out)); if (substr($out, -2) !== "\r\n") { $out .= "\r\n"; } if (!isset($case_insensitive_headers['Connection'])) { $out .= "Connection: Close\r\n"; } $out .= "\r\n" . $request_body; $options['hooks']->dispatch('fsockopen.before_send', array(&$out)); fwrite($socket, $out); $options['hooks']->dispatch('fsockopen.after_send', array($out)); if (!$options['blocking']) { fclose($socket); $fake_headers = ''; $options['hooks']->dispatch('fsockopen.after_request', array(&$fake_headers)); return ''; } $timeout_sec = (int) floor($options['timeout']); if ($timeout_sec === $options['timeout']) { $timeout_msec = 0; } else { $timeout_msec = self::SECOND_IN_MICROSECONDS * $options['timeout'] % self::SECOND_IN_MICROSECONDS; } stream_set_timeout($socket, $timeout_sec, $timeout_msec); $response = ''; $body = ''; $headers = ''; $this->info = stream_get_meta_data($socket); $size = 0; $doingbody = false; $download = false; if ($options['filename']) { $download = fopen($options['filename'], 'wb'); } while (!feof($socket)) { $this->info = stream_get_meta_data($socket); if ($this->info['timed_out']) { throw new Requests_Exception('fsocket timed out', 'timeout'); } $block = fread($socket, Requests::BUFFER_SIZE); if (!$doingbody) { $response .= $block; if (strpos($response, "\r\n\r\n")) { list($headers, $block) = explode("\r\n\r\n", $response, 2); $doingbody = true; } } // Are we in body mode now? if ($doingbody) { $options['hooks']->dispatch('request.progress', array($block, $size, $this->max_bytes)); $data_length = strlen($block); if ($this->max_bytes) { // Have we already hit a limit? if ($size === $this->max_bytes) { continue; } if (($size + $data_length) > $this->max_bytes) { // Limit the length $limited_length = ($this->max_bytes - $size); $block = substr($block, 0, $limited_length); } } $size += strlen($block); if ($download) { fwrite($download, $block); } else { $body .= $block; } } } $this->headers = $headers; if ($download) { fclose($download); } else { $this->headers .= "\r\n\r\n" . $body; } fclose($socket); $options['hooks']->dispatch('fsockopen.after_request', array(&$this->headers, &$this->info)); return $this->headers; } ``` | Uses | Description | | --- | --- | | [Requests::flatten()](../requests/flatten) wp-includes/class-requests.php | Convert a key => value array to a ‘key: value’ array for headers | | [Requests\_Utility\_CaseInsensitiveDictionary::\_\_construct()](../requests_utility_caseinsensitivedictionary/__construct) wp-includes/Requests/Utility/CaseInsensitiveDictionary.php | Creates a case insensitive dictionary. | | [Requests\_Exception::\_\_construct()](../requests_exception/__construct) wp-includes/Requests/Exception.php | Create a new exception | | [Requests\_Transport\_fsockopen::verify\_certificate\_from\_context()](verify_certificate_from_context) wp-includes/Requests/Transport/fsockopen.php | Verify the certificate against common name and subject alternative names | | [Requests\_Transport\_fsockopen::format\_get()](format_get) wp-includes/Requests/Transport/fsockopen.php | Format a URL given GET data | | [Requests\_Transport\_fsockopen::accept\_encoding()](accept_encoding) wp-includes/Requests/Transport/fsockopen.php | Retrieve the encodings we can accept | wordpress WP_Customize_Nav_Menu_Item_Control::content_template() WP\_Customize\_Nav\_Menu\_Item\_Control::content\_template() ============================================================ JS/Underscore template for the control UI. File: `wp-includes/customize/class-wp-customize-nav-menu-item-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menu-item-control.php/) ``` public function content_template() { ?> <div class="menu-item-bar"> <div class="menu-item-handle"> <span class="item-type" aria-hidden="true">{{ data.item_type_label }}</span> <span class="item-title" aria-hidden="true"> <span class="spinner"></span> <span class="menu-item-title<# if ( ! data.title && ! data.original_title ) { #> no-title<# } #>">{{ data.title || data.original_title || wp.customize.Menus.data.l10n.untitled }}</span> </span> <span class="item-controls"> <button type="button" class="button-link item-edit" aria-expanded="false"><span class="screen-reader-text"> <?php /* translators: 1: Title of a menu item, 2: Type of a menu item. */ printf( __( 'Edit menu item: %1$s (%2$s)' ), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.item_type_label }}' ); ?> </span><span class="toggle-indicator" aria-hidden="true"></span></button> <button type="button" class="button-link item-delete submitdelete deletion"><span class="screen-reader-text"> <?php /* translators: 1: Title of a menu item, 2: Type of a menu item. */ printf( __( 'Remove Menu Item: %1$s (%2$s)' ), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.item_type_label }}' ); ?> </span></button> </span> </div> </div> <div class="menu-item-settings" id="menu-item-settings-{{ data.menu_item_id }}"> <# if ( 'custom' === data.item_type ) { #> <p class="field-url description description-thin"> <label for="edit-menu-item-url-{{ data.menu_item_id }}"> <?php _e( 'URL' ); ?><br /> <input class="widefat code edit-menu-item-url" type="text" id="edit-menu-item-url-{{ data.menu_item_id }}" name="menu-item-url" /> </label> </p> <# } #> <p class="description description-thin"> <label for="edit-menu-item-title-{{ data.menu_item_id }}"> <?php _e( 'Navigation Label' ); ?><br /> <input type="text" id="edit-menu-item-title-{{ data.menu_item_id }}" placeholder="{{ data.original_title }}" class="widefat edit-menu-item-title" name="menu-item-title" /> </label> </p> <p class="field-link-target description description-thin"> <label for="edit-menu-item-target-{{ data.menu_item_id }}"> <input type="checkbox" id="edit-menu-item-target-{{ data.menu_item_id }}" class="edit-menu-item-target" value="_blank" name="menu-item-target" /> <?php _e( 'Open link in a new tab' ); ?> </label> </p> <p class="field-title-attribute field-attr-title description description-thin"> <label for="edit-menu-item-attr-title-{{ data.menu_item_id }}"> <?php _e( 'Title Attribute' ); ?><br /> <input type="text" id="edit-menu-item-attr-title-{{ data.menu_item_id }}" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title" /> </label> </p> <p class="field-css-classes description description-thin"> <label for="edit-menu-item-classes-{{ data.menu_item_id }}"> <?php _e( 'CSS Classes' ); ?><br /> <input type="text" id="edit-menu-item-classes-{{ data.menu_item_id }}" class="widefat code edit-menu-item-classes" name="menu-item-classes" /> </label> </p> <p class="field-xfn description description-thin"> <label for="edit-menu-item-xfn-{{ data.menu_item_id }}"> <?php _e( 'Link Relationship (XFN)' ); ?><br /> <input type="text" id="edit-menu-item-xfn-{{ data.menu_item_id }}" class="widefat code edit-menu-item-xfn" name="menu-item-xfn" /> </label> </p> <p class="field-description description description-thin"> <label for="edit-menu-item-description-{{ data.menu_item_id }}"> <?php _e( 'Description' ); ?><br /> <textarea id="edit-menu-item-description-{{ data.menu_item_id }}" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description">{{ data.description }}</textarea> <span class="description"><?php _e( 'The description will be displayed in the menu if the active theme supports it.' ); ?></span> </label> </p> <?php /** * Fires at the end of the form field template for nav menu items in the customizer. * * Additional fields can be rendered here and managed in JavaScript. * * @since 5.4.0 */ do_action( 'wp_nav_menu_item_custom_fields_customize_template' ); ?> <div class="menu-item-actions description-thin submitbox"> <# if ( ( 'post_type' === data.item_type || 'taxonomy' === data.item_type ) && '' !== data.original_title ) { #> <p class="link-to-original"> <?php /* translators: Nav menu item original title. %s: Original title. */ printf( __( 'Original: %s' ), '<a class="original-link" href="{{ data.url }}">{{ data.original_title }}</a>' ); ?> </p> <# } #> <button type="button" class="button-link button-link-delete item-delete submitdelete deletion"><?php _e( 'Remove' ); ?></button> <span class="spinner"></span> </div> <input type="hidden" name="menu-item-db-id[{{ data.menu_item_id }}]" class="menu-item-data-db-id" value="{{ data.menu_item_id }}" /> <input type="hidden" name="menu-item-parent-id[{{ data.menu_item_id }}]" class="menu-item-data-parent-id" value="{{ data.parent }}" /> </div><!-- .menu-item-settings--> <ul class="menu-item-transport"></ul> <?php } ``` [do\_action( 'wp\_nav\_menu\_item\_custom\_fields\_customize\_template' )](../../hooks/wp_nav_menu_item_custom_fields_customize_template) Fires at the end of the form field template for nav menu items in the customizer. | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |
programming_docs
wordpress WP_Customize_Nav_Menu_Item_Control::json(): array WP\_Customize\_Nav\_Menu\_Item\_Control::json(): array ====================================================== Return parameters for this control. array Exported parameters. File: `wp-includes/customize/class-wp-customize-nav-menu-item-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menu-item-control.php/) ``` public function json() { $exported = parent::json(); $exported['menu_item_id'] = $this->setting->post_id; return $exported; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Control::json()](../wp_customize_control/json) wp-includes/class-wp-customize-control.php | Get the data to export to the client via JSON. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menu_Item_Control::__construct( WP_Customize_Manager $manager, string $id, array $args = array() ) WP\_Customize\_Nav\_Menu\_Item\_Control::\_\_construct( WP\_Customize\_Manager $manager, string $id, array $args = array() ) ============================================================================================================================ Constructor. * [WP\_Customize\_Control::\_\_construct()](../wp_customize_control/__construct) `$manager` [WP\_Customize\_Manager](../wp_customize_manager) Required Customizer bootstrap instance. `$id` string Required The control ID. `$args` array Optional Arguments to override class property defaults. See [WP\_Customize\_Control::\_\_construct()](../wp_customize_control/__construct) for information on accepted arguments. More Arguments from WP\_Customize\_Control::\_\_construct( ... $args ) Array of properties for the new Control object. * `instance_number`intOrder in which this instance was created in relation to other instances. * `manager`[WP\_Customize\_Manager](../wp_customize_manager)Customizer bootstrap instance. * `id`stringControl ID. * `settings`arrayAll settings tied to the control. If undefined, `$id` will be used. * `setting`stringThe primary setting for the control (if there is one). Default `'default'`. * `capability`stringCapability required to use this control. Normally this is empty and the capability is derived from `$settings`. * `priority`intOrder priority to load the control. Default 10. * `section`stringSection the control belongs to. * `label`stringLabel for the control. * `description`stringDescription for the control. * `choices`arrayList of choices for `'radio'` or `'select'` type controls, where values are the keys, and labels are the values. * `input_attrs`arrayList of custom input attributes for control output, where attribute names are the keys and values are the values. Not used for `'checkbox'`, `'radio'`, `'select'`, `'textarea'`, or `'dropdown-pages'` control types. * `allow_addition`boolShow UI for adding new content, currently only used for the dropdown-pages control. Default false. * `json`arrayDeprecated. Use [WP\_Customize\_Control::json()](../wp_customize_control/json) instead. * `type`stringControl type. Core controls include `'text'`, `'checkbox'`, `'textarea'`, `'radio'`, `'select'`, and `'dropdown-pages'`. Additional input types such as `'email'`, `'url'`, `'number'`, `'hidden'`, and `'date'` are supported implicitly. Default `'text'`. * `active_callback`callableActive callback. Default: `array()` File: `wp-includes/customize/class-wp-customize-nav-menu-item-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menu-item-control.php/) ``` public function __construct( $manager, $id, $args = array() ) { parent::__construct( $manager, $id, $args ); } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Control::\_\_construct()](../wp_customize_control/__construct) wp-includes/class-wp-customize-control.php | Constructor. | | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::customize\_register()](../wp_customize_nav_menus/customize_register) wp-includes/class-wp-customize-nav-menus.php | Adds the customizer settings and controls. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menu_Item_Control::render_content() WP\_Customize\_Nav\_Menu\_Item\_Control::render\_content() ========================================================== Don’t render the control’s content – it’s rendered with a JS template. File: `wp-includes/customize/class-wp-customize-nav-menu-item-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-nav-menu-item-control.php/) ``` public function render_content() {} ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_REST_Search_Controller::prepare_item_for_response( int|string $item, WP_REST_Request $request ): WP_REST_Response WP\_REST\_Search\_Controller::prepare\_item\_for\_response( int|string $item, WP\_REST\_Request $request ): WP\_REST\_Response ============================================================================================================================== Prepares a single search result for response. `$item` int|string Required ID of the item to prepare. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request object. [WP\_REST\_Response](../wp_rest_response) Response object. File: `wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/) ``` public function prepare_item_for_response( $item, $request ) { // Restores the more descriptive, specific name for use within this method. $item_id = $item; $handler = $this->get_search_handler( $request ); if ( is_wp_error( $handler ) ) { return new WP_REST_Response(); } $fields = $this->get_fields_for_response( $request ); $data = $handler->prepare_item( $item_id, $fields ); $data = $this->add_additional_fields_to_object( $data, $request ); $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $links = $handler->prepare_item_links( $item_id ); $links['collection'] = array( 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ); $response->add_links( $links ); } return $response; } ``` | Uses | Description | | --- | --- | | [rest\_is\_field\_included()](../../functions/rest_is_field_included) wp-includes/rest-api.php | Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body. | | [WP\_REST\_Search\_Controller::get\_search\_handler()](get_search_handler) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Gets the search handler to handle the current request. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [WP\_REST\_Search\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Retrieves a collection of search results. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$id` to `$item` to match parent class for PHP 8 named parameter support. | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | The `$id` parameter can accept a string. | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Search_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Search\_Controller::get\_items( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ==================================================================================================== Retrieves a collection of search results. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/) ``` public function get_items( $request ) { $handler = $this->get_search_handler( $request ); if ( is_wp_error( $handler ) ) { return $handler; } $result = $handler->search_items( $request ); if ( ! isset( $result[ WP_REST_Search_Handler::RESULT_IDS ] ) || ! is_array( $result[ WP_REST_Search_Handler::RESULT_IDS ] ) || ! isset( $result[ WP_REST_Search_Handler::RESULT_TOTAL ] ) ) { return new WP_Error( 'rest_search_handler_error', __( 'Internal search handler error.' ), array( 'status' => 500 ) ); } $ids = $result[ WP_REST_Search_Handler::RESULT_IDS ]; $results = array(); foreach ( $ids as $id ) { $data = $this->prepare_item_for_response( $id, $request ); $results[] = $this->prepare_response_for_collection( $data ); } $total = (int) $result[ WP_REST_Search_Handler::RESULT_TOTAL ]; $page = (int) $request['page']; $per_page = (int) $request['per_page']; $max_pages = ceil( $total / $per_page ); if ( $page > $max_pages && $total > 0 ) { return new WP_Error( 'rest_search_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); } $response = rest_ensure_response( $results ); $response->header( 'X-WP-Total', $total ); $response->header( 'X-WP-TotalPages', $max_pages ); $request_params = $request->get_query_params(); $base = add_query_arg( urlencode_deep( $request_params ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); if ( $page > 1 ) { $prev_link = add_query_arg( 'page', $page - 1, $base ); $response->link_header( 'prev', $prev_link ); } if ( $page < $max_pages ) { $next_link = add_query_arg( 'page', $page + 1, $base ); $response->link_header( 'next', $next_link ); } return $response; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Search\_Controller::get\_search\_handler()](get_search_handler) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Gets the search handler to handle the current request. | | [WP\_REST\_Search\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Prepares a single search result for response. | | [urlencode\_deep()](../../functions/urlencode_deep) wp-includes/formatting.php | Navigates through an array, object, or scalar, and encodes the values to be used in a URL. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Search_Controller::sanitize_subtypes( string|array $subtypes, WP_REST_Request $request, string $parameter ): array|WP_Error WP\_REST\_Search\_Controller::sanitize\_subtypes( string|array $subtypes, WP\_REST\_Request $request, string $parameter ): array|WP\_Error ========================================================================================================================================== Sanitizes the list of subtypes, to ensure only subtypes of the passed type are included. `$subtypes` string|array Required One or more subtypes. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. `$parameter` string Required Parameter name. array|[WP\_Error](../wp_error) List of valid subtypes, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/) ``` public function sanitize_subtypes( $subtypes, $request, $parameter ) { $subtypes = wp_parse_slug_list( $subtypes ); $subtypes = rest_parse_request_arg( $subtypes, $request, $parameter ); if ( is_wp_error( $subtypes ) ) { return $subtypes; } // 'any' overrides any other subtype. if ( in_array( self::TYPE_ANY, $subtypes, true ) ) { return array( self::TYPE_ANY ); } $handler = $this->get_search_handler( $request ); if ( is_wp_error( $handler ) ) { return $handler; } return array_intersect( $subtypes, $handler->get_subtypes() ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Search\_Controller::get\_search\_handler()](get_search_handler) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Gets the search handler to handle the current request. | | [rest\_parse\_request\_arg()](../../functions/rest_parse_request_arg) wp-includes/rest-api.php | Parse a request argument based on details registered to the route. | | [wp\_parse\_slug\_list()](../../functions/wp_parse_slug_list) wp-includes/functions.php | Cleans up an array, comma- or space-separated list of slugs. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Search_Controller::get_items_permission_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Search\_Controller::get\_items\_permission\_check( WP\_REST\_Request $request ): true|WP\_Error ========================================================================================================= Checks if a given request has access to search content. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has search access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/) ``` public function get_items_permission_check( $request ) { return true; } ``` | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Search_Controller::register_routes() WP\_REST\_Search\_Controller::register\_routes() ================================================ Registers the routes for the search controller. * [register\_rest\_route()](../../functions/register_rest_route) File: `wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/) ``` public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permission_check' ), 'args' => $this->get_collection_params(), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Search\_Controller::get\_collection\_params()](get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Retrieves the query params for the search results collection. | | [register\_rest\_route()](../../functions/register_rest_route) wp-includes/rest-api.php | Registers a REST API route. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Search_Controller::get_collection_params(): array WP\_REST\_Search\_Controller::get\_collection\_params(): array ============================================================== Retrieves the query params for the search results collection. array Collection parameters. File: `wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/) ``` public function get_collection_params() { $types = array(); $subtypes = array(); foreach ( $this->search_handlers as $search_handler ) { $types[] = $search_handler->get_type(); $subtypes = array_merge( $subtypes, $search_handler->get_subtypes() ); } $types = array_unique( $types ); $subtypes = array_unique( $subtypes ); $query_params = parent::get_collection_params(); $query_params['context']['default'] = 'view'; $query_params[ self::PROP_TYPE ] = array( 'default' => $types[0], 'description' => __( 'Limit results to items of an object type.' ), 'type' => 'string', 'enum' => $types, ); $query_params[ self::PROP_SUBTYPE ] = array( 'default' => self::TYPE_ANY, 'description' => __( 'Limit results to items of one or more object subtypes.' ), 'type' => 'array', 'items' => array( 'enum' => array_merge( $subtypes, array( self::TYPE_ANY ) ), 'type' => 'string', ), 'sanitize_callback' => array( $this, 'sanitize_subtypes' ), ); $query_params['exclude'] = array( 'description' => __( 'Ensure result set excludes specific IDs.' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), ); $query_params['include'] = array( 'description' => __( 'Limit result set to specific IDs.' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), ); return $query_params; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Controller::get\_collection\_params()](../wp_rest_controller/get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves the query params for the collections. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_REST\_Search\_Controller::register\_routes()](register_routes) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Registers the routes for the search controller. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. |
programming_docs
wordpress WP_REST_Search_Controller::__construct( array $search_handlers ) WP\_REST\_Search\_Controller::\_\_construct( array $search\_handlers ) ====================================================================== Constructor. `$search_handlers` array Required List of search handlers to use in the controller. Each search handler instance must extend the `WP_REST_Search_Handler` class. File: `wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/) ``` public function __construct( array $search_handlers ) { $this->namespace = 'wp/v2'; $this->rest_base = 'search'; foreach ( $search_handlers as $search_handler ) { if ( ! $search_handler instanceof WP_REST_Search_Handler ) { _doing_it_wrong( __METHOD__, /* translators: %s: PHP class name. */ sprintf( __( 'REST search handlers must extend the %s class.' ), 'WP_REST_Search_Handler' ), '5.0.0' ); continue; } $this->search_handlers[ $search_handler->get_type() ] = $search_handler; } } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_doing\_it\_wrong()](../../functions/_doing_it_wrong) wp-includes/functions.php | Marks something as being incorrectly called. | | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Search_Controller::get_search_handler( WP_REST_Request $request ): WP_REST_Search_Handler|WP_Error WP\_REST\_Search\_Controller::get\_search\_handler( WP\_REST\_Request $request ): WP\_REST\_Search\_Handler|WP\_Error ===================================================================================================================== Gets the search handler to handle the current request. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Search\_Handler](../wp_rest_search_handler)|[WP\_Error](../wp_error) Search handler for the request type, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/) ``` protected function get_search_handler( $request ) { $type = $request->get_param( self::PROP_TYPE ); if ( ! $type || ! isset( $this->search_handlers[ $type ] ) ) { return new WP_Error( 'rest_search_invalid_type', __( 'Invalid type parameter.' ), array( 'status' => 400 ) ); } return $this->search_handlers[ $type ]; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Search\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Retrieves a collection of search results. | | [WP\_REST\_Search\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Prepares a single search result for response. | | [WP\_REST\_Search\_Controller::sanitize\_subtypes()](sanitize_subtypes) wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Sanitizes the list of subtypes, to ensure only subtypes of the passed type are included. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Search_Controller::get_item_schema(): array WP\_REST\_Search\_Controller::get\_item\_schema(): array ======================================================== Retrieves the item schema, conforming to JSON Schema. array Item schema data. File: `wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $types = array(); $subtypes = array(); foreach ( $this->search_handlers as $search_handler ) { $types[] = $search_handler->get_type(); $subtypes = array_merge( $subtypes, $search_handler->get_subtypes() ); } $types = array_unique( $types ); $subtypes = array_unique( $subtypes ); $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'search-result', 'type' => 'object', 'properties' => array( self::PROP_ID => array( 'description' => __( 'Unique identifier for the object.' ), 'type' => array( 'integer', 'string' ), 'context' => array( 'view', 'embed' ), 'readonly' => true, ), self::PROP_TITLE => array( 'description' => __( 'The title for the object.' ), 'type' => 'string', 'context' => array( 'view', 'embed' ), 'readonly' => true, ), self::PROP_URL => array( 'description' => __( 'URL to the object.' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'embed' ), 'readonly' => true, ), self::PROP_TYPE => array( 'description' => __( 'Object type.' ), 'type' => 'string', 'enum' => $types, 'context' => array( 'view', 'embed' ), 'readonly' => true, ), self::PROP_SUBTYPE => array( 'description' => __( 'Object subtype.' ), 'type' => 'string', 'enum' => $subtypes, 'context' => array( 'view', 'embed' ), 'readonly' => true, ), ), ); $this->schema = $schema; return $this->add_additional_fields_schema( $this->schema ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_Customize_Theme_Control::content_template() WP\_Customize\_Theme\_Control::content\_template() ================================================== Render a JS template for theme display. File: `wp-includes/customize/class-wp-customize-theme-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-theme-control.php/) ``` public function content_template() { /* translators: %s: Theme name. */ $details_label = sprintf( __( 'Details for theme: %s' ), '{{ data.theme.name }}' ); /* translators: %s: Theme name. */ $customize_label = sprintf( __( 'Customize theme: %s' ), '{{ data.theme.name }}' ); /* translators: %s: Theme name. */ $preview_label = sprintf( __( 'Live preview theme: %s' ), '{{ data.theme.name }}' ); /* translators: %s: Theme name. */ $install_label = sprintf( __( 'Install and preview theme: %s' ), '{{ data.theme.name }}' ); ?> <# if ( data.theme.active ) { #> <div class="theme active" tabindex="0" aria-describedby="{{ data.section }}-{{ data.theme.id }}-action"> <# } else { #> <div class="theme" tabindex="0" aria-describedby="{{ data.section }}-{{ data.theme.id }}-action"> <# } #> <# if ( data.theme.screenshot && data.theme.screenshot[0] ) { #> <div class="theme-screenshot"> <img data-src="{{ data.theme.screenshot[0] }}?ver={{ data.theme.version }}" alt="" /> </div> <# } else { #> <div class="theme-screenshot blank"></div> <# } #> <span class="more-details theme-details" id="{{ data.section }}-{{ data.theme.id }}-action" aria-label="<?php echo esc_attr( $details_label ); ?>"><?php _e( 'Theme Details' ); ?></span> <div class="theme-author"> <?php /* translators: Theme author name. */ printf( _x( 'By %s', 'theme author' ), '{{ data.theme.author }}' ); ?> </div> <# if ( 'installed' === data.theme.type && data.theme.hasUpdate ) { #> <# if ( data.theme.updateResponse.compatibleWP && data.theme.updateResponse.compatiblePHP ) { #> <div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}"> <p> <?php if ( is_multisite() ) { _e( 'New version available.' ); } else { printf( /* translators: %s: "Update now" button. */ __( 'New version available. %s' ), '<button class="button-link update-theme" type="button">' . __( 'Update now' ) . '</button>' ); } ?> </p> </div> <# } else { #> <div class="update-message notice inline notice-error notice-alt" data-slug="{{ data.theme.id }}"> <p> <# if ( ! data.theme.updateResponse.compatibleWP && ! data.theme.updateResponse.compatiblePHP ) { #> <?php printf( /* translators: %s: Theme name. */ __( 'There is a new version of %s available, but it does not work with your versions of WordPress and PHP.' ), '{{{ data.theme.name }}}' ); if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { printf( /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), self_admin_url( 'update-core.php' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } elseif ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } elseif ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } ?> <# } else if ( ! data.theme.updateResponse.compatibleWP ) { #> <?php printf( /* translators: %s: Theme name. */ __( 'There is a new version of %s available, but it does not work with your version of WordPress.' ), '{{{ data.theme.name }}}' ); if ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } ?> <# } else if ( ! data.theme.updateResponse.compatiblePHP ) { #> <?php printf( /* translators: %s: Theme name. */ __( 'There is a new version of %s available, but it does not work with your version of PHP.' ), '{{{ data.theme.name }}}' ); if ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } ?> <# } #> </p> </div> <# } #> <# } #> <# if ( ! data.theme.compatibleWP || ! data.theme.compatiblePHP ) { #> <div class="notice notice-error notice-alt"><p> <# if ( ! data.theme.compatibleWP && ! data.theme.compatiblePHP ) { #> <?php _e( 'This theme does not work with your versions of WordPress and PHP.' ); if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { printf( /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), self_admin_url( 'update-core.php' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } elseif ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } elseif ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } ?> <# } else if ( ! data.theme.compatibleWP ) { #> <?php _e( 'This theme does not work with your version of WordPress.' ); if ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } ?> <# } else if ( ! data.theme.compatiblePHP ) { #> <?php _e( 'This theme does not work with your version of PHP.' ); if ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } ?> <# } #> </p></div> <# } #> <# if ( data.theme.active ) { #> <div class="theme-id-container"> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name"> <span><?php _ex( 'Previewing:', 'theme' ); ?></span> {{ data.theme.name }} </h3> <div class="theme-actions"> <button type="button" class="button button-primary customize-theme" aria-label="<?php echo esc_attr( $customize_label ); ?>"><?php _e( 'Customize' ); ?></button> </div> </div> <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div> <# } else if ( 'installed' === data.theme.type ) { #> <# if ( data.theme.blockTheme ) { #> <div class="theme-id-container"> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> <div class="theme-actions"> <# if ( data.theme.actions.activate ) { #> <?php /* translators: %s: Theme name. */ $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' ); ?> <a href="{{{ data.theme.actions.activate }}}" class="button button-primary activate" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a> <# } #> </div> </div> <div class="notice notice-error notice-alt"><p> <?php _e( 'This theme doesn\'t support Customizer.' ); ?> <# if ( data.theme.actions.activate ) { #> <?php echo ' '; printf( /* translators: %s: URL to the themes page (also it activates the theme). */ __( 'However, you can still <a href="%s">activate this theme</a>, and use the Site Editor to customize it.' ), '{{{ data.theme.actions.activate }}}' ); ?> <# } #> </p></div> <# } else { #> <div class="theme-id-container"> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> <div class="theme-actions"> <# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #> <button type="button" class="button button-primary preview-theme" aria-label="<?php echo esc_attr( $preview_label ); ?>" data-slug="{{ data.theme.id }}"><?php _e( 'Live Preview' ); ?></button> <# } else { #> <button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $preview_label ); ?>"><?php _e( 'Live Preview' ); ?></button> <# } #> </div> </div> <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div> <# } #> <# } else { #> <div class="theme-id-container"> <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3> <div class="theme-actions"> <# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #> <button type="button" class="button button-primary theme-install preview" aria-label="<?php echo esc_attr( $install_label ); ?>" data-slug="{{ data.theme.id }}" data-name="{{ data.theme.name }}"><?php _e( 'Install &amp; Preview' ); ?></button> <# } else { #> <button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $install_label ); ?>" disabled><?php _e( 'Install &amp; Preview' ); ?></button> <# } #> </div> </div> <# } #> </div> <?php } ``` | Uses | Description | | --- | --- | | [wp\_get\_update\_php\_url()](../../functions/wp_get_update_php_url) wp-includes/functions.php | Gets the URL to learn more about updating the PHP version the site is running on. | | [wp\_update\_php\_annotation()](../../functions/wp_update_php_annotation) wp-includes/functions.php | Prints the default annotation for the web host altering the “Update PHP” page URL. | | [\_ex()](../../functions/_ex) wp-includes/l10n.php | Displays translated string with gettext context. | | [self\_admin\_url()](../../functions/self_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for either the current site or the network depending on context. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | Version | Description | | --- | --- | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Introduced. | wordpress WP_Customize_Theme_Control::to_json() WP\_Customize\_Theme\_Control::to\_json() ========================================= Refresh the parameters passed to the JavaScript via JSON. * [WP\_Customize\_Control::to\_json()](../wp_customize_control/to_json) File: `wp-includes/customize/class-wp-customize-theme-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-theme-control.php/) ``` public function to_json() { parent::to_json(); $this->json['theme'] = $this->theme; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Control::to\_json()](../wp_customize_control/to_json) wp-includes/class-wp-customize-control.php | Refresh the parameters passed to the JavaScript via JSON. | | Version | Description | | --- | --- | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Introduced. | wordpress WP_Customize_Theme_Control::render_content() WP\_Customize\_Theme\_Control::render\_content() ================================================ Don’t render the control content from PHP, as it’s rendered via JS on load. File: `wp-includes/customize/class-wp-customize-theme-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-theme-control.php/) ``` public function render_content() {} ``` | Version | Description | | --- | --- | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Introduced. |
programming_docs
wordpress WP_Widget_Search::form( array $instance ) WP\_Widget\_Search::form( array $instance ) =========================================== Outputs the settings form for the Search widget. `$instance` array Required Current settings. File: `wp-includes/widgets/class-wp-widget-search.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-search.php/) ``` public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); $title = $instance['title']; ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> </p> <?php } ``` | Uses | Description | | --- | --- | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Search::update( array $new_instance, array $old_instance ): array WP\_Widget\_Search::update( array $new\_instance, array $old\_instance ): array =============================================================================== Handles updating settings for the current Search widget instance. `$new_instance` array Required New settings for this instance as input by the user via [WP\_Widget::form()](../wp_widget/form). `$old_instance` array Required Old settings for this instance. array Updated settings. File: `wp-includes/widgets/class-wp-widget-search.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-search.php/) ``` public function update( $new_instance, $old_instance ) { $instance = $old_instance; $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '' ) ); $instance['title'] = sanitize_text_field( $new_instance['title'] ); return $instance; } ``` | Uses | Description | | --- | --- | | [sanitize\_text\_field()](../../functions/sanitize_text_field) wp-includes/formatting.php | Sanitizes a string from user input or from the database. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Search::__construct() WP\_Widget\_Search::\_\_construct() =================================== Sets up a new Search widget instance. File: `wp-includes/widgets/class-wp-widget-search.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-search.php/) ``` public function __construct() { $widget_ops = array( 'classname' => 'widget_search', 'description' => __( 'A search form for your site.' ), 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, ); parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget::\_\_construct()](../wp_widget/__construct) wp-includes/class-wp-widget.php | PHP5 constructor. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Search::widget( array $args, array $instance ) WP\_Widget\_Search::widget( array $args, array $instance ) ========================================================== Outputs the content for the current Search widget instance. `$args` array Required Display arguments including `'before_title'`, `'after_title'`, `'before_widget'`, and `'after_widget'`. `$instance` array Required Settings for the current Search widget instance. File: `wp-includes/widgets/class-wp-widget-search.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-search.php/) ``` public function widget( $args, $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } // Use active theme search form if it exists. get_search_form(); echo $args['after_widget']; } ``` [apply\_filters( 'widget\_title', string $title, array $instance, mixed $id\_base )](../../hooks/widget_title) Filters the widget title. | Uses | Description | | --- | --- | | [get\_search\_form()](../../functions/get_search_form) wp-includes/general-template.php | Displays search form. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::extra_tablenav( string $which ) WP\_MS\_Sites\_List\_Table::extra\_tablenav( string $which ) ============================================================ Extra controls to be displayed between bulk actions and pagination. `$which` string Required The location of the extra table nav markup: `'top'` or `'bottom'`. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` protected function extra_tablenav( $which ) { ?> <div class="alignleft actions"> <?php if ( 'top' === $which ) { ob_start(); /** * Fires before the Filter button on the MS sites list table. * * @since 5.3.0 * * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. */ do_action( 'restrict_manage_sites', $which ); $output = ob_get_clean(); if ( ! empty( $output ) ) { echo $output; submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'site-query-submit' ) ); } } ?> </div> <?php /** * Fires immediately following the closing "actions" div in the tablenav for the * MS sites list table. * * @since 5.3.0 * * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. */ do_action( 'manage_sites_extra_tablenav', $which ); } ``` [do\_action( 'manage\_sites\_extra\_tablenav', string $which )](../../hooks/manage_sites_extra_tablenav) Fires immediately following the closing “actions” div in the tablenav for the MS sites list table. [do\_action( 'restrict\_manage\_sites', string $which )](../../hooks/restrict_manage_sites) Fires before the Filter button on the MS sites list table. | Uses | Description | | --- | --- | | [submit\_button()](../../functions/submit_button) wp-admin/includes/template.php | Echoes a submit button, with provided text and appropriate class(es). | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Version | Description | | --- | --- | | [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::prepare_items() WP\_MS\_Sites\_List\_Table::prepare\_items() ============================================ Prepares the list of sites for display. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function prepare_items() { global $mode, $s, $wpdb; if ( ! empty( $_REQUEST['mode'] ) ) { $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list'; set_user_setting( 'sites_list_mode', $mode ); } else { $mode = get_user_setting( 'sites_list_mode', 'list' ); } $per_page = $this->get_items_per_page( 'sites_network_per_page' ); $pagenum = $this->get_pagenum(); $s = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; $wild = ''; if ( false !== strpos( $s, '*' ) ) { $wild = '*'; $s = trim( $s, '*' ); } /* * If the network is large and a search is not being performed, show only * the latest sites with no paging in order to avoid expensive count queries. */ if ( ! $s && wp_is_large_network() ) { if ( ! isset( $_REQUEST['orderby'] ) ) { $_GET['orderby'] = ''; $_REQUEST['orderby'] = ''; } if ( ! isset( $_REQUEST['order'] ) ) { $_GET['order'] = 'DESC'; $_REQUEST['order'] = 'DESC'; } } $args = array( 'number' => (int) $per_page, 'offset' => (int) ( ( $pagenum - 1 ) * $per_page ), 'network_id' => get_current_network_id(), ); if ( empty( $s ) ) { // Nothing to do. } elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { // IPv4 address. $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . ( ! empty( $wild ) ? '%' : '' ) ); $reg_blog_ids = $wpdb->get_col( $sql ); if ( $reg_blog_ids ) { $args['site__in'] = $reg_blog_ids; } } elseif ( is_numeric( $s ) && empty( $wild ) ) { $args['ID'] = $s; } else { $args['search'] = $s; if ( ! is_subdomain_install() ) { $args['search_columns'] = array( 'path' ); } } $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : ''; if ( 'registered' === $order_by ) { // 'registered' is a valid field name. } elseif ( 'lastupdated' === $order_by ) { $order_by = 'last_updated'; } elseif ( 'blogname' === $order_by ) { if ( is_subdomain_install() ) { $order_by = 'domain'; } else { $order_by = 'path'; } } elseif ( 'blog_id' === $order_by ) { $order_by = 'id'; } elseif ( ! $order_by ) { $order_by = false; } $args['orderby'] = $order_by; if ( $order_by ) { $args['order'] = ( isset( $_REQUEST['order'] ) && 'DESC' === strtoupper( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC'; } if ( wp_is_large_network() ) { $args['no_found_rows'] = true; } else { $args['no_found_rows'] = false; } // Take into account the role the user has selected. $status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : ''; if ( in_array( $status, array( 'public', 'archived', 'mature', 'spam', 'deleted' ), true ) ) { $args[ $status ] = 1; } /** * Filters the arguments for the site query in the sites list table. * * @since 4.6.0 * * @param array $args An array of get_sites() arguments. */ $args = apply_filters( 'ms_sites_list_table_query_args', $args ); $_sites = get_sites( $args ); if ( is_array( $_sites ) ) { update_site_cache( $_sites ); $this->items = array_slice( $_sites, 0, $per_page ); } $total_sites = get_sites( array_merge( $args, array( 'count' => true, 'offset' => 0, 'number' => 0, ) ) ); $this->set_pagination_args( array( 'total_items' => $total_sites, 'per_page' => $per_page, ) ); } ``` [apply\_filters( 'ms\_sites\_list\_table\_query\_args', array $args )](../../hooks/ms_sites_list_table_query_args) Filters the arguments for the site query in the sites list table. | Uses | Description | | --- | --- | | [get\_current\_network\_id()](../../functions/get_current_network_id) wp-includes/load.php | Retrieves the current network ID. | | [get\_sites()](../../functions/get_sites) wp-includes/ms-site.php | Retrieves a list of sites matching requested arguments. | | [update\_site\_cache()](../../functions/update_site_cache) wp-includes/ms-site.php | Updates sites in cache. | | [wpdb::esc\_like()](../wpdb/esc_like) wp-includes/class-wpdb.php | First half of escaping for `LIKE` special characters `%` and `_` before preparing for SQL. | | [set\_user\_setting()](../../functions/set_user_setting) wp-includes/option.php | Adds or updates user interface setting. | | [get\_user\_setting()](../../functions/get_user_setting) wp-includes/option.php | Retrieves user interface setting value based on setting name. | | [wp\_is\_large\_network()](../../functions/wp_is_large_network) wp-includes/ms-functions.php | Determines whether or not we have a large network. | | [is\_subdomain\_install()](../../functions/is_subdomain_install) wp-includes/ms-load.php | Whether a subdomain configuration is enabled. | | [wpdb::get\_col()](../wpdb/get_col) wp-includes/class-wpdb.php | Retrieves one column from the database. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [wpdb::prepare()](../wpdb/prepare) wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::ajax_user_can(): bool WP\_MS\_Sites\_List\_Table::ajax\_user\_can(): bool =================================================== bool File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function ajax_user_can() { return current_user_can( 'manage_sites' ); } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | wordpress WP_MS_Sites_List_Table::column_blogname( array $blog ) WP\_MS\_Sites\_List\_Table::column\_blogname( array $blog ) =========================================================== Handles the site name column output. `$blog` array Required Current site. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function column_blogname( $blog ) { global $mode; $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); ?> <strong> <a href="<?php echo esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ); ?>" class="edit"><?php echo $blogname; ?></a> <?php $this->site_states( $blog ); ?> </strong> <?php if ( 'list' !== $mode ) { switch_to_blog( $blog['blog_id'] ); echo '<p>'; printf( /* translators: 1: Site title, 2: Site tagline. */ __( '%1$s &#8211; %2$s' ), get_option( 'blogname' ), '<em>' . get_option( 'blogdescription' ) . '</em>' ); echo '</p>'; restore_current_blog(); } } ``` | Uses | Description | | --- | --- | | [WP\_MS\_Sites\_List\_Table::site\_states()](site_states) wp-admin/includes/class-wp-ms-sites-list-table.php | Maybe output comma-separated site states. | | [untrailingslashit()](../../functions/untrailingslashit) wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. | | [network\_admin\_url()](../../functions/network_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the network. | | [switch\_to\_blog()](../../functions/switch_to_blog) wp-includes/ms-blogs.php | Switch the current blog. | | [restore\_current\_blog()](../../functions/restore_current_blog) wp-includes/ms-blogs.php | Restore the current blog, after calling [switch\_to\_blog()](../../functions/switch_to_blog) . | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::display_rows() WP\_MS\_Sites\_List\_Table::display\_rows() =========================================== File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function display_rows() { foreach ( $this->items as $blog ) { $blog = $blog->to_array(); $class = ''; reset( $this->status_list ); foreach ( $this->status_list as $status => $col ) { if ( 1 == $blog[ $status ] ) { $class = " class='{$col[0]}'"; } } echo "<tr{$class}>"; $this->single_row_columns( $blog ); echo '</tr>'; } } ``` wordpress WP_MS_Sites_List_Table::column_id( array $blog ) WP\_MS\_Sites\_List\_Table::column\_id( array $blog ) ===================================================== Handles the ID column output. `$blog` array Required Current site. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function column_id( $blog ) { echo $blog['blog_id']; } ``` | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::no_items() WP\_MS\_Sites\_List\_Table::no\_items() ======================================= File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function no_items() { _e( 'No sites found.' ); } ``` | Uses | Description | | --- | --- | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | wordpress WP_MS_Sites_List_Table::pagination( string $which ) WP\_MS\_Sites\_List\_Table::pagination( string $which ) ======================================================= `$which` string Required The location of the pagination nav markup: `'top'` or `'bottom'`. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` protected function pagination( $which ) { global $mode; parent::pagination( $which ); if ( 'top' === $which ) { $this->view_switcher( $mode ); } } ``` | Uses | Description | | --- | --- | | [WP\_List\_Table::pagination()](../wp_list_table/pagination) wp-admin/includes/class-wp-list-table.php | Displays the pagination. | wordpress WP_MS_Sites_List_Table::get_default_primary_column_name(): string WP\_MS\_Sites\_List\_Table::get\_default\_primary\_column\_name(): string ========================================================================= Gets the name of the default primary column. string Name of the default primary column, in this case, `'blogname'`. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` protected function get_default_primary_column_name() { return 'blogname'; } ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |
programming_docs
wordpress WP_MS_Sites_List_Table::handle_row_actions( array $item, string $column_name, string $primary ): string WP\_MS\_Sites\_List\_Table::handle\_row\_actions( array $item, string $column\_name, string $primary ): string ============================================================================================================== Generates and displays row action links. `$item` array Required Site being acted upon. `$column_name` string Required Current column name. `$primary` string Required Primary column name. string Row actions output for sites in Multisite, or an empty string if the current column is not the primary column. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` protected function handle_row_actions( $item, $column_name, $primary ) { if ( $primary !== $column_name ) { return ''; } // Restores the more descriptive, specific name for use within this method. $blog = $item; $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); // Preordered. $actions = array( 'edit' => '', 'backend' => '', 'activate' => '', 'deactivate' => '', 'archive' => '', 'unarchive' => '', 'spam' => '', 'unspam' => '', 'delete' => '', 'visit' => '', ); $actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $blog['blog_id'] ) ) . '">' . __( 'Edit' ) . '</a>'; $actions['backend'] = "<a href='" . esc_url( get_admin_url( $blog['blog_id'] ) ) . "' class='edit'>" . __( 'Dashboard' ) . '</a>'; if ( get_network()->site_id != $blog['blog_id'] ) { if ( '1' == $blog['deleted'] ) { $actions['activate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=activateblog&amp;id=' . $blog['blog_id'] ), 'activateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Activate' ) . '</a>'; } else { $actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deactivateblog&amp;id=' . $blog['blog_id'] ), 'deactivateblog_' . $blog['blog_id'] ) ) . '">' . __( 'Deactivate' ) . '</a>'; } if ( '1' == $blog['archived'] ) { $actions['unarchive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unarchiveblog&amp;id=' . $blog['blog_id'] ), 'unarchiveblog_' . $blog['blog_id'] ) ) . '">' . __( 'Unarchive' ) . '</a>'; } else { $actions['archive'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=archiveblog&amp;id=' . $blog['blog_id'] ), 'archiveblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Archive', 'verb; site' ) . '</a>'; } if ( '1' == $blog['spam'] ) { $actions['unspam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=unspamblog&amp;id=' . $blog['blog_id'] ), 'unspamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Not Spam', 'site' ) . '</a>'; } else { $actions['spam'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=spamblog&amp;id=' . $blog['blog_id'] ), 'spamblog_' . $blog['blog_id'] ) ) . '">' . _x( 'Spam', 'site' ) . '</a>'; } if ( current_user_can( 'delete_site', $blog['blog_id'] ) ) { $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( network_admin_url( 'sites.php?action=confirm&amp;action2=deleteblog&amp;id=' . $blog['blog_id'] ), 'deleteblog_' . $blog['blog_id'] ) ) . '">' . __( 'Delete' ) . '</a>'; } } $actions['visit'] = "<a href='" . esc_url( get_home_url( $blog['blog_id'], '/' ) ) . "' rel='bookmark'>" . __( 'Visit' ) . '</a>'; /** * Filters the action links displayed for each site in the Sites list table. * * The 'Edit', 'Dashboard', 'Delete', and 'Visit' links are displayed by * default for each site. The site's status determines whether to show the * 'Activate' or 'Deactivate' link, 'Unarchive' or 'Archive' links, and * 'Not Spam' or 'Spam' link for each site. * * @since 3.1.0 * * @param string[] $actions An array of action links to be displayed. * @param int $blog_id The site ID. * @param string $blogname Site path, formatted depending on whether it is a sub-domain * or subdirectory multisite installation. */ $actions = apply_filters( 'manage_sites_action_links', array_filter( $actions ), $blog['blog_id'], $blogname ); return $this->row_actions( $actions ); } ``` [apply\_filters( 'manage\_sites\_action\_links', string[] $actions, int $blog\_id, string $blogname )](../../hooks/manage_sites_action_links) Filters the action links displayed for each site in the Sites list table. | Uses | Description | | --- | --- | | [get\_network()](../../functions/get_network) wp-includes/ms-network.php | Retrieves network data given a network ID or network object. | | [untrailingslashit()](../../functions/untrailingslashit) wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. | | [network\_admin\_url()](../../functions/network_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the network. | | [get\_admin\_url()](../../functions/get_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for a given site. | | [get\_home\_url()](../../functions/get_home_url) wp-includes/link-template.php | Retrieves the URL for a given site where the front end is accessible. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support. | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::get_views(): array WP\_MS\_Sites\_List\_Table::get\_views(): array =============================================== Gets links to filter sites by status. array File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` protected function get_views() { $counts = wp_count_sites(); $statuses = array( /* translators: %s: Number of sites. */ 'all' => _nx_noop( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', 'sites' ), /* translators: %s: Number of sites. */ 'public' => _n_noop( 'Public <span class="count">(%s)</span>', 'Public <span class="count">(%s)</span>' ), /* translators: %s: Number of sites. */ 'archived' => _n_noop( 'Archived <span class="count">(%s)</span>', 'Archived <span class="count">(%s)</span>' ), /* translators: %s: Number of sites. */ 'mature' => _n_noop( 'Mature <span class="count">(%s)</span>', 'Mature <span class="count">(%s)</span>' ), /* translators: %s: Number of sites. */ 'spam' => _nx_noop( 'Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'sites' ), /* translators: %s: Number of sites. */ 'deleted' => _n_noop( 'Deleted <span class="count">(%s)</span>', 'Deleted <span class="count">(%s)</span>' ), ); $view_links = array(); $requested_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : ''; $url = 'sites.php'; foreach ( $statuses as $status => $label_count ) { if ( (int) $counts[ $status ] > 0 ) { $label = sprintf( translate_nooped_plural( $label_count, $counts[ $status ] ), number_format_i18n( $counts[ $status ] ) ); $full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url ); $view_links[ $status ] = array( 'url' => esc_url( $full_url ), 'label' => $label, 'current' => $requested_status === $status || ( '' === $requested_status && 'all' === $status ), ); } } return $this->get_views_links( $view_links ); } ``` | Uses | Description | | --- | --- | | [wp\_count\_sites()](../../functions/wp_count_sites) wp-includes/ms-blogs.php | Count number of sites grouped by site status. | | [\_nx\_noop()](../../functions/_nx_noop) wp-includes/l10n.php | Registers plural strings with gettext context in POT file, but does not translate them. | | [\_n\_noop()](../../functions/_n_noop) wp-includes/l10n.php | Registers plural strings in POT file, but does not translate them. | | [translate\_nooped\_plural()](../../functions/translate_nooped_plural) wp-includes/l10n.php | Translates and returns the singular or plural form of a string that’s been registered with [\_n\_noop()](../../functions/_n_noop) or [\_nx\_noop()](../../functions/_nx_noop) . | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [number\_format\_i18n()](../../functions/number_format_i18n) wp-includes/functions.php | Converts float number to format based on the locale. | | Version | Description | | --- | --- | | [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::get_sortable_columns(): array WP\_MS\_Sites\_List\_Table::get\_sortable\_columns(): array =========================================================== array File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` protected function get_sortable_columns() { return array( 'blogname' => 'blogname', 'lastupdated' => 'lastupdated', 'registered' => 'blog_id', ); } ``` wordpress WP_MS_Sites_List_Table::site_states( array $site ) WP\_MS\_Sites\_List\_Table::site\_states( array $site ) ======================================================= Maybe output comma-separated site states. `$site` array Required File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` protected function site_states( $site ) { $site_states = array(); // $site is still an array, so get the object. $_site = WP_Site::get_instance( $site['blog_id'] ); if ( is_main_site( $_site->id ) ) { $site_states['main'] = __( 'Main' ); } reset( $this->status_list ); $site_status = isset( $_REQUEST['status'] ) ? wp_unslash( trim( $_REQUEST['status'] ) ) : ''; foreach ( $this->status_list as $status => $col ) { if ( ( 1 === (int) $_site->{$status} ) && ( $site_status !== $status ) ) { $site_states[ $col[0] ] = $col[1]; } } /** * Filters the default site display states for items in the Sites list table. * * @since 5.3.0 * * @param string[] $site_states An array of site states. Default 'Main', * 'Archived', 'Mature', 'Spam', 'Deleted'. * @param WP_Site $site The current site object. */ $site_states = apply_filters( 'display_site_states', $site_states, $_site ); if ( ! empty( $site_states ) ) { $state_count = count( $site_states ); $i = 0; echo ' &mdash; '; foreach ( $site_states as $state ) { ++$i; $separator = ( $i < $state_count ) ? ', ' : ''; echo "<span class='post-state'>{$state}{$separator}</span>"; } } } ``` [apply\_filters( 'display\_site\_states', string[] $site\_states, WP\_Site $site )](../../hooks/display_site_states) Filters the default site display states for items in the Sites list table. | Uses | Description | | --- | --- | | [WP\_Site::get\_instance()](../wp_site/get_instance) wp-includes/class-wp-site.php | Retrieves a site from the database by its ID. | | [is\_main\_site()](../../functions/is_main_site) wp-includes/functions.php | Determines whether a site is the main site of the current network. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_MS\_Sites\_List\_Table::column\_blogname()](column_blogname) wp-admin/includes/class-wp-ms-sites-list-table.php | Handles the site name column output. | | Version | Description | | --- | --- | | [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::column_cb( array $item ) WP\_MS\_Sites\_List\_Table::column\_cb( array $item ) ===================================================== Handles the checkbox column output. `$item` array Required Current site. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function column_cb( $item ) { // Restores the more descriptive, specific name for use within this method. $blog = $item; if ( ! is_main_site( $blog['blog_id'] ) ) : $blogname = untrailingslashit( $blog['domain'] . $blog['path'] ); ?> <label class="screen-reader-text" for="blog_<?php echo $blog['blog_id']; ?>"> <?php /* translators: %s: Site URL. */ printf( __( 'Select %s' ), $blogname ); ?> </label> <input type="checkbox" id="blog_<?php echo $blog['blog_id']; ?>" name="allblogs[]" value="<?php echo esc_attr( $blog['blog_id'] ); ?>" /> <?php endif; } ``` | Uses | Description | | --- | --- | | [untrailingslashit()](../../functions/untrailingslashit) wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. | | [is\_main\_site()](../../functions/is_main_site) wp-includes/functions.php | Determines whether a site is the main site of the current network. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support. | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::get_columns(): array WP\_MS\_Sites\_List\_Table::get\_columns(): array ================================================= array File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function get_columns() { $sites_columns = array( 'cb' => '<input type="checkbox" />', 'blogname' => __( 'URL' ), 'lastupdated' => __( 'Last Updated' ), 'registered' => _x( 'Registered', 'site' ), 'users' => __( 'Users' ), ); if ( has_filter( 'wpmublogsaction' ) ) { $sites_columns['plugins'] = __( 'Actions' ); } /** * Filters the displayed site columns in Sites list table. * * @since MU (3.0.0) * * @param string[] $sites_columns An array of displayed site columns. Default 'cb', * 'blogname', 'lastupdated', 'registered', 'users'. */ return apply_filters( 'wpmu_blogs_columns', $sites_columns ); } ``` [apply\_filters( 'wpmu\_blogs\_columns', string[] $sites\_columns )](../../hooks/wpmu_blogs_columns) Filters the displayed site columns in Sites list table. | Uses | Description | | --- | --- | | [has\_filter()](../../functions/has_filter) wp-includes/plugin.php | Checks if any filter has been registered for a hook. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | wordpress WP_MS_Sites_List_Table::get_bulk_actions(): array WP\_MS\_Sites\_List\_Table::get\_bulk\_actions(): array ======================================================= array File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` protected function get_bulk_actions() { $actions = array(); if ( current_user_can( 'delete_sites' ) ) { $actions['delete'] = __( 'Delete' ); } $actions['spam'] = _x( 'Mark as spam', 'site' ); $actions['notspam'] = _x( 'Not spam', 'site' ); return $actions; } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | wordpress WP_MS_Sites_List_Table::column_lastupdated( array $blog ) WP\_MS\_Sites\_List\_Table::column\_lastupdated( array $blog ) ============================================================== Handles the lastupdated column output. `$blog` array Required Current site. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function column_lastupdated( $blog ) { global $mode; if ( 'list' === $mode ) { $date = __( 'Y/m/d' ); } else { $date = __( 'Y/m/d g:i:s a' ); } echo ( '0000-00-00 00:00:00' === $blog['last_updated'] ) ? __( 'Never' ) : mysql2date( $date, $blog['last_updated'] ); } ``` | Uses | Description | | --- | --- | | [mysql2date()](../../functions/mysql2date) wp-includes/functions.php | Converts given MySQL date string into a different format. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::column_users( array $blog ) WP\_MS\_Sites\_List\_Table::column\_users( array $blog ) ======================================================== Handles the users column output. `$blog` array Required Current site. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function column_users( $blog ) { $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' ); if ( ! $user_count ) { $blog_users = new WP_User_Query( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID', 'number' => 1, 'count_total' => true, ) ); $user_count = $blog_users->get_total(); wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS ); } printf( '<a href="%s">%s</a>', esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ), number_format_i18n( $user_count ) ); } ``` | Uses | Description | | --- | --- | | [wp\_cache\_set()](../../functions/wp_cache_set) wp-includes/cache.php | Saves the data to the cache. | | [network\_admin\_url()](../../functions/network_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the network. | | [WP\_User\_Query::\_\_construct()](../wp_user_query/__construct) wp-includes/class-wp-user-query.php | PHP5 constructor. | | [wp\_cache\_get()](../../functions/wp_cache_get) wp-includes/cache.php | Retrieves the cache contents from the cache by key and group. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [number\_format\_i18n()](../../functions/number_format_i18n) wp-includes/functions.php | Converts float number to format based on the locale. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |
programming_docs
wordpress WP_MS_Sites_List_Table::__construct( array $args = array() ) WP\_MS\_Sites\_List\_Table::\_\_construct( array $args = array() ) ================================================================== Constructor. * [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct): for more information on default arguments. `$args` array Optional An associative array of arguments. Default: `array()` File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function __construct( $args = array() ) { $this->status_list = array( 'archived' => array( 'site-archived', __( 'Archived' ) ), 'spam' => array( 'site-spammed', _x( 'Spam', 'site' ) ), 'deleted' => array( 'site-deleted', __( 'Deleted' ) ), 'mature' => array( 'site-mature', __( 'Mature' ) ), ); parent::__construct( array( 'plural' => 'sites', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } ``` | Uses | Description | | --- | --- | | [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct) wp-admin/includes/class-wp-list-table.php | Constructor. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::column_plugins( array $blog ) WP\_MS\_Sites\_List\_Table::column\_plugins( array $blog ) ========================================================== Handles the plugins column output. `$blog` array Required Current site. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function column_plugins( $blog ) { if ( has_filter( 'wpmublogsaction' ) ) { /** * Fires inside the auxiliary 'Actions' column of the Sites list table. * * By default this column is hidden unless something is hooked to the action. * * @since MU (3.0.0) * * @param int $blog_id The site ID. */ do_action( 'wpmublogsaction', $blog['blog_id'] ); } } ``` [do\_action( 'wpmublogsaction', int $blog\_id )](../../hooks/wpmublogsaction) Fires inside the auxiliary ‘Actions’ column of the Sites list table. | Uses | Description | | --- | --- | | [has\_filter()](../../functions/has_filter) wp-includes/plugin.php | Checks if any filter has been registered for a hook. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::column_default( array $item, string $column_name ) WP\_MS\_Sites\_List\_Table::column\_default( array $item, string $column\_name ) ================================================================================ Handles output for the default column. `$item` array Required Current site. `$column_name` string Required Current column name. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function column_default( $item, $column_name ) { /** * Fires for each registered custom column in the Sites list table. * * @since 3.1.0 * * @param string $column_name The name of the column to display. * @param int $blog_id The site ID. */ do_action( 'manage_sites_custom_column', $column_name, $item['blog_id'] ); } ``` [do\_action( 'manage\_sites\_custom\_column', string $column\_name, int $blog\_id )](../../hooks/manage_sites_custom_column) Fires for each registered custom column in the Sites list table. | Uses | Description | | --- | --- | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$blog` to `$item` to match parent class for PHP 8 named parameter support. | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Sites_List_Table::column_registered( array $blog ) WP\_MS\_Sites\_List\_Table::column\_registered( array $blog ) ============================================================= Handles the registered column output. `$blog` array Required Current site. File: `wp-admin/includes/class-wp-ms-sites-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-sites-list-table.php/) ``` public function column_registered( $blog ) { global $mode; if ( 'list' === $mode ) { $date = __( 'Y/m/d' ); } else { $date = __( 'Y/m/d g:i:s a' ); } if ( '0000-00-00 00:00:00' === $blog['registered'] ) { echo '&#x2014;'; } else { echo mysql2date( $date, $blog['registered'] ); } } ``` | Uses | Description | | --- | --- | | [mysql2date()](../../functions/mysql2date) wp-includes/functions.php | Converts given MySQL date string into a different format. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress Plugin_Installer_Skin::after() Plugin\_Installer\_Skin::after() ================================ Action to perform following a plugin install. File: `wp-admin/includes/class-plugin-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-installer-skin.php/) ``` public function after() { // Check if the plugin can be overwritten and output the HTML. if ( $this->do_overwrite() ) { return; } $plugin_file = $this->upgrader->plugin_info(); $install_actions = array(); $from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'plugins'; if ( 'import' === $from ) { $install_actions['activate_plugin'] = sprintf( '<a class="button button-primary" href="%s" target="_parent">%s</a>', wp_nonce_url( 'plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ), __( 'Activate Plugin &amp; Run Importer' ) ); } elseif ( 'press-this' === $from ) { $install_actions['activate_plugin'] = sprintf( '<a class="button button-primary" href="%s" target="_parent">%s</a>', wp_nonce_url( 'plugins.php?action=activate&amp;from=press-this&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ), __( 'Activate Plugin &amp; Go to Press This' ) ); } else { $install_actions['activate_plugin'] = sprintf( '<a class="button button-primary" href="%s" target="_parent">%s</a>', wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ), __( 'Activate Plugin' ) ); } if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { $install_actions['network_activate'] = sprintf( '<a class="button button-primary" href="%s" target="_parent">%s</a>', wp_nonce_url( 'plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ), __( 'Network Activate' ) ); unset( $install_actions['activate_plugin'] ); } if ( 'import' === $from ) { $install_actions['importers_page'] = sprintf( '<a href="%s" target="_parent">%s</a>', admin_url( 'import.php' ), __( 'Go to Importers' ) ); } elseif ( 'web' === $this->type ) { $install_actions['plugins_page'] = sprintf( '<a href="%s" target="_parent">%s</a>', self_admin_url( 'plugin-install.php' ), __( 'Go to Plugin Installer' ) ); } elseif ( 'upload' === $this->type && 'plugins' === $from ) { $install_actions['plugins_page'] = sprintf( '<a href="%s">%s</a>', self_admin_url( 'plugin-install.php' ), __( 'Go to Plugin Installer' ) ); } else { $install_actions['plugins_page'] = sprintf( '<a href="%s" target="_parent">%s</a>', self_admin_url( 'plugins.php' ), __( 'Go to Plugins page' ) ); } if ( ! $this->result || is_wp_error( $this->result ) ) { unset( $install_actions['activate_plugin'], $install_actions['network_activate'] ); } elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) || is_plugin_active( $plugin_file ) ) { unset( $install_actions['activate_plugin'] ); } /** * Filters the list of action links available following a single plugin installation. * * @since 2.7.0 * * @param string[] $install_actions Array of plugin action links. * @param object $api Object containing WordPress.org API plugin data. Empty * for non-API installs, such as when a plugin is installed * via upload. * @param string $plugin_file Path to the plugin file relative to the plugins directory. */ $install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file ); if ( ! empty( $install_actions ) ) { $this->feedback( implode( ' ', (array) $install_actions ) ); } } ``` [apply\_filters( 'install\_plugin\_complete\_actions', string[] $install\_actions, object $api, string $plugin\_file )](../../hooks/install_plugin_complete_actions) Filters the list of action links available following a single plugin installation. | Uses | Description | | --- | --- | | [Plugin\_Installer\_Skin::do\_overwrite()](do_overwrite) wp-admin/includes/class-plugin-installer-skin.php | Check if the plugin can be overwritten and output the HTML for overwriting a plugin on upload. | | [is\_plugin\_active()](../../functions/is_plugin_active) wp-admin/includes/plugin.php | Determines whether a plugin is active. | | [self\_admin\_url()](../../functions/self_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for either the current site or the network depending on context. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress Plugin_Installer_Skin::hide_process_failed( WP_Error $wp_error ): bool Plugin\_Installer\_Skin::hide\_process\_failed( WP\_Error $wp\_error ): bool ============================================================================ Hides the `process_failed` error when updating a plugin by uploading a zip file. `$wp_error` [WP\_Error](../wp_error) Required [WP\_Error](../wp_error) object. bool File: `wp-admin/includes/class-plugin-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-installer-skin.php/) ``` public function hide_process_failed( $wp_error ) { if ( 'upload' === $this->type && '' === $this->overwrite && $wp_error->get_error_code() === 'folder_exists' ) { return true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Error::get\_error\_code()](../wp_error/get_error_code) wp-includes/class-wp-error.php | Retrieves the first error code available. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress Plugin_Installer_Skin::__construct( array $args = array() ) Plugin\_Installer\_Skin::\_\_construct( array $args = array() ) =============================================================== `$args` array Optional Default: `array()` File: `wp-admin/includes/class-plugin-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-installer-skin.php/) ``` public function __construct( $args = array() ) { $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '', 'overwrite' => '', ); $args = wp_parse_args( $args, $defaults ); $this->type = $args['type']; $this->url = $args['url']; $this->api = isset( $args['api'] ) ? $args['api'] : array(); $this->overwrite = $args['overwrite']; parent::__construct( $args ); } ``` | Uses | Description | | --- | --- | | [WP\_Upgrader\_Skin::\_\_construct()](../wp_upgrader_skin/__construct) wp-admin/includes/class-wp-upgrader-skin.php | Constructor. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | wordpress Plugin_Installer_Skin::do_overwrite(): bool Plugin\_Installer\_Skin::do\_overwrite(): bool ============================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Check if the plugin can be overwritten and output the HTML for overwriting a plugin on upload. bool Whether the plugin can be overwritten and HTML was outputted. File: `wp-admin/includes/class-plugin-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-installer-skin.php/) ``` private function do_overwrite() { if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) { return false; } $folder = $this->result->get_error_data( 'folder_exists' ); $folder = ltrim( substr( $folder, strlen( WP_PLUGIN_DIR ) ), '/' ); $current_plugin_data = false; $all_plugins = get_plugins(); foreach ( $all_plugins as $plugin => $plugin_data ) { if ( strrpos( $plugin, $folder ) !== 0 ) { continue; } $current_plugin_data = $plugin_data; } $new_plugin_data = $this->upgrader->new_plugin_data; if ( ! $current_plugin_data || ! $new_plugin_data ) { return false; } echo '<h2 class="update-from-upload-heading">' . esc_html__( 'This plugin is already installed.' ) . '</h2>'; $this->is_downgrading = version_compare( $current_plugin_data['Version'], $new_plugin_data['Version'], '>' ); $rows = array( 'Name' => __( 'Plugin name' ), 'Version' => __( 'Version' ), 'Author' => __( 'Author' ), 'RequiresWP' => __( 'Required WordPress version' ), 'RequiresPHP' => __( 'Required PHP version' ), ); $table = '<table class="update-from-upload-comparison"><tbody>'; $table .= '<tr><th></th><th>' . esc_html_x( 'Current', 'plugin' ) . '</th>'; $table .= '<th>' . esc_html_x( 'Uploaded', 'plugin' ) . '</th></tr>'; $is_same_plugin = true; // Let's consider only these rows. foreach ( $rows as $field => $label ) { $old_value = ! empty( $current_plugin_data[ $field ] ) ? (string) $current_plugin_data[ $field ] : '-'; $new_value = ! empty( $new_plugin_data[ $field ] ) ? (string) $new_plugin_data[ $field ] : '-'; $is_same_plugin = $is_same_plugin && ( $old_value === $new_value ); $diff_field = ( 'Version' !== $field && $new_value !== $old_value ); $diff_version = ( 'Version' === $field && $this->is_downgrading ); $table .= '<tr><td class="name-label">' . $label . '</td><td>' . wp_strip_all_tags( $old_value ) . '</td>'; $table .= ( $diff_field || $diff_version ) ? '<td class="warning">' : '<td>'; $table .= wp_strip_all_tags( $new_value ) . '</td></tr>'; } $table .= '</tbody></table>'; /** * Filters the compare table output for overwriting a plugin package on upload. * * @since 5.5.0 * * @param string $table The output table with Name, Version, Author, RequiresWP, and RequiresPHP info. * @param array $current_plugin_data Array with current plugin data. * @param array $new_plugin_data Array with uploaded plugin data. */ echo apply_filters( 'install_plugin_overwrite_comparison', $table, $current_plugin_data, $new_plugin_data ); $install_actions = array(); $can_update = true; $blocked_message = '<p>' . esc_html__( 'The plugin cannot be updated due to the following:' ) . '</p>'; $blocked_message .= '<ul class="ul-disc">'; $requires_php = isset( $new_plugin_data['RequiresPHP'] ) ? $new_plugin_data['RequiresPHP'] : null; $requires_wp = isset( $new_plugin_data['RequiresWP'] ) ? $new_plugin_data['RequiresWP'] : null; if ( ! is_php_version_compatible( $requires_php ) ) { $error = sprintf( /* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */ __( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ), PHP_VERSION, $requires_php ); $blocked_message .= '<li>' . esc_html( $error ) . '</li>'; $can_update = false; } if ( ! is_wp_version_compatible( $requires_wp ) ) { $error = sprintf( /* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */ __( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ), get_bloginfo( 'version' ), $requires_wp ); $blocked_message .= '<li>' . esc_html( $error ) . '</li>'; $can_update = false; } $blocked_message .= '</ul>'; if ( $can_update ) { if ( $this->is_downgrading ) { $warning = sprintf( /* translators: %s: Documentation URL. */ __( 'You are uploading an older version of a current plugin. You can continue to install the older version, but be sure to <a href="%s">back up your database and files</a> first.' ), __( 'https://wordpress.org/support/article/wordpress-backups/' ) ); } else { $warning = sprintf( /* translators: %s: Documentation URL. */ __( 'You are updating a plugin. Be sure to <a href="%s">back up your database and files</a> first.' ), __( 'https://wordpress.org/support/article/wordpress-backups/' ) ); } echo '<p class="update-from-upload-notice">' . $warning . '</p>'; $overwrite = $this->is_downgrading ? 'downgrade-plugin' : 'update-plugin'; $install_actions['overwrite_plugin'] = sprintf( '<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>', wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'plugin-upload' ), _x( 'Replace current with uploaded', 'plugin' ) ); } else { echo $blocked_message; } $cancel_url = add_query_arg( 'action', 'upload-plugin-cancel-overwrite', $this->url ); $install_actions['plugins_page'] = sprintf( '<a class="button" href="%s">%s</a>', wp_nonce_url( $cancel_url, 'plugin-upload-cancel-overwrite' ), __( 'Cancel and go back' ) ); /** * Filters the list of action links available following a single plugin installation failure * when overwriting is allowed. * * @since 5.5.0 * * @param string[] $install_actions Array of plugin action links. * @param object $api Object containing WordPress.org API plugin data. * @param array $new_plugin_data Array with uploaded plugin data. */ $install_actions = apply_filters( 'install_plugin_overwrite_actions', $install_actions, $this->api, $new_plugin_data ); if ( ! empty( $install_actions ) ) { printf( '<p class="update-from-upload-expired hidden">%s</p>', __( 'The uploaded file has expired. Please go back and upload it again.' ) ); echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>'; } return true; } ``` [apply\_filters( 'install\_plugin\_overwrite\_actions', string[] $install\_actions, object $api, array $new\_plugin\_data )](../../hooks/install_plugin_overwrite_actions) Filters the list of action links available following a single plugin installation failure when overwriting is allowed. [apply\_filters( 'install\_plugin\_overwrite\_comparison', string $table, array $current\_plugin\_data, array $new\_plugin\_data )](../../hooks/install_plugin_overwrite_comparison) Filters the compare table output for overwriting a plugin package on upload. | Uses | Description | | --- | --- | | [is\_php\_version\_compatible()](../../functions/is_php_version_compatible) wp-includes/functions.php | Checks compatibility with the current PHP version. | | [is\_wp\_version\_compatible()](../../functions/is_wp_version_compatible) wp-includes/functions.php | Checks compatibility with the current WordPress version. | | [get\_plugins()](../../functions/get_plugins) wp-admin/includes/plugin.php | Checks the plugins directory and retrieve all plugin files with plugin data. | | [esc\_html\_\_()](../../functions/esc_html__) wp-includes/l10n.php | Retrieves the translation of $text and escapes it for safe use in HTML output. | | [esc\_html\_x()](../../functions/esc_html_x) wp-includes/l10n.php | Translates string with gettext context, and escapes it for safe use in HTML output. | | [wp\_strip\_all\_tags()](../../functions/wp_strip_all_tags) wp-includes/formatting.php | Properly strips all HTML tags including script and style | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [Plugin\_Installer\_Skin::after()](after) wp-admin/includes/class-plugin-installer-skin.php | Action to perform following a plugin install. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |
programming_docs
wordpress Plugin_Installer_Skin::before() Plugin\_Installer\_Skin::before() ================================= Action to perform before installing a plugin. File: `wp-admin/includes/class-plugin-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-installer-skin.php/) ``` public function before() { if ( ! empty( $this->api ) ) { $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version ); } } ``` | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Customize_Background_Image_Setting::update( mixed $value ) WP\_Customize\_Background\_Image\_Setting::update( mixed $value ) ================================================================= `$value` mixed Required The value to update. Not used. File: `wp-includes/customize/class-wp-customize-background-image-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-background-image-setting.php/) ``` public function update( $value ) { remove_theme_mod( 'background_image_thumb' ); } ``` | Uses | Description | | --- | --- | | [remove\_theme\_mod()](../../functions/remove_theme_mod) wp-includes/theme.php | Removes theme modification name from active theme list. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Upload_Control::to_json() WP\_Customize\_Upload\_Control::to\_json() ========================================== Refresh the parameters passed to the JavaScript via JSON. File: `wp-includes/customize/class-wp-customize-upload-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-upload-control.php/) ``` public function to_json() { parent::to_json(); $value = $this->value(); if ( $value ) { // Get the attachment model for the existing file. $attachment_id = attachment_url_to_postid( $value ); if ( $attachment_id ) { $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id ); } } } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Media\_Control::to\_json()](../wp_customize_media_control/to_json) wp-includes/customize/class-wp-customize-media-control.php | Refresh the parameters passed to the JavaScript via JSON. | | [attachment\_url\_to\_postid()](../../functions/attachment_url_to_postid) wp-includes/media.php | Tries to convert an attachment URL into a post ID. | | [wp\_prepare\_attachment\_for\_js()](../../functions/wp_prepare_attachment_for_js) wp-includes/media.php | Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_MS_Themes_List_Table::single_row( WP_Theme $theme ) WP\_MS\_Themes\_List\_Table::single\_row( WP\_Theme $theme ) ============================================================ `$theme` [WP\_Theme](../wp_theme) Required File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function single_row( $theme ) { global $status, $totals; if ( $this->is_site_themes ) { $allowed = $theme->is_allowed( 'site', $this->site_id ); } else { $allowed = $theme->is_allowed( 'network' ); } $stylesheet = $theme->get_stylesheet(); $class = ! $allowed ? 'inactive' : 'active'; if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) { $class .= ' update'; } printf( '<tr class="%s" data-slug="%s">', esc_attr( $class ), esc_attr( $stylesheet ) ); $this->single_row_columns( $theme ); echo '</tr>'; if ( $this->is_site_themes ) { remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' ); } /** * Fires after each row in the Multisite themes list table. * * @since 3.1.0 * * @param string $stylesheet Directory name of the theme. * @param WP_Theme $theme Current WP_Theme object. * @param string $status Status of the theme. */ do_action( 'after_theme_row', $stylesheet, $theme, $status ); /** * Fires after each specific row in the Multisite themes list table. * * The dynamic portion of the hook name, `$stylesheet`, refers to the * directory name of the theme, most often synonymous with the template * name of the theme. * * @since 3.5.0 * * @param string $stylesheet Directory name of the theme. * @param WP_Theme $theme Current WP_Theme object. * @param string $status Status of the theme. */ do_action( "after_theme_row_{$stylesheet}", $stylesheet, $theme, $status ); } ``` [do\_action( 'after\_theme\_row', string $stylesheet, WP\_Theme $theme, string $status )](../../hooks/after_theme_row) Fires after each row in the Multisite themes list table. [do\_action( "after\_theme\_row\_{$stylesheet}", string $stylesheet, WP\_Theme $theme, string $status )](../../hooks/after_theme_row_stylesheet) Fires after each specific row in the Multisite themes list table. | Uses | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::single\_row\_columns()](single_row_columns) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the output for a single table row. | | [remove\_action()](../../functions/remove_action) wp-includes/plugin.php | Removes a callback function from an action hook. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Used By | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::display\_rows()](display_rows) wp-admin/includes/class-wp-ms-themes-list-table.php | | wordpress WP_MS_Themes_List_Table::prepare_items() WP\_MS\_Themes\_List\_Table::prepare\_items() ============================================= File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function prepare_items() { global $status, $totals, $page, $orderby, $order, $s; wp_reset_vars( array( 'orderby', 'order', 's' ) ); $themes = array( /** * Filters the full array of WP_Theme objects to list in the Multisite * themes list table. * * @since 3.1.0 * * @param WP_Theme[] $all Array of WP_Theme objects to display in the list table. */ 'all' => apply_filters( 'all_themes', wp_get_themes() ), 'search' => array(), 'enabled' => array(), 'disabled' => array(), 'upgrade' => array(), 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ), ); if ( $this->show_autoupdates ) { $auto_updates = (array) get_site_option( 'auto_update_themes', array() ); $themes['auto-update-enabled'] = array(); $themes['auto-update-disabled'] = array(); } if ( $this->is_site_themes ) { $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' ); $allowed_where = 'site'; } else { $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' ); $allowed_where = 'network'; } $current = get_site_transient( 'update_themes' ); $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current; foreach ( (array) $themes['all'] as $key => $theme ) { if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) { unset( $themes['all'][ $key ] ); continue; } if ( $maybe_update && isset( $current->response[ $key ] ) ) { $themes['all'][ $key ]->update = true; $themes['upgrade'][ $key ] = $themes['all'][ $key ]; } $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled'; $themes[ $filter ][ $key ] = $themes['all'][ $key ]; $theme_data = array( 'update_supported' => isset( $theme->update_supported ) ? $theme->update_supported : true, ); // Extra info if known. array_merge() ensures $theme_data has precedence if keys collide. if ( isset( $current->response[ $key ] ) ) { $theme_data = array_merge( (array) $current->response[ $key ], $theme_data ); } elseif ( isset( $current->no_update[ $key ] ) ) { $theme_data = array_merge( (array) $current->no_update[ $key ], $theme_data ); } else { $theme_data['update_supported'] = false; } $theme->update_supported = $theme_data['update_supported']; /* * Create the expected payload for the auto_update_theme filter, this is the same data * as contained within $updates or $no_updates but used when the Theme is not known. */ $filter_payload = array( 'theme' => $key, 'new_version' => '', 'url' => '', 'package' => '', 'requires' => '', 'requires_php' => '', ); $filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) ); $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $filter_payload ); if ( ! is_null( $auto_update_forced ) ) { $theme->auto_update_forced = $auto_update_forced; } if ( $this->show_autoupdates ) { $enabled = in_array( $key, $auto_updates, true ) && $theme->update_supported; if ( isset( $theme->auto_update_forced ) ) { $enabled = (bool) $theme->auto_update_forced; } if ( $enabled ) { $themes['auto-update-enabled'][ $key ] = $theme; } else { $themes['auto-update-disabled'][ $key ] = $theme; } } } if ( $s ) { $status = 'search'; $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) ); } $totals = array(); $js_themes = array(); foreach ( $themes as $type => $list ) { $totals[ $type ] = count( $list ); $js_themes[ $type ] = array_keys( $list ); } if ( empty( $themes[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) { $status = 'all'; } $this->items = $themes[ $status ]; WP_Theme::sort_by_name( $this->items ); $this->has_items = ! empty( $themes['all'] ); $total_this_page = $totals[ $status ]; wp_localize_script( 'updates', '_wpUpdatesItemCounts', array( 'themes' => $js_themes, 'totals' => wp_get_update_data(), ) ); if ( $orderby ) { $orderby = ucfirst( $orderby ); $order = strtoupper( $order ); if ( 'Name' === $orderby ) { if ( 'ASC' === $order ) { $this->items = array_reverse( $this->items ); } } else { uasort( $this->items, array( $this, '_order_callback' ) ); } } $start = ( $page - 1 ) * $themes_per_page; if ( $total_this_page > $themes_per_page ) { $this->items = array_slice( $this->items, $start, $themes_per_page, true ); } $this->set_pagination_args( array( 'total_items' => $total_this_page, 'per_page' => $themes_per_page, ) ); } ``` [apply\_filters( 'all\_themes', WP\_Theme[] $all )](../../hooks/all_themes) Filters the full array of [WP\_Theme](../wp_theme) objects to list in the Multisite themes list table. | Uses | Description | | --- | --- | | [wp\_is\_auto\_update\_forced\_for\_item()](../../functions/wp_is_auto_update_forced_for_item) wp-admin/includes/update.php | Checks whether auto-updates are forced for an item. | | [wp\_reset\_vars()](../../functions/wp_reset_vars) wp-admin/includes/misc.php | Resets global variables based on $\_GET and $\_POST. | | [wp\_get\_themes()](../../functions/wp_get_themes) wp-includes/theme.php | Returns an array of [WP\_Theme](../wp_theme) objects based on the arguments. | | [WP\_Theme::sort\_by\_name()](../wp_theme/sort_by_name) wp-includes/class-wp-theme.php | Sorts themes by name. | | [wp\_localize\_script()](../../functions/wp_localize_script) wp-includes/functions.wp-scripts.php | Localize a script. | | [wp\_get\_update\_data()](../../functions/wp_get_update_data) wp-includes/update.php | Collects counts and UI strings for available updates. | | [get\_site\_transient()](../../functions/get_site_transient) wp-includes/option.php | Retrieves the value of a site transient. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_site\_option()](../../functions/get_site_option) wp-includes/option.php | Retrieve an option value for the current network based on name of option. | wordpress WP_MS_Themes_List_Table::ajax_user_can(): bool WP\_MS\_Themes\_List\_Table::ajax\_user\_can(): bool ==================================================== bool File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function ajax_user_can() { if ( $this->is_site_themes ) { return current_user_can( 'manage_sites' ); } else { return current_user_can( 'manage_network_themes' ); } } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | wordpress WP_MS_Themes_List_Table::display_rows() WP\_MS\_Themes\_List\_Table::display\_rows() ============================================ File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function display_rows() { foreach ( $this->items as $theme ) { $this->single_row( $theme ); } } ``` | Uses | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::single\_row()](single_row) wp-admin/includes/class-wp-ms-themes-list-table.php | | wordpress WP_MS_Themes_List_Table::no_items() WP\_MS\_Themes\_List\_Table::no\_items() ======================================== File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function no_items() { if ( $this->has_items ) { _e( 'No themes found.' ); } else { _e( 'No themes are currently available.' ); } } ``` | Uses | Description | | --- | --- | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | wordpress WP_MS_Themes_List_Table::get_views(): array WP\_MS\_Themes\_List\_Table::get\_views(): array ================================================ array File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` protected function get_views() { global $totals, $status; $status_links = array(); foreach ( $totals as $type => $count ) { if ( ! $count ) { continue; } switch ( $type ) { case 'all': /* translators: %s: Number of themes. */ $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' ); break; case 'enabled': /* translators: %s: Number of themes. */ $text = _nx( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count, 'themes' ); break; case 'disabled': /* translators: %s: Number of themes. */ $text = _nx( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count, 'themes' ); break; case 'upgrade': /* translators: %s: Number of themes. */ $text = _nx( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count, 'themes' ); break; case 'broken': /* translators: %s: Number of themes. */ $text = _nx( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count, 'themes' ); break; case 'auto-update-enabled': /* translators: %s: Number of themes. */ $text = _n( 'Auto-updates Enabled <span class="count">(%s)</span>', 'Auto-updates Enabled <span class="count">(%s)</span>', $count ); break; case 'auto-update-disabled': /* translators: %s: Number of themes. */ $text = _n( 'Auto-updates Disabled <span class="count">(%s)</span>', 'Auto-updates Disabled <span class="count">(%s)</span>', $count ); break; } if ( $this->is_site_themes ) { $url = 'site-themes.php?id=' . $this->site_id; } else { $url = 'themes.php'; } if ( 'search' !== $type ) { $status_links[ $type ] = array( 'url' => esc_url( add_query_arg( 'theme_status', $type, $url ) ), 'label' => sprintf( $text, number_format_i18n( $count ) ), 'current' => $type === $status, ); } } return $this->get_views_links( $status_links ); } ``` | Uses | Description | | --- | --- | | [\_nx()](../../functions/_nx) wp-includes/l10n.php | Translates and retrieves the singular or plural form based on the supplied number, with gettext context. | | [\_n()](../../functions/_n) wp-includes/l10n.php | Translates and retrieves the singular or plural form based on the supplied number. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [number\_format\_i18n()](../../functions/number_format_i18n) wp-includes/functions.php | Converts float number to format based on the locale. | wordpress WP_MS_Themes_List_Table::get_sortable_columns(): array WP\_MS\_Themes\_List\_Table::get\_sortable\_columns(): array ============================================================ array File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` protected function get_sortable_columns() { return array( 'name' => 'name', ); } ``` wordpress WP_MS_Themes_List_Table::column_autoupdates( WP_Theme $theme ) WP\_MS\_Themes\_List\_Table::column\_autoupdates( WP\_Theme $theme ) ==================================================================== Handles the auto-updates column output. `$theme` [WP\_Theme](../wp_theme) Required The current [WP\_Theme](../wp_theme) object. File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function column_autoupdates( $theme ) { global $status, $page; static $auto_updates, $available_updates; if ( ! $auto_updates ) { $auto_updates = (array) get_site_option( 'auto_update_themes', array() ); } if ( ! $available_updates ) { $available_updates = get_site_transient( 'update_themes' ); } $stylesheet = $theme->get_stylesheet(); if ( isset( $theme->auto_update_forced ) ) { if ( $theme->auto_update_forced ) { // Forced on. $text = __( 'Auto-updates enabled' ); } else { $text = __( 'Auto-updates disabled' ); } $action = 'unavailable'; $time_class = ' hidden'; } elseif ( empty( $theme->update_supported ) ) { $text = ''; $action = 'unavailable'; $time_class = ' hidden'; } elseif ( in_array( $stylesheet, $auto_updates, true ) ) { $text = __( 'Disable auto-updates' ); $action = 'disable'; $time_class = ''; } else { $text = __( 'Enable auto-updates' ); $action = 'enable'; $time_class = ' hidden'; } $query_args = array( 'action' => "{$action}-auto-update", 'theme' => $stylesheet, 'paged' => $page, 'theme_status' => $status, ); $url = add_query_arg( $query_args, 'themes.php' ); if ( 'unavailable' === $action ) { $html[] = '<span class="label">' . $text . '</span>'; } else { $html[] = sprintf( '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">', wp_nonce_url( $url, 'updates' ), $action ); $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>'; $html[] = '<span class="label">' . $text . '</span>'; $html[] = '</a>'; } if ( isset( $available_updates->response[ $stylesheet ] ) ) { $html[] = sprintf( '<div class="auto-update-time%s">%s</div>', $time_class, wp_get_auto_update_message() ); } $html = implode( '', $html ); /** * Filters the HTML of the auto-updates setting for each theme in the Themes list table. * * @since 5.5.0 * * @param string $html The HTML for theme's auto-update setting, including * toggle auto-update action link and time to next update. * @param string $stylesheet Directory name of the theme. * @param WP_Theme $theme WP_Theme object. */ echo apply_filters( 'theme_auto_update_setting_html', $html, $stylesheet, $theme ); echo '<div class="notice notice-error notice-alt inline hidden"><p></p></div>'; } ``` [apply\_filters( 'theme\_auto\_update\_setting\_html', string $html, string $stylesheet, WP\_Theme $theme )](../../hooks/theme_auto_update_setting_html) Filters the HTML of the auto-updates setting for each theme in the Themes list table. | Uses | Description | | --- | --- | | [wp\_get\_auto\_update\_message()](../../functions/wp_get_auto_update_message) wp-admin/includes/update.php | Determines the appropriate auto-update message to be displayed. | | [get\_site\_transient()](../../functions/get_site_transient) wp-includes/option.php | Retrieves the value of a site transient. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_site\_option()](../../functions/get_site_option) wp-includes/option.php | Retrieve an option value for the current network based on name of option. | | Used By | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::single\_row\_columns()](single_row_columns) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the output for a single table row. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |
programming_docs
wordpress WP_MS_Themes_List_Table::column_description( WP_Theme $theme ) WP\_MS\_Themes\_List\_Table::column\_description( WP\_Theme $theme ) ==================================================================== Handles the description column output. `$theme` [WP\_Theme](../wp_theme) Required The current [WP\_Theme](../wp_theme) object. File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function column_description( $theme ) { global $status, $totals; if ( $theme->errors() ) { $pre = 'broken' === $status ? __( 'Broken Theme:' ) . ' ' : ''; echo '<p><strong class="error-message">' . $pre . $theme->errors()->get_error_message() . '</strong></p>'; } if ( $this->is_site_themes ) { $allowed = $theme->is_allowed( 'site', $this->site_id ); } else { $allowed = $theme->is_allowed( 'network' ); } $class = ! $allowed ? 'inactive' : 'active'; if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) { $class .= ' update'; } echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div> <div class='$class second theme-version-author-uri'>"; $stylesheet = $theme->get_stylesheet(); $theme_meta = array(); if ( $theme->get( 'Version' ) ) { /* translators: %s: Theme version. */ $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display( 'Version' ) ); } /* translators: %s: Theme author. */ $theme_meta[] = sprintf( __( 'By %s' ), $theme->display( 'Author' ) ); if ( $theme->get( 'ThemeURI' ) ) { /* translators: %s: Theme name. */ $aria_label = sprintf( __( 'Visit theme site for %s' ), $theme->display( 'Name' ) ); $theme_meta[] = sprintf( '<a href="%s" aria-label="%s">%s</a>', $theme->display( 'ThemeURI' ), esc_attr( $aria_label ), __( 'Visit Theme Site' ) ); } if ( $theme->parent() ) { $theme_meta[] = sprintf( /* translators: %s: Theme name. */ __( 'Child theme of %s' ), '<strong>' . $theme->parent()->display( 'Name' ) . '</strong>' ); } /** * Filters the array of row meta for each theme in the Multisite themes * list table. * * @since 3.1.0 * * @param string[] $theme_meta An array of the theme's metadata, including * the version, author, and theme URI. * @param string $stylesheet Directory name of the theme. * @param WP_Theme $theme WP_Theme object. * @param string $status Status of the theme. */ $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status ); echo implode( ' | ', $theme_meta ); echo '</div>'; } ``` [apply\_filters( 'theme\_row\_meta', string[] $theme\_meta, string $stylesheet, WP\_Theme $theme, string $status )](../../hooks/theme_row_meta) Filters the array of row meta for each theme in the Multisite themes list table. | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::single\_row\_columns()](single_row_columns) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the output for a single table row. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Themes_List_Table::get_table_classes(): array WP\_MS\_Themes\_List\_Table::get\_table\_classes(): array ========================================================= array File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` protected function get_table_classes() { // @todo Remove and add CSS for .themes. return array( 'widefat', 'plugins' ); } ``` wordpress WP_MS_Themes_List_Table::column_cb( WP_Theme $item ) WP\_MS\_Themes\_List\_Table::column\_cb( WP\_Theme $item ) ========================================================== Handles the checkbox column output. `$item` [WP\_Theme](../wp_theme) Required The current [WP\_Theme](../wp_theme) object. File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function column_cb( $item ) { // Restores the more descriptive, specific name for use within this method. $theme = $item; $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) ); ?> <input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ); ?>" id="<?php echo $checkbox_id; ?>" /> <label class="screen-reader-text" for="<?php echo $checkbox_id; ?>" ><?php _e( 'Select' ); ?> <?php echo $theme->display( 'Name' ); ?></label> <?php } ``` | Uses | Description | | --- | --- | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Used By | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::single\_row\_columns()](single_row_columns) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the output for a single table row. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support. | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Themes_List_Table::get_columns(): array WP\_MS\_Themes\_List\_Table::get\_columns(): array ================================================== array File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function get_columns() { $columns = array( 'cb' => '<input type="checkbox" />', 'name' => __( 'Theme' ), 'description' => __( 'Description' ), ); if ( $this->show_autoupdates ) { $columns['auto-updates'] = __( 'Automatic Updates' ); } return $columns; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | wordpress WP_MS_Themes_List_Table::get_bulk_actions(): array WP\_MS\_Themes\_List\_Table::get\_bulk\_actions(): array ======================================================== array File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` protected function get_bulk_actions() { global $status; $actions = array(); if ( 'enabled' !== $status ) { $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ); } if ( 'disabled' !== $status ) { $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ); } if ( ! $this->is_site_themes ) { if ( current_user_can( 'update_themes' ) ) { $actions['update-selected'] = __( 'Update' ); } if ( current_user_can( 'delete_themes' ) ) { $actions['delete-selected'] = __( 'Delete' ); } } if ( $this->show_autoupdates ) { if ( 'auto-update-enabled' !== $status ) { $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' ); } if ( 'auto-update-disabled' !== $status ) { $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' ); } } return $actions; } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | wordpress WP_MS_Themes_List_Table::__construct( array $args = array() ) WP\_MS\_Themes\_List\_Table::\_\_construct( array $args = array() ) =================================================================== Constructor. * [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct): for more information on default arguments. `$args` array Optional An associative array of arguments. Default: `array()` File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function __construct( $args = array() ) { global $status, $page; parent::__construct( array( 'plural' => 'themes', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all'; if ( ! in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken', 'auto-update-enabled', 'auto-update-disabled' ), true ) ) { $status = 'all'; } $page = $this->get_pagenum(); $this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false; if ( $this->is_site_themes ) { $this->site_id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0; } $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'theme' ) && ! $this->is_site_themes && current_user_can( 'update_themes' ); } ``` | Uses | Description | | --- | --- | | [wp\_is\_auto\_update\_enabled\_for\_type()](../../functions/wp_is_auto_update_enabled_for_type) wp-admin/includes/update.php | Checks whether auto-updates are enabled. | | [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct) wp-admin/includes/class-wp-list-table.php | Constructor. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_MS_Themes_List_Table::_order_callback( array $theme_a, array $theme_b ): int WP\_MS\_Themes\_List\_Table::\_order\_callback( array $theme\_a, array $theme\_b ): int ======================================================================================= `$theme_a` array Required `$theme_b` array Required int File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function _order_callback( $theme_a, $theme_b ) { global $orderby, $order; $a = $theme_a[ $orderby ]; $b = $theme_b[ $orderby ]; if ( $a === $b ) { return 0; } if ( 'DESC' === $order ) { return ( $a < $b ) ? 1 : -1; } else { return ( $a < $b ) ? -1 : 1; } } ``` wordpress WP_MS_Themes_List_Table::get_primary_column_name(): string WP\_MS\_Themes\_List\_Table::get\_primary\_column\_name(): string ================================================================= Gets the name of the primary column. string Unalterable name of the primary column name, in this case, `'name'`. File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` protected function get_primary_column_name() { return 'name'; } ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Themes_List_Table::single_row_columns( WP_Theme $item ) WP\_MS\_Themes\_List\_Table::single\_row\_columns( WP\_Theme $item ) ==================================================================== Handles the output for a single table row. `$item` [WP\_Theme](../wp_theme) Required The current [WP\_Theme](../wp_theme) object. File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function single_row_columns( $item ) { list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); foreach ( $columns as $column_name => $column_display_name ) { $extra_classes = ''; if ( in_array( $column_name, $hidden, true ) ) { $extra_classes .= ' hidden'; } switch ( $column_name ) { case 'cb': echo '<th scope="row" class="check-column">'; $this->column_cb( $item ); echo '</th>'; break; case 'name': $active_theme_label = ''; /* The presence of the site_id property means that this is a subsite view and a label for the active theme needs to be added */ if ( ! empty( $this->site_id ) ) { $stylesheet = get_blog_option( $this->site_id, 'stylesheet' ); $template = get_blog_option( $this->site_id, 'template' ); /* Add a label for the active template */ if ( $item->get_template() === $template ) { $active_theme_label = ' &mdash; ' . __( 'Active Theme' ); } /* In case this is a child theme, label it properly */ if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) { $active_theme_label = ' &mdash; ' . __( 'Active Child Theme' ); } } echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display( 'Name' ) . $active_theme_label . '</strong>'; $this->column_name( $item ); echo '</td>'; break; case 'description': echo "<td class='column-description desc{$extra_classes}'>"; $this->column_description( $item ); echo '</td>'; break; case 'auto-updates': echo "<td class='column-auto-updates{$extra_classes}'>"; $this->column_autoupdates( $item ); echo '</td>'; break; default: echo "<td class='$column_name column-$column_name{$extra_classes}'>"; $this->column_default( $item, $column_name ); echo '</td>'; break; } } } ``` | Uses | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::column\_autoupdates()](column_autoupdates) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the auto-updates column output. | | [WP\_MS\_Themes\_List\_Table::column\_name()](column_name) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the name column output. | | [WP\_MS\_Themes\_List\_Table::column\_description()](column_description) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the description column output. | | [WP\_MS\_Themes\_List\_Table::column\_default()](column_default) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles default column output. | | [WP\_MS\_Themes\_List\_Table::column\_cb()](column_cb) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the checkbox column output. | | [get\_blog\_option()](../../functions/get_blog_option) wp-includes/ms-blogs.php | Retrieve option value for a given blog id based on name of option. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::single\_row()](single_row) wp-admin/includes/class-wp-ms-themes-list-table.php | | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_MS_Themes_List_Table::column_name( WP_Theme $theme ) WP\_MS\_Themes\_List\_Table::column\_name( WP\_Theme $theme ) ============================================================= Handles the name column output. `$theme` [WP\_Theme](../wp_theme) Required The current [WP\_Theme](../wp_theme) object. File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function column_name( $theme ) { global $status, $page, $s; $context = $status; if ( $this->is_site_themes ) { $url = "site-themes.php?id={$this->site_id}&amp;"; $allowed = $theme->is_allowed( 'site', $this->site_id ); } else { $url = 'themes.php?'; $allowed = $theme->is_allowed( 'network' ); } // Pre-order. $actions = array( 'enable' => '', 'disable' => '', 'delete' => '', ); $stylesheet = $theme->get_stylesheet(); $theme_key = urlencode( $stylesheet ); if ( ! $allowed ) { if ( ! $theme->errors() ) { $url = add_query_arg( array( 'action' => 'enable', 'theme' => $theme_key, 'paged' => $page, 's' => $s, ), $url ); if ( $this->is_site_themes ) { /* translators: %s: Theme name. */ $aria_label = sprintf( __( 'Enable %s' ), $theme->display( 'Name' ) ); } else { /* translators: %s: Theme name. */ $aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) ); } $actions['enable'] = sprintf( '<a href="%s" class="edit" aria-label="%s">%s</a>', esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ), esc_attr( $aria_label ), ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) ); } } else { $url = add_query_arg( array( 'action' => 'disable', 'theme' => $theme_key, 'paged' => $page, 's' => $s, ), $url ); if ( $this->is_site_themes ) { /* translators: %s: Theme name. */ $aria_label = sprintf( __( 'Disable %s' ), $theme->display( 'Name' ) ); } else { /* translators: %s: Theme name. */ $aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) ); } $actions['disable'] = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ), esc_attr( $aria_label ), ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) ); } if ( ! $allowed && ! $this->is_site_themes && current_user_can( 'delete_themes' ) && get_option( 'stylesheet' ) !== $stylesheet && get_option( 'template' ) !== $stylesheet ) { $url = add_query_arg( array( 'action' => 'delete-selected', 'checked[]' => $theme_key, 'theme_status' => $context, 'paged' => $page, 's' => $s, ), 'themes.php' ); /* translators: %s: Theme name. */ $aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) ); $actions['delete'] = sprintf( '<a href="%s" class="delete" aria-label="%s">%s</a>', esc_url( wp_nonce_url( $url, 'bulk-themes' ) ), esc_attr( $aria_label ), __( 'Delete' ) ); } /** * Filters the action links displayed for each theme in the Multisite * themes list table. * * The action links displayed are determined by the theme's status, and * which Multisite themes list table is being displayed - the Network * themes list table (themes.php), which displays all installed themes, * or the Site themes list table (site-themes.php), which displays the * non-network enabled themes when editing a site in the Network admin. * * The default action links for the Network themes list table include * 'Network Enable', 'Network Disable', and 'Delete'. * * The default action links for the Site themes list table include * 'Enable', and 'Disable'. * * @since 2.8.0 * * @param string[] $actions An array of action links. * @param WP_Theme $theme The current WP_Theme object. * @param string $context Status of the theme, one of 'all', 'enabled', or 'disabled'. */ $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context ); /** * Filters the action links of a specific theme in the Multisite themes * list table. * * The dynamic portion of the hook name, `$stylesheet`, refers to the * directory name of the theme, which in most cases is synonymous * with the template name. * * @since 3.1.0 * * @param string[] $actions An array of action links. * @param WP_Theme $theme The current WP_Theme object. * @param string $context Status of the theme, one of 'all', 'enabled', or 'disabled'. */ $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, $context ); echo $this->row_actions( $actions, true ); } ``` [apply\_filters( 'theme\_action\_links', string[] $actions, WP\_Theme $theme, string $context )](../../hooks/theme_action_links) Filters the action links displayed for each theme in the Multisite themes list table. [apply\_filters( "theme\_action\_links\_{$stylesheet}", string[] $actions, WP\_Theme $theme, string $context )](../../hooks/theme_action_links_stylesheet) Filters the action links of a specific theme in the Multisite themes list table. | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Used By | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::single\_row\_columns()](single_row_columns) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the output for a single table row. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |
programming_docs
wordpress WP_MS_Themes_List_Table::_search_callback( WP_Theme $theme ): bool WP\_MS\_Themes\_List\_Table::\_search\_callback( WP\_Theme $theme ): bool ========================================================================= `$theme` [WP\_Theme](../wp_theme) Required bool File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function _search_callback( $theme ) { static $term = null; if ( is_null( $term ) ) { $term = wp_unslash( $_REQUEST['s'] ); } foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) { // Don't mark up; Do translate. if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) { return true; } } if ( false !== stripos( $theme->get_stylesheet(), $term ) ) { return true; } if ( false !== stripos( $theme->get_template(), $term ) ) { return true; } return false; } ``` | Uses | Description | | --- | --- | | [stripos()](../../functions/stripos) wp-includes/class-pop3.php | | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | wordpress WP_MS_Themes_List_Table::column_default( WP_Theme $item, string $column_name ) WP\_MS\_Themes\_List\_Table::column\_default( WP\_Theme $item, string $column\_name ) ===================================================================================== Handles default column output. `$item` [WP\_Theme](../wp_theme) Required The current [WP\_Theme](../wp_theme) object. `$column_name` string Required The current column name. File: `wp-admin/includes/class-wp-ms-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ms-themes-list-table.php/) ``` public function column_default( $item, $column_name ) { /** * Fires inside each custom column of the Multisite themes list table. * * @since 3.1.0 * * @param string $column_name Name of the column. * @param string $stylesheet Directory name of the theme. * @param WP_Theme $theme Current WP_Theme object. */ do_action( 'manage_themes_custom_column', $column_name, $item->get_stylesheet(), // Directory name of the theme. $item // Theme object. ); } ``` [do\_action( 'manage\_themes\_custom\_column', string $column\_name, string $stylesheet, WP\_Theme $theme )](../../hooks/manage_themes_custom_column) Fires inside each custom column of the Multisite themes list table. | Uses | Description | | --- | --- | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Used By | Description | | --- | --- | | [WP\_MS\_Themes\_List\_Table::single\_row\_columns()](single_row_columns) wp-admin/includes/class-wp-ms-themes-list-table.php | Handles the output for a single table row. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$theme` to `$item` to match parent class for PHP 8 named parameter support. | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Block_Patterns_Registry::register( string $pattern_name, array $pattern_properties ): bool WP\_Block\_Patterns\_Registry::register( string $pattern\_name, array $pattern\_properties ): bool ================================================================================================== Registers a block pattern. `$pattern_name` string Required Block pattern name including namespace. `$pattern_properties` array Required List of properties for the block pattern. * `title`stringRequired. A human-readable title for the pattern. * `content`stringRequired. Block HTML markup for the pattern. * `description`stringOptional. Visually hidden text used to describe the pattern in the inserter. A description is optional, but is strongly encouraged when the title does not fully describe what the pattern does. The description will help users discover the pattern while searching. * `viewportWidth`intOptional. The intended width of the pattern to allow for a scaled preview within the pattern inserter. * `categories`arrayOptional. A list of registered pattern categories used to group block patterns. Block patterns can be shown on multiple categories. A category must be registered separately in order to be used here. * `blockTypes`arrayOptional. A list of block names including namespace that could use the block pattern in certain contexts (placeholder, transforms). The block pattern is available in the block editor inserter regardless of this list of block names. Certain blocks support further specificity besides the block name (e.g. for `core/template-part` you can specify areas like `core/template-part/header` or `core/template-part/footer`). * `keywords`arrayOptional. A list of aliases or keywords that help users discover the pattern while searching. bool True if the pattern was registered with success and false otherwise. File: `wp-includes/class-wp-block-patterns-registry.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-patterns-registry.php/) ``` public function register( $pattern_name, $pattern_properties ) { if ( ! isset( $pattern_name ) || ! is_string( $pattern_name ) ) { _doing_it_wrong( __METHOD__, __( 'Pattern name must be a string.' ), '5.5.0' ); return false; } if ( ! isset( $pattern_properties['title'] ) || ! is_string( $pattern_properties['title'] ) ) { _doing_it_wrong( __METHOD__, __( 'Pattern title must be a string.' ), '5.5.0' ); return false; } if ( ! isset( $pattern_properties['content'] ) || ! is_string( $pattern_properties['content'] ) ) { _doing_it_wrong( __METHOD__, __( 'Pattern content must be a string.' ), '5.5.0' ); return false; } $pattern = array_merge( $pattern_properties, array( 'name' => $pattern_name ) ); $this->registered_patterns[ $pattern_name ] = $pattern; // If the pattern is registered inside an action other than `init`, store it // also to a dedicated array. Used to detect deprecated registrations inside // `admin_init` or `current_screen`. if ( current_action() && 'init' !== current_action() ) { $this->registered_patterns_outside_init[ $pattern_name ] = $pattern; } return true; } ``` | Uses | Description | | --- | --- | | [current\_action()](../../functions/current_action) wp-includes/plugin.php | Retrieves the name of the current action hook. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_doing\_it\_wrong()](../../functions/_doing_it_wrong) wp-includes/functions.php | Marks something as being incorrectly called. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Added support for the `blockTypes` property. | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Block_Patterns_Registry::unregister( string $pattern_name ): bool WP\_Block\_Patterns\_Registry::unregister( string $pattern\_name ): bool ======================================================================== Unregisters a block pattern. `$pattern_name` string Required Block pattern name including namespace. bool True if the pattern was unregistered with success and false otherwise. File: `wp-includes/class-wp-block-patterns-registry.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-patterns-registry.php/) ``` public function unregister( $pattern_name ) { if ( ! $this->is_registered( $pattern_name ) ) { _doing_it_wrong( __METHOD__, /* translators: %s: Pattern name. */ sprintf( __( 'Pattern "%s" not found.' ), $pattern_name ), '5.5.0' ); return false; } unset( $this->registered_patterns[ $pattern_name ] ); unset( $this->registered_patterns_outside_init[ $pattern_name ] ); return true; } ``` | Uses | Description | | --- | --- | | [WP\_Block\_Patterns\_Registry::is\_registered()](is_registered) wp-includes/class-wp-block-patterns-registry.php | Checks if a block pattern is registered. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_doing\_it\_wrong()](../../functions/_doing_it_wrong) wp-includes/functions.php | Marks something as being incorrectly called. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Block_Patterns_Registry::get_registered( string $pattern_name ): array WP\_Block\_Patterns\_Registry::get\_registered( string $pattern\_name ): array ============================================================================== Retrieves an array containing the properties of a registered block pattern. `$pattern_name` string Required Block pattern name including namespace. array Registered pattern properties. File: `wp-includes/class-wp-block-patterns-registry.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-patterns-registry.php/) ``` public function get_registered( $pattern_name ) { if ( ! $this->is_registered( $pattern_name ) ) { return null; } return $this->registered_patterns[ $pattern_name ]; } ``` | Uses | Description | | --- | --- | | [WP\_Block\_Patterns\_Registry::is\_registered()](is_registered) wp-includes/class-wp-block-patterns-registry.php | Checks if a block pattern is registered. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Block_Patterns_Registry::get_all_registered( bool $outside_init_only = false ): array[] WP\_Block\_Patterns\_Registry::get\_all\_registered( bool $outside\_init\_only = false ): array[] ================================================================================================= Retrieves all registered block patterns. `$outside_init_only` bool Optional Return only patterns registered outside the `init` action. Default: `false` array[] Array of arrays containing the registered block patterns properties, and per style. File: `wp-includes/class-wp-block-patterns-registry.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-patterns-registry.php/) ``` public function get_all_registered( $outside_init_only = false ) { return array_values( $outside_init_only ? $this->registered_patterns_outside_init : $this->registered_patterns ); } ``` | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Block_Patterns_Registry::get_instance(): WP_Block_Patterns_Registry WP\_Block\_Patterns\_Registry::get\_instance(): WP\_Block\_Patterns\_Registry ============================================================================= Utility method to retrieve the main instance of the class. The instance will be created if it does not exist yet. [WP\_Block\_Patterns\_Registry](../wp_block_patterns_registry) The main instance. File: `wp-includes/class-wp-block-patterns-registry.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-patterns-registry.php/) ``` public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } ``` | Used By | Description | | --- | --- | | [\_register\_remote\_theme\_patterns()](../../functions/_register_remote_theme_patterns) wp-includes/block-patterns.php | Registers patterns from Pattern Directory provided by a theme’s `theme.json` file. | | [\_register\_theme\_block\_patterns()](../../functions/_register_theme_block_patterns) wp-includes/block-patterns.php | Register any patterns that the active theme may provide under its `./patterns/` directory. Each pattern is defined as a PHP file and defines its metadata using plugin-style headers. The minimum required definition is: | | [WP\_REST\_Block\_Patterns\_Controller::get\_items()](../wp_rest_block_patterns_controller/get_items) wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php | Retrieves all block patterns. | | [\_load\_remote\_featured\_patterns()](../../functions/_load_remote_featured_patterns) wp-includes/block-patterns.php | Register `Featured` (category) patterns from wordpress.org/patterns. | | [register\_block\_pattern()](../../functions/register_block_pattern) wp-includes/class-wp-block-patterns-registry.php | Registers a new block pattern. | | [unregister\_block\_pattern()](../../functions/unregister_block_pattern) wp-includes/class-wp-block-patterns-registry.php | Unregisters a block pattern. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Block_Patterns_Registry::is_registered( string $pattern_name ): bool WP\_Block\_Patterns\_Registry::is\_registered( string $pattern\_name ): bool ============================================================================ Checks if a block pattern is registered. `$pattern_name` string Required Block pattern name including namespace. bool True if the pattern is registered, false otherwise. File: `wp-includes/class-wp-block-patterns-registry.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-patterns-registry.php/) ``` public function is_registered( $pattern_name ) { return isset( $this->registered_patterns[ $pattern_name ] ); } ``` | Used By | Description | | --- | --- | | [WP\_Block\_Patterns\_Registry::unregister()](unregister) wp-includes/class-wp-block-patterns-registry.php | Unregisters a block pattern. | | [WP\_Block\_Patterns\_Registry::get\_registered()](get_registered) wp-includes/class-wp-block-patterns-registry.php | Retrieves an array containing the properties of a registered block pattern. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Comments_Controller::get_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Comments\_Controller::get\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ===================================================================================================== Retrieves a comment. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or error object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function get_item( $request ) { $comment = $this->get_comment( $request['id'] ); if ( is_wp_error( $comment ) ) { return $comment; } $data = $this->prepare_item_for_response( $comment, $request ); $response = rest_ensure_response( $data ); return $response; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_comment()](get_comment) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Get the comment, if the ID is valid. | | [WP\_REST\_Comments\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares a single comment output for response. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::prepare_status_response( string|int $comment_approved ): string WP\_REST\_Comments\_Controller::prepare\_status\_response( string|int $comment\_approved ): string ================================================================================================== Checks comment\_approved to set comment status for single comment output. `$comment_approved` string|int Required comment status. string Comment status. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function prepare_status_response( $comment_approved ) { switch ( $comment_approved ) { case 'hold': case '0': $status = 'hold'; break; case 'approve': case '1': $status = 'approved'; break; case 'spam': case 'trash': default: $status = $comment_approved; break; } return $status; } ``` | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares a single comment output for response. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::prepare_item_for_response( WP_Comment $item, WP_REST_Request $request ): WP_REST_Response WP\_REST\_Comments\_Controller::prepare\_item\_for\_response( WP\_Comment $item, WP\_REST\_Request $request ): WP\_REST\_Response ================================================================================================================================= Prepares a single comment output for response. `$item` [WP\_Comment](../wp_comment) Required Comment object. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request object. [WP\_REST\_Response](../wp_rest_response) Response object. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function prepare_item_for_response( $item, $request ) { // Restores the more descriptive, specific name for use within this method. $comment = $item; $fields = $this->get_fields_for_response( $request ); $data = array(); if ( in_array( 'id', $fields, true ) ) { $data['id'] = (int) $comment->comment_ID; } if ( in_array( 'post', $fields, true ) ) { $data['post'] = (int) $comment->comment_post_ID; } if ( in_array( 'parent', $fields, true ) ) { $data['parent'] = (int) $comment->comment_parent; } if ( in_array( 'author', $fields, true ) ) { $data['author'] = (int) $comment->user_id; } if ( in_array( 'author_name', $fields, true ) ) { $data['author_name'] = $comment->comment_author; } if ( in_array( 'author_email', $fields, true ) ) { $data['author_email'] = $comment->comment_author_email; } if ( in_array( 'author_url', $fields, true ) ) { $data['author_url'] = $comment->comment_author_url; } if ( in_array( 'author_ip', $fields, true ) ) { $data['author_ip'] = $comment->comment_author_IP; } if ( in_array( 'author_user_agent', $fields, true ) ) { $data['author_user_agent'] = $comment->comment_agent; } if ( in_array( 'date', $fields, true ) ) { $data['date'] = mysql_to_rfc3339( $comment->comment_date ); } if ( in_array( 'date_gmt', $fields, true ) ) { $data['date_gmt'] = mysql_to_rfc3339( $comment->comment_date_gmt ); } if ( in_array( 'content', $fields, true ) ) { $data['content'] = array( /** This filter is documented in wp-includes/comment-template.php */ 'rendered' => apply_filters( 'comment_text', $comment->comment_content, $comment ), 'raw' => $comment->comment_content, ); } if ( in_array( 'link', $fields, true ) ) { $data['link'] = get_comment_link( $comment ); } if ( in_array( 'status', $fields, true ) ) { $data['status'] = $this->prepare_status_response( $comment->comment_approved ); } if ( in_array( 'type', $fields, true ) ) { $data['type'] = get_comment_type( $comment->comment_ID ); } if ( in_array( 'author_avatar_urls', $fields, true ) ) { $data['author_avatar_urls'] = rest_get_avatar_urls( $comment ); } if ( in_array( 'meta', $fields, true ) ) { $data['meta'] = $this->meta->get_value( $comment->comment_ID, $request ); } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); // Wrap the data in a response object. $response = rest_ensure_response( $data ); if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $response->add_links( $this->prepare_links( $comment ) ); } /** * Filters a comment returned from the REST API. * * Allows modification of the comment right before it is returned. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param WP_Comment $comment The original comment object. * @param WP_REST_Request $request Request used to generate the response. */ return apply_filters( 'rest_prepare_comment', $response, $comment, $request ); } ``` [apply\_filters( 'comment\_text', string $comment\_text, WP\_Comment|null $comment, array $args )](../../hooks/comment_text) Filters the text of a comment to be displayed. [apply\_filters( 'rest\_prepare\_comment', WP\_REST\_Response $response, WP\_Comment $comment, WP\_REST\_Request $request )](../../hooks/rest_prepare_comment) Filters a comment returned from the REST API. | Uses | Description | | --- | --- | | [rest\_is\_field\_included()](../../functions/rest_is_field_included) wp-includes/rest-api.php | Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body. | | [rest\_get\_avatar\_urls()](../../functions/rest_get_avatar_urls) wp-includes/rest-api.php | Retrieves the avatar urls in various sizes. | | [WP\_REST\_Comments\_Controller::prepare\_status\_response()](prepare_status_response) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks comment\_approved to set comment status for single comment output. | | [WP\_REST\_Comments\_Controller::prepare\_links()](prepare_links) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares links for the request. | | [mysql\_to\_rfc3339()](../../functions/mysql_to_rfc3339) wp-includes/functions.php | Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601 (Y-m-d\TH:i:s). | | [get\_comment\_link()](../../functions/get_comment_link) wp-includes/comment-template.php | Retrieves the link to a given comment. | | [get\_comment\_type()](../../functions/get_comment_type) wp-includes/comment-template.php | Retrieves the comment type of the current comment. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Updates a comment. | | [WP\_REST\_Comments\_Controller::delete\_item()](delete_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Deletes a comment. | | [WP\_REST\_Comments\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves a comment. | | [WP\_REST\_Comments\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Creates a comment. | | [WP\_REST\_Comments\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves a list of comment items. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$comment` to `$item` to match parent class for PHP 8 named parameter support. | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |
programming_docs
wordpress WP_REST_Comments_Controller::prepare_links( WP_Comment $comment ): array WP\_REST\_Comments\_Controller::prepare\_links( WP\_Comment $comment ): array ============================================================================= Prepares links for the request. `$comment` [WP\_Comment](../wp_comment) Required Comment object. array Links for the given comment. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function prepare_links( $comment ) { $links = array( 'self' => array( 'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID ) ), ), 'collection' => array( 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ), ); if ( 0 !== (int) $comment->user_id ) { $links['author'] = array( 'href' => rest_url( 'wp/v2/users/' . $comment->user_id ), 'embeddable' => true, ); } if ( 0 !== (int) $comment->comment_post_ID ) { $post = get_post( $comment->comment_post_ID ); $post_route = rest_get_route_for_post( $post ); if ( ! empty( $post->ID ) && $post_route ) { $links['up'] = array( 'href' => rest_url( $post_route ), 'embeddable' => true, 'post_type' => $post->post_type, ); } } if ( 0 !== (int) $comment->comment_parent ) { $links['in-reply-to'] = array( 'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_parent ) ), 'embeddable' => true, ); } // Only grab one comment to verify the comment has children. $comment_children = $comment->get_children( array( 'number' => 1, 'count' => true, ) ); if ( ! empty( $comment_children ) ) { $args = array( 'parent' => $comment->comment_ID, ); $rest_url = add_query_arg( $args, rest_url( $this->namespace . '/' . $this->rest_base ) ); $links['children'] = array( 'href' => $rest_url, 'embeddable' => true, ); } return $links; } ``` | Uses | Description | | --- | --- | | [rest\_get\_route\_for\_post()](../../functions/rest_get_route_for_post) wp-includes/rest-api.php | Gets the REST API route for a post. | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares a single comment output for response. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Comments\_Controller::get\_items( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ====================================================================================================== Retrieves a list of comment items. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or error object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function get_items( $request ) { // Retrieve the list of registered collection query parameters. $registered = $this->get_collection_params(); /* * This array defines mappings between public API query parameters whose * values are accepted as-passed, and their internal WP_Query parameter * name equivalents (some are the same). Only values which are also * present in $registered will be set. */ $parameter_mappings = array( 'author' => 'author__in', 'author_email' => 'author_email', 'author_exclude' => 'author__not_in', 'exclude' => 'comment__not_in', 'include' => 'comment__in', 'offset' => 'offset', 'order' => 'order', 'parent' => 'parent__in', 'parent_exclude' => 'parent__not_in', 'per_page' => 'number', 'post' => 'post__in', 'search' => 'search', 'status' => 'status', 'type' => 'type', ); $prepared_args = array(); /* * For each known parameter which is both registered and present in the request, * set the parameter's value on the query $prepared_args. */ foreach ( $parameter_mappings as $api_param => $wp_param ) { if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) { $prepared_args[ $wp_param ] = $request[ $api_param ]; } } // Ensure certain parameter values default to empty strings. foreach ( array( 'author_email', 'search' ) as $param ) { if ( ! isset( $prepared_args[ $param ] ) ) { $prepared_args[ $param ] = ''; } } if ( isset( $registered['orderby'] ) ) { $prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] ); } $prepared_args['no_found_rows'] = false; $prepared_args['update_comment_post_cache'] = true; $prepared_args['date_query'] = array(); // Set before into date query. Date query must be specified as an array of an array. if ( isset( $registered['before'], $request['before'] ) ) { $prepared_args['date_query'][0]['before'] = $request['before']; } // Set after into date query. Date query must be specified as an array of an array. if ( isset( $registered['after'], $request['after'] ) ) { $prepared_args['date_query'][0]['after'] = $request['after']; } if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) { $prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 ); } /** * Filters WP_Comment_Query arguments when querying comments via the REST API. * * @since 4.7.0 * * @link https://developer.wordpress.org/reference/classes/wp_comment_query/ * * @param array $prepared_args Array of arguments for WP_Comment_Query. * @param WP_REST_Request $request The REST API request. */ $prepared_args = apply_filters( 'rest_comment_query', $prepared_args, $request ); $query = new WP_Comment_Query; $query_result = $query->query( $prepared_args ); $comments = array(); foreach ( $query_result as $comment ) { if ( ! $this->check_read_permission( $comment, $request ) ) { continue; } $data = $this->prepare_item_for_response( $comment, $request ); $comments[] = $this->prepare_response_for_collection( $data ); } $total_comments = (int) $query->found_comments; $max_pages = (int) $query->max_num_pages; if ( $total_comments < 1 ) { // Out-of-bounds, run the query again without LIMIT for total count. unset( $prepared_args['number'], $prepared_args['offset'] ); $query = new WP_Comment_Query; $prepared_args['count'] = true; $total_comments = $query->query( $prepared_args ); $max_pages = ceil( $total_comments / $request['per_page'] ); } $response = rest_ensure_response( $comments ); $response->header( 'X-WP-Total', $total_comments ); $response->header( 'X-WP-TotalPages', $max_pages ); $base = add_query_arg( urlencode_deep( $request->get_query_params() ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); if ( $request['page'] > 1 ) { $prev_page = $request['page'] - 1; if ( $prev_page > $max_pages ) { $prev_page = $max_pages; } $prev_link = add_query_arg( 'page', $prev_page, $base ); $response->link_header( 'prev', $prev_link ); } if ( $max_pages > $request['page'] ) { $next_page = $request['page'] + 1; $next_link = add_query_arg( 'page', $next_page, $base ); $response->link_header( 'next', $next_link ); } return $response; } ``` [apply\_filters( 'rest\_comment\_query', array $prepared\_args, WP\_REST\_Request $request )](../../hooks/rest_comment_query) Filters [WP\_Comment\_Query](../wp_comment_query) arguments when querying comments via the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_collection\_params()](get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves the query params for collections. | | [WP\_REST\_Comments\_Controller::check\_read\_permission()](check_read_permission) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if the comment can be read. | | [WP\_REST\_Comments\_Controller::normalize\_query\_param()](normalize_query_param) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepends internal property prefix to query parameters to match our response fields. | | [WP\_REST\_Comments\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares a single comment output for response. | | [WP\_Comment\_Query::\_\_construct()](../wp_comment_query/__construct) wp-includes/class-wp-comment-query.php | Constructor. | | [urlencode\_deep()](../../functions/urlencode_deep) wp-includes/formatting.php | Navigates through an array, object, or scalar, and encodes the values to be used in a URL. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::create_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Comments\_Controller::create\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ======================================================================================================== Creates a comment. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or error object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { return new WP_Error( 'rest_comment_exists', __( 'Cannot create existing comment.' ), array( 'status' => 400 ) ); } // Do not allow comments to be created with a non-default type. if ( ! empty( $request['type'] ) && 'comment' !== $request['type'] ) { return new WP_Error( 'rest_invalid_comment_type', __( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) ); } $prepared_comment = $this->prepare_item_for_database( $request ); if ( is_wp_error( $prepared_comment ) ) { return $prepared_comment; } $prepared_comment['comment_type'] = 'comment'; if ( ! isset( $prepared_comment['comment_content'] ) ) { $prepared_comment['comment_content'] = ''; } if ( ! $this->check_is_comment_content_allowed( $prepared_comment ) ) { return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) ); } // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). if ( ! isset( $prepared_comment['comment_date_gmt'] ) ) { $prepared_comment['comment_date_gmt'] = current_time( 'mysql', true ); } // Set author data if the user's logged in. $missing_author = empty( $prepared_comment['user_id'] ) && empty( $prepared_comment['comment_author'] ) && empty( $prepared_comment['comment_author_email'] ) && empty( $prepared_comment['comment_author_url'] ); if ( is_user_logged_in() && $missing_author ) { $user = wp_get_current_user(); $prepared_comment['user_id'] = $user->ID; $prepared_comment['comment_author'] = $user->display_name; $prepared_comment['comment_author_email'] = $user->user_email; $prepared_comment['comment_author_url'] = $user->user_url; } // Honor the discussion setting that requires a name and email address of the comment author. if ( get_option( 'require_name_email' ) ) { if ( empty( $prepared_comment['comment_author'] ) || empty( $prepared_comment['comment_author_email'] ) ) { return new WP_Error( 'rest_comment_author_data_required', __( 'Creating a comment requires valid author name and email values.' ), array( 'status' => 400 ) ); } } if ( ! isset( $prepared_comment['comment_author_email'] ) ) { $prepared_comment['comment_author_email'] = ''; } if ( ! isset( $prepared_comment['comment_author_url'] ) ) { $prepared_comment['comment_author_url'] = ''; } if ( ! isset( $prepared_comment['comment_agent'] ) ) { $prepared_comment['comment_agent'] = ''; } $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_comment ); if ( is_wp_error( $check_comment_lengths ) ) { $error_code = $check_comment_lengths->get_error_code(); return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); } $prepared_comment['comment_approved'] = wp_allow_comment( $prepared_comment, true ); if ( is_wp_error( $prepared_comment['comment_approved'] ) ) { $error_code = $prepared_comment['comment_approved']->get_error_code(); $error_message = $prepared_comment['comment_approved']->get_error_message(); if ( 'comment_duplicate' === $error_code ) { return new WP_Error( $error_code, $error_message, array( 'status' => 409 ) ); } if ( 'comment_flood' === $error_code ) { return new WP_Error( $error_code, $error_message, array( 'status' => 400 ) ); } return $prepared_comment['comment_approved']; } /** * Filters a comment before it is inserted via the REST API. * * Allows modification of the comment right before it is inserted via wp_insert_comment(). * Returning a WP_Error value from the filter will short-circuit insertion and allow * skipping further processing. * * @since 4.7.0 * @since 4.8.0 `$prepared_comment` can now be a WP_Error to short-circuit insertion. * * @param array|WP_Error $prepared_comment The prepared comment data for wp_insert_comment(). * @param WP_REST_Request $request Request used to insert the comment. */ $prepared_comment = apply_filters( 'rest_pre_insert_comment', $prepared_comment, $request ); if ( is_wp_error( $prepared_comment ) ) { return $prepared_comment; } $comment_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_comment ) ) ); if ( ! $comment_id ) { return new WP_Error( 'rest_comment_failed_create', __( 'Creating comment failed.' ), array( 'status' => 500 ) ); } if ( isset( $request['status'] ) ) { $this->handle_status_param( $request['status'], $comment_id ); } $comment = get_comment( $comment_id ); /** * Fires after a comment is created or updated via the REST API. * * @since 4.7.0 * * @param WP_Comment $comment Inserted or updated comment object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a comment, false * when updating. */ do_action( 'rest_insert_comment', $comment, $request, true ); $schema = $this->get_item_schema(); if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { $meta_update = $this->meta->update_value( $request['meta'], $comment_id ); if ( is_wp_error( $meta_update ) ) { return $meta_update; } } $fields_update = $this->update_additional_fields_for_object( $comment, $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update; } $context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view'; $request->set_param( 'context', $context ); /** * Fires completely after a comment is created or updated via the REST API. * * @since 5.0.0 * * @param WP_Comment $comment Inserted or updated comment object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a comment, false * when updating. */ do_action( 'rest_after_insert_comment', $comment, $request, true ); $response = $this->prepare_item_for_response( $comment, $request ); $response = rest_ensure_response( $response ); $response->set_status( 201 ); $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment_id ) ) ); return $response; } ``` [do\_action( 'rest\_after\_insert\_comment', WP\_Comment $comment, WP\_REST\_Request $request, bool $creating )](../../hooks/rest_after_insert_comment) Fires completely after a comment is created or updated via the REST API. [do\_action( 'rest\_insert\_comment', WP\_Comment $comment, WP\_REST\_Request $request, bool $creating )](../../hooks/rest_insert_comment) Fires after a comment is created or updated via the REST API. [apply\_filters( 'rest\_pre\_insert\_comment', array|WP\_Error $prepared\_comment, WP\_REST\_Request $request )](../../hooks/rest_pre_insert_comment) Filters a comment before it is inserted via the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::check\_is\_comment\_content\_allowed()](check_is_comment_content_allowed) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | If empty comments are not allowed, checks if the provided comment content is not empty. | | [WP\_REST\_Comments\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves the comment’s schema, conforming to JSON Schema. | | [WP\_REST\_Comments\_Controller::prepare\_item\_for\_database()](prepare_item_for_database) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares a single comment to be inserted into the database. | | [WP\_REST\_Comments\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares a single comment output for response. | | [wp\_check\_comment\_data\_max\_lengths()](../../functions/wp_check_comment_data_max_lengths) wp-includes/comment.php | Compares the lengths of comment data against the maximum character limits. | | [wp\_allow\_comment()](../../functions/wp_allow_comment) wp-includes/comment.php | Validates whether this comment is allowed to be made. | | [wp\_filter\_comment()](../../functions/wp_filter_comment) wp-includes/comment.php | Filters and sanitizes comment data. | | [wp\_insert\_comment()](../../functions/wp_insert_comment) wp-includes/comment.php | Inserts a comment into the database. | | [WP\_REST\_Comments\_Controller::handle\_status\_param()](handle_status_param) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Sets the comment\_status of a given comment object when creating or updating a comment. | | [wp\_get\_current\_user()](../../functions/wp_get_current_user) wp-includes/pluggable.php | Retrieves the current user object. | | [current\_time()](../../functions/current_time) wp-includes/functions.php | Retrieves the current time based on specified type. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [get\_comment()](../../functions/get_comment) wp-includes/comment.php | Retrieves comment data given a comment ID or comment object. | | [is\_user\_logged\_in()](../../functions/is_user_logged_in) wp-includes/pluggable.php | Determines whether the current visitor is a logged in user. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [wp\_slash()](../../functions/wp_slash) wp-includes/formatting.php | Adds slashes to a string or recursively adds slashes to strings within an array. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |
programming_docs
wordpress WP_REST_Comments_Controller::get_comment( int $id ): WP_Comment|WP_Error WP\_REST\_Comments\_Controller::get\_comment( int $id ): WP\_Comment|WP\_Error ============================================================================== Get the comment, if the ID is valid. `$id` int Required Supplied ID. [WP\_Comment](../wp_comment)|[WP\_Error](../wp_error) Comment object if ID is valid, [WP\_Error](../wp_error) otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function get_comment( $id ) { $error = new WP_Error( 'rest_comment_invalid_id', __( 'Invalid comment ID.' ), array( 'status' => 404 ) ); if ( (int) $id <= 0 ) { return $error; } $id = (int) $id; $comment = get_comment( $id ); if ( empty( $comment ) ) { return $error; } if ( ! empty( $comment->comment_post_ID ) ) { $post = get_post( (int) $comment->comment_post_ID ); if ( empty( $post ) ) { return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); } } return $comment; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [get\_comment()](../../functions/get_comment) wp-includes/comment.php | Retrieves comment data given a comment ID or comment object. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::update\_item\_permissions\_check()](update_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a given REST request has access to update a comment. | | [WP\_REST\_Comments\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Updates a comment. | | [WP\_REST\_Comments\_Controller::delete\_item\_permissions\_check()](delete_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a given request has access to delete a comment. | | [WP\_REST\_Comments\_Controller::delete\_item()](delete_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Deletes a comment. | | [WP\_REST\_Comments\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a given request has access to read the comment. | | [WP\_REST\_Comments\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves a comment. | | Version | Description | | --- | --- | | [4.7.2](https://developer.wordpress.org/reference/since/4.7.2/) | Introduced. | wordpress WP_REST_Comments_Controller::update_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Comments\_Controller::update\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ======================================================================================================== Updates a comment. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or error object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function update_item( $request ) { $comment = $this->get_comment( $request['id'] ); if ( is_wp_error( $comment ) ) { return $comment; } $id = $comment->comment_ID; if ( isset( $request['type'] ) && get_comment_type( $id ) !== $request['type'] ) { return new WP_Error( 'rest_comment_invalid_type', __( 'Sorry, you are not allowed to change the comment type.' ), array( 'status' => 404 ) ); } $prepared_args = $this->prepare_item_for_database( $request ); if ( is_wp_error( $prepared_args ) ) { return $prepared_args; } if ( ! empty( $prepared_args['comment_post_ID'] ) ) { $post = get_post( $prepared_args['comment_post_ID'] ); if ( empty( $post ) ) { return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid post ID.' ), array( 'status' => 403 ) ); } } if ( empty( $prepared_args ) && isset( $request['status'] ) ) { // Only the comment status is being changed. $change = $this->handle_status_param( $request['status'], $id ); if ( ! $change ) { return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment status failed.' ), array( 'status' => 500 ) ); } } elseif ( ! empty( $prepared_args ) ) { if ( is_wp_error( $prepared_args ) ) { return $prepared_args; } if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), array( 'status' => 400 ) ); } $prepared_args['comment_ID'] = $id; $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); if ( is_wp_error( $check_comment_lengths ) ) { $error_code = $check_comment_lengths->get_error_code(); return new WP_Error( $error_code, __( 'Comment field exceeds maximum length allowed.' ), array( 'status' => 400 ) ); } $updated = wp_update_comment( wp_slash( (array) $prepared_args ), true ); if ( is_wp_error( $updated ) ) { return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) ); } if ( isset( $request['status'] ) ) { $this->handle_status_param( $request['status'], $id ); } } $comment = get_comment( $id ); /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php */ do_action( 'rest_insert_comment', $comment, $request, false ); $schema = $this->get_item_schema(); if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { $meta_update = $this->meta->update_value( $request['meta'], $id ); if ( is_wp_error( $meta_update ) ) { return $meta_update; } } $fields_update = $this->update_additional_fields_for_object( $comment, $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update; } $request->set_param( 'context', 'edit' ); /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php */ do_action( 'rest_after_insert_comment', $comment, $request, false ); $response = $this->prepare_item_for_response( $comment, $request ); return rest_ensure_response( $response ); } ``` [do\_action( 'rest\_after\_insert\_comment', WP\_Comment $comment, WP\_REST\_Request $request, bool $creating )](../../hooks/rest_after_insert_comment) Fires completely after a comment is created or updated via the REST API. [do\_action( 'rest\_insert\_comment', WP\_Comment $comment, WP\_REST\_Request $request, bool $creating )](../../hooks/rest_insert_comment) Fires after a comment is created or updated via the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_comment()](get_comment) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Get the comment, if the ID is valid. | | [WP\_REST\_Comments\_Controller::handle\_status\_param()](handle_status_param) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Sets the comment\_status of a given comment object when creating or updating a comment. | | [WP\_REST\_Comments\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves the comment’s schema, conforming to JSON Schema. | | [WP\_REST\_Comments\_Controller::prepare\_item\_for\_database()](prepare_item_for_database) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares a single comment to be inserted into the database. | | [WP\_REST\_Comments\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares a single comment output for response. | | [wp\_check\_comment\_data\_max\_lengths()](../../functions/wp_check_comment_data_max_lengths) wp-includes/comment.php | Compares the lengths of comment data against the maximum character limits. | | [get\_comment\_type()](../../functions/get_comment_type) wp-includes/comment-template.php | Retrieves the comment type of the current comment. | | [wp\_update\_comment()](../../functions/wp_update_comment) wp-includes/comment.php | Updates an existing comment in the database. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_slash()](../../functions/wp_slash) wp-includes/formatting.php | Adds slashes to a string or recursively adds slashes to strings within an array. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [get\_comment()](../../functions/get_comment) wp-includes/comment.php | Retrieves comment data given a comment ID or comment object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::delete_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Comments\_Controller::delete\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ============================================================================================================== Checks if a given request has access to delete a comment. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has access to delete the item, error object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function delete_item_permissions_check( $request ) { $comment = $this->get_comment( $request['id'] ); if ( is_wp_error( $comment ) ) { return $comment; } if ( ! $this->check_edit_permission( $comment ) ) { return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this comment.' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_comment()](get_comment) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Get the comment, if the ID is valid. | | [WP\_REST\_Comments\_Controller::check\_edit\_permission()](check_edit_permission) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a comment can be edited or deleted. | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::check_read_post_permission( WP_Post $post, WP_REST_Request $request ): bool WP\_REST\_Comments\_Controller::check\_read\_post\_permission( WP\_Post $post, WP\_REST\_Request $request ): bool ================================================================================================================= Checks if the post can be read. Correctly handles posts with the inherit status. `$post` [WP\_Post](../wp_post) Required Post object. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request data to check. bool Whether post can be read. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function check_read_post_permission( $post, $request ) { $post_type = get_post_type_object( $post->post_type ); // Return false if custom post type doesn't exist if ( ! $post_type ) { return false; } $posts_controller = $post_type->get_rest_controller(); // Ensure the posts controller is specifically a WP_REST_Posts_Controller instance // before using methods specific to that controller. if ( ! $posts_controller instanceof WP_REST_Posts_Controller ) { $posts_controller = new WP_REST_Posts_Controller( $post->post_type ); } $has_password_filter = false; // Only check password if a specific post was queried for or a single comment $requested_post = ! empty( $request['post'] ) && ( ! is_array( $request['post'] ) || 1 === count( $request['post'] ) ); $requested_comment = ! empty( $request['id'] ); if ( ( $requested_post || $requested_comment ) && $posts_controller->can_access_password_content( $post, $request ) ) { add_filter( 'post_password_required', '__return_false' ); $has_password_filter = true; } if ( post_password_required( $post ) ) { $result = current_user_can( 'edit_post', $post->ID ); } else { $result = $posts_controller->check_read_permission( $post ); } if ( $has_password_filter ) { remove_filter( 'post_password_required', '__return_false' ); } return $result; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::\_\_construct()](../wp_rest_posts_controller/__construct) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Constructor. | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [post\_password\_required()](../../functions/post_password_required) wp-includes/post-template.php | Determines whether the post requires password and whether a correct password has been provided. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::check\_read\_permission()](check_read_permission) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if the comment can be read. | | [WP\_REST\_Comments\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a given request has access to read the comment. | | [WP\_REST\_Comments\_Controller::create\_item\_permissions\_check()](create_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a given request has access to create a comment. | | [WP\_REST\_Comments\_Controller::get\_items\_permissions\_check()](get_items_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a given request has access to read comments. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::normalize_query_param( string $query_param ): string WP\_REST\_Comments\_Controller::normalize\_query\_param( string $query\_param ): string ======================================================================================= Prepends internal property prefix to query parameters to match our response fields. `$query_param` string Required Query parameter. string The normalized query parameter. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function normalize_query_param( $query_param ) { $prefix = 'comment_'; switch ( $query_param ) { case 'id': $normalized = $prefix . 'ID'; break; case 'post': $normalized = $prefix . 'post_ID'; break; case 'parent': $normalized = $prefix . 'parent'; break; case 'include': $normalized = 'comment__in'; break; default: $normalized = $prefix . $query_param; break; } return $normalized; } ``` | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves a list of comment items. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::prepare_item_for_database( WP_REST_Request $request ): array|WP_Error WP\_REST\_Comments\_Controller::prepare\_item\_for\_database( WP\_REST\_Request $request ): array|WP\_Error =========================================================================================================== Prepares a single comment to be inserted into the database. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request object. array|[WP\_Error](../wp_error) Prepared comment, otherwise [WP\_Error](../wp_error) object. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function prepare_item_for_database( $request ) { $prepared_comment = array(); /* * Allow the comment_content to be set via the 'content' or * the 'content.raw' properties of the Request object. */ if ( isset( $request['content'] ) && is_string( $request['content'] ) ) { $prepared_comment['comment_content'] = trim( $request['content'] ); } elseif ( isset( $request['content']['raw'] ) && is_string( $request['content']['raw'] ) ) { $prepared_comment['comment_content'] = trim( $request['content']['raw'] ); } if ( isset( $request['post'] ) ) { $prepared_comment['comment_post_ID'] = (int) $request['post']; } if ( isset( $request['parent'] ) ) { $prepared_comment['comment_parent'] = $request['parent']; } if ( isset( $request['author'] ) ) { $user = new WP_User( $request['author'] ); if ( $user->exists() ) { $prepared_comment['user_id'] = $user->ID; $prepared_comment['comment_author'] = $user->display_name; $prepared_comment['comment_author_email'] = $user->user_email; $prepared_comment['comment_author_url'] = $user->user_url; } else { return new WP_Error( 'rest_comment_author_invalid', __( 'Invalid comment author ID.' ), array( 'status' => 400 ) ); } } if ( isset( $request['author_name'] ) ) { $prepared_comment['comment_author'] = $request['author_name']; } if ( isset( $request['author_email'] ) ) { $prepared_comment['comment_author_email'] = $request['author_email']; } if ( isset( $request['author_url'] ) ) { $prepared_comment['comment_author_url'] = $request['author_url']; } if ( isset( $request['author_ip'] ) && current_user_can( 'moderate_comments' ) ) { $prepared_comment['comment_author_IP'] = $request['author_ip']; } elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( $_SERVER['REMOTE_ADDR'] ) ) { $prepared_comment['comment_author_IP'] = $_SERVER['REMOTE_ADDR']; } else { $prepared_comment['comment_author_IP'] = '127.0.0.1'; } if ( ! empty( $request['author_user_agent'] ) ) { $prepared_comment['comment_agent'] = $request['author_user_agent']; } elseif ( $request->get_header( 'user_agent' ) ) { $prepared_comment['comment_agent'] = $request->get_header( 'user_agent' ); } if ( ! empty( $request['date'] ) ) { $date_data = rest_get_date_with_gmt( $request['date'] ); if ( ! empty( $date_data ) ) { list( $prepared_comment['comment_date'], $prepared_comment['comment_date_gmt'] ) = $date_data; } } elseif ( ! empty( $request['date_gmt'] ) ) { $date_data = rest_get_date_with_gmt( $request['date_gmt'], true ); if ( ! empty( $date_data ) ) { list( $prepared_comment['comment_date'], $prepared_comment['comment_date_gmt'] ) = $date_data; } } /** * Filters a comment added via the REST API after it is prepared for insertion into the database. * * Allows modification of the comment right after it is prepared for the database. * * @since 4.7.0 * * @param array $prepared_comment The prepared comment data for `wp_insert_comment`. * @param WP_REST_Request $request The current request. */ return apply_filters( 'rest_preprocess_comment', $prepared_comment, $request ); } ``` [apply\_filters( 'rest\_preprocess\_comment', array $prepared\_comment, WP\_REST\_Request $request )](../../hooks/rest_preprocess_comment) Filters a comment added via the REST API after it is prepared for insertion into the database. | Uses | Description | | --- | --- | | [rest\_is\_ip\_address()](../../functions/rest_is_ip_address) wp-includes/rest-api.php | Determines if an IP address is valid. | | [rest\_get\_date\_with\_gmt()](../../functions/rest_get_date_with_gmt) wp-includes/rest-api.php | Parses a date into both its local and UTC equivalent, in MySQL datetime format. | | [WP\_User::\_\_construct()](../wp_user/__construct) wp-includes/class-wp-user.php | Constructor. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Updates a comment. | | [WP\_REST\_Comments\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Creates a comment. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |
programming_docs
wordpress WP_REST_Comments_Controller::get_items_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Comments\_Controller::get\_items\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ============================================================================================================ Checks if a given request has access to read comments. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access, error object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function get_items_permissions_check( $request ) { if ( ! empty( $request['post'] ) ) { foreach ( (array) $request['post'] as $post_id ) { $post = get_post( $post_id ); if ( ! empty( $post_id ) && $post && ! $this->check_read_post_permission( $post, $request ) ) { return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); } elseif ( 0 === $post_id && ! current_user_can( 'moderate_comments' ) ) { return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read comments without a post.' ), array( 'status' => rest_authorization_required_code() ) ); } } } if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) { return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); } if ( ! current_user_can( 'edit_posts' ) ) { $protected_params = array( 'author', 'author_exclude', 'author_email', 'type', 'status' ); $forbidden_params = array(); foreach ( $protected_params as $param ) { if ( 'status' === $param ) { if ( 'approve' !== $request[ $param ] ) { $forbidden_params[] = $param; } } elseif ( 'type' === $param ) { if ( 'comment' !== $request[ $param ] ) { $forbidden_params[] = $param; } } elseif ( ! empty( $request[ $param ] ) ) { $forbidden_params[] = $param; } } if ( ! empty( $forbidden_params ) ) { return new WP_Error( 'rest_forbidden_param', /* translators: %s: List of forbidden parameters. */ sprintf( __( 'Query parameter not permitted: %s' ), implode( ', ', $forbidden_params ) ), array( 'status' => rest_authorization_required_code() ) ); } } return true; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::check\_read\_post\_permission()](check_read_post_permission) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if the post can be read. | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::update_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Comments\_Controller::update\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ============================================================================================================== Checks if a given REST request has access to update a comment. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has access to update the item, error object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function update_item_permissions_check( $request ) { $comment = $this->get_comment( $request['id'] ); if ( is_wp_error( $comment ) ) { return $comment; } if ( ! $this->check_edit_permission( $comment ) ) { return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this comment.' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_comment()](get_comment) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Get the comment, if the ID is valid. | | [WP\_REST\_Comments\_Controller::check\_edit\_permission()](check_edit_permission) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a comment can be edited or deleted. | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::handle_status_param( string|int $new_status, int $comment_id ): bool WP\_REST\_Comments\_Controller::handle\_status\_param( string|int $new\_status, int $comment\_id ): bool ======================================================================================================== Sets the comment\_status of a given comment object when creating or updating a comment. `$new_status` string|int Required New comment status. `$comment_id` int Required Comment ID. bool Whether the status was changed. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function handle_status_param( $new_status, $comment_id ) { $old_status = wp_get_comment_status( $comment_id ); if ( $new_status === $old_status ) { return false; } switch ( $new_status ) { case 'approved': case 'approve': case '1': $changed = wp_set_comment_status( $comment_id, 'approve' ); break; case 'hold': case '0': $changed = wp_set_comment_status( $comment_id, 'hold' ); break; case 'spam': $changed = wp_spam_comment( $comment_id ); break; case 'unspam': $changed = wp_unspam_comment( $comment_id ); break; case 'trash': $changed = wp_trash_comment( $comment_id ); break; case 'untrash': $changed = wp_untrash_comment( $comment_id ); break; default: $changed = false; break; } return $changed; } ``` | Uses | Description | | --- | --- | | [wp\_set\_comment\_status()](../../functions/wp_set_comment_status) wp-includes/comment.php | Sets the status of a comment. | | [wp\_get\_comment\_status()](../../functions/wp_get_comment_status) wp-includes/comment.php | Retrieves the status of a comment by comment ID. | | [wp\_spam\_comment()](../../functions/wp_spam_comment) wp-includes/comment.php | Marks a comment as Spam. | | [wp\_unspam\_comment()](../../functions/wp_unspam_comment) wp-includes/comment.php | Removes a comment from the Spam. | | [wp\_trash\_comment()](../../functions/wp_trash_comment) wp-includes/comment.php | Moves a comment to the Trash | | [wp\_untrash\_comment()](../../functions/wp_untrash_comment) wp-includes/comment.php | Removes a comment from the Trash | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Updates a comment. | | [WP\_REST\_Comments\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Creates a comment. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::check_is_comment_content_allowed( array $prepared_comment ): bool WP\_REST\_Comments\_Controller::check\_is\_comment\_content\_allowed( array $prepared\_comment ): bool ====================================================================================================== If empty comments are not allowed, checks if the provided comment content is not empty. `$prepared_comment` array Required The prepared comment data. bool True if the content is allowed, false otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function check_is_comment_content_allowed( $prepared_comment ) { $check = wp_parse_args( $prepared_comment, array( 'comment_post_ID' => 0, 'comment_author' => null, 'comment_author_email' => null, 'comment_author_url' => null, 'comment_parent' => 0, 'user_id' => 0, ) ); /** This filter is documented in wp-includes/comment.php */ $allow_empty = apply_filters( 'allow_empty_comment', false, $check ); if ( $allow_empty ) { return true; } /* * Do not allow a comment to be created with missing or empty * comment_content. See wp_handle_comment_submission(). */ return '' !== $check['comment_content']; } ``` [apply\_filters( 'allow\_empty\_comment', bool $allow\_empty\_comment, array $commentdata )](../../hooks/allow_empty_comment) Filters whether an empty comment should be allowed. | Uses | Description | | --- | --- | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Creates a comment. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Comments_Controller::register_routes() WP\_REST\_Comments\_Controller::register\_routes() ================================================== Registers the routes for comments. * [register\_rest\_route()](../../functions/register_rest_route) File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'create_item' ), 'permission_callback' => array( $this, 'create_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( 'args' => array( 'id' => array( 'description' => __( 'Unique identifier for the comment.' ), 'type' => 'integer', ), ), array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 'password' => array( 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), 'type' => 'string', ), ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_item' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), ), array( 'methods' => WP_REST_Server::DELETABLE, 'callback' => array( $this, 'delete_item' ), 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 'args' => array( 'force' => array( 'type' => 'boolean', 'default' => false, 'description' => __( 'Whether to bypass Trash and force deletion.' ), ), 'password' => array( 'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ), 'type' => 'string', ), ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_collection\_params()](get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves the query params for collections. | | [register\_rest\_route()](../../functions/register_rest_route) wp-includes/rest-api.php | Registers a REST API route. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::check_edit_permission( WP_Comment $comment ): bool WP\_REST\_Comments\_Controller::check\_edit\_permission( WP\_Comment $comment ): bool ===================================================================================== Checks if a comment can be edited or deleted. `$comment` [WP\_Comment](../wp_comment) Required Comment object. bool Whether the comment can be edited or deleted. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function check_edit_permission( $comment ) { if ( 0 === (int) get_current_user_id() ) { return false; } if ( current_user_can( 'moderate_comments' ) ) { return true; } return current_user_can( 'edit_comment', $comment->comment_ID ); } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [get\_current\_user\_id()](../../functions/get_current_user_id) wp-includes/user.php | Gets the current user’s ID. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::update\_item\_permissions\_check()](update_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a given REST request has access to update a comment. | | [WP\_REST\_Comments\_Controller::delete\_item\_permissions\_check()](delete_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a given request has access to delete a comment. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::get_collection_params(): array WP\_REST\_Comments\_Controller::get\_collection\_params(): array ================================================================ Retrieves the query params for collections. array Comments collection parameters. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function get_collection_params() { $query_params = parent::get_collection_params(); $query_params['context']['default'] = 'view'; $query_params['after'] = array( 'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ), 'type' => 'string', 'format' => 'date-time', ); $query_params['author'] = array( 'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), ); $query_params['author_exclude'] = array( 'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), ); $query_params['author_email'] = array( 'default' => null, 'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ), 'format' => 'email', 'type' => 'string', ); $query_params['before'] = array( 'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ), 'type' => 'string', 'format' => 'date-time', ); $query_params['exclude'] = array( 'description' => __( 'Ensure result set excludes specific IDs.' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), ); $query_params['include'] = array( 'description' => __( 'Limit result set to specific IDs.' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'default' => array(), ); $query_params['offset'] = array( 'description' => __( 'Offset the result set by a specific number of items.' ), 'type' => 'integer', ); $query_params['order'] = array( 'description' => __( 'Order sort attribute ascending or descending.' ), 'type' => 'string', 'default' => 'desc', 'enum' => array( 'asc', 'desc', ), ); $query_params['orderby'] = array( 'description' => __( 'Sort collection by comment attribute.' ), 'type' => 'string', 'default' => 'date_gmt', 'enum' => array( 'date', 'date_gmt', 'id', 'include', 'post', 'parent', 'type', ), ); $query_params['parent'] = array( 'default' => array(), 'description' => __( 'Limit result set to comments of specific parent IDs.' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), ); $query_params['parent_exclude'] = array( 'default' => array(), 'description' => __( 'Ensure result set excludes specific parent IDs.' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), ); $query_params['post'] = array( 'default' => array(), 'description' => __( 'Limit result set to comments assigned to specific post IDs.' ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), ); $query_params['status'] = array( 'default' => 'approve', 'description' => __( 'Limit result set to comments assigned a specific status. Requires authorization.' ), 'sanitize_callback' => 'sanitize_key', 'type' => 'string', 'validate_callback' => 'rest_validate_request_arg', ); $query_params['type'] = array( 'default' => 'comment', 'description' => __( 'Limit result set to comments assigned a specific type. Requires authorization.' ), 'sanitize_callback' => 'sanitize_key', 'type' => 'string', 'validate_callback' => 'rest_validate_request_arg', ); $query_params['password'] = array( 'description' => __( 'The password for the post if it is password protected.' ), 'type' => 'string', ); /** * Filters REST API collection parameters for the comments controller. * * This filter registers the collection parameter, but does not map the * collection parameter to an internal WP_Comment_Query parameter. Use the * `rest_comment_query` filter to set WP_Comment_Query parameters. * * @since 4.7.0 * * @param array $query_params JSON Schema-formatted collection parameters. */ return apply_filters( 'rest_comment_collection_params', $query_params ); } ``` [apply\_filters( 'rest\_comment\_collection\_params', array $query\_params )](../../hooks/rest_comment_collection_params) Filters REST API collection parameters for the comments controller. | Uses | Description | | --- | --- | | [WP\_REST\_Controller::get\_collection\_params()](../wp_rest_controller/get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves the query params for the collections. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::register\_routes()](register_routes) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Registers the routes for comments. | | [WP\_REST\_Comments\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves a list of comment items. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |
programming_docs
wordpress WP_REST_Comments_Controller::check_read_permission( WP_Comment $comment, WP_REST_Request $request ): bool WP\_REST\_Comments\_Controller::check\_read\_permission( WP\_Comment $comment, WP\_REST\_Request $request ): bool ================================================================================================================= Checks if the comment can be read. `$comment` [WP\_Comment](../wp_comment) Required Comment object. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request data to check. bool Whether the comment can be read. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` protected function check_read_permission( $comment, $request ) { if ( ! empty( $comment->comment_post_ID ) ) { $post = get_post( $comment->comment_post_ID ); if ( $post ) { if ( $this->check_read_post_permission( $post, $request ) && 1 === (int) $comment->comment_approved ) { return true; } } } if ( 0 === get_current_user_id() ) { return false; } if ( empty( $comment->comment_post_ID ) && ! current_user_can( 'moderate_comments' ) ) { return false; } if ( ! empty( $comment->user_id ) && get_current_user_id() === (int) $comment->user_id ) { return true; } return current_user_can( 'edit_comment', $comment->comment_ID ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::check\_read\_post\_permission()](check_read_post_permission) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if the post can be read. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [get\_current\_user\_id()](../../functions/get_current_user_id) wp-includes/user.php | Gets the current user’s ID. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if a given request has access to read the comment. | | [WP\_REST\_Comments\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Retrieves a list of comment items. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::__construct() WP\_REST\_Comments\_Controller::\_\_construct() =============================================== Constructor. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function __construct() { $this->namespace = 'wp/v2'; $this->rest_base = 'comments'; $this->meta = new WP_REST_Comment_Meta_Fields(); } ``` | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::get_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Comments\_Controller::get\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error =========================================================================================================== Checks if a given request has access to read the comment. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access for the item, error object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function get_item_permissions_check( $request ) { $comment = $this->get_comment( $request['id'] ); if ( is_wp_error( $comment ) ) { return $comment; } if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( 'moderate_comments' ) ) { return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit comments.' ), array( 'status' => rest_authorization_required_code() ) ); } $post = get_post( $comment->comment_post_ID ); if ( ! $this->check_read_permission( $comment, $request ) ) { return new WP_Error( 'rest_cannot_read', __( 'Sorry, you are not allowed to read this comment.' ), array( 'status' => rest_authorization_required_code() ) ); } if ( $post && ! $this->check_read_post_permission( $post, $request ) ) { return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_comment()](get_comment) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Get the comment, if the ID is valid. | | [WP\_REST\_Comments\_Controller::check\_read\_permission()](check_read_permission) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if the comment can be read. | | [WP\_REST\_Comments\_Controller::check\_read\_post\_permission()](check_read_post_permission) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if the post can be read. | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::create_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Comments\_Controller::create\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ============================================================================================================== Checks if a given request has access to create a comment. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has access to create items, error object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function create_item_permissions_check( $request ) { if ( ! is_user_logged_in() ) { if ( get_option( 'comment_registration' ) ) { return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); } /** * Filters whether comments can be created via the REST API without authentication. * * Enables creating comments for anonymous users. * * @since 4.7.0 * * @param bool $allow_anonymous Whether to allow anonymous comments to * be created. Default `false`. * @param WP_REST_Request $request Request used to generate the * response. */ $allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request ); if ( ! $allow_anonymous ) { return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); } } // Limit who can set comment `author`, `author_ip` or `status` to anything other than the default. if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) { return new WP_Error( 'rest_comment_invalid_author', /* translators: %s: Request parameter. */ sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ), array( 'status' => rest_authorization_required_code() ) ); } if ( isset( $request['author_ip'] ) && ! current_user_can( 'moderate_comments' ) ) { if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) { return new WP_Error( 'rest_comment_invalid_author_ip', /* translators: %s: Request parameter. */ sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ), array( 'status' => rest_authorization_required_code() ) ); } } if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) { return new WP_Error( 'rest_comment_invalid_status', /* translators: %s: Request parameter. */ sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ), array( 'status' => rest_authorization_required_code() ) ); } if ( empty( $request['post'] ) ) { return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); } $post = get_post( (int) $request['post'] ); if ( ! $post ) { return new WP_Error( 'rest_comment_invalid_post_id', __( 'Sorry, you are not allowed to create this comment without a post.' ), array( 'status' => 403 ) ); } if ( 'draft' === $post->post_status ) { return new WP_Error( 'rest_comment_draft_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); } if ( 'trash' === $post->post_status ) { return new WP_Error( 'rest_comment_trash_post', __( 'Sorry, you are not allowed to create a comment on this post.' ), array( 'status' => 403 ) ); } if ( ! $this->check_read_post_permission( $post, $request ) ) { return new WP_Error( 'rest_cannot_read_post', __( 'Sorry, you are not allowed to read the post for this comment.' ), array( 'status' => rest_authorization_required_code() ) ); } if ( ! comments_open( $post->ID ) ) { return new WP_Error( 'rest_comment_closed', __( 'Sorry, comments are closed for this item.' ), array( 'status' => 403 ) ); } return true; } ``` [apply\_filters( 'rest\_allow\_anonymous\_comments', bool $allow\_anonymous, WP\_REST\_Request $request )](../../hooks/rest_allow_anonymous_comments) Filters whether comments can be created via the REST API without authentication. | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::check\_read\_post\_permission()](check_read_post_permission) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Checks if the post can be read. | | [comments\_open()](../../functions/comments_open) wp-includes/comment-template.php | Determines whether the current post is open for comments. | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [is\_user\_logged\_in()](../../functions/is_user_logged_in) wp-includes/pluggable.php | Determines whether the current visitor is a logged in user. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [get\_current\_user\_id()](../../functions/get_current_user_id) wp-includes/user.php | Gets the current user’s ID. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::delete_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Comments\_Controller::delete\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ======================================================================================================== Deletes a comment. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or error object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function delete_item( $request ) { $comment = $this->get_comment( $request['id'] ); if ( is_wp_error( $comment ) ) { return $comment; } $force = isset( $request['force'] ) ? (bool) $request['force'] : false; /** * Filters whether a comment can be trashed via the REST API. * * Return false to disable trash support for the comment. * * @since 4.7.0 * * @param bool $supports_trash Whether the comment supports trashing. * @param WP_Comment $comment The comment object being considered for trashing support. */ $supports_trash = apply_filters( 'rest_comment_trashable', ( EMPTY_TRASH_DAYS > 0 ), $comment ); $request->set_param( 'context', 'edit' ); if ( $force ) { $previous = $this->prepare_item_for_response( $comment, $request ); $result = wp_delete_comment( $comment->comment_ID, true ); $response = new WP_REST_Response(); $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data(), ) ); } else { // If this type doesn't support trashing, error out. if ( ! $supports_trash ) { return new WP_Error( 'rest_trash_not_supported', /* translators: %s: force=true */ sprintf( __( "The comment does not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); } if ( 'trash' === $comment->comment_approved ) { return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.' ), array( 'status' => 410 ) ); } $result = wp_trash_comment( $comment->comment_ID ); $comment = get_comment( $comment->comment_ID ); $response = $this->prepare_item_for_response( $comment, $request ); } if ( ! $result ) { return new WP_Error( 'rest_cannot_delete', __( 'The comment cannot be deleted.' ), array( 'status' => 500 ) ); } /** * Fires after a comment is deleted via the REST API. * * @since 4.7.0 * * @param WP_Comment $comment The deleted comment data. * @param WP_REST_Response $response The response returned from the API. * @param WP_REST_Request $request The request sent to the API. */ do_action( 'rest_delete_comment', $comment, $response, $request ); return $response; } ``` [apply\_filters( 'rest\_comment\_trashable', bool $supports\_trash, WP\_Comment $comment )](../../hooks/rest_comment_trashable) Filters whether a comment can be trashed via the REST API. [do\_action( 'rest\_delete\_comment', WP\_Comment $comment, WP\_REST\_Response $response, WP\_REST\_Request $request )](../../hooks/rest_delete_comment) Fires after a comment is deleted via the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::get\_comment()](get_comment) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Get the comment, if the ID is valid. | | [WP\_REST\_Comments\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Prepares a single comment output for response. | | [wp\_delete\_comment()](../../functions/wp_delete_comment) wp-includes/comment.php | Trashes or deletes a comment. | | [wp\_trash\_comment()](../../functions/wp_trash_comment) wp-includes/comment.php | Moves a comment to the Trash | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [get\_comment()](../../functions/get_comment) wp-includes/comment.php | Retrieves comment data given a comment ID or comment object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Comments_Controller::get_item_schema(): array WP\_REST\_Comments\_Controller::get\_item\_schema(): array ========================================================== Retrieves the comment’s schema, conforming to JSON Schema. array File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'comment', 'type' => 'object', 'properties' => array( 'id' => array( 'description' => __( 'Unique identifier for the comment.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'author' => array( 'description' => __( 'The ID of the user object, if author was a user.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), ), 'author_email' => array( 'description' => __( 'Email address for the comment author.' ), 'type' => 'string', 'format' => 'email', 'context' => array( 'edit' ), 'arg_options' => array( 'sanitize_callback' => array( $this, 'check_comment_author_email' ), 'validate_callback' => null, // Skip built-in validation of 'email'. ), ), 'author_ip' => array( 'description' => __( 'IP address for the comment author.' ), 'type' => 'string', 'format' => 'ip', 'context' => array( 'edit' ), ), 'author_name' => array( 'description' => __( 'Display name for the comment author.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => 'sanitize_text_field', ), ), 'author_url' => array( 'description' => __( 'URL for the comment author.' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit', 'embed' ), ), 'author_user_agent' => array( 'description' => __( 'User agent for the comment author.' ), 'type' => 'string', 'context' => array( 'edit' ), 'arg_options' => array( 'sanitize_callback' => 'sanitize_text_field', ), ), 'content' => array( 'description' => __( 'The content for the comment.' ), 'type' => 'object', 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database(). 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database(). ), 'properties' => array( 'raw' => array( 'description' => __( 'Content for the comment, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), ), 'rendered' => array( 'description' => __( 'HTML content for the comment, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), ), ), 'date' => array( 'description' => __( "The date the comment was published, in the site's timezone." ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit', 'embed' ), ), 'date_gmt' => array( 'description' => __( 'The date the comment was published, as GMT.' ), 'type' => 'string', 'format' => 'date-time', 'context' => array( 'view', 'edit' ), ), 'link' => array( 'description' => __( 'URL to the comment.' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'parent' => array( 'description' => __( 'The ID for the parent of the comment.' ), 'type' => 'integer', 'context' => array( 'view', 'edit', 'embed' ), 'default' => 0, ), 'post' => array( 'description' => __( 'The ID of the associated post object.' ), 'type' => 'integer', 'context' => array( 'view', 'edit' ), 'default' => 0, ), 'status' => array( 'description' => __( 'State of the comment.' ), 'type' => 'string', 'context' => array( 'view', 'edit' ), 'arg_options' => array( 'sanitize_callback' => 'sanitize_key', ), ), 'type' => array( 'description' => __( 'Type of the comment.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), ), ); if ( get_option( 'show_avatars' ) ) { $avatar_properties = array(); $avatar_sizes = rest_get_avatar_sizes(); foreach ( $avatar_sizes as $size ) { $avatar_properties[ $size ] = array( /* translators: %d: Avatar image size in pixels. */ 'description' => sprintf( __( 'Avatar URL with image size of %d pixels.' ), $size ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'embed', 'view', 'edit' ), ); } $schema['properties']['author_avatar_urls'] = array( 'description' => __( 'Avatar URLs for the comment author.' ), 'type' => 'object', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, 'properties' => $avatar_properties, ); } $schema['properties']['meta'] = $this->meta->get_field_schema(); $this->schema = $schema; return $this->add_additional_fields_schema( $this->schema ); } ``` | Uses | Description | | --- | --- | | [rest\_get\_avatar\_sizes()](../../functions/rest_get_avatar_sizes) wp-includes/rest-api.php | Retrieves the pixel sizes for avatars. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Used By | Description | | --- | --- | | [WP\_REST\_Comments\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Updates a comment. | | [WP\_REST\_Comments\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Creates a comment. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |
programming_docs
wordpress WP_REST_Comments_Controller::check_comment_author_email( string $value, WP_REST_Request $request, string $param ): string|WP_Error WP\_REST\_Comments\_Controller::check\_comment\_author\_email( string $value, WP\_REST\_Request $request, string $param ): string|WP\_Error =========================================================================================================================================== Checks a comment author email for validity. Accepts either a valid email address or empty string as a valid comment author email address. Setting the comment author email to an empty string is allowed when a comment is being updated. `$value` string Required Author email value submitted. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. `$param` string Required The parameter name. string|[WP\_Error](../wp_error) The sanitized email address, if valid, otherwise an error. File: `wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/) ``` public function check_comment_author_email( $value, $request, $param ) { $email = (string) $value; if ( empty( $email ) ) { return $email; } $check_email = rest_validate_request_arg( $email, $request, $param ); if ( is_wp_error( $check_email ) ) { return $check_email; } return $email; } ``` | Uses | Description | | --- | --- | | [rest\_validate\_request\_arg()](../../functions/rest_validate_request_arg) wp-includes/rest-api.php | Validate a request argument based on details registered to the route. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Filesystem_FTPext::chmod( string $file, int|false $mode = false, bool $recursive = false ): bool WP\_Filesystem\_FTPext::chmod( string $file, int|false $mode = false, bool $recursive = false ): bool ===================================================================================================== Changes filesystem permissions. `$file` string Required Path to the file. `$mode` int|false Optional The permissions as octal number, usually 0644 for files, 0755 for directories. Default: `false` `$recursive` bool Optional If set to true, changes file permissions recursively. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function chmod( $file, $mode = false, $recursive = false ) { if ( ! $mode ) { if ( $this->is_file( $file ) ) { $mode = FS_CHMOD_FILE; } elseif ( $this->is_dir( $file ) ) { $mode = FS_CHMOD_DIR; } else { return false; } } // chmod any sub-objects if recursive. if ( $recursive && $this->is_dir( $file ) ) { $filelist = $this->dirlist( $file ); foreach ( (array) $filelist as $filename => $filemeta ) { $this->chmod( $file . '/' . $filename, $mode, $recursive ); } } // chmod the file or directory. if ( ! function_exists( 'ftp_chmod' ) ) { return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) ); } return (bool) ftp_chmod( $this->link, $mode, $file ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a file. | | [WP\_Filesystem\_FTPext::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a directory. | | [WP\_Filesystem\_FTPext::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_FTPext::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpext.php | Changes filesystem permissions. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::mkdir()](mkdir) wp-admin/includes/class-wp-filesystem-ftpext.php | Creates a directory. | | [WP\_Filesystem\_FTPext::put\_contents()](put_contents) wp-admin/includes/class-wp-filesystem-ftpext.php | Writes a string to a file. | | [WP\_Filesystem\_FTPext::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpext.php | Changes filesystem permissions. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::size( string $file ): int|false WP\_Filesystem\_FTPext::size( string $file ): int|false ======================================================= Gets the file size (in bytes). `$file` string Required Path to file. int|false Size of the file in bytes on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function size( $file ) { $size = ftp_size( $this->link, $file ); return ( $size > -1 ) ? $size : false; } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::getchmod( string $file ): string WP\_Filesystem\_FTPext::getchmod( string $file ): string ======================================================== Gets the permissions of the specified file or filepath in their octal format. `$file` string Required Path to the file. string Mode of the file (the last 3 digits). File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function getchmod( $file ) { $dir = $this->dirlist( $file ); return $dir[ $file ]['permsn']; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::__destruct() WP\_Filesystem\_FTPext::\_\_destruct() ====================================== Destructor. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function __destruct() { if ( $this->link ) { ftp_close( $this->link ); } } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::exists( string $path ): bool WP\_Filesystem\_FTPext::exists( string $path ): bool ==================================================== Checks if a file or directory exists. `$path` string Required Path to file or directory. bool Whether $path exists or not. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function exists( $path ) { if ( $this->is_dir( $path ) ) { return true; } return ! empty( ftp_rawlist( $this->link, $path ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a directory. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a file. | | [WP\_Filesystem\_FTPext::copy()](copy) wp-admin/includes/class-wp-filesystem-ftpext.php | Copies a file. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Uses [WP\_Filesystem\_FTPext::is\_dir()](is_dir) to check for directory existence and ftp\_rawlist() to check for file existence. | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::chdir( string $dir ): bool WP\_Filesystem\_FTPext::chdir( string $dir ): bool ================================================== Changes current directory. `$dir` string Required The new current directory. bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function chdir( $dir ) { return @ftp_chdir( $this->link, $dir ); } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::rmdir( string $path, bool $recursive = false ): bool WP\_Filesystem\_FTPext::rmdir( string $path, bool $recursive = false ): bool ============================================================================ Deletes a directory. `$path` string Required Path to directory. `$recursive` bool Optional Whether to recursively remove files/directories. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function rmdir( $path, $recursive = false ) { return $this->delete( $path, $recursive ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::delete()](delete) wp-admin/includes/class-wp-filesystem-ftpext.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::get_contents( string $file ): string|false WP\_Filesystem\_FTPext::get\_contents( string $file ): string|false =================================================================== Reads entire file into a string. `$file` string Required Name of the file to read. string|false Read data on success, false if no temporary file could be opened, or if the file couldn't be retrieved. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function get_contents( $file ) { $tempfile = wp_tempnam( $file ); $temphandle = fopen( $tempfile, 'w+' ); if ( ! $temphandle ) { unlink( $tempfile ); return false; } if ( ! ftp_fget( $this->link, $temphandle, $file, FTP_BINARY ) ) { fclose( $temphandle ); unlink( $tempfile ); return false; } fseek( $temphandle, 0 ); // Skip back to the start of the file being written to. $contents = ''; while ( ! feof( $temphandle ) ) { $contents .= fread( $temphandle, 8 * KB_IN_BYTES ); } fclose( $temphandle ); unlink( $tempfile ); return $contents; } ``` | Uses | Description | | --- | --- | | [wp\_tempnam()](../../functions/wp_tempnam) wp-admin/includes/file.php | Returns a filename of a temporary unique file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::get\_contents\_array()](get_contents_array) wp-admin/includes/class-wp-filesystem-ftpext.php | Reads entire file into an array. | | [WP\_Filesystem\_FTPext::copy()](copy) wp-admin/includes/class-wp-filesystem-ftpext.php | Copies a file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::is_writable( string $path ): bool WP\_Filesystem\_FTPext::is\_writable( string $path ): bool ========================================================== Checks if a file or directory is writable. `$path` string Required Path to file or directory. bool Whether $path is writable. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function is_writable( $path ) { return true; } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::group( string $file ): string|false WP\_Filesystem\_FTPext::group( string $file ): string|false =========================================================== Gets the file’s group. `$file` string Required Path to the file. string|false The group on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function group( $file ) { $dir = $this->dirlist( $file ); return $dir[ $file ]['group']; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::put_contents( string $file, string $contents, int|false $mode = false ): bool WP\_Filesystem\_FTPext::put\_contents( string $file, string $contents, int|false $mode = false ): bool ====================================================================================================== Writes a string to a file. `$file` string Required Remote path to the file where to write the data. `$contents` string Required The data to write. `$mode` int|false Optional The file permissions as octal number, usually 0644. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function put_contents( $file, $contents, $mode = false ) { $tempfile = wp_tempnam( $file ); $temphandle = fopen( $tempfile, 'wb+' ); if ( ! $temphandle ) { unlink( $tempfile ); return false; } mbstring_binary_safe_encoding(); $data_length = strlen( $contents ); $bytes_written = fwrite( $temphandle, $contents ); reset_mbstring_encoding(); if ( $data_length !== $bytes_written ) { fclose( $temphandle ); unlink( $tempfile ); return false; } fseek( $temphandle, 0 ); // Skip back to the start of the file being written to. $ret = ftp_fput( $this->link, $file, $temphandle, FTP_BINARY ); fclose( $temphandle ); unlink( $tempfile ); $this->chmod( $file, $mode ); return $ret; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpext.php | Changes filesystem permissions. | | [wp\_tempnam()](../../functions/wp_tempnam) wp-admin/includes/file.php | Returns a filename of a temporary unique file. | | [mbstring\_binary\_safe\_encoding()](../../functions/mbstring_binary_safe_encoding) wp-includes/functions.php | Sets the mbstring internal encoding to a binary safe encoding when func\_overload is enabled. | | [reset\_mbstring\_encoding()](../../functions/reset_mbstring_encoding) wp-includes/functions.php | Resets the mbstring internal encoding to a users previously set encoding. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::copy()](copy) wp-admin/includes/class-wp-filesystem-ftpext.php | Copies a file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::is_dir( string $path ): bool WP\_Filesystem\_FTPext::is\_dir( string $path ): bool ===================================================== Checks if resource is a directory. `$path` string Required Directory path. bool Whether $path is a directory. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function is_dir( $path ) { $cwd = $this->cwd(); $result = @ftp_chdir( $this->link, trailingslashit( $path ) ); if ( $result && $path === $this->cwd() || $this->cwd() !== $cwd ) { @ftp_chdir( $this->link, $cwd ); return true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::cwd()](cwd) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets the current working directory. | | [trailingslashit()](../../functions/trailingslashit) wp-includes/formatting.php | Appends a trailing slash. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a file. | | [WP\_Filesystem\_FTPext::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpext.php | Changes filesystem permissions. | | [WP\_Filesystem\_FTPext::exists()](exists) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if a file or directory exists. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::parselisting( string $line ): array WP\_Filesystem\_FTPext::parselisting( string $line ): array =========================================================== `$line` string Required array File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function parselisting( $line ) { static $is_windows = null; if ( is_null( $is_windows ) ) { $is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false; } if ( $is_windows && preg_match( '/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer ) ) { $b = array(); if ( $lucifer[3] < 70 ) { $lucifer[3] += 2000; } else { $lucifer[3] += 1900; // 4-digit year fix. } $b['isdir'] = ( '<DIR>' === $lucifer[7] ); if ( $b['isdir'] ) { $b['type'] = 'd'; } else { $b['type'] = 'f'; } $b['size'] = $lucifer[7]; $b['month'] = $lucifer[1]; $b['day'] = $lucifer[2]; $b['year'] = $lucifer[3]; $b['hour'] = $lucifer[4]; $b['minute'] = $lucifer[5]; $b['time'] = mktime( $lucifer[4] + ( strcasecmp( $lucifer[6], 'PM' ) === 0 ? 12 : 0 ), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3] ); $b['am/pm'] = $lucifer[6]; $b['name'] = $lucifer[8]; } elseif ( ! $is_windows ) { $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY ); if ( $lucifer ) { // echo $line."\n"; $lcount = count( $lucifer ); if ( $lcount < 8 ) { return ''; } $b = array(); $b['isdir'] = 'd' === $lucifer[0][0]; $b['islink'] = 'l' === $lucifer[0][0]; if ( $b['isdir'] ) { $b['type'] = 'd'; } elseif ( $b['islink'] ) { $b['type'] = 'l'; } else { $b['type'] = 'f'; } $b['perms'] = $lucifer[0]; $b['permsn'] = $this->getnumchmodfromh( $b['perms'] ); $b['number'] = $lucifer[1]; $b['owner'] = $lucifer[2]; $b['group'] = $lucifer[3]; $b['size'] = $lucifer[4]; if ( 8 === $lcount ) { sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] ); sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] ); $b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] ); $b['name'] = $lucifer[7]; } else { $b['month'] = $lucifer[5]; $b['day'] = $lucifer[6]; if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) { $b['year'] = gmdate( 'Y' ); $b['hour'] = $l2[1]; $b['minute'] = $l2[2]; } else { $b['year'] = $lucifer[7]; $b['hour'] = 0; $b['minute'] = 0; } $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) ); $b['name'] = $lucifer[8]; } } } // Replace symlinks formatted as "source -> target" with just the source name. if ( isset( $b['islink'] ) && $b['islink'] ) { $b['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $b['name'] ); } return $b; } ``` | Uses | Description | | --- | --- | | [stripos()](../../functions/stripos) wp-includes/class-pop3.php | | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. |
programming_docs
wordpress WP_Filesystem_FTPext::is_readable( string $file ): bool WP\_Filesystem\_FTPext::is\_readable( string $file ): bool ========================================================== Checks if a file is readable. `$file` string Required Path to file. bool Whether $file is readable. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function is_readable( $file ) { return true; } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::is_file( string $file ): bool WP\_Filesystem\_FTPext::is\_file( string $file ): bool ====================================================== Checks if resource is a file. `$file` string Required File path. bool Whether $file is a file. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function is_file( $file ) { return $this->exists( $file ) && ! $this->is_dir( $file ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a directory. | | [WP\_Filesystem\_FTPext::exists()](exists) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if a file or directory exists. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_FTPext::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpext.php | Changes filesystem permissions. | | [WP\_Filesystem\_FTPext::delete()](delete) wp-admin/includes/class-wp-filesystem-ftpext.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::mtime( string $file ): int|false WP\_Filesystem\_FTPext::mtime( string $file ): int|false ======================================================== Gets the file modification time. `$file` string Required Path to file. int|false Unix timestamp representing modification time, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function mtime( $file ) { return ftp_mdtm( $this->link, $file ); } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::mkdir( string $path, int|false $chmod = false, string|int|false $chown = false, string|int|false $chgrp = false ): bool WP\_Filesystem\_FTPext::mkdir( string $path, int|false $chmod = false, string|int|false $chown = false, string|int|false $chgrp = false ): bool =============================================================================================================================================== Creates a directory. `$path` string Required Path for new directory. `$chmod` int|false Optional The permissions as octal number (or false to skip chmod). Default: `false` `$chown` string|int|false Optional A user name or number (or false to skip chown). Default: `false` `$chgrp` string|int|false Optional A group name or number (or false to skip chgrp). Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { $path = untrailingslashit( $path ); if ( empty( $path ) ) { return false; } if ( ! ftp_mkdir( $this->link, $path ) ) { return false; } $this->chmod( $path, $chmod ); return true; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpext.php | Changes filesystem permissions. | | [untrailingslashit()](../../functions/untrailingslashit) wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::owner( string $file ): string|false WP\_Filesystem\_FTPext::owner( string $file ): string|false =========================================================== Gets the file owner. `$file` string Required Path to the file. string|false Username of the owner on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function owner( $file ) { $dir = $this->dirlist( $file ); return $dir[ $file ]['owner']; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::cwd(): string|false WP\_Filesystem\_FTPext::cwd(): string|false =========================================== Gets the current working directory. string|false The current working directory on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function cwd() { $cwd = ftp_pwd( $this->link ); if ( $cwd ) { $cwd = trailingslashit( $cwd ); } return $cwd; } ``` | Uses | Description | | --- | --- | | [trailingslashit()](../../functions/trailingslashit) wp-includes/formatting.php | Appends a trailing slash. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a directory. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::__construct( array $opt = '' ) WP\_Filesystem\_FTPext::\_\_construct( array $opt = '' ) ======================================================== Constructor. `$opt` array Optional Default: `''` File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function __construct( $opt = '' ) { $this->method = 'ftpext'; $this->errors = new WP_Error(); // Check if possible to use ftp functions. if ( ! extension_loaded( 'ftp' ) ) { $this->errors->add( 'no_ftp_ext', __( 'The ftp PHP extension is not available' ) ); return; } // This class uses the timeout on a per-connection basis, others use it on a per-action basis. if ( ! defined( 'FS_TIMEOUT' ) ) { define( 'FS_TIMEOUT', 4 * MINUTE_IN_SECONDS ); } if ( empty( $opt['port'] ) ) { $this->options['port'] = 21; } else { $this->options['port'] = $opt['port']; } if ( empty( $opt['hostname'] ) ) { $this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) ); } else { $this->options['hostname'] = $opt['hostname']; } // Check if the options provided are OK. if ( empty( $opt['username'] ) ) { $this->errors->add( 'empty_username', __( 'FTP username is required' ) ); } else { $this->options['username'] = $opt['username']; } if ( empty( $opt['password'] ) ) { $this->errors->add( 'empty_password', __( 'FTP password is required' ) ); } else { $this->options['password'] = $opt['password']; } $this->options['ssl'] = false; if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) { $this->options['ssl'] = true; } } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::copy( string $source, string $destination, bool $overwrite = false, int|false $mode = false ): bool WP\_Filesystem\_FTPext::copy( string $source, string $destination, bool $overwrite = false, int|false $mode = false ): bool =========================================================================================================================== Copies a file. `$source` string Required Path to the source file. `$destination` string Required Path to the destination file. `$overwrite` bool Optional Whether to overwrite the destination file if it exists. Default: `false` `$mode` int|false Optional The permissions as octal number, usually 0644 for files, 0755 for dirs. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function copy( $source, $destination, $overwrite = false, $mode = false ) { if ( ! $overwrite && $this->exists( $destination ) ) { return false; } $content = $this->get_contents( $source ); if ( false === $content ) { return false; } return $this->put_contents( $destination, $content, $mode ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::exists()](exists) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if a file or directory exists. | | [WP\_Filesystem\_FTPext::get\_contents()](get_contents) wp-admin/includes/class-wp-filesystem-ftpext.php | Reads entire file into a string. | | [WP\_Filesystem\_FTPext::put\_contents()](put_contents) wp-admin/includes/class-wp-filesystem-ftpext.php | Writes a string to a file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::get_contents_array( string $file ): array|false WP\_Filesystem\_FTPext::get\_contents\_array( string $file ): array|false ========================================================================= Reads entire file into an array. `$file` string Required Path to the file. array|false File contents in an array on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function get_contents_array( $file ) { return explode( "\n", $this->get_contents( $file ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::get\_contents()](get_contents) wp-admin/includes/class-wp-filesystem-ftpext.php | Reads entire file into a string. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::dirlist( string $path = '.', bool $include_hidden = true, bool $recursive = false ): array|false WP\_Filesystem\_FTPext::dirlist( string $path = '.', bool $include\_hidden = true, bool $recursive = false ): array|false ========================================================================================================================= Gets details for files in a directory or a specific file. `$path` string Optional Path to directory or file. Default: `'.'` `$include_hidden` bool Optional Whether to include details of hidden ("." prefixed) files. Default: `true` `$recursive` bool Optional Whether to recursively include file details in nested directories. Default: `false` array|false Array of files. False if unable to list directory contents. * `name`stringName of the file or directory. * `perms`string\*nix representation of permissions. * `permsn`stringOctal representation of permissions. * `owner`stringOwner name or ID. * `size`intSize of file in bytes. * `lastmodunix`intLast modified unix timestamp. * `lastmod`mixedLast modified month (3 letter) and day (without leading 0). * `time`intLast modified time. * `type`stringType of resource. `'f'` for file, `'d'` for directory. * `files`mixedIf a directory and `$recursive` is true, contains another array of files. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) { if ( $this->is_file( $path ) ) { $limit_file = basename( $path ); $path = dirname( $path ) . '/'; } else { $limit_file = false; } $pwd = ftp_pwd( $this->link ); if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist. return false; } $list = ftp_rawlist( $this->link, '-a', false ); @ftp_chdir( $this->link, $pwd ); if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least). return false; } $dirlist = array(); foreach ( $list as $k => $v ) { $entry = $this->parselisting( $v ); if ( empty( $entry ) ) { continue; } if ( '.' === $entry['name'] || '..' === $entry['name'] ) { continue; } if ( ! $include_hidden && '.' === $entry['name'][0] ) { continue; } if ( $limit_file && $entry['name'] !== $limit_file ) { continue; } $dirlist[ $entry['name'] ] = $entry; } $ret = array(); foreach ( (array) $dirlist as $struc ) { if ( 'd' === $struc['type'] ) { if ( $recursive ) { $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); } else { $struc['files'] = array(); } } $ret[ $struc['name'] ] = $struc; } return $ret; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a file. | | [WP\_Filesystem\_FTPext::parselisting()](parselisting) wp-admin/includes/class-wp-filesystem-ftpext.php | | | [WP\_Filesystem\_FTPext::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_FTPext::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpext.php | Changes filesystem permissions. | | [WP\_Filesystem\_FTPext::owner()](owner) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets the file owner. | | [WP\_Filesystem\_FTPext::getchmod()](getchmod) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets the permissions of the specified file or filepath in their octal format. | | [WP\_Filesystem\_FTPext::group()](group) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets the file’s group. | | [WP\_Filesystem\_FTPext::delete()](delete) wp-admin/includes/class-wp-filesystem-ftpext.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::move( string $source, string $destination, bool $overwrite = false ): bool WP\_Filesystem\_FTPext::move( string $source, string $destination, bool $overwrite = false ): bool ================================================================================================== Moves a file. `$source` string Required Path to the source file. `$destination` string Required Path to the destination file. `$overwrite` bool Optional Whether to overwrite the destination file if it exists. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function move( $source, $destination, $overwrite = false ) { return ftp_rename( $this->link, $source, $destination ); } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::atime( string $file ): int|false WP\_Filesystem\_FTPext::atime( string $file ): int|false ======================================================== Gets the file’s last access time. `$file` string Required Path to file. int|false Unix timestamp representing last access time, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function atime( $file ) { return false; } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::touch( string $file, int $time, int $atime ): bool WP\_Filesystem\_FTPext::touch( string $file, int $time, int $atime ): bool ========================================================================== Sets the access and modification times of a file. Note: If $file doesn’t exist, it will be created. `$file` string Required Path to file. `$time` int Optional Modified time to set for file. Default 0. `$atime` int Optional Access time to set for file. Default 0. bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function touch( $file, $time = 0, $atime = 0 ) { return false; } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_FTPext::delete( string $file, bool $recursive = false, string|false $type = false ): bool WP\_Filesystem\_FTPext::delete( string $file, bool $recursive = false, string|false $type = false ): bool ========================================================================================================= Deletes a file or directory. `$file` string Required Path to the file or directory. `$recursive` bool Optional If set to true, deletes files and folders recursively. Default: `false` `$type` string|false Optional Type of resource. `'f'` for file, `'d'` for directory. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function delete( $file, $recursive = false, $type = false ) { if ( empty( $file ) ) { return false; } if ( 'f' === $type || $this->is_file( $file ) ) { return ftp_delete( $this->link, $file ); } if ( ! $recursive ) { return ftp_rmdir( $this->link, $file ); } $filelist = $this->dirlist( trailingslashit( $file ) ); if ( ! empty( $filelist ) ) { foreach ( $filelist as $delete_file ) { $this->delete( trailingslashit( $file ) . $delete_file['name'], $recursive, $delete_file['type'] ); } } return ftp_rmdir( $this->link, $file ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_FTPext::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpext.php | Checks if resource is a file. | | [WP\_Filesystem\_FTPext::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpext.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_FTPext::delete()](delete) wp-admin/includes/class-wp-filesystem-ftpext.php | Deletes a file or directory. | | [trailingslashit()](../../functions/trailingslashit) wp-includes/formatting.php | Appends a trailing slash. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_FTPext::rmdir()](rmdir) wp-admin/includes/class-wp-filesystem-ftpext.php | Deletes a directory. | | [WP\_Filesystem\_FTPext::delete()](delete) wp-admin/includes/class-wp-filesystem-ftpext.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |
programming_docs
wordpress WP_Filesystem_FTPext::connect(): bool WP\_Filesystem\_FTPext::connect(): bool ======================================= Connects filesystem. bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpext.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpext.php/) ``` public function connect() { if ( isset( $this->options['ssl'] ) && $this->options['ssl'] && function_exists( 'ftp_ssl_connect' ) ) { $this->link = @ftp_ssl_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT ); } else { $this->link = @ftp_connect( $this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT ); } if ( ! $this->link ) { $this->errors->add( 'connect', sprintf( /* translators: %s: hostname:port */ __( 'Failed to connect to FTP Server %s' ), $this->options['hostname'] . ':' . $this->options['port'] ) ); return false; } if ( ! @ftp_login( $this->link, $this->options['username'], $this->options['password'] ) ) { $this->errors->add( 'auth', sprintf( /* translators: %s: Username. */ __( 'Username/Password incorrect for %s' ), $this->options['username'] ) ); return false; } // Set the connection to use Passive FTP. ftp_pasv( $this->link, true ); if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) { @ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT ); } return true; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::save_nav_menus_created_posts( WP_Customize_Setting $setting ) WP\_Customize\_Nav\_Menus::save\_nav\_menus\_created\_posts( WP\_Customize\_Setting $setting ) ============================================================================================== Publishes the auto-draft posts that were created for nav menu items. The post IDs will have been sanitized by already by `WP_Customize_Nav_Menu_Items::sanitize_nav_menus_created_posts()` to remove any post IDs for which the user cannot publish or for which the post is not an auto-draft. `$setting` [WP\_Customize\_Setting](../wp_customize_setting) Required Customizer setting object. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function save_nav_menus_created_posts( $setting ) { $post_ids = $setting->post_value(); if ( ! empty( $post_ids ) ) { foreach ( $post_ids as $post_id ) { // Prevent overriding the status that a user may have prematurely updated the post to. $current_status = get_post_status( $post_id ); if ( 'auto-draft' !== $current_status && 'draft' !== $current_status ) { continue; } $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish'; $args = array( 'ID' => $post_id, 'post_status' => $target_status, ); $post_name = get_post_meta( $post_id, '_customize_draft_post_name', true ); if ( $post_name ) { $args['post_name'] = $post_name; } // Note that wp_publish_post() cannot be used because unique slugs need to be assigned. wp_update_post( wp_slash( $args ) ); delete_post_meta( $post_id, '_customize_draft_post_name' ); } } } ``` | Uses | Description | | --- | --- | | [wp\_update\_post()](../../functions/wp_update_post) wp-includes/post.php | Updates a post with new post data. | | [delete\_post\_meta()](../../functions/delete_post_meta) wp-includes/post.php | Deletes a post meta field for the given post ID. | | [get\_post\_status()](../../functions/get_post_status) wp-includes/post.php | Retrieves the post status based on the post ID. | | [get\_post\_type()](../../functions/get_post_type) wp-includes/post.php | Retrieves the post type of the current post or of a given post. | | [wp\_slash()](../../functions/wp_slash) wp-includes/formatting.php | Adds slashes to a string or recursively adds slashes to strings within an array. | | [get\_post\_meta()](../../functions/get_post_meta) wp-includes/post.php | Retrieves a post meta field for the given post ID. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::search_available_items_query( array $args = array() ): array WP\_Customize\_Nav\_Menus::search\_available\_items\_query( array $args = array() ): array ========================================================================================== Performs post queries for available-item searching. Based on WP\_Editor::wp\_link\_query(). `$args` array Optional Accepts `'pagenum'` and `'s'` (search) arguments. Default: `array()` array Menu items. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function search_available_items_query( $args = array() ) { $items = array(); $post_type_objects = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' ); $query = array( 'post_type' => array_keys( $post_type_objects ), 'suppress_filters' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'post_status' => 'publish', 'posts_per_page' => 20, ); $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1; $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0; if ( isset( $args['s'] ) ) { $query['s'] = $args['s']; } $posts = array(); // Prepend list of posts with nav_menus_created_posts search results on first page. $nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' ); if ( 1 === $args['pagenum'] && $nav_menus_created_posts_setting && count( $nav_menus_created_posts_setting->value() ) > 0 ) { $stub_post_query = new WP_Query( array_merge( $query, array( 'post_status' => 'auto-draft', 'post__in' => $nav_menus_created_posts_setting->value(), 'posts_per_page' => -1, ) ) ); $posts = array_merge( $posts, $stub_post_query->posts ); } // Query posts. $get_posts = new WP_Query( $query ); $posts = array_merge( $posts, $get_posts->posts ); // Create items for posts. foreach ( $posts as $post ) { $post_title = $post->post_title; if ( '' === $post_title ) { /* translators: %d: ID of a post. */ $post_title = sprintf( __( '#%d (no title)' ), $post->ID ); } $post_type_label = $post_type_objects[ $post->post_type ]->labels->singular_name; $post_states = get_post_states( $post ); if ( ! empty( $post_states ) ) { $post_type_label = implode( ',', $post_states ); } $items[] = array( 'id' => 'post-' . $post->ID, 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ), 'type' => 'post_type', 'type_label' => $post_type_label, 'object' => $post->post_type, 'object_id' => (int) $post->ID, 'url' => get_permalink( (int) $post->ID ), ); } // Query taxonomy terms. $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'names' ); $terms = get_terms( array( 'taxonomies' => $taxonomies, 'name__like' => $args['s'], 'number' => 20, 'hide_empty' => false, 'offset' => 20 * ( $args['pagenum'] - 1 ), ) ); // Check if any taxonomies were found. if ( ! empty( $terms ) ) { foreach ( $terms as $term ) { $items[] = array( 'id' => 'term-' . $term->term_id, 'title' => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ), 'type' => 'taxonomy', 'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name, 'object' => $term->taxonomy, 'object_id' => (int) $term->term_id, 'url' => get_term_link( (int) $term->term_id, $term->taxonomy ), ); } } // Add "Home" link if search term matches. Treat as a page, but switch to custom on add. if ( isset( $args['s'] ) ) { // Only insert custom "Home" link if there's no Front Page $front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; if ( empty( $front_page ) ) { $title = _x( 'Home', 'nav menu home label' ); $matches = function_exists( 'mb_stripos' ) ? false !== mb_stripos( $title, $args['s'] ) : false !== stripos( $title, $args['s'] ); if ( $matches ) { $items[] = array( 'id' => 'home', 'title' => $title, 'type' => 'custom', 'type_label' => __( 'Custom Link' ), 'object' => '', 'url' => home_url(), ); } } } /** * Filters the available menu items during a search request. * * @since 4.5.0 * * @param array $items The array of menu items. * @param array $args Includes 'pagenum' and 's' (search) arguments. */ $items = apply_filters( 'customize_nav_menu_searched_items', $items, $args ); return $items; } ``` [apply\_filters( 'customize\_nav\_menu\_searched\_items', array $items, array $args )](../../hooks/customize_nav_menu_searched_items) Filters the available menu items during a search request. | Uses | Description | | --- | --- | | [stripos()](../../functions/stripos) wp-includes/class-pop3.php | | | [get\_post\_states()](../../functions/get_post_states) wp-admin/includes/template.php | Retrieves an array of post states from a post. | | [WP\_Query::\_\_construct()](../wp_query/__construct) wp-includes/class-wp-query.php | Constructor. | | [get\_term\_link()](../../functions/get_term_link) wp-includes/taxonomy.php | Generates a permalink for a taxonomy term archive. | | [get\_terms()](../../functions/get_terms) wp-includes/taxonomy.php | Retrieves the terms in a given taxonomy or list of taxonomies. | | [get\_taxonomies()](../../functions/get_taxonomies) wp-includes/taxonomy.php | Retrieves a list of registered taxonomy names or objects. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | [get\_taxonomy()](../../functions/get_taxonomy) wp-includes/taxonomy.php | Retrieves the taxonomy object of $taxonomy. | | [home\_url()](../../functions/home_url) wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. | | [get\_permalink()](../../functions/get_permalink) wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [get\_post\_types()](../../functions/get_post_types) wp-includes/post.php | Gets a list of all registered post type objects. | | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::ajax\_search\_available\_items()](ajax_search_available_items) wp-includes/class-wp-customize-nav-menus.php | Ajax handler for searching available menu items. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::insert_auto_draft_post( array $postarr ): WP_Post|WP_Error WP\_Customize\_Nav\_Menus::insert\_auto\_draft\_post( array $postarr ): WP\_Post|WP\_Error ========================================================================================== Adds a new `auto-draft` post. `$postarr` array Required Post array. Note that post\_status is overridden to be `auto-draft` [WP\_Post](../wp_post)|[WP\_Error](../wp_error) Inserted auto-draft post object or error. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function insert_auto_draft_post( $postarr ) { if ( ! isset( $postarr['post_type'] ) ) { return new WP_Error( 'unknown_post_type', __( 'Invalid post type.' ) ); } if ( empty( $postarr['post_title'] ) ) { return new WP_Error( 'empty_title', __( 'Empty title.' ) ); } if ( ! empty( $postarr['post_status'] ) ) { return new WP_Error( 'status_forbidden', __( 'Status is forbidden.' ) ); } /* * If the changeset is a draft, this will change to draft the next time the changeset * is updated; otherwise, auto-draft will persist in autosave revisions, until save. */ $postarr['post_status'] = 'auto-draft'; // Auto-drafts are allowed to have empty post_names, so it has to be explicitly set. if ( empty( $postarr['post_name'] ) ) { $postarr['post_name'] = sanitize_title( $postarr['post_title'] ); } if ( ! isset( $postarr['meta_input'] ) ) { $postarr['meta_input'] = array(); } $postarr['meta_input']['_customize_draft_post_name'] = $postarr['post_name']; $postarr['meta_input']['_customize_changeset_uuid'] = $this->manager->changeset_uuid(); unset( $postarr['post_name'] ); add_filter( 'wp_insert_post_empty_content', '__return_false', 1000 ); $r = wp_insert_post( wp_slash( $postarr ), true ); remove_filter( 'wp_insert_post_empty_content', '__return_false', 1000 ); if ( is_wp_error( $r ) ) { return $r; } else { return get_post( $r ); } } ``` | Uses | Description | | --- | --- | | [sanitize\_title()](../../functions/sanitize_title) wp-includes/formatting.php | Sanitizes a string into a slug, which can be used in URLs or HTML attributes. | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [wp\_insert\_post()](../../functions/wp_insert_post) wp-includes/post.php | Inserts or update a post. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_slash()](../../functions/wp_slash) wp-includes/formatting.php | Adds slashes to a string or recursively adds slashes to strings within an array. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::ajax\_insert\_auto\_draft\_post()](ajax_insert_auto_draft_post) wp-includes/class-wp-customize-nav-menus.php | Ajax handler for adding a new auto-draft post. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::customize_dynamic_partial_args( array|false $partial_args, string $partial_id ): array WP\_Customize\_Nav\_Menus::customize\_dynamic\_partial\_args( array|false $partial\_args, string $partial\_id ): array ====================================================================================================================== Filters arguments for dynamic nav\_menu selective refresh partials. `$partial_args` array|false Required Partial args. `$partial_id` string Required Partial ID. array Partial args. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function customize_dynamic_partial_args( $partial_args, $partial_id ) { if ( preg_match( '/^nav_menu_instance\[[0-9a-f]{32}\]$/', $partial_id ) ) { if ( false === $partial_args ) { $partial_args = array(); } $partial_args = array_merge( $partial_args, array( 'type' => 'nav_menu_instance', 'render_callback' => array( $this, 'render_nav_menu_partial' ), 'container_inclusive' => true, 'settings' => array(), // Empty because the nav menu instance may relate to a menu or a location. 'capability' => 'edit_theme_options', ) ); } return $partial_args; } ``` | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::filter_dynamic_setting_args( false|array $setting_args, string $setting_id ): array|false WP\_Customize\_Nav\_Menus::filter\_dynamic\_setting\_args( false|array $setting\_args, string $setting\_id ): array|false ========================================================================================================================= Filters a dynamic setting’s constructor args. For a dynamic setting to be registered, this filter must be employed to override the default false value with an array of args to pass to the [WP\_Customize\_Setting](../wp_customize_setting) constructor. `$setting_args` false|array Required The arguments to the [WP\_Customize\_Setting](../wp_customize_setting) constructor. `$setting_id` string Required ID for dynamic setting, usually coming from `$_POST['customized']`. array|false File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function filter_dynamic_setting_args( $setting_args, $setting_id ) { if ( preg_match( WP_Customize_Nav_Menu_Setting::ID_PATTERN, $setting_id ) ) { $setting_args = array( 'type' => WP_Customize_Nav_Menu_Setting::TYPE, 'transport' => 'postMessage', ); } elseif ( preg_match( WP_Customize_Nav_Menu_Item_Setting::ID_PATTERN, $setting_id ) ) { $setting_args = array( 'type' => WP_Customize_Nav_Menu_Item_Setting::TYPE, 'transport' => 'postMessage', ); } return $setting_args; } ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::load_available_items_query( string $object_type = 'post_type', string $object_name = 'page', int $page ): array|WP_Error WP\_Customize\_Nav\_Menus::load\_available\_items\_query( string $object\_type = 'post\_type', string $object\_name = 'page', int $page ): array|WP\_Error ========================================================================================================================================================== Performs the post\_type and taxonomy queries for loading available menu items. `$object_type` string Optional Accepts any custom object type and has built-in support for `'post_type'` and `'taxonomy'`. Default is `'post_type'`. Default: `'post_type'` `$object_name` string Optional Accepts any registered taxonomy or post type name. Default is `'page'`. Default: `'page'` `$page` int Optional The page number used to generate the query offset. Default is `'0'`. array|[WP\_Error](../wp_error) An array of menu items on success, a [WP\_Error](../wp_error) object on failure. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function load_available_items_query( $object_type = 'post_type', $object_name = 'page', $page = 0 ) { $items = array(); if ( 'post_type' === $object_type ) { $post_type = get_post_type_object( $object_name ); if ( ! $post_type ) { return new WP_Error( 'nav_menus_invalid_post_type' ); } /* * If we're dealing with pages, let's prioritize the Front Page, * Posts Page and Privacy Policy Page at the top of the list. */ $important_pages = array(); $suppress_page_ids = array(); if ( 0 === $page && 'page' === $object_name ) { // Insert Front Page or custom "Home" link. $front_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0; if ( ! empty( $front_page ) ) { $front_page_obj = get_post( $front_page ); $important_pages[] = $front_page_obj; $suppress_page_ids[] = $front_page_obj->ID; } else { // Add "Home" link. Treat as a page, but switch to custom on add. $items[] = array( 'id' => 'home', 'title' => _x( 'Home', 'nav menu home label' ), 'type' => 'custom', 'type_label' => __( 'Custom Link' ), 'object' => '', 'url' => home_url(), ); } // Insert Posts Page. $posts_page = 'page' === get_option( 'show_on_front' ) ? (int) get_option( 'page_for_posts' ) : 0; if ( ! empty( $posts_page ) ) { $posts_page_obj = get_post( $posts_page ); $important_pages[] = $posts_page_obj; $suppress_page_ids[] = $posts_page_obj->ID; } // Insert Privacy Policy Page. $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); if ( ! empty( $privacy_policy_page_id ) ) { $privacy_policy_page = get_post( $privacy_policy_page_id ); if ( $privacy_policy_page instanceof WP_Post && 'publish' === $privacy_policy_page->post_status ) { $important_pages[] = $privacy_policy_page; $suppress_page_ids[] = $privacy_policy_page->ID; } } } elseif ( 'post' !== $object_name && 0 === $page && $post_type->has_archive ) { // Add a post type archive link. $items[] = array( 'id' => $object_name . '-archive', 'title' => $post_type->labels->archives, 'type' => 'post_type_archive', 'type_label' => __( 'Post Type Archive' ), 'object' => $object_name, 'url' => get_post_type_archive_link( $object_name ), ); } // Prepend posts with nav_menus_created_posts on first page. $posts = array(); if ( 0 === $page && $this->manager->get_setting( 'nav_menus_created_posts' ) ) { foreach ( $this->manager->get_setting( 'nav_menus_created_posts' )->value() as $post_id ) { $auto_draft_post = get_post( $post_id ); if ( $post_type->name === $auto_draft_post->post_type ) { $posts[] = $auto_draft_post; } } } $args = array( 'numberposts' => 10, 'offset' => 10 * $page, 'orderby' => 'date', 'order' => 'DESC', 'post_type' => $object_name, ); // Add suppression array to arguments for get_posts. if ( ! empty( $suppress_page_ids ) ) { $args['post__not_in'] = $suppress_page_ids; } $posts = array_merge( $posts, $important_pages, get_posts( $args ) ); foreach ( $posts as $post ) { $post_title = $post->post_title; if ( '' === $post_title ) { /* translators: %d: ID of a post. */ $post_title = sprintf( __( '#%d (no title)' ), $post->ID ); } $post_type_label = get_post_type_object( $post->post_type )->labels->singular_name; $post_states = get_post_states( $post ); if ( ! empty( $post_states ) ) { $post_type_label = implode( ',', $post_states ); } $items[] = array( 'id' => "post-{$post->ID}", 'title' => html_entity_decode( $post_title, ENT_QUOTES, get_bloginfo( 'charset' ) ), 'type' => 'post_type', 'type_label' => $post_type_label, 'object' => $post->post_type, 'object_id' => (int) $post->ID, 'url' => get_permalink( (int) $post->ID ), ); } } elseif ( 'taxonomy' === $object_type ) { $terms = get_terms( array( 'taxonomy' => $object_name, 'child_of' => 0, 'exclude' => '', 'hide_empty' => false, 'hierarchical' => 1, 'include' => '', 'number' => 10, 'offset' => 10 * $page, 'order' => 'DESC', 'orderby' => 'count', 'pad_counts' => false, ) ); if ( is_wp_error( $terms ) ) { return $terms; } foreach ( $terms as $term ) { $items[] = array( 'id' => "term-{$term->term_id}", 'title' => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ), 'type' => 'taxonomy', 'type_label' => get_taxonomy( $term->taxonomy )->labels->singular_name, 'object' => $term->taxonomy, 'object_id' => (int) $term->term_id, 'url' => get_term_link( (int) $term->term_id, $term->taxonomy ), ); } } /** * Filters the available menu items. * * @since 4.3.0 * * @param array $items The array of menu items. * @param string $object_type The object type. * @param string $object_name The object name. * @param int $page The current page number. */ $items = apply_filters( 'customize_nav_menu_available_items', $items, $object_type, $object_name, $page ); return $items; } ``` [apply\_filters( 'customize\_nav\_menu\_available\_items', array $items, string $object\_type, string $object\_name, int $page )](../../hooks/customize_nav_menu_available_items) Filters the available menu items. | Uses | Description | | --- | --- | | [get\_post\_states()](../../functions/get_post_states) wp-admin/includes/template.php | Retrieves an array of post states from a post. | | [get\_terms()](../../functions/get_terms) wp-includes/taxonomy.php | Retrieves the terms in a given taxonomy or list of taxonomies. | | [get\_posts()](../../functions/get_posts) wp-includes/post.php | Retrieves an array of the latest posts, or posts matching the given criteria. | | [get\_post\_type\_archive\_link()](../../functions/get_post_type_archive_link) wp-includes/link-template.php | Retrieves the permalink for a post type archive. | | [get\_term\_link()](../../functions/get_term_link) wp-includes/taxonomy.php | Generates a permalink for a taxonomy term archive. | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | [get\_taxonomy()](../../functions/get_taxonomy) wp-includes/taxonomy.php | Retrieves the taxonomy object of $taxonomy. | | [home\_url()](../../functions/home_url) wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [get\_permalink()](../../functions/get_permalink) wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::ajax\_load\_available\_items()](ajax_load_available_items) wp-includes/class-wp-customize-nav-menus.php | Ajax handler for loading available menu items. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |
programming_docs
wordpress WP_Customize_Nav_Menus::customize_register() WP\_Customize\_Nav\_Menus::customize\_register() ================================================ Adds the customizer settings and controls. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function customize_register() { $changeset = $this->manager->unsanitized_post_values(); // Preview settings for nav menus early so that the sections and controls will be added properly. $nav_menus_setting_ids = array(); foreach ( array_keys( $changeset ) as $setting_id ) { if ( preg_match( '/^(nav_menu_locations|nav_menu|nav_menu_item)\[/', $setting_id ) ) { $nav_menus_setting_ids[] = $setting_id; } } $settings = $this->manager->add_dynamic_settings( $nav_menus_setting_ids ); if ( $this->manager->settings_previewed() ) { foreach ( $settings as $setting ) { $setting->preview(); } } // Require JS-rendered control types. $this->manager->register_panel_type( 'WP_Customize_Nav_Menus_Panel' ); $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Control' ); $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Name_Control' ); $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Locations_Control' ); $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Auto_Add_Control' ); $this->manager->register_control_type( 'WP_Customize_Nav_Menu_Item_Control' ); // Create a panel for Menus. $description = '<p>' . __( 'This panel is used for managing navigation menus for content you have already published on your site. You can create menus and add items for existing content such as pages, posts, categories, tags, formats, or custom links.' ) . '</p>'; if ( current_theme_supports( 'widgets' ) ) { $description .= '<p>' . sprintf( /* translators: %s: URL to the Widgets panel of the Customizer. */ __( 'Menus can be displayed in locations defined by your theme or in <a href="%s">widget areas</a> by adding a &#8220;Navigation Menu&#8221; widget.' ), "javascript:wp.customize.panel( 'widgets' ).focus();" ) . '</p>'; } else { $description .= '<p>' . __( 'Menus can be displayed in locations defined by your theme.' ) . '</p>'; } /* * Once multiple theme supports are allowed in WP_Customize_Panel, * this panel can be restricted to themes that support menus or widgets. */ $this->manager->add_panel( new WP_Customize_Nav_Menus_Panel( $this->manager, 'nav_menus', array( 'title' => __( 'Menus' ), 'description' => $description, 'priority' => 100, ) ) ); $menus = wp_get_nav_menus(); // Menu locations. $locations = get_registered_nav_menus(); $num_locations = count( $locations ); if ( 1 === $num_locations ) { $description = '<p>' . __( 'Your theme can display menus in one location. Select which menu you would like to use.' ) . '</p>'; } else { /* translators: %s: Number of menu locations. */ $description = '<p>' . sprintf( _n( 'Your theme can display menus in %s location. Select which menu you would like to use.', 'Your theme can display menus in %s locations. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>'; } if ( current_theme_supports( 'widgets' ) ) { /* translators: URL to the Widgets panel of the Customizer. */ $description .= '<p>' . sprintf( __( 'If your theme has widget areas, you can also add menus there. Visit the <a href="%s">Widgets panel</a> and add a &#8220;Navigation Menu widget&#8221; to display a menu in a sidebar or footer.' ), "javascript:wp.customize.panel( 'widgets' ).focus();" ) . '</p>'; } $this->manager->add_section( 'menu_locations', array( 'title' => 1 === $num_locations ? _x( 'View Location', 'menu locations' ) : _x( 'View All Locations', 'menu locations' ), 'panel' => 'nav_menus', 'priority' => 30, 'description' => $description, ) ); $choices = array( '0' => __( '&mdash; Select &mdash;' ) ); foreach ( $menus as $menu ) { $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' ); } // Attempt to re-map the nav menu location assignments when previewing a theme switch. $mapped_nav_menu_locations = array(); if ( ! $this->manager->is_theme_active() ) { $theme_mods = get_option( 'theme_mods_' . $this->manager->get_stylesheet(), array() ); // If there is no data from a previous activation, start fresh. if ( empty( $theme_mods['nav_menu_locations'] ) ) { $theme_mods['nav_menu_locations'] = array(); } $mapped_nav_menu_locations = wp_map_nav_menu_locations( $theme_mods['nav_menu_locations'], $this->original_nav_menu_locations ); } foreach ( $locations as $location => $description ) { $setting_id = "nav_menu_locations[{$location}]"; $setting = $this->manager->get_setting( $setting_id ); if ( $setting ) { $setting->transport = 'postMessage'; remove_filter( "customize_sanitize_{$setting_id}", 'absint' ); add_filter( "customize_sanitize_{$setting_id}", array( $this, 'intval_base10' ) ); } else { $this->manager->add_setting( $setting_id, array( 'sanitize_callback' => array( $this, 'intval_base10' ), 'theme_supports' => 'menus', 'type' => 'theme_mod', 'transport' => 'postMessage', 'default' => 0, ) ); } // Override the assigned nav menu location if mapped during previewed theme switch. if ( empty( $changeset[ $setting_id ] ) && isset( $mapped_nav_menu_locations[ $location ] ) ) { $this->manager->set_post_value( $setting_id, $mapped_nav_menu_locations[ $location ] ); } $this->manager->add_control( new WP_Customize_Nav_Menu_Location_Control( $this->manager, $setting_id, array( 'label' => $description, 'location_id' => $location, 'section' => 'menu_locations', 'choices' => $choices, ) ) ); } // Used to denote post states for special pages. if ( ! function_exists( 'get_post_states' ) ) { require_once ABSPATH . 'wp-admin/includes/template.php'; } // Register each menu as a Customizer section, and add each menu item to each menu. foreach ( $menus as $menu ) { $menu_id = $menu->term_id; // Create a section for each menu. $section_id = 'nav_menu[' . $menu_id . ']'; $this->manager->add_section( new WP_Customize_Nav_Menu_Section( $this->manager, $section_id, array( 'title' => html_entity_decode( $menu->name, ENT_QUOTES, get_bloginfo( 'charset' ) ), 'priority' => 10, 'panel' => 'nav_menus', ) ) ); $nav_menu_setting_id = 'nav_menu[' . $menu_id . ']'; $this->manager->add_setting( new WP_Customize_Nav_Menu_Setting( $this->manager, $nav_menu_setting_id, array( 'transport' => 'postMessage', ) ) ); // Add the menu contents. $menu_items = (array) wp_get_nav_menu_items( $menu_id ); foreach ( array_values( $menu_items ) as $i => $item ) { // Create a setting for each menu item (which doesn't actually manage data, currently). $menu_item_setting_id = 'nav_menu_item[' . $item->ID . ']'; $value = (array) $item; if ( empty( $value['post_title'] ) ) { $value['title'] = ''; } $value['nav_menu_term_id'] = $menu_id; $this->manager->add_setting( new WP_Customize_Nav_Menu_Item_Setting( $this->manager, $menu_item_setting_id, array( 'value' => $value, 'transport' => 'postMessage', ) ) ); // Create a control for each menu item. $this->manager->add_control( new WP_Customize_Nav_Menu_Item_Control( $this->manager, $menu_item_setting_id, array( 'label' => $item->title, 'section' => $section_id, 'priority' => 10 + $i, ) ) ); } // Note: other controls inside of this section get added dynamically in JS via the MenuSection.ready() function. } // Add the add-new-menu section and controls. $this->manager->add_section( 'add_menu', array( 'type' => 'new_menu', 'title' => __( 'New Menu' ), 'panel' => 'nav_menus', 'priority' => 20, ) ); $this->manager->add_setting( new WP_Customize_Filter_Setting( $this->manager, 'nav_menus_created_posts', array( 'transport' => 'postMessage', 'type' => 'option', // To prevent theme prefix in changeset. 'default' => array(), 'sanitize_callback' => array( $this, 'sanitize_nav_menus_created_posts' ), ) ) ); } ``` | Uses | Description | | --- | --- | | [wp\_map\_nav\_menu\_locations()](../../functions/wp_map_nav_menu_locations) wp-includes/nav-menu.php | Maps nav menu locations according to assignments in previously active theme. | | [WP\_Customize\_Nav\_Menu\_Item\_Control::\_\_construct()](../wp_customize_nav_menu_item_control/__construct) wp-includes/customize/class-wp-customize-nav-menu-item-control.php | Constructor. | | [wp\_get\_nav\_menu\_items()](../../functions/wp_get_nav_menu_items) wp-includes/nav-menu.php | Retrieves all menu items of a navigation menu. | | [wp\_get\_nav\_menus()](../../functions/wp_get_nav_menus) wp-includes/nav-menu.php | Returns all navigation menu objects. | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [wp\_html\_excerpt()](../../functions/wp_html_excerpt) wp-includes/formatting.php | Safely extracts not more than the first $count characters from HTML string. | | [WP\_Customize\_Nav\_Menu\_Item\_Setting::\_\_construct()](../wp_customize_nav_menu_item_setting/__construct) wp-includes/customize/class-wp-customize-nav-menu-item-setting.php | Constructor. | | [\_n()](../../functions/_n) wp-includes/l10n.php | Translates and retrieves the singular or plural form based on the supplied number. | | [WP\_Customize\_Nav\_Menu\_Setting::\_\_construct()](../wp_customize_nav_menu_setting/__construct) wp-includes/customize/class-wp-customize-nav-menu-setting.php | Constructor. | | [get\_registered\_nav\_menus()](../../functions/get_registered_nav_menus) wp-includes/nav-menu.php | Retrieves all registered navigation menu locations in a theme. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | [number\_format\_i18n()](../../functions/number_format_i18n) wp-includes/functions.php | Converts float number to format based on the locale. | | [current\_theme\_supports()](../../functions/current_theme_supports) wp-includes/theme.php | Checks a theme’s support for a given feature. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::print_templates() WP\_Customize\_Nav\_Menus::print\_templates() ============================================= Prints the JavaScript templates used to render Menu Customizer components. Templates are imported into the JS use wp.template. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function print_templates() { ?> <script type="text/html" id="tmpl-available-menu-item"> <li id="menu-item-tpl-{{ data.id }}" class="menu-item-tpl" data-menu-item-id="{{ data.id }}"> <div class="menu-item-bar"> <div class="menu-item-handle"> <span class="item-type" aria-hidden="true">{{ data.type_label }}</span> <span class="item-title" aria-hidden="true"> <span class="menu-item-title<# if ( ! data.title ) { #> no-title<# } #>">{{ data.title || wp.customize.Menus.data.l10n.untitled }}</span> </span> <button type="button" class="button-link item-add"> <span class="screen-reader-text"> <?php /* translators: 1: Title of a menu item, 2: Type of a menu item. */ printf( __( 'Add to menu: %1$s (%2$s)' ), '{{ data.title || wp.customize.Menus.data.l10n.untitled }}', '{{ data.type_label }}' ); ?> </span> </button> </div> </div> </li> </script> <script type="text/html" id="tmpl-menu-item-reorder-nav"> <div class="menu-item-reorder-nav"> <?php printf( '<button type="button" class="menus-move-up">%1$s</button><button type="button" class="menus-move-down">%2$s</button><button type="button" class="menus-move-left">%3$s</button><button type="button" class="menus-move-right">%4$s</button>', __( 'Move up' ), __( 'Move down' ), __( 'Move one level up' ), __( 'Move one level down' ) ); ?> </div> </script> <script type="text/html" id="tmpl-nav-menu-delete-button"> <div class="menu-delete-item"> <button type="button" class="button-link button-link-delete"> <?php _e( 'Delete Menu' ); ?> </button> </div> </script> <script type="text/html" id="tmpl-nav-menu-submit-new-button"> <p id="customize-new-menu-submit-description"><?php _e( 'Click &#8220;Next&#8221; to start adding links to your new menu.' ); ?></p> <button id="customize-new-menu-submit" type="button" class="button" aria-describedby="customize-new-menu-submit-description"><?php _e( 'Next' ); ?></button> </script> <script type="text/html" id="tmpl-nav-menu-locations-header"> <span class="customize-control-title customize-section-title-menu_locations-heading">{{ data.l10n.locationsTitle }}</span> <p class="customize-control-description customize-section-title-menu_locations-description">{{ data.l10n.locationsDescription }}</p> </script> <script type="text/html" id="tmpl-nav-menu-create-menu-section-title"> <p class="add-new-menu-notice"> <?php _e( 'It does not look like your site has any menus yet. Want to build one? Click the button to start.' ); ?> </p> <p class="add-new-menu-notice"> <?php _e( 'You&#8217;ll create a menu, assign it a location, and add menu items like links to pages and categories. If your theme has multiple menu areas, you might need to create more than one.' ); ?> </p> <h3> <button type="button" class="button customize-add-menu-button"> <?php _e( 'Create New Menu' ); ?> </button> </h3> </script> <?php } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::filter_dynamic_setting_class( string $setting_class, string $setting_id, array $setting_args ): string WP\_Customize\_Nav\_Menus::filter\_dynamic\_setting\_class( string $setting\_class, string $setting\_id, array $setting\_args ): string ======================================================================================================================================= Allows non-statically created settings to be constructed with custom [WP\_Customize\_Setting](../wp_customize_setting) subclass. `$setting_class` string Required [WP\_Customize\_Setting](../wp_customize_setting) or a subclass. `$setting_id` string Required ID for dynamic setting, usually coming from `$_POST['customized']`. `$setting_args` array Required [WP\_Customize\_Setting](../wp_customize_setting) or a subclass. string File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function filter_dynamic_setting_class( $setting_class, $setting_id, $setting_args ) { unset( $setting_id ); if ( ! empty( $setting_args['type'] ) && WP_Customize_Nav_Menu_Setting::TYPE === $setting_args['type'] ) { $setting_class = 'WP_Customize_Nav_Menu_Setting'; } elseif ( ! empty( $setting_args['type'] ) && WP_Customize_Nav_Menu_Item_Setting::TYPE === $setting_args['type'] ) { $setting_class = 'WP_Customize_Nav_Menu_Item_Setting'; } return $setting_class; } ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::available_items_template() WP\_Customize\_Nav\_Menus::available\_items\_template() ======================================================= Prints the HTML template used to render the add-menu-item frame. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function available_items_template() { ?> <div id="available-menu-items" class="accordion-container"> <div class="customize-section-title"> <button type="button" class="customize-section-back" tabindex="-1"> <span class="screen-reader-text"><?php _e( 'Back' ); ?></span> </button> <h3> <span class="customize-action"> <?php /* translators: &#9656; is the unicode right-pointing triangle. %s: Section title in the Customizer. */ printf( __( 'Customizing &#9656; %s' ), esc_html( $this->manager->get_panel( 'nav_menus' )->title ) ); ?> </span> <?php _e( 'Add Menu Items' ); ?> </h3> </div> <div id="available-menu-items-search" class="accordion-section cannot-expand"> <div class="accordion-section-title"> <label class="screen-reader-text" for="menu-items-search"><?php _e( 'Search Menu Items' ); ?></label> <input type="text" id="menu-items-search" placeholder="<?php esc_attr_e( 'Search menu items&hellip;' ); ?>" aria-describedby="menu-items-search-desc" /> <p class="screen-reader-text" id="menu-items-search-desc"><?php _e( 'The search results will be updated as you type.' ); ?></p> <span class="spinner"></span> </div> <div class="search-icon" aria-hidden="true"></div> <button type="button" class="clear-results"><span class="screen-reader-text"><?php _e( 'Clear Results' ); ?></span></button> <ul class="accordion-section-content available-menu-items-list" data-type="search"></ul> </div> <?php // Ensure the page post type comes first in the list. $item_types = $this->available_item_types(); $page_item_type = null; foreach ( $item_types as $i => $item_type ) { if ( isset( $item_type['object'] ) && 'page' === $item_type['object'] ) { $page_item_type = $item_type; unset( $item_types[ $i ] ); } } $this->print_custom_links_available_menu_item(); if ( $page_item_type ) { $this->print_post_type_container( $page_item_type ); } // Containers for per-post-type item browsing; items are added with JS. foreach ( $item_types as $item_type ) { $this->print_post_type_container( $item_type ); } ?> </div><!-- #available-menu-items --> <?php } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::print\_custom\_links\_available\_menu\_item()](print_custom_links_available_menu_item) wp-includes/class-wp-customize-nav-menus.php | Prints the markup for available menu item custom links. | | [WP\_Customize\_Nav\_Menus::print\_post\_type\_container()](print_post_type_container) wp-includes/class-wp-customize-nav-menus.php | Prints the markup for new menu items. | | [WP\_Customize\_Nav\_Menus::available\_item\_types()](available_item_types) wp-includes/class-wp-customize-nav-menus.php | Returns an array of all the available item types. | | [esc\_attr\_e()](../../functions/esc_attr_e) wp-includes/l10n.php | Displays translated text that has been escaped for safe use in an attribute. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |
programming_docs
wordpress WP_Customize_Nav_Menus::filter_wp_nav_menu_args( array $args ): array WP\_Customize\_Nav\_Menus::filter\_wp\_nav\_menu\_args( array $args ): array ============================================================================ Keeps track of the arguments that are being passed to [wp\_nav\_menu()](../../functions/wp_nav_menu) . * [wp\_nav\_menu()](../../functions/wp_nav_menu) * [WP\_Customize\_Widgets::filter\_dynamic\_sidebar\_params()](../wp_customize_widgets/filter_dynamic_sidebar_params) `$args` array Required An array containing [wp\_nav\_menu()](../../functions/wp_nav_menu) arguments. More Arguments from wp\_nav\_menu( ... $args ) Array of nav menu arguments. * `menu`int|string|[WP\_Term](../wp_term)Desired menu. Accepts a menu ID, slug, name, or object. * `menu_class`stringCSS class to use for the ul element which forms the menu. Default `'menu'`. * `menu_id`stringThe ID that is applied to the ul element which forms the menu. Default is the menu slug, incremented. * `container`stringWhether to wrap the ul, and what to wrap it with. Default `'div'`. * `container_class`stringClass that is applied to the container. Default 'menu-{menu slug}-container'. * `container_id`stringThe ID that is applied to the container. * `container_aria_label`stringThe aria-label attribute that is applied to the container when it's a nav element. * `fallback_cb`callable|falseIf the menu doesn't exist, a callback function will fire. Default is `'wp_page_menu'`. Set to false for no fallback. * `before`stringText before the link markup. * `after`stringText after the link markup. * `link_before`stringText before the link text. * `link_after`stringText after the link text. * `echo`boolWhether to echo the menu or return it. Default true. * `depth`intHow many levels of the hierarchy are to be included. 0 means all. Default 0. Default 0. * `walker`objectInstance of a custom walker class. * `theme_location`stringTheme location to be used. Must be registered with [register\_nav\_menu()](../../functions/register_nav_menu) in order to be selectable by the user. * `items_wrap`stringHow the list items should be wrapped. Uses printf() format with numbered placeholders. Default is a ul with an id and class. * `item_spacing`stringWhether to preserve whitespace within the menu's HTML. Accepts `'preserve'` or `'discard'`. Default `'preserve'`. array Arguments. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function filter_wp_nav_menu_args( $args ) { /* * The following conditions determine whether or not this instance of * wp_nav_menu() can use selective refreshed. A wp_nav_menu() can be * selective refreshed if... */ $can_partial_refresh = ( // ...if wp_nav_menu() is directly echoing out the menu (and thus isn't manipulating the string after generated), ! empty( $args['echo'] ) && // ...and if the fallback_cb can be serialized to JSON, since it will be included in the placement context data, ( empty( $args['fallback_cb'] ) || is_string( $args['fallback_cb'] ) ) && // ...and if the walker can also be serialized to JSON, since it will be included in the placement context data as well, ( empty( $args['walker'] ) || is_string( $args['walker'] ) ) // ...and if it has a theme location assigned or an assigned menu to display, && ( ! empty( $args['theme_location'] ) || ( ! empty( $args['menu'] ) && ( is_numeric( $args['menu'] ) || is_object( $args['menu'] ) ) ) ) && // ...and if the nav menu would be rendered with a wrapper container element (upon which to attach data-* attributes). ( ! empty( $args['container'] ) || ( isset( $args['items_wrap'] ) && '<' === substr( $args['items_wrap'], 0, 1 ) ) ) ); $args['can_partial_refresh'] = $can_partial_refresh; $exported_args = $args; // Empty out args which may not be JSON-serializable. if ( ! $can_partial_refresh ) { $exported_args['fallback_cb'] = ''; $exported_args['walker'] = ''; } /* * Replace object menu arg with a term_id menu arg, as this exports better * to JS and is easier to compare hashes. */ if ( ! empty( $exported_args['menu'] ) && is_object( $exported_args['menu'] ) ) { $exported_args['menu'] = $exported_args['menu']->term_id; } ksort( $exported_args ); $exported_args['args_hmac'] = $this->hash_nav_menu_args( $exported_args ); $args['customize_preview_nav_menus_args'] = $exported_args; $this->preview_nav_menu_instance_args[ $exported_args['args_hmac'] ] = $exported_args; return $args; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::hash\_nav\_menu\_args()](../wp_customize_nav_menus/hash_nav_menu_args) wp-includes/class-wp-customize-nav-menus.php | Hashes (hmac) the nav menu arguments to ensure they are not tampered with when submitted in the Ajax request. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::export_preview_data() WP\_Customize\_Nav\_Menus::export\_preview\_data() ================================================== Exports data from PHP to JS. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function export_preview_data() { // Why not wp_localize_script? Because we're not localizing, and it forces values into strings. $exports = array( 'navMenuInstanceArgs' => $this->preview_nav_menu_instance_args, ); printf( '<script>var _wpCustomizePreviewNavMenusExports = %s;</script>', wp_json_encode( $exports ) ); } ``` | Uses | Description | | --- | --- | | [wp\_json\_encode()](../../functions/wp_json_encode) wp-includes/functions.php | Encodes a variable into JSON, with some sanity checks. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::print_custom_links_available_menu_item() WP\_Customize\_Nav\_Menus::print\_custom\_links\_available\_menu\_item() ======================================================================== Prints the markup for available menu item custom links. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` protected function print_custom_links_available_menu_item() { ?> <div id="new-custom-menu-item" class="accordion-section"> <h4 class="accordion-section-title" role="presentation"> <?php _e( 'Custom Links' ); ?> <button type="button" class="button-link" aria-expanded="false"> <span class="screen-reader-text"><?php _e( 'Toggle section: Custom Links' ); ?></span> <span class="toggle-indicator" aria-hidden="true"></span> </button> </h4> <div class="accordion-section-content customlinkdiv"> <input type="hidden" value="custom" id="custom-menu-item-type" name="menu-item[-1][menu-item-type]" /> <p id="menu-item-url-wrap" class="wp-clearfix"> <label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label> <input id="custom-menu-item-url" name="menu-item[-1][menu-item-url]" type="text" class="code menu-item-textbox" placeholder="https://"> </p> <p id="menu-item-name-wrap" class="wp-clearfix"> <label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label> <input id="custom-menu-item-name" name="menu-item[-1][menu-item-title]" type="text" class="regular-text menu-item-textbox"> </p> <p class="button-controls"> <span class="add-to-menu"> <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu' ); ?>" name="add-custom-menu-item" id="custom-menu-item-submit"> <span class="spinner"></span> </span> </p> </div> </div> <?php } ``` | Uses | Description | | --- | --- | | [esc\_attr\_e()](../../functions/esc_attr_e) wp-includes/l10n.php | Displays translated text that has been escaped for safe use in an attribute. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::available\_items\_template()](available_items_template) wp-includes/class-wp-customize-nav-menus.php | Prints the HTML template used to render the add-menu-item frame. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::customize_preview_enqueue_deps() WP\_Customize\_Nav\_Menus::customize\_preview\_enqueue\_deps() ============================================================== Enqueues scripts for the Customizer preview. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function customize_preview_enqueue_deps() { wp_enqueue_script( 'customize-preview-nav-menus' ); // Note that we have overridden this. } ``` | Uses | Description | | --- | --- | | [wp\_enqueue\_script()](../../functions/wp_enqueue_script) wp-includes/functions.wp-scripts.php | Enqueue a script. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::customize_preview_init() WP\_Customize\_Nav\_Menus::customize\_preview\_init() ===================================================== Adds hooks for the Customizer preview. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function customize_preview_init() { add_action( 'wp_enqueue_scripts', array( $this, 'customize_preview_enqueue_deps' ) ); add_filter( 'wp_nav_menu_args', array( $this, 'filter_wp_nav_menu_args' ), 1000 ); add_filter( 'wp_nav_menu', array( $this, 'filter_wp_nav_menu' ), 10, 2 ); add_action( 'wp_footer', array( $this, 'export_preview_data' ), 1 ); add_filter( 'customize_render_partials_response', array( $this, 'export_partial_rendered_nav_menu_instances' ) ); } ``` | Uses | Description | | --- | --- | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::sanitize_nav_menus_created_posts( array $value ): array WP\_Customize\_Nav\_Menus::sanitize\_nav\_menus\_created\_posts( array $value ): array ====================================================================================== Sanitizes post IDs for posts created for nav menu items to be published. `$value` array Required Post IDs. array Post IDs. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function sanitize_nav_menus_created_posts( $value ) { $post_ids = array(); foreach ( wp_parse_id_list( $value ) as $post_id ) { if ( empty( $post_id ) ) { continue; } $post = get_post( $post_id ); if ( 'auto-draft' !== $post->post_status && 'draft' !== $post->post_status ) { continue; } $post_type_obj = get_post_type_object( $post->post_type ); if ( ! $post_type_obj ) { continue; } if ( ! current_user_can( $post_type_obj->cap->publish_posts ) || ! current_user_can( 'edit_post', $post_id ) ) { continue; } $post_ids[] = $post->ID; } return $post_ids; } ``` | Uses | Description | | --- | --- | | [wp\_parse\_id\_list()](../../functions/wp_parse_id_list) wp-includes/functions.php | Cleans up an array, comma- or space-separated list of IDs. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::filter_wp_nav_menu( string $nav_menu_content, object $args ): string WP\_Customize\_Nav\_Menus::filter\_wp\_nav\_menu( string $nav\_menu\_content, object $args ): string ==================================================================================================== Prepares [wp\_nav\_menu()](../../functions/wp_nav_menu) calls for partial refresh. Injects attributes into container element. * [wp\_nav\_menu()](../../functions/wp_nav_menu) `$nav_menu_content` string Required The HTML content for the navigation menu. `$args` object Required An object containing [wp\_nav\_menu()](../../functions/wp_nav_menu) arguments. More Arguments from wp\_nav\_menu( ... $args ) Array of nav menu arguments. * `menu`int|string|[WP\_Term](../wp_term)Desired menu. Accepts a menu ID, slug, name, or object. * `menu_class`stringCSS class to use for the ul element which forms the menu. Default `'menu'`. * `menu_id`stringThe ID that is applied to the ul element which forms the menu. Default is the menu slug, incremented. * `container`stringWhether to wrap the ul, and what to wrap it with. Default `'div'`. * `container_class`stringClass that is applied to the container. Default 'menu-{menu slug}-container'. * `container_id`stringThe ID that is applied to the container. * `container_aria_label`stringThe aria-label attribute that is applied to the container when it's a nav element. * `fallback_cb`callable|falseIf the menu doesn't exist, a callback function will fire. Default is `'wp_page_menu'`. Set to false for no fallback. * `before`stringText before the link markup. * `after`stringText after the link markup. * `link_before`stringText before the link text. * `link_after`stringText after the link text. * `echo`boolWhether to echo the menu or return it. Default true. * `depth`intHow many levels of the hierarchy are to be included. 0 means all. Default 0. Default 0. * `walker`objectInstance of a custom walker class. * `theme_location`stringTheme location to be used. Must be registered with [register\_nav\_menu()](../../functions/register_nav_menu) in order to be selectable by the user. * `items_wrap`stringHow the list items should be wrapped. Uses printf() format with numbered placeholders. Default is a ul with an id and class. * `item_spacing`stringWhether to preserve whitespace within the menu's HTML. Accepts `'preserve'` or `'discard'`. Default `'preserve'`. string Nav menu HTML with selective refresh attributes added if partial can be refreshed. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function filter_wp_nav_menu( $nav_menu_content, $args ) { if ( isset( $args->customize_preview_nav_menus_args['can_partial_refresh'] ) && $args->customize_preview_nav_menus_args['can_partial_refresh'] ) { $attributes = sprintf( ' data-customize-partial-id="%s"', esc_attr( 'nav_menu_instance[' . $args->customize_preview_nav_menus_args['args_hmac'] . ']' ) ); $attributes .= ' data-customize-partial-type="nav_menu_instance"'; $attributes .= sprintf( ' data-customize-partial-placement-context="%s"', esc_attr( wp_json_encode( $args->customize_preview_nav_menus_args ) ) ); $nav_menu_content = preg_replace( '#^(<\w+)#', '$1 ' . str_replace( '\\', '\\\\', $attributes ), $nav_menu_content, 1 ); } return $nav_menu_content; } ``` | Uses | Description | | --- | --- | | [wp\_json\_encode()](../../functions/wp_json_encode) wp-includes/functions.php | Encodes a variable into JSON, with some sanity checks. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::export_partial_rendered_nav_menu_instances( array $response ): array WP\_Customize\_Nav\_Menus::export\_partial\_rendered\_nav\_menu\_instances( array $response ): array ==================================================================================================== Exports any [wp\_nav\_menu()](../../functions/wp_nav_menu) calls during the rendering of any partials. `$response` array Required Response. array Response. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function export_partial_rendered_nav_menu_instances( $response ) { $response['nav_menu_instance_args'] = $this->preview_nav_menu_instance_args; return $response; } ``` | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::intval_base10( mixed $value ): int WP\_Customize\_Nav\_Menus::intval\_base10( mixed $value ): int ============================================================== Gets the base10 intval. This is used as a setting’s sanitize\_callback; we can’t use just plain intval because the second argument is not what intval() expects. `$value` mixed Required Number to convert. int Integer. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function intval_base10( $value ) { return intval( $value, 10 ); } ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::make_auto_draft_status_previewable() WP\_Customize\_Nav\_Menus::make\_auto\_draft\_status\_previewable() =================================================================== Makes the auto-draft status protected so that it can be queried. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function make_auto_draft_status_previewable() { global $wp_post_statuses; $wp_post_statuses['auto-draft']->protected = true; } ``` | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::ajax_search_available_items() WP\_Customize\_Nav\_Menus::ajax\_search\_available\_items() =========================================================== Ajax handler for searching available menu items. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function ajax_search_available_items() { check_ajax_referer( 'customize-menus', 'customize-menus-nonce' ); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); } if ( empty( $_POST['search'] ) ) { wp_send_json_error( 'nav_menus_missing_search_parameter' ); } $p = isset( $_POST['page'] ) ? absint( $_POST['page'] ) : 0; if ( $p < 1 ) { $p = 1; } $s = sanitize_text_field( wp_unslash( $_POST['search'] ) ); $items = $this->search_available_items_query( array( 'pagenum' => $p, 's' => $s, ) ); if ( empty( $items ) ) { wp_send_json_error( array( 'message' => __( 'No results found.' ) ) ); } else { wp_send_json_success( array( 'items' => $items ) ); } } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::search\_available\_items\_query()](search_available_items_query) wp-includes/class-wp-customize-nav-menus.php | Performs post queries for available-item searching. | | [sanitize\_text\_field()](../../functions/sanitize_text_field) wp-includes/formatting.php | Sanitizes a string from user input or from the database. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [check\_ajax\_referer()](../../functions/check_ajax_referer) wp-includes/pluggable.php | Verifies the Ajax request to prevent processing requests external of the blog. | | [wp\_send\_json\_error()](../../functions/wp_send_json_error) wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating failure. | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | [wp\_send\_json\_success()](../../functions/wp_send_json_success) wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating success. | | [wp\_die()](../../functions/wp_die) wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |
programming_docs
wordpress WP_Customize_Nav_Menus::__construct( WP_Customize_Manager $manager ) WP\_Customize\_Nav\_Menus::\_\_construct( WP\_Customize\_Manager $manager ) =========================================================================== Constructor. `$manager` [WP\_Customize\_Manager](../wp_customize_manager) Required Customizer bootstrap instance. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function __construct( $manager ) { $this->manager = $manager; $this->original_nav_menu_locations = get_nav_menu_locations(); // See https://github.com/xwp/wp-customize-snapshots/blob/962586659688a5b1fd9ae93618b7ce2d4e7a421c/php/class-customize-snapshot-manager.php#L469-L499 add_action( 'customize_register', array( $this, 'customize_register' ), 11 ); add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_dynamic_setting_args' ), 10, 2 ); add_filter( 'customize_dynamic_setting_class', array( $this, 'filter_dynamic_setting_class' ), 10, 3 ); add_action( 'customize_save_nav_menus_created_posts', array( $this, 'save_nav_menus_created_posts' ) ); // Skip remaining hooks when the user can't manage nav menus anyway. if ( ! current_user_can( 'edit_theme_options' ) ) { return; } add_filter( 'customize_refresh_nonces', array( $this, 'filter_nonces' ) ); add_action( 'wp_ajax_load-available-menu-items-customizer', array( $this, 'ajax_load_available_items' ) ); add_action( 'wp_ajax_search-available-menu-items-customizer', array( $this, 'ajax_search_available_items' ) ); add_action( 'wp_ajax_customize-nav-menus-insert-auto-draft', array( $this, 'ajax_insert_auto_draft_post' ) ); add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_templates' ) ); add_action( 'customize_controls_print_footer_scripts', array( $this, 'available_items_template' ) ); add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) ); add_action( 'customize_preview_init', array( $this, 'make_auto_draft_status_previewable' ) ); // Selective Refresh partials. add_filter( 'customize_dynamic_partial_args', array( $this, 'customize_dynamic_partial_args' ), 10, 2 ); } ``` | Uses | Description | | --- | --- | | [get\_nav\_menu\_locations()](../../functions/get_nav_menu_locations) wp-includes/nav-menu.php | Retrieves all registered navigation menu locations and the menus assigned to them. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Customize\_Manager::\_\_construct()](../wp_customize_manager/__construct) wp-includes/class-wp-customize-manager.php | Constructor. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::enqueue_scripts() WP\_Customize\_Nav\_Menus::enqueue\_scripts() ============================================= Enqueues scripts and styles for Customizer pane. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function enqueue_scripts() { wp_enqueue_style( 'customize-nav-menus' ); wp_enqueue_script( 'customize-nav-menus' ); $temp_nav_menu_setting = new WP_Customize_Nav_Menu_Setting( $this->manager, 'nav_menu[-1]' ); $temp_nav_menu_item_setting = new WP_Customize_Nav_Menu_Item_Setting( $this->manager, 'nav_menu_item[-1]' ); $num_locations = count( get_registered_nav_menus() ); if ( 1 === $num_locations ) { $locations_description = __( 'Your theme can display menus in one location.' ); } else { /* translators: %s: Number of menu locations. */ $locations_description = sprintf( _n( 'Your theme can display menus in %s location.', 'Your theme can display menus in %s locations.', $num_locations ), number_format_i18n( $num_locations ) ); } // Pass data to JS. $settings = array( 'allMenus' => wp_get_nav_menus(), 'itemTypes' => $this->available_item_types(), 'l10n' => array( 'untitled' => _x( '(no label)', 'missing menu item navigation label' ), 'unnamed' => _x( '(unnamed)', 'Missing menu name.' ), 'custom_label' => __( 'Custom Link' ), 'page_label' => get_post_type_object( 'page' )->labels->singular_name, /* translators: %s: Menu location. */ 'menuLocation' => _x( '(Currently set to: %s)', 'menu' ), 'locationsTitle' => 1 === $num_locations ? __( 'Menu Location' ) : __( 'Menu Locations' ), 'locationsDescription' => $locations_description, 'menuNameLabel' => __( 'Menu Name' ), 'newMenuNameDescription' => __( 'If your theme has multiple menus, giving them clear names will help you manage them.' ), 'itemAdded' => __( 'Menu item added' ), 'itemDeleted' => __( 'Menu item deleted' ), 'menuAdded' => __( 'Menu created' ), 'menuDeleted' => __( 'Menu deleted' ), 'movedUp' => __( 'Menu item moved up' ), 'movedDown' => __( 'Menu item moved down' ), 'movedLeft' => __( 'Menu item moved out of submenu' ), 'movedRight' => __( 'Menu item is now a sub-item' ), /* translators: &#9656; is the unicode right-pointing triangle. %s: Section title in the Customizer. */ 'customizingMenus' => sprintf( __( 'Customizing &#9656; %s' ), esc_html( $this->manager->get_panel( 'nav_menus' )->title ) ), /* translators: %s: Title of an invalid menu item. */ 'invalidTitleTpl' => __( '%s (Invalid)' ), /* translators: %s: Title of a menu item in draft status. */ 'pendingTitleTpl' => __( '%s (Pending)' ), /* translators: %d: Number of menu items found. */ 'itemsFound' => __( 'Number of items found: %d' ), /* translators: %d: Number of additional menu items found. */ 'itemsFoundMore' => __( 'Additional items found: %d' ), 'itemsLoadingMore' => __( 'Loading more results... please wait.' ), 'reorderModeOn' => __( 'Reorder mode enabled' ), 'reorderModeOff' => __( 'Reorder mode closed' ), 'reorderLabelOn' => esc_attr__( 'Reorder menu items' ), 'reorderLabelOff' => esc_attr__( 'Close reorder mode' ), ), 'settingTransport' => 'postMessage', 'phpIntMax' => PHP_INT_MAX, 'defaultSettingValues' => array( 'nav_menu' => $temp_nav_menu_setting->default, 'nav_menu_item' => $temp_nav_menu_item_setting->default, ), 'locationSlugMappedToName' => get_registered_nav_menus(), ); $data = sprintf( 'var _wpCustomizeNavMenusSettings = %s;', wp_json_encode( $settings ) ); wp_scripts()->add_data( 'customize-nav-menus', 'data', $data ); // This is copied from nav-menus.php, and it has an unfortunate object name of `menus`. $nav_menus_l10n = array( 'oneThemeLocationNoMenus' => null, 'moveUp' => __( 'Move up one' ), 'moveDown' => __( 'Move down one' ), 'moveToTop' => __( 'Move to the top' ), /* translators: %s: Previous item name. */ 'moveUnder' => __( 'Move under %s' ), /* translators: %s: Previous item name. */ 'moveOutFrom' => __( 'Move out from under %s' ), /* translators: %s: Previous item name. */ 'under' => __( 'Under %s' ), /* translators: %s: Previous item name. */ 'outFrom' => __( 'Out from under %s' ), /* translators: 1: Item name, 2: Item position, 3: Total number of items. */ 'menuFocus' => __( '%1$s. Menu item %2$d of %3$d.' ), /* translators: 1: Item name, 2: Item position, 3: Parent item name. */ 'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ), ); wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n ); } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Nav\_Menu\_Setting::\_\_construct()](../wp_customize_nav_menu_setting/__construct) wp-includes/customize/class-wp-customize-nav-menu-setting.php | Constructor. | | [WP\_Customize\_Nav\_Menu\_Item\_Setting::\_\_construct()](../wp_customize_nav_menu_item_setting/__construct) wp-includes/customize/class-wp-customize-nav-menu-item-setting.php | Constructor. | | [wp\_get\_nav\_menus()](../../functions/wp_get_nav_menus) wp-includes/nav-menu.php | Returns all navigation menu objects. | | [wp\_enqueue\_style()](../../functions/wp_enqueue_style) wp-includes/functions.wp-styles.php | Enqueue a CSS stylesheet. | | [wp\_localize\_script()](../../functions/wp_localize_script) wp-includes/functions.wp-scripts.php | Localize a script. | | [wp\_enqueue\_script()](../../functions/wp_enqueue_script) wp-includes/functions.wp-scripts.php | Enqueue a script. | | [esc\_attr\_\_()](../../functions/esc_attr__) wp-includes/l10n.php | Retrieves the translation of $text and escapes it for safe use in an attribute. | | [wp\_scripts()](../../functions/wp_scripts) wp-includes/functions.wp-scripts.php | Initialize $wp\_scripts if it has not been set. | | [\_n()](../../functions/_n) wp-includes/l10n.php | Translates and retrieves the singular or plural form based on the supplied number. | | [WP\_Customize\_Nav\_Menus::available\_item\_types()](available_item_types) wp-includes/class-wp-customize-nav-menus.php | Returns an array of all the available item types. | | [get\_registered\_nav\_menus()](../../functions/get_registered_nav_menus) wp-includes/nav-menu.php | Retrieves all registered navigation menu locations in a theme. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_json\_encode()](../../functions/wp_json_encode) wp-includes/functions.php | Encodes a variable into JSON, with some sanity checks. | | [number\_format\_i18n()](../../functions/number_format_i18n) wp-includes/functions.php | Converts float number to format based on the locale. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::render_nav_menu_partial( WP_Customize_Partial $partial, array $nav_menu_args ): string|false WP\_Customize\_Nav\_Menus::render\_nav\_menu\_partial( WP\_Customize\_Partial $partial, array $nav\_menu\_args ): string|false ============================================================================================================================== Renders a specific menu via [wp\_nav\_menu()](../../functions/wp_nav_menu) using the supplied arguments. * [wp\_nav\_menu()](../../functions/wp_nav_menu) `$partial` [WP\_Customize\_Partial](../wp_customize_partial) Required Partial. `$nav_menu_args` array Required Nav menu args supplied as container context. string|false File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function render_nav_menu_partial( $partial, $nav_menu_args ) { unset( $partial ); if ( ! isset( $nav_menu_args['args_hmac'] ) ) { // Error: missing_args_hmac. return false; } $nav_menu_args_hmac = $nav_menu_args['args_hmac']; unset( $nav_menu_args['args_hmac'] ); ksort( $nav_menu_args ); if ( ! hash_equals( $this->hash_nav_menu_args( $nav_menu_args ), $nav_menu_args_hmac ) ) { // Error: args_hmac_mismatch. return false; } ob_start(); wp_nav_menu( $nav_menu_args ); $content = ob_get_clean(); return $content; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::hash\_nav\_menu\_args()](hash_nav_menu_args) wp-includes/class-wp-customize-nav-menus.php | Hashes (hmac) the nav menu arguments to ensure they are not tampered with when submitted in the Ajax request. | | [wp\_nav\_menu()](../../functions/wp_nav_menu) wp-includes/nav-menu-template.php | Displays a navigation menu. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::filter_nonces( string[] $nonces ): string[] WP\_Customize\_Nav\_Menus::filter\_nonces( string[] $nonces ): string[] ======================================================================= Adds a nonce for customizing menus. `$nonces` string[] Required Array of nonces. string[] Modified array of nonces. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function filter_nonces( $nonces ) { $nonces['customize-menus'] = wp_create_nonce( 'customize-menus' ); return $nonces; } ``` | Uses | Description | | --- | --- | | [wp\_create\_nonce()](../../functions/wp_create_nonce) wp-includes/pluggable.php | Creates a cryptographic token tied to a specific action, user, user session, and window of time. | | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::hash_nav_menu_args( array $args ): string WP\_Customize\_Nav\_Menus::hash\_nav\_menu\_args( array $args ): string ======================================================================= Hashes (hmac) the nav menu arguments to ensure they are not tampered with when submitted in the Ajax request. Note that the array is expected to be pre-sorted. `$args` array Required The arguments to hash. string Hashed nav menu arguments. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function hash_nav_menu_args( $args ) { return wp_hash( serialize( $args ) ); } ``` | Uses | Description | | --- | --- | | [wp\_hash()](../../functions/wp_hash) wp-includes/pluggable.php | Gets hash of given string. | | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::render\_nav\_menu\_partial()](render_nav_menu_partial) wp-includes/class-wp-customize-nav-menus.php | Renders a specific menu via [wp\_nav\_menu()](../../functions/wp_nav_menu) using the supplied arguments. | | [WP\_Customize\_Nav\_Menus::filter\_wp\_nav\_menu\_args()](filter_wp_nav_menu_args) wp-includes/class-wp-customize-nav-menus.php | Keeps track of the arguments that are being passed to [wp\_nav\_menu()](../../functions/wp_nav_menu) . | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::print_post_type_container( array $available_item_type ) WP\_Customize\_Nav\_Menus::print\_post\_type\_container( array $available\_item\_type ) ======================================================================================= Prints the markup for new menu items. To be used in the template #available-menu-items. `$available_item_type` array Required Menu item data to output, including title, type, and label. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` protected function print_post_type_container( $available_item_type ) { $id = sprintf( 'available-menu-items-%s-%s', $available_item_type['type'], $available_item_type['object'] ); ?> <div id="<?php echo esc_attr( $id ); ?>" class="accordion-section"> <h4 class="accordion-section-title" role="presentation"> <?php echo esc_html( $available_item_type['title'] ); ?> <span class="spinner"></span> <span class="no-items"><?php _e( 'No items' ); ?></span> <button type="button" class="button-link" aria-expanded="false"> <span class="screen-reader-text"> <?php /* translators: %s: Title of a section with menu items. */ printf( __( 'Toggle section: %s' ), esc_html( $available_item_type['title'] ) ); ?> </span> <span class="toggle-indicator" aria-hidden="true"></span> </button> </h4> <div class="accordion-section-content"> <?php if ( 'post_type' === $available_item_type['type'] ) : ?> <?php $post_type_obj = get_post_type_object( $available_item_type['object'] ); ?> <?php if ( current_user_can( $post_type_obj->cap->create_posts ) && current_user_can( $post_type_obj->cap->publish_posts ) ) : ?> <div class="new-content-item"> <label for="<?php echo esc_attr( 'create-item-input-' . $available_item_type['object'] ); ?>" class="screen-reader-text"><?php echo esc_html( $post_type_obj->labels->add_new_item ); ?></label> <input type="text" id="<?php echo esc_attr( 'create-item-input-' . $available_item_type['object'] ); ?>" class="create-item-input" placeholder="<?php echo esc_attr( $post_type_obj->labels->add_new_item ); ?>"> <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button> </div> <?php endif; ?> <?php endif; ?> <ul class="available-menu-items-list" data-type="<?php echo esc_attr( $available_item_type['type'] ); ?>" data-object="<?php echo esc_attr( $available_item_type['object'] ); ?>" data-type_label="<?php echo esc_attr( isset( $available_item_type['type_label'] ) ? $available_item_type['type_label'] : $available_item_type['type'] ); ?>"></ul> </div> </div> <?php } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::available\_items\_template()](available_items_template) wp-includes/class-wp-customize-nav-menus.php | Prints the HTML template used to render the add-menu-item frame. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::available_item_types(): array WP\_Customize\_Nav\_Menus::available\_item\_types(): array ========================================================== Returns an array of all the available item types. array The available menu item types. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function available_item_types() { $item_types = array(); $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' ); if ( $post_types ) { foreach ( $post_types as $slug => $post_type ) { $item_types[] = array( 'title' => $post_type->labels->name, 'type_label' => $post_type->labels->singular_name, 'type' => 'post_type', 'object' => $post_type->name, ); } } $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'objects' ); if ( $taxonomies ) { foreach ( $taxonomies as $slug => $taxonomy ) { if ( 'post_format' === $taxonomy && ! current_theme_supports( 'post-formats' ) ) { continue; } $item_types[] = array( 'title' => $taxonomy->labels->name, 'type_label' => $taxonomy->labels->singular_name, 'type' => 'taxonomy', 'object' => $taxonomy->name, ); } } /** * Filters the available menu item types. * * @since 4.3.0 * @since 4.7.0 Each array item now includes a `$type_label` in addition to `$title`, `$type`, and `$object`. * * @param array $item_types Navigation menu item types. */ $item_types = apply_filters( 'customize_nav_menu_available_item_types', $item_types ); return $item_types; } ``` [apply\_filters( 'customize\_nav\_menu\_available\_item\_types', array $item\_types )](../../hooks/customize_nav_menu_available_item_types) Filters the available menu item types. | Uses | Description | | --- | --- | | [get\_taxonomies()](../../functions/get_taxonomies) wp-includes/taxonomy.php | Retrieves a list of registered taxonomy names or objects. | | [current\_theme\_supports()](../../functions/current_theme_supports) wp-includes/theme.php | Checks a theme’s support for a given feature. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_post\_types()](../../functions/get_post_types) wp-includes/post.php | Gets a list of all registered post type objects. | | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::available\_items\_template()](available_items_template) wp-includes/class-wp-customize-nav-menus.php | Prints the HTML template used to render the add-menu-item frame. | | [WP\_Customize\_Nav\_Menus::enqueue\_scripts()](enqueue_scripts) wp-includes/class-wp-customize-nav-menus.php | Enqueues scripts and styles for Customizer pane. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Each array item now includes a `$type_label` in addition to `$title`, `$type`, and `$object`. | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |
programming_docs
wordpress WP_Customize_Nav_Menus::ajax_insert_auto_draft_post() WP\_Customize\_Nav\_Menus::ajax\_insert\_auto\_draft\_post() ============================================================ Ajax handler for adding a new auto-draft post. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function ajax_insert_auto_draft_post() { if ( ! check_ajax_referer( 'customize-menus', 'customize-menus-nonce', false ) ) { wp_send_json_error( 'bad_nonce', 400 ); } if ( ! current_user_can( 'customize' ) ) { wp_send_json_error( 'customize_not_allowed', 403 ); } if ( empty( $_POST['params'] ) || ! is_array( $_POST['params'] ) ) { wp_send_json_error( 'missing_params', 400 ); } $params = wp_unslash( $_POST['params'] ); $illegal_params = array_diff( array_keys( $params ), array( 'post_type', 'post_title' ) ); if ( ! empty( $illegal_params ) ) { wp_send_json_error( 'illegal_params', 400 ); } $params = array_merge( array( 'post_type' => '', 'post_title' => '', ), $params ); if ( empty( $params['post_type'] ) || ! post_type_exists( $params['post_type'] ) ) { status_header( 400 ); wp_send_json_error( 'missing_post_type_param' ); } $post_type_object = get_post_type_object( $params['post_type'] ); if ( ! current_user_can( $post_type_object->cap->create_posts ) || ! current_user_can( $post_type_object->cap->publish_posts ) ) { status_header( 403 ); wp_send_json_error( 'insufficient_post_permissions' ); } $params['post_title'] = trim( $params['post_title'] ); if ( '' === $params['post_title'] ) { status_header( 400 ); wp_send_json_error( 'missing_post_title' ); } $r = $this->insert_auto_draft_post( $params ); if ( is_wp_error( $r ) ) { $error = $r; if ( ! empty( $post_type_object->labels->singular_name ) ) { $singular_name = $post_type_object->labels->singular_name; } else { $singular_name = __( 'Post' ); } $data = array( /* translators: 1: Post type name, 2: Error message. */ 'message' => sprintf( __( '%1$s could not be created: %2$s' ), $singular_name, $error->get_error_message() ), ); wp_send_json_error( $data ); } else { $post = $r; $data = array( 'post_id' => $post->ID, 'url' => get_permalink( $post->ID ), ); wp_send_json_success( $data ); } } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::insert\_auto\_draft\_post()](insert_auto_draft_post) wp-includes/class-wp-customize-nav-menus.php | Adds a new `auto-draft` post. | | [status\_header()](../../functions/status_header) wp-includes/functions.php | Sets HTTP status header. | | [post\_type\_exists()](../../functions/post_type_exists) wp-includes/post.php | Determines whether a post type is registered. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [check\_ajax\_referer()](../../functions/check_ajax_referer) wp-includes/pluggable.php | Verifies the Ajax request to prevent processing requests external of the blog. | | [wp\_send\_json\_error()](../../functions/wp_send_json_error) wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating failure. | | [wp\_send\_json\_success()](../../functions/wp_send_json_success) wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating success. | | [get\_permalink()](../../functions/get_permalink) wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Nav_Menus::ajax_load_available_items() WP\_Customize\_Nav\_Menus::ajax\_load\_available\_items() ========================================================= Ajax handler for loading available menu items. File: `wp-includes/class-wp-customize-nav-menus.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-nav-menus.php/) ``` public function ajax_load_available_items() { check_ajax_referer( 'customize-menus', 'customize-menus-nonce' ); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); } $all_items = array(); $item_types = array(); if ( isset( $_POST['item_types'] ) && is_array( $_POST['item_types'] ) ) { $item_types = wp_unslash( $_POST['item_types'] ); } elseif ( isset( $_POST['type'] ) && isset( $_POST['object'] ) ) { // Back compat. $item_types[] = array( 'type' => wp_unslash( $_POST['type'] ), 'object' => wp_unslash( $_POST['object'] ), 'page' => empty( $_POST['page'] ) ? 0 : absint( $_POST['page'] ), ); } else { wp_send_json_error( 'nav_menus_missing_type_or_object_parameter' ); } foreach ( $item_types as $item_type ) { if ( empty( $item_type['type'] ) || empty( $item_type['object'] ) ) { wp_send_json_error( 'nav_menus_missing_type_or_object_parameter' ); } $type = sanitize_key( $item_type['type'] ); $object = sanitize_key( $item_type['object'] ); $page = empty( $item_type['page'] ) ? 0 : absint( $item_type['page'] ); $items = $this->load_available_items_query( $type, $object, $page ); if ( is_wp_error( $items ) ) { wp_send_json_error( $items->get_error_code() ); } $all_items[ $item_type['type'] . ':' . $item_type['object'] ] = $items; } wp_send_json_success( array( 'items' => $all_items ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Nav\_Menus::load\_available\_items\_query()](load_available_items_query) wp-includes/class-wp-customize-nav-menus.php | Performs the post\_type and taxonomy queries for loading available menu items. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [sanitize\_key()](../../functions/sanitize_key) wp-includes/formatting.php | Sanitizes a string key. | | [check\_ajax\_referer()](../../functions/check_ajax_referer) wp-includes/pluggable.php | Verifies the Ajax request to prevent processing requests external of the blog. | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | [wp\_send\_json\_error()](../../functions/wp_send_json_error) wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating failure. | | [wp\_send\_json\_success()](../../functions/wp_send_json_success) wp-includes/functions.php | Sends a JSON response back to an Ajax request, indicating success. | | [wp\_die()](../../functions/wp_die) wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Text_Diff_Renderer_Table::interleave_changed_lines( array $orig, array $final ): array WP\_Text\_Diff\_Renderer\_Table::interleave\_changed\_lines( array $orig, array $final ): array =============================================================================================== Takes changed blocks and matches which rows in orig turned into which rows in final. `$orig` array Required Lines of the original version of the text. `$final` array Required Lines of the final version of the text. array Array containing results of comparing the original text to the final text. * `orig_matches`arrayAssociative array of original matches. Index == row number of `$orig`, value == corresponding row number of that same line in `$final` or `'x'` if there is no corresponding row (indicating it is a deleted line). * `final_matches`arrayAssociative array of final matches. Index == row number of `$final`, value == corresponding row number of that same line in `$orig` or `'x'` if there is no corresponding row (indicating it is a new line). * `orig_rows`arrayAssociative array of interleaved rows of `$orig` with blanks to keep matches aligned with side-by-side diff of `$final`. A value >= 0 corresponds to index of `$orig`. Value < 0 indicates a blank row. * `final_rows`arrayAssociative array of interleaved rows of `$final` with blanks to keep matches aligned with side-by-side diff of `$orig`. A value >= 0 corresponds to index of `$final`. Value < 0 indicates a blank row. File: `wp-includes/class-wp-text-diff-renderer-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-text-diff-renderer-table.php/) ``` public function interleave_changed_lines( $orig, $final ) { // Contains all pairwise string comparisons. Keys are such that this need only be a one dimensional array. $matches = array(); foreach ( array_keys( $orig ) as $o ) { foreach ( array_keys( $final ) as $f ) { $matches[ "$o,$f" ] = $this->compute_string_distance( $orig[ $o ], $final[ $f ] ); } } asort( $matches ); // Order by string distance. $orig_matches = array(); $final_matches = array(); foreach ( $matches as $keys => $difference ) { list($o, $f) = explode( ',', $keys ); $o = (int) $o; $f = (int) $f; // Already have better matches for these guys. if ( isset( $orig_matches[ $o ] ) && isset( $final_matches[ $f ] ) ) { continue; } // First match for these guys. Must be best match. if ( ! isset( $orig_matches[ $o ] ) && ! isset( $final_matches[ $f ] ) ) { $orig_matches[ $o ] = $f; $final_matches[ $f ] = $o; continue; } // Best match of this final is already taken? Must mean this final is a new row. if ( isset( $orig_matches[ $o ] ) ) { $final_matches[ $f ] = 'x'; } elseif ( isset( $final_matches[ $f ] ) ) { // Best match of this orig is already taken? Must mean this orig is a deleted row. $orig_matches[ $o ] = 'x'; } } // We read the text in this order. ksort( $orig_matches ); ksort( $final_matches ); // Stores rows and blanks for each column. $orig_rows = array_keys( $orig_matches ); $orig_rows_copy = $orig_rows; $final_rows = array_keys( $final_matches ); // Interleaves rows with blanks to keep matches aligned. // We may end up with some extraneous blank rows, but we'll just ignore them later. foreach ( $orig_rows_copy as $orig_row ) { $final_pos = array_search( $orig_matches[ $orig_row ], $final_rows, true ); $orig_pos = (int) array_search( $orig_row, $orig_rows, true ); if ( false === $final_pos ) { // This orig is paired with a blank final. array_splice( $final_rows, $orig_pos, 0, -1 ); } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows. $diff_array = range( -1, $final_pos - $orig_pos ); array_splice( $final_rows, $orig_pos, 0, $diff_array ); } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows. $diff_array = range( -1, $orig_pos - $final_pos ); array_splice( $orig_rows, $orig_pos, 0, $diff_array ); } } // Pad the ends with blank rows if the columns aren't the same length. $diff_count = count( $orig_rows ) - count( $final_rows ); if ( $diff_count < 0 ) { while ( $diff_count < 0 ) { array_push( $orig_rows, $diff_count++ ); } } elseif ( $diff_count > 0 ) { $diff_count = -1 * $diff_count; while ( $diff_count < 0 ) { array_push( $final_rows, $diff_count++ ); } } return array( $orig_matches, $final_matches, $orig_rows, $final_rows ); } ``` | Uses | Description | | --- | --- | | [WP\_Text\_Diff\_Renderer\_Table::compute\_string\_distance()](compute_string_distance) wp-includes/class-wp-text-diff-renderer-table.php | Computes a number that is intended to reflect the “distance” between two strings. | | Used By | Description | | --- | --- | | [WP\_Text\_Diff\_Renderer\_Table::\_changed()](_changed) wp-includes/class-wp-text-diff-renderer-table.php | Process changed lines to do word-by-word diffs for extra highlighting. | | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Introduced. | wordpress WP_Text_Diff_Renderer_Table::compute_string_distance( string $string1, string $string2 ): int WP\_Text\_Diff\_Renderer\_Table::compute\_string\_distance( string $string1, string $string2 ): int =================================================================================================== Computes a number that is intended to reflect the “distance” between two strings. `$string1` string Required `$string2` string Required int File: `wp-includes/class-wp-text-diff-renderer-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-text-diff-renderer-table.php/) ``` public function compute_string_distance( $string1, $string2 ) { // Use an md5 hash of the strings for a count cache, as it's fast to generate, and collisions aren't a concern. $count_key1 = md5( $string1 ); $count_key2 = md5( $string2 ); // Cache vectors containing character frequency for all chars in each string. if ( ! isset( $this->count_cache[ $count_key1 ] ) ) { $this->count_cache[ $count_key1 ] = count_chars( $string1 ); } if ( ! isset( $this->count_cache[ $count_key2 ] ) ) { $this->count_cache[ $count_key2 ] = count_chars( $string2 ); } $chars1 = $this->count_cache[ $count_key1 ]; $chars2 = $this->count_cache[ $count_key2 ]; $difference_key = md5( implode( ',', $chars1 ) . ':' . implode( ',', $chars2 ) ); if ( ! isset( $this->difference_cache[ $difference_key ] ) ) { // L1-norm of difference vector. $this->difference_cache[ $difference_key ] = array_sum( array_map( array( $this, 'difference' ), $chars1, $chars2 ) ); } $difference = $this->difference_cache[ $difference_key ]; // $string1 has zero length? Odd. Give huge penalty by not dividing. if ( ! $string1 ) { return $difference; } // Return distance per character (of string1). return $difference / strlen( $string1 ); } ``` | Used By | Description | | --- | --- | | [WP\_Text\_Diff\_Renderer\_Table::interleave\_changed\_lines()](interleave_changed_lines) wp-includes/class-wp-text-diff-renderer-table.php | Takes changed blocks and matches which rows in orig turned into which rows in final. | | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Introduced. | wordpress WP_Text_Diff_Renderer_Table::__unset( string $name ) WP\_Text\_Diff\_Renderer\_Table::\_\_unset( string $name ) ========================================================== Make private properties un-settable for backward compatibility. `$name` string Required Property to unset. File: `wp-includes/class-wp-text-diff-renderer-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-text-diff-renderer-table.php/) ``` public function __unset( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { unset( $this->$name ); } } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Text_Diff_Renderer_Table::__set( string $name, mixed $value ): mixed WP\_Text\_Diff\_Renderer\_Table::\_\_set( string $name, mixed $value ): mixed ============================================================================= Make private properties settable for backward compatibility. `$name` string Required Property to check if set. `$value` mixed Required Property value. mixed Newly-set property. File: `wp-includes/class-wp-text-diff-renderer-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-text-diff-renderer-table.php/) ``` public function __set( $name, $value ) { if ( in_array( $name, $this->compat_fields, true ) ) { return $this->$name = $value; } } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Text_Diff_Renderer_Table::__get( string $name ): mixed WP\_Text\_Diff\_Renderer\_Table::\_\_get( string $name ): mixed =============================================================== Make private properties readable for backward compatibility. `$name` string Required Property to get. mixed Property. File: `wp-includes/class-wp-text-diff-renderer-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-text-diff-renderer-table.php/) ``` public function __get( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { return $this->$name; } } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Text_Diff_Renderer_Table::__isset( string $name ): bool WP\_Text\_Diff\_Renderer\_Table::\_\_isset( string $name ): bool ================================================================ Make private properties checkable for backward compatibility. `$name` string Required Property to check if set. bool Whether the property is set. File: `wp-includes/class-wp-text-diff-renderer-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-text-diff-renderer-table.php/) ``` public function __isset( $name ) { if ( in_array( $name, $this->compat_fields, true ) ) { return isset( $this->$name ); } } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Text_Diff_Renderer_Table::_changed( array $orig, array $final ): string WP\_Text\_Diff\_Renderer\_Table::\_changed( array $orig, array $final ): string =============================================================================== Process changed lines to do word-by-word diffs for extra highlighting. (TRAC style) sometimes these lines can actually be deleted or added rows. We do additional processing to figure that out `$orig` array Required `$final` array Required string File: `wp-includes/class-wp-text-diff-renderer-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-text-diff-renderer-table.php/) ``` public function _changed( $orig, $final ) { $r = ''; /* * Does the aforementioned additional processing: * *_matches tell what rows are "the same" in orig and final. Those pairs will be diffed to get word changes. * - match is numeric: an index in other column. * - match is 'X': no match. It is a new row. * *_rows are column vectors for the orig column and the final column. * - row >= 0: an index of the $orig or $final array. * - row < 0: a blank row for that column. */ list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final ); // These will hold the word changes as determined by an inline diff. $orig_diffs = array(); $final_diffs = array(); // Compute word diffs for each matched pair using the inline diff. foreach ( $orig_matches as $o => $f ) { if ( is_numeric( $o ) && is_numeric( $f ) ) { $text_diff = new Text_Diff( 'auto', array( array( $orig[ $o ] ), array( $final[ $f ] ) ) ); $renderer = new $this->inline_diff_renderer; $diff = $renderer->render( $text_diff ); // If they're too different, don't include any <ins> or <del>'s. if ( preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches ) ) { // Length of all text between <ins> or <del>. $stripped_matches = strlen( strip_tags( implode( ' ', $diff_matches[0] ) ) ); // Since we count length of text between <ins> or <del> (instead of picking just one), // we double the length of chars not in those tags. $stripped_diff = strlen( strip_tags( $diff ) ) * 2 - $stripped_matches; $diff_ratio = $stripped_matches / $stripped_diff; if ( $diff_ratio > $this->_diff_threshold ) { continue; // Too different. Don't save diffs. } } // Un-inline the diffs by removing <del> or <ins>. $orig_diffs[ $o ] = preg_replace( '|<ins>.*?</ins>|', '', $diff ); $final_diffs[ $f ] = preg_replace( '|<del>.*?</del>|', '', $diff ); } } foreach ( array_keys( $orig_rows ) as $row ) { // Both columns have blanks. Ignore them. if ( $orig_rows[ $row ] < 0 && $final_rows[ $row ] < 0 ) { continue; } // If we have a word based diff, use it. Otherwise, use the normal line. if ( isset( $orig_diffs[ $orig_rows[ $row ] ] ) ) { $orig_line = $orig_diffs[ $orig_rows[ $row ] ]; } elseif ( isset( $orig[ $orig_rows[ $row ] ] ) ) { $orig_line = htmlspecialchars( $orig[ $orig_rows[ $row ] ] ); } else { $orig_line = ''; } if ( isset( $final_diffs[ $final_rows[ $row ] ] ) ) { $final_line = $final_diffs[ $final_rows[ $row ] ]; } elseif ( isset( $final[ $final_rows[ $row ] ] ) ) { $final_line = htmlspecialchars( $final[ $final_rows[ $row ] ] ); } else { $final_line = ''; } if ( $orig_rows[ $row ] < 0 ) { // Orig is blank. This is really an added row. $r .= $this->_added( array( $final_line ), false ); } elseif ( $final_rows[ $row ] < 0 ) { // Final is blank. This is really a deleted row. $r .= $this->_deleted( array( $orig_line ), false ); } else { // A true changed row. if ( $this->_show_split_view ) { $r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->addedLine( $final_line ) . "</tr>\n"; } else { $r .= '<tr>' . $this->deletedLine( $orig_line ) . '</tr><tr>' . $this->addedLine( $final_line ) . "</tr>\n"; } } } return $r; } ``` | Uses | Description | | --- | --- | | [WP\_Text\_Diff\_Renderer\_Table::interleave\_changed\_lines()](interleave_changed_lines) wp-includes/class-wp-text-diff-renderer-table.php | Takes changed blocks and matches which rows in orig turned into which rows in final. | | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Introduced. |
programming_docs
wordpress WP_Text_Diff_Renderer_Table::__construct( array $params = array() ) WP\_Text\_Diff\_Renderer\_Table::\_\_construct( array $params = array() ) ========================================================================= Constructor – Call parent constructor with params array. This will set class properties based on the key value pairs in the array. `$params` array Optional Default: `array()` File: `wp-includes/class-wp-text-diff-renderer-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-text-diff-renderer-table.php/) ``` public function __construct( $params = array() ) { parent::__construct( $params ); if ( isset( $params['show_split_view'] ) ) { $this->_show_split_view = $params['show_split_view']; } } ``` | Used By | Description | | --- | --- | | [wp\_text\_diff()](../../functions/wp_text_diff) wp-includes/pluggable.php | Displays a human readable HTML representation of the difference between two strings. | | Version | Description | | --- | --- | | [2.6.0](https://developer.wordpress.org/reference/since/2.6.0/) | Introduced. | wordpress Theme_Installer_Skin::after() Theme\_Installer\_Skin::after() =============================== Action to perform following a single theme install. File: `wp-admin/includes/class-theme-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-theme-installer-skin.php/) ``` public function after() { if ( $this->do_overwrite() ) { return; } if ( empty( $this->upgrader->result['destination_name'] ) ) { return; } $theme_info = $this->upgrader->theme_info(); if ( empty( $theme_info ) ) { return; } $name = $theme_info->display( 'Name' ); $stylesheet = $this->upgrader->result['destination_name']; $template = $theme_info->get_template(); $activate_link = add_query_arg( array( 'action' => 'activate', 'template' => urlencode( $template ), 'stylesheet' => urlencode( $stylesheet ), ), admin_url( 'themes.php' ) ); $activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); $install_actions = array(); if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) && ! $theme_info->is_block_theme() ) { $customize_url = add_query_arg( array( 'theme' => urlencode( $stylesheet ), 'return' => urlencode( admin_url( 'web' === $this->type ? 'theme-install.php' : 'themes.php' ) ), ), admin_url( 'customize.php' ) ); $install_actions['preview'] = sprintf( '<a href="%s" class="hide-if-no-customize load-customize">' . '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', esc_url( $customize_url ), __( 'Live Preview' ), /* translators: %s: Theme name. */ sprintf( __( 'Live Preview &#8220;%s&#8221;' ), $name ) ); } $install_actions['activate'] = sprintf( '<a href="%s" class="activatelink">' . '<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', esc_url( $activate_link ), __( 'Activate' ), /* translators: %s: Theme name. */ sprintf( _x( 'Activate &#8220;%s&#8221;', 'theme' ), $name ) ); if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) { $install_actions['network_enable'] = sprintf( '<a href="%s" target="_parent">%s</a>', esc_url( wp_nonce_url( 'themes.php?action=enable&amp;theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ), __( 'Network Enable' ) ); } if ( 'web' === $this->type ) { $install_actions['themes_page'] = sprintf( '<a href="%s" target="_parent">%s</a>', self_admin_url( 'theme-install.php' ), __( 'Go to Theme Installer' ) ); } elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) { $install_actions['themes_page'] = sprintf( '<a href="%s" target="_parent">%s</a>', self_admin_url( 'themes.php' ), __( 'Go to Themes page' ) ); } if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) { unset( $install_actions['activate'], $install_actions['preview'] ); } elseif ( get_option( 'template' ) === $stylesheet ) { unset( $install_actions['activate'] ); } /** * Filters the list of action links available following a single theme installation. * * @since 2.8.0 * * @param string[] $install_actions Array of theme action links. * @param object $api Object containing WordPress.org API theme data. * @param string $stylesheet Theme directory name. * @param WP_Theme $theme_info Theme object. */ $install_actions = apply_filters( 'install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info ); if ( ! empty( $install_actions ) ) { $this->feedback( implode( ' | ', (array) $install_actions ) ); } } ``` [apply\_filters( 'install\_theme\_complete\_actions', string[] $install\_actions, object $api, string $stylesheet, WP\_Theme $theme\_info )](../../hooks/install_theme_complete_actions) Filters the list of action links available following a single theme installation. | Uses | Description | | --- | --- | | [Theme\_Installer\_Skin::do\_overwrite()](do_overwrite) wp-admin/includes/class-theme-installer-skin.php | Check if the theme can be overwritten and output the HTML for overwriting a theme on upload. | | [is\_network\_admin()](../../functions/is_network_admin) wp-includes/load.php | Determines whether the current request is for the network administrative interface. | | [self\_admin\_url()](../../functions/self_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for either the current site or the network depending on context. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress Theme_Installer_Skin::hide_process_failed( WP_Error $wp_error ): bool Theme\_Installer\_Skin::hide\_process\_failed( WP\_Error $wp\_error ): bool =========================================================================== Hides the `process_failed` error when updating a theme by uploading a zip file. `$wp_error` [WP\_Error](../wp_error) Required [WP\_Error](../wp_error) object. bool File: `wp-admin/includes/class-theme-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-theme-installer-skin.php/) ``` public function hide_process_failed( $wp_error ) { if ( 'upload' === $this->type && '' === $this->overwrite && $wp_error->get_error_code() === 'folder_exists' ) { return true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Error::get\_error\_code()](../wp_error/get_error_code) wp-includes/class-wp-error.php | Retrieves the first error code available. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress Theme_Installer_Skin::__construct( array $args = array() ) Theme\_Installer\_Skin::\_\_construct( array $args = array() ) ============================================================== `$args` array Optional Default: `array()` File: `wp-admin/includes/class-theme-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-theme-installer-skin.php/) ``` public function __construct( $args = array() ) { $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '', 'overwrite' => '', ); $args = wp_parse_args( $args, $defaults ); $this->type = $args['type']; $this->url = $args['url']; $this->api = isset( $args['api'] ) ? $args['api'] : array(); $this->overwrite = $args['overwrite']; parent::__construct( $args ); } ``` | Uses | Description | | --- | --- | | [WP\_Upgrader\_Skin::\_\_construct()](../wp_upgrader_skin/__construct) wp-admin/includes/class-wp-upgrader-skin.php | Constructor. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | wordpress Theme_Installer_Skin::do_overwrite(): bool Theme\_Installer\_Skin::do\_overwrite(): bool ============================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Check if the theme can be overwritten and output the HTML for overwriting a theme on upload. bool Whether the theme can be overwritten and HTML was outputted. File: `wp-admin/includes/class-theme-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-theme-installer-skin.php/) ``` private function do_overwrite() { if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) { return false; } $folder = $this->result->get_error_data( 'folder_exists' ); $folder = rtrim( $folder, '/' ); $current_theme_data = false; $all_themes = wp_get_themes( array( 'errors' => null ) ); foreach ( $all_themes as $theme ) { $stylesheet_dir = wp_normalize_path( $theme->get_stylesheet_directory() ); if ( rtrim( $stylesheet_dir, '/' ) !== $folder ) { continue; } $current_theme_data = $theme; } $new_theme_data = $this->upgrader->new_theme_data; if ( ! $current_theme_data || ! $new_theme_data ) { return false; } echo '<h2 class="update-from-upload-heading">' . esc_html__( 'This theme is already installed.' ) . '</h2>'; // Check errors for active theme. if ( is_wp_error( $current_theme_data->errors() ) ) { $this->feedback( 'current_theme_has_errors', $current_theme_data->errors()->get_error_message() ); } $this->is_downgrading = version_compare( $current_theme_data['Version'], $new_theme_data['Version'], '>' ); $is_invalid_parent = false; if ( ! empty( $new_theme_data['Template'] ) ) { $is_invalid_parent = ! in_array( $new_theme_data['Template'], array_keys( $all_themes ), true ); } $rows = array( 'Name' => __( 'Theme name' ), 'Version' => __( 'Version' ), 'Author' => __( 'Author' ), 'RequiresWP' => __( 'Required WordPress version' ), 'RequiresPHP' => __( 'Required PHP version' ), 'Template' => __( 'Parent theme' ), ); $table = '<table class="update-from-upload-comparison"><tbody>'; $table .= '<tr><th></th><th>' . esc_html_x( 'Active', 'theme' ) . '</th><th>' . esc_html_x( 'Uploaded', 'theme' ) . '</th></tr>'; $is_same_theme = true; // Let's consider only these rows. foreach ( $rows as $field => $label ) { $old_value = $current_theme_data->display( $field, false ); $old_value = $old_value ? (string) $old_value : '-'; $new_value = ! empty( $new_theme_data[ $field ] ) ? (string) $new_theme_data[ $field ] : '-'; if ( $old_value === $new_value && '-' === $new_value && 'Template' === $field ) { continue; } $is_same_theme = $is_same_theme && ( $old_value === $new_value ); $diff_field = ( 'Version' !== $field && $new_value !== $old_value ); $diff_version = ( 'Version' === $field && $this->is_downgrading ); $invalid_parent = false; if ( 'Template' === $field && $is_invalid_parent ) { $invalid_parent = true; $new_value .= ' ' . __( '(not found)' ); } $table .= '<tr><td class="name-label">' . $label . '</td><td>' . wp_strip_all_tags( $old_value ) . '</td>'; $table .= ( $diff_field || $diff_version || $invalid_parent ) ? '<td class="warning">' : '<td>'; $table .= wp_strip_all_tags( $new_value ) . '</td></tr>'; } $table .= '</tbody></table>'; /** * Filters the compare table output for overwriting a theme package on upload. * * @since 5.5.0 * * @param string $table The output table with Name, Version, Author, RequiresWP, and RequiresPHP info. * @param WP_Theme $current_theme_data Active theme data. * @param array $new_theme_data Array with uploaded theme data. */ echo apply_filters( 'install_theme_overwrite_comparison', $table, $current_theme_data, $new_theme_data ); $install_actions = array(); $can_update = true; $blocked_message = '<p>' . esc_html__( 'The theme cannot be updated due to the following:' ) . '</p>'; $blocked_message .= '<ul class="ul-disc">'; $requires_php = isset( $new_theme_data['RequiresPHP'] ) ? $new_theme_data['RequiresPHP'] : null; $requires_wp = isset( $new_theme_data['RequiresWP'] ) ? $new_theme_data['RequiresWP'] : null; if ( ! is_php_version_compatible( $requires_php ) ) { $error = sprintf( /* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */ __( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ), PHP_VERSION, $requires_php ); $blocked_message .= '<li>' . esc_html( $error ) . '</li>'; $can_update = false; } if ( ! is_wp_version_compatible( $requires_wp ) ) { $error = sprintf( /* translators: 1: Current WordPress version, 2: Version required by the uploaded theme. */ __( 'Your WordPress version is %1$s, however the uploaded theme requires %2$s.' ), get_bloginfo( 'version' ), $requires_wp ); $blocked_message .= '<li>' . esc_html( $error ) . '</li>'; $can_update = false; } $blocked_message .= '</ul>'; if ( $can_update ) { if ( $this->is_downgrading ) { $warning = sprintf( /* translators: %s: Documentation URL. */ __( 'You are uploading an older version of the active theme. You can continue to install the older version, but be sure to <a href="%s">back up your database and files</a> first.' ), __( 'https://wordpress.org/support/article/wordpress-backups/' ) ); } else { $warning = sprintf( /* translators: %s: Documentation URL. */ __( 'You are updating a theme. Be sure to <a href="%s">back up your database and files</a> first.' ), __( 'https://wordpress.org/support/article/wordpress-backups/' ) ); } echo '<p class="update-from-upload-notice">' . $warning . '</p>'; $overwrite = $this->is_downgrading ? 'downgrade-theme' : 'update-theme'; $install_actions['overwrite_theme'] = sprintf( '<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>', wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'theme-upload' ), _x( 'Replace active with uploaded', 'theme' ) ); } else { echo $blocked_message; } $cancel_url = add_query_arg( 'action', 'upload-theme-cancel-overwrite', $this->url ); $install_actions['themes_page'] = sprintf( '<a class="button" href="%s" target="_parent">%s</a>', wp_nonce_url( $cancel_url, 'theme-upload-cancel-overwrite' ), __( 'Cancel and go back' ) ); /** * Filters the list of action links available following a single theme installation failure * when overwriting is allowed. * * @since 5.5.0 * * @param string[] $install_actions Array of theme action links. * @param object $api Object containing WordPress.org API theme data. * @param array $new_theme_data Array with uploaded theme data. */ $install_actions = apply_filters( 'install_theme_overwrite_actions', $install_actions, $this->api, $new_theme_data ); if ( ! empty( $install_actions ) ) { printf( '<p class="update-from-upload-expired hidden">%s</p>', __( 'The uploaded file has expired. Please go back and upload it again.' ) ); echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>'; } return true; } ``` [apply\_filters( 'install\_theme\_overwrite\_actions', string[] $install\_actions, object $api, array $new\_theme\_data )](../../hooks/install_theme_overwrite_actions) Filters the list of action links available following a single theme installation failure when overwriting is allowed. [apply\_filters( 'install\_theme\_overwrite\_comparison', string $table, WP\_Theme $current\_theme\_data, array $new\_theme\_data )](../../hooks/install_theme_overwrite_comparison) Filters the compare table output for overwriting a theme package on upload. | Uses | Description | | --- | --- | | [is\_php\_version\_compatible()](../../functions/is_php_version_compatible) wp-includes/functions.php | Checks compatibility with the current PHP version. | | [is\_wp\_version\_compatible()](../../functions/is_wp_version_compatible) wp-includes/functions.php | Checks compatibility with the current WordPress version. | | [wp\_get\_themes()](../../functions/wp_get_themes) wp-includes/theme.php | Returns an array of [WP\_Theme](../wp_theme) objects based on the arguments. | | [esc\_html\_\_()](../../functions/esc_html__) wp-includes/l10n.php | Retrieves the translation of $text and escapes it for safe use in HTML output. | | [esc\_html\_x()](../../functions/esc_html_x) wp-includes/l10n.php | Translates string with gettext context, and escapes it for safe use in HTML output. | | [wp\_strip\_all\_tags()](../../functions/wp_strip_all_tags) wp-includes/formatting.php | Properly strips all HTML tags including script and style | | [wp\_normalize\_path()](../../functions/wp_normalize_path) wp-includes/functions.php | Normalizes a filesystem path. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [Theme\_Installer\_Skin::after()](after) wp-admin/includes/class-theme-installer-skin.php | Action to perform following a single theme install. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress Theme_Installer_Skin::before() Theme\_Installer\_Skin::before() ================================ Action to perform before installing a theme. File: `wp-admin/includes/class-theme-installer-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-theme-installer-skin.php/) ``` public function before() { if ( ! empty( $this->api ) ) { $this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version ); } } ``` | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |
programming_docs
wordpress Walker_Page::start_lvl( string $output, int $depth, array $args = array() ) Walker\_Page::start\_lvl( string $output, int $depth, array $args = array() ) ============================================================================= Outputs the beginning of the current level in the tree before elements are output. * [Walker::start\_lvl()](../walker/start_lvl) `$output` string Required Used to append additional content (passed by reference). `$depth` int Optional Depth of page. Used for padding. Default 0. `$args` array Optional Arguments for outputting the next level. Default: `array()` File: `wp-includes/class-walker-page.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-page.php/) ``` public function start_lvl( &$output, $depth = 0, $args = array() ) { if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) { $t = "\t"; $n = "\n"; } else { $t = ''; $n = ''; } $indent = str_repeat( $t, $depth ); $output .= "{$n}{$indent}<ul class='children'>{$n}"; } ``` | Version | Description | | --- | --- | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress Walker_Page::start_el( string $output, WP_Post $data_object, int $depth, array $args = array(), int $current_object_id ) Walker\_Page::start\_el( string $output, WP\_Post $data\_object, int $depth, array $args = array(), int $current\_object\_id ) ============================================================================================================================== Outputs the beginning of the current element in the tree. * [Walker::start\_el()](../walker/start_el) `$output` string Required Used to append additional content. Passed by reference. `$data_object` [WP\_Post](../wp_post) Required Page data object. `$depth` int Optional Depth of page. Used for padding. Default 0. `$args` array Optional Array of arguments. Default: `array()` `$current_object_id` int Optional ID of the current page. Default 0. File: `wp-includes/class-walker-page.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-page.php/) ``` public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) { // Restores the more descriptive, specific name for use within this method. $page = $data_object; $current_page_id = $current_object_id; if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) { $t = "\t"; $n = "\n"; } else { $t = ''; $n = ''; } if ( $depth ) { $indent = str_repeat( $t, $depth ); } else { $indent = ''; } $css_class = array( 'page_item', 'page-item-' . $page->ID ); if ( isset( $args['pages_with_children'][ $page->ID ] ) ) { $css_class[] = 'page_item_has_children'; } if ( ! empty( $current_page_id ) ) { $_current_page = get_post( $current_page_id ); if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) { $css_class[] = 'current_page_ancestor'; } if ( $page->ID == $current_page_id ) { $css_class[] = 'current_page_item'; } elseif ( $_current_page && $page->ID === $_current_page->post_parent ) { $css_class[] = 'current_page_parent'; } } elseif ( get_option( 'page_for_posts' ) == $page->ID ) { $css_class[] = 'current_page_parent'; } /** * Filters the list of CSS classes to include with each page item in the list. * * @since 2.8.0 * * @see wp_list_pages() * * @param string[] $css_class An array of CSS classes to be applied to each list item. * @param WP_Post $page Page data object. * @param int $depth Depth of page, used for padding. * @param array $args An array of arguments. * @param int $current_page_id ID of the current page. */ $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page_id ) ); $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : ''; if ( '' === $page->post_title ) { /* translators: %d: ID of a post. */ $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID ); } $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before']; $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after']; $atts = array(); $atts['href'] = get_permalink( $page->ID ); $atts['aria-current'] = ( $page->ID == $current_page_id ) ? 'page' : ''; /** * Filters the HTML attributes applied to a page menu item's anchor element. * * @since 4.8.0 * * @param array $atts { * The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored. * * @type string $href The href attribute. * @type string $aria-current The aria-current attribute. * } * @param WP_Post $page Page data object. * @param int $depth Depth of page, used for padding. * @param array $args An array of arguments. * @param int $current_page_id ID of the current page. */ $atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page_id ); $attributes = ''; foreach ( $atts as $attr => $value ) { if ( is_scalar( $value ) && '' !== $value && false !== $value ) { $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); $attributes .= ' ' . $attr . '="' . $value . '"'; } } $output .= $indent . sprintf( '<li%s><a%s>%s%s%s</a>', $css_classes, $attributes, $args['link_before'], /** This filter is documented in wp-includes/post-template.php */ apply_filters( 'the_title', $page->post_title, $page->ID ), $args['link_after'] ); if ( ! empty( $args['show_date'] ) ) { if ( 'modified' === $args['show_date'] ) { $time = $page->post_modified; } else { $time = $page->post_date; } $date_format = empty( $args['date_format'] ) ? '' : $args['date_format']; $output .= ' ' . mysql2date( $date_format, $time ); } } ``` [apply\_filters( 'page\_css\_class', string[] $css\_class, WP\_Post $page, int $depth, array $args, int $current\_page\_id )](../../hooks/page_css_class) Filters the list of CSS classes to include with each page item in the list. [apply\_filters( 'page\_menu\_link\_attributes', array $atts, WP\_Post $page, int $depth, array $args, int $current\_page\_id )](../../hooks/page_menu_link_attributes) Filters the HTML attributes applied to a page menu item’s anchor element. [apply\_filters( 'the\_title', string $post\_title, int $post\_id )](../../hooks/the_title) Filters the post title. | Uses | Description | | --- | --- | | [mysql2date()](../../functions/mysql2date) wp-includes/functions.php | Converts given MySQL date string into a different format. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [get\_permalink()](../../functions/get_permalink) wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$page` to `$data_object` and `$current_page` to `$current_object_id` to match parent class for PHP 8 named parameter support. | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress Walker_Page::end_lvl( string $output, int $depth, array $args = array() ) Walker\_Page::end\_lvl( string $output, int $depth, array $args = array() ) =========================================================================== Outputs the end of the current level in the tree after elements are output. * [Walker::end\_lvl()](../walker/end_lvl) `$output` string Required Used to append additional content (passed by reference). `$depth` int Optional Depth of page. Used for padding. Default 0. `$args` array Optional Arguments for outputting the end of the current level. Default: `array()` File: `wp-includes/class-walker-page.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-page.php/) ``` public function end_lvl( &$output, $depth = 0, $args = array() ) { if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) { $t = "\t"; $n = "\n"; } else { $t = ''; $n = ''; } $indent = str_repeat( $t, $depth ); $output .= "{$indent}</ul>{$n}"; } ``` | Version | Description | | --- | --- | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress Walker_Page::end_el( string $output, WP_Post $data_object, int $depth, array $args = array() ) Walker\_Page::end\_el( string $output, WP\_Post $data\_object, int $depth, array $args = array() ) ================================================================================================== Outputs the end of the current element in the tree. * [Walker::end\_el()](../walker/end_el) `$output` string Required Used to append additional content. Passed by reference. `$data_object` [WP\_Post](../wp_post) Required Page data object. Not used. `$depth` int Optional Depth of page. Default 0 (unused). `$args` array Optional Array of arguments. Default: `array()` File: `wp-includes/class-walker-page.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-page.php/) ``` public function end_el( &$output, $data_object, $depth = 0, $args = array() ) { if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) { $t = "\t"; $n = "\n"; } else { $t = ''; $n = ''; } $output .= "</li>{$n}"; } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$page` to `$data_object` to match parent class for PHP 8 named parameter support. | | [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::get_nav_menu_item( int $id ): object|WP_Error WP\_REST\_Menu\_Items\_Controller::get\_nav\_menu\_item( int $id ): object|WP\_Error ==================================================================================== Gets the nav menu item, if the ID is valid. `$id` int Required Supplied ID. object|[WP\_Error](../wp_error) Post object if ID is valid, [WP\_Error](../wp_error) otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` protected function get_nav_menu_item( $id ) { $post = $this->get_post( $id ); if ( is_wp_error( $post ) ) { return $post; } return wp_setup_nav_menu_item( $post ); } ``` | Uses | Description | | --- | --- | | [wp\_setup\_nav\_menu\_item()](../../functions/wp_setup_nav_menu_item) wp-includes/nav-menu.php | Decorates a menu item object with the shared navigation menu item properties. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post output for response. | | [WP\_REST\_Menu\_Items\_Controller::prepare\_links()](prepare_links) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares links for the request. | | [WP\_REST\_Menu\_Items\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Creates a single post. | | [WP\_REST\_Menu\_Items\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Updates a single nav menu item. | | [WP\_REST\_Menu\_Items\_Controller::delete\_item()](delete_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Deletes a single menu item. | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_database()](prepare_item_for_database) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post for create or update. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::prepare_item_for_response( WP_Post $item, WP_REST_Request $request ): WP_REST_Response WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_response( WP\_Post $item, WP\_REST\_Request $request ): WP\_REST\_Response ================================================================================================================================= Prepares a single post output for response. `$item` [WP\_Post](../wp_post) Required Post object. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request object. [WP\_REST\_Response](../wp_rest_response) Response object. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` public function prepare_item_for_response( $item, $request ) { // Base fields for every post. $fields = $this->get_fields_for_response( $request ); $menu_item = $this->get_nav_menu_item( $item->ID ); $data = array(); if ( rest_is_field_included( 'id', $fields ) ) { $data['id'] = $menu_item->ID; } if ( rest_is_field_included( 'title', $fields ) ) { $data['title'] = array(); } if ( rest_is_field_included( 'title.raw', $fields ) ) { $data['title']['raw'] = $menu_item->title; } if ( rest_is_field_included( 'title.rendered', $fields ) ) { add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); /** This filter is documented in wp-includes/post-template.php */ $title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID ); $data['title']['rendered'] = $title; remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); } if ( rest_is_field_included( 'status', $fields ) ) { $data['status'] = $menu_item->post_status; } if ( rest_is_field_included( 'url', $fields ) ) { $data['url'] = $menu_item->url; } if ( rest_is_field_included( 'attr_title', $fields ) ) { // Same as post_excerpt. $data['attr_title'] = $menu_item->attr_title; } if ( rest_is_field_included( 'description', $fields ) ) { // Same as post_content. $data['description'] = $menu_item->description; } if ( rest_is_field_included( 'type', $fields ) ) { $data['type'] = $menu_item->type; } if ( rest_is_field_included( 'type_label', $fields ) ) { $data['type_label'] = $menu_item->type_label; } if ( rest_is_field_included( 'object', $fields ) ) { $data['object'] = $menu_item->object; } if ( rest_is_field_included( 'object_id', $fields ) ) { // It is stored as a string, but should be exposed as an integer. $data['object_id'] = absint( $menu_item->object_id ); } if ( rest_is_field_included( 'parent', $fields ) ) { // Same as post_parent, exposed as an integer. $data['parent'] = (int) $menu_item->menu_item_parent; } if ( rest_is_field_included( 'menu_order', $fields ) ) { // Same as post_parent, exposed as an integer. $data['menu_order'] = (int) $menu_item->menu_order; } if ( rest_is_field_included( 'target', $fields ) ) { $data['target'] = $menu_item->target; } if ( rest_is_field_included( 'classes', $fields ) ) { $data['classes'] = (array) $menu_item->classes; } if ( rest_is_field_included( 'xfn', $fields ) ) { $data['xfn'] = array_map( 'sanitize_html_class', explode( ' ', $menu_item->xfn ) ); } if ( rest_is_field_included( 'invalid', $fields ) ) { $data['invalid'] = (bool) $menu_item->_invalid; } if ( rest_is_field_included( 'meta', $fields ) ) { $data['meta'] = $this->meta->get_value( $menu_item->ID, $request ); } $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $taxonomy ) { $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; if ( rest_is_field_included( $base, $fields ) ) { $terms = get_the_terms( $item, $taxonomy->name ); if ( ! is_array( $terms ) ) { continue; } $term_ids = $terms ? array_values( wp_list_pluck( $terms, 'term_id' ) ) : array(); if ( 'nav_menu' === $taxonomy->name ) { $data[ $base ] = $term_ids ? array_shift( $term_ids ) : 0; } else { $data[ $base ] = $term_ids; } } } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); // Wrap the data in a response object. $response = rest_ensure_response( $data ); if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $links = $this->prepare_links( $item ); $response->add_links( $links ); if ( ! empty( $links['self']['href'] ) ) { $actions = $this->get_available_actions( $item, $request ); $self = $links['self']['href']; foreach ( $actions as $rel ) { $response->add_link( $rel, $self ); } } } /** * Filters the menu item data for a REST API response. * * @since 5.9.0 * * @param WP_REST_Response $response The response object. * @param object $menu_item Menu item setup by {@see wp_setup_nav_menu_item()}. * @param WP_REST_Request $request Request object. */ return apply_filters( 'rest_prepare_nav_menu_item', $response, $menu_item, $request ); } ``` [apply\_filters( 'rest\_prepare\_nav\_menu\_item', WP\_REST\_Response $response, object $menu\_item, WP\_REST\_Request $request )](../../hooks/rest_prepare_nav_menu_item) Filters the menu item data for a REST API response. [apply\_filters( 'the\_title', string $post\_title, int $post\_id )](../../hooks/the_title) Filters the post title. | Uses | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::prepare\_links()](prepare_links) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares links for the request. | | [WP\_REST\_Menu\_Items\_Controller::get\_nav\_menu\_item()](get_nav_menu_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Gets the nav menu item, if the ID is valid. | | [rest\_is\_field\_included()](../../functions/rest_is_field_included) wp-includes/rest-api.php | Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body. | | [get\_the\_terms()](../../functions/get_the_terms) wp-includes/category-template.php | Retrieves the terms of the taxonomy that are attached to the post. | | [wp\_list\_filter()](../../functions/wp_list_filter) wp-includes/functions.php | Filters a list of objects, based on a set of key => value arguments. | | [wp\_list\_pluck()](../../functions/wp_list_pluck) wp-includes/functions.php | Plucks a certain field out of each object or array in an array. | | [get\_object\_taxonomies()](../../functions/get_object_taxonomies) wp-includes/taxonomy.php | Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name. | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Creates a single post. | | [WP\_REST\_Menu\_Items\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Updates a single nav menu item. | | [WP\_REST\_Menu\_Items\_Controller::delete\_item()](delete_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Deletes a single menu item. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |
programming_docs
wordpress WP_REST_Menu_Items_Controller::prepare_links( WP_Post $post ): array WP\_REST\_Menu\_Items\_Controller::prepare\_links( WP\_Post $post ): array ========================================================================== Prepares links for the request. `$post` [WP\_Post](../wp_post) Required Post object. array Links for the given post. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` protected function prepare_links( $post ) { $links = parent::prepare_links( $post ); $menu_item = $this->get_nav_menu_item( $post->ID ); if ( empty( $menu_item->object_id ) ) { return $links; } $path = ''; $type = ''; $key = $menu_item->type; if ( 'post_type' === $menu_item->type ) { $path = rest_get_route_for_post( $menu_item->object_id ); $type = get_post_type( $menu_item->object_id ); } elseif ( 'taxonomy' === $menu_item->type ) { $path = rest_get_route_for_term( $menu_item->object_id ); $type = get_term_field( 'taxonomy', $menu_item->object_id ); } if ( $path && $type ) { $links['https://api.w.org/menu-item-object'][] = array( 'href' => rest_url( $path ), $key => $type, 'embeddable' => true, ); } return $links; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::get\_nav\_menu\_item()](get_nav_menu_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Gets the nav menu item, if the ID is valid. | | [rest\_get\_route\_for\_post()](../../functions/rest_get_route_for_post) wp-includes/rest-api.php | Gets the REST API route for a post. | | [rest\_get\_route\_for\_term()](../../functions/rest_get_route_for_term) wp-includes/rest-api.php | Gets the REST API route for a term. | | [WP\_REST\_Posts\_Controller::prepare\_links()](../wp_rest_posts_controller/prepare_links) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares links for the request. | | [get\_term\_field()](../../functions/get_term_field) wp-includes/taxonomy.php | Gets sanitized term field. | | [get\_post\_type()](../../functions/get_post_type) wp-includes/post.php | Retrieves the post type of the current post or of a given post. | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | Used By | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post output for response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::get_menu_id( int $menu_item_id ): int WP\_REST\_Menu\_Items\_Controller::get\_menu\_id( int $menu\_item\_id ): int ============================================================================ Gets the id of the menu that the given menu item belongs to. `$menu_item_id` int Required Menu item id. int File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` protected function get_menu_id( $menu_item_id ) { $menu_ids = wp_get_post_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) ); $menu_id = 0; if ( $menu_ids && ! is_wp_error( $menu_ids ) ) { $menu_id = array_shift( $menu_ids ); } return $menu_id; } ``` | Uses | Description | | --- | --- | | [wp\_get\_post\_terms()](../../functions/wp_get_post_terms) wp-includes/post.php | Retrieves the terms for a post. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_database()](prepare_item_for_database) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post for create or update. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::create_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Menu\_Items\_Controller::create\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error =========================================================================================================== Creates a single post. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` public function create_item( $request ) { if ( ! empty( $request['id'] ) ) { return new WP_Error( 'rest_post_exists', __( 'Cannot create existing post.' ), array( 'status' => 400 ) ); } $prepared_nav_item = $this->prepare_item_for_database( $request ); if ( is_wp_error( $prepared_nav_item ) ) { return $prepared_nav_item; } $prepared_nav_item = (array) $prepared_nav_item; $nav_menu_item_id = wp_update_nav_menu_item( $prepared_nav_item['menu-id'], $prepared_nav_item['menu-item-db-id'], wp_slash( $prepared_nav_item ), false ); if ( is_wp_error( $nav_menu_item_id ) ) { if ( 'db_insert_error' === $nav_menu_item_id->get_error_code() ) { $nav_menu_item_id->add_data( array( 'status' => 500 ) ); } else { $nav_menu_item_id->add_data( array( 'status' => 400 ) ); } return $nav_menu_item_id; } $nav_menu_item = $this->get_nav_menu_item( $nav_menu_item_id ); if ( is_wp_error( $nav_menu_item ) ) { $nav_menu_item->add_data( array( 'status' => 404 ) ); return $nav_menu_item; } /** * Fires after a single menu item is created or updated via the REST API. * * @since 5.9.0 * * @param object $nav_menu_item Inserted or updated menu item object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a menu item, false when updating. */ do_action( 'rest_insert_nav_menu_item', $nav_menu_item, $request, true ); $schema = $this->get_item_schema(); if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { $meta_update = $this->meta->update_value( $request['meta'], $nav_menu_item_id ); if ( is_wp_error( $meta_update ) ) { return $meta_update; } } $nav_menu_item = $this->get_nav_menu_item( $nav_menu_item_id ); $fields_update = $this->update_additional_fields_for_object( $nav_menu_item, $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update; } $request->set_param( 'context', 'edit' ); /** * Fires after a single menu item is completely created or updated via the REST API. * * @since 5.9.0 * * @param object $nav_menu_item Inserted or updated menu item object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a menu item, false when updating. */ do_action( 'rest_after_insert_nav_menu_item', $nav_menu_item, $request, true ); $post = get_post( $nav_menu_item_id ); wp_after_insert_post( $post, false, null ); $response = $this->prepare_item_for_response( $post, $request ); $response = rest_ensure_response( $response ); $response->set_status( 201 ); $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $nav_menu_item_id ) ) ); return $response; } ``` [do\_action( 'rest\_after\_insert\_nav\_menu\_item', object $nav\_menu\_item, WP\_REST\_Request $request, bool $creating )](../../hooks/rest_after_insert_nav_menu_item) Fires after a single menu item is completely created or updated via the REST API. [do\_action( 'rest\_insert\_nav\_menu\_item', object $nav\_menu\_item, WP\_REST\_Request $request, bool $creating )](../../hooks/rest_insert_nav_menu_item) Fires after a single menu item is created or updated via the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Retrieves the term’s schema, conforming to JSON Schema. | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post output for response. | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_database()](prepare_item_for_database) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post for create or update. | | [WP\_REST\_Menu\_Items\_Controller::get\_nav\_menu\_item()](get_nav_menu_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Gets the nav menu item, if the ID is valid. | | [wp\_after\_insert\_post()](../../functions/wp_after_insert_post) wp-includes/post.php | Fires actions after a post, its terms and meta data has been saved. | | [wp\_update\_nav\_menu\_item()](../../functions/wp_update_nav_menu_item) wp-includes/nav-menu.php | Saves the properties of a menu item or create a new one. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_slash()](../../functions/wp_slash) wp-includes/formatting.php | Adds slashes to a string or recursively adds slashes to strings within an array. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::prepare_items_query( array $prepared_args = array(), WP_REST_Request $request = null ): array WP\_REST\_Menu\_Items\_Controller::prepare\_items\_query( array $prepared\_args = array(), WP\_REST\_Request $request = null ): array ===================================================================================================================================== Determines the allowed query\_vars for a get\_items() response and prepares them for [WP\_Query](../wp_query). `$prepared_args` array Optional Prepared [WP\_Query](../wp_query) arguments. Default: `array()` `$request` [WP\_REST\_Request](../wp_rest_request) Optional Full details about the request. Default: `null` array Items query arguments. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` protected function prepare_items_query( $prepared_args = array(), $request = null ) { $query_args = parent::prepare_items_query( $prepared_args, $request ); // Map to proper WP_Query orderby param. if ( isset( $query_args['orderby'], $request['orderby'] ) ) { $orderby_mappings = array( 'id' => 'ID', 'include' => 'post__in', 'slug' => 'post_name', 'include_slugs' => 'post_name__in', 'menu_order' => 'menu_order', ); if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { $query_args['orderby'] = $orderby_mappings[ $request['orderby'] ]; } } $query_args['update_menu_item_cache'] = true; return $query_args; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::prepare\_items\_query()](../wp_rest_posts_controller/prepare_items_query) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Determines the allowed query\_vars for a get\_items() response and prepares them for [WP\_Query](../wp_query). | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::update_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Menu\_Items\_Controller::update\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error =========================================================================================================== Updates a single nav menu item. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` public function update_item( $request ) { $valid_check = $this->get_nav_menu_item( $request['id'] ); if ( is_wp_error( $valid_check ) ) { return $valid_check; } $post_before = get_post( $request['id'] ); $prepared_nav_item = $this->prepare_item_for_database( $request ); if ( is_wp_error( $prepared_nav_item ) ) { return $prepared_nav_item; } $prepared_nav_item = (array) $prepared_nav_item; $nav_menu_item_id = wp_update_nav_menu_item( $prepared_nav_item['menu-id'], $prepared_nav_item['menu-item-db-id'], wp_slash( $prepared_nav_item ), false ); if ( is_wp_error( $nav_menu_item_id ) ) { if ( 'db_update_error' === $nav_menu_item_id->get_error_code() ) { $nav_menu_item_id->add_data( array( 'status' => 500 ) ); } else { $nav_menu_item_id->add_data( array( 'status' => 400 ) ); } return $nav_menu_item_id; } $nav_menu_item = $this->get_nav_menu_item( $nav_menu_item_id ); if ( is_wp_error( $nav_menu_item ) ) { $nav_menu_item->add_data( array( 'status' => 404 ) ); return $nav_menu_item; } /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php */ do_action( 'rest_insert_nav_menu_item', $nav_menu_item, $request, false ); $schema = $this->get_item_schema(); if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { $meta_update = $this->meta->update_value( $request['meta'], $nav_menu_item->ID ); if ( is_wp_error( $meta_update ) ) { return $meta_update; } } $post = get_post( $nav_menu_item_id ); $nav_menu_item = $this->get_nav_menu_item( $nav_menu_item_id ); $fields_update = $this->update_additional_fields_for_object( $nav_menu_item, $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update; } $request->set_param( 'context', 'edit' ); /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php */ do_action( 'rest_after_insert_nav_menu_item', $nav_menu_item, $request, false ); wp_after_insert_post( $post, true, $post_before ); $response = $this->prepare_item_for_response( get_post( $nav_menu_item_id ), $request ); return rest_ensure_response( $response ); } ``` [do\_action( 'rest\_after\_insert\_nav\_menu\_item', object $nav\_menu\_item, WP\_REST\_Request $request, bool $creating )](../../hooks/rest_after_insert_nav_menu_item) Fires after a single menu item is completely created or updated via the REST API. [do\_action( 'rest\_insert\_nav\_menu\_item', object $nav\_menu\_item, WP\_REST\_Request $request, bool $creating )](../../hooks/rest_insert_nav_menu_item) Fires after a single menu item is created or updated via the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Retrieves the term’s schema, conforming to JSON Schema. | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post output for response. | | [WP\_REST\_Menu\_Items\_Controller::get\_nav\_menu\_item()](get_nav_menu_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Gets the nav menu item, if the ID is valid. | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_database()](prepare_item_for_database) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post for create or update. | | [wp\_after\_insert\_post()](../../functions/wp_after_insert_post) wp-includes/post.php | Fires actions after a post, its terms and meta data has been saved. | | [wp\_update\_nav\_menu\_item()](../../functions/wp_update_nav_menu_item) wp-includes/nav-menu.php | Saves the properties of a menu item or create a new one. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [wp\_slash()](../../functions/wp_slash) wp-includes/formatting.php | Adds slashes to a string or recursively adds slashes to strings within an array. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::check_has_read_only_access( WP_REST_Request $request ): bool|WP_Error WP\_REST\_Menu\_Items\_Controller::check\_has\_read\_only\_access( WP\_REST\_Request $request ): bool|WP\_Error =============================================================================================================== Checks whether the current user has read permission for the endpoint. This allows for any user that can `edit_theme_options` or edit any REST API available post type. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. bool|[WP\_Error](../wp_error) Whether the current user has permission. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` protected function check_has_read_only_access( $request ) { if ( current_user_can( 'edit_theme_options' ) ) { return true; } if ( current_user_can( 'edit_posts' ) ) { return true; } foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) { if ( current_user_can( $post_type->cap->edit_posts ) ) { return true; } } return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to view menu items.' ), array( 'status' => rest_authorization_required_code() ) ); } ``` | Uses | Description | | --- | --- | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post\_types()](../../functions/get_post_types) wp-includes/post.php | Gets a list of all registered post type objects. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::get\_items\_permissions\_check()](get_items_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Checks if a given request has access to read menu items. | | [WP\_REST\_Menu\_Items\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Checks if a given request has access to read a menu item if they have access to edit them. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |
programming_docs
wordpress WP_REST_Menu_Items_Controller::prepare_item_for_database( WP_REST_Request $request ): object|WP_Error WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_database( WP\_REST\_Request $request ): object|WP\_Error =============================================================================================================== Prepares a single post for create or update. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request object. object|[WP\_Error](../wp_error) File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` protected function prepare_item_for_database( $request ) { $menu_item_db_id = $request['id']; $menu_item_obj = $this->get_nav_menu_item( $menu_item_db_id ); // Need to persist the menu item data. See https://core.trac.wordpress.org/ticket/28138 if ( ! is_wp_error( $menu_item_obj ) ) { // Correct the menu position if this was the first item. See https://core.trac.wordpress.org/ticket/28140 $position = ( 0 === $menu_item_obj->menu_order ) ? 1 : $menu_item_obj->menu_order; $prepared_nav_item = array( 'menu-item-db-id' => $menu_item_db_id, 'menu-item-object-id' => $menu_item_obj->object_id, 'menu-item-object' => $menu_item_obj->object, 'menu-item-parent-id' => $menu_item_obj->menu_item_parent, 'menu-item-position' => $position, 'menu-item-type' => $menu_item_obj->type, 'menu-item-title' => $menu_item_obj->title, 'menu-item-url' => $menu_item_obj->url, 'menu-item-description' => $menu_item_obj->description, 'menu-item-attr-title' => $menu_item_obj->attr_title, 'menu-item-target' => $menu_item_obj->target, 'menu-item-classes' => $menu_item_obj->classes, // Stored in the database as a string. 'menu-item-xfn' => explode( ' ', $menu_item_obj->xfn ), 'menu-item-status' => $menu_item_obj->post_status, 'menu-id' => $this->get_menu_id( $menu_item_db_id ), ); } else { $prepared_nav_item = array( 'menu-id' => 0, 'menu-item-db-id' => 0, 'menu-item-object-id' => 0, 'menu-item-object' => '', 'menu-item-parent-id' => 0, 'menu-item-position' => 1, 'menu-item-type' => 'custom', 'menu-item-title' => '', 'menu-item-url' => '', 'menu-item-description' => '', 'menu-item-attr-title' => '', 'menu-item-target' => '', 'menu-item-classes' => array(), 'menu-item-xfn' => array(), 'menu-item-status' => 'publish', ); } $mapping = array( 'menu-item-db-id' => 'id', 'menu-item-object-id' => 'object_id', 'menu-item-object' => 'object', 'menu-item-parent-id' => 'parent', 'menu-item-position' => 'menu_order', 'menu-item-type' => 'type', 'menu-item-url' => 'url', 'menu-item-description' => 'description', 'menu-item-attr-title' => 'attr_title', 'menu-item-target' => 'target', 'menu-item-classes' => 'classes', 'menu-item-xfn' => 'xfn', 'menu-item-status' => 'status', ); $schema = $this->get_item_schema(); foreach ( $mapping as $original => $api_request ) { if ( isset( $request[ $api_request ] ) ) { $prepared_nav_item[ $original ] = $request[ $api_request ]; } } $taxonomy = get_taxonomy( 'nav_menu' ); $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; // If menus submitted, cast to int. if ( ! empty( $request[ $base ] ) ) { $prepared_nav_item['menu-id'] = absint( $request[ $base ] ); } // Nav menu title. if ( ! empty( $schema['properties']['title'] ) && isset( $request['title'] ) ) { if ( is_string( $request['title'] ) ) { $prepared_nav_item['menu-item-title'] = $request['title']; } elseif ( ! empty( $request['title']['raw'] ) ) { $prepared_nav_item['menu-item-title'] = $request['title']['raw']; } } $error = new WP_Error(); // Check if object id exists before saving. if ( ! $prepared_nav_item['menu-item-object'] ) { // If taxonomy, check if term exists. if ( 'taxonomy' === $prepared_nav_item['menu-item-type'] ) { $original = get_term( absint( $prepared_nav_item['menu-item-object-id'] ) ); if ( empty( $original ) || is_wp_error( $original ) ) { $error->add( 'rest_term_invalid_id', __( 'Invalid term ID.' ), array( 'status' => 400 ) ); } else { $prepared_nav_item['menu-item-object'] = get_term_field( 'taxonomy', $original ); } // If post, check if post object exists. } elseif ( 'post_type' === $prepared_nav_item['menu-item-type'] ) { $original = get_post( absint( $prepared_nav_item['menu-item-object-id'] ) ); if ( empty( $original ) ) { $error->add( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 400 ) ); } else { $prepared_nav_item['menu-item-object'] = get_post_type( $original ); } } } // If post type archive, check if post type exists. if ( 'post_type_archive' === $prepared_nav_item['menu-item-type'] ) { $post_type = $prepared_nav_item['menu-item-object'] ? $prepared_nav_item['menu-item-object'] : false; $original = get_post_type_object( $post_type ); if ( ! $original ) { $error->add( 'rest_post_invalid_type', __( 'Invalid post type.' ), array( 'status' => 400 ) ); } } // Check if menu item is type custom, then title and url are required. if ( 'custom' === $prepared_nav_item['menu-item-type'] ) { if ( '' === $prepared_nav_item['menu-item-title'] ) { $error->add( 'rest_title_required', __( 'The title is required when using a custom menu item type.' ), array( 'status' => 400 ) ); } if ( empty( $prepared_nav_item['menu-item-url'] ) ) { $error->add( 'rest_url_required', __( 'The url is required when using a custom menu item type.' ), array( 'status' => 400 ) ); } } if ( $error->has_errors() ) { return $error; } // The xfn and classes properties are arrays, but passed to wp_update_nav_menu_item as a string. foreach ( array( 'menu-item-xfn', 'menu-item-classes' ) as $key ) { $prepared_nav_item[ $key ] = implode( ' ', $prepared_nav_item[ $key ] ); } // Only draft / publish are valid post status for menu items. if ( 'publish' !== $prepared_nav_item['menu-item-status'] ) { $prepared_nav_item['menu-item-status'] = 'draft'; } $prepared_nav_item = (object) $prepared_nav_item; /** * Filters a menu item before it is inserted via the REST API. * * @since 5.9.0 * * @param object $prepared_nav_item An object representing a single menu item prepared * for inserting or updating the database. * @param WP_REST_Request $request Request object. */ return apply_filters( 'rest_pre_insert_nav_menu_item', $prepared_nav_item, $request ); } ``` [apply\_filters( 'rest\_pre\_insert\_nav\_menu\_item', object $prepared\_nav\_item, WP\_REST\_Request $request )](../../hooks/rest_pre_insert_nav_menu_item) Filters a menu item before it is inserted via the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::get\_menu\_id()](get_menu_id) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Gets the id of the menu that the given menu item belongs to. | | [WP\_REST\_Menu\_Items\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Retrieves the term’s schema, conforming to JSON Schema. | | [WP\_REST\_Menu\_Items\_Controller::get\_nav\_menu\_item()](get_nav_menu_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Gets the nav menu item, if the ID is valid. | | [get\_term\_field()](../../functions/get_term_field) wp-includes/taxonomy.php | Gets sanitized term field. | | [get\_post\_type()](../../functions/get_post_type) wp-includes/post.php | Retrieves the post type of the current post or of a given post. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | [get\_taxonomy()](../../functions/get_taxonomy) wp-includes/taxonomy.php | Retrieves the taxonomy object of $taxonomy. | | [get\_term()](../../functions/get_term) wp-includes/taxonomy.php | Gets all term data from database by term ID. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Creates a single post. | | [WP\_REST\_Menu\_Items\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Updates a single nav menu item. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::get_items_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Menu\_Items\_Controller::get\_items\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error =============================================================================================================== Checks if a given request has access to read menu items. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` public function get_items_permissions_check( $request ) { $has_permission = parent::get_items_permissions_check( $request ); if ( true !== $has_permission ) { return $has_permission; } return $this->check_has_read_only_access( $request ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::check\_has\_read\_only\_access()](check_has_read_only_access) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Checks whether the current user has read permission for the endpoint. | | [WP\_REST\_Posts\_Controller::get\_items\_permissions\_check()](../wp_rest_posts_controller/get_items_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks if a given request has access to read posts. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::get_collection_params(): array WP\_REST\_Menu\_Items\_Controller::get\_collection\_params(): array =================================================================== Retrieves the query params for the posts collection. array Collection parameters. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` public function get_collection_params() { $query_params = parent::get_collection_params(); $query_params['menu_order'] = array( 'description' => __( 'Limit result set to posts with a specific menu_order value.' ), 'type' => 'integer', ); $query_params['order'] = array( 'description' => __( 'Order sort attribute ascending or descending.' ), 'type' => 'string', 'default' => 'asc', 'enum' => array( 'asc', 'desc' ), ); $query_params['orderby'] = array( 'description' => __( 'Sort collection by object attribute.' ), 'type' => 'string', 'default' => 'menu_order', 'enum' => array( 'author', 'date', 'id', 'include', 'modified', 'parent', 'relevance', 'slug', 'include_slugs', 'title', 'menu_order', ), ); // Change default to 100 items. $query_params['per_page']['default'] = 100; return $query_params; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::get\_collection\_params()](../wp_rest_posts_controller/get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves the query params for the posts collection. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::get_item_permissions_check( WP_REST_Request $request ): bool|WP_Error WP\_REST\_Menu\_Items\_Controller::get\_item\_permissions\_check( WP\_REST\_Request $request ): bool|WP\_Error ============================================================================================================== Checks if a given request has access to read a menu item if they have access to edit them. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. bool|[WP\_Error](../wp_error) True if the request has read access for the item, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` public function get_item_permissions_check( $request ) { $permission_check = parent::get_item_permissions_check( $request ); if ( true !== $permission_check ) { return $permission_check; } return $this->check_has_read_only_access( $request ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::check\_has\_read\_only\_access()](check_has_read_only_access) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Checks whether the current user has read permission for the endpoint. | | [WP\_REST\_Posts\_Controller::get\_item\_permissions\_check()](../wp_rest_posts_controller/get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks if a given request has access to read a post. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::delete_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Menu\_Items\_Controller::delete\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error =========================================================================================================== Deletes a single menu item. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) True on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` public function delete_item( $request ) { $menu_item = $this->get_nav_menu_item( $request['id'] ); if ( is_wp_error( $menu_item ) ) { return $menu_item; } // We don't support trashing for menu items. if ( ! $request['force'] ) { /* translators: %s: force=true */ return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Menu items do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); } $previous = $this->prepare_item_for_response( get_post( $request['id'] ), $request ); $result = wp_delete_post( $request['id'], true ); if ( ! $result ) { return new WP_Error( 'rest_cannot_delete', __( 'The post cannot be deleted.' ), array( 'status' => 500 ) ); } $response = new WP_REST_Response(); $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data(), ) ); /** * Fires immediately after a single menu item is deleted via the REST API. * * @since 5.9.0 * * @param object $nav_menu_item Inserted or updated menu item object. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request Request object. */ do_action( 'rest_delete_nav_menu_item', $menu_item, $response, $request ); return $response; } ``` [do\_action( 'rest\_delete\_nav\_menu\_item', object $nav\_menu\_item, WP\_REST\_Response $response, WP\_REST\_Request $request )](../../hooks/rest_delete_nav_menu_item) Fires immediately after a single menu item is deleted via the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post output for response. | | [WP\_REST\_Menu\_Items\_Controller::get\_nav\_menu\_item()](get_nav_menu_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Gets the nav menu item, if the ID is valid. | | [wp\_delete\_post()](../../functions/wp_delete_post) wp-includes/post.php | Trashes or deletes a post or page. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Menu_Items_Controller::get_item_schema(): array WP\_REST\_Menu\_Items\_Controller::get\_item\_schema(): array ============================================================= Retrieves the term’s schema, conforming to JSON Schema. array Item schema data. File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` public function get_item_schema() { $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => $this->post_type, 'type' => 'object', ); $schema['properties']['title'] = array( 'description' => __( 'The title for the object.' ), 'type' => array( 'string', 'object' ), 'context' => array( 'view', 'edit', 'embed' ), 'properties' => array( 'raw' => array( 'description' => __( 'Title for the object, as it exists in the database.' ), 'type' => 'string', 'context' => array( 'edit' ), ), 'rendered' => array( 'description' => __( 'HTML title for the object, transformed for display.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), ), ); $schema['properties']['id'] = array( 'description' => __( 'Unique identifier for the object.' ), 'type' => 'integer', 'default' => 0, 'minimum' => 0, 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ); $schema['properties']['type_label'] = array( 'description' => __( 'The singular label used to describe this type of menu item.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ); $schema['properties']['type'] = array( 'description' => __( 'The family of objects originally represented, such as "post_type" or "taxonomy".' ), 'type' => 'string', 'enum' => array( 'taxonomy', 'post_type', 'post_type_archive', 'custom' ), 'context' => array( 'view', 'edit', 'embed' ), 'default' => 'custom', ); $schema['properties']['status'] = array( 'description' => __( 'A named status for the object.' ), 'type' => 'string', 'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ), 'default' => 'publish', 'context' => array( 'view', 'edit', 'embed' ), ); $schema['properties']['parent'] = array( 'description' => __( 'The ID for the parent of the object.' ), 'type' => 'integer', 'minimum' => 0, 'default' => 0, 'context' => array( 'view', 'edit', 'embed' ), ); $schema['properties']['attr_title'] = array( 'description' => __( 'Text for the title attribute of the link element for this menu item.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => 'sanitize_text_field', ), ); $schema['properties']['classes'] = array( 'description' => __( 'Class names for the link element of this menu item.' ), 'type' => 'array', 'items' => array( 'type' => 'string', ), 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => function ( $value ) { return array_map( 'sanitize_html_class', wp_parse_list( $value ) ); }, ), ); $schema['properties']['description'] = array( 'description' => __( 'The description of this menu item.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => 'sanitize_text_field', ), ); $schema['properties']['menu_order'] = array( 'description' => __( 'The DB ID of the nav_menu_item that is this item\'s menu parent, if any, otherwise 0.' ), 'context' => array( 'view', 'edit', 'embed' ), 'type' => 'integer', 'minimum' => 1, 'default' => 1, ); $schema['properties']['object'] = array( 'description' => __( 'The type of object originally represented, such as "category", "post", or "attachment".' ), 'context' => array( 'view', 'edit', 'embed' ), 'type' => 'string', 'arg_options' => array( 'sanitize_callback' => 'sanitize_key', ), ); $schema['properties']['object_id'] = array( 'description' => __( 'The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories.' ), 'context' => array( 'view', 'edit', 'embed' ), 'type' => 'integer', 'minimum' => 0, 'default' => 0, ); $schema['properties']['target'] = array( 'description' => __( 'The target attribute of the link element for this menu item.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'enum' => array( '_blank', '', ), ); $schema['properties']['url'] = array( 'description' => __( 'The URL to which this menu item points.' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'validate_callback' => static function ( $url ) { if ( '' === $url ) { return true; } if ( sanitize_url( $url ) ) { return true; } return new WP_Error( 'rest_invalid_url', __( 'Invalid URL.' ) ); }, ), ); $schema['properties']['xfn'] = array( 'description' => __( 'The XFN relationship expressed in the link of this menu item.' ), 'type' => 'array', 'items' => array( 'type' => 'string', ), 'context' => array( 'view', 'edit', 'embed' ), 'arg_options' => array( 'sanitize_callback' => function ( $value ) { return array_map( 'sanitize_html_class', wp_parse_list( $value ) ); }, ), ); $schema['properties']['invalid'] = array( 'description' => __( 'Whether the menu item represents an object that no longer exists.' ), 'context' => array( 'view', 'edit', 'embed' ), 'type' => 'boolean', 'readonly' => true, ); $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); foreach ( $taxonomies as $taxonomy ) { $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; $schema['properties'][ $base ] = array( /* translators: %s: taxonomy name */ 'description' => sprintf( __( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ), 'type' => 'array', 'items' => array( 'type' => 'integer', ), 'context' => array( 'view', 'edit' ), ); if ( 'nav_menu' === $taxonomy->name ) { $schema['properties'][ $base ]['type'] = 'integer'; unset( $schema['properties'][ $base ]['items'] ); } } $schema['properties']['meta'] = $this->meta->get_field_schema(); $schema_links = $this->get_schema_links(); if ( $schema_links ) { $schema['links'] = $schema_links; } return $this->add_additional_fields_schema( $schema ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::get\_schema\_links()](get_schema_links) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Retrieves Link Description Objects that should be added to the Schema for the posts collection. | | [wp\_parse\_list()](../../functions/wp_parse_list) wp-includes/functions.php | Converts a comma- or space-separated list of scalar values to an array. | | [sanitize\_url()](../../functions/sanitize_url) wp-includes/formatting.php | Sanitizes a URL for database or redirect usage. | | [wp\_list\_filter()](../../functions/wp_list_filter) wp-includes/functions.php | Filters a list of objects, based on a set of key => value arguments. | | [get\_object\_taxonomies()](../../functions/get_object_taxonomies) wp-includes/taxonomy.php | Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name. | | [get\_post\_stati()](../../functions/get_post_stati) wp-includes/post.php | Gets a list of post statuses. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Creates a single post. | | [WP\_REST\_Menu\_Items\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Updates a single nav menu item. | | [WP\_REST\_Menu\_Items\_Controller::prepare\_item\_for\_database()](prepare_item_for_database) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post for create or update. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |
programming_docs
wordpress WP_REST_Menu_Items_Controller::get_schema_links(): array WP\_REST\_Menu\_Items\_Controller::get\_schema\_links(): array ============================================================== Retrieves Link Description Objects that should be added to the Schema for the posts collection. array File: `wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php/) ``` protected function get_schema_links() { $links = parent::get_schema_links(); $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" ); $links[] = array( 'rel' => 'https://api.w.org/menu-item-object', 'title' => __( 'Get linked object.' ), 'href' => $href, 'targetSchema' => array( 'type' => 'object', 'properties' => array( 'object' => array( 'type' => 'integer', ), ), ), ); return $links; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Posts\_Controller::get\_schema\_links()](../wp_rest_posts_controller/get_schema_links) wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves Link Description Objects that should be added to the Schema for the posts collection. | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_REST\_Menu\_Items\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Retrieves the term’s schema, conforming to JSON Schema. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress Bulk_Theme_Upgrader_Skin::after( string $title = '' ) Bulk\_Theme\_Upgrader\_Skin::after( string $title = '' ) ======================================================== `$title` string Optional Default: `''` File: `wp-admin/includes/class-bulk-theme-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-theme-upgrader-skin.php/) ``` public function after( $title = '' ) { parent::after( $this->theme_info->display( 'Name' ) ); $this->decrement_update_count( 'theme' ); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::after()](../bulk_upgrader_skin/after) wp-admin/includes/class-bulk-upgrader-skin.php | | wordpress Bulk_Theme_Upgrader_Skin::add_strings() Bulk\_Theme\_Upgrader\_Skin::add\_strings() =========================================== File: `wp-admin/includes/class-bulk-theme-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-theme-upgrader-skin.php/) ``` public function add_strings() { parent::add_strings(); /* translators: 1: Theme name, 2: Number of the theme, 3: Total number of themes being updated. */ $this->upgrader->strings['skin_before_update_header'] = __( 'Updating Theme %1$s (%2$d/%3$d)' ); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::add\_strings()](../bulk_upgrader_skin/add_strings) wp-admin/includes/class-bulk-upgrader-skin.php | | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | wordpress Bulk_Theme_Upgrader_Skin::bulk_footer() Bulk\_Theme\_Upgrader\_Skin::bulk\_footer() =========================================== File: `wp-admin/includes/class-bulk-theme-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-theme-upgrader-skin.php/) ``` public function bulk_footer() { parent::bulk_footer(); $update_actions = array( 'themes_page' => sprintf( '<a href="%s" target="_parent">%s</a>', self_admin_url( 'themes.php' ), __( 'Go to Themes page' ) ), 'updates_page' => sprintf( '<a href="%s" target="_parent">%s</a>', self_admin_url( 'update-core.php' ), __( 'Go to WordPress Updates page' ) ), ); if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) { unset( $update_actions['themes_page'] ); } /** * Filters the list of action links available following bulk theme updates. * * @since 3.0.0 * * @param string[] $update_actions Array of theme action links. * @param WP_Theme $theme_info Theme object for the last-updated theme. */ $update_actions = apply_filters( 'update_bulk_theme_complete_actions', $update_actions, $this->theme_info ); if ( ! empty( $update_actions ) ) { $this->feedback( implode( ' | ', (array) $update_actions ) ); } } ``` [apply\_filters( 'update\_bulk\_theme\_complete\_actions', string[] $update\_actions, WP\_Theme $theme\_info )](../../hooks/update_bulk_theme_complete_actions) Filters the list of action links available following bulk theme updates. | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::bulk\_footer()](../bulk_upgrader_skin/bulk_footer) wp-admin/includes/class-bulk-upgrader-skin.php | | | [self\_admin\_url()](../../functions/self_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for either the current site or the network depending on context. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | wordpress Bulk_Theme_Upgrader_Skin::before( string $title = '' ) Bulk\_Theme\_Upgrader\_Skin::before( string $title = '' ) ========================================================= `$title` string Optional Default: `''` File: `wp-admin/includes/class-bulk-theme-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-bulk-theme-upgrader-skin.php/) ``` public function before( $title = '' ) { parent::before( $this->theme_info->display( 'Name' ) ); } ``` | Uses | Description | | --- | --- | | [Bulk\_Upgrader\_Skin::before()](../bulk_upgrader_skin/before) wp-admin/includes/class-bulk-upgrader-skin.php | | wordpress WP_Term::to_array(): array WP\_Term::to\_array(): array ============================ Converts an object to array. array Object as array. File: `wp-includes/class-wp-term.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-term.php/) ``` public function to_array() { return get_object_vars( $this ); } ``` | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Term::__get( string $key ): mixed WP\_Term::\_\_get( string $key ): mixed ======================================= Getter. `$key` string Required Property to get. mixed Property value. File: `wp-includes/class-wp-term.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-term.php/) ``` public function __get( $key ) { switch ( $key ) { case 'data': $data = new stdClass(); $columns = array( 'term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count' ); foreach ( $columns as $column ) { $data->{$column} = isset( $this->{$column} ) ? $this->{$column} : null; } return sanitize_term( $data, $data->taxonomy, 'raw' ); } } ``` | Uses | Description | | --- | --- | | [sanitize\_term()](../../functions/sanitize_term) wp-includes/taxonomy.php | Sanitizes all term fields. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Term::__construct( WP_Term|object $term ) WP\_Term::\_\_construct( WP\_Term|object $term ) ================================================ Constructor. `$term` [WP\_Term](../wp_term)|object Required Term object. File: `wp-includes/class-wp-term.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-term.php/) ``` public function __construct( $term ) { foreach ( get_object_vars( $term ) as $key => $value ) { $this->$key = $value; } } ``` | Used By | Description | | --- | --- | | [WP\_Term::get\_instance()](get_instance) wp-includes/class-wp-term.php | Retrieve [WP\_Term](../wp_term) instance. | | [get\_term()](../../functions/get_term) wp-includes/taxonomy.php | Gets all term data from database by term ID. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Term::get_instance( int $term_id, string $taxonomy = null ): WP_Term|WP_Error|false WP\_Term::get\_instance( int $term\_id, string $taxonomy = null ): WP\_Term|WP\_Error|false =========================================================================================== Retrieve [WP\_Term](../wp_term) instance. `$term_id` int Required Term ID. `$taxonomy` string Optional Limit matched terms to those matching `$taxonomy`. Only used for disambiguating potentially shared terms. Default: `null` [WP\_Term](../wp_term)|[WP\_Error](../wp_error)|false Term object, if found. [WP\_Error](../wp_error) if `$term_id` is shared between taxonomies and there's insufficient data to distinguish which term is intended. False for other failures. File: `wp-includes/class-wp-term.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-term.php/) ``` public static function get_instance( $term_id, $taxonomy = null ) { global $wpdb; $term_id = (int) $term_id; if ( ! $term_id ) { return false; } $_term = wp_cache_get( $term_id, 'terms' ); // If there isn't a cached version, hit the database. if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) { // Any term found in the cache is not a match, so don't use it. $_term = false; // Grab all matching terms, in case any are shared between taxonomies. $terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id = %d", $term_id ) ); if ( ! $terms ) { return false; } // If a taxonomy was specified, find a match. if ( $taxonomy ) { foreach ( $terms as $match ) { if ( $taxonomy === $match->taxonomy ) { $_term = $match; break; } } // If only one match was found, it's the one we want. } elseif ( 1 === count( $terms ) ) { $_term = reset( $terms ); // Otherwise, the term must be shared between taxonomies. } else { // If the term is shared only with invalid taxonomies, return the one valid term. foreach ( $terms as $t ) { if ( ! taxonomy_exists( $t->taxonomy ) ) { continue; } // Only hit if we've already identified a term in a valid taxonomy. if ( $_term ) { return new WP_Error( 'ambiguous_term_id', __( 'Term ID is shared between multiple taxonomies' ), $term_id ); } $_term = $t; } } if ( ! $_term ) { return false; } // Don't return terms from invalid taxonomies. if ( ! taxonomy_exists( $_term->taxonomy ) ) { return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) ); } $_term = sanitize_term( $_term, $_term->taxonomy, 'raw' ); // Don't cache terms that are shared between taxonomies. if ( 1 === count( $terms ) ) { wp_cache_add( $term_id, $_term, 'terms' ); } } $term_obj = new WP_Term( $_term ); $term_obj->filter( $term_obj->filter ); return $term_obj; } ``` | Uses | Description | | --- | --- | | [WP\_Term::\_\_construct()](__construct) wp-includes/class-wp-term.php | Constructor. | | [wp\_cache\_add()](../../functions/wp_cache_add) wp-includes/cache.php | Adds data to the cache, if the cache key doesn’t already exist. | | [sanitize\_term()](../../functions/sanitize_term) wp-includes/taxonomy.php | Sanitizes all term fields. | | [taxonomy\_exists()](../../functions/taxonomy_exists) wp-includes/taxonomy.php | Determines whether the taxonomy name exists. | | [wp\_cache\_get()](../../functions/wp_cache_get) wp-includes/cache.php | Retrieves the cache contents from the cache by key and group. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wpdb::get\_results()](../wpdb/get_results) wp-includes/class-wpdb.php | Retrieves an entire SQL result set from the database (i.e., many rows). | | [wpdb::prepare()](../wpdb/prepare) wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [get\_term()](../../functions/get_term) wp-includes/taxonomy.php | Gets all term data from database by term ID. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Term::filter( string $filter ) WP\_Term::filter( string $filter ) ================================== Sanitizes term fields, according to the filter type provided. `$filter` string Required Filter context. Accepts `'edit'`, `'db'`, `'display'`, `'attribute'`, `'js'`, `'rss'`, or `'raw'`. File: `wp-includes/class-wp-term.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-term.php/) ``` public function filter( $filter ) { sanitize_term( $this, $this->taxonomy, $filter ); } ``` | Uses | Description | | --- | --- | | [sanitize\_term()](../../functions/sanitize_term) wp-includes/taxonomy.php | Sanitizes all term fields. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Feed_Cache_Transient::load(): mixed WP\_Feed\_Cache\_Transient::load(): mixed ========================================= Gets the transient. mixed Transient value. File: `wp-includes/class-wp-feed-cache-transient.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-feed-cache-transient.php/) ``` public function load() { return get_transient( $this->name ); } ``` | Uses | Description | | --- | --- | | [get\_transient()](../../functions/get_transient) wp-includes/option.php | Retrieves the value of a transient. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Feed_Cache_Transient::mtime(): mixed WP\_Feed\_Cache\_Transient::mtime(): mixed ========================================== Gets mod transient. mixed Transient value. File: `wp-includes/class-wp-feed-cache-transient.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-feed-cache-transient.php/) ``` public function mtime() { return get_transient( $this->mod_name ); } ``` | Uses | Description | | --- | --- | | [get\_transient()](../../functions/get_transient) wp-includes/option.php | Retrieves the value of a transient. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Feed_Cache_Transient::save( SimplePie $data ): true WP\_Feed\_Cache\_Transient::save( SimplePie $data ): true ========================================================= Sets the transient. `$data` SimplePie Required Data to save. true Always true. File: `wp-includes/class-wp-feed-cache-transient.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-feed-cache-transient.php/) ``` public function save( $data ) { if ( $data instanceof SimplePie ) { $data = $data->data; } set_transient( $this->name, $data, $this->lifetime ); set_transient( $this->mod_name, time(), $this->lifetime ); return true; } ``` | Uses | Description | | --- | --- | | [set\_transient()](../../functions/set_transient) wp-includes/option.php | Sets/updates the value of a transient. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Feed_Cache_Transient::__construct( string $location, string $filename, string $extension ) WP\_Feed\_Cache\_Transient::\_\_construct( string $location, string $filename, string $extension ) ================================================================================================== Constructor. `$location` string Required URL location (scheme is used to determine handler). `$filename` string Required Unique identifier for cache object. `$extension` string Required `'spi'` or `'spc'`. File: `wp-includes/class-wp-feed-cache-transient.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-feed-cache-transient.php/) ``` public function __construct( $location, $filename, $extension ) { $this->name = 'feed_' . $filename; $this->mod_name = 'feed_mod_' . $filename; $lifetime = $this->lifetime; /** * Filters the transient lifetime of the feed cache. * * @since 2.8.0 * * @param int $lifetime Cache duration in seconds. Default is 43200 seconds (12 hours). * @param string $filename Unique identifier for the cache object. */ $this->lifetime = apply_filters( 'wp_feed_cache_transient_lifetime', $lifetime, $filename ); } ``` [apply\_filters( 'wp\_feed\_cache\_transient\_lifetime', int $lifetime, string $filename )](../../hooks/wp_feed_cache_transient_lifetime) Filters the transient lifetime of the feed cache. | Uses | Description | | --- | --- | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Feed\_Cache::create()](../wp_feed_cache/create) wp-includes/class-wp-feed-cache.php | Creates a new SimplePie\_Cache object. | | Version | Description | | --- | --- | | [3.2.0](https://developer.wordpress.org/reference/since/3.2.0/) | Updated to use a PHP5 constructor. | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Feed_Cache_Transient::unlink(): true WP\_Feed\_Cache\_Transient::unlink(): true ========================================== Deletes transients. true Always true. File: `wp-includes/class-wp-feed-cache-transient.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-feed-cache-transient.php/) ``` public function unlink() { delete_transient( $this->name ); delete_transient( $this->mod_name ); return true; } ``` | Uses | Description | | --- | --- | | [delete\_transient()](../../functions/delete_transient) wp-includes/option.php | Deletes a transient. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Feed_Cache_Transient::touch(): bool WP\_Feed\_Cache\_Transient::touch(): bool ========================================= Sets mod transient. bool False if value was not set and true if value was set. File: `wp-includes/class-wp-feed-cache-transient.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-feed-cache-transient.php/) ``` public function touch() { return set_transient( $this->mod_name, time(), $this->lifetime ); } ``` | Uses | Description | | --- | --- | | [set\_transient()](../../functions/set_transient) wp-includes/option.php | Sets/updates the value of a transient. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |
programming_docs
wordpress WP_Network_Query::parse_order( string $order ): string WP\_Network\_Query::parse\_order( string $order ): string ========================================================= Parses an ‘order’ query variable and cast it to ‘ASC’ or ‘DESC’ as necessary. `$order` string Required The `'order'` query variable. string The sanitized `'order'` query variable. File: `wp-includes/class-wp-network-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network-query.php/) ``` protected function parse_order( $order ) { if ( ! is_string( $order ) || empty( $order ) ) { return 'ASC'; } if ( 'ASC' === strtoupper( $order ) ) { return 'ASC'; } else { return 'DESC'; } } ``` | Used By | Description | | --- | --- | | [WP\_Network\_Query::get\_network\_ids()](get_network_ids) wp-includes/class-wp-network-query.php | Used internally to get a list of network IDs matching the query vars. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Network_Query::get_network_ids(): int|array WP\_Network\_Query::get\_network\_ids(): int|array ================================================== Used internally to get a list of network IDs matching the query vars. int|array A single count of network IDs if a count query. An array of network IDs if a full query. File: `wp-includes/class-wp-network-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network-query.php/) ``` protected function get_network_ids() { global $wpdb; $order = $this->parse_order( $this->query_vars['order'] ); // Disable ORDER BY with 'none', an empty array, or boolean false. if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) { $orderby = ''; } elseif ( ! empty( $this->query_vars['orderby'] ) ) { $ordersby = is_array( $this->query_vars['orderby'] ) ? $this->query_vars['orderby'] : preg_split( '/[,\s]/', $this->query_vars['orderby'] ); $orderby_array = array(); foreach ( $ordersby as $_key => $_value ) { if ( ! $_value ) { continue; } if ( is_int( $_key ) ) { $_orderby = $_value; $_order = $order; } else { $_orderby = $_key; $_order = $_value; } $parsed = $this->parse_orderby( $_orderby ); if ( ! $parsed ) { continue; } if ( 'network__in' === $_orderby ) { $orderby_array[] = $parsed; continue; } $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); } $orderby = implode( ', ', $orderby_array ); } else { $orderby = "$wpdb->site.id $order"; } $number = absint( $this->query_vars['number'] ); $offset = absint( $this->query_vars['offset'] ); $limits = ''; if ( ! empty( $number ) ) { if ( $offset ) { $limits = 'LIMIT ' . $offset . ',' . $number; } else { $limits = 'LIMIT ' . $number; } } if ( $this->query_vars['count'] ) { $fields = 'COUNT(*)'; } else { $fields = "$wpdb->site.id"; } // Parse network IDs for an IN clause. if ( ! empty( $this->query_vars['network__in'] ) ) { $this->sql_clauses['where']['network__in'] = "$wpdb->site.id IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__in'] ) ) . ' )'; } // Parse network IDs for a NOT IN clause. if ( ! empty( $this->query_vars['network__not_in'] ) ) { $this->sql_clauses['where']['network__not_in'] = "$wpdb->site.id NOT IN ( " . implode( ',', wp_parse_id_list( $this->query_vars['network__not_in'] ) ) . ' )'; } if ( ! empty( $this->query_vars['domain'] ) ) { $this->sql_clauses['where']['domain'] = $wpdb->prepare( "$wpdb->site.domain = %s", $this->query_vars['domain'] ); } // Parse network domain for an IN clause. if ( is_array( $this->query_vars['domain__in'] ) ) { $this->sql_clauses['where']['domain__in'] = "$wpdb->site.domain IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__in'] ) ) . "' )"; } // Parse network domain for a NOT IN clause. if ( is_array( $this->query_vars['domain__not_in'] ) ) { $this->sql_clauses['where']['domain__not_in'] = "$wpdb->site.domain NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['domain__not_in'] ) ) . "' )"; } if ( ! empty( $this->query_vars['path'] ) ) { $this->sql_clauses['where']['path'] = $wpdb->prepare( "$wpdb->site.path = %s", $this->query_vars['path'] ); } // Parse network path for an IN clause. if ( is_array( $this->query_vars['path__in'] ) ) { $this->sql_clauses['where']['path__in'] = "$wpdb->site.path IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__in'] ) ) . "' )"; } // Parse network path for a NOT IN clause. if ( is_array( $this->query_vars['path__not_in'] ) ) { $this->sql_clauses['where']['path__not_in'] = "$wpdb->site.path NOT IN ( '" . implode( "', '", $wpdb->_escape( $this->query_vars['path__not_in'] ) ) . "' )"; } // Falsey search strings are ignored. if ( strlen( $this->query_vars['search'] ) ) { $this->sql_clauses['where']['search'] = $this->get_search_sql( $this->query_vars['search'], array( "$wpdb->site.domain", "$wpdb->site.path" ) ); } $join = ''; $where = implode( ' AND ', $this->sql_clauses['where'] ); $groupby = ''; $pieces = array( 'fields', 'join', 'where', 'orderby', 'limits', 'groupby' ); /** * Filters the network query clauses. * * @since 4.6.0 * * @param string[] $clauses An associative array of network query clauses. * @param WP_Network_Query $query Current instance of WP_Network_Query (passed by reference). */ $clauses = apply_filters_ref_array( 'networks_clauses', array( compact( $pieces ), &$this ) ); $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : ''; $join = isset( $clauses['join'] ) ? $clauses['join'] : ''; $where = isset( $clauses['where'] ) ? $clauses['where'] : ''; $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : ''; $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : ''; $groupby = isset( $clauses['groupby'] ) ? $clauses['groupby'] : ''; if ( $where ) { $where = 'WHERE ' . $where; } if ( $groupby ) { $groupby = 'GROUP BY ' . $groupby; } if ( $orderby ) { $orderby = "ORDER BY $orderby"; } $found_rows = ''; if ( ! $this->query_vars['no_found_rows'] ) { $found_rows = 'SQL_CALC_FOUND_ROWS'; } $this->sql_clauses['select'] = "SELECT $found_rows $fields"; $this->sql_clauses['from'] = "FROM $wpdb->site $join"; $this->sql_clauses['groupby'] = $groupby; $this->sql_clauses['orderby'] = $orderby; $this->sql_clauses['limits'] = $limits; $this->request = " {$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']} "; if ( $this->query_vars['count'] ) { return (int) $wpdb->get_var( $this->request ); } $network_ids = $wpdb->get_col( $this->request ); return array_map( 'intval', $network_ids ); } ``` [apply\_filters\_ref\_array( 'networks\_clauses', string[] $clauses, WP\_Network\_Query $query )](../../hooks/networks_clauses) Filters the network query clauses. | Uses | Description | | --- | --- | | [WP\_Network\_Query::parse\_order()](parse_order) wp-includes/class-wp-network-query.php | Parses an ‘order’ query variable and cast it to ‘ASC’ or ‘DESC’ as necessary. | | [WP\_Network\_Query::parse\_orderby()](parse_orderby) wp-includes/class-wp-network-query.php | Parses and sanitizes ‘orderby’ keys passed to the network query. | | [WP\_Network\_Query::get\_search\_sql()](get_search_sql) wp-includes/class-wp-network-query.php | Used internally to generate an SQL string for searching across multiple columns. | | [wp\_parse\_id\_list()](../../functions/wp_parse_id_list) wp-includes/functions.php | Cleans up an array, comma- or space-separated list of IDs. | | [apply\_filters\_ref\_array()](../../functions/apply_filters_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook, specifying arguments in an array. | | [wpdb::get\_col()](../wpdb/get_col) wp-includes/class-wpdb.php | Retrieves one column from the database. | | [wpdb::\_escape()](../wpdb/_escape) wp-includes/class-wpdb.php | Escapes data. Works on arrays. | | [absint()](../../functions/absint) wp-includes/functions.php | Converts a value to non-negative integer. | | [wpdb::get\_var()](../wpdb/get_var) wp-includes/class-wpdb.php | Retrieves one variable from the database. | | [wpdb::prepare()](../wpdb/prepare) wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. | | Used By | Description | | --- | --- | | [WP\_Network\_Query::get\_networks()](get_networks) wp-includes/class-wp-network-query.php | Gets a list of networks matching the query vars. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Network_Query::parse_orderby( string $orderby ): string|false WP\_Network\_Query::parse\_orderby( string $orderby ): string|false =================================================================== Parses and sanitizes ‘orderby’ keys passed to the network query. `$orderby` string Required Alias for the field to order by. string|false Value to used in the ORDER clause. False otherwise. File: `wp-includes/class-wp-network-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network-query.php/) ``` protected function parse_orderby( $orderby ) { global $wpdb; $allowed_keys = array( 'id', 'domain', 'path', ); $parsed = false; if ( 'network__in' === $orderby ) { $network__in = implode( ',', array_map( 'absint', $this->query_vars['network__in'] ) ); $parsed = "FIELD( {$wpdb->site}.id, $network__in )"; } elseif ( 'domain_length' === $orderby || 'path_length' === $orderby ) { $field = substr( $orderby, 0, -7 ); $parsed = "CHAR_LENGTH($wpdb->site.$field)"; } elseif ( in_array( $orderby, $allowed_keys, true ) ) { $parsed = "$wpdb->site.$orderby"; } return $parsed; } ``` | Used By | Description | | --- | --- | | [WP\_Network\_Query::get\_network\_ids()](get_network_ids) wp-includes/class-wp-network-query.php | Used internally to get a list of network IDs matching the query vars. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Network_Query::set_found_networks() WP\_Network\_Query::set\_found\_networks() ========================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Populates found\_networks and max\_num\_pages properties for the current query if the limit clause was used. File: `wp-includes/class-wp-network-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network-query.php/) ``` private function set_found_networks() { global $wpdb; if ( $this->query_vars['number'] && ! $this->query_vars['no_found_rows'] ) { /** * Filters the query used to retrieve found network count. * * @since 4.6.0 * * @param string $found_networks_query SQL query. Default 'SELECT FOUND_ROWS()'. * @param WP_Network_Query $network_query The `WP_Network_Query` instance. */ $found_networks_query = apply_filters( 'found_networks_query', 'SELECT FOUND_ROWS()', $this ); $this->found_networks = (int) $wpdb->get_var( $found_networks_query ); } } ``` [apply\_filters( 'found\_networks\_query', string $found\_networks\_query, WP\_Network\_Query $network\_query )](../../hooks/found_networks_query) Filters the query used to retrieve found network count. | Uses | Description | | --- | --- | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [wpdb::get\_var()](../wpdb/get_var) wp-includes/class-wpdb.php | Retrieves one variable from the database. | | Used By | Description | | --- | --- | | [WP\_Network\_Query::get\_networks()](get_networks) wp-includes/class-wp-network-query.php | Gets a list of networks matching the query vars. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Network_Query::query( string|array $query ): array|int WP\_Network\_Query::query( string|array $query ): array|int =========================================================== Sets up the WordPress query for retrieving networks. `$query` string|array Required Array or URL query string of parameters. array|int List of [WP\_Network](../wp_network) objects, a list of network IDs when `'fields'` is set to `'ids'`, or the number of networks when `'count'` is passed as a query var. File: `wp-includes/class-wp-network-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network-query.php/) ``` public function query( $query ) { $this->query_vars = wp_parse_args( $query ); return $this->get_networks(); } ``` | Uses | Description | | --- | --- | | [WP\_Network\_Query::get\_networks()](get_networks) wp-includes/class-wp-network-query.php | Gets a list of networks matching the query vars. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Used By | Description | | --- | --- | | [WP\_Network\_Query::\_\_construct()](__construct) wp-includes/class-wp-network-query.php | Constructor. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Network_Query::parse_query( string|array $query = '' ) WP\_Network\_Query::parse\_query( string|array $query = '' ) ============================================================ Parses arguments passed to the network query with default query parameters. `$query` string|array Optional [WP\_Network\_Query](../wp_network_query) arguments. See [WP\_Network\_Query::\_\_construct()](__construct) More Arguments from WP\_Network\_Query::\_\_construct( ... $query ) Array or query string of network query parameters. * `network__in`int[]Array of network IDs to include. * `network__not_in`int[]Array of network IDs to exclude. * `count`boolWhether to return a network count (true) or array of network objects. Default false. * `fields`stringNetwork fields to return. Accepts `'ids'` (returns an array of network IDs) or empty (returns an array of complete network objects). * `number`intMaximum number of networks to retrieve. Default empty (no limit). * `offset`intNumber of networks to offset the query. Used to build LIMIT clause. Default 0. * `no_found_rows`boolWhether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. * `orderby`string|arrayNetwork status or array of statuses. Accepts `'id'`, `'domain'`, `'path'`, `'domain_length'`, `'path_length'` and `'network__in'`. Also accepts false, an empty array, or `'none'` to disable `ORDER BY` clause. Default `'id'`. * `order`stringHow to order retrieved networks. Accepts `'ASC'`, `'DESC'`. Default `'ASC'`. * `domain`stringLimit results to those affiliated with a given domain. * `domain__in`string[]Array of domains to include affiliated networks for. * `domain__not_in`string[]Array of domains to exclude affiliated networks for. * `path`stringLimit results to those affiliated with a given path. * `path__in`string[]Array of paths to include affiliated networks for. * `path__not_in`string[]Array of paths to exclude affiliated networks for. * `search`stringSearch term(s) to retrieve matching networks for. * `update_network_cache`boolWhether to prime the cache for found networks. Default true. Default: `''` File: `wp-includes/class-wp-network-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network-query.php/) ``` public function parse_query( $query = '' ) { if ( empty( $query ) ) { $query = $this->query_vars; } $this->query_vars = wp_parse_args( $query, $this->query_var_defaults ); /** * Fires after the network query vars have been parsed. * * @since 4.6.0 * * @param WP_Network_Query $query The WP_Network_Query instance (passed by reference). */ do_action_ref_array( 'parse_network_query', array( &$this ) ); } ``` [do\_action\_ref\_array( 'parse\_network\_query', WP\_Network\_Query $query )](../../hooks/parse_network_query) Fires after the network query vars have been parsed. | Uses | Description | | --- | --- | | [do\_action\_ref\_array()](../../functions/do_action_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook, specifying arguments in an array. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Used By | Description | | --- | --- | | [WP\_Network\_Query::get\_networks()](get_networks) wp-includes/class-wp-network-query.php | Gets a list of networks matching the query vars. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Network_Query::get_search_sql( string $search, string[] $columns ): string WP\_Network\_Query::get\_search\_sql( string $search, string[] $columns ): string ================================================================================= Used internally to generate an SQL string for searching across multiple columns. `$search` string Required Search string. `$columns` string[] Required Array of columns to search. string Search SQL. File: `wp-includes/class-wp-network-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network-query.php/) ``` protected function get_search_sql( $search, $columns ) { global $wpdb; $like = '%' . $wpdb->esc_like( $search ) . '%'; $searches = array(); foreach ( $columns as $column ) { $searches[] = $wpdb->prepare( "$column LIKE %s", $like ); } return '(' . implode( ' OR ', $searches ) . ')'; } ``` | Uses | Description | | --- | --- | | [wpdb::esc\_like()](../wpdb/esc_like) wp-includes/class-wpdb.php | First half of escaping for `LIKE` special characters `%` and `_` before preparing for SQL. | | [wpdb::prepare()](../wpdb/prepare) wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. | | Used By | Description | | --- | --- | | [WP\_Network\_Query::get\_network\_ids()](get_network_ids) wp-includes/class-wp-network-query.php | Used internally to get a list of network IDs matching the query vars. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Network_Query::__construct( string|array $query = '' ) WP\_Network\_Query::\_\_construct( string|array $query = '' ) ============================================================= Constructor. Sets up the network query, based on the query vars passed. `$query` string|array Optional Array or query string of network query parameters. * `network__in`int[]Array of network IDs to include. * `network__not_in`int[]Array of network IDs to exclude. * `count`boolWhether to return a network count (true) or array of network objects. Default false. * `fields`stringNetwork fields to return. Accepts `'ids'` (returns an array of network IDs) or empty (returns an array of complete network objects). * `number`intMaximum number of networks to retrieve. Default empty (no limit). * `offset`intNumber of networks to offset the query. Used to build LIMIT clause. Default 0. * `no_found_rows`boolWhether to disable the `SQL_CALC_FOUND_ROWS` query. Default true. * `orderby`string|arrayNetwork status or array of statuses. Accepts `'id'`, `'domain'`, `'path'`, `'domain_length'`, `'path_length'` and `'network__in'`. Also accepts false, an empty array, or `'none'` to disable `ORDER BY` clause. Default `'id'`. * `order`stringHow to order retrieved networks. Accepts `'ASC'`, `'DESC'`. Default `'ASC'`. * `domain`stringLimit results to those affiliated with a given domain. * `domain__in`string[]Array of domains to include affiliated networks for. * `domain__not_in`string[]Array of domains to exclude affiliated networks for. * `path`stringLimit results to those affiliated with a given path. * `path__in`string[]Array of paths to include affiliated networks for. * `path__not_in`string[]Array of paths to exclude affiliated networks for. * `search`stringSearch term(s) to retrieve matching networks for. * `update_network_cache`boolWhether to prime the cache for found networks. Default true. Default: `''` File: `wp-includes/class-wp-network-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network-query.php/) ``` public function __construct( $query = '' ) { $this->query_var_defaults = array( 'network__in' => '', 'network__not_in' => '', 'count' => false, 'fields' => '', 'number' => '', 'offset' => '', 'no_found_rows' => true, 'orderby' => 'id', 'order' => 'ASC', 'domain' => '', 'domain__in' => '', 'domain__not_in' => '', 'path' => '', 'path__in' => '', 'path__not_in' => '', 'search' => '', 'update_network_cache' => true, ); if ( ! empty( $query ) ) { $this->query( $query ); } } ``` | Uses | Description | | --- | --- | | [WP\_Network\_Query::query()](query) wp-includes/class-wp-network-query.php | Sets up the WordPress query for retrieving networks. | | Used By | Description | | --- | --- | | [WP\_Debug\_Data::debug\_data()](../wp_debug_data/debug_data) wp-admin/includes/class-wp-debug-data.php | Static function for generating site debug data when required. | | [get\_networks()](../../functions/get_networks) wp-includes/ms-network.php | Retrieves a list of networks. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. |
programming_docs
wordpress WP_Network_Query::get_networks(): array|int WP\_Network\_Query::get\_networks(): array|int ============================================== Gets a list of networks matching the query vars. array|int List of [WP\_Network](../wp_network) objects, a list of network IDs when `'fields'` is set to `'ids'`, or the number of networks when `'count'` is passed as a query var. File: `wp-includes/class-wp-network-query.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network-query.php/) ``` public function get_networks() { $this->parse_query(); /** * Fires before networks are retrieved. * * @since 4.6.0 * * @param WP_Network_Query $query Current instance of WP_Network_Query (passed by reference). */ do_action_ref_array( 'pre_get_networks', array( &$this ) ); $network_data = null; /** * Filters the network data before the query takes place. * * Return a non-null value to bypass WordPress' default network queries. * * The expected return type from this filter depends on the value passed * in the request query vars: * - When `$this->query_vars['count']` is set, the filter should return * the network count as an integer. * - When `'ids' === $this->query_vars['fields']`, the filter should return * an array of network IDs. * - Otherwise the filter should return an array of WP_Network objects. * * Note that if the filter returns an array of network data, it will be assigned * to the `networks` property of the current WP_Network_Query instance. * * Filtering functions that require pagination information are encouraged to set * the `found_networks` and `max_num_pages` properties of the WP_Network_Query object, * passed to the filter by reference. If WP_Network_Query does not perform a database * query, it will not have enough information to generate these values itself. * * @since 5.2.0 * @since 5.6.0 The returned array of network data is assigned to the `networks` property * of the current WP_Network_Query instance. * * @param array|int|null $network_data Return an array of network data to short-circuit WP's network query, * the network count as an integer if `$this->query_vars['count']` is set, * or null to allow WP to run its normal queries. * @param WP_Network_Query $query The WP_Network_Query instance, passed by reference. */ $network_data = apply_filters_ref_array( 'networks_pre_query', array( $network_data, &$this ) ); if ( null !== $network_data ) { if ( is_array( $network_data ) && ! $this->query_vars['count'] ) { $this->networks = $network_data; } return $network_data; } // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. $_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ); // Ignore the $fields, $update_network_cache arguments as the queried result will be the same regardless. unset( $_args['fields'], $_args['update_network_cache'] ); $key = md5( serialize( $_args ) ); $last_changed = wp_cache_get_last_changed( 'networks' ); $cache_key = "get_network_ids:$key:$last_changed"; $cache_value = wp_cache_get( $cache_key, 'networks' ); if ( false === $cache_value ) { $network_ids = $this->get_network_ids(); if ( $network_ids ) { $this->set_found_networks(); } $cache_value = array( 'network_ids' => $network_ids, 'found_networks' => $this->found_networks, ); wp_cache_add( $cache_key, $cache_value, 'networks' ); } else { $network_ids = $cache_value['network_ids']; $this->found_networks = $cache_value['found_networks']; } if ( $this->found_networks && $this->query_vars['number'] ) { $this->max_num_pages = ceil( $this->found_networks / $this->query_vars['number'] ); } // If querying for a count only, there's nothing more to do. if ( $this->query_vars['count'] ) { // $network_ids is actually a count in this case. return (int) $network_ids; } $network_ids = array_map( 'intval', $network_ids ); if ( 'ids' === $this->query_vars['fields'] ) { $this->networks = $network_ids; return $this->networks; } if ( $this->query_vars['update_network_cache'] ) { _prime_network_caches( $network_ids ); } // Fetch full network objects from the primed cache. $_networks = array(); foreach ( $network_ids as $network_id ) { $_network = get_network( $network_id ); if ( $_network ) { $_networks[] = $_network; } } /** * Filters the network query results. * * @since 4.6.0 * * @param WP_Network[] $_networks An array of WP_Network objects. * @param WP_Network_Query $query Current instance of WP_Network_Query (passed by reference). */ $_networks = apply_filters_ref_array( 'the_networks', array( $_networks, &$this ) ); // Convert to WP_Network instances. $this->networks = array_map( 'get_network', $_networks ); return $this->networks; } ``` [apply\_filters\_ref\_array( 'networks\_pre\_query', array|int|null $network\_data, WP\_Network\_Query $query )](../../hooks/networks_pre_query) Filters the network data before the query takes place. [do\_action\_ref\_array( 'pre\_get\_networks', WP\_Network\_Query $query )](../../hooks/pre_get_networks) Fires before networks are retrieved. [apply\_filters\_ref\_array( 'the\_networks', WP\_Network[] $\_networks, WP\_Network\_Query $query )](../../hooks/the_networks) Filters the network query results. | Uses | Description | | --- | --- | | [wp\_cache\_get\_last\_changed()](../../functions/wp_cache_get_last_changed) wp-includes/functions.php | Gets last changed date for the specified cache group. | | [WP\_Network\_Query::set\_found\_networks()](set_found_networks) wp-includes/class-wp-network-query.php | Populates found\_networks and max\_num\_pages properties for the current query if the limit clause was used. | | [WP\_Network\_Query::get\_network\_ids()](get_network_ids) wp-includes/class-wp-network-query.php | Used internally to get a list of network IDs matching the query vars. | | [WP\_Network\_Query::parse\_query()](parse_query) wp-includes/class-wp-network-query.php | Parses arguments passed to the network query with default query parameters. | | [\_prime\_network\_caches()](../../functions/_prime_network_caches) wp-includes/ms-network.php | Adds any networks from the given IDs to the cache that do not already exist in cache. | | [get\_network()](../../functions/get_network) wp-includes/ms-network.php | Retrieves network data given a network ID or network object. | | [wp\_cache\_add()](../../functions/wp_cache_add) wp-includes/cache.php | Adds data to the cache, if the cache key doesn’t already exist. | | [wp\_array\_slice\_assoc()](../../functions/wp_array_slice_assoc) wp-includes/functions.php | Extracts a slice of an array, given a list of keys. | | [do\_action\_ref\_array()](../../functions/do_action_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook, specifying arguments in an array. | | [apply\_filters\_ref\_array()](../../functions/apply_filters_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook, specifying arguments in an array. | | [wp\_cache\_get()](../../functions/wp_cache_get) wp-includes/cache.php | Retrieves the cache contents from the cache by key and group. | | Used By | Description | | --- | --- | | [WP\_Network\_Query::query()](query) wp-includes/class-wp-network-query.php | Sets up the WordPress query for retrieving networks. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Customize_Background_Position_Control::content_template() WP\_Customize\_Background\_Position\_Control::content\_template() ================================================================= Render a JS template for the content of the position control. File: `wp-includes/customize/class-wp-customize-background-position-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-background-position-control.php/) ``` public function content_template() { $options = array( array( 'left top' => array( 'label' => __( 'Top Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt', ), 'center top' => array( 'label' => __( 'Top' ), 'icon' => 'dashicons dashicons-arrow-up-alt', ), 'right top' => array( 'label' => __( 'Top Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt', ), ), array( 'left center' => array( 'label' => __( 'Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt', ), 'center center' => array( 'label' => __( 'Center' ), 'icon' => 'background-position-center-icon', ), 'right center' => array( 'label' => __( 'Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt', ), ), array( 'left bottom' => array( 'label' => __( 'Bottom Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt', ), 'center bottom' => array( 'label' => __( 'Bottom' ), 'icon' => 'dashicons dashicons-arrow-down-alt', ), 'right bottom' => array( 'label' => __( 'Bottom Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt', ), ), ); ?> <# if ( data.label ) { #> <span class="customize-control-title">{{{ data.label }}}</span> <# } #> <# if ( data.description ) { #> <span class="description customize-control-description">{{{ data.description }}}</span> <# } #> <div class="customize-control-content"> <fieldset> <legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend> <div class="background-position-control"> <?php foreach ( $options as $group ) : ?> <div class="button-group"> <?php foreach ( $group as $value => $input ) : ?> <label> <input class="ui-helper-hidden-accessible" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>"> <span class="button display-options position"><span class="<?php echo esc_attr( $input['icon'] ); ?>" aria-hidden="true"></span></span> <span class="screen-reader-text"><?php echo $input['label']; ?></span> </label> <?php endforeach; ?> </div> <?php endforeach; ?> </div> </fieldset> </div> <?php } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Background_Position_Control::render_content() WP\_Customize\_Background\_Position\_Control::render\_content() =============================================================== Don’t render the control content from PHP, as it’s rendered via JS on load. File: `wp-includes/customize/class-wp-customize-background-position-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-background-position-control.php/) ``` public function render_content() {} ``` | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::chmod( string $file, int|false $mode = false, bool $recursive = false ): bool WP\_Filesystem\_ftpsockets::chmod( string $file, int|false $mode = false, bool $recursive = false ): bool ========================================================================================================= Changes filesystem permissions. `$file` string Required Path to the file. `$mode` int|false Optional The permissions as octal number, usually 0644 for files, 0755 for directories. Default: `false` `$recursive` bool Optional If set to true, changes file permissions recursively. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function chmod( $file, $mode = false, $recursive = false ) { if ( ! $mode ) { if ( $this->is_file( $file ) ) { $mode = FS_CHMOD_FILE; } elseif ( $this->is_dir( $file ) ) { $mode = FS_CHMOD_DIR; } else { return false; } } // chmod any sub-objects if recursive. if ( $recursive && $this->is_dir( $file ) ) { $filelist = $this->dirlist( $file ); foreach ( (array) $filelist as $filename => $filemeta ) { $this->chmod( $file . '/' . $filename, $mode, $recursive ); } } // chmod the file or directory. return $this->ftp->chmod( $file, $mode ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_ftpsockets::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a file. | | [WP\_Filesystem\_ftpsockets::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a directory. | | [WP\_Filesystem\_ftpsockets::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Changes filesystem permissions. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::mkdir()](mkdir) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Creates a directory. | | [WP\_Filesystem\_ftpsockets::put\_contents()](put_contents) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Writes a string to a file. | | [WP\_Filesystem\_ftpsockets::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Changes filesystem permissions. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::size( string $file ): int|false WP\_Filesystem\_ftpsockets::size( string $file ): int|false =========================================================== Gets the file size (in bytes). `$file` string Required Path to file. int|false Size of the file in bytes on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function size( $file ) { return $this->ftp->filesize( $file ); } ``` | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::exists()](exists) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if a file or directory exists. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::getchmod( string $file ): string WP\_Filesystem\_ftpsockets::getchmod( string $file ): string ============================================================ Gets the permissions of the specified file or filepath in their octal format. `$file` string Required Path to the file. string Mode of the file (the last 3 digits). File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function getchmod( $file ) { $dir = $this->dirlist( $file ); return $dir[ $file ]['permsn']; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::__destruct() WP\_Filesystem\_ftpsockets::\_\_destruct() ========================================== Destructor. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function __destruct() { $this->ftp->quit(); } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::exists( string $path ): bool WP\_Filesystem\_ftpsockets::exists( string $path ): bool ======================================================== Checks if a file or directory exists. `$path` string Required Path to file or directory. bool Whether $path exists or not. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function exists( $path ) { if ( $this->is_dir( $path ) ) { return true; } return is_numeric( $this->size( $path ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a directory. | | [WP\_Filesystem\_ftpsockets::size()](size) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets the file size (in bytes). | | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_ftpsockets::copy()](copy) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Copies a file. | | [WP\_Filesystem\_ftpsockets::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a file. | | [WP\_Filesystem\_ftpsockets::get\_contents()](get_contents) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Reads entire file into a string. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Uses [WP\_Filesystem\_ftpsockets::is\_dir()](is_dir) to check for directory existence and file size to check for file existence. | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::chdir( string $dir ): bool WP\_Filesystem\_ftpsockets::chdir( string $dir ): bool ====================================================== Changes current directory. `$dir` string Required The new current directory. bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function chdir( $dir ) { return $this->ftp->chdir( $dir ); } ``` | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a directory. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::rmdir( string $path, bool $recursive = false ): bool WP\_Filesystem\_ftpsockets::rmdir( string $path, bool $recursive = false ): bool ================================================================================ Deletes a directory. `$path` string Required Path to directory. `$recursive` bool Optional Whether to recursively remove files/directories. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function rmdir( $path, $recursive = false ) { return $this->delete( $path, $recursive ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::delete()](delete) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |
programming_docs
wordpress WP_Filesystem_ftpsockets::get_contents( string $file ): string|false WP\_Filesystem\_ftpsockets::get\_contents( string $file ): string|false ======================================================================= Reads entire file into a string. `$file` string Required Name of the file to read. string|false Read data on success, false if no temporary file could be opened, or if the file couldn't be retrieved. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function get_contents( $file ) { if ( ! $this->exists( $file ) ) { return false; } $tempfile = wp_tempnam( $file ); $temphandle = fopen( $tempfile, 'w+' ); if ( ! $temphandle ) { unlink( $tempfile ); return false; } mbstring_binary_safe_encoding(); if ( ! $this->ftp->fget( $temphandle, $file ) ) { fclose( $temphandle ); unlink( $tempfile ); reset_mbstring_encoding(); return ''; // Blank document. File does exist, it's just blank. } reset_mbstring_encoding(); fseek( $temphandle, 0 ); // Skip back to the start of the file being written to. $contents = ''; while ( ! feof( $temphandle ) ) { $contents .= fread( $temphandle, 8 * KB_IN_BYTES ); } fclose( $temphandle ); unlink( $tempfile ); return $contents; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::exists()](exists) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if a file or directory exists. | | [wp\_tempnam()](../../functions/wp_tempnam) wp-admin/includes/file.php | Returns a filename of a temporary unique file. | | [mbstring\_binary\_safe\_encoding()](../../functions/mbstring_binary_safe_encoding) wp-includes/functions.php | Sets the mbstring internal encoding to a binary safe encoding when func\_overload is enabled. | | [reset\_mbstring\_encoding()](../../functions/reset_mbstring_encoding) wp-includes/functions.php | Resets the mbstring internal encoding to a users previously set encoding. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::copy()](copy) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Copies a file. | | [WP\_Filesystem\_ftpsockets::get\_contents\_array()](get_contents_array) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Reads entire file into an array. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::is_writable( string $path ): bool WP\_Filesystem\_ftpsockets::is\_writable( string $path ): bool ============================================================== Checks if a file or directory is writable. `$path` string Required Path to file or directory. bool Whether $path is writable. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function is_writable( $path ) { return true; } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::group( string $file ): string|false WP\_Filesystem\_ftpsockets::group( string $file ): string|false =============================================================== Gets the file’s group. `$file` string Required Path to the file. string|false The group on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function group( $file ) { $dir = $this->dirlist( $file ); return $dir[ $file ]['group']; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::put_contents( string $file, string $contents, int|false $mode = false ): bool WP\_Filesystem\_ftpsockets::put\_contents( string $file, string $contents, int|false $mode = false ): bool ========================================================================================================== Writes a string to a file. `$file` string Required Remote path to the file where to write the data. `$contents` string Required The data to write. `$mode` int|false Optional The file permissions as octal number, usually 0644. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function put_contents( $file, $contents, $mode = false ) { $tempfile = wp_tempnam( $file ); $temphandle = @fopen( $tempfile, 'w+' ); if ( ! $temphandle ) { unlink( $tempfile ); return false; } // The FTP class uses string functions internally during file download/upload. mbstring_binary_safe_encoding(); $bytes_written = fwrite( $temphandle, $contents ); if ( false === $bytes_written || strlen( $contents ) !== $bytes_written ) { fclose( $temphandle ); unlink( $tempfile ); reset_mbstring_encoding(); return false; } fseek( $temphandle, 0 ); // Skip back to the start of the file being written to. $ret = $this->ftp->fput( $file, $temphandle ); reset_mbstring_encoding(); fclose( $temphandle ); unlink( $tempfile ); $this->chmod( $file, $mode ); return $ret; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Changes filesystem permissions. | | [wp\_tempnam()](../../functions/wp_tempnam) wp-admin/includes/file.php | Returns a filename of a temporary unique file. | | [mbstring\_binary\_safe\_encoding()](../../functions/mbstring_binary_safe_encoding) wp-includes/functions.php | Sets the mbstring internal encoding to a binary safe encoding when func\_overload is enabled. | | [reset\_mbstring\_encoding()](../../functions/reset_mbstring_encoding) wp-includes/functions.php | Resets the mbstring internal encoding to a users previously set encoding. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::copy()](copy) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Copies a file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::is_dir( string $path ): bool WP\_Filesystem\_ftpsockets::is\_dir( string $path ): bool ========================================================= Checks if resource is a directory. `$path` string Required Directory path. bool Whether $path is a directory. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function is_dir( $path ) { $cwd = $this->cwd(); if ( $this->chdir( $path ) ) { $this->chdir( $cwd ); return true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::cwd()](cwd) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets the current working directory. | | [WP\_Filesystem\_ftpsockets::chdir()](chdir) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Changes current directory. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::exists()](exists) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if a file or directory exists. | | [WP\_Filesystem\_ftpsockets::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a file. | | [WP\_Filesystem\_ftpsockets::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Changes filesystem permissions. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::is_readable( string $file ): bool WP\_Filesystem\_ftpsockets::is\_readable( string $file ): bool ============================================================== Checks if a file is readable. `$file` string Required Path to file. bool Whether $file is readable. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function is_readable( $file ) { return true; } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::is_file( string $file ): bool WP\_Filesystem\_ftpsockets::is\_file( string $file ): bool ========================================================== Checks if resource is a file. `$file` string Required File path. bool Whether $file is a file. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function is_file( $file ) { if ( $this->is_dir( $file ) ) { return false; } if ( $this->exists( $file ) ) { return true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a directory. | | [WP\_Filesystem\_ftpsockets::exists()](exists) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if a file or directory exists. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_ftpsockets::delete()](delete) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Deletes a file or directory. | | [WP\_Filesystem\_ftpsockets::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Changes filesystem permissions. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::mtime( string $file ): int|false WP\_Filesystem\_ftpsockets::mtime( string $file ): int|false ============================================================ Gets the file modification time. `$file` string Required Path to file. int|false Unix timestamp representing modification time, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function mtime( $file ) { return $this->ftp->mdtm( $file ); } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::mkdir( string $path, int|false $chmod = false, string|int|false $chown = false, string|int|false $chgrp = false ): bool WP\_Filesystem\_ftpsockets::mkdir( string $path, int|false $chmod = false, string|int|false $chown = false, string|int|false $chgrp = false ): bool =================================================================================================================================================== Creates a directory. `$path` string Required Path for new directory. `$chmod` int|false Optional The permissions as octal number (or false to skip chmod). Default: `false` `$chown` string|int|false Optional A user name or number (or false to skip chown). Default: `false` `$chgrp` string|int|false Optional A group name or number (or false to skip chgrp). Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { $path = untrailingslashit( $path ); if ( empty( $path ) ) { return false; } if ( ! $this->ftp->mkdir( $path ) ) { return false; } if ( ! $chmod ) { $chmod = FS_CHMOD_DIR; } $this->chmod( $path, $chmod ); return true; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Changes filesystem permissions. | | [untrailingslashit()](../../functions/untrailingslashit) wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::owner( string $file ): string|false WP\_Filesystem\_ftpsockets::owner( string $file ): string|false =============================================================== Gets the file owner. `$file` string Required Path to the file. string|false Username of the owner on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function owner( $file ) { $dir = $this->dirlist( $file ); return $dir[ $file ]['owner']; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::cwd(): string|false WP\_Filesystem\_ftpsockets::cwd(): string|false =============================================== Gets the current working directory. string|false The current working directory on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function cwd() { $cwd = $this->ftp->pwd(); if ( $cwd ) { $cwd = trailingslashit( $cwd ); } return $cwd; } ``` | Uses | Description | | --- | --- | | [trailingslashit()](../../functions/trailingslashit) wp-includes/formatting.php | Appends a trailing slash. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a directory. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::__construct( array $opt = '' ) WP\_Filesystem\_ftpsockets::\_\_construct( array $opt = '' ) ============================================================ Constructor. `$opt` array Optional Default: `''` File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function __construct( $opt = '' ) { $this->method = 'ftpsockets'; $this->errors = new WP_Error(); // Check if possible to use ftp functions. if ( ! include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) { return; } $this->ftp = new ftp(); if ( empty( $opt['port'] ) ) { $this->options['port'] = 21; } else { $this->options['port'] = (int) $opt['port']; } if ( empty( $opt['hostname'] ) ) { $this->errors->add( 'empty_hostname', __( 'FTP hostname is required' ) ); } else { $this->options['hostname'] = $opt['hostname']; } // Check if the options provided are OK. if ( empty( $opt['username'] ) ) { $this->errors->add( 'empty_username', __( 'FTP username is required' ) ); } else { $this->options['username'] = $opt['username']; } if ( empty( $opt['password'] ) ) { $this->errors->add( 'empty_password', __( 'FTP password is required' ) ); } else { $this->options['password'] = $opt['password']; } } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::copy( string $source, string $destination, bool $overwrite = false, int|false $mode = false ): bool WP\_Filesystem\_ftpsockets::copy( string $source, string $destination, bool $overwrite = false, int|false $mode = false ): bool =============================================================================================================================== Copies a file. `$source` string Required Path to the source file. `$destination` string Required Path to the destination file. `$overwrite` bool Optional Whether to overwrite the destination file if it exists. Default: `false` `$mode` int|false Optional The permissions as octal number, usually 0644 for files, 0755 for dirs. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function copy( $source, $destination, $overwrite = false, $mode = false ) { if ( ! $overwrite && $this->exists( $destination ) ) { return false; } $content = $this->get_contents( $source ); if ( false === $content ) { return false; } return $this->put_contents( $destination, $content, $mode ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::exists()](exists) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if a file or directory exists. | | [WP\_Filesystem\_ftpsockets::get\_contents()](get_contents) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Reads entire file into a string. | | [WP\_Filesystem\_ftpsockets::put\_contents()](put_contents) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Writes a string to a file. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::get_contents_array( string $file ): array|false WP\_Filesystem\_ftpsockets::get\_contents\_array( string $file ): array|false ============================================================================= Reads entire file into an array. `$file` string Required Path to the file. array|false File contents in an array on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function get_contents_array( $file ) { return explode( "\n", $this->get_contents( $file ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::get\_contents()](get_contents) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Reads entire file into a string. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |
programming_docs
wordpress WP_Filesystem_ftpsockets::dirlist( string $path = '.', bool $include_hidden = true, bool $recursive = false ): array|false WP\_Filesystem\_ftpsockets::dirlist( string $path = '.', bool $include\_hidden = true, bool $recursive = false ): array|false ============================================================================================================================= Gets details for files in a directory or a specific file. `$path` string Optional Path to directory or file. Default: `'.'` `$include_hidden` bool Optional Whether to include details of hidden ("." prefixed) files. Default: `true` `$recursive` bool Optional Whether to recursively include file details in nested directories. Default: `false` array|false Array of files. False if unable to list directory contents. * `name`stringName of the file or directory. * `perms`string\*nix representation of permissions. * `permsn`stringOctal representation of permissions. * `owner`stringOwner name or ID. * `size`intSize of file in bytes. * `lastmodunix`intLast modified unix timestamp. * `lastmod`mixedLast modified month (3 letter) and day (without leading 0). * `time`intLast modified time. * `type`stringType of resource. `'f'` for file, `'d'` for directory. * `files`mixedIf a directory and `$recursive` is true, contains another array of files. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function dirlist( $path = '.', $include_hidden = true, $recursive = false ) { if ( $this->is_file( $path ) ) { $limit_file = basename( $path ); $path = dirname( $path ) . '/'; } else { $limit_file = false; } mbstring_binary_safe_encoding(); $list = $this->ftp->dirlist( $path ); if ( empty( $list ) && ! $this->exists( $path ) ) { reset_mbstring_encoding(); return false; } $ret = array(); foreach ( $list as $struc ) { if ( '.' === $struc['name'] || '..' === $struc['name'] ) { continue; } if ( ! $include_hidden && '.' === $struc['name'][0] ) { continue; } if ( $limit_file && $struc['name'] !== $limit_file ) { continue; } if ( 'd' === $struc['type'] ) { if ( $recursive ) { $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); } else { $struc['files'] = array(); } } // Replace symlinks formatted as "source -> target" with just the source name. if ( $struc['islink'] ) { $struc['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $struc['name'] ); } // Add the octal representation of the file permissions. $struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] ); $ret[ $struc['name'] ] = $struc; } reset_mbstring_encoding(); return $ret; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_ftpsockets::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a file. | | [WP\_Filesystem\_ftpsockets::exists()](exists) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if a file or directory exists. | | [mbstring\_binary\_safe\_encoding()](../../functions/mbstring_binary_safe_encoding) wp-includes/functions.php | Sets the mbstring internal encoding to a binary safe encoding when func\_overload is enabled. | | [reset\_mbstring\_encoding()](../../functions/reset_mbstring_encoding) wp-includes/functions.php | Resets the mbstring internal encoding to a users previously set encoding. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_ftpsockets::owner()](owner) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets the file owner. | | [WP\_Filesystem\_ftpsockets::getchmod()](getchmod) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets the permissions of the specified file or filepath in their octal format. | | [WP\_Filesystem\_ftpsockets::group()](group) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Gets the file’s group. | | [WP\_Filesystem\_ftpsockets::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Changes filesystem permissions. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::move( string $source, string $destination, bool $overwrite = false ): bool WP\_Filesystem\_ftpsockets::move( string $source, string $destination, bool $overwrite = false ): bool ====================================================================================================== Moves a file. `$source` string Required Path to the source file. `$destination` string Required Path to the destination file. `$overwrite` bool Optional Whether to overwrite the destination file if it exists. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function move( $source, $destination, $overwrite = false ) { return $this->ftp->rename( $source, $destination ); } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::atime( string $file ): int|false WP\_Filesystem\_ftpsockets::atime( string $file ): int|false ============================================================ Gets the file’s last access time. `$file` string Required Path to file. int|false Unix timestamp representing last access time, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function atime( $file ) { return false; } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::touch( string $file, int $time, int $atime ): bool WP\_Filesystem\_ftpsockets::touch( string $file, int $time, int $atime ): bool ============================================================================== Sets the access and modification times of a file. Note: If $file doesn’t exist, it will be created. `$file` string Required Path to file. `$time` int Optional Modified time to set for file. Default 0. `$atime` int Optional Access time to set for file. Default 0. bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function touch( $file, $time = 0, $atime = 0 ) { return false; } ``` | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::delete( string $file, bool $recursive = false, string|false $type = false ): bool WP\_Filesystem\_ftpsockets::delete( string $file, bool $recursive = false, string|false $type = false ): bool ============================================================================================================= Deletes a file or directory. `$file` string Required Path to the file or directory. `$recursive` bool Optional If set to true, deletes files and folders recursively. Default: `false` `$type` string|false Optional Type of resource. `'f'` for file, `'d'` for directory. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function delete( $file, $recursive = false, $type = false ) { if ( empty( $file ) ) { return false; } if ( 'f' === $type || $this->is_file( $file ) ) { return $this->ftp->delete( $file ); } if ( ! $recursive ) { return $this->ftp->rmdir( $file ); } return $this->ftp->mdel( $file ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Checks if resource is a file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_ftpsockets::rmdir()](rmdir) wp-admin/includes/class-wp-filesystem-ftpsockets.php | Deletes a directory. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress WP_Filesystem_ftpsockets::connect(): bool WP\_Filesystem\_ftpsockets::connect(): bool =========================================== Connects filesystem. bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ftpsockets.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ftpsockets.php/) ``` public function connect() { if ( ! $this->ftp ) { return false; } $this->ftp->setTimeout( FS_CONNECT_TIMEOUT ); if ( ! $this->ftp->SetServer( $this->options['hostname'], $this->options['port'] ) ) { $this->errors->add( 'connect', sprintf( /* translators: %s: hostname:port */ __( 'Failed to connect to FTP Server %s' ), $this->options['hostname'] . ':' . $this->options['port'] ) ); return false; } if ( ! $this->ftp->connect() ) { $this->errors->add( 'connect', sprintf( /* translators: %s: hostname:port */ __( 'Failed to connect to FTP Server %s' ), $this->options['hostname'] . ':' . $this->options['port'] ) ); return false; } if ( ! $this->ftp->login( $this->options['username'], $this->options['password'] ) ) { $this->errors->add( 'auth', sprintf( /* translators: %s: Username. */ __( 'Username/Password incorrect for %s' ), $this->options['username'] ) ); return false; } $this->ftp->SetType( FTP_BINARY ); $this->ftp->Passive( true ); $this->ftp->setTimeout( FS_TIMEOUT ); return true; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. | wordpress Requests_Cookie_Jar::getIterator(): ArrayIterator Requests\_Cookie\_Jar::getIterator(): ArrayIterator =================================================== Get an iterator for the data ArrayIterator File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function getIterator() { return new ArrayIterator($this->cookies); } ``` wordpress Requests_Cookie_Jar::offsetGet( string $key ): string|null Requests\_Cookie\_Jar::offsetGet( string $key ): string|null ============================================================ Get the value for the item `$key` string Required Item key string|null Item value (null if offsetExists is false) File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function offsetGet($key) { if (!isset($this->cookies[$key])) { return null; } return $this->cookies[$key]; } ``` wordpress Requests_Cookie_Jar::offsetUnset( string $key ) Requests\_Cookie\_Jar::offsetUnset( string $key ) ================================================= Unset the given header `$key` string Required File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function offsetUnset($key) { unset($this->cookies[$key]); } ``` wordpress Requests_Cookie_Jar::offsetSet( string $key, string $value ) Requests\_Cookie\_Jar::offsetSet( string $key, string $value ) ============================================================== Set the given item `$key` string Required Item name `$value` string Required Item value File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function offsetSet($key, $value) { if ($key === null) { throw new Requests_Exception('Object is a dictionary, not a list', 'invalidset'); } $this->cookies[$key] = $value; } ``` | Uses | Description | | --- | --- | | [Requests\_Exception::\_\_construct()](../requests_exception/__construct) wp-includes/Requests/Exception.php | Create a new exception | wordpress Requests_Cookie_Jar::before_request( string $url, array $headers, array $data, string $type, array $options ) Requests\_Cookie\_Jar::before\_request( string $url, array $headers, array $data, string $type, array $options ) ================================================================================================================ Add Cookie header to a request if we have any As per RFC 6265, cookies are separated by ‘; ‘ `$url` string Required `$headers` array Required `$data` array Required `$type` string Required `$options` array Required File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function before_request($url, &$headers, &$data, &$type, &$options) { if (!$url instanceof Requests_IRI) { $url = new Requests_IRI($url); } if (!empty($this->cookies)) { $cookies = array(); foreach ($this->cookies as $key => $cookie) { $cookie = $this->normalize_cookie($cookie, $key); // Skip expired cookies if ($cookie->is_expired()) { continue; } if ($cookie->domain_matches($url->host)) { $cookies[] = $cookie->format_for_header(); } } $headers['Cookie'] = implode('; ', $cookies); } } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::\_\_construct()](../requests_iri/__construct) wp-includes/Requests/IRI.php | Create a new IRI object, from a specified string | | [Requests\_Cookie\_Jar::normalize\_cookie()](normalize_cookie) wp-includes/Requests/Cookie/Jar.php | Normalise cookie data into a [Requests\_Cookie](../requests_cookie) | wordpress Requests_Cookie_Jar::register( Requests_Hooker $hooks ) Requests\_Cookie\_Jar::register( Requests\_Hooker $hooks ) ========================================================== Register the cookie handler with the request’s hooking system `$hooks` Requests\_Hooker Required Hooking system File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function register(Requests_Hooker $hooks) { $hooks->register('requests.before_request', array($this, 'before_request')); $hooks->register('requests.before_redirect_check', array($this, 'before_redirect_check')); } ``` wordpress Requests_Cookie_Jar::normalize_cookie( string|Requests_Cookie $cookie, $key = null ): Requests_Cookie Requests\_Cookie\_Jar::normalize\_cookie( string|Requests\_Cookie $cookie, $key = null ): Requests\_Cookie ========================================================================================================== Normalise cookie data into a [Requests\_Cookie](../requests_cookie) `$cookie` string|[Requests\_Cookie](../requests_cookie) Required [Requests\_Cookie](../requests_cookie) File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function normalize_cookie($cookie, $key = null) { if ($cookie instanceof Requests_Cookie) { return $cookie; } return Requests_Cookie::parse($cookie, $key); } ``` | Uses | Description | | --- | --- | | [Requests\_Cookie::parse()](../requests_cookie/parse) wp-includes/Requests/Cookie.php | Parse a cookie string into a cookie object | | Used By | Description | | --- | --- | | [Requests\_Cookie\_Jar::before\_request()](before_request) wp-includes/Requests/Cookie/Jar.php | Add Cookie header to a request if we have any | | [Requests\_Cookie\_Jar::normalizeCookie()](normalizecookie) wp-includes/Requests/Cookie/Jar.php | Normalise cookie data into a [Requests\_Cookie](../requests_cookie) | wordpress Requests_Cookie_Jar::offsetExists( string $key ): boolean Requests\_Cookie\_Jar::offsetExists( string $key ): boolean =========================================================== Check if the given item exists `$key` string Required Item key boolean Does the item exist? File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function offsetExists($key) { return isset($this->cookies[$key]); } ``` wordpress Requests_Cookie_Jar::normalizeCookie( $cookie, $key = null ): Requests_Cookie Requests\_Cookie\_Jar::normalizeCookie( $cookie, $key = null ): Requests\_Cookie ================================================================================ This method has been deprecated. Use [Requests\_Cookie\_Jar::normalize\_cookie()](normalize_cookie) instead. Normalise cookie data into a [Requests\_Cookie](../requests_cookie) [Requests\_Cookie](../requests_cookie) File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function normalizeCookie($cookie, $key = null) { return $this->normalize_cookie($cookie, $key); } ``` | Uses | Description | | --- | --- | | [Requests\_Cookie\_Jar::normalize\_cookie()](normalize_cookie) wp-includes/Requests/Cookie/Jar.php | Normalise cookie data into a [Requests\_Cookie](../requests_cookie) | wordpress Requests_Cookie_Jar::__construct( array $cookies = array() ) Requests\_Cookie\_Jar::\_\_construct( array $cookies = array() ) ================================================================ Create a new jar `$cookies` array Optional Existing cookie values Default: `array()` File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function __construct($cookies = array()) { $this->cookies = $cookies; } ``` | Used By | Description | | --- | --- | | [Requests::set\_defaults()](../requests/set_defaults) wp-includes/class-requests.php | Set the default values | | [Requests\_Response::\_\_construct()](../requests_response/__construct) wp-includes/Requests/Response.php | Constructor | | [Requests\_Session::\_\_construct()](../requests_session/__construct) wp-includes/Requests/Session.php | Create a new session | | [WP\_Http::normalize\_cookies()](../wp_http/normalize_cookies) wp-includes/class-wp-http.php | Normalizes cookies for using in Requests. | wordpress Requests_Cookie_Jar::before_redirect_check( $return ) Requests\_Cookie\_Jar::before\_redirect\_check( $return ) ========================================================= Parse all cookies from a response and attach them to the response File: `wp-includes/Requests/Cookie/Jar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/cookie/jar.php/) ``` public function before_redirect_check(Requests_Response $return) { $url = $return->url; if (!$url instanceof Requests_IRI) { $url = new Requests_IRI($url); } $cookies = Requests_Cookie::parse_from_headers($return->headers, $url); $this->cookies = array_merge($this->cookies, $cookies); $return->cookies = $this; } ``` | Uses | Description | | --- | --- | | [Requests\_Cookie::parse\_from\_headers()](../requests_cookie/parse_from_headers) wp-includes/Requests/Cookie.php | Parse all Set-Cookie headers from request headers | | [Requests\_IRI::\_\_construct()](../requests_iri/__construct) wp-includes/Requests/IRI.php | Create a new IRI object, from a specified string |
programming_docs
wordpress WP_Site_Health_Auto_Updates::test_wp_version_check_attached(): array WP\_Site\_Health\_Auto\_Updates::test\_wp\_version\_check\_attached(): array ============================================================================ Checks if updates are intercepted by a filter. array The test results. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_wp_version_check_attached() { if ( ( ! is_multisite() || is_main_site() && is_network_admin() ) && ! has_filter( 'wp_version_check', 'wp_version_check' ) ) { return array( 'description' => sprintf( /* translators: %s: Name of the filter used. */ __( 'A plugin has prevented updates by disabling %s.' ), '<code>wp_version_check()</code>' ), 'severity' => 'fail', ); } } ``` | Uses | Description | | --- | --- | | [is\_network\_admin()](../../functions/is_network_admin) wp-includes/load.php | Determines whether the current request is for the network administrative interface. | | [is\_main\_site()](../../functions/is_main_site) wp-includes/functions.php | Determines whether a site is the main site of the current network. | | [has\_filter()](../../functions/has_filter) wp-includes/plugin.php | Checks if any filter has been registered for a hook. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::test_filters_automatic_updater_disabled(): array WP\_Site\_Health\_Auto\_Updates::test\_filters\_automatic\_updater\_disabled(): array ===================================================================================== Checks if automatic updates are disabled by a filter. array The test results. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_filters_automatic_updater_disabled() { /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */ if ( apply_filters( 'automatic_updater_disabled', false ) ) { return array( 'description' => sprintf( /* translators: %s: Name of the filter used. */ __( 'The %s filter is enabled.' ), '<code>automatic_updater_disabled</code>' ), 'severity' => 'fail', ); } } ``` [apply\_filters( 'automatic\_updater\_disabled', bool $disabled )](../../hooks/automatic_updater_disabled) Filters whether to entirely disable background updates. | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::test_all_files_writable(): array|false WP\_Site\_Health\_Auto\_Updates::test\_all\_files\_writable(): array|false ========================================================================== Checks if core files are writable by the web user/group. array|false The test results. False if they're not writeable. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_all_files_writable() { global $wp_filesystem; require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z $skin = new Automatic_Upgrader_Skin; $success = $skin->request_filesystem_credentials( false, ABSPATH ); if ( ! $success ) { return false; } WP_Filesystem(); if ( 'direct' !== $wp_filesystem->method ) { return false; } // Make sure the `get_core_checksums()` function is available during our REST API call. if ( ! function_exists( 'get_core_checksums' ) ) { require_once ABSPATH . '/wp-admin/includes/update.php'; } $checksums = get_core_checksums( $wp_version, 'en_US' ); $dev = ( false !== strpos( $wp_version, '-' ) ); // Get the last stable version's files and test against that. if ( ! $checksums && $dev ) { $checksums = get_core_checksums( (float) $wp_version - 0.1, 'en_US' ); } // There aren't always checksums for development releases, so just skip the test if we still can't find any. if ( ! $checksums && $dev ) { return false; } if ( ! $checksums ) { $description = sprintf( /* translators: %s: WordPress version. */ __( "Couldn't retrieve a list of the checksums for WordPress %s." ), $wp_version ); $description .= ' ' . __( 'This could mean that connections are failing to WordPress.org.' ); return array( 'description' => $description, 'severity' => 'warning', ); } $unwritable_files = array(); foreach ( array_keys( $checksums ) as $file ) { if ( 'wp-content' === substr( $file, 0, 10 ) ) { continue; } if ( ! file_exists( ABSPATH . $file ) ) { continue; } if ( ! is_writable( ABSPATH . $file ) ) { $unwritable_files[] = $file; } } if ( $unwritable_files ) { if ( count( $unwritable_files ) > 20 ) { $unwritable_files = array_slice( $unwritable_files, 0, 20 ); $unwritable_files[] = '...'; } return array( 'description' => __( 'Some files are not writable by WordPress:' ) . ' <ul><li>' . implode( '</li><li>', $unwritable_files ) . '</li></ul>', 'severity' => 'fail', ); } else { return array( 'description' => __( 'All of your WordPress files are writable.' ), 'severity' => 'pass', ); } } ``` | Uses | Description | | --- | --- | | [get\_core\_checksums()](../../functions/get_core_checksums) wp-admin/includes/update.php | Gets and caches the checksums for the given version of WordPress. | | [WP\_Filesystem()](../../functions/wp_filesystem) wp-admin/includes/file.php | Initializes and connects the WordPress Filesystem Abstraction classes. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::test_check_wp_filesystem_method(): array WP\_Site\_Health\_Auto\_Updates::test\_check\_wp\_filesystem\_method(): array ============================================================================= Checks if we can access files without providing credentials. array The test results. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_check_wp_filesystem_method() { // Make sure the `request_filesystem_credentials()` function is available during our REST API call. if ( ! function_exists( 'request_filesystem_credentials' ) ) { require_once ABSPATH . '/wp-admin/includes/file.php'; } $skin = new Automatic_Upgrader_Skin; $success = $skin->request_filesystem_credentials( false, ABSPATH ); if ( ! $success ) { $description = __( 'Your installation of WordPress prompts for FTP credentials to perform updates.' ); $description .= ' ' . __( '(Your site is performing updates over FTP due to file ownership. Talk to your hosting company.)' ); return array( 'description' => $description, 'severity' => 'fail', ); } return array( 'description' => __( 'Your installation of WordPress does not require FTP credentials to perform updates.' ), 'severity' => 'pass', ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::test_constants( string $constant, bool|string|array $value ): array WP\_Site\_Health\_Auto\_Updates::test\_constants( string $constant, bool|string|array $value ): array ===================================================================================================== Tests if auto-updates related constants are set correctly. `$constant` string Required The name of the constant to check. `$value` bool|string|array Required The value that the constant should be, if set, or an array of acceptable values. array The test results. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_constants( $constant, $value ) { $acceptable_values = (array) $value; if ( defined( $constant ) && ! in_array( constant( $constant ), $acceptable_values, true ) ) { return array( 'description' => sprintf( /* translators: 1: Name of the constant used. 2: Value of the constant used. */ __( 'The %1$s constant is defined as %2$s' ), "<code>$constant</code>", '<code>' . esc_html( var_export( constant( $constant ), true ) ) . '</code>' ), 'severity' => 'fail', ); } } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.5.1](https://developer.wordpress.org/reference/since/5.5.1/) | The `$value` parameter can accept an array. | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::test_accepts_minor_updates(): array WP\_Site\_Health\_Auto\_Updates::test\_accepts\_minor\_updates(): array ======================================================================= Checks if the site supports automatic minor updates. array The test results. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_accepts_minor_updates() { if ( defined( 'WP_AUTO_UPDATE_CORE' ) && false === WP_AUTO_UPDATE_CORE ) { return array( 'description' => sprintf( /* translators: %s: Name of the constant used. */ __( 'WordPress security and maintenance releases are blocked by %s.' ), "<code>define( 'WP_AUTO_UPDATE_CORE', false );</code>" ), 'severity' => 'fail', ); } /** This filter is documented in wp-admin/includes/class-core-upgrader.php */ if ( ! apply_filters( 'allow_minor_auto_core_updates', true ) ) { return array( 'description' => sprintf( /* translators: %s: Name of the filter used. */ __( 'WordPress security and maintenance releases are blocked by the %s filter.' ), '<code>allow_minor_auto_core_updates</code>' ), 'severity' => 'fail', ); } } ``` [apply\_filters( 'allow\_minor\_auto\_core\_updates', bool $upgrade\_minor )](../../hooks/allow_minor_auto_core_updates) Filters whether to enable minor automatic core updates. | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::__construct() WP\_Site\_Health\_Auto\_Updates::\_\_construct() ================================================ [WP\_Site\_Health\_Auto\_Updates](../wp_site_health_auto_updates) constructor. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function __construct() { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } ``` | Used By | Description | | --- | --- | | [WP\_Site\_Health::get\_test\_background\_updates()](../wp_site_health/get_test_background_updates) wp-admin/includes/class-wp-site-health.php | Tests if WordPress can run automated background updates. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::test_wp_automatic_updates_disabled(): array|false WP\_Site\_Health\_Auto\_Updates::test\_wp\_automatic\_updates\_disabled(): array|false ====================================================================================== Checks if automatic updates are disabled. array|false The test results. False if auto-updates are enabled. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_wp_automatic_updates_disabled() { if ( ! class_exists( 'WP_Automatic_Updater' ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php'; } $auto_updates = new WP_Automatic_Updater(); if ( ! $auto_updates->is_disabled() ) { return false; } return array( 'description' => __( 'All automatic updates are disabled.' ), 'severity' => 'fail', ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::test_if_failed_update(): array|false WP\_Site\_Health\_Auto\_Updates::test\_if\_failed\_update(): array|false ======================================================================== Checks if automatic updates have tried to run, but failed, previously. array|false The test results. False if the auto-updates failed. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_if_failed_update() { $failed = get_site_option( 'auto_core_update_failed' ); if ( ! $failed ) { return false; } if ( ! empty( $failed['critical'] ) ) { $description = __( 'A previous automatic background update ended with a critical failure, so updates are now disabled.' ); $description .= ' ' . __( 'You would have received an email because of this.' ); $description .= ' ' . __( "When you've been able to update using the \"Update now\" button on Dashboard > Updates, this error will be cleared for future update attempts." ); $description .= ' ' . sprintf( /* translators: %s: Code of error shown. */ __( 'The error code was %s.' ), '<code>' . $failed['error_code'] . '</code>' ); return array( 'description' => $description, 'severity' => 'warning', ); } $description = __( 'A previous automatic background update could not occur.' ); if ( empty( $failed['retry'] ) ) { $description .= ' ' . __( 'You would have received an email because of this.' ); } $description .= ' ' . __( 'Another attempt will be made with the next release.' ); $description .= ' ' . sprintf( /* translators: %s: Code of error shown. */ __( 'The error code was %s.' ), '<code>' . $failed['error_code'] . '</code>' ); return array( 'description' => $description, 'severity' => 'warning', ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_site\_option()](../../functions/get_site_option) wp-includes/option.php | Retrieve an option value for the current network based on name of option. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::run_tests(): array WP\_Site\_Health\_Auto\_Updates::run\_tests(): array ==================================================== Runs tests to determine if auto-updates can run. array The test results. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function run_tests() { $tests = array( $this->test_constants( 'WP_AUTO_UPDATE_CORE', array( true, 'beta', 'rc', 'development', 'branch-development', 'minor' ) ), $this->test_wp_version_check_attached(), $this->test_filters_automatic_updater_disabled(), $this->test_wp_automatic_updates_disabled(), $this->test_if_failed_update(), $this->test_vcs_abspath(), $this->test_check_wp_filesystem_method(), $this->test_all_files_writable(), $this->test_accepts_dev_updates(), $this->test_accepts_minor_updates(), ); $tests = array_filter( $tests ); $tests = array_map( static function( $test ) { $test = (object) $test; if ( empty( $test->severity ) ) { $test->severity = 'warning'; } return $test; }, $tests ); return $tests; } ``` | Uses | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::test\_wp\_automatic\_updates\_disabled()](test_wp_automatic_updates_disabled) wp-admin/includes/class-wp-site-health-auto-updates.php | Checks if automatic updates are disabled. | | [WP\_Site\_Health\_Auto\_Updates::test\_check\_wp\_filesystem\_method()](test_check_wp_filesystem_method) wp-admin/includes/class-wp-site-health-auto-updates.php | Checks if we can access files without providing credentials. | | [WP\_Site\_Health\_Auto\_Updates::test\_all\_files\_writable()](test_all_files_writable) wp-admin/includes/class-wp-site-health-auto-updates.php | Checks if core files are writable by the web user/group. | | [WP\_Site\_Health\_Auto\_Updates::test\_accepts\_dev\_updates()](test_accepts_dev_updates) wp-admin/includes/class-wp-site-health-auto-updates.php | Checks if the install is using a development branch and can use nightly packages. | | [WP\_Site\_Health\_Auto\_Updates::test\_accepts\_minor\_updates()](test_accepts_minor_updates) wp-admin/includes/class-wp-site-health-auto-updates.php | Checks if the site supports automatic minor updates. | | [WP\_Site\_Health\_Auto\_Updates::test\_constants()](test_constants) wp-admin/includes/class-wp-site-health-auto-updates.php | Tests if auto-updates related constants are set correctly. | | [WP\_Site\_Health\_Auto\_Updates::test\_wp\_version\_check\_attached()](test_wp_version_check_attached) wp-admin/includes/class-wp-site-health-auto-updates.php | Checks if updates are intercepted by a filter. | | [WP\_Site\_Health\_Auto\_Updates::test\_filters\_automatic\_updater\_disabled()](test_filters_automatic_updater_disabled) wp-admin/includes/class-wp-site-health-auto-updates.php | Checks if automatic updates are disabled by a filter. | | [WP\_Site\_Health\_Auto\_Updates::test\_if\_failed\_update()](test_if_failed_update) wp-admin/includes/class-wp-site-health-auto-updates.php | Checks if automatic updates have tried to run, but failed, previously. | | [WP\_Site\_Health\_Auto\_Updates::test\_vcs\_abspath()](test_vcs_abspath) wp-admin/includes/class-wp-site-health-auto-updates.php | Checks if WordPress is controlled by a VCS (Git, Subversion etc). | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. |
programming_docs
wordpress WP_Site_Health_Auto_Updates::test_accepts_dev_updates(): array|false WP\_Site\_Health\_Auto\_Updates::test\_accepts\_dev\_updates(): array|false =========================================================================== Checks if the install is using a development branch and can use nightly packages. array|false The test results. False if it isn't a development version. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_accepts_dev_updates() { require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z // Only for dev versions. if ( false === strpos( $wp_version, '-' ) ) { return false; } if ( defined( 'WP_AUTO_UPDATE_CORE' ) && ( 'minor' === WP_AUTO_UPDATE_CORE || false === WP_AUTO_UPDATE_CORE ) ) { return array( 'description' => sprintf( /* translators: %s: Name of the constant used. */ __( 'WordPress development updates are blocked by the %s constant.' ), '<code>WP_AUTO_UPDATE_CORE</code>' ), 'severity' => 'fail', ); } /** This filter is documented in wp-admin/includes/class-core-upgrader.php */ if ( ! apply_filters( 'allow_dev_auto_core_updates', $wp_version ) ) { return array( 'description' => sprintf( /* translators: %s: Name of the filter used. */ __( 'WordPress development updates are blocked by the %s filter.' ), '<code>allow_dev_auto_core_updates</code>' ), 'severity' => 'fail', ); } } ``` [apply\_filters( 'allow\_dev\_auto\_core\_updates', bool $upgrade\_dev )](../../hooks/allow_dev_auto_core_updates) Filters whether to enable automatic core updates for development versions. | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress WP_Site_Health_Auto_Updates::test_vcs_abspath(): array WP\_Site\_Health\_Auto\_Updates::test\_vcs\_abspath(): array ============================================================ Checks if WordPress is controlled by a VCS (Git, Subversion etc). array The test results. File: `wp-admin/includes/class-wp-site-health-auto-updates.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-site-health-auto-updates.php/) ``` public function test_vcs_abspath() { $context_dirs = array( ABSPATH ); $vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' ); $check_dirs = array(); foreach ( $context_dirs as $context_dir ) { // Walk up from $context_dir to the root. do { $check_dirs[] = $context_dir; // Once we've hit '/' or 'C:\', we need to stop. dirname will keep returning the input here. if ( dirname( $context_dir ) === $context_dir ) { break; } // Continue one level at a time. } while ( $context_dir = dirname( $context_dir ) ); } $check_dirs = array_unique( $check_dirs ); // Search all directories we've found for evidence of version control. foreach ( $vcs_dirs as $vcs_dir ) { foreach ( $check_dirs as $check_dir ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition,Squiz.PHP.DisallowMultipleAssignments if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) ) { break 2; } } } /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */ if ( $checkout && ! apply_filters( 'automatic_updates_is_vcs_checkout', true, ABSPATH ) ) { return array( 'description' => sprintf( /* translators: 1: Folder name. 2: Version control directory. 3: Filter name. */ __( 'The folder %1$s was detected as being under version control (%2$s), but the %3$s filter is allowing updates.' ), '<code>' . $check_dir . '</code>', "<code>$vcs_dir</code>", '<code>automatic_updates_is_vcs_checkout</code>' ), 'severity' => 'info', ); } if ( $checkout ) { return array( 'description' => sprintf( /* translators: 1: Folder name. 2: Version control directory. */ __( 'The folder %1$s was detected as being under version control (%2$s).' ), '<code>' . $check_dir . '</code>', "<code>$vcs_dir</code>" ), 'severity' => 'warning', ); } return array( 'description' => __( 'No version control systems were detected.' ), 'severity' => 'pass', ); } ``` [apply\_filters( 'automatic\_updates\_is\_vcs\_checkout', bool $checkout, string $context )](../../hooks/automatic_updates_is_vcs_checkout) Filters whether the automatic updater should consider a filesystem location to be potentially managed by a version control system. | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Site\_Health\_Auto\_Updates::run\_tests()](run_tests) wp-admin/includes/class-wp-site-health-auto-updates.php | Runs tests to determine if auto-updates can run. | | Version | Description | | --- | --- | | [5.2.0](https://developer.wordpress.org/reference/since/5.2.0/) | Introduced. | wordpress Requests_IRI::replace_invalid_with_pct_encoding( string $string, string $extra_chars, bool $iprivate = false ): string Requests\_IRI::replace\_invalid\_with\_pct\_encoding( string $string, string $extra\_chars, bool $iprivate = false ): string ============================================================================================================================ Replace invalid character with percent encoding `$string` string Required Input string `$extra_chars` string Required Valid characters not in iunreserved or iprivate (this is ASCII-only) `$iprivate` bool Optional Allow iprivate Default: `false` string File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false) { // Normalize as many pct-encoded sections as possible $string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array($this, 'remove_iunreserved_percent_encoded'), $string); // Replace invalid percent characters $string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string); // Add unreserved and % to $extra_chars (the latter is safe because all // pct-encoded sections are now valid). $extra_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%'; // Now replace any bytes that aren't allowed with their pct-encoded versions $position = 0; $strlen = strlen($string); while (($position += strspn($string, $extra_chars, $position)) < $strlen) { $value = ord($string[$position]); // Start position $start = $position; // By default we are valid $valid = true; // No one byte sequences are valid due to the while. // Two byte sequence: if (($value & 0xE0) === 0xC0) { $character = ($value & 0x1F) << 6; $length = 2; $remaining = 1; } // Three byte sequence: elseif (($value & 0xF0) === 0xE0) { $character = ($value & 0x0F) << 12; $length = 3; $remaining = 2; } // Four byte sequence: elseif (($value & 0xF8) === 0xF0) { $character = ($value & 0x07) << 18; $length = 4; $remaining = 3; } // Invalid byte: else { $valid = false; $length = 1; $remaining = 0; } if ($remaining) { if ($position + $length <= $strlen) { for ($position++; $remaining; $position++) { $value = ord($string[$position]); // Check that the byte is valid, then add it to the character: if (($value & 0xC0) === 0x80) { $character |= ($value & 0x3F) << (--$remaining * 6); } // If it is invalid, count the sequence as invalid and reprocess the current byte: else { $valid = false; $position--; break; } } } else { $position = $strlen - 1; $valid = false; } } // Percent encode anything invalid or not in ucschar if ( // Invalid sequences !$valid // Non-shortest form sequences are invalid || $length > 1 && $character <= 0x7F || $length > 2 && $character <= 0x7FF || $length > 3 && $character <= 0xFFFF // Outside of range of ucschar codepoints // Noncharacters || ($character & 0xFFFE) === 0xFFFE || $character >= 0xFDD0 && $character <= 0xFDEF || ( // Everything else not in ucschar $character > 0xD7FF && $character < 0xF900 || $character < 0xA0 || $character > 0xEFFFD ) && ( // Everything not in iprivate, if it applies !$iprivate || $character < 0xE000 || $character > 0x10FFFD ) ) { // If we were a character, pretend we weren't, but rather an error. if ($valid) { $position--; } for ($j = $start; $j <= $position; $j++) { $string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1); $j += 2; $position += 2; $strlen += 2; } } } return $string; } ``` | Used By | Description | | --- | --- | | [Requests\_IRI::set\_userinfo()](set_userinfo) wp-includes/Requests/IRI.php | Set the iuserinfo. | | [Requests\_IRI::set\_host()](set_host) wp-includes/Requests/IRI.php | Set the ihost. Returns true on success, false on failure (if there are any invalid characters). | | [Requests\_IRI::set\_path()](set_path) wp-includes/Requests/IRI.php | Set the ipath. | | [Requests\_IRI::set\_query()](set_query) wp-includes/Requests/IRI.php | Set the iquery. | | [Requests\_IRI::set\_fragment()](set_fragment) wp-includes/Requests/IRI.php | Set the ifragment. | wordpress Requests_IRI::to_uri( $string ): string|false Requests\_IRI::to\_uri( $string ): string|false =============================================== Convert an IRI to a URI (or parts thereof) IRI to convert (or false from [get\_iri](../../functions/get_iri)) string|false URI if IRI is valid, false otherwise. File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function to_uri($string) { if (!is_string($string)) { return false; } static $non_ascii; if (!$non_ascii) { $non_ascii = implode('', range("\x80", "\xFF")); } $position = 0; $strlen = strlen($string); while (($position += strcspn($string, $non_ascii, $position)) < $strlen) { $string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1); $position += 3; $strlen += 2; } return $string; } ``` | Used By | Description | | --- | --- | | [Requests\_IRI::get\_uri()](get_uri) wp-includes/Requests/IRI.php | Get the complete URI | | [Requests\_IRI::get\_authority()](get_authority) wp-includes/Requests/IRI.php | Get the complete authority | wordpress Requests_IRI::__unset( string $name ) Requests\_IRI::\_\_unset( string $name ) ======================================== Overload \_\_unset() to provide access via properties `$name` string Required Property name File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` public function __unset($name) { if (method_exists($this, 'set_' . $name)) { call_user_func(array($this, 'set_' . $name), ''); } } ``` wordpress Requests_IRI::remove_dot_segments( string $input ): string Requests\_IRI::remove\_dot\_segments( string $input ): string ============================================================= Remove dot segments from a path `$input` string Required string File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function remove_dot_segments($input) { $output = ''; while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') { // A: If the input buffer begins with a prefix of "../" or "./", // then remove that prefix from the input buffer; otherwise, if (strpos($input, '../') === 0) { $input = substr($input, 3); } elseif (strpos($input, './') === 0) { $input = substr($input, 2); } // B: if the input buffer begins with a prefix of "/./" or "/.", // where "." is a complete path segment, then replace that prefix // with "/" in the input buffer; otherwise, elseif (strpos($input, '/./') === 0) { $input = substr($input, 2); } elseif ($input === '/.') { $input = '/'; } // C: if the input buffer begins with a prefix of "/../" or "/..", // where ".." is a complete path segment, then replace that prefix // with "/" in the input buffer and remove the last segment and its // preceding "/" (if any) from the output buffer; otherwise, elseif (strpos($input, '/../') === 0) { $input = substr($input, 3); $output = substr_replace($output, '', strrpos($output, '/')); } elseif ($input === '/..') { $input = '/'; $output = substr_replace($output, '', strrpos($output, '/')); } // D: if the input buffer consists only of "." or "..", then remove // that from the input buffer; otherwise, elseif ($input === '.' || $input === '..') { $input = ''; } // E: move the first path segment in the input buffer to the end of // the output buffer, including the initial "/" character (if any) // and any subsequent characters up to, but not including, the next // "/" character or the end of the input buffer elseif (($pos = strpos($input, '/', 1)) !== false) { $output .= substr($input, 0, $pos); $input = substr_replace($input, '', 0, $pos); } else { $output .= $input; $input = ''; } } return $output . $input; } ``` | Used By | Description | | --- | --- | | [Requests\_IRI::set\_path()](set_path) wp-includes/Requests/IRI.php | Set the ipath. | wordpress Requests_IRI::set_query( string $iquery ): bool Requests\_IRI::set\_query( string $iquery ): bool ================================================= Set the iquery. `$iquery` string Required bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function set_query($iquery) { if ($iquery === null) { $this->iquery = null; } else { $this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', true); $this->scheme_normalization(); } return true; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::replace\_invalid\_with\_pct\_encoding()](replace_invalid_with_pct_encoding) wp-includes/Requests/IRI.php | Replace invalid character with percent encoding | | [Requests\_IRI::scheme\_normalization()](scheme_normalization) wp-includes/Requests/IRI.php | | | Used By | Description | | --- | --- | | [Requests\_IRI::set\_iri()](set_iri) wp-includes/Requests/IRI.php | Set the entire IRI. Returns true on success, false on failure (if there are any invalid characters). | wordpress Requests_IRI::parse_iri( string $iri ): array Requests\_IRI::parse\_iri( string $iri ): array =============================================== Parse an IRI into scheme/authority/path/query/fragment segments `$iri` string Required array File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function parse_iri($iri) { $iri = trim($iri, "\x20\x09\x0A\x0C\x0D"); $has_match = preg_match('/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match); if (!$has_match) { throw new Requests_Exception('Cannot parse supplied IRI', 'iri.cannot_parse', $iri); } if ($match[1] === '') { $match['scheme'] = null; } if (!isset($match[3]) || $match[3] === '') { $match['authority'] = null; } if (!isset($match[5])) { $match['path'] = ''; } if (!isset($match[6]) || $match[6] === '') { $match['query'] = null; } if (!isset($match[8]) || $match[8] === '') { $match['fragment'] = null; } return $match; } ``` | Uses | Description | | --- | --- | | [Requests\_Exception::\_\_construct()](../requests_exception/__construct) wp-includes/Requests/Exception.php | Create a new exception | | Used By | Description | | --- | --- | | [Requests\_IRI::set\_iri()](set_iri) wp-includes/Requests/IRI.php | Set the entire IRI. Returns true on success, false on failure (if there are any invalid characters). | wordpress Requests_IRI::__set( string $name, mixed $value ) Requests\_IRI::\_\_set( string $name, mixed $value ) ==================================================== Overload \_\_set() to provide access via properties `$name` string Required Property name `$value` mixed Required Property value File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` public function __set($name, $value) { if (method_exists($this, 'set_' . $name)) { call_user_func(array($this, 'set_' . $name), $value); } elseif ( $name === 'iauthority' || $name === 'iuserinfo' || $name === 'ihost' || $name === 'ipath' || $name === 'iquery' || $name === 'ifragment' ) { call_user_func(array($this, 'set_' . substr($name, 1)), $value); } } ``` wordpress Requests_IRI::set_port( string $port ): bool Requests\_IRI::set\_port( string $port ): bool ============================================== Set the port. Returns true on success, false on failure (if there are any invalid characters). `$port` string Required bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function set_port($port) { if ($port === null) { $this->port = null; return true; } if (strspn($port, '0123456789') === strlen($port)) { $this->port = (int) $port; $this->scheme_normalization(); return true; } $this->port = null; return false; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::scheme\_normalization()](scheme_normalization) wp-includes/Requests/IRI.php | | | Used By | Description | | --- | --- | | [Requests\_IRI::set\_authority()](set_authority) wp-includes/Requests/IRI.php | Set the authority. Returns true on success, false on failure (if there are any invalid characters). | wordpress Requests_IRI::__get( string $name ): mixed Requests\_IRI::\_\_get( string $name ): mixed ============================================= Overload \_\_get() to provide access via properties `$name` string Required Property name mixed File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` public function __get($name) { // isset() returns false for null, we don't want to do that // Also why we use array_key_exists below instead of isset() $props = get_object_vars($this); if ( $name === 'iri' || $name === 'uri' || $name === 'iauthority' || $name === 'authority' ) { $method = 'get_' . $name; $return = $this->$method(); } elseif (array_key_exists($name, $props)) { $return = $this->$name; } // host -> ihost elseif (($prop = 'i' . $name) && array_key_exists($prop, $props)) { $name = $prop; $return = $this->$prop; } // ischeme -> scheme elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props)) { $name = $prop; $return = $this->$prop; } else { trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE); $return = null; } if ($return === null && isset($this->normalization[$this->scheme][$name])) { return $this->normalization[$this->scheme][$name]; } else { return $return; } } ```
programming_docs
wordpress Requests_IRI::set_userinfo( string $iuserinfo ): bool Requests\_IRI::set\_userinfo( string $iuserinfo ): bool ======================================================= Set the iuserinfo. `$iuserinfo` string Required bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function set_userinfo($iuserinfo) { if ($iuserinfo === null) { $this->iuserinfo = null; } else { $this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, '!$&\'()*+,;=:'); $this->scheme_normalization(); } return true; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::replace\_invalid\_with\_pct\_encoding()](replace_invalid_with_pct_encoding) wp-includes/Requests/IRI.php | Replace invalid character with percent encoding | | [Requests\_IRI::scheme\_normalization()](scheme_normalization) wp-includes/Requests/IRI.php | | | Used By | Description | | --- | --- | | [Requests\_IRI::set\_authority()](set_authority) wp-includes/Requests/IRI.php | Set the authority. Returns true on success, false on failure (if there are any invalid characters). | wordpress Requests_IRI::get_authority(): string Requests\_IRI::get\_authority(): string ======================================= Get the complete authority string File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function get_authority() { $iauthority = $this->get_iauthority(); if (is_string($iauthority)) { return $this->to_uri($iauthority); } else { return $iauthority; } } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::get\_iauthority()](get_iauthority) wp-includes/Requests/IRI.php | Get the complete iauthority | | [Requests\_IRI::to\_uri()](to_uri) wp-includes/Requests/IRI.php | Convert an IRI to a URI (or parts thereof) | wordpress Requests_IRI::set_authority( string $authority ): bool Requests\_IRI::set\_authority( string $authority ): bool ======================================================== Set the authority. Returns true on success, false on failure (if there are any invalid characters). `$authority` string Required bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function set_authority($authority) { static $cache; if (!$cache) { $cache = array(); } if ($authority === null) { $this->iuserinfo = null; $this->ihost = null; $this->port = null; return true; } if (isset($cache[$authority])) { list($this->iuserinfo, $this->ihost, $this->port, $return) = $cache[$authority]; return $return; } $remaining = $authority; if (($iuserinfo_end = strrpos($remaining, '@')) !== false) { $iuserinfo = substr($remaining, 0, $iuserinfo_end); $remaining = substr($remaining, $iuserinfo_end + 1); } else { $iuserinfo = null; } if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) { $port = substr($remaining, $port_start + 1); if ($port === false || $port === '') { $port = null; } $remaining = substr($remaining, 0, $port_start); } else { $port = null; } $return = $this->set_userinfo($iuserinfo) && $this->set_host($remaining) && $this->set_port($port); $cache[$authority] = array($this->iuserinfo, $this->ihost, $this->port, $return); return $return; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::set\_userinfo()](set_userinfo) wp-includes/Requests/IRI.php | Set the iuserinfo. | | [Requests\_IRI::set\_host()](set_host) wp-includes/Requests/IRI.php | Set the ihost. Returns true on success, false on failure (if there are any invalid characters). | | [Requests\_IRI::set\_port()](set_port) wp-includes/Requests/IRI.php | Set the port. Returns true on success, false on failure (if there are any invalid characters). | | Used By | Description | | --- | --- | | [Requests\_IRI::set\_iri()](set_iri) wp-includes/Requests/IRI.php | Set the entire IRI. Returns true on success, false on failure (if there are any invalid characters). | wordpress Requests_IRI::get_iri(): string|false Requests\_IRI::get\_iri(): string|false ======================================= Get the complete IRI string|false File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function get_iri() { if (!$this->is_valid()) { return false; } $iri = ''; if ($this->scheme !== null) { $iri .= $this->scheme . ':'; } if (($iauthority = $this->get_iauthority()) !== null) { $iri .= '//' . $iauthority; } $iri .= $this->ipath; if ($this->iquery !== null) { $iri .= '?' . $this->iquery; } if ($this->ifragment !== null) { $iri .= '#' . $this->ifragment; } return $iri; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::get\_iauthority()](get_iauthority) wp-includes/Requests/IRI.php | Get the complete iauthority | | [Requests\_IRI::is\_valid()](is_valid) wp-includes/Requests/IRI.php | Check if the object represents a valid IRI. This needs to be done on each call as some things change depending on another part of the IRI. | | Used By | Description | | --- | --- | | [Requests\_IRI::get\_uri()](get_uri) wp-includes/Requests/IRI.php | Get the complete URI | | [Requests\_IRI::\_\_toString()](__tostring) wp-includes/Requests/IRI.php | Return the entire IRI when you try and read the object as a string | wordpress Requests_IRI::__isset( string $name ): bool Requests\_IRI::\_\_isset( string $name ): bool ============================================== Overload \_\_isset() to provide access via properties `$name` string Required Property name bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` public function __isset($name) { return (method_exists($this, 'get_' . $name) || isset($this->$name)); } ``` wordpress Requests_IRI::set_fragment( string $ifragment ): bool Requests\_IRI::set\_fragment( string $ifragment ): bool ======================================================= Set the ifragment. `$ifragment` string Required bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function set_fragment($ifragment) { if ($ifragment === null) { $this->ifragment = null; } else { $this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, '!$&\'()*+,;=:@/?'); $this->scheme_normalization(); } return true; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::replace\_invalid\_with\_pct\_encoding()](replace_invalid_with_pct_encoding) wp-includes/Requests/IRI.php | Replace invalid character with percent encoding | | [Requests\_IRI::scheme\_normalization()](scheme_normalization) wp-includes/Requests/IRI.php | | | Used By | Description | | --- | --- | | [Requests\_IRI::set\_iri()](set_iri) wp-includes/Requests/IRI.php | Set the entire IRI. Returns true on success, false on failure (if there are any invalid characters). | wordpress Requests_IRI::is_valid(): bool Requests\_IRI::is\_valid(): bool ================================ Check if the object represents a valid IRI. This needs to be done on each call as some things change depending on another part of the IRI. bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` public function is_valid() { $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null; if ($this->ipath !== '' && ( $isauthority && $this->ipath[0] !== '/' || ( $this->scheme === null && !$isauthority && strpos($this->ipath, ':') !== false && (strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/')) ) ) ) { return false; } return true; } ``` | Used By | Description | | --- | --- | | [Requests\_IRI::get\_iri()](get_iri) wp-includes/Requests/IRI.php | Get the complete IRI | wordpress Requests_IRI::set_scheme( string $scheme ): bool Requests\_IRI::set\_scheme( string $scheme ): bool ================================================== Set the scheme. Returns true on success, false on failure (if there are any invalid characters). `$scheme` string Required bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function set_scheme($scheme) { if ($scheme === null) { $this->scheme = null; } elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme)) { $this->scheme = null; return false; } else { $this->scheme = strtolower($scheme); } return true; } ``` | Used By | Description | | --- | --- | | [Requests\_IRI::set\_iri()](set_iri) wp-includes/Requests/IRI.php | Set the entire IRI. Returns true on success, false on failure (if there are any invalid characters). | wordpress Requests_IRI::scheme_normalization() Requests\_IRI::scheme\_normalization() ====================================== File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function scheme_normalization() { if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) { $this->iuserinfo = null; } if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost']) { $this->ihost = null; } if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port']) { $this->port = null; } if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath']) { $this->ipath = ''; } if (isset($this->ihost) && empty($this->ipath)) { $this->ipath = '/'; } if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery']) { $this->iquery = null; } if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment']) { $this->ifragment = null; } } ``` | Used By | Description | | --- | --- | | [Requests\_IRI::set\_userinfo()](set_userinfo) wp-includes/Requests/IRI.php | Set the iuserinfo. | | [Requests\_IRI::set\_host()](set_host) wp-includes/Requests/IRI.php | Set the ihost. Returns true on success, false on failure (if there are any invalid characters). | | [Requests\_IRI::set\_port()](set_port) wp-includes/Requests/IRI.php | Set the port. Returns true on success, false on failure (if there are any invalid characters). | | [Requests\_IRI::set\_path()](set_path) wp-includes/Requests/IRI.php | Set the ipath. | | [Requests\_IRI::set\_query()](set_query) wp-includes/Requests/IRI.php | Set the iquery. | | [Requests\_IRI::set\_fragment()](set_fragment) wp-includes/Requests/IRI.php | Set the ifragment. | wordpress Requests_IRI::__toString(): string Requests\_IRI::\_\_toString(): string ===================================== Return the entire IRI when you try and read the object as a string string File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` public function __toString() { return $this->get_iri(); } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::get\_iri()](get_iri) wp-includes/Requests/IRI.php | Get the complete IRI | wordpress Requests_IRI::remove_iunreserved_percent_encoded( array $match ): string Requests\_IRI::remove\_iunreserved\_percent\_encoded( array $match ): string ============================================================================ Callback function for preg\_replace\_callback. Removes sequences of percent encoded bytes that represent UTF-8 encoded characters in iunreserved `$match` array Required PCRE match string Replacement File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function remove_iunreserved_percent_encoded($match) { // As we just have valid percent encoded sequences we can just explode // and ignore the first member of the returned array (an empty string). $bytes = explode('%', $match[0]); // Initialize the new string (this is what will be returned) and that // there are no bytes remaining in the current sequence (unsurprising // at the first byte!). $string = ''; $remaining = 0; // Loop over each and every byte, and set $value to its value for ($i = 1, $len = count($bytes); $i < $len; $i++) { $value = hexdec($bytes[$i]); // If we're the first byte of sequence: if (!$remaining) { // Start position $start = $i; // By default we are valid $valid = true; // One byte sequence: if ($value <= 0x7F) { $character = $value; $length = 1; } // Two byte sequence: elseif (($value & 0xE0) === 0xC0) { $character = ($value & 0x1F) << 6; $length = 2; $remaining = 1; } // Three byte sequence: elseif (($value & 0xF0) === 0xE0) { $character = ($value & 0x0F) << 12; $length = 3; $remaining = 2; } // Four byte sequence: elseif (($value & 0xF8) === 0xF0) { $character = ($value & 0x07) << 18; $length = 4; $remaining = 3; } // Invalid byte: else { $valid = false; $remaining = 0; } } // Continuation byte: else { // Check that the byte is valid, then add it to the character: if (($value & 0xC0) === 0x80) { $remaining--; $character |= ($value & 0x3F) << ($remaining * 6); } // If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence: else { $valid = false; $remaining = 0; $i--; } } // If we've reached the end of the current byte sequence, append it to Unicode::$data if (!$remaining) { // Percent encode anything invalid or not in iunreserved if ( // Invalid sequences !$valid // Non-shortest form sequences are invalid || $length > 1 && $character <= 0x7F || $length > 2 && $character <= 0x7FF || $length > 3 && $character <= 0xFFFF // Outside of range of iunreserved codepoints || $character < 0x2D || $character > 0xEFFFD // Noncharacters || ($character & 0xFFFE) === 0xFFFE || $character >= 0xFDD0 && $character <= 0xFDEF // Everything else not in iunreserved (this is all BMP) || $character === 0x2F || $character > 0x39 && $character < 0x41 || $character > 0x5A && $character < 0x61 || $character > 0x7A && $character < 0x7E || $character > 0x7E && $character < 0xA0 || $character > 0xD7FF && $character < 0xF900 ) { for ($j = $start; $j <= $i; $j++) { $string .= '%' . strtoupper($bytes[$j]); } } else { for ($j = $start; $j <= $i; $j++) { $string .= chr(hexdec($bytes[$j])); } } } } // If we have any bytes left over they are invalid (i.e., we are // mid-way through a multi-byte sequence) if ($remaining) { for ($j = $start; $j < $len; $j++) { $string .= '%' . strtoupper($bytes[$j]); } } return $string; } ``` wordpress Requests_IRI::__construct( string|null $iri = null ) Requests\_IRI::\_\_construct( string|null $iri = null ) ======================================================= Create a new IRI object, from a specified string `$iri` string|null Optional Default: `null` File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` public function __construct($iri = null) { $this->set_iri($iri); } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::set\_iri()](set_iri) wp-includes/Requests/IRI.php | Set the entire IRI. Returns true on success, false on failure (if there are any invalid characters). | | Used By | Description | | --- | --- | | [Requests::set\_defaults()](../requests/set_defaults) wp-includes/class-requests.php | Set the default values | | [Requests\_IRI::absolutize()](absolutize) wp-includes/Requests/IRI.php | Create a new IRI object by resolving a relative IRI | | [Requests\_Cookie\_Jar::before\_request()](../requests_cookie_jar/before_request) wp-includes/Requests/Cookie/Jar.php | Add Cookie header to a request if we have any | | [Requests\_Cookie\_Jar::before\_redirect\_check()](../requests_cookie_jar/before_redirect_check) wp-includes/Requests/Cookie/Jar.php | Parse all cookies from a response and attach them to the response | wordpress Requests_IRI::absolutize( Requests_IRI|string $base, Requests_IRI|string $relative ): Requests_IRI|false Requests\_IRI::absolutize( Requests\_IRI|string $base, Requests\_IRI|string $relative ): Requests\_IRI|false ============================================================================================================ Create a new IRI object by resolving a relative IRI Returns false if $base is not absolute, otherwise an IRI. `$base` [Requests\_IRI](../requests_iri)|string Required (Absolute) Base IRI `$relative` [Requests\_IRI](../requests_iri)|string Required Relative IRI [Requests\_IRI](../requests_iri)|false File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` public static function absolutize($base, $relative) { if (!($relative instanceof Requests_IRI)) { $relative = new Requests_IRI($relative); } if (!$relative->is_valid()) { return false; } elseif ($relative->scheme !== null) { return clone $relative; } if (!($base instanceof Requests_IRI)) { $base = new Requests_IRI($base); } if ($base->scheme === null || !$base->is_valid()) { return false; } if ($relative->get_iri() !== '') { if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null) { $target = clone $relative; $target->scheme = $base->scheme; } else { $target = new Requests_IRI; $target->scheme = $base->scheme; $target->iuserinfo = $base->iuserinfo; $target->ihost = $base->ihost; $target->port = $base->port; if ($relative->ipath !== '') { if ($relative->ipath[0] === '/') { $target->ipath = $relative->ipath; } elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '') { $target->ipath = '/' . $relative->ipath; } elseif (($last_segment = strrpos($base->ipath, '/')) !== false) { $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath; } else { $target->ipath = $relative->ipath; } $target->ipath = $target->remove_dot_segments($target->ipath); $target->iquery = $relative->iquery; } else { $target->ipath = $base->ipath; if ($relative->iquery !== null) { $target->iquery = $relative->iquery; } elseif ($base->iquery !== null) { $target->iquery = $base->iquery; } } $target->ifragment = $relative->ifragment; } } else { $target = clone $base; $target->ifragment = null; } $target->scheme_normalization(); return $target; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::\_\_construct()](__construct) wp-includes/Requests/IRI.php | Create a new IRI object, from a specified string | | Used By | Description | | --- | --- | | [Requests::parse\_response()](../requests/parse_response) wp-includes/class-requests.php | HTTP response parser | | [Requests\_Session::merge\_request()](../requests_session/merge_request) wp-includes/Requests/Session.php | Merge a request’s data with the default data |
programming_docs
wordpress Requests_IRI::get_iauthority(): string|null Requests\_IRI::get\_iauthority(): string|null ============================================= Get the complete iauthority string|null File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function get_iauthority() { if ($this->iuserinfo === null && $this->ihost === null && $this->port === null) { return null; } $iauthority = ''; if ($this->iuserinfo !== null) { $iauthority .= $this->iuserinfo . '@'; } if ($this->ihost !== null) { $iauthority .= $this->ihost; } if ($this->port !== null) { $iauthority .= ':' . $this->port; } return $iauthority; } ``` | Used By | Description | | --- | --- | | [Requests\_IRI::get\_iri()](get_iri) wp-includes/Requests/IRI.php | Get the complete IRI | | [Requests\_IRI::get\_authority()](get_authority) wp-includes/Requests/IRI.php | Get the complete authority | wordpress Requests_IRI::set_path( string $ipath ): bool Requests\_IRI::set\_path( string $ipath ): bool =============================================== Set the ipath. `$ipath` string Required bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function set_path($ipath) { static $cache; if (!$cache) { $cache = array(); } $ipath = (string) $ipath; if (isset($cache[$ipath])) { $this->ipath = $cache[$ipath][(int) ($this->scheme !== null)]; } else { $valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/'); $removed = $this->remove_dot_segments($valid); $cache[$ipath] = array($valid, $removed); $this->ipath = ($this->scheme !== null) ? $removed : $valid; } $this->scheme_normalization(); return true; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::replace\_invalid\_with\_pct\_encoding()](replace_invalid_with_pct_encoding) wp-includes/Requests/IRI.php | Replace invalid character with percent encoding | | [Requests\_IRI::remove\_dot\_segments()](remove_dot_segments) wp-includes/Requests/IRI.php | Remove dot segments from a path | | [Requests\_IRI::scheme\_normalization()](scheme_normalization) wp-includes/Requests/IRI.php | | | Used By | Description | | --- | --- | | [Requests\_IRI::set\_iri()](set_iri) wp-includes/Requests/IRI.php | Set the entire IRI. Returns true on success, false on failure (if there are any invalid characters). | wordpress Requests_IRI::set_iri( string $iri ): bool Requests\_IRI::set\_iri( string $iri ): bool ============================================ Set the entire IRI. Returns true on success, false on failure (if there are any invalid characters). `$iri` string Required bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function set_iri($iri) { static $cache; if (!$cache) { $cache = array(); } if ($iri === null) { return true; } if (isset($cache[$iri])) { list($this->scheme, $this->iuserinfo, $this->ihost, $this->port, $this->ipath, $this->iquery, $this->ifragment, $return) = $cache[$iri]; return $return; } $parsed = $this->parse_iri((string) $iri); $return = $this->set_scheme($parsed['scheme']) && $this->set_authority($parsed['authority']) && $this->set_path($parsed['path']) && $this->set_query($parsed['query']) && $this->set_fragment($parsed['fragment']); $cache[$iri] = array($this->scheme, $this->iuserinfo, $this->ihost, $this->port, $this->ipath, $this->iquery, $this->ifragment, $return); return $return; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::set\_scheme()](set_scheme) wp-includes/Requests/IRI.php | Set the scheme. Returns true on success, false on failure (if there are any invalid characters). | | [Requests\_IRI::set\_authority()](set_authority) wp-includes/Requests/IRI.php | Set the authority. Returns true on success, false on failure (if there are any invalid characters). | | [Requests\_IRI::set\_path()](set_path) wp-includes/Requests/IRI.php | Set the ipath. | | [Requests\_IRI::set\_query()](set_query) wp-includes/Requests/IRI.php | Set the iquery. | | [Requests\_IRI::set\_fragment()](set_fragment) wp-includes/Requests/IRI.php | Set the ifragment. | | [Requests\_IRI::parse\_iri()](parse_iri) wp-includes/Requests/IRI.php | Parse an IRI into scheme/authority/path/query/fragment segments | | Used By | Description | | --- | --- | | [Requests\_IRI::\_\_construct()](__construct) wp-includes/Requests/IRI.php | Create a new IRI object, from a specified string | wordpress Requests_IRI::get_uri(): string Requests\_IRI::get\_uri(): string ================================= Get the complete URI string File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function get_uri() { return $this->to_uri($this->get_iri()); } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::to\_uri()](to_uri) wp-includes/Requests/IRI.php | Convert an IRI to a URI (or parts thereof) | | [Requests\_IRI::get\_iri()](get_iri) wp-includes/Requests/IRI.php | Get the complete IRI | wordpress Requests_IRI::set_host( string $ihost ): bool Requests\_IRI::set\_host( string $ihost ): bool =============================================== Set the ihost. Returns true on success, false on failure (if there are any invalid characters). `$ihost` string Required bool File: `wp-includes/Requests/IRI.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/iri.php/) ``` protected function set_host($ihost) { if ($ihost === null) { $this->ihost = null; return true; } if (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']') { if (Requests_IPv6::check_ipv6(substr($ihost, 1, -1))) { $this->ihost = '[' . Requests_IPv6::compress(substr($ihost, 1, -1)) . ']'; } else { $this->ihost = null; return false; } } else { $ihost = $this->replace_invalid_with_pct_encoding($ihost, '!$&\'()*+,;='); // Lowercase, but ignore pct-encoded sections (as they should // remain uppercase). This must be done after the previous step // as that can add unescaped characters. $position = 0; $strlen = strlen($ihost); while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen) { if ($ihost[$position] === '%') { $position += 3; } else { $ihost[$position] = strtolower($ihost[$position]); $position++; } } $this->ihost = $ihost; } $this->scheme_normalization(); return true; } ``` | Uses | Description | | --- | --- | | [Requests\_IRI::replace\_invalid\_with\_pct\_encoding()](replace_invalid_with_pct_encoding) wp-includes/Requests/IRI.php | Replace invalid character with percent encoding | | [Requests\_IRI::scheme\_normalization()](scheme_normalization) wp-includes/Requests/IRI.php | | | [Requests\_IPv6::check\_ipv6()](../requests_ipv6/check_ipv6) wp-includes/Requests/IPv6.php | Checks an IPv6 address | | [Requests\_IPv6::compress()](../requests_ipv6/compress) wp-includes/Requests/IPv6.php | Compresses an IPv6 address | | Used By | Description | | --- | --- | | [Requests\_IRI::set\_authority()](set_authority) wp-includes/Requests/IRI.php | Set the authority. Returns true on success, false on failure (if there are any invalid characters). | wordpress WP_Nav_Menu_Widget::form( array $instance ) WP\_Nav\_Menu\_Widget::form( array $instance ) ============================================== Outputs the settings form for the Navigation Menu widget. `$instance` array Required Current settings. File: `wp-includes/widgets/class-wp-nav-menu-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-nav-menu-widget.php/) ``` public function form( $instance ) { global $wp_customize; $title = isset( $instance['title'] ) ? $instance['title'] : ''; $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : ''; // Get menus. $menus = wp_get_nav_menus(); $empty_menus_style = ''; $not_empty_menus_style = ''; if ( empty( $menus ) ) { $empty_menus_style = ' style="display:none" '; } else { $not_empty_menus_style = ' style="display:none" '; } $nav_menu_style = ''; if ( ! $nav_menu ) { $nav_menu_style = 'display: none;'; } // If no menus exists, direct the user to go and create some. ?> <p class="nav-menu-widget-no-menus-message" <?php echo $not_empty_menus_style; ?>> <?php if ( $wp_customize instanceof WP_Customize_Manager ) { $url = 'javascript: wp.customize.panel( "nav_menus" ).focus();'; } else { $url = admin_url( 'nav-menus.php' ); } printf( /* translators: %s: URL to create a new menu. */ __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), // The URL can be a `javascript:` link, so esc_attr() is used here instead of esc_url(). esc_attr( $url ) ); ?> </p> <div class="nav-menu-widget-form-controls" <?php echo $empty_menus_style; ?>> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>" /> </p> <p> <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label> <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>"> <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option> <?php foreach ( $menus as $menu ) : ?> <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $nav_menu, $menu->term_id ); ?>> <?php echo esc_html( $menu->name ); ?> </option> <?php endforeach; ?> </select> </p> <?php if ( $wp_customize instanceof WP_Customize_Manager ) : ?> <p class="edit-selected-nav-menu" style="<?php echo $nav_menu_style; ?>"> <button type="button" class="button"><?php _e( 'Edit Menu' ); ?></button> </p> <?php endif; ?> </div> <?php } ``` | Uses | Description | | --- | --- | | [wp\_get\_nav\_menus()](../../functions/wp_get_nav_menus) wp-includes/nav-menu.php | Returns all navigation menu objects. | | [selected()](../../functions/selected) wp-includes/general-template.php | Outputs the HTML selected attribute. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress WP_Nav_Menu_Widget::update( array $new_instance, array $old_instance ): array WP\_Nav\_Menu\_Widget::update( array $new\_instance, array $old\_instance ): array ================================================================================== Handles updating settings for the current Navigation Menu widget instance. `$new_instance` array Required New settings for this instance as input by the user via [WP\_Widget::form()](../wp_widget/form). `$old_instance` array Required Old settings for this instance. array Updated settings to save. File: `wp-includes/widgets/class-wp-nav-menu-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-nav-menu-widget.php/) ``` public function update( $new_instance, $old_instance ) { $instance = array(); if ( ! empty( $new_instance['title'] ) ) { $instance['title'] = sanitize_text_field( $new_instance['title'] ); } if ( ! empty( $new_instance['nav_menu'] ) ) { $instance['nav_menu'] = (int) $new_instance['nav_menu']; } return $instance; } ``` | Uses | Description | | --- | --- | | [sanitize\_text\_field()](../../functions/sanitize_text_field) wp-includes/formatting.php | Sanitizes a string from user input or from the database. | | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress WP_Nav_Menu_Widget::__construct() WP\_Nav\_Menu\_Widget::\_\_construct() ====================================== Sets up a new Navigation Menu widget instance. File: `wp-includes/widgets/class-wp-nav-menu-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-nav-menu-widget.php/) ``` public function __construct() { $widget_ops = array( 'description' => __( 'Add a navigation menu to your sidebar.' ), 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, ); parent::__construct( 'nav_menu', __( 'Navigation Menu' ), $widget_ops ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget::\_\_construct()](../wp_widget/__construct) wp-includes/class-wp-widget.php | PHP5 constructor. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress WP_Nav_Menu_Widget::widget( array $args, array $instance ) WP\_Nav\_Menu\_Widget::widget( array $args, array $instance ) ============================================================= Outputs the content for the current Navigation Menu widget instance. `$args` array Required Display arguments including `'before_title'`, `'after_title'`, `'before_widget'`, and `'after_widget'`. `$instance` array Required Settings for the current Navigation Menu widget instance. File: `wp-includes/widgets/class-wp-nav-menu-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-nav-menu-widget.php/) ``` public function widget( $args, $instance ) { // Get menu. $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; if ( ! $nav_menu ) { return; } $default_title = __( 'Menu' ); $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml'; /** * Filters the HTML format of widgets with navigation links. * * @since 5.5.0 * * @param string $format The type of markup to use in widgets with navigation links. * Accepts 'html5', 'xhtml'. */ $format = apply_filters( 'navigation_widgets_format', $format ); if ( 'html5' === $format ) { // The title may be filtered: Strip out HTML and make sure the aria-label is never empty. $title = trim( strip_tags( $title ) ); $aria_label = $title ? $title : $default_title; $nav_menu_args = array( 'fallback_cb' => '', 'menu' => $nav_menu, 'container' => 'nav', 'container_aria_label' => $aria_label, 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', ); } else { $nav_menu_args = array( 'fallback_cb' => '', 'menu' => $nav_menu, ); } /** * Filters the arguments for the Navigation Menu widget. * * @since 4.2.0 * @since 4.4.0 Added the `$instance` parameter. * * @param array $nav_menu_args { * An array of arguments passed to wp_nav_menu() to retrieve a navigation menu. * * @type callable|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty. * @type mixed $menu Menu ID, slug, or name. * } * @param WP_Term $nav_menu Nav menu object for the current menu. * @param array $args Display arguments for the current widget. * @param array $instance Array of settings for the current widget. */ wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args, $instance ) ); echo $args['after_widget']; } ``` [apply\_filters( 'navigation\_widgets\_format', string $format )](../../hooks/navigation_widgets_format) Filters the HTML format of widgets with navigation links. [apply\_filters( 'widget\_nav\_menu\_args', array $nav\_menu\_args, WP\_Term $nav\_menu, array $args, array $instance )](../../hooks/widget_nav_menu_args) Filters the arguments for the Navigation Menu widget. [apply\_filters( 'widget\_title', string $title, array $instance, mixed $id\_base )](../../hooks/widget_title) Filters the widget title. | Uses | Description | | --- | --- | | [wp\_nav\_menu()](../../functions/wp_nav_menu) wp-includes/nav-menu-template.php | Displays a navigation menu. | | [wp\_get\_nav\_menu\_object()](../../functions/wp_get_nav_menu_object) wp-includes/nav-menu.php | Returns a navigation menu object. | | [current\_theme\_supports()](../../functions/current_theme_supports) wp-includes/theme.php | Checks a theme’s support for a given feature. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress WP_Sitemaps_Stylesheet::get_sitemap_index_stylesheet() WP\_Sitemaps\_Stylesheet::get\_sitemap\_index\_stylesheet() =========================================================== Returns the escaped XSL for the index sitemaps. File: `wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php/) ``` public function get_sitemap_index_stylesheet() { $css = $this->get_stylesheet_css(); $title = esc_xml( __( 'XML Sitemap' ) ); $description = esc_xml( __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' ) ); $learn_more = sprintf( '<a href="%s">%s</a>', esc_url( __( 'https://www.sitemaps.org/' ) ), esc_xml( __( 'Learn more about XML sitemaps.' ) ) ); $text = sprintf( /* translators: %s: Number of URLs. */ esc_xml( __( 'Number of URLs in this XML Sitemap: %s.' ) ), '<xsl:value-of select="count( sitemap:sitemapindex/sitemap:sitemap )" />' ); $lang = get_language_attributes( 'html' ); $url = esc_xml( __( 'URL' ) ); $lastmod = esc_xml( __( 'Last Modified' ) ); $xsl_content = <<<XSL <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" exclude-result-prefixes="sitemap" > <xsl:output method="html" encoding="UTF-8" indent="yes" /> <!-- Set variables for whether lastmod occurs for any sitemap in the index. We do this up front because it can be expensive in a large sitemap. --> <xsl:variable name="has-lastmod" select="count( /sitemap:sitemapindex/sitemap:sitemap/sitemap:lastmod )" /> <xsl:template match="/"> <html {$lang}> <head> <title>{$title}</title> <style> {$css} </style> </head> <body> <div id="sitemap"> <div id="sitemap__header"> <h1>{$title}</h1> <p>{$description}</p> <p>{$learn_more}</p> </div> <div id="sitemap__content"> <p class="text">{$text}</p> <table id="sitemap__table"> <thead> <tr> <th class="loc">{$url}</th> <xsl:if test="\$has-lastmod"> <th class="lastmod">{$lastmod}</th> </xsl:if> </tr> </thead> <tbody> <xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap"> <tr> <td class="loc"><a href="{sitemap:loc}"><xsl:value-of select="sitemap:loc" /></a></td> <xsl:if test="\$has-lastmod"> <td class="lastmod"><xsl:value-of select="sitemap:lastmod" /></td> </xsl:if> </tr> </xsl:for-each> </tbody> </table> </div> </div> </body> </html> </xsl:template> </xsl:stylesheet> XSL; /** * Filters the content of the sitemap index stylesheet. * * @since 5.5.0 * * @param string $xsl_content Full content for the XML stylesheet. */ return apply_filters( 'wp_sitemaps_stylesheet_index_content', $xsl_content ); } ``` [apply\_filters( 'wp\_sitemaps\_stylesheet\_index\_content', string $xsl\_content )](../../hooks/wp_sitemaps_stylesheet_index_content) Filters the content of the sitemap index stylesheet. | Uses | Description | | --- | --- | | [esc\_xml()](../../functions/esc_xml) wp-includes/formatting.php | Escaping for XML blocks. | | [WP\_Sitemaps\_Stylesheet::get\_stylesheet\_css()](get_stylesheet_css) wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php | Gets the CSS to be included in sitemap XSL stylesheets. | | [get\_language\_attributes()](../../functions/get_language_attributes) wp-includes/general-template.php | Gets the language attributes for the ‘html’ tag. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Stylesheet::render\_stylesheet()](render_stylesheet) wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php | Renders the XSL stylesheet depending on whether it’s the sitemap index or not. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |
programming_docs
wordpress WP_Sitemaps_Stylesheet::get_sitemap_stylesheet() WP\_Sitemaps\_Stylesheet::get\_sitemap\_stylesheet() ==================================================== Returns the escaped XSL for all sitemaps, except index. File: `wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php/) ``` public function get_sitemap_stylesheet() { $css = $this->get_stylesheet_css(); $title = esc_xml( __( 'XML Sitemap' ) ); $description = esc_xml( __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' ) ); $learn_more = sprintf( '<a href="%s">%s</a>', esc_url( __( 'https://www.sitemaps.org/' ) ), esc_xml( __( 'Learn more about XML sitemaps.' ) ) ); $text = sprintf( /* translators: %s: Number of URLs. */ esc_xml( __( 'Number of URLs in this XML Sitemap: %s.' ) ), '<xsl:value-of select="count( sitemap:urlset/sitemap:url )" />' ); $lang = get_language_attributes( 'html' ); $url = esc_xml( __( 'URL' ) ); $lastmod = esc_xml( __( 'Last Modified' ) ); $changefreq = esc_xml( __( 'Change Frequency' ) ); $priority = esc_xml( __( 'Priority' ) ); $xsl_content = <<<XSL <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" exclude-result-prefixes="sitemap" > <xsl:output method="html" encoding="UTF-8" indent="yes" /> <!-- Set variables for whether lastmod, changefreq or priority occur for any url in the sitemap. We do this up front because it can be expensive in a large sitemap. --> <xsl:variable name="has-lastmod" select="count( /sitemap:urlset/sitemap:url/sitemap:lastmod )" /> <xsl:variable name="has-changefreq" select="count( /sitemap:urlset/sitemap:url/sitemap:changefreq )" /> <xsl:variable name="has-priority" select="count( /sitemap:urlset/sitemap:url/sitemap:priority )" /> <xsl:template match="/"> <html {$lang}> <head> <title>{$title}</title> <style> {$css} </style> </head> <body> <div id="sitemap"> <div id="sitemap__header"> <h1>{$title}</h1> <p>{$description}</p> <p>{$learn_more}</p> </div> <div id="sitemap__content"> <p class="text">{$text}</p> <table id="sitemap__table"> <thead> <tr> <th class="loc">{$url}</th> <xsl:if test="\$has-lastmod"> <th class="lastmod">{$lastmod}</th> </xsl:if> <xsl:if test="\$has-changefreq"> <th class="changefreq">{$changefreq}</th> </xsl:if> <xsl:if test="\$has-priority"> <th class="priority">{$priority}</th> </xsl:if> </tr> </thead> <tbody> <xsl:for-each select="sitemap:urlset/sitemap:url"> <tr> <td class="loc"><a href="{sitemap:loc}"><xsl:value-of select="sitemap:loc" /></a></td> <xsl:if test="\$has-lastmod"> <td class="lastmod"><xsl:value-of select="sitemap:lastmod" /></td> </xsl:if> <xsl:if test="\$has-changefreq"> <td class="changefreq"><xsl:value-of select="sitemap:changefreq" /></td> </xsl:if> <xsl:if test="\$has-priority"> <td class="priority"><xsl:value-of select="sitemap:priority" /></td> </xsl:if> </tr> </xsl:for-each> </tbody> </table> </div> </div> </body> </html> </xsl:template> </xsl:stylesheet> XSL; /** * Filters the content of the sitemap stylesheet. * * @since 5.5.0 * * @param string $xsl_content Full content for the XML stylesheet. */ return apply_filters( 'wp_sitemaps_stylesheet_content', $xsl_content ); } ``` [apply\_filters( 'wp\_sitemaps\_stylesheet\_content', string $xsl\_content )](../../hooks/wp_sitemaps_stylesheet_content) Filters the content of the sitemap stylesheet. | Uses | Description | | --- | --- | | [esc\_xml()](../../functions/esc_xml) wp-includes/formatting.php | Escaping for XML blocks. | | [WP\_Sitemaps\_Stylesheet::get\_stylesheet\_css()](get_stylesheet_css) wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php | Gets the CSS to be included in sitemap XSL stylesheets. | | [get\_language\_attributes()](../../functions/get_language_attributes) wp-includes/general-template.php | Gets the language attributes for the ‘html’ tag. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Stylesheet::render\_stylesheet()](render_stylesheet) wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php | Renders the XSL stylesheet depending on whether it’s the sitemap index or not. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Stylesheet::get_stylesheet_css(): string WP\_Sitemaps\_Stylesheet::get\_stylesheet\_css(): string ======================================================== Gets the CSS to be included in sitemap XSL stylesheets. string The CSS. File: `wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php/) ``` public function get_stylesheet_css() { $text_align = is_rtl() ? 'right' : 'left'; $css = <<<EOF body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; color: #444; } #sitemap { max-width: 980px; margin: 0 auto; } #sitemap__table { width: 100%; border: solid 1px #ccc; border-collapse: collapse; } #sitemap__table tr td.loc { /* * URLs should always be LTR. * See https://core.trac.wordpress.org/ticket/16834 * and https://core.trac.wordpress.org/ticket/49949 */ direction: ltr; } #sitemap__table tr th { text-align: {$text_align}; } #sitemap__table tr td, #sitemap__table tr th { padding: 10px; } #sitemap__table tr:nth-child(odd) td { background-color: #eee; } a:hover { text-decoration: none; } EOF; /** * Filters the CSS only for the sitemap stylesheet. * * @since 5.5.0 * * @param string $css CSS to be applied to default XSL file. */ return apply_filters( 'wp_sitemaps_stylesheet_css', $css ); } ``` [apply\_filters( 'wp\_sitemaps\_stylesheet\_css', string $css )](../../hooks/wp_sitemaps_stylesheet_css) Filters the CSS only for the sitemap stylesheet. | Uses | Description | | --- | --- | | [is\_rtl()](../../functions/is_rtl) wp-includes/l10n.php | Determines whether the current locale is right-to-left (RTL). | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Stylesheet::get\_sitemap\_stylesheet()](get_sitemap_stylesheet) wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php | Returns the escaped XSL for all sitemaps, except index. | | [WP\_Sitemaps\_Stylesheet::get\_sitemap\_index\_stylesheet()](get_sitemap_index_stylesheet) wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php | Returns the escaped XSL for the index sitemaps. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Stylesheet::render_stylesheet( string $type ) WP\_Sitemaps\_Stylesheet::render\_stylesheet( string $type ) ============================================================ Renders the XSL stylesheet depending on whether it’s the sitemap index or not. `$type` string Required Stylesheet type. Either `'sitemap'` or `'index'`. File: `wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php/) ``` public function render_stylesheet( $type ) { header( 'Content-type: application/xml; charset=UTF-8' ); if ( 'sitemap' === $type ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All content escaped below. echo $this->get_sitemap_stylesheet(); } if ( 'index' === $type ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All content escaped below. echo $this->get_sitemap_index_stylesheet(); } exit; } ``` | Uses | Description | | --- | --- | | [WP\_Sitemaps\_Stylesheet::get\_sitemap\_stylesheet()](get_sitemap_stylesheet) wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php | Returns the escaped XSL for all sitemaps, except index. | | [WP\_Sitemaps\_Stylesheet::get\_sitemap\_index\_stylesheet()](get_sitemap_index_stylesheet) wp-includes/sitemaps/class-wp-sitemaps-stylesheet.php | Returns the escaped XSL for the index sitemaps. | wordpress WP_Internal_Pointers::pointer_wp360_locks() WP\_Internal\_Pointers::pointer\_wp360\_locks() =============================================== File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp360_locks() {} ``` wordpress WP_Internal_Pointers::pointer_wp340_choose_image_from_library() WP\_Internal\_Pointers::pointer\_wp340\_choose\_image\_from\_library() ====================================================================== File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp340_choose_image_from_library() {} ``` wordpress WP_Internal_Pointers::pointer_wp410_dfw() WP\_Internal\_Pointers::pointer\_wp410\_dfw() ============================================= File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp410_dfw() {} ``` wordpress WP_Internal_Pointers::print_js( string $pointer_id, string $selector, array $args ) WP\_Internal\_Pointers::print\_js( string $pointer\_id, string $selector, array $args ) ======================================================================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Print the pointer JavaScript data. `$pointer_id` string Required The pointer ID. `$selector` string Required The HTML elements, on which the pointer should be attached. `$args` array Required Arguments to be passed to the pointer JS (see wp-pointer.js). File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` private static function print_js( $pointer_id, $selector, $args ) { if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) { return; } ?> <script type="text/javascript"> (function($){ var options = <?php echo wp_json_encode( $args ); ?>, setup; if ( ! options ) return; options = $.extend( options, { close: function() { $.post( ajaxurl, { pointer: '<?php echo $pointer_id; ?>', action: 'dismiss-wp-pointer' }); } }); setup = function() { $('<?php echo $selector; ?>').first().pointer( options ).pointer('open'); }; if ( options.position && options.position.defer_loading ) $(window).bind( 'load.wp-pointers', setup ); else $( function() { setup(); } ); })( jQuery ); </script> <?php } ``` | Uses | Description | | --- | --- | | [wp\_json\_encode()](../../functions/wp_json_encode) wp-includes/functions.php | Encodes a variable into JSON, with some sanity checks. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Internal_Pointers::pointer_wp330_media_uploader() WP\_Internal\_Pointers::pointer\_wp330\_media\_uploader() ========================================================= File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp330_media_uploader() {} ``` wordpress WP_Internal_Pointers::pointer_wp390_widgets() WP\_Internal\_Pointers::pointer\_wp390\_widgets() ================================================= File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp390_widgets() {} ``` wordpress WP_Internal_Pointers::pointer_wp360_revisions() WP\_Internal\_Pointers::pointer\_wp360\_revisions() =================================================== File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp360_revisions() {} ``` wordpress WP_Internal_Pointers::dismiss_pointers_for_new_users( int $user_id ) WP\_Internal\_Pointers::dismiss\_pointers\_for\_new\_users( int $user\_id ) =========================================================================== Prevents new users from seeing existing ‘new feature’ pointers. `$user_id` int Required User ID. File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function dismiss_pointers_for_new_users( $user_id ) { add_user_meta( $user_id, 'dismissed_wp_pointers', '' ); } ``` | Uses | Description | | --- | --- | | [add\_user\_meta()](../../functions/add_user_meta) wp-includes/user.php | Adds meta data to a user. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Internal_Pointers::pointer_wp350_media() WP\_Internal\_Pointers::pointer\_wp350\_media() =============================================== File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp350_media() {} ``` wordpress WP_Internal_Pointers::pointer_wp340_customize_current_theme_link() WP\_Internal\_Pointers::pointer\_wp340\_customize\_current\_theme\_link() ========================================================================= File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp340_customize_current_theme_link() {} ``` wordpress WP_Internal_Pointers::pointer_wp496_privacy() WP\_Internal\_Pointers::pointer\_wp496\_privacy() ================================================= File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp496_privacy() {} ``` wordpress WP_Internal_Pointers::pointer_wp330_toolbar() WP\_Internal\_Pointers::pointer\_wp330\_toolbar() ================================================= File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp330_toolbar() {} ``` wordpress WP_Internal_Pointers::enqueue_scripts( string $hook_suffix ) WP\_Internal\_Pointers::enqueue\_scripts( string $hook\_suffix ) ================================================================ Initializes the new feature pointers. `$hook_suffix` string Required The current admin page. File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function enqueue_scripts( $hook_suffix ) { /* * Register feature pointers * * Format: * array( * hook_suffix => pointer callback * ) * * Example: * array( * 'themes.php' => 'wp390_widgets' * ) */ $registered_pointers = array( // None currently. ); // Check if screen related pointer is registered. if ( empty( $registered_pointers[ $hook_suffix ] ) ) { return; } $pointers = (array) $registered_pointers[ $hook_suffix ]; /* * Specify required capabilities for feature pointers * * Format: * array( * pointer callback => Array of required capabilities * ) * * Example: * array( * 'wp390_widgets' => array( 'edit_theme_options' ) * ) */ $caps_required = array( // None currently. ); // Get dismissed pointers. $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); $got_pointers = false; foreach ( array_diff( $pointers, $dismissed ) as $pointer ) { if ( isset( $caps_required[ $pointer ] ) ) { foreach ( $caps_required[ $pointer ] as $cap ) { if ( ! current_user_can( $cap ) ) { continue 2; } } } // Bind pointer print function. add_action( 'admin_print_footer_scripts', array( 'WP_Internal_Pointers', 'pointer_' . $pointer ) ); $got_pointers = true; } if ( ! $got_pointers ) { return; } // Add pointers script and style to queue. wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'wp-pointer' ); } ``` | Uses | Description | | --- | --- | | [wp\_enqueue\_script()](../../functions/wp_enqueue_script) wp-includes/functions.wp-scripts.php | Enqueue a script. | | [wp\_enqueue\_style()](../../functions/wp_enqueue_style) wp-includes/functions.wp-styles.php | Enqueue a CSS stylesheet. | | [get\_user\_meta()](../../functions/get_user_meta) wp-includes/user.php | Retrieves user meta field for a user. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [get\_current\_user\_id()](../../functions/get_current_user_id) wp-includes/user.php | Gets the current user’s ID. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Internal_Pointers::pointer_wp330_saving_widgets() WP\_Internal\_Pointers::pointer\_wp330\_saving\_widgets() ========================================================= File: `wp-admin/includes/class-wp-internal-pointers.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-internal-pointers.php/) ``` public static function pointer_wp330_saving_widgets() {} ```
programming_docs
wordpress WP_Themes_List_Table::prepare_items() WP\_Themes\_List\_Table::prepare\_items() ========================================= File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function prepare_items() { $themes = wp_get_themes( array( 'allowed' => true ) ); if ( ! empty( $_REQUEST['s'] ) ) { $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) ); } if ( ! empty( $_REQUEST['features'] ) ) { $this->features = $_REQUEST['features']; } if ( $this->search_terms || $this->features ) { foreach ( $themes as $key => $theme ) { if ( ! $this->search_theme( $theme ) ) { unset( $themes[ $key ] ); } } } unset( $themes[ get_option( 'stylesheet' ) ] ); WP_Theme::sort_by_name( $themes ); $per_page = 36; $page = $this->get_pagenum(); $start = ( $page - 1 ) * $per_page; $this->items = array_slice( $themes, $start, $per_page, true ); $this->set_pagination_args( array( 'total_items' => count( $themes ), 'per_page' => $per_page, 'infinite_scroll' => true, ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Themes\_List\_Table::search\_theme()](search_theme) wp-admin/includes/class-wp-themes-list-table.php | | | [wp\_get\_themes()](../../functions/wp_get_themes) wp-includes/theme.php | Returns an array of [WP\_Theme](../wp_theme) objects based on the arguments. | | [WP\_Theme::sort\_by\_name()](../wp_theme/sort_by_name) wp-includes/class-wp-theme.php | Sorts themes by name. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | wordpress WP_Themes_List_Table::ajax_user_can(): bool WP\_Themes\_List\_Table::ajax\_user\_can(): bool ================================================ bool File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function ajax_user_can() { // Do not check edit_theme_options here. Ajax calls for available themes require switch_themes. return current_user_can( 'switch_themes' ); } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | wordpress WP_Themes_List_Table::display_rows() WP\_Themes\_List\_Table::display\_rows() ======================================== File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function display_rows() { $themes = $this->items; foreach ( $themes as $theme ) : ?> <div class="available-theme"> <?php $template = $theme->get_template(); $stylesheet = $theme->get_stylesheet(); $title = $theme->display( 'Name' ); $version = $theme->display( 'Version' ); $author = $theme->display( 'Author' ); $activate_link = wp_nonce_url( 'themes.php?action=activate&amp;template=' . urlencode( $template ) . '&amp;stylesheet=' . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet ); $actions = array(); $actions['activate'] = sprintf( '<a href="%s" class="activatelink" title="%s">%s</a>', $activate_link, /* translators: %s: Theme name. */ esc_attr( sprintf( _x( 'Activate &#8220;%s&#8221;', 'theme' ), $title ) ), __( 'Activate' ) ); if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { $actions['preview'] .= sprintf( '<a href="%s" class="load-customize hide-if-no-customize">%s</a>', wp_customize_url( $stylesheet ), __( 'Live Preview' ) ); } if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) { $actions['delete'] = sprintf( '<a class="submitdelete deletion" href="%s" onclick="return confirm( \'%s\' );">%s</a>', wp_nonce_url( 'themes.php?action=delete&amp;stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ), /* translators: %s: Theme name. */ esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ), __( 'Delete' ) ); } /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ $actions = apply_filters( 'theme_action_links', $actions, $theme, 'all' ); /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */ $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, 'all' ); $delete_action = isset( $actions['delete'] ) ? '<div class="delete-theme">' . $actions['delete'] . '</div>' : ''; unset( $actions['delete'] ); $screenshot = $theme->get_screenshot(); ?> <span class="screenshot hide-if-customize"> <?php if ( $screenshot ) : ?> <img src="<?php echo esc_url( $screenshot . '?ver=' . $theme->version ); ?>" alt="" /> <?php endif; ?> </span> <a href="<?php echo wp_customize_url( $stylesheet ); ?>" class="screenshot load-customize hide-if-no-customize"> <?php if ( $screenshot ) : ?> <img src="<?php echo esc_url( $screenshot . '?ver=' . $theme->version ); ?>" alt="" /> <?php endif; ?> </a> <h3><?php echo $title; ?></h3> <div class="theme-author"> <?php /* translators: %s: Theme author. */ printf( __( 'By %s' ), $author ); ?> </div> <div class="action-links"> <ul> <?php foreach ( $actions as $action ) : ?> <li><?php echo $action; ?></li> <?php endforeach; ?> <li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e( 'Details' ); ?></a></li> </ul> <?php echo $delete_action; ?> <?php theme_update_available( $theme ); ?> </div> <div class="themedetaildiv hide-if-js"> <p><strong><?php _e( 'Version:' ); ?></strong> <?php echo $version; ?></p> <p><?php echo $theme->display( 'Description' ); ?></p> <?php if ( $theme->parent() ) { printf( /* translators: 1: Link to documentation on child themes, 2: Name of parent theme. */ ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>', __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ), $theme->parent()->display( 'Name' ) ); } ?> </div> </div> <?php endforeach; } ``` [apply\_filters( 'theme\_action\_links', string[] $actions, WP\_Theme $theme, string $context )](../../hooks/theme_action_links) Filters the action links displayed for each theme in the Multisite themes list table. [apply\_filters( "theme\_action\_links\_{$stylesheet}", string[] $actions, WP\_Theme $theme, string $context )](../../hooks/theme_action_links_stylesheet) Filters the action links of a specific theme in the Multisite themes list table. | Uses | Description | | --- | --- | | [theme\_update\_available()](../../functions/theme_update_available) wp-admin/includes/theme.php | Check if there is an update for a theme available. | | [wp\_customize\_url()](../../functions/wp_customize_url) wp-includes/theme.php | Returns a URL to load the Customizer. | | [esc\_js()](../../functions/esc_js) wp-includes/formatting.php | Escapes single quotes, `"`, , `&amp;`, and fixes line endings. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Themes\_List\_Table::display\_rows\_or\_placeholder()](display_rows_or_placeholder) wp-admin/includes/class-wp-themes-list-table.php | | wordpress WP_Themes_List_Table::no_items() WP\_Themes\_List\_Table::no\_items() ==================================== File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function no_items() { if ( $this->search_terms || $this->features ) { _e( 'No items found.' ); return; } $blog_id = get_current_blog_id(); if ( is_multisite() ) { if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) { printf( /* translators: 1: URL to Themes tab on Edit Site screen, 2: URL to Add Themes screen. */ __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $blog_id ), network_admin_url( 'theme-install.php' ) ); return; } elseif ( current_user_can( 'manage_network_themes' ) ) { printf( /* translators: %s: URL to Themes tab on Edit Site screen. */ __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $blog_id ) ); return; } // Else, fallthrough. install_themes doesn't help if you can't enable it. } else { if ( current_user_can( 'install_themes' ) ) { printf( /* translators: %s: URL to Add Themes screen. */ __( 'You only have one theme installed right now. Live a little! You can choose from over 1,000 free themes in the WordPress Theme Directory at any time: just click on the <a href="%s">Install Themes</a> tab above.' ), admin_url( 'theme-install.php' ) ); return; } } // Fallthrough. printf( /* translators: %s: Network title. */ __( 'Only the active theme is available to you. Contact the %s administrator for information about accessing additional themes.' ), get_site_option( 'site_name' ) ); } ``` | Uses | Description | | --- | --- | | [network\_admin\_url()](../../functions/network_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the network. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_current\_blog\_id()](../../functions/get_current_blog_id) wp-includes/load.php | Retrieve the current site ID. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | [get\_site\_option()](../../functions/get_site_option) wp-includes/option.php | Retrieve an option value for the current network based on name of option. | | Used By | Description | | --- | --- | | [WP\_Themes\_List\_Table::display\_rows\_or\_placeholder()](display_rows_or_placeholder) wp-admin/includes/class-wp-themes-list-table.php | | wordpress WP_Themes_List_Table::_js_vars( array $extra_args = array() ) WP\_Themes\_List\_Table::\_js\_vars( array $extra\_args = array() ) =================================================================== Send required variables to JavaScript land `$extra_args` array Optional Default: `array()` File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function _js_vars( $extra_args = array() ) { $search_string = isset( $_REQUEST['s'] ) ? esc_attr( wp_unslash( $_REQUEST['s'] ) ) : ''; $args = array( 'search' => $search_string, 'features' => $this->features, 'paged' => $this->get_pagenum(), 'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1, ); if ( is_array( $extra_args ) ) { $args = array_merge( $args, $extra_args ); } printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", wp_json_encode( $args ) ); parent::_js_vars(); } ``` | Uses | Description | | --- | --- | | [WP\_List\_Table::\_js\_vars()](../wp_list_table/_js_vars) wp-admin/includes/class-wp-list-table.php | Sends required variables to JavaScript land. | | [wp\_json\_encode()](../../functions/wp_json_encode) wp-includes/functions.php | Encodes a variable into JSON, with some sanity checks. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Used By | Description | | --- | --- | | [WP\_Theme\_Install\_List\_Table::\_js\_vars()](../wp_theme_install_list_table/_js_vars) wp-admin/includes/class-wp-theme-install-list-table.php | Send required variables to JavaScript land | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Themes_List_Table::tablenav( string $which = 'top' ) WP\_Themes\_List\_Table::tablenav( string $which = 'top' ) ========================================================== `$which` string Optional Default: `'top'` File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function tablenav( $which = 'top' ) { if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) { return; } ?> <div class="tablenav themes <?php echo $which; ?>"> <?php $this->pagination( $which ); ?> <span class="spinner"></span> <br class="clear" /> </div> <?php } ``` | Used By | Description | | --- | --- | | [WP\_Themes\_List\_Table::display()](display) wp-admin/includes/class-wp-themes-list-table.php | Displays the themes table. | wordpress WP_Themes_List_Table::display_rows_or_placeholder() WP\_Themes\_List\_Table::display\_rows\_or\_placeholder() ========================================================= File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function display_rows_or_placeholder() { if ( $this->has_items() ) { $this->display_rows(); } else { echo '<div class="no-items">'; $this->no_items(); echo '</div>'; } } ``` | Uses | Description | | --- | --- | | [WP\_Themes\_List\_Table::display\_rows()](display_rows) wp-admin/includes/class-wp-themes-list-table.php | | | [WP\_Themes\_List\_Table::no\_items()](no_items) wp-admin/includes/class-wp-themes-list-table.php | | | Used By | Description | | --- | --- | | [WP\_Themes\_List\_Table::display()](display) wp-admin/includes/class-wp-themes-list-table.php | Displays the themes table. | wordpress WP_Themes_List_Table::search_theme( WP_Theme $theme ): bool WP\_Themes\_List\_Table::search\_theme( WP\_Theme $theme ): bool ================================================================ `$theme` [WP\_Theme](../wp_theme) Required bool File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function search_theme( $theme ) { // Search the features. foreach ( $this->features as $word ) { if ( ! in_array( $word, $theme->get( 'Tags' ), true ) ) { return false; } } // Match all phrases. foreach ( $this->search_terms as $word ) { if ( in_array( $word, $theme->get( 'Tags' ), true ) ) { continue; } foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) { // Don't mark up; Do translate. if ( false !== stripos( strip_tags( $theme->display( $header, false, true ) ), $word ) ) { continue 2; } } if ( false !== stripos( $theme->get_stylesheet(), $word ) ) { continue; } if ( false !== stripos( $theme->get_template(), $word ) ) { continue; } return false; } return true; } ``` | Uses | Description | | --- | --- | | [stripos()](../../functions/stripos) wp-includes/class-pop3.php | | | Used By | Description | | --- | --- | | [WP\_Themes\_List\_Table::prepare\_items()](prepare_items) wp-admin/includes/class-wp-themes-list-table.php | | wordpress WP_Themes_List_Table::display() WP\_Themes\_List\_Table::display() ================================== Displays the themes table. Overrides the parent display() method to provide a different container. File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function display() { wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); ?> <?php $this->tablenav( 'top' ); ?> <div id="availablethemes"> <?php $this->display_rows_or_placeholder(); ?> </div> <?php $this->tablenav( 'bottom' ); ?> <?php } ``` | Uses | Description | | --- | --- | | [WP\_Themes\_List\_Table::tablenav()](tablenav) wp-admin/includes/class-wp-themes-list-table.php | | | [WP\_Themes\_List\_Table::display\_rows\_or\_placeholder()](display_rows_or_placeholder) wp-admin/includes/class-wp-themes-list-table.php | | | [wp\_nonce\_field()](../../functions/wp_nonce_field) wp-includes/functions.php | Retrieves or display nonce hidden field for forms. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Themes_List_Table::get_columns(): array WP\_Themes\_List\_Table::get\_columns(): array ============================================== array File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function get_columns() { return array(); } ``` wordpress WP_Themes_List_Table::__construct( array $args = array() ) WP\_Themes\_List\_Table::\_\_construct( array $args = array() ) =============================================================== Constructor. * [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct): for more information on default arguments. `$args` array Optional An associative array of arguments. Default: `array()` File: `wp-admin/includes/class-wp-themes-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-themes-list-table.php/) ``` public function __construct( $args = array() ) { parent::__construct( array( 'ajax' => true, 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } ``` | Uses | Description | | --- | --- | | [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct) wp-admin/includes/class-wp-list-table.php | Constructor. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |
programming_docs
wordpress WP_Filesystem_SSH2::chmod( string $file, int|false $mode = false, bool $recursive = false ): bool WP\_Filesystem\_SSH2::chmod( string $file, int|false $mode = false, bool $recursive = false ): bool =================================================================================================== Changes filesystem permissions. `$file` string Required Path to the file. `$mode` int|false Optional The permissions as octal number, usually 0644 for files, 0755 for directories. Default: `false` `$recursive` bool Optional If set to true, changes file permissions recursively. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function chmod( $file, $mode = false, $recursive = false ) { if ( ! $this->exists( $file ) ) { return false; } if ( ! $mode ) { if ( $this->is_file( $file ) ) { $mode = FS_CHMOD_FILE; } elseif ( $this->is_dir( $file ) ) { $mode = FS_CHMOD_DIR; } else { return false; } } if ( ! $recursive || ! $this->is_dir( $file ) ) { return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true ); } return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::exists()](exists) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if a file or directory exists. | | [WP\_Filesystem\_SSH2::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if resource is a file. | | [WP\_Filesystem\_SSH2::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if resource is a directory. | | [WP\_Filesystem\_SSH2::run\_command()](run_command) wp-admin/includes/class-wp-filesystem-ssh2.php | | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::put\_contents()](put_contents) wp-admin/includes/class-wp-filesystem-ssh2.php | Writes a string to a file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::size( string $file ): int|false WP\_Filesystem\_SSH2::size( string $file ): int|false ===================================================== Gets the file size (in bytes). `$file` string Required Path to file. int|false Size of the file in bytes on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function size( $file ) { return filesize( $this->sftp_path( $file ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::getchmod( string $file ): string WP\_Filesystem\_SSH2::getchmod( string $file ): string ====================================================== Gets the permissions of the specified file or filepath in their octal format. `$file` string Required Path to the file. string Mode of the file (the last 3 digits). File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function getchmod( $file ) { return substr( decoct( @fileperms( $this->sftp_path( $file ) ) ), -3 ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::exists( string $path ): bool WP\_Filesystem\_SSH2::exists( string $path ): bool ================================================== Checks if a file or directory exists. `$path` string Required Path to file or directory. bool Whether $path exists or not. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function exists( $path ) { return file_exists( $this->sftp_path( $path ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::chgrp()](chgrp) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes the file group. | | [WP\_Filesystem\_SSH2::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes filesystem permissions. | | [WP\_Filesystem\_SSH2::chown()](chown) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes the owner of a file or directory. | | [WP\_Filesystem\_SSH2::copy()](copy) wp-admin/includes/class-wp-filesystem-ssh2.php | Copies a file. | | [WP\_Filesystem\_SSH2::move()](move) wp-admin/includes/class-wp-filesystem-ssh2.php | Moves a file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::chdir( string $dir ): bool WP\_Filesystem\_SSH2::chdir( string $dir ): bool ================================================ Changes current directory. `$dir` string Required The new current directory. bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function chdir( $dir ) { return $this->run_command( 'cd ' . $dir, true ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::run\_command()](run_command) wp-admin/includes/class-wp-filesystem-ssh2.php | | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::rmdir( string $path, bool $recursive = false ): bool WP\_Filesystem\_SSH2::rmdir( string $path, bool $recursive = false ): bool ========================================================================== Deletes a directory. `$path` string Required Path to directory. `$recursive` bool Optional Whether to recursively remove files/directories. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function rmdir( $path, $recursive = false ) { return $this->delete( $path, $recursive ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::delete()](delete) wp-admin/includes/class-wp-filesystem-ssh2.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::get_contents( string $file ): string|false WP\_Filesystem\_SSH2::get\_contents( string $file ): string|false ================================================================= Reads entire file into a string. `$file` string Required Name of the file to read. string|false Read data on success, false if no temporary file could be opened, or if the file couldn't be retrieved. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function get_contents( $file ) { return file_get_contents( $this->sftp_path( $file ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::copy()](copy) wp-admin/includes/class-wp-filesystem-ssh2.php | Copies a file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::chown( string $file, string|int $owner, bool $recursive = false ): bool WP\_Filesystem\_SSH2::chown( string $file, string|int $owner, bool $recursive = false ): bool ============================================================================================= Changes the owner of a file or directory. `$file` string Required Path to the file or directory. `$owner` string|int Required A user name or number. `$recursive` bool Optional If set to true, changes file owner recursively. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function chown( $file, $owner, $recursive = false ) { if ( ! $this->exists( $file ) ) { return false; } if ( ! $recursive || ! $this->is_dir( $file ) ) { return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); } return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::exists()](exists) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if a file or directory exists. | | [WP\_Filesystem\_SSH2::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if resource is a directory. | | [WP\_Filesystem\_SSH2::run\_command()](run_command) wp-admin/includes/class-wp-filesystem-ssh2.php | | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::mkdir()](mkdir) wp-admin/includes/class-wp-filesystem-ssh2.php | Creates a directory. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::is_writable( string $path ): bool WP\_Filesystem\_SSH2::is\_writable( string $path ): bool ======================================================== Checks if a file or directory is writable. `$path` string Required Path to file or directory. bool Whether $path is writable. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function is_writable( $path ) { // PHP will base its writable checks on system_user === file_owner, not ssh_user === file_owner. return true; } ``` | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::group( string $file ): string|false WP\_Filesystem\_SSH2::group( string $file ): string|false ========================================================= Gets the file’s group. `$file` string Required Path to the file. string|false The group on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function group( $file ) { $gid = @filegroup( $this->sftp_path( $file ) ); if ( ! $gid ) { return false; } if ( ! function_exists( 'posix_getgrgid' ) ) { return $gid; } $grouparray = posix_getgrgid( $gid ); if ( ! $grouparray ) { return false; } return $grouparray['name']; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::chgrp( string $file, string|int $group, bool $recursive = false ): bool WP\_Filesystem\_SSH2::chgrp( string $file, string|int $group, bool $recursive = false ): bool ============================================================================================= Changes the file group. `$file` string Required Path to the file. `$group` string|int Required A group name or number. `$recursive` bool Optional If set to true, changes file group recursively. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function chgrp( $file, $group, $recursive = false ) { if ( ! $this->exists( $file ) ) { return false; } if ( ! $recursive || ! $this->is_dir( $file ) ) { return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); } return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::exists()](exists) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if a file or directory exists. | | [WP\_Filesystem\_SSH2::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if resource is a directory. | | [WP\_Filesystem\_SSH2::run\_command()](run_command) wp-admin/includes/class-wp-filesystem-ssh2.php | | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::mkdir()](mkdir) wp-admin/includes/class-wp-filesystem-ssh2.php | Creates a directory. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::put_contents( string $file, string $contents, int|false $mode = false ): bool WP\_Filesystem\_SSH2::put\_contents( string $file, string $contents, int|false $mode = false ): bool ==================================================================================================== Writes a string to a file. `$file` string Required Remote path to the file where to write the data. `$contents` string Required The data to write. `$mode` int|false Optional The file permissions as octal number, usually 0644. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function put_contents( $file, $contents, $mode = false ) { $ret = file_put_contents( $this->sftp_path( $file ), $contents ); if ( strlen( $contents ) !== $ret ) { return false; } $this->chmod( $file, $mode ); return true; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | [WP\_Filesystem\_SSH2::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes filesystem permissions. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::copy()](copy) wp-admin/includes/class-wp-filesystem-ssh2.php | Copies a file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::run_command( string $command, bool $returnbool = false ): bool|string WP\_Filesystem\_SSH2::run\_command( string $command, bool $returnbool = false ): bool|string ============================================================================================ `$command` string Required `$returnbool` bool Optional Default: `false` bool|string True on success, false on failure. String if the command was executed, `$returnbool` is false (default), and data from the resulting stream was retrieved. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function run_command( $command, $returnbool = false ) { if ( ! $this->link ) { return false; } $stream = ssh2_exec( $this->link, $command ); if ( ! $stream ) { $this->errors->add( 'command', sprintf( /* translators: %s: Command. */ __( 'Unable to perform command: %s' ), $command ) ); } else { stream_set_blocking( $stream, true ); stream_set_timeout( $stream, FS_TIMEOUT ); $data = stream_get_contents( $stream ); fclose( $stream ); if ( $returnbool ) { return ( false === $data ) ? false : '' !== trim( $data ); } else { return $data; } } return false; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::chdir()](chdir) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes current directory. | | [WP\_Filesystem\_SSH2::chgrp()](chgrp) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes the file group. | | [WP\_Filesystem\_SSH2::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes filesystem permissions. | | [WP\_Filesystem\_SSH2::chown()](chown) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes the owner of a file or directory. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::is_dir( string $path ): bool WP\_Filesystem\_SSH2::is\_dir( string $path ): bool =================================================== Checks if resource is a directory. `$path` string Required Directory path. bool Whether $path is a directory. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function is_dir( $path ) { return is_dir( $this->sftp_path( $path ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_SSH2::chgrp()](chgrp) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes the file group. | | [WP\_Filesystem\_SSH2::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes filesystem permissions. | | [WP\_Filesystem\_SSH2::chown()](chown) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes the owner of a file or directory. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |
programming_docs
wordpress WP_Filesystem_SSH2::is_readable( string $file ): bool WP\_Filesystem\_SSH2::is\_readable( string $file ): bool ======================================================== Checks if a file is readable. `$file` string Required Path to file. bool Whether $file is readable. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function is_readable( $file ) { return is_readable( $this->sftp_path( $file ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::is_file( string $file ): bool WP\_Filesystem\_SSH2::is\_file( string $file ): bool ==================================================== Checks if resource is a file. `$file` string Required File path. bool Whether $file is a file. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function is_file( $file ) { return is_file( $this->sftp_path( $file ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_SSH2::chmod()](chmod) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes filesystem permissions. | | [WP\_Filesystem\_SSH2::delete()](delete) wp-admin/includes/class-wp-filesystem-ssh2.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::mtime( string $file ): int|false WP\_Filesystem\_SSH2::mtime( string $file ): int|false ====================================================== Gets the file modification time. `$file` string Required Path to file. int|false Unix timestamp representing modification time, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function mtime( $file ) { return filemtime( $this->sftp_path( $file ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::mkdir( string $path, int|false $chmod = false, string|int|false $chown = false, string|int|false $chgrp = false ): bool WP\_Filesystem\_SSH2::mkdir( string $path, int|false $chmod = false, string|int|false $chown = false, string|int|false $chgrp = false ): bool ============================================================================================================================================= Creates a directory. `$path` string Required Path for new directory. `$chmod` int|false Optional The permissions as octal number (or false to skip chmod). Default: `false` `$chown` string|int|false Optional A user name or number (or false to skip chown). Default: `false` `$chgrp` string|int|false Optional A group name or number (or false to skip chgrp). Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { $path = untrailingslashit( $path ); if ( empty( $path ) ) { return false; } if ( ! $chmod ) { $chmod = FS_CHMOD_DIR; } if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) { return false; } // Set directory permissions. ssh2_sftp_chmod( $this->sftp_link, $path, $chmod ); if ( $chown ) { $this->chown( $path, $chown ); } if ( $chgrp ) { $this->chgrp( $path, $chgrp ); } return true; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::chown()](chown) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes the owner of a file or directory. | | [WP\_Filesystem\_SSH2::chgrp()](chgrp) wp-admin/includes/class-wp-filesystem-ssh2.php | Changes the file group. | | [untrailingslashit()](../../functions/untrailingslashit) wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::owner( string $file ): string|false WP\_Filesystem\_SSH2::owner( string $file ): string|false ========================================================= Gets the file owner. `$file` string Required Path to the file. string|false Username of the owner on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function owner( $file ) { $owneruid = @fileowner( $this->sftp_path( $file ) ); if ( ! $owneruid ) { return false; } if ( ! function_exists( 'posix_getpwuid' ) ) { return $owneruid; } $ownerarray = posix_getpwuid( $owneruid ); if ( ! $ownerarray ) { return false; } return $ownerarray['name']; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::cwd(): string|false WP\_Filesystem\_SSH2::cwd(): string|false ========================================= Gets the current working directory. string|false The current working directory on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function cwd() { $cwd = ssh2_sftp_realpath( $this->sftp_link, '.' ); if ( $cwd ) { $cwd = trailingslashit( trim( $cwd ) ); } return $cwd; } ``` | Uses | Description | | --- | --- | | [trailingslashit()](../../functions/trailingslashit) wp-includes/formatting.php | Appends a trailing slash. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::__construct( array $opt = '' ) WP\_Filesystem\_SSH2::\_\_construct( array $opt = '' ) ====================================================== Constructor. `$opt` array Optional Default: `''` File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function __construct( $opt = '' ) { $this->method = 'ssh2'; $this->errors = new WP_Error(); // Check if possible to use ssh2 functions. if ( ! extension_loaded( 'ssh2' ) ) { $this->errors->add( 'no_ssh2_ext', __( 'The ssh2 PHP extension is not available' ) ); return; } // Set defaults: if ( empty( $opt['port'] ) ) { $this->options['port'] = 22; } else { $this->options['port'] = $opt['port']; } if ( empty( $opt['hostname'] ) ) { $this->errors->add( 'empty_hostname', __( 'SSH2 hostname is required' ) ); } else { $this->options['hostname'] = $opt['hostname']; } // Check if the options provided are OK. if ( ! empty( $opt['public_key'] ) && ! empty( $opt['private_key'] ) ) { $this->options['public_key'] = $opt['public_key']; $this->options['private_key'] = $opt['private_key']; $this->options['hostkey'] = array( 'hostkey' => 'ssh-rsa,ssh-ed25519' ); $this->keys = true; } elseif ( empty( $opt['username'] ) ) { $this->errors->add( 'empty_username', __( 'SSH2 username is required' ) ); } if ( ! empty( $opt['username'] ) ) { $this->options['username'] = $opt['username']; } if ( empty( $opt['password'] ) ) { // Password can be blank if we are using keys. if ( ! $this->keys ) { $this->errors->add( 'empty_password', __( 'SSH2 password is required' ) ); } } else { $this->options['password'] = $opt['password']; } } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::copy( string $source, string $destination, bool $overwrite = false, int|false $mode = false ): bool WP\_Filesystem\_SSH2::copy( string $source, string $destination, bool $overwrite = false, int|false $mode = false ): bool ========================================================================================================================= Copies a file. `$source` string Required Path to the source file. `$destination` string Required Path to the destination file. `$overwrite` bool Optional Whether to overwrite the destination file if it exists. Default: `false` `$mode` int|false Optional The permissions as octal number, usually 0644 for files, 0755 for dirs. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function copy( $source, $destination, $overwrite = false, $mode = false ) { if ( ! $overwrite && $this->exists( $destination ) ) { return false; } $content = $this->get_contents( $source ); if ( false === $content ) { return false; } return $this->put_contents( $destination, $content, $mode ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::exists()](exists) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if a file or directory exists. | | [WP\_Filesystem\_SSH2::get\_contents()](get_contents) wp-admin/includes/class-wp-filesystem-ssh2.php | Reads entire file into a string. | | [WP\_Filesystem\_SSH2::put\_contents()](put_contents) wp-admin/includes/class-wp-filesystem-ssh2.php | Writes a string to a file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::sftp_path( string $path ): string WP\_Filesystem\_SSH2::sftp\_path( string $path ): string ======================================================== Gets the ssh2.sftp PHP stream wrapper path to open for the given file. This method also works around a PHP bug where the root directory (/) cannot be opened by PHP functions, causing a false failure. In order to work around this, the path is converted to /./ which is semantically the same as / See <https://bugs.php.net/bug.php?id=64169> for more details. `$path` string Required The File/Directory path on the remote server to return string The ssh2.sftp:// wrapped path to use. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function sftp_path( $path ) { if ( '/' === $path ) { $path = '/./'; } return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' ); } ``` | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::exists()](exists) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if a file or directory exists. | | [WP\_Filesystem\_SSH2::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if resource is a file. | | [WP\_Filesystem\_SSH2::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if resource is a directory. | | [WP\_Filesystem\_SSH2::is\_readable()](is_readable) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if a file is readable. | | [WP\_Filesystem\_SSH2::atime()](atime) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the file’s last access time. | | [WP\_Filesystem\_SSH2::mtime()](mtime) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the file modification time. | | [WP\_Filesystem\_SSH2::size()](size) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the file size (in bytes). | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_SSH2::get\_contents()](get_contents) wp-admin/includes/class-wp-filesystem-ssh2.php | Reads entire file into a string. | | [WP\_Filesystem\_SSH2::get\_contents\_array()](get_contents_array) wp-admin/includes/class-wp-filesystem-ssh2.php | Reads entire file into an array. | | [WP\_Filesystem\_SSH2::put\_contents()](put_contents) wp-admin/includes/class-wp-filesystem-ssh2.php | Writes a string to a file. | | [WP\_Filesystem\_SSH2::owner()](owner) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the file owner. | | [WP\_Filesystem\_SSH2::getchmod()](getchmod) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the permissions of the specified file or filepath in their octal format. | | [WP\_Filesystem\_SSH2::group()](group) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the file’s group. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Filesystem_SSH2::get_contents_array( string $file ): array|false WP\_Filesystem\_SSH2::get\_contents\_array( string $file ): array|false ======================================================================= Reads entire file into an array. `$file` string Required Path to the file. array|false File contents in an array on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function get_contents_array( $file ) { return file( $this->sftp_path( $file ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::dirlist( string $path, bool $include_hidden = true, bool $recursive = false ): array|false WP\_Filesystem\_SSH2::dirlist( string $path, bool $include\_hidden = true, bool $recursive = false ): array|false ================================================================================================================= Gets details for files in a directory or a specific file. `$path` string Required Path to directory or file. `$include_hidden` bool Optional Whether to include details of hidden ("." prefixed) files. Default: `true` `$recursive` bool Optional Whether to recursively include file details in nested directories. Default: `false` array|false Array of files. False if unable to list directory contents. * `name`stringName of the file or directory. * `perms`string\*nix representation of permissions. * `permsn`stringOctal representation of permissions. * `owner`stringOwner name or ID. * `size`intSize of file in bytes. * `lastmodunix`intLast modified unix timestamp. * `lastmod`mixedLast modified month (3 letter) and day (without leading 0). * `time`intLast modified time. * `type`stringType of resource. `'f'` for file, `'d'` for directory. * `files`mixedIf a directory and `$recursive` is true, contains another array of files. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function dirlist( $path, $include_hidden = true, $recursive = false ) { if ( $this->is_file( $path ) ) { $limit_file = basename( $path ); $path = dirname( $path ); } else { $limit_file = false; } if ( ! $this->is_dir( $path ) || ! $this->is_readable( $path ) ) { return false; } $ret = array(); $dir = dir( $this->sftp_path( $path ) ); if ( ! $dir ) { return false; } while ( false !== ( $entry = $dir->read() ) ) { $struc = array(); $struc['name'] = $entry; if ( '.' === $struc['name'] || '..' === $struc['name'] ) { continue; // Do not care about these folders. } if ( ! $include_hidden && '.' === $struc['name'][0] ) { continue; } if ( $limit_file && $struc['name'] !== $limit_file ) { continue; } $struc['perms'] = $this->gethchmod( $path . '/' . $entry ); $struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] ); $struc['number'] = false; $struc['owner'] = $this->owner( $path . '/' . $entry ); $struc['group'] = $this->group( $path . '/' . $entry ); $struc['size'] = $this->size( $path . '/' . $entry ); $struc['lastmodunix'] = $this->mtime( $path . '/' . $entry ); $struc['lastmod'] = gmdate( 'M j', $struc['lastmodunix'] ); $struc['time'] = gmdate( 'h:i:s', $struc['lastmodunix'] ); $struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f'; if ( 'd' === $struc['type'] ) { if ( $recursive ) { $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); } else { $struc['files'] = array(); } } $ret[ $struc['name'] ] = $struc; } $dir->close(); unset( $dir ); return $ret; } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | [WP\_Filesystem\_SSH2::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if resource is a file. | | [WP\_Filesystem\_SSH2::is\_dir()](is_dir) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if resource is a directory. | | [WP\_Filesystem\_SSH2::is\_readable()](is_readable) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if a file is readable. | | [WP\_Filesystem\_SSH2::size()](size) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the file size (in bytes). | | [WP\_Filesystem\_SSH2::mtime()](mtime) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the file modification time. | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_SSH2::owner()](owner) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the file owner. | | [WP\_Filesystem\_SSH2::group()](group) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the file’s group. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_SSH2::delete()](delete) wp-admin/includes/class-wp-filesystem-ssh2.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |
programming_docs
wordpress WP_Filesystem_SSH2::move( string $source, string $destination, bool $overwrite = false ): bool WP\_Filesystem\_SSH2::move( string $source, string $destination, bool $overwrite = false ): bool ================================================================================================ Moves a file. `$source` string Required Path to the source file. `$destination` string Required Path to the destination file. `$overwrite` bool Optional Whether to overwrite the destination file if it exists. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function move( $source, $destination, $overwrite = false ) { if ( $this->exists( $destination ) ) { if ( $overwrite ) { // We need to remove the destination file before we can rename the source. $this->delete( $destination, false, 'f' ); } else { // If we're not overwriting, the rename will fail, so return early. return false; } } return ssh2_sftp_rename( $this->sftp_link, $source, $destination ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::exists()](exists) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if a file or directory exists. | | [WP\_Filesystem\_SSH2::delete()](delete) wp-admin/includes/class-wp-filesystem-ssh2.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::atime( string $file ): int|false WP\_Filesystem\_SSH2::atime( string $file ): int|false ====================================================== Gets the file’s last access time. `$file` string Required Path to file. int|false Unix timestamp representing last access time, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function atime( $file ) { return fileatime( $this->sftp_path( $file ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::sftp\_path()](sftp_path) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets the ssh2.sftp PHP stream wrapper path to open for the given file. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::touch( string $file, int $time, int $atime ) WP\_Filesystem\_SSH2::touch( string $file, int $time, int $atime ) ================================================================== Sets the access and modification times of a file. Note: Not implemented. `$file` string Required Path to file. `$time` int Optional Modified time to set for file. Default 0. `$atime` int Optional Access time to set for file. Default 0. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function touch( $file, $time = 0, $atime = 0 ) { // Not implemented. } ``` | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::delete( string $file, bool $recursive = false, string|false $type = false ): bool WP\_Filesystem\_SSH2::delete( string $file, bool $recursive = false, string|false $type = false ): bool ======================================================================================================= Deletes a file or directory. `$file` string Required Path to the file or directory. `$recursive` bool Optional If set to true, deletes files and folders recursively. Default: `false` `$type` string|false Optional Type of resource. `'f'` for file, `'d'` for directory. Default: `false` bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function delete( $file, $recursive = false, $type = false ) { if ( 'f' === $type || $this->is_file( $file ) ) { return ssh2_sftp_unlink( $this->sftp_link, $file ); } if ( ! $recursive ) { return ssh2_sftp_rmdir( $this->sftp_link, $file ); } $filelist = $this->dirlist( $file ); if ( is_array( $filelist ) ) { foreach ( $filelist as $filename => $fileinfo ) { $this->delete( $file . '/' . $filename, $recursive, $fileinfo['type'] ); } } return ssh2_sftp_rmdir( $this->sftp_link, $file ); } ``` | Uses | Description | | --- | --- | | [WP\_Filesystem\_SSH2::is\_file()](is_file) wp-admin/includes/class-wp-filesystem-ssh2.php | Checks if resource is a file. | | [WP\_Filesystem\_SSH2::dirlist()](dirlist) wp-admin/includes/class-wp-filesystem-ssh2.php | Gets details for files in a directory or a specific file. | | [WP\_Filesystem\_SSH2::delete()](delete) wp-admin/includes/class-wp-filesystem-ssh2.php | Deletes a file or directory. | | Used By | Description | | --- | --- | | [WP\_Filesystem\_SSH2::rmdir()](rmdir) wp-admin/includes/class-wp-filesystem-ssh2.php | Deletes a directory. | | [WP\_Filesystem\_SSH2::move()](move) wp-admin/includes/class-wp-filesystem-ssh2.php | Moves a file. | | [WP\_Filesystem\_SSH2::delete()](delete) wp-admin/includes/class-wp-filesystem-ssh2.php | Deletes a file or directory. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Filesystem_SSH2::connect(): bool WP\_Filesystem\_SSH2::connect(): bool ===================================== Connects filesystem. bool True on success, false on failure. File: `wp-admin/includes/class-wp-filesystem-ssh2.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-filesystem-ssh2.php/) ``` public function connect() { if ( ! $this->keys ) { $this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'] ); } else { $this->link = @ssh2_connect( $this->options['hostname'], $this->options['port'], $this->options['hostkey'] ); } if ( ! $this->link ) { $this->errors->add( 'connect', sprintf( /* translators: %s: hostname:port */ __( 'Failed to connect to SSH2 Server %s' ), $this->options['hostname'] . ':' . $this->options['port'] ) ); return false; } if ( ! $this->keys ) { if ( ! @ssh2_auth_password( $this->link, $this->options['username'], $this->options['password'] ) ) { $this->errors->add( 'auth', sprintf( /* translators: %s: Username. */ __( 'Username/Password incorrect for %s' ), $this->options['username'] ) ); return false; } } else { if ( ! @ssh2_auth_pubkey_file( $this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] ) ) { $this->errors->add( 'auth', sprintf( /* translators: %s: Username. */ __( 'Public and Private keys incorrect for %s' ), $this->options['username'] ) ); return false; } } $this->sftp_link = ssh2_sftp( $this->link ); if ( ! $this->sftp_link ) { $this->errors->add( 'connect', sprintf( /* translators: %s: hostname:port */ __( 'Failed to initialize a SFTP subsystem session with the SSH2 Server %s' ), $this->options['hostname'] . ':' . $this->options['port'] ) ); return false; } return true; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress WP_Post::to_array(): array WP\_Post::to\_array(): array ============================ Convert object to array. array Object as array. File: `wp-includes/class-wp-post.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post.php/) ``` public function to_array() { $post = get_object_vars( $this ); foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) { if ( $this->__isset( $key ) ) { $post[ $key ] = $this->__get( $key ); } } return $post; } ``` | Uses | Description | | --- | --- | | [WP\_Post::\_\_isset()](__isset) wp-includes/class-wp-post.php | Isset-er. | | [WP\_Post::\_\_get()](__get) wp-includes/class-wp-post.php | Getter. | | Version | Description | | --- | --- | | [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. | wordpress WP_Post::__get( string $key ): mixed WP\_Post::\_\_get( string $key ): mixed ======================================= Getter. `$key` string Required Key to get. mixed File: `wp-includes/class-wp-post.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post.php/) ``` public function __get( $key ) { if ( 'page_template' === $key && $this->__isset( $key ) ) { return get_post_meta( $this->ID, '_wp_page_template', true ); } if ( 'post_category' === $key ) { if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) { $terms = get_the_terms( $this, 'category' ); } if ( empty( $terms ) ) { return array(); } return wp_list_pluck( $terms, 'term_id' ); } if ( 'tags_input' === $key ) { if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) { $terms = get_the_terms( $this, 'post_tag' ); } if ( empty( $terms ) ) { return array(); } return wp_list_pluck( $terms, 'name' ); } // Rest of the values need filtering. if ( 'ancestors' === $key ) { $value = get_post_ancestors( $this ); } else { $value = get_post_meta( $this->ID, $key, true ); } if ( $this->filter ) { $value = sanitize_post_field( $key, $value, $this->ID, $this->filter ); } return $value; } ``` | Uses | Description | | --- | --- | | [get\_the\_terms()](../../functions/get_the_terms) wp-includes/category-template.php | Retrieves the terms of the taxonomy that are attached to the post. | | [wp\_list\_pluck()](../../functions/wp_list_pluck) wp-includes/functions.php | Plucks a certain field out of each object or array in an array. | | [is\_object\_in\_taxonomy()](../../functions/is_object_in_taxonomy) wp-includes/taxonomy.php | Determines if the given object type is associated with the given taxonomy. | | [WP\_Post::\_\_isset()](__isset) wp-includes/class-wp-post.php | Isset-er. | | [sanitize\_post\_field()](../../functions/sanitize_post_field) wp-includes/post.php | Sanitizes a post field based on context. | | [get\_post\_ancestors()](../../functions/get_post_ancestors) wp-includes/post.php | Retrieves the IDs of the ancestors of a post. | | [get\_post\_meta()](../../functions/get_post_meta) wp-includes/post.php | Retrieves a post meta field for the given post ID. | | Used By | Description | | --- | --- | | [WP\_Post::to\_array()](to_array) wp-includes/class-wp-post.php | Convert object to array. | | Version | Description | | --- | --- | | [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. | wordpress WP_Post::__isset( string $key ): bool WP\_Post::\_\_isset( string $key ): bool ======================================== Isset-er. `$key` string Required Property to check if set. bool File: `wp-includes/class-wp-post.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post.php/) ``` public function __isset( $key ) { if ( 'ancestors' === $key ) { return true; } if ( 'page_template' === $key ) { return true; } if ( 'post_category' === $key ) { return true; } if ( 'tags_input' === $key ) { return true; } return metadata_exists( 'post', $this->ID, $key ); } ``` | Uses | Description | | --- | --- | | [metadata\_exists()](../../functions/metadata_exists) wp-includes/meta.php | Determines if a meta field with the given key exists for the given object ID. | | Used By | Description | | --- | --- | | [WP\_Post::\_\_get()](__get) wp-includes/class-wp-post.php | Getter. | | [WP\_Post::to\_array()](to_array) wp-includes/class-wp-post.php | Convert object to array. | | Version | Description | | --- | --- | | [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. | wordpress WP_Post::__construct( WP_Post|object $post ) WP\_Post::\_\_construct( WP\_Post|object $post ) ================================================ Constructor. `$post` [WP\_Post](../wp_post)|object Required Post object. File: `wp-includes/class-wp-post.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post.php/) ``` public function __construct( $post ) { foreach ( get_object_vars( $post ) as $key => $value ) { $this->$key = $value; } } ``` | Used By | Description | | --- | --- | | [WP\_Customize\_Nav\_Menu\_Item\_Setting::value\_as\_wp\_post\_nav\_menu\_item()](../wp_customize_nav_menu_item_setting/value_as_wp_post_nav_menu_item) wp-includes/customize/class-wp-customize-nav-menu-item-setting.php | Get the value emulated into a [WP\_Post](../wp_post) and set up as a nav\_menu\_item. | | [get\_attachment\_fields\_to\_edit()](../../functions/get_attachment_fields_to_edit) wp-admin/includes/media.php | Retrieves the attachment fields to edit form fields. | | [get\_default\_post\_to\_edit()](../../functions/get_default_post_to_edit) wp-admin/includes/post.php | Returns default post information to use when populating the “Write Post” form. | | [WP\_Post::get\_instance()](get_instance) wp-includes/class-wp-post.php | Retrieve [WP\_Post](../wp_post) instance. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Version | Description | | --- | --- | | [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. | wordpress WP_Post::get_instance( int $post_id ): WP_Post|false WP\_Post::get\_instance( int $post\_id ): WP\_Post|false ======================================================== Retrieve [WP\_Post](../wp_post) instance. `$post_id` int Required Post ID. [WP\_Post](../wp_post)|false Post object, false otherwise. File: `wp-includes/class-wp-post.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post.php/) ``` public static function get_instance( $post_id ) { global $wpdb; $post_id = (int) $post_id; if ( ! $post_id ) { return false; } $_post = wp_cache_get( $post_id, 'posts' ); if ( ! $_post ) { $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) ); if ( ! $_post ) { return false; } $_post = sanitize_post( $_post, 'raw' ); wp_cache_add( $_post->ID, $_post, 'posts' ); } elseif ( empty( $_post->filter ) || 'raw' !== $_post->filter ) { $_post = sanitize_post( $_post, 'raw' ); } return new WP_Post( $_post ); } ``` | Uses | Description | | --- | --- | | [wp\_cache\_add()](../../functions/wp_cache_add) wp-includes/cache.php | Adds data to the cache, if the cache key doesn’t already exist. | | [WP\_Post::\_\_construct()](__construct) wp-includes/class-wp-post.php | Constructor. | | [sanitize\_post()](../../functions/sanitize_post) wp-includes/post.php | Sanitizes every post field. | | [wpdb::get\_row()](../wpdb/get_row) wp-includes/class-wpdb.php | Retrieves one row from the database. | | [wp\_cache\_get()](../../functions/wp_cache_get) wp-includes/cache.php | Retrieves the cache contents from the cache by key and group. | | [wpdb::prepare()](../wpdb/prepare) wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. | | Used By | Description | | --- | --- | | [WP\_Post::filter()](filter) wp-includes/class-wp-post.php | {@Missing Summary} | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Version | Description | | --- | --- | | [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. | wordpress WP_Post::filter( string $filter ): WP_Post WP\_Post::filter( string $filter ): WP\_Post ============================================ {@Missing Summary} `$filter` string Required Filter. [WP\_Post](../wp_post) File: `wp-includes/class-wp-post.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post.php/) ``` public function filter( $filter ) { if ( $this->filter === $filter ) { return $this; } if ( 'raw' === $filter ) { return self::get_instance( $this->ID ); } return sanitize_post( $this, $filter ); } ``` | Uses | Description | | --- | --- | | [WP\_Post::get\_instance()](get_instance) wp-includes/class-wp-post.php | Retrieve [WP\_Post](../wp_post) instance. | | [sanitize\_post()](../../functions/sanitize_post) wp-includes/post.php | Sanitizes every post field. | | Version | Description | | --- | --- | | [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. | wordpress Walker_Nav_Menu_Checklist::start_lvl( string $output, int $depth, stdClass $args = null ) Walker\_Nav\_Menu\_Checklist::start\_lvl( string $output, int $depth, stdClass $args = null ) ============================================================================================= Starts the list before the elements are added. * [Walker\_Nav\_Menu::start\_lvl()](../walker_nav_menu/start_lvl) `$output` string Required Used to append additional content (passed by reference). `$depth` int Required Depth of page. Used for padding. `$args` stdClass Optional Not used. Default: `null` File: `wp-admin/includes/class-walker-nav-menu-checklist.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-walker-nav-menu-checklist.php/) ``` public function start_lvl( &$output, $depth = 0, $args = null ) { $indent = str_repeat( "\t", $depth ); $output .= "\n$indent<ul class='children'>\n"; } ``` | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress Walker_Nav_Menu_Checklist::start_el( string $output, WP_Post $data_object, int $depth, stdClass $args = null, int $current_object_id ) Walker\_Nav\_Menu\_Checklist::start\_el( string $output, WP\_Post $data\_object, int $depth, stdClass $args = null, int $current\_object\_id ) ============================================================================================================================================== Start the element output. * [Walker\_Nav\_Menu::start\_el()](../walker_nav_menu/start_el) `$output` string Required Used to append additional content (passed by reference). `$data_object` [WP\_Post](../wp_post) Required Menu item data object. `$depth` int Required Depth of menu item. Used for padding. `$args` stdClass Optional Not used. Default: `null` `$current_object_id` int Optional ID of the current menu item. Default 0. File: `wp-admin/includes/class-walker-nav-menu-checklist.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-walker-nav-menu-checklist.php/) ``` public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) { global $_nav_menu_placeholder, $nav_menu_selected_id; // Restores the more descriptive, specific name for use within this method. $menu_item = $data_object; $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? (int) $_nav_menu_placeholder - 1 : -1; $possible_object_id = isset( $menu_item->post_type ) && 'nav_menu_item' === $menu_item->post_type ? $menu_item->object_id : $_nav_menu_placeholder; $possible_db_id = ( ! empty( $menu_item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $menu_item->ID : 0; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $output .= $indent . '<li>'; $output .= '<label class="menu-item-title">'; $output .= '<input type="checkbox"' . wp_nav_menu_disabled_check( $nav_menu_selected_id, false ) . ' class="menu-item-checkbox'; if ( ! empty( $menu_item->front_or_home ) ) { $output .= ' add-to-top'; } $output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="' . esc_attr( $menu_item->object_id ) . '" /> '; if ( ! empty( $menu_item->label ) ) { $title = $menu_item->label; } elseif ( isset( $menu_item->post_type ) ) { /** This filter is documented in wp-includes/post-template.php */ $title = apply_filters( 'the_title', $menu_item->post_title, $menu_item->ID ); } $output .= isset( $title ) ? esc_html( $title ) : esc_html( $menu_item->title ); if ( empty( $menu_item->label ) && isset( $menu_item->post_type ) && 'page' === $menu_item->post_type ) { // Append post states. $output .= _post_states( $menu_item, false ); } $output .= '</label>'; // Menu item hidden fields. $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />'; $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="' . esc_attr( $menu_item->object ) . '" />'; $output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="' . esc_attr( $menu_item->menu_item_parent ) . '" />'; $output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="' . esc_attr( $menu_item->type ) . '" />'; $output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="' . esc_attr( $menu_item->title ) . '" />'; $output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="' . esc_attr( $menu_item->url ) . '" />'; $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="' . esc_attr( $menu_item->target ) . '" />'; $output .= '<input type="hidden" class="menu-item-attr-title" name="menu-item[' . $possible_object_id . '][menu-item-attr-title]" value="' . esc_attr( $menu_item->attr_title ) . '" />'; $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="' . esc_attr( implode( ' ', $menu_item->classes ) ) . '" />'; $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="' . esc_attr( $menu_item->xfn ) . '" />'; } ``` [apply\_filters( 'the\_title', string $post\_title, int $post\_id )](../../hooks/the_title) Filters the post title. | Uses | Description | | --- | --- | | [\_post\_states()](../../functions/_post_states) wp-admin/includes/template.php | Echoes or returns the post states as HTML. | | [wp\_nav\_menu\_disabled\_check()](../../functions/wp_nav_menu_disabled_check) wp-admin/includes/nav-menu.php | Check whether to disable the Menu Locations meta box submit button and inputs. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$item` to `$data_object` and `$id` to `$current_object_id` to match parent class for PHP 8 named parameter support. | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |
programming_docs
wordpress Walker_Nav_Menu_Checklist::end_lvl( string $output, int $depth, stdClass $args = null ) Walker\_Nav\_Menu\_Checklist::end\_lvl( string $output, int $depth, stdClass $args = null ) =========================================================================================== Ends the list of after the elements are added. * [Walker\_Nav\_Menu::end\_lvl()](../walker_nav_menu/end_lvl) `$output` string Required Used to append additional content (passed by reference). `$depth` int Required Depth of page. Used for padding. `$args` stdClass Optional Not used. Default: `null` File: `wp-admin/includes/class-walker-nav-menu-checklist.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-walker-nav-menu-checklist.php/) ``` public function end_lvl( &$output, $depth = 0, $args = null ) { $indent = str_repeat( "\t", $depth ); $output .= "\n$indent</ul>"; } ``` | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress Walker_Nav_Menu_Checklist::__construct( array|false $fields = false ) Walker\_Nav\_Menu\_Checklist::\_\_construct( array|false $fields = false ) ========================================================================== `$fields` array|false Optional Database fields to use. Default: `false` File: `wp-admin/includes/class-walker-nav-menu-checklist.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-walker-nav-menu-checklist.php/) ``` public function __construct( $fields = false ) { if ( $fields ) { $this->db_fields = $fields; } } ``` | Used By | Description | | --- | --- | | [\_wp\_ajax\_menu\_quick\_search()](../../functions/_wp_ajax_menu_quick_search) wp-admin/includes/nav-menu.php | Prints the appropriate response to a menu quick search. | | [wp\_nav\_menu\_item\_post\_type\_meta\_box()](../../functions/wp_nav_menu_item_post_type_meta_box) wp-admin/includes/nav-menu.php | Displays a meta box for a post type menu item. | | [wp\_nav\_menu\_item\_taxonomy\_meta\_box()](../../functions/wp_nav_menu_item_taxonomy_meta_box) wp-admin/includes/nav-menu.php | Displays a meta box for a taxonomy menu item. | wordpress WP_REST_Block_Types_Controller::get_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Block\_Types\_Controller::get\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ========================================================================================================= Retrieves a specific block type. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` public function get_item( $request ) { $block_name = sprintf( '%s/%s', $request['namespace'], $request['name'] ); $block_type = $this->get_block( $block_name ); if ( is_wp_error( $block_type ) ) { return $block_type; } $data = $this->prepare_item_for_response( $block_type, $request ); return rest_ensure_response( $data ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::get\_block()](get_block) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Get the block, if the name is valid. | | [WP\_REST\_Block\_Types\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Prepares a block type object for serialization. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::prepare_item_for_response( WP_Block_Type $item, WP_REST_Request $request ): WP_REST_Response WP\_REST\_Block\_Types\_Controller::prepare\_item\_for\_response( WP\_Block\_Type $item, WP\_REST\_Request $request ): WP\_REST\_Response ========================================================================================================================================= Prepares a block type object for serialization. `$item` [WP\_Block\_Type](../wp_block_type) Required Block type data. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response) Block type data. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` public function prepare_item_for_response( $item, $request ) { // Restores the more descriptive, specific name for use within this method. $block_type = $item; $fields = $this->get_fields_for_response( $request ); $data = array(); if ( rest_is_field_included( 'attributes', $fields ) ) { $data['attributes'] = $block_type->get_attributes(); } if ( rest_is_field_included( 'is_dynamic', $fields ) ) { $data['is_dynamic'] = $block_type->is_dynamic(); } $schema = $this->get_item_schema(); // Fields deprecated in WordPress 6.1, but left in the schema for backwards compatibility. $deprecated_fields = array( 'editor_script', 'script', 'view_script', 'editor_style', 'style', ); $extra_fields = array_merge( array( 'api_version', 'name', 'title', 'description', 'icon', 'category', 'keywords', 'parent', 'ancestor', 'provides_context', 'uses_context', 'supports', 'styles', 'textdomain', 'example', 'editor_script_handles', 'script_handles', 'view_script_handles', 'editor_style_handles', 'style_handles', 'variations', ), $deprecated_fields ); foreach ( $extra_fields as $extra_field ) { if ( rest_is_field_included( $extra_field, $fields ) ) { if ( isset( $block_type->$extra_field ) ) { $field = $block_type->$extra_field; if ( in_array( $extra_field, $deprecated_fields, true ) && is_array( $field ) ) { // Since the schema only allows strings or null (but no arrays), we return the first array item. $field = ! empty( $field ) ? array_shift( $field ) : ''; } } elseif ( array_key_exists( 'default', $schema['properties'][ $extra_field ] ) ) { $field = $schema['properties'][ $extra_field ]['default']; } else { $field = ''; } $data[ $extra_field ] = rest_sanitize_value_from_schema( $field, $schema['properties'][ $extra_field ] ); } } if ( rest_is_field_included( 'styles', $fields ) ) { $styles = $this->style_registry->get_registered_styles_for_block( $block_type->name ); $styles = array_values( $styles ); $data['styles'] = wp_parse_args( $styles, $data['styles'] ); $data['styles'] = array_filter( $data['styles'] ); } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $response->add_links( $this->prepare_links( $block_type ) ); } /** * Filters a block type returned from the REST API. * * Allows modification of the block type data right before it is returned. * * @since 5.5.0 * * @param WP_REST_Response $response The response object. * @param WP_Block_Type $block_type The original block type object. * @param WP_REST_Request $request Request used to generate the response. */ return apply_filters( 'rest_prepare_block_type', $response, $block_type, $request ); } ``` [apply\_filters( 'rest\_prepare\_block\_type', WP\_REST\_Response $response, WP\_Block\_Type $block\_type, WP\_REST\_Request $request )](../../hooks/rest_prepare_block_type) Filters a block type returned from the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Retrieves the block type’ schema, conforming to JSON Schema. | | [WP\_REST\_Block\_Types\_Controller::prepare\_links()](prepare_links) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Prepares links for the request. | | [rest\_is\_field\_included()](../../functions/rest_is_field_included) wp-includes/rest-api.php | Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body. | | [rest\_sanitize\_value\_from\_schema()](../../functions/rest_sanitize_value_from_schema) wp-includes/rest-api.php | Sanitize a value based on a schema. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Retrieves a specific block type. | | [WP\_REST\_Block\_Types\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Retrieves all post block types, depending on user context. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$block_type` to `$item` to match parent class for PHP 8 named parameter support. | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::prepare_links( WP_Block_Type $block_type ): array WP\_REST\_Block\_Types\_Controller::prepare\_links( WP\_Block\_Type $block\_type ): array ========================================================================================= Prepares links for the request. `$block_type` [WP\_Block\_Type](../wp_block_type) Required Block type data. array Links for the given block type. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` protected function prepare_links( $block_type ) { list( $namespace ) = explode( '/', $block_type->name ); $links = array( 'collection' => array( 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ), 'self' => array( 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $block_type->name ) ), ), 'up' => array( 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $namespace ) ), ), ); if ( $block_type->is_dynamic() ) { $links['https://api.w.org/render-block'] = array( 'href' => add_query_arg( 'context', 'edit', rest_url( sprintf( '%s/%s/%s', 'wp/v2', 'block-renderer', $block_type->name ) ) ), ); } return $links; } ``` | Uses | Description | | --- | --- | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | Used By | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Prepares a block type object for serialization. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Block\_Types\_Controller::get\_items( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ========================================================================================================== Retrieves all post block types, depending on user context. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` public function get_items( $request ) { $data = array(); $block_types = $this->block_registry->get_all_registered(); // Retrieve the list of registered collection query parameters. $registered = $this->get_collection_params(); $namespace = ''; if ( isset( $registered['namespace'] ) && ! empty( $request['namespace'] ) ) { $namespace = $request['namespace']; } foreach ( $block_types as $slug => $obj ) { if ( $namespace ) { list ( $block_namespace ) = explode( '/', $obj->name ); if ( $namespace !== $block_namespace ) { continue; } } $block_type = $this->prepare_item_for_response( $obj, $request ); $data[] = $this->prepare_response_for_collection( $block_type ); } return rest_ensure_response( $data ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::get\_collection\_params()](get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Retrieves the query params for collections. | | [WP\_REST\_Block\_Types\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Prepares a block type object for serialization. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::get_block( string $name ): WP_Block_Type|WP_Error WP\_REST\_Block\_Types\_Controller::get\_block( string $name ): WP\_Block\_Type|WP\_Error ========================================================================================= Get the block, if the name is valid. `$name` string Required Block name. [WP\_Block\_Type](../wp_block_type)|[WP\_Error](../wp_error) Block type object if name is valid, [WP\_Error](../wp_error) otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` protected function get_block( $name ) { $block_type = $this->block_registry->get_registered( $name ); if ( empty( $block_type ) ) { return new WP_Error( 'rest_block_type_invalid', __( 'Invalid block type.' ), array( 'status' => 404 ) ); } return $block_type; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Retrieves a specific block type. | | [WP\_REST\_Block\_Types\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Checks if a given request has access to read a block type. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::get_items_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Block\_Types\_Controller::get\_items\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ================================================================================================================ Checks whether a given request has permission to read post block types. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` public function get_items_permissions_check( $request ) { return $this->check_read_permission(); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::check\_read\_permission()](check_read_permission) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Checks whether a given block type should be visible. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::register_routes() WP\_REST\_Block\_Types\_Controller::register\_routes() ====================================================== Registers the routes for block types. * [register\_rest\_route()](../../functions/register_rest_route) File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<namespace>[a-zA-Z0-9_-]+)', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<namespace>[a-zA-Z0-9_-]+)/(?P<name>[a-zA-Z0-9_-]+)', array( 'args' => array( 'name' => array( 'description' => __( 'Block name.' ), 'type' => 'string', ), 'namespace' => array( 'description' => __( 'Block namespace.' ), 'type' => 'string', ), ), array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::get\_collection\_params()](get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Retrieves the query params for collections. | | [register\_rest\_route()](../../functions/register_rest_route) wp-includes/rest-api.php | Registers a REST API route. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |
programming_docs
wordpress WP_REST_Block_Types_Controller::get_collection_params(): array WP\_REST\_Block\_Types\_Controller::get\_collection\_params(): array ==================================================================== Retrieves the query params for collections. array Collection parameters. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` public function get_collection_params() { return array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 'namespace' => array( 'description' => __( 'Block namespace.' ), 'type' => 'string', ), ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::register\_routes()](register_routes) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Registers the routes for block types. | | [WP\_REST\_Block\_Types\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Retrieves all post block types, depending on user context. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::check_read_permission(): true|WP_Error WP\_REST\_Block\_Types\_Controller::check\_read\_permission(): true|WP\_Error ============================================================================= Checks whether a given block type should be visible. true|[WP\_Error](../wp_error) True if the block type is visible, [WP\_Error](../wp_error) otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` protected function check_read_permission() { if ( current_user_can( 'edit_posts' ) ) { return true; } foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) { if ( current_user_can( $post_type->cap->edit_posts ) ) { return true; } } return new WP_Error( 'rest_block_type_cannot_view', __( 'Sorry, you are not allowed to manage block types.' ), array( 'status' => rest_authorization_required_code() ) ); } ``` | Uses | Description | | --- | --- | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post\_types()](../../functions/get_post_types) wp-includes/post.php | Gets a list of all registered post type objects. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::get\_items\_permissions\_check()](get_items_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Checks whether a given request has permission to read post block types. | | [WP\_REST\_Block\_Types\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Checks if a given request has access to read a block type. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::__construct() WP\_REST\_Block\_Types\_Controller::\_\_construct() =================================================== Constructor. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` public function __construct() { $this->namespace = 'wp/v2'; $this->rest_base = 'block-types'; $this->block_registry = WP_Block_Type_Registry::get_instance(); $this->style_registry = WP_Block_Styles_Registry::get_instance(); } ``` | Uses | Description | | --- | --- | | [WP\_Block\_Styles\_Registry::get\_instance()](../wp_block_styles_registry/get_instance) wp-includes/class-wp-block-styles-registry.php | Utility method to retrieve the main instance of the class. | | [WP\_Block\_Type\_Registry::get\_instance()](../wp_block_type_registry/get_instance) wp-includes/class-wp-block-type-registry.php | Utility method to retrieve the main instance of the class. | | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::get_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Block\_Types\_Controller::get\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error =============================================================================================================== Checks if a given request has access to read a block type. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access for the item, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` public function get_item_permissions_check( $request ) { $check = $this->check_read_permission(); if ( is_wp_error( $check ) ) { return $check; } $block_name = sprintf( '%s/%s', $request['namespace'], $request['name'] ); $block_type = $this->get_block( $block_name ); if ( is_wp_error( $block_type ) ) { return $block_type; } return true; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::get\_block()](get_block) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Get the block, if the name is valid. | | [WP\_REST\_Block\_Types\_Controller::check\_read\_permission()](check_read_permission) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Checks whether a given block type should be visible. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_REST_Block_Types_Controller::get_item_schema(): array WP\_REST\_Block\_Types\_Controller::get\_item\_schema(): array ============================================================== Retrieves the block type’ schema, conforming to JSON Schema. array Item schema data. File: `wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } // rest_validate_value_from_schema doesn't understand $refs, pull out reused definitions for readability. $inner_blocks_definition = array( 'description' => __( 'The list of inner blocks used in the example.' ), 'type' => 'array', 'items' => array( 'type' => 'object', 'properties' => array( 'name' => array( 'description' => __( 'The name of the inner block.' ), 'type' => 'string', ), 'attributes' => array( 'description' => __( 'The attributes of the inner block.' ), 'type' => 'object', ), 'innerBlocks' => array( 'description' => __( "A list of the inner block's own inner blocks. This is a recursive definition following the parent innerBlocks schema." ), 'type' => 'array', ), ), ), ); $example_definition = array( 'description' => __( 'Block example.' ), 'type' => array( 'object', 'null' ), 'default' => null, 'properties' => array( 'attributes' => array( 'description' => __( 'The attributes used in the example.' ), 'type' => 'object', ), 'innerBlocks' => $inner_blocks_definition, ), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ); $keywords_definition = array( 'description' => __( 'Block keywords.' ), 'type' => 'array', 'items' => array( 'type' => 'string', ), 'default' => array(), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ); $icon_definition = array( 'description' => __( 'Icon of block type.' ), 'type' => array( 'string', 'null' ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ); $category_definition = array( 'description' => __( 'Block category.' ), 'type' => array( 'string', 'null' ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ); $this->schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'block-type', 'type' => 'object', 'properties' => array( 'api_version' => array( 'description' => __( 'Version of block API.' ), 'type' => 'integer', 'default' => 1, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'title' => array( 'description' => __( 'Title of block type.' ), 'type' => 'string', 'default' => '', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'name' => array( 'description' => __( 'Unique name identifying the block type.' ), 'type' => 'string', 'default' => '', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'description' => array( 'description' => __( 'Description of block type.' ), 'type' => 'string', 'default' => '', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'icon' => $icon_definition, 'attributes' => array( 'description' => __( 'Block attributes.' ), 'type' => array( 'object', 'null' ), 'properties' => array(), 'default' => null, 'additionalProperties' => array( 'type' => 'object', ), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'provides_context' => array( 'description' => __( 'Context provided by blocks of this type.' ), 'type' => 'object', 'properties' => array(), 'additionalProperties' => array( 'type' => 'string', ), 'default' => array(), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'uses_context' => array( 'description' => __( 'Context values inherited by blocks of this type.' ), 'type' => 'array', 'default' => array(), 'items' => array( 'type' => 'string', ), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'supports' => array( 'description' => __( 'Block supports.' ), 'type' => 'object', 'default' => array(), 'properties' => array(), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'category' => $category_definition, 'is_dynamic' => array( 'description' => __( 'Is the block dynamically rendered.' ), 'type' => 'boolean', 'default' => false, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'editor_script_handles' => array( 'description' => __( 'Editor script handles.' ), 'type' => array( 'array' ), 'default' => array(), 'items' => array( 'type' => 'string', ), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'script_handles' => array( 'description' => __( 'Public facing and editor script handles.' ), 'type' => array( 'array' ), 'default' => array(), 'items' => array( 'type' => 'string', ), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'view_script_handles' => array( 'description' => __( 'Public facing script handles.' ), 'type' => array( 'array' ), 'default' => array(), 'items' => array( 'type' => 'string', ), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'editor_style_handles' => array( 'description' => __( 'Editor style handles.' ), 'type' => array( 'array' ), 'default' => array(), 'items' => array( 'type' => 'string', ), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'style_handles' => array( 'description' => __( 'Public facing and editor style handles.' ), 'type' => array( 'array' ), 'default' => array(), 'items' => array( 'type' => 'string', ), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'styles' => array( 'description' => __( 'Block style variations.' ), 'type' => 'array', 'items' => array( 'type' => 'object', 'properties' => array( 'name' => array( 'description' => __( 'Unique name identifying the style.' ), 'type' => 'string', 'required' => true, ), 'label' => array( 'description' => __( 'The human-readable label for the style.' ), 'type' => 'string', ), 'inline_style' => array( 'description' => __( 'Inline CSS code that registers the CSS class required for the style.' ), 'type' => 'string', ), 'style_handle' => array( 'description' => __( 'Contains the handle that defines the block style.' ), 'type' => 'string', ), ), ), 'default' => array(), 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'variations' => array( 'description' => __( 'Block variations.' ), 'type' => 'array', 'items' => array( 'type' => 'object', 'properties' => array( 'name' => array( 'description' => __( 'The unique and machine-readable name.' ), 'type' => 'string', 'required' => true, ), 'title' => array( 'description' => __( 'A human-readable variation title.' ), 'type' => 'string', 'required' => true, ), 'description' => array( 'description' => __( 'A detailed variation description.' ), 'type' => 'string', 'required' => false, ), 'category' => $category_definition, 'icon' => $icon_definition, 'isDefault' => array( 'description' => __( 'Indicates whether the current variation is the default one.' ), 'type' => 'boolean', 'required' => false, 'default' => false, ), 'attributes' => array( 'description' => __( 'The initial values for attributes.' ), 'type' => 'object', ), 'innerBlocks' => $inner_blocks_definition, 'example' => $example_definition, 'scope' => array( 'description' => __( 'The list of scopes where the variation is applicable. When not provided, it assumes all available scopes.' ), 'type' => array( 'array', 'null' ), 'default' => null, 'items' => array( 'type' => 'string', 'enum' => array( 'block', 'inserter', 'transform' ), ), 'readonly' => true, ), 'keywords' => $keywords_definition, ), ), 'readonly' => true, 'context' => array( 'embed', 'view', 'edit' ), 'default' => null, ), 'textdomain' => array( 'description' => __( 'Public text domain.' ), 'type' => array( 'string', 'null' ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'parent' => array( 'description' => __( 'Parent blocks.' ), 'type' => array( 'array', 'null' ), 'items' => array( 'type' => 'string', ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'ancestor' => array( 'description' => __( 'Ancestor blocks.' ), 'type' => array( 'array', 'null' ), 'items' => array( 'type' => 'string', ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'keywords' => $keywords_definition, 'example' => $example_definition, ), ); // Properties deprecated in WordPress 6.1, but left in the schema for backwards compatibility. $deprecated_properties = array( 'editor_script' => array( 'description' => __( 'Editor script handle. DEPRECATED: Use `editor_script_handles` instead.' ), 'type' => array( 'string', 'null' ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'script' => array( 'description' => __( 'Public facing and editor script handle. DEPRECATED: Use `script_handles` instead.' ), 'type' => array( 'string', 'null' ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'view_script' => array( 'description' => __( 'Public facing script handle. DEPRECATED: Use `view_script_handles` instead.' ), 'type' => array( 'string', 'null' ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'editor_style' => array( 'description' => __( 'Editor style handle. DEPRECATED: Use `editor_style_handles` instead.' ), 'type' => array( 'string', 'null' ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'style' => array( 'description' => __( 'Public facing and editor style handle. DEPRECATED: Use `style_handles` instead.' ), 'type' => array( 'string', 'null' ), 'default' => null, 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), ); $this->schema['properties'] = array_merge( $this->schema['properties'], $deprecated_properties ); return $this->add_additional_fields_schema( $this->schema ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_REST\_Block\_Types\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Prepares a block type object for serialization. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |
programming_docs
wordpress WP_Widget_Calendar::form( array $instance ) WP\_Widget\_Calendar::form( array $instance ) ============================================= Outputs the settings form for the Calendar widget. `$instance` array Required Current settings. File: `wp-includes/widgets/class-wp-widget-calendar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-calendar.php/) ``` public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /> </p> <?php } ``` | Uses | Description | | --- | --- | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Calendar::update( array $new_instance, array $old_instance ): array WP\_Widget\_Calendar::update( array $new\_instance, array $old\_instance ): array ================================================================================= Handles updating settings for the current Calendar widget instance. `$new_instance` array Required New settings for this instance as input by the user via [WP\_Widget::form()](../wp_widget/form). `$old_instance` array Required Old settings for this instance. array Updated settings to save. File: `wp-includes/widgets/class-wp-widget-calendar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-calendar.php/) ``` public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = sanitize_text_field( $new_instance['title'] ); return $instance; } ``` | Uses | Description | | --- | --- | | [sanitize\_text\_field()](../../functions/sanitize_text_field) wp-includes/formatting.php | Sanitizes a string from user input or from the database. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Calendar::__construct() WP\_Widget\_Calendar::\_\_construct() ===================================== Sets up a new Calendar widget instance. File: `wp-includes/widgets/class-wp-widget-calendar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-calendar.php/) ``` public function __construct() { $widget_ops = array( 'classname' => 'widget_calendar', 'description' => __( 'A calendar of your site’s posts.' ), 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, ); parent::__construct( 'calendar', __( 'Calendar' ), $widget_ops ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget::\_\_construct()](../wp_widget/__construct) wp-includes/class-wp-widget.php | PHP5 constructor. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Calendar::widget( array $args, array $instance ) WP\_Widget\_Calendar::widget( array $args, array $instance ) ============================================================ Outputs the content for the current Calendar widget instance. `$args` array Required Display arguments including `'before_title'`, `'after_title'`, `'before_widget'`, and `'after_widget'`. `$instance` array Required The settings for the particular instance of the widget. File: `wp-includes/widgets/class-wp-widget-calendar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-calendar.php/) ``` public function widget( $args, $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } if ( 0 === self::$instance ) { echo '<div id="calendar_wrap" class="calendar_wrap">'; } else { echo '<div class="calendar_wrap">'; } get_calendar(); echo '</div>'; echo $args['after_widget']; self::$instance++; } ``` [apply\_filters( 'widget\_title', string $title, array $instance, mixed $id\_base )](../../hooks/widget_title) Filters the widget title. | Uses | Description | | --- | --- | | [get\_calendar()](../../functions/get_calendar) wp-includes/general-template.php | Displays calendar with days that have posts as links. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Plugins_List_Table::single_row( array $item ) WP\_Plugins\_List\_Table::single\_row( array $item ) ==================================================== `$item` array Required File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function single_row( $item ) { global $status, $page, $s, $totals; static $plugin_id_attrs = array(); list( $plugin_file, $plugin_data ) = $item; $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_data['Name'] ); $plugin_id_attr = $plugin_slug; // Ensure the ID attribute is unique. $suffix = 2; while ( in_array( $plugin_id_attr, $plugin_id_attrs, true ) ) { $plugin_id_attr = "$plugin_slug-$suffix"; $suffix++; } $plugin_id_attrs[] = $plugin_id_attr; $context = $status; $screen = $this->screen; // Pre-order. $actions = array( 'deactivate' => '', 'activate' => '', 'details' => '', 'delete' => '', ); // Do not restrict by default. $restrict_network_active = false; $restrict_network_only = false; $requires_php = isset( $plugin_data['RequiresPHP'] ) ? $plugin_data['RequiresPHP'] : null; $requires_wp = isset( $plugin_data['RequiresWP'] ) ? $plugin_data['RequiresWP'] : null; $compatible_php = is_php_version_compatible( $requires_php ); $compatible_wp = is_wp_version_compatible( $requires_wp ); if ( 'mustuse' === $context ) { $is_active = true; } elseif ( 'dropins' === $context ) { $dropins = _get_dropins(); $plugin_name = $plugin_file; if ( $plugin_file !== $plugin_data['Name'] ) { $plugin_name .= '<br />' . $plugin_data['Name']; } if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant. $is_active = true; $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true. $is_active = true; $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>'; } else { $is_active = false; $description = '<p><strong>' . $dropins[ $plugin_file ][0] . ' <span class="error-message">' . __( 'Inactive:' ) . '</span></strong> ' . sprintf( /* translators: 1: Drop-in constant name, 2: wp-config.php */ __( 'Requires %1$s in %2$s file.' ), "<code>define('" . $dropins[ $plugin_file ][1] . "', true);</code>", '<code>wp-config.php</code>' ) . '</p>'; } if ( $plugin_data['Description'] ) { $description .= '<p>' . $plugin_data['Description'] . '</p>'; } } else { if ( $screen->in_admin( 'network' ) ) { $is_active = is_plugin_active_for_network( $plugin_file ); } else { $is_active = is_plugin_active( $plugin_file ); $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) ); $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active ); } if ( $screen->in_admin( 'network' ) ) { if ( $is_active ) { if ( current_user_can( 'manage_network_plugins' ) ) { $actions['deactivate'] = sprintf( '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>', wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Network Deactivate' ) ); } } else { if ( current_user_can( 'manage_network_plugins' ) ) { if ( $compatible_php && $compatible_wp ) { $actions['activate'] = sprintf( '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>', wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Network Activate' ) ); } else { $actions['activate'] = sprintf( '<span>%s</span>', _x( 'Cannot Activate', 'plugin' ) ); } } if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) { $actions['delete'] = sprintf( '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>', wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Delete' ) ); } } } else { if ( $restrict_network_active ) { $actions = array( 'network_active' => __( 'Network Active' ), ); } elseif ( $restrict_network_only ) { $actions = array( 'network_only' => __( 'Network Only' ), ); } elseif ( $is_active ) { if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) { $actions['deactivate'] = sprintf( '<a href="%s" id="deactivate-%s" aria-label="%s">%s</a>', wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Deactivate' ) ); } if ( current_user_can( 'resume_plugin', $plugin_file ) && is_plugin_paused( $plugin_file ) ) { $actions['resume'] = sprintf( '<a href="%s" id="resume-%s" class="resume-link" aria-label="%s">%s</a>', wp_nonce_url( 'plugins.php?action=resume&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'resume-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Resume %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Resume' ) ); } } else { if ( current_user_can( 'activate_plugin', $plugin_file ) ) { if ( $compatible_php && $compatible_wp ) { $actions['activate'] = sprintf( '<a href="%s" id="activate-%s" class="edit" aria-label="%s">%s</a>', wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'activate-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Activate' ) ); } else { $actions['activate'] = sprintf( '<span>%s</span>', _x( 'Cannot Activate', 'plugin' ) ); } } if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) { $actions['delete'] = sprintf( '<a href="%s" id="delete-%s" class="delete" aria-label="%s">%s</a>', wp_nonce_url( 'plugins.php?action=delete-selected&amp;checked[]=' . urlencode( $plugin_file ) . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-plugins' ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Delete' ) ); } } // End if $is_active. } // End if $screen->in_admin( 'network' ). } // End if $context. $actions = array_filter( $actions ); if ( $screen->in_admin( 'network' ) ) { /** * Filters the action links displayed for each plugin in the Network Admin Plugins list table. * * @since 3.1.0 * * @param string[] $actions An array of plugin action links. By default this can include * 'activate', 'deactivate', and 'delete'. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $context The plugin context. By default this can include 'all', * 'active', 'inactive', 'recently_activated', 'upgrade', * 'mustuse', 'dropins', and 'search'. */ $actions = apply_filters( 'network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); /** * Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table. * * The dynamic portion of the hook name, `$plugin_file`, refers to the path * to the plugin file, relative to the plugins directory. * * @since 3.1.0 * * @param string[] $actions An array of plugin action links. By default this can include * 'activate', 'deactivate', and 'delete'. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $context The plugin context. By default this can include 'all', * 'active', 'inactive', 'recently_activated', 'upgrade', * 'mustuse', 'dropins', and 'search'. */ $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); } else { /** * Filters the action links displayed for each plugin in the Plugins list table. * * @since 2.5.0 * @since 2.6.0 The `$context` parameter was added. * @since 4.9.0 The 'Edit' link was removed from the list of action links. * * @param string[] $actions An array of plugin action links. By default this can include * 'activate', 'deactivate', and 'delete'. With Multisite active * this can also include 'network_active' and 'network_only' items. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $context The plugin context. By default this can include 'all', * 'active', 'inactive', 'recently_activated', 'upgrade', * 'mustuse', 'dropins', and 'search'. */ $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); /** * Filters the list of action links displayed for a specific plugin in the Plugins list table. * * The dynamic portion of the hook name, `$plugin_file`, refers to the path * to the plugin file, relative to the plugins directory. * * @since 2.7.0 * @since 4.9.0 The 'Edit' link was removed from the list of action links. * * @param string[] $actions An array of plugin action links. By default this can include * 'activate', 'deactivate', and 'delete'. With Multisite active * this can also include 'network_active' and 'network_only' items. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $context The plugin context. By default this can include 'all', * 'active', 'inactive', 'recently_activated', 'upgrade', * 'mustuse', 'dropins', and 'search'. */ $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); } $class = $is_active ? 'active' : 'inactive'; $checkbox_id = 'checkbox_' . md5( $plugin_file ); if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ), true ) || ! $compatible_php ) { $checkbox = ''; } else { $checkbox = sprintf( '<label class="screen-reader-text" for="%1$s">%2$s</label>' . '<input type="checkbox" name="checked[]" value="%3$s" id="%1$s" />', $checkbox_id, /* translators: %s: Plugin name. */ sprintf( __( 'Select %s' ), $plugin_data['Name'] ), esc_attr( $plugin_file ) ); } if ( 'dropins' !== $context ) { $description = '<p>' . ( $plugin_data['Description'] ? $plugin_data['Description'] : '&nbsp;' ) . '</p>'; $plugin_name = $plugin_data['Name']; } if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) || ! $compatible_php || ! $compatible_wp ) { $class .= ' update'; } $paused = ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file ); if ( $paused ) { $class .= ' paused'; } if ( is_uninstallable_plugin( $plugin_file ) ) { $class .= ' is-uninstallable'; } printf( '<tr class="%s" data-slug="%s" data-plugin="%s">', esc_attr( $class ), esc_attr( $plugin_slug ), esc_attr( $plugin_file ) ); list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); $auto_updates = (array) get_site_option( 'auto_update_plugins', array() ); $available_updates = get_site_transient( 'update_plugins' ); foreach ( $columns as $column_name => $column_display_name ) { $extra_classes = ''; if ( in_array( $column_name, $hidden, true ) ) { $extra_classes = ' hidden'; } switch ( $column_name ) { case 'cb': echo "<th scope='row' class='check-column'>$checkbox</th>"; break; case 'name': echo "<td class='plugin-title column-primary'><strong>$plugin_name</strong>"; echo $this->row_actions( $actions, true ); echo '</td>'; break; case 'description': $classes = 'column-description desc'; echo "<td class='$classes{$extra_classes}'> <div class='plugin-description'>$description</div> <div class='$class second plugin-version-author-uri'>"; $plugin_meta = array(); if ( ! empty( $plugin_data['Version'] ) ) { /* translators: %s: Plugin version number. */ $plugin_meta[] = sprintf( __( 'Version %s' ), $plugin_data['Version'] ); } if ( ! empty( $plugin_data['Author'] ) ) { $author = $plugin_data['Author']; if ( ! empty( $plugin_data['AuthorURI'] ) ) { $author = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; } /* translators: %s: Plugin author name. */ $plugin_meta[] = sprintf( __( 'By %s' ), $author ); } // Details link using API info, if available. if ( isset( $plugin_data['slug'] ) && current_user_can( 'install_plugins' ) ) { $plugin_meta[] = sprintf( '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>', esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data['slug'] . '&TB_iframe=true&width=600&height=550' ) ), /* translators: %s: Plugin name. */ esc_attr( sprintf( __( 'More information about %s' ), $plugin_name ) ), esc_attr( $plugin_name ), __( 'View details' ) ); } elseif ( ! empty( $plugin_data['PluginURI'] ) ) { /* translators: %s: Plugin name. */ $aria_label = sprintf( __( 'Visit plugin site for %s' ), $plugin_name ); $plugin_meta[] = sprintf( '<a href="%s" aria-label="%s">%s</a>', esc_url( $plugin_data['PluginURI'] ), esc_attr( $aria_label ), __( 'Visit plugin site' ) ); } /** * Filters the array of row meta for each plugin in the Plugins list table. * * @since 2.8.0 * * @param string[] $plugin_meta An array of the plugin's metadata, including * the version, author, author URI, and plugin URI. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data { * An array of plugin data. * * @type string $id Plugin ID, e.g. `w.org/plugins/[plugin-name]`. * @type string $slug Plugin slug. * @type string $plugin Plugin basename. * @type string $new_version New plugin version. * @type string $url Plugin URL. * @type string $package Plugin update package URL. * @type string[] $icons An array of plugin icon URLs. * @type string[] $banners An array of plugin banner URLs. * @type string[] $banners_rtl An array of plugin RTL banner URLs. * @type string $requires The version of WordPress which the plugin requires. * @type string $tested The version of WordPress the plugin is tested against. * @type string $requires_php The version of PHP which the plugin requires. * @type string $upgrade_notice The upgrade notice for the new plugin version. * @type bool $update-supported Whether the plugin supports updates. * @type string $Name The human-readable name of the plugin. * @type string $PluginURI Plugin URI. * @type string $Version Plugin version. * @type string $Description Plugin description. * @type string $Author Plugin author. * @type string $AuthorURI Plugin author URI. * @type string $TextDomain Plugin textdomain. * @type string $DomainPath Relative path to the plugin's .mo file(s). * @type bool $Network Whether the plugin can only be activated network-wide. * @type string $RequiresWP The version of WordPress which the plugin requires. * @type string $RequiresPHP The version of PHP which the plugin requires. * @type string $UpdateURI ID of the plugin for update purposes, should be a URI. * @type string $Title The human-readable title of the plugin. * @type string $AuthorName Plugin author's name. * @type bool $update Whether there's an available update. Default null. * } * @param string $status Status filter currently applied to the plugin list. Possible * values are: 'all', 'active', 'inactive', 'recently_activated', * 'upgrade', 'mustuse', 'dropins', 'search', 'paused', * 'auto-update-enabled', 'auto-update-disabled'. */ $plugin_meta = apply_filters( 'plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $status ); echo implode( ' | ', $plugin_meta ); echo '</div>'; if ( $paused ) { $notice_text = __( 'This plugin failed to load properly and is paused during recovery mode.' ); printf( '<p><span class="dashicons dashicons-warning"></span> <strong>%s</strong></p>', $notice_text ); $error = wp_get_plugin_error( $plugin_file ); if ( false !== $error ) { printf( '<div class="error-display"><p>%s</p></div>', wp_get_extension_error_description( $error ) ); } } echo '</td>'; break; case 'auto-updates': if ( ! $this->show_autoupdates ) { break; } echo "<td class='column-auto-updates{$extra_classes}'>"; $html = array(); if ( isset( $plugin_data['auto-update-forced'] ) ) { if ( $plugin_data['auto-update-forced'] ) { // Forced on. $text = __( 'Auto-updates enabled' ); } else { $text = __( 'Auto-updates disabled' ); } $action = 'unavailable'; $time_class = ' hidden'; } elseif ( empty( $plugin_data['update-supported'] ) ) { $text = ''; $action = 'unavailable'; $time_class = ' hidden'; } elseif ( in_array( $plugin_file, $auto_updates, true ) ) { $text = __( 'Disable auto-updates' ); $action = 'disable'; $time_class = ''; } else { $text = __( 'Enable auto-updates' ); $action = 'enable'; $time_class = ' hidden'; } $query_args = array( 'action' => "{$action}-auto-update", 'plugin' => $plugin_file, 'paged' => $page, 'plugin_status' => $status, ); $url = add_query_arg( $query_args, 'plugins.php' ); if ( 'unavailable' === $action ) { $html[] = '<span class="label">' . $text . '</span>'; } else { $html[] = sprintf( '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">', wp_nonce_url( $url, 'updates' ), $action ); $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>'; $html[] = '<span class="label">' . $text . '</span>'; $html[] = '</a>'; } if ( ! empty( $plugin_data['update'] ) ) { $html[] = sprintf( '<div class="auto-update-time%s">%s</div>', $time_class, wp_get_auto_update_message() ); } $html = implode( '', $html ); /** * Filters the HTML of the auto-updates setting for each plugin in the Plugins list table. * * @since 5.5.0 * * @param string $html The HTML of the plugin's auto-update column content, * including toggle auto-update action links and * time to next update. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. */ echo apply_filters( 'plugin_auto_update_setting_html', $html, $plugin_file, $plugin_data ); echo '<div class="notice notice-error notice-alt inline hidden"><p></p></div>'; echo '</td>'; break; default: $classes = "$column_name column-$column_name $class"; echo "<td class='$classes{$extra_classes}'>"; /** * Fires inside each custom column of the Plugins list table. * * @since 3.1.0 * * @param string $column_name Name of the column. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. */ do_action( 'manage_plugins_custom_column', $column_name, $plugin_file, $plugin_data ); echo '</td>'; } } echo '</tr>'; if ( ! $compatible_php || ! $compatible_wp ) { printf( '<tr class="plugin-update-tr">' . '<td colspan="%s" class="plugin-update colspanchange">' . '<div class="update-message notice inline notice-error notice-alt"><p>', esc_attr( $this->get_column_count() ) ); if ( ! $compatible_php && ! $compatible_wp ) { _e( 'This plugin does not work with your versions of WordPress and PHP.' ); if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { printf( /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), self_admin_url( 'update-core.php' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } elseif ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } elseif ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } } elseif ( ! $compatible_wp ) { _e( 'This plugin does not work with your version of WordPress.' ); if ( current_user_can( 'update_core' ) ) { printf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( '<a href="%s">Please update WordPress</a>.' ), self_admin_url( 'update-core.php' ) ); } } elseif ( ! $compatible_php ) { _e( 'This plugin does not work with your version of PHP.' ); if ( current_user_can( 'update_php' ) ) { printf( /* translators: %s: URL to Update PHP page. */ ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); wp_update_php_annotation( '</p><p><em>', '</em>' ); } } echo '</p></div></td></tr>'; } /** * Fires after each row in the Plugins list table. * * @since 2.3.0 * @since 5.5.0 Added 'auto-update-enabled' and 'auto-update-disabled' * to possible values for `$status`. * * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $status Status filter currently applied to the plugin list. * Possible values are: 'all', 'active', 'inactive', * 'recently_activated', 'upgrade', 'mustuse', 'dropins', * 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled'. */ do_action( 'after_plugin_row', $plugin_file, $plugin_data, $status ); /** * Fires after each specific row in the Plugins list table. * * The dynamic portion of the hook name, `$plugin_file`, refers to the path * to the plugin file, relative to the plugins directory. * * @since 2.7.0 * @since 5.5.0 Added 'auto-update-enabled' and 'auto-update-disabled' * to possible values for `$status`. * * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $status Status filter currently applied to the plugin list. * Possible values are: 'all', 'active', 'inactive', * 'recently_activated', 'upgrade', 'mustuse', 'dropins', * 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled'. */ do_action( "after_plugin_row_{$plugin_file}", $plugin_file, $plugin_data, $status ); } ``` [do\_action( 'after\_plugin\_row', string $plugin\_file, array $plugin\_data, string $status )](../../hooks/after_plugin_row) Fires after each row in the Plugins list table. [do\_action( "after\_plugin\_row\_{$plugin\_file}", string $plugin\_file, array $plugin\_data, string $status )](../../hooks/after_plugin_row_plugin_file) Fires after each specific row in the Plugins list table. [do\_action( 'manage\_plugins\_custom\_column', string $column\_name, string $plugin\_file, array $plugin\_data )](../../hooks/manage_plugins_custom_column) Fires inside each custom column of the Plugins list table. [apply\_filters( 'network\_admin\_plugin\_action\_links', string[] $actions, string $plugin\_file, array $plugin\_data, string $context )](../../hooks/network_admin_plugin_action_links) Filters the action links displayed for each plugin in the Network Admin Plugins list table. [apply\_filters( "network\_admin\_plugin\_action\_links\_{$plugin\_file}", string[] $actions, string $plugin\_file, array $plugin\_data, string $context )](../../hooks/network_admin_plugin_action_links_plugin_file) Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table. [apply\_filters( 'plugin\_action\_links', string[] $actions, string $plugin\_file, array $plugin\_data, string $context )](../../hooks/plugin_action_links) Filters the action links displayed for each plugin in the Plugins list table. [apply\_filters( "plugin\_action\_links\_{$plugin\_file}", string[] $actions, string $plugin\_file, array $plugin\_data, string $context )](../../hooks/plugin_action_links_plugin_file) Filters the list of action links displayed for a specific plugin in the Plugins list table. [apply\_filters( 'plugin\_auto\_update\_setting\_html', string $html, string $plugin\_file, array $plugin\_data )](../../hooks/plugin_auto_update_setting_html) Filters the HTML of the auto-updates setting for each plugin in the Plugins list table. [apply\_filters( 'plugin\_row\_meta', string[] $plugin\_meta, string $plugin\_file, array $plugin\_data, string $status )](../../hooks/plugin_row_meta) Filters the array of row meta for each plugin in the Plugins list table. | Uses | Description | | --- | --- | | [wp\_get\_auto\_update\_message()](../../functions/wp_get_auto_update_message) wp-admin/includes/update.php | Determines the appropriate auto-update message to be displayed. | | [\_get\_dropins()](../../functions/_get_dropins) wp-admin/includes/plugin.php | Returns drop-ins that WordPress uses. | | [self\_admin\_url()](../../functions/self_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for either the current site or the network depending on context. | | [network\_admin\_url()](../../functions/network_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the network. | | [wp\_get\_extension\_error\_description()](../../functions/wp_get_extension_error_description) wp-includes/error-protection.php | Get a human readable description of an extension’s error. | | [get\_site\_transient()](../../functions/get_site_transient) wp-includes/option.php | Retrieves the value of a site transient. | | [is\_network\_only\_plugin()](../../functions/is_network_only_plugin) wp-admin/includes/plugin.php | Checks for “Network: true” in the plugin header to see if this should be activated only as a network wide plugin. The plugin would also work when Multisite is not enabled. | | [is\_plugin\_active()](../../functions/is_plugin_active) wp-admin/includes/plugin.php | Determines whether a plugin is active. | | [is\_plugin\_active\_for\_network()](../../functions/is_plugin_active_for_network) wp-admin/includes/plugin.php | Determines whether the plugin is active for the entire network. | | [is\_uninstallable\_plugin()](../../functions/is_uninstallable_plugin) wp-admin/includes/plugin.php | Determines whether the plugin can be uninstalled. | | [wp\_update\_php\_annotation()](../../functions/wp_update_php_annotation) wp-includes/functions.php | Prints the default annotation for the web host altering the “Update PHP” page URL. | | [wp\_get\_update\_php\_url()](../../functions/wp_get_update_php_url) wp-includes/functions.php | Gets the URL to learn more about updating the PHP version the site is running on. | | [is\_plugin\_paused()](../../functions/is_plugin_paused) wp-admin/includes/plugin.php | Determines whether a plugin is technically active but was paused while loading. | | [wp\_get\_plugin\_error()](../../functions/wp_get_plugin_error) wp-admin/includes/plugin.php | Gets the error that was recorded for a paused plugin. | | [is\_wp\_version\_compatible()](../../functions/is_wp_version_compatible) wp-includes/functions.php | Checks compatibility with the current WordPress version. | | [is\_php\_version\_compatible()](../../functions/is_php_version_compatible) wp-includes/functions.php | Checks compatibility with the current PHP version. | | [sanitize\_title()](../../functions/sanitize_title) wp-includes/formatting.php | Sanitizes a string into a slug, which can be used in URLs or HTML attributes. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [get\_site\_option()](../../functions/get_site_option) wp-includes/option.php | Retrieve an option value for the current network based on name of option. | | Used By | Description | | --- | --- | | [WP\_Plugins\_List\_Table::display\_rows()](display_rows) wp-admin/includes/class-wp-plugins-list-table.php | |
programming_docs
wordpress WP_Plugins_List_Table::extra_tablenav( string $which ) WP\_Plugins\_List\_Table::extra\_tablenav( string $which ) ========================================================== `$which` string Required File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` protected function extra_tablenav( $which ) { global $status; if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ), true ) ) { return; } echo '<div class="alignleft actions">'; if ( 'recently_activated' === $status ) { submit_button( __( 'Clear List' ), '', 'clear-recent-list', false ); } elseif ( 'top' === $which && 'mustuse' === $status ) { echo '<p>' . sprintf( /* translators: %s: mu-plugins directory name. */ __( 'Files in the %s directory are executed automatically.' ), '<code>' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '</code>' ) . '</p>'; } elseif ( 'top' === $which && 'dropins' === $status ) { echo '<p>' . sprintf( /* translators: %s: wp-content directory name. */ __( 'Drop-ins are single files, found in the %s directory, that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ), '<code>' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '</code>' ) . '</p>'; } echo '</div>'; } ``` | Uses | Description | | --- | --- | | [submit\_button()](../../functions/submit_button) wp-admin/includes/template.php | Echoes a submit button, with provided text and appropriate class(es). | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | wordpress WP_Plugins_List_Table::current_action(): string WP\_Plugins\_List\_Table::current\_action(): string =================================================== string File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function current_action() { if ( isset( $_POST['clear-recent-list'] ) ) { return 'clear-recent-list'; } return parent::current_action(); } ``` | Uses | Description | | --- | --- | | [WP\_List\_Table::current\_action()](../wp_list_table/current_action) wp-admin/includes/class-wp-list-table.php | Gets the current action selected from the bulk actions dropdown. | wordpress WP_Plugins_List_Table::prepare_items() WP\_Plugins\_List\_Table::prepare\_items() ========================================== File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function prepare_items() { global $status, $plugins, $totals, $page, $orderby, $order, $s; wp_reset_vars( array( 'orderby', 'order' ) ); /** * Filters the full array of plugins to list in the Plugins list table. * * @since 3.0.0 * * @see get_plugins() * * @param array $all_plugins An array of plugins to display in the list table. */ $all_plugins = apply_filters( 'all_plugins', get_plugins() ); $plugins = array( 'all' => $all_plugins, 'search' => array(), 'active' => array(), 'inactive' => array(), 'recently_activated' => array(), 'upgrade' => array(), 'mustuse' => array(), 'dropins' => array(), 'paused' => array(), ); if ( $this->show_autoupdates ) { $auto_updates = (array) get_site_option( 'auto_update_plugins', array() ); $plugins['auto-update-enabled'] = array(); $plugins['auto-update-disabled'] = array(); } $screen = $this->screen; if ( ! is_multisite() || ( $screen->in_admin( 'network' ) && current_user_can( 'manage_network_plugins' ) ) ) { /** * Filters whether to display the advanced plugins list table. * * There are two types of advanced plugins - must-use and drop-ins - * which can be used in a single site or Multisite network. * * The $type parameter allows you to differentiate between the type of advanced * plugins to filter the display of. Contexts include 'mustuse' and 'dropins'. * * @since 3.0.0 * * @param bool $show Whether to show the advanced plugins for the specified * plugin type. Default true. * @param string $type The plugin type. Accepts 'mustuse', 'dropins'. */ if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) { $plugins['mustuse'] = get_mu_plugins(); } /** This action is documented in wp-admin/includes/class-wp-plugins-list-table.php */ if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) { $plugins['dropins'] = get_dropins(); } if ( current_user_can( 'update_plugins' ) ) { $current = get_site_transient( 'update_plugins' ); foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { if ( isset( $current->response[ $plugin_file ] ) ) { $plugins['all'][ $plugin_file ]['update'] = true; $plugins['upgrade'][ $plugin_file ] = $plugins['all'][ $plugin_file ]; } } } } if ( ! $screen->in_admin( 'network' ) ) { $show = current_user_can( 'manage_network_plugins' ); /** * Filters whether to display network-active plugins alongside plugins active for the current site. * * This also controls the display of inactive network-only plugins (plugins with * "Network: true" in the plugin header). * * Plugins cannot be network-activated or network-deactivated from this screen. * * @since 4.4.0 * * @param bool $show Whether to show network-active plugins. Default is whether the current * user can manage network plugins (ie. a Super Admin). */ $show_network_active = apply_filters( 'show_network_active_plugins', $show ); } if ( $screen->in_admin( 'network' ) ) { $recently_activated = get_site_option( 'recently_activated', array() ); } else { $recently_activated = get_option( 'recently_activated', array() ); } foreach ( $recently_activated as $key => $time ) { if ( $time + WEEK_IN_SECONDS < time() ) { unset( $recently_activated[ $key ] ); } } if ( $screen->in_admin( 'network' ) ) { update_site_option( 'recently_activated', $recently_activated ); } else { update_option( 'recently_activated', $recently_activated ); } $plugin_info = get_site_transient( 'update_plugins' ); foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide. if ( isset( $plugin_info->response[ $plugin_file ] ) ) { $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], array( 'update-supported' => true ), $plugin_data ); } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) { $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], array( 'update-supported' => true ), $plugin_data ); } elseif ( empty( $plugin_data['update-supported'] ) ) { $plugin_data['update-supported'] = false; } /* * Create the payload that's used for the auto_update_plugin filter. * This is the same data contained within $plugin_info->(response|no_update) however * not all plugins will be contained in those keys, this avoids unexpected warnings. */ $filter_payload = array( 'id' => $plugin_file, 'slug' => '', 'plugin' => $plugin_file, 'new_version' => '', 'url' => '', 'package' => '', 'icons' => array(), 'banners' => array(), 'banners_rtl' => array(), 'tested' => '', 'requires_php' => '', 'compatibility' => new stdClass(), ); $filter_payload = (object) wp_parse_args( $plugin_data, $filter_payload ); $auto_update_forced = wp_is_auto_update_forced_for_item( 'plugin', null, $filter_payload ); if ( ! is_null( $auto_update_forced ) ) { $plugin_data['auto-update-forced'] = $auto_update_forced; } $plugins['all'][ $plugin_file ] = $plugin_data; // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade. if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) { $plugins['upgrade'][ $plugin_file ] = $plugin_data; } // Filter into individual sections. if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) { if ( $show_network_active ) { // On the non-network screen, show inactive network-only plugins if allowed. $plugins['inactive'][ $plugin_file ] = $plugin_data; } else { // On the non-network screen, filter out network-only plugins as long as they're not individually active. unset( $plugins['all'][ $plugin_file ] ); } } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) { if ( $show_network_active ) { // On the non-network screen, show network-active plugins if allowed. $plugins['active'][ $plugin_file ] = $plugin_data; } else { // On the non-network screen, filter out network-active plugins. unset( $plugins['all'][ $plugin_file ] ); } } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) ) || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) { // On the non-network screen, populate the active list with plugins that are individually activated. // On the network admin screen, populate the active list with plugins that are network-activated. $plugins['active'][ $plugin_file ] = $plugin_data; if ( ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file ) ) { $plugins['paused'][ $plugin_file ] = $plugin_data; } } else { if ( isset( $recently_activated[ $plugin_file ] ) ) { // Populate the recently activated list with plugins that have been recently activated. $plugins['recently_activated'][ $plugin_file ] = $plugin_data; } // Populate the inactive list with plugins that aren't activated. $plugins['inactive'][ $plugin_file ] = $plugin_data; } if ( $this->show_autoupdates ) { $enabled = in_array( $plugin_file, $auto_updates, true ) && $plugin_data['update-supported']; if ( isset( $plugin_data['auto-update-forced'] ) ) { $enabled = (bool) $plugin_data['auto-update-forced']; } if ( $enabled ) { $plugins['auto-update-enabled'][ $plugin_file ] = $plugin_data; } else { $plugins['auto-update-disabled'][ $plugin_file ] = $plugin_data; } } } if ( strlen( $s ) ) { $status = 'search'; $plugins['search'] = array_filter( $plugins['all'], array( $this, '_search_callback' ) ); } $totals = array(); foreach ( $plugins as $type => $list ) { $totals[ $type ] = count( $list ); } if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) { $status = 'all'; } $this->items = array(); foreach ( $plugins[ $status ] as $plugin_file => $plugin_data ) { // Translate, don't apply markup, sanitize HTML. $this->items[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); } $total_this_page = $totals[ $status ]; $js_plugins = array(); foreach ( $plugins as $key => $list ) { $js_plugins[ $key ] = array_keys( $list ); } wp_localize_script( 'updates', '_wpUpdatesItemCounts', array( 'plugins' => $js_plugins, 'totals' => wp_get_update_data(), ) ); if ( ! $orderby ) { $orderby = 'Name'; } else { $orderby = ucfirst( $orderby ); } $order = strtoupper( $order ); uasort( $this->items, array( $this, '_order_callback' ) ); $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ), 999 ); $start = ( $page - 1 ) * $plugins_per_page; if ( $total_this_page > $plugins_per_page ) { $this->items = array_slice( $this->items, $start, $plugins_per_page ); } $this->set_pagination_args( array( 'total_items' => $total_this_page, 'per_page' => $plugins_per_page, ) ); } ``` [apply\_filters( 'all\_plugins', array $all\_plugins )](../../hooks/all_plugins) Filters the full array of plugins to list in the Plugins list table. [apply\_filters( 'show\_advanced\_plugins', bool $show, string $type )](../../hooks/show_advanced_plugins) Filters whether to display the advanced plugins list table. [apply\_filters( 'show\_network\_active\_plugins', bool $show )](../../hooks/show_network_active_plugins) Filters whether to display network-active plugins alongside plugins active for the current site. | Uses | Description | | --- | --- | | [wp\_is\_auto\_update\_forced\_for\_item()](../../functions/wp_is_auto_update_forced_for_item) wp-admin/includes/update.php | Checks whether auto-updates are forced for an item. | | [get\_site\_transient()](../../functions/get_site_transient) wp-includes/option.php | Retrieves the value of a site transient. | | [wp\_reset\_vars()](../../functions/wp_reset_vars) wp-admin/includes/misc.php | Resets global variables based on $\_GET and $\_POST. | | [get\_dropins()](../../functions/get_dropins) wp-admin/includes/plugin.php | Checks the wp-content directory and retrieve all drop-ins with any plugin data. | | [is\_network\_only\_plugin()](../../functions/is_network_only_plugin) wp-admin/includes/plugin.php | Checks for “Network: true” in the plugin header to see if this should be activated only as a network wide plugin. The plugin would also work when Multisite is not enabled. | | [is\_plugin\_active()](../../functions/is_plugin_active) wp-admin/includes/plugin.php | Determines whether a plugin is active. | | [is\_plugin\_active\_for\_network()](../../functions/is_plugin_active_for_network) wp-admin/includes/plugin.php | Determines whether the plugin is active for the entire network. | | [get\_plugins()](../../functions/get_plugins) wp-admin/includes/plugin.php | Checks the plugins directory and retrieve all plugin files with plugin data. | | [get\_mu\_plugins()](../../functions/get_mu_plugins) wp-admin/includes/plugin.php | Checks the mu-plugins directory and retrieve all mu-plugin files with any plugin data. | | [\_get\_plugin\_data\_markup\_translate()](../../functions/_get_plugin_data_markup_translate) wp-admin/includes/plugin.php | Sanitizes plugin data, optionally adds markup, optionally translates. | | [is\_plugin\_paused()](../../functions/is_plugin_paused) wp-admin/includes/plugin.php | Determines whether a plugin is technically active but was paused while loading. | | [wp\_localize\_script()](../../functions/wp_localize_script) wp-includes/functions.wp-scripts.php | Localize a script. | | [wp\_get\_update\_data()](../../functions/wp_get_update_data) wp-includes/update.php | Collects counts and UI strings for available updates. | | [update\_site\_option()](../../functions/update_site_option) wp-includes/option.php | Updates the value of an option that was already added for the current network. | | [update\_option()](../../functions/update_option) wp-includes/option.php | Updates the value of an option that was already added. | | [get\_site\_option()](../../functions/get_site_option) wp-includes/option.php | Retrieve an option value for the current network based on name of option. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | wordpress WP_Plugins_List_Table::ajax_user_can(): bool WP\_Plugins\_List\_Table::ajax\_user\_can(): bool ================================================= bool File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function ajax_user_can() { return current_user_can( 'activate_plugins' ); } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | wordpress WP_Plugins_List_Table::display_rows() WP\_Plugins\_List\_Table::display\_rows() ========================================= File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function display_rows() { global $status; if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ), true ) ) { return; } foreach ( $this->items as $plugin_file => $plugin_data ) { $this->single_row( array( $plugin_file, $plugin_data ) ); } } ``` | Uses | Description | | --- | --- | | [WP\_Plugins\_List\_Table::single\_row()](single_row) wp-admin/includes/class-wp-plugins-list-table.php | | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | wordpress WP_Plugins_List_Table::no_items() WP\_Plugins\_List\_Table::no\_items() ===================================== File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function no_items() { global $plugins; if ( ! empty( $_REQUEST['s'] ) ) { $s = esc_html( wp_unslash( $_REQUEST['s'] ) ); /* translators: %s: Plugin search term. */ printf( __( 'No plugins found for: %s.' ), '<strong>' . $s . '</strong>' ); // We assume that somebody who can install plugins in multisite is experienced enough to not need this helper link. if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) { echo ' <a href="' . esc_url( admin_url( 'plugin-install.php?tab=search&s=' . urlencode( $s ) ) ) . '">' . __( 'Search for plugins in the WordPress Plugin Directory.' ) . '</a>'; } } elseif ( ! empty( $plugins['all'] ) ) { _e( 'No plugins found.' ); } else { _e( 'No plugins are currently available.' ); } } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | wordpress WP_Plugins_List_Table::get_views(): array WP\_Plugins\_List\_Table::get\_views(): array ============================================= array File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` protected function get_views() { global $totals, $status; $status_links = array(); foreach ( $totals as $type => $count ) { if ( ! $count ) { continue; } switch ( $type ) { case 'all': /* translators: %s: Number of plugins. */ $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'plugins' ); break; case 'active': /* translators: %s: Number of plugins. */ $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count ); break; case 'recently_activated': /* translators: %s: Number of plugins. */ $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count ); break; case 'inactive': /* translators: %s: Number of plugins. */ $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count ); break; case 'mustuse': /* translators: %s: Number of plugins. */ $text = _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $count ); break; case 'dropins': /* translators: %s: Number of plugins. */ $text = _n( 'Drop-in <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $count ); break; case 'paused': /* translators: %s: Number of plugins. */ $text = _n( 'Paused <span class="count">(%s)</span>', 'Paused <span class="count">(%s)</span>', $count ); break; case 'upgrade': /* translators: %s: Number of plugins. */ $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count ); break; case 'auto-update-enabled': /* translators: %s: Number of plugins. */ $text = _n( 'Auto-updates Enabled <span class="count">(%s)</span>', 'Auto-updates Enabled <span class="count">(%s)</span>', $count ); break; case 'auto-update-disabled': /* translators: %s: Number of plugins. */ $text = _n( 'Auto-updates Disabled <span class="count">(%s)</span>', 'Auto-updates Disabled <span class="count">(%s)</span>', $count ); break; } if ( 'search' !== $type ) { $status_links[ $type ] = array( 'url' => add_query_arg( 'plugin_status', $type, 'plugins.php' ), 'label' => sprintf( $text, number_format_i18n( $count ) ), 'current' => $type === $status, ); } } return $this->get_views_links( $status_links ); } ``` | Uses | Description | | --- | --- | | [\_nx()](../../functions/_nx) wp-includes/l10n.php | Translates and retrieves the singular or plural form based on the supplied number, with gettext context. | | [\_n()](../../functions/_n) wp-includes/l10n.php | Translates and retrieves the singular or plural form based on the supplied number. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [number\_format\_i18n()](../../functions/number_format_i18n) wp-includes/functions.php | Converts float number to format based on the locale. |
programming_docs
wordpress WP_Plugins_List_Table::get_sortable_columns(): array WP\_Plugins\_List\_Table::get\_sortable\_columns(): array ========================================================= array File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` protected function get_sortable_columns() { return array(); } ``` wordpress WP_Plugins_List_Table::get_table_classes(): array WP\_Plugins\_List\_Table::get\_table\_classes(): array ====================================================== array File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` protected function get_table_classes() { return array( 'widefat', $this->_args['plural'] ); } ``` wordpress WP_Plugins_List_Table::get_columns(): array WP\_Plugins\_List\_Table::get\_columns(): array =============================================== array File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function get_columns() { global $status; $columns = array( 'cb' => ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ? '<input type="checkbox" />' : '', 'name' => __( 'Plugin' ), 'description' => __( 'Description' ), ); if ( $this->show_autoupdates ) { $columns['auto-updates'] = __( 'Automatic Updates' ); } return $columns; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | wordpress WP_Plugins_List_Table::search_box( string $text, string $input_id ) WP\_Plugins\_List\_Table::search\_box( string $text, string $input\_id ) ======================================================================== Displays the search box. `$text` string Required The `'submit'` button label. `$input_id` string Required ID attribute value for the search input field. File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function search_box( $text, $input_id ) { if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { return; } $input_id = $input_id . '-search-input'; if ( ! empty( $_REQUEST['orderby'] ) ) { echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; } if ( ! empty( $_REQUEST['order'] ) ) { echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; } ?> <p class="search-box"> <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label> <input type="search" id="<?php echo esc_attr( $input_id ); ?>" class="wp-filter-search" name="s" value="<?php _admin_search_query(); ?>" placeholder="<?php esc_attr_e( 'Search installed plugins...' ); ?>" /> <?php submit_button( $text, 'hide-if-js', '', false, array( 'id' => 'search-submit' ) ); ?> </p> <?php } ``` | Uses | Description | | --- | --- | | [\_admin\_search\_query()](../../functions/_admin_search_query) wp-admin/includes/template.php | Displays the search query. | | [submit\_button()](../../functions/submit_button) wp-admin/includes/template.php | Echoes a submit button, with provided text and appropriate class(es). | | [esc\_attr\_e()](../../functions/esc_attr_e) wp-includes/l10n.php | Displays translated text that has been escaped for safe use in an attribute. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Plugins_List_Table::get_bulk_actions(): array WP\_Plugins\_List\_Table::get\_bulk\_actions(): array ===================================================== array File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` protected function get_bulk_actions() { global $status; $actions = array(); if ( 'active' !== $status ) { $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Activate' ) : __( 'Activate' ); } if ( 'inactive' !== $status && 'recent' !== $status ) { $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? __( 'Network Deactivate' ) : __( 'Deactivate' ); } if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { if ( current_user_can( 'update_plugins' ) ) { $actions['update-selected'] = __( 'Update' ); } if ( current_user_can( 'delete_plugins' ) && ( 'active' !== $status ) ) { $actions['delete-selected'] = __( 'Delete' ); } if ( $this->show_autoupdates ) { if ( 'auto-update-enabled' !== $status ) { $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' ); } if ( 'auto-update-disabled' !== $status ) { $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' ); } } } return $actions; } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | wordpress WP_Plugins_List_Table::__construct( array $args = array() ) WP\_Plugins\_List\_Table::\_\_construct( array $args = array() ) ================================================================ Constructor. * [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct): for more information on default arguments. `$args` array Optional An associative array of arguments. Default: `array()` File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function __construct( $args = array() ) { global $status, $page; parent::__construct( array( 'plural' => 'plugins', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); $allowed_statuses = array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused', 'auto-update-enabled', 'auto-update-disabled' ); $status = 'all'; if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], $allowed_statuses, true ) ) { $status = $_REQUEST['plugin_status']; } if ( isset( $_REQUEST['s'] ) ) { $_SERVER['REQUEST_URI'] = add_query_arg( 's', wp_unslash( $_REQUEST['s'] ) ); } $page = $this->get_pagenum(); $this->show_autoupdates = wp_is_auto_update_enabled_for_type( 'plugin' ) && current_user_can( 'update_plugins' ) && ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) && ! in_array( $status, array( 'mustuse', 'dropins' ), true ); } ``` | Uses | Description | | --- | --- | | [wp\_is\_auto\_update\_enabled\_for\_type()](../../functions/wp_is_auto_update_enabled_for_type) wp-admin/includes/update.php | Checks whether auto-updates are enabled. | | [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct) wp-admin/includes/class-wp-list-table.php | Constructor. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Plugins_List_Table::bulk_actions( string $which = '' ) WP\_Plugins\_List\_Table::bulk\_actions( string $which = '' ) ============================================================= `$which` string Optional Default: `''` File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function bulk_actions( $which = '' ) { global $status; if ( in_array( $status, array( 'mustuse', 'dropins' ), true ) ) { return; } parent::bulk_actions( $which ); } ``` | Uses | Description | | --- | --- | | [WP\_List\_Table::bulk\_actions()](../wp_list_table/bulk_actions) wp-admin/includes/class-wp-list-table.php | Displays the bulk actions dropdown. | wordpress WP_Plugins_List_Table::_order_callback( array $plugin_a, array $plugin_b ): int WP\_Plugins\_List\_Table::\_order\_callback( array $plugin\_a, array $plugin\_b ): int ====================================================================================== `$plugin_a` array Required `$plugin_b` array Required int File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function _order_callback( $plugin_a, $plugin_b ) { global $orderby, $order; $a = $plugin_a[ $orderby ]; $b = $plugin_b[ $orderby ]; if ( $a === $b ) { return 0; } if ( 'DESC' === $order ) { return strcasecmp( $b, $a ); } else { return strcasecmp( $a, $b ); } } ``` wordpress WP_Plugins_List_Table::get_primary_column_name(): string WP\_Plugins\_List\_Table::get\_primary\_column\_name(): string ============================================================== Gets the name of the primary column for this specific list table. string Unalterable name for the primary column, in this case, `'name'`. File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` protected function get_primary_column_name() { return 'name'; } ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Plugins_List_Table::_search_callback( array $plugin ): bool WP\_Plugins\_List\_Table::\_search\_callback( array $plugin ): bool =================================================================== `$plugin` array Required bool File: `wp-admin/includes/class-wp-plugins-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-plugins-list-table.php/) ``` public function _search_callback( $plugin ) { global $s; foreach ( $plugin as $value ) { if ( is_string( $value ) && false !== stripos( strip_tags( $value ), urldecode( $s ) ) ) { return true; } } return false; } ``` | Uses | Description | | --- | --- | | [stripos()](../../functions/stripos) wp-includes/class-pop3.php | | wordpress Requests_Exception::getData(): mixed Requests\_Exception::getData(): mixed ===================================== Gives any relevant data mixed File: `wp-includes/Requests/Exception.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/exception.php/) ``` public function getData() { return $this->data; } ``` wordpress Requests_Exception::getType(): string Requests\_Exception::getType(): string ====================================== Like {@see getCode()}, but a string code. string File: `wp-includes/Requests/Exception.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/exception.php/) ``` public function getType() { return $this->type; } ``` wordpress Requests_Exception::__construct( string $message, string $type, mixed $data = null, integer $code ) Requests\_Exception::\_\_construct( string $message, string $type, mixed $data = null, integer $code ) ====================================================================================================== Create a new exception `$message` string Required Exception message `$type` string Required Exception type `$data` mixed Optional Associated data Default: `null` `$code` integer Required Exception numerical code, if applicable File: `wp-includes/Requests/Exception.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/exception.php/) ``` public function __construct($message, $type, $data = null, $code = 0) { parent::__construct($message, $code); $this->type = $type; $this->data = $data; } ``` | Used By | Description | | --- | --- | | [WP\_Http::validate\_redirects()](../wp_http/validate_redirects) wp-includes/class-wp-http.php | Validate redirected URLs. | | [Requests::set\_defaults()](../requests/set_defaults) wp-includes/class-requests.php | Set the default values | | [Requests::parse\_response()](../requests/parse_response) wp-includes/class-requests.php | HTTP response parser | | [Requests::get\_transport()](../requests/get_transport) wp-includes/class-requests.php | Get a working transport | | [Requests\_Utility\_CaseInsensitiveDictionary::offsetSet()](../requests_utility_caseinsensitivedictionary/offsetset) wp-includes/Requests/Utility/CaseInsensitiveDictionary.php | Set the given item | | [Requests\_Exception\_HTTP::\_\_construct()](../requests_exception_http/__construct) wp-includes/Requests/Exception/HTTP.php | Create a new exception | | [Requests\_Response::throw\_for\_status()](../requests_response/throw_for_status) wp-includes/Requests/Response.php | Throws an exception if the request was not successful | | [Requests\_IRI::parse\_iri()](../requests_iri/parse_iri) wp-includes/Requests/IRI.php | Parse an IRI into scheme/authority/path/query/fragment segments | | [Requests\_Proxy\_HTTP::\_\_construct()](../requests_proxy_http/__construct) wp-includes/Requests/Proxy/HTTP.php | Constructor | | [Requests\_Auth\_Basic::\_\_construct()](../requests_auth_basic/__construct) wp-includes/Requests/Auth/Basic.php | Constructor | | [Requests\_Cookie\_Jar::offsetSet()](../requests_cookie_jar/offsetset) wp-includes/Requests/Cookie/Jar.php | Set the given item | | [Requests\_Transport\_cURL::process\_response()](../requests_transport_curl/process_response) wp-includes/Requests/Transport/cURL.php | Process a response | | [Requests\_Transport\_fsockopen::verify\_certificate\_from\_context()](../requests_transport_fsockopen/verify_certificate_from_context) wp-includes/Requests/Transport/fsockopen.php | Verify the certificate against common name and subject alternative names | | [Requests\_Transport\_fsockopen::request()](../requests_transport_fsockopen/request) wp-includes/Requests/Transport/fsockopen.php | Perform a request | | [Requests\_Response\_Headers::offsetSet()](../requests_response_headers/offsetset) wp-includes/Requests/Response/Headers.php | Set the given item | | [Requests\_IDNAEncoder::utf8\_to\_codepoints()](../requests_idnaencoder/utf8_to_codepoints) wp-includes/Requests/IDNAEncoder.php | Convert a UTF-8 string to a UCS-4 codepoint array | | [Requests\_IDNAEncoder::punycode\_encode()](../requests_idnaencoder/punycode_encode) wp-includes/Requests/IDNAEncoder.php | RFC3492-compliant encoder | | [Requests\_IDNAEncoder::digit\_to\_char()](../requests_idnaencoder/digit_to_char) wp-includes/Requests/IDNAEncoder.php | Convert a digit to its respective character | | [Requests\_IDNAEncoder::to\_ascii()](../requests_idnaencoder/to_ascii) wp-includes/Requests/IDNAEncoder.php | Convert a UTF-8 string to an ASCII string using Punycode | wordpress WP_Role::remove_cap( string $cap ) WP\_Role::remove\_cap( string $cap ) ==================================== Removes a capability from a role. `$cap` string Required Capability name. Changing the capabilities of a role is persistent, meaning the removed capability will stay in effect until explicitly granted. This setting is saved to the database (in table wp\_options, field 'wp\_user\_roles'), so you should run this only once, on theme/plugin activation and/or deactivation. File: `wp-includes/class-wp-role.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-role.php/) ``` public function remove_cap( $cap ) { unset( $this->capabilities[ $cap ] ); wp_roles()->remove_cap( $this->name, $cap ); } ``` | Uses | Description | | --- | --- | | [wp\_roles()](../../functions/wp_roles) wp-includes/capabilities.php | Retrieves the global [WP\_Roles](../wp_roles) instance and instantiates it if necessary. | | [WP\_Roles::remove\_cap()](../wp_roles/remove_cap) wp-includes/class-wp-roles.php | Removes a capability from role. | | Version | Description | | --- | --- | | [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. | wordpress WP_Role::add_cap( string $cap, bool $grant = true ) WP\_Role::add\_cap( string $cap, bool $grant = true ) ===================================================== Assign role a capability. `$cap` string Required Capability name. `$grant` bool Optional Whether role has capability privilege. Default: `true` Changing the capabilities of a role is persistent, meaning the added capability will stay in effect until explicitly revoked. This setting is saved to the database (in table wp\_options, field wp\_user\_roles), so it might be better to run this on theme/plugin activation. File: `wp-includes/class-wp-role.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-role.php/) ``` public function add_cap( $cap, $grant = true ) { $this->capabilities[ $cap ] = $grant; wp_roles()->add_cap( $this->name, $cap, $grant ); } ``` | Uses | Description | | --- | --- | | [wp\_roles()](../../functions/wp_roles) wp-includes/capabilities.php | Retrieves the global [WP\_Roles](../wp_roles) instance and instantiates it if necessary. | | [WP\_Roles::add\_cap()](../wp_roles/add_cap) wp-includes/class-wp-roles.php | Adds a capability to role. | | Version | Description | | --- | --- | | [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. | wordpress WP_Role::has_cap( string $cap ): bool WP\_Role::has\_cap( string $cap ): bool ======================================= Determines whether the role has the given capability. `$cap` string Required Capability name. bool Whether the role has the given capability. File: `wp-includes/class-wp-role.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-role.php/) ``` public function has_cap( $cap ) { /** * Filters which capabilities a role has. * * @since 2.0.0 * * @param bool[] $capabilities Array of key/value pairs where keys represent a capability name and boolean values * represent whether the role has that capability. * @param string $cap Capability name. * @param string $name Role name. */ $capabilities = apply_filters( 'role_has_cap', $this->capabilities, $cap, $this->name ); if ( ! empty( $capabilities[ $cap ] ) ) { return $capabilities[ $cap ]; } else { return false; } } ``` [apply\_filters( 'role\_has\_cap', bool[] $capabilities, string $cap, string $name )](../../hooks/role_has_cap) Filters which capabilities a role has. | Uses | Description | | --- | --- | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |
programming_docs
wordpress WP_Role::__construct( string $role, bool[] $capabilities ) WP\_Role::\_\_construct( string $role, bool[] $capabilities ) ============================================================= Constructor – Set up object properties. The list of capabilities must have the key as the name of the capability and the value a boolean of whether it is granted to the role. `$role` string Required Role name. `$capabilities` bool[] Required Array of key/value pairs where keys represent a capability name and boolean values represent whether the role has that capability. File: `wp-includes/class-wp-role.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-role.php/) ``` public function __construct( $role, $capabilities ) { $this->name = $role; $this->capabilities = $capabilities; } ``` | Used By | Description | | --- | --- | | [WP\_Roles::init\_roles()](../wp_roles/init_roles) wp-includes/class-wp-roles.php | Initializes all of the available roles. | | [WP\_Roles::add\_role()](../wp_roles/add_role) wp-includes/class-wp-roles.php | Adds a role name with capabilities to the list. | | Version | Description | | --- | --- | | [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. | wordpress WP_Widget_Media_Audio::get_instance_schema(): array WP\_Widget\_Media\_Audio::get\_instance\_schema(): array ======================================================== Get schema for properties of a widget instance (item). * [WP\_REST\_Controller::get\_item\_schema()](../wp_rest_controller/get_item_schema) * [WP\_REST\_Controller::get\_additional\_fields()](../wp_rest_controller/get_additional_fields) array Schema for properties. File: `wp-includes/widgets/class-wp-widget-media-audio.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-media-audio.php/) ``` public function get_instance_schema() { $schema = array( 'preload' => array( 'type' => 'string', 'enum' => array( 'none', 'auto', 'metadata' ), 'default' => 'none', 'description' => __( 'Preload' ), ), 'loop' => array( 'type' => 'boolean', 'default' => false, 'description' => __( 'Loop' ), ), ); foreach ( wp_get_audio_extensions() as $audio_extension ) { $schema[ $audio_extension ] = array( 'type' => 'string', 'default' => '', 'format' => 'uri', /* translators: %s: Audio extension. */ 'description' => sprintf( __( 'URL to the %s audio source file' ), $audio_extension ), ); } return array_merge( $schema, parent::get_instance_schema() ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget\_Media::get\_instance\_schema()](../wp_widget_media/get_instance_schema) wp-includes/widgets/class-wp-widget-media.php | Get schema for properties of a widget instance (item). | | [wp\_get\_audio\_extensions()](../../functions/wp_get_audio_extensions) wp-includes/media.php | Returns a filtered list of supported audio formats. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_Widget\_Media\_Audio::enqueue\_admin\_scripts()](enqueue_admin_scripts) wp-includes/widgets/class-wp-widget-media-audio.php | Loads the required media files for the media manager and scripts for media widgets. | | [WP\_Widget\_Media\_Audio::render\_media()](render_media) wp-includes/widgets/class-wp-widget-media-audio.php | Render the media on the frontend. | | Version | Description | | --- | --- | | [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | Introduced. | wordpress WP_Widget_Media_Audio::enqueue_admin_scripts() WP\_Widget\_Media\_Audio::enqueue\_admin\_scripts() =================================================== Loads the required media files for the media manager and scripts for media widgets. File: `wp-includes/widgets/class-wp-widget-media-audio.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-media-audio.php/) ``` public function enqueue_admin_scripts() { parent::enqueue_admin_scripts(); wp_enqueue_style( 'wp-mediaelement' ); wp_enqueue_script( 'wp-mediaelement' ); $handle = 'media-audio-widget'; wp_enqueue_script( $handle ); $exported_schema = array(); foreach ( $this->get_instance_schema() as $field => $field_schema ) { $exported_schema[ $field ] = wp_array_slice_assoc( $field_schema, array( 'type', 'default', 'enum', 'minimum', 'format', 'media_prop', 'should_preview_update' ) ); } wp_add_inline_script( $handle, sprintf( 'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;', wp_json_encode( $this->id_base ), wp_json_encode( $exported_schema ) ) ); wp_add_inline_script( $handle, sprintf( ' wp.mediaWidgets.controlConstructors[ %1$s ].prototype.mime_type = %2$s; wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n = _.extend( {}, wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n, %3$s ); ', wp_json_encode( $this->id_base ), wp_json_encode( $this->widget_options['mime_type'] ), wp_json_encode( $this->l10n ) ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget\_Media\_Audio::get\_instance\_schema()](get_instance_schema) wp-includes/widgets/class-wp-widget-media-audio.php | Get schema for properties of a widget instance (item). | | [WP\_Widget\_Media::enqueue\_admin\_scripts()](../wp_widget_media/enqueue_admin_scripts) wp-includes/widgets/class-wp-widget-media.php | Loads the required scripts and styles for the widget control. | | [wp\_add\_inline\_script()](../../functions/wp_add_inline_script) wp-includes/functions.wp-scripts.php | Adds extra code to a registered script. | | [wp\_enqueue\_script()](../../functions/wp_enqueue_script) wp-includes/functions.wp-scripts.php | Enqueue a script. | | [wp\_array\_slice\_assoc()](../../functions/wp_array_slice_assoc) wp-includes/functions.php | Extracts a slice of an array, given a list of keys. | | [wp\_enqueue\_style()](../../functions/wp_enqueue_style) wp-includes/functions.wp-styles.php | Enqueue a CSS stylesheet. | | [wp\_json\_encode()](../../functions/wp_json_encode) wp-includes/functions.php | Encodes a variable into JSON, with some sanity checks. | | Version | Description | | --- | --- | | [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | Introduced. | wordpress WP_Widget_Media_Audio::render_media( array $instance ) WP\_Widget\_Media\_Audio::render\_media( array $instance ) ========================================================== Render the media on the frontend. `$instance` array Required Widget instance props. File: `wp-includes/widgets/class-wp-widget-media-audio.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-media-audio.php/) ``` public function render_media( $instance ) { $instance = array_merge( wp_list_pluck( $this->get_instance_schema(), 'default' ), $instance ); $attachment = null; if ( $this->is_attachment_with_mime_type( $instance['attachment_id'], $this->widget_options['mime_type'] ) ) { $attachment = get_post( $instance['attachment_id'] ); } if ( $attachment ) { $src = wp_get_attachment_url( $attachment->ID ); } else { $src = $instance['url']; } echo wp_audio_shortcode( array_merge( $instance, compact( 'src' ) ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget\_Media\_Audio::get\_instance\_schema()](get_instance_schema) wp-includes/widgets/class-wp-widget-media-audio.php | Get schema for properties of a widget instance (item). | | [wp\_list\_pluck()](../../functions/wp_list_pluck) wp-includes/functions.php | Plucks a certain field out of each object or array in an array. | | [wp\_audio\_shortcode()](../../functions/wp_audio_shortcode) wp-includes/media.php | Builds the Audio shortcode output. | | [wp\_get\_attachment\_url()](../../functions/wp_get_attachment_url) wp-includes/post.php | Retrieves the URL for an attachment. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Version | Description | | --- | --- | | [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | Introduced. | wordpress WP_Widget_Media_Audio::render_control_template_scripts() WP\_Widget\_Media\_Audio::render\_control\_template\_scripts() ============================================================== Render form template scripts. File: `wp-includes/widgets/class-wp-widget-media-audio.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-media-audio.php/) ``` public function render_control_template_scripts() { parent::render_control_template_scripts() ?> <script type="text/html" id="tmpl-wp-media-widget-audio-preview"> <# if ( data.error && 'missing_attachment' === data.error ) { #> <div class="notice notice-error notice-alt notice-missing-attachment"> <p><?php echo $this->l10n['missing_attachment']; ?></p> </div> <# } else if ( data.error ) { #> <div class="notice notice-error notice-alt"> <p><?php _e( 'Unable to preview media due to an unknown error.' ); ?></p> </div> <# } else if ( data.model && data.model.src ) { #> <?php wp_underscore_audio_template(); ?> <# } #> </script> <?php } ``` | Uses | Description | | --- | --- | | [WP\_Widget\_Media::render\_control\_template\_scripts()](../wp_widget_media/render_control_template_scripts) wp-includes/widgets/class-wp-widget-media.php | Render form template scripts. | | [wp\_underscore\_audio\_template()](../../functions/wp_underscore_audio_template) wp-includes/media-template.php | Outputs the markup for a audio tag to be used in an Underscore template when data.model is passed. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | Version | Description | | --- | --- | | [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | Introduced. | wordpress WP_Widget_Media_Audio::__construct() WP\_Widget\_Media\_Audio::\_\_construct() ========================================= Constructor. File: `wp-includes/widgets/class-wp-widget-media-audio.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-media-audio.php/) ``` public function __construct() { parent::__construct( 'media_audio', __( 'Audio' ), array( 'description' => __( 'Displays an audio player.' ), 'mime_type' => 'audio', ) ); $this->l10n = array_merge( $this->l10n, array( 'no_media_selected' => __( 'No audio selected' ), 'add_media' => _x( 'Add Audio', 'label for button in the audio widget' ), 'replace_media' => _x( 'Replace Audio', 'label for button in the audio widget; should preferably not be longer than ~13 characters long' ), 'edit_media' => _x( 'Edit Audio', 'label for button in the audio widget; should preferably not be longer than ~13 characters long' ), 'missing_attachment' => sprintf( /* translators: %s: URL to media library. */ __( 'That audio file cannot be found. Check your <a href="%s">media library</a> and make sure it was not deleted.' ), esc_url( admin_url( 'upload.php' ) ) ), /* translators: %d: Widget count. */ 'media_library_state_multi' => _n_noop( 'Audio Widget (%d)', 'Audio Widget (%d)' ), 'media_library_state_single' => __( 'Audio Widget' ), 'unsupported_file_type' => __( 'Looks like this is not the correct kind of file. Please link to an audio file instead.' ), ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget\_Media::\_\_construct()](../wp_widget_media/__construct) wp-includes/widgets/class-wp-widget-media.php | Constructor. | | [\_n\_noop()](../../functions/_n_noop) wp-includes/l10n.php | Registers plural strings in POT file, but does not translate them. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | Version | Description | | --- | --- | | [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | Introduced. | wordpress WP_Widget_Media_Audio::enqueue_preview_scripts() WP\_Widget\_Media\_Audio::enqueue\_preview\_scripts() ===================================================== Enqueue preview scripts. These scripts normally are enqueued just-in-time when an audio shortcode is used. In the customizer, however, widgets can be dynamically added and rendered via selective refresh, and so it is important to unconditionally enqueue them in case a widget does get added. File: `wp-includes/widgets/class-wp-widget-media-audio.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-media-audio.php/) ``` public function enqueue_preview_scripts() { /** This filter is documented in wp-includes/media.php */ if ( 'mediaelement' === apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ) ) { wp_enqueue_style( 'wp-mediaelement' ); wp_enqueue_script( 'wp-mediaelement' ); } } ``` [apply\_filters( 'wp\_audio\_shortcode\_library', string $library )](../../hooks/wp_audio_shortcode_library) Filters the media library used for the audio shortcode. | Uses | Description | | --- | --- | | [wp\_enqueue\_script()](../../functions/wp_enqueue_script) wp-includes/functions.wp-scripts.php | Enqueue a script. | | [wp\_enqueue\_style()](../../functions/wp_enqueue_style) wp-includes/functions.wp-styles.php | Enqueue a CSS stylesheet. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | Introduced. | wordpress WP_Sitemaps_Provider::get_max_num_pages( string $object_subtype = '' ): int WP\_Sitemaps\_Provider::get\_max\_num\_pages( string $object\_subtype = '' ): int ================================================================================= Gets the max number of pages available for the object type. `$object_subtype` string Optional Object subtype. Default: `''` int Total number of pages. File: `wp-includes/sitemaps/class-wp-sitemaps-provider.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-provider.php/) ``` abstract public function get_max_num_pages( $object_subtype = '' ); ``` | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Provider::get\_sitemap\_type\_data()](get_sitemap_type_data) wp-includes/sitemaps/class-wp-sitemaps-provider.php | Gets data about each sitemap type. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Provider::get_sitemap_type_data(): array[] WP\_Sitemaps\_Provider::get\_sitemap\_type\_data(): array[] =========================================================== Gets data about each sitemap type. array[] Array of sitemap types including object subtype name and number of pages. File: `wp-includes/sitemaps/class-wp-sitemaps-provider.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-provider.php/) ``` public function get_sitemap_type_data() { $sitemap_data = array(); $object_subtypes = $this->get_object_subtypes(); // If there are no object subtypes, include a single sitemap for the // entire object type. if ( empty( $object_subtypes ) ) { $sitemap_data[] = array( 'name' => '', 'pages' => $this->get_max_num_pages(), ); return $sitemap_data; } // Otherwise, include individual sitemaps for every object subtype. foreach ( $object_subtypes as $object_subtype_name => $data ) { $object_subtype_name = (string) $object_subtype_name; $sitemap_data[] = array( 'name' => $object_subtype_name, 'pages' => $this->get_max_num_pages( $object_subtype_name ), ); } return $sitemap_data; } ``` | Uses | Description | | --- | --- | | [WP\_Sitemaps\_Provider::get\_object\_subtypes()](get_object_subtypes) wp-includes/sitemaps/class-wp-sitemaps-provider.php | Returns the list of supported object subtypes exposed by the provider. | | [WP\_Sitemaps\_Provider::get\_max\_num\_pages()](get_max_num_pages) wp-includes/sitemaps/class-wp-sitemaps-provider.php | Gets the max number of pages available for the object type. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Provider::get\_sitemap\_entries()](get_sitemap_entries) wp-includes/sitemaps/class-wp-sitemaps-provider.php | Lists sitemap pages exposed by this provider. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Provider::get_sitemap_entries(): array[] WP\_Sitemaps\_Provider::get\_sitemap\_entries(): array[] ======================================================== Lists sitemap pages exposed by this provider. The returned data is used to populate the sitemap entries of the index. array[] Array of sitemap entries. File: `wp-includes/sitemaps/class-wp-sitemaps-provider.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-provider.php/) ``` public function get_sitemap_entries() { $sitemaps = array(); $sitemap_types = $this->get_sitemap_type_data(); foreach ( $sitemap_types as $type ) { for ( $page = 1; $page <= $type['pages']; $page ++ ) { $sitemap_entry = array( 'loc' => $this->get_sitemap_url( $type['name'], $page ), ); /** * Filters the sitemap entry for the sitemap index. * * @since 5.5.0 * * @param array $sitemap_entry Sitemap entry for the post. * @param string $object_type Object empty name. * @param string $object_subtype Object subtype name. * Empty string if the object type does not support subtypes. * @param int $page Page number of results. */ $sitemap_entry = apply_filters( 'wp_sitemaps_index_entry', $sitemap_entry, $this->object_type, $type['name'], $page ); $sitemaps[] = $sitemap_entry; } } return $sitemaps; } ``` [apply\_filters( 'wp\_sitemaps\_index\_entry', array $sitemap\_entry, string $object\_type, string $object\_subtype, int $page )](../../hooks/wp_sitemaps_index_entry) Filters the sitemap entry for the sitemap index. | Uses | Description | | --- | --- | | [WP\_Sitemaps\_Provider::get\_sitemap\_url()](get_sitemap_url) wp-includes/sitemaps/class-wp-sitemaps-provider.php | Gets the URL of a sitemap entry. | | [WP\_Sitemaps\_Provider::get\_sitemap\_type\_data()](get_sitemap_type_data) wp-includes/sitemaps/class-wp-sitemaps-provider.php | Gets data about each sitemap type. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Provider::get_sitemap_url( string $name, int $page ): string WP\_Sitemaps\_Provider::get\_sitemap\_url( string $name, int $page ): string ============================================================================ Gets the URL of a sitemap entry. `$name` string Required The name of the sitemap. `$page` int Required The page of the sitemap. string The composed URL for a sitemap entry. File: `wp-includes/sitemaps/class-wp-sitemaps-provider.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-provider.php/) ``` public function get_sitemap_url( $name, $page ) { global $wp_rewrite; // Accounts for cases where name is not included, ex: sitemaps-users-1.xml. $params = array_filter( array( 'sitemap' => $this->name, 'sitemap-subtype' => $name, 'paged' => $page, ) ); $basename = sprintf( '/wp-sitemap-%1$s.xml', implode( '-', $params ) ); if ( ! $wp_rewrite->using_permalinks() ) { $basename = '/?' . http_build_query( $params, '', '&' ); } return home_url( $basename ); } ``` | Uses | Description | | --- | --- | | [WP\_Rewrite::using\_permalinks()](../wp_rewrite/using_permalinks) wp-includes/class-wp-rewrite.php | Determines whether permalinks are being used. | | [home\_url()](../../functions/home_url) wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. | | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Provider::get\_sitemap\_entries()](get_sitemap_entries) wp-includes/sitemaps/class-wp-sitemaps-provider.php | Lists sitemap pages exposed by this provider. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |
programming_docs
wordpress WP_Sitemaps_Provider::get_url_list( int $page_num, string $object_subtype = '' ): array[] WP\_Sitemaps\_Provider::get\_url\_list( int $page\_num, string $object\_subtype = '' ): array[] =============================================================================================== Gets a URL list for a sitemap. `$page_num` int Required Page of results. `$object_subtype` string Optional Object subtype name. Default: `''` array[] Array of URL information for a sitemap. File: `wp-includes/sitemaps/class-wp-sitemaps-provider.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-provider.php/) ``` abstract public function get_url_list( $page_num, $object_subtype = '' ); ``` | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Sitemaps_Provider::get_object_subtypes(): array WP\_Sitemaps\_Provider::get\_object\_subtypes(): array ====================================================== Returns the list of supported object subtypes exposed by the provider. array List of object subtypes objects keyed by their name. File: `wp-includes/sitemaps/class-wp-sitemaps-provider.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/class-wp-sitemaps-provider.php/) ``` public function get_object_subtypes() { return array(); } ``` | Used By | Description | | --- | --- | | [WP\_Sitemaps\_Provider::get\_sitemap\_type\_data()](get_sitemap_type_data) wp-includes/sitemaps/class-wp-sitemaps-provider.php | Gets data about each sitemap type. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. | wordpress WP_Privacy_Policy_Content::add( string $plugin_name, string $policy_text ) WP\_Privacy\_Policy\_Content::add( string $plugin\_name, string $policy\_text ) =============================================================================== Add content to the postbox shown when editing the privacy policy. Plugins and themes should suggest text for inclusion in the site’s privacy policy. The suggested text should contain information about any functionality that affects user privacy, and will be shown in the Suggested Privacy Policy Content postbox. Intended for use from `wp_add_privacy_policy_content()`. `$plugin_name` string Required The name of the plugin or theme that is suggesting content for the site's privacy policy. `$policy_text` string Required The suggested content for inclusion in the policy. File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` public static function add( $plugin_name, $policy_text ) { if ( empty( $plugin_name ) || empty( $policy_text ) ) { return; } $data = array( 'plugin_name' => $plugin_name, 'policy_text' => $policy_text, ); if ( ! in_array( $data, self::$policy_content, true ) ) { self::$policy_content[] = $data; } } ``` | Used By | Description | | --- | --- | | [wp\_add\_privacy\_policy\_content()](../../functions/wp_add_privacy_policy_content) wp-admin/includes/plugin.php | Declares a helper function for adding content to the Privacy Policy Guide. | | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Privacy_Policy_Content::get_default_content( bool $description = false, bool $blocks = true ): string WP\_Privacy\_Policy\_Content::get\_default\_content( bool $description = false, bool $blocks = true ): string ============================================================================================================= Return the default suggested privacy policy content. `$description` bool Optional Whether to include the descriptions under the section headings. Default: `false` `$blocks` bool Optional Whether to format the content for the block editor. Default: `true` string The default policy content. File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` public static function get_default_content( $description = false, $blocks = true ) { $suggested_text = '<strong class="privacy-policy-tutorial">' . __( 'Suggested text:' ) . ' </strong>'; $content = ''; $strings = array(); // Start of the suggested privacy policy text. if ( $description ) { $strings[] = '<div class="wp-suggested-text">'; } /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Who we are' ) . '</h2>'; if ( $description ) { /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should note your site URL, as well as the name of the company, organization, or individual behind it, and some accurate contact information.' ) . '</p>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'The amount of information you may be required to show will vary depending on your local or national business regulations. You may, for example, be required to display a physical address, a registered address, or your company registration number.' ) . '</p>'; } else { /* translators: Default privacy policy text. %s: Site URL. */ $strings[] = '<p>' . $suggested_text . sprintf( __( 'Our website address is: %s.' ), get_bloginfo( 'url', 'display' ) ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'What personal data we collect and why we collect it' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should note what personal data you collect from users and site visitors. This may include personal data, such as name, email address, personal account preferences; transactional data, such as purchase information; and technical data, such as information about cookies.' ) . '</p>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'You should also note any collection and retention of sensitive personal data, such as data concerning health.' ) . '</p>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In addition to listing what personal data you collect, you need to note why you collect it. These explanations must note either the legal basis for your data collection and retention or the active consent the user has given.' ) . '</p>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'Personal data is not just created by a user&#8217;s interactions with your site. Personal data is also generated from technical processes such as contact forms, comments, cookies, analytics, and third party embeds.' ) . '</p>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'By default WordPress does not collect any personal data about visitors, and only collects the data shown on the User Profile screen from registered users. However some of your plugins may collect personal data. You should add the relevant information below.' ) . '</p>'; } /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Comments' ) . '</h2>'; if ( $description ) { /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should note what information is captured through comments. We have noted the data which WordPress collects by default.' ) . '</p>'; } else { /* translators: Default privacy policy text. */ $strings[] = '<p>' . $suggested_text . __( 'When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor&#8217;s IP address and browser user agent string to help spam detection.' ) . '</p>'; /* translators: Default privacy policy text. */ $strings[] = '<p>' . __( 'An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your comment, your profile picture is visible to the public in the context of your comment.' ) . '</p>'; } /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Media' ) . '</h2>'; if ( $description ) { /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should note what information may be disclosed by users who can upload media files. All uploaded files are usually publicly accessible.' ) . '</p>'; } else { /* translators: Default privacy policy text. */ $strings[] = '<p>' . $suggested_text . __( 'If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.' ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Contact forms' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'By default, WordPress does not include a contact form. If you use a contact form plugin, use this subsection to note what personal data is captured when someone submits a contact form, and how long you keep it. For example, you may note that you keep contact form submissions for a certain period for customer service purposes, but you do not use the information submitted through them for marketing purposes.' ) . '</p>'; } /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Cookies' ) . '</h2>'; if ( $description ) { /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should list the cookies your web site uses, including those set by your plugins, social media, and analytics. We have provided the cookies which WordPress installs by default.' ) . '</p>'; } else { /* translators: Default privacy policy text. */ $strings[] = '<p>' . $suggested_text . __( 'If you leave a comment on our site you may opt-in to saving your name, email address and website in cookies. These are for your convenience so that you do not have to fill in your details again when you leave another comment. These cookies will last for one year.' ) . '</p>'; /* translators: Default privacy policy text. */ $strings[] = '<p>' . __( 'If you visit our login page, we will set a temporary cookie to determine if your browser accepts cookies. This cookie contains no personal data and is discarded when you close your browser.' ) . '</p>'; /* translators: Default privacy policy text. */ $strings[] = '<p>' . __( 'When you log in, we will also set up several cookies to save your login information and your screen display choices. Login cookies last for two days, and screen options cookies last for a year. If you select &quot;Remember Me&quot;, your login will persist for two weeks. If you log out of your account, the login cookies will be removed.' ) . '</p>'; /* translators: Default privacy policy text. */ $strings[] = '<p>' . __( 'If you edit or publish an article, an additional cookie will be saved in your browser. This cookie includes no personal data and simply indicates the post ID of the article you just edited. It expires after 1 day.' ) . '</p>'; } if ( ! $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Embedded content from other websites' ) . '</h2>'; /* translators: Default privacy policy text. */ $strings[] = '<p>' . $suggested_text . __( 'Articles on this site may include embedded content (e.g. videos, images, articles, etc.). Embedded content from other websites behaves in the exact same way as if the visitor has visited the other website.' ) . '</p>'; /* translators: Default privacy policy text. */ $strings[] = '<p>' . __( 'These websites may collect data about you, use cookies, embed additional third-party tracking, and monitor your interaction with that embedded content, including tracking your interaction with the embedded content if you have an account and are logged in to that website.' ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Analytics' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this subsection you should note what analytics package you use, how users can opt out of analytics tracking, and a link to your analytics provider&#8217;s privacy policy, if any.' ) . '</p>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'By default WordPress does not collect any analytics data. However, many web hosting accounts collect some anonymous analytics data. You may also have installed a WordPress plugin that provides analytics services. In that case, add information from that plugin here.' ) . '</p>'; } /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Who we share your data with' ) . '</h2>'; if ( $description ) { /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should name and list all third party providers with whom you share site data, including partners, cloud-based services, payment processors, and third party service providers, and note what data you share with them and why. Link to their own privacy policies if possible.' ) . '</p>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'By default WordPress does not share any personal data with anyone.' ) . '</p>'; } else { /* translators: Default privacy policy text. */ $strings[] = '<p>' . $suggested_text . __( 'If you request a password reset, your IP address will be included in the reset email.' ) . '</p>'; } /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'How long we retain your data' ) . '</h2>'; if ( $description ) { /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain how long you retain personal data collected or processed by the web site. While it is your responsibility to come up with the schedule of how long you keep each dataset for and why you keep it, that information does need to be listed here. For example, you may want to say that you keep contact form entries for six months, analytics records for a year, and customer purchase records for ten years.' ) . '</p>'; } else { /* translators: Default privacy policy text. */ $strings[] = '<p>' . $suggested_text . __( 'If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognize and approve any follow-up comments automatically instead of holding them in a moderation queue.' ) . '</p>'; /* translators: Default privacy policy text. */ $strings[] = '<p>' . __( 'For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.' ) . '</p>'; } /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'What rights you have over your data' ) . '</h2>'; if ( $description ) { /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain what rights your users have over their data and how they can invoke those rights.' ) . '</p>'; } else { /* translators: Default privacy policy text. */ $strings[] = '<p>' . $suggested_text . __( 'If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.' ) . '</p>'; } /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Where your data is sent' ) . '</h2>'; if ( $description ) { /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should list all transfers of your site data outside the European Union and describe the means by which that data is safeguarded to European data protection standards. This could include your web hosting, cloud storage, or other third party services.' ) . '</p>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'European data protection law requires data about European residents which is transferred outside the European Union to be safeguarded to the same standards as if the data was in Europe. So in addition to listing where data goes, you should describe how you ensure that these standards are met either by yourself or by your third party providers, whether that is through an agreement such as Privacy Shield, model clauses in your contracts, or binding corporate rules.' ) . '</p>'; } else { /* translators: Default privacy policy text. */ $strings[] = '<p>' . $suggested_text . __( 'Visitor comments may be checked through an automated spam detection service.' ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Contact information' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should provide a contact method for privacy-specific concerns. If you are required to have a Data Protection Officer, list their name and full contact details here as well.' ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Additional information' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'If you use your site for commercial purposes and you engage in more complex collection or processing of personal data, you should note the following information in your privacy policy in addition to the information we have already discussed.' ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'How we protect your data' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain what measures you have taken to protect your users&#8217; data. This could include technical measures such as encryption; security measures such as two factor authentication; and measures such as staff training in data protection. If you have carried out a Privacy Impact Assessment, you can mention it here too.' ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'What data breach procedures we have in place' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'In this section you should explain what procedures you have in place to deal with data breaches, either potential or real, such as internal reporting systems, contact mechanisms, or bug bounties.' ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'What third parties we receive data from' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'If your web site receives data about users from third parties, including advertisers, this information must be included within the section of your privacy policy dealing with third party data.' ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'What automated decision making and/or profiling we do with user data' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'If your web site provides a service which includes automated decision making - for example, allowing customers to apply for credit, or aggregating their data into an advertising profile - you must note that this is taking place, and include information about how that information is used, what decisions are made with that aggregated data, and what rights users have over decisions made without human intervention.' ) . '</p>'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '<h2>' . __( 'Industry regulatory disclosure requirements' ) . '</h2>'; /* translators: Privacy policy tutorial. */ $strings[] = '<p class="privacy-policy-tutorial">' . __( 'If you are a member of a regulated industry, or if you are subject to additional privacy laws, you may be required to disclose that information here.' ) . '</p>'; $strings[] = '</div>'; } if ( $blocks ) { foreach ( $strings as $key => $string ) { if ( 0 === strpos( $string, '<p>' ) ) { $strings[ $key ] = '<!-- wp:paragraph -->' . $string . '<!-- /wp:paragraph -->'; } if ( 0 === strpos( $string, '<h2>' ) ) { $strings[ $key ] = '<!-- wp:heading -->' . $string . '<!-- /wp:heading -->'; } } } $content = implode( '', $strings ); // End of the suggested privacy policy text. /** * Filters the default content suggested for inclusion in a privacy policy. * * @since 4.9.6 * @since 5.0.0 Added the `$strings`, `$description`, and `$blocks` parameters. * @deprecated 5.7.0 Use wp_add_privacy_policy_content() instead. * * @param string $content The default policy content. * @param string[] $strings An array of privacy policy content strings. * @param bool $description Whether policy descriptions should be included. * @param bool $blocks Whether the content should be formatted for the block editor. */ return apply_filters_deprecated( 'wp_get_default_privacy_policy_content', array( $content, $strings, $description, $blocks ), '5.7.0', 'wp_add_privacy_policy_content()' ); } ``` [apply\_filters\_deprecated( 'wp\_get\_default\_privacy\_policy\_content', string $content, string[] $strings, bool $description, bool $blocks )](../../hooks/wp_get_default_privacy_policy_content) Filters the default content suggested for inclusion in a privacy policy. | Uses | Description | | --- | --- | | [apply\_filters\_deprecated()](../../functions/apply_filters_deprecated) wp-includes/plugin.php | Fires functions attached to a deprecated filter hook. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | Used By | Description | | --- | --- | | [WP\_Privacy\_Policy\_Content::add\_suggested\_content()](add_suggested_content) wp-admin/includes/class-wp-privacy-policy-content.php | Add the suggested privacy policy text to the policy postbox. | | [wp\_install\_defaults()](../../functions/wp_install_defaults) wp-admin/includes/upgrade.php | Creates the initial content for a newly-installed site. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Added the `$blocks` parameter. | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. |
programming_docs
wordpress WP_Privacy_Policy_Content::_policy_page_updated( int $post_id ) WP\_Privacy\_Policy\_Content::\_policy\_page\_updated( int $post\_id ) ====================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Update the cached policy info when the policy page is updated. `$post_id` int Required The ID of the updated post. File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` public static function _policy_page_updated( $post_id ) { $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); if ( ! $policy_page_id || $policy_page_id !== (int) $post_id ) { return; } // Remove updated|removed status. $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); $done = array(); $update_cache = false; foreach ( $old as $old_key => $old_data ) { if ( ! empty( $old_data['removed'] ) ) { // Remove the old policy text. $update_cache = true; continue; } if ( ! empty( $old_data['updated'] ) ) { // 'updated' is now 'added'. $done[] = array( 'plugin_name' => $old_data['plugin_name'], 'policy_text' => $old_data['policy_text'], 'added' => $old_data['updated'], ); $update_cache = true; } else { $done[] = $old_data; } } if ( $update_cache ) { delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); // Update the cache. foreach ( $done as $data ) { add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); } } } ``` | Uses | Description | | --- | --- | | [delete\_post\_meta()](../../functions/delete_post_meta) wp-includes/post.php | Deletes a post meta field for the given post ID. | | [add\_post\_meta()](../../functions/add_post_meta) wp-includes/post.php | Adds a meta field to the given post. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [get\_post\_meta()](../../functions/get_post_meta) wp-includes/post.php | Retrieves a post meta field for the given post ID. | | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Privacy_Policy_Content::get_suggested_policy_text(): array WP\_Privacy\_Policy\_Content::get\_suggested\_policy\_text(): array =================================================================== Check for updated, added or removed privacy policy information from plugins. Caches the current info in post\_meta of the policy page. array The privacy policy text/information added by core and plugins. File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` public static function get_suggested_policy_text() { $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); $checked = array(); $time = time(); $update_cache = false; $new = self::$policy_content; $old = array(); if ( $policy_page_id ) { $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); } // Check for no-changes and updates. foreach ( $new as $new_key => $new_data ) { foreach ( $old as $old_key => $old_data ) { $found = false; if ( $new_data['policy_text'] === $old_data['policy_text'] ) { // Use the new plugin name in case it was changed, translated, etc. if ( $old_data['plugin_name'] !== $new_data['plugin_name'] ) { $old_data['plugin_name'] = $new_data['plugin_name']; $update_cache = true; } // A plugin was re-activated. if ( ! empty( $old_data['removed'] ) ) { unset( $old_data['removed'] ); $old_data['added'] = $time; $update_cache = true; } $checked[] = $old_data; $found = true; } elseif ( $new_data['plugin_name'] === $old_data['plugin_name'] ) { // The info for the policy was updated. $checked[] = array( 'plugin_name' => $new_data['plugin_name'], 'policy_text' => $new_data['policy_text'], 'updated' => $time, ); $found = true; $update_cache = true; } if ( $found ) { unset( $new[ $new_key ], $old[ $old_key ] ); continue 2; } } } if ( ! empty( $new ) ) { // A plugin was activated. foreach ( $new as $new_data ) { if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) { $new_data['added'] = $time; $checked[] = $new_data; } } $update_cache = true; } if ( ! empty( $old ) ) { // A plugin was deactivated. foreach ( $old as $old_data ) { if ( ! empty( $old_data['plugin_name'] ) && ! empty( $old_data['policy_text'] ) ) { $data = array( 'plugin_name' => $old_data['plugin_name'], 'policy_text' => $old_data['policy_text'], 'removed' => $time, ); $checked[] = $data; } } $update_cache = true; } if ( $update_cache && $policy_page_id ) { delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); // Update the cache. foreach ( $checked as $data ) { add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); } } return $checked; } ``` | Uses | Description | | --- | --- | | [delete\_post\_meta()](../../functions/delete_post_meta) wp-includes/post.php | Deletes a post meta field for the given post ID. | | [add\_post\_meta()](../../functions/add_post_meta) wp-includes/post.php | Adds a meta field to the given post. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [get\_post\_meta()](../../functions/get_post_meta) wp-includes/post.php | Retrieves a post meta field for the given post ID. | | Used By | Description | | --- | --- | | [WP\_Privacy\_Policy\_Content::privacy\_policy\_guide()](privacy_policy_guide) wp-admin/includes/class-wp-privacy-policy-content.php | Output the privacy policy guide together with content from the theme and plugins. | | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Privacy_Policy_Content::privacy_policy_guide() WP\_Privacy\_Policy\_Content::privacy\_policy\_guide() ====================================================== Output the privacy policy guide together with content from the theme and plugins. File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` public static function privacy_policy_guide() { $content_array = self::get_suggested_policy_text(); $content = ''; $date_format = __( 'F j, Y' ); foreach ( $content_array as $section ) { $class = ''; $meta = ''; $removed = ''; if ( ! empty( $section['removed'] ) ) { $badge_class = ' red'; $date = date_i18n( $date_format, $section['removed'] ); /* translators: %s: Date of plugin deactivation. */ $badge_title = sprintf( __( 'Removed %s.' ), $date ); /* translators: %s: Date of plugin deactivation. */ $removed = __( 'You deactivated this plugin on %s and may no longer need this policy.' ); $removed = '<div class="notice notice-info inline"><p>' . sprintf( $removed, $date ) . '</p></div>'; } elseif ( ! empty( $section['updated'] ) ) { $badge_class = ' blue'; $date = date_i18n( $date_format, $section['updated'] ); /* translators: %s: Date of privacy policy text update. */ $badge_title = sprintf( __( 'Updated %s.' ), $date ); } $plugin_name = esc_html( $section['plugin_name'] ); $sanitized_policy_name = sanitize_title_with_dashes( $plugin_name ); ?> <h4 class="privacy-settings-accordion-heading"> <button aria-expanded="false" class="privacy-settings-accordion-trigger" aria-controls="privacy-settings-accordion-block-<?php echo $sanitized_policy_name; ?>" type="button"> <span class="title"><?php echo $plugin_name; ?></span> <?php if ( ! empty( $section['removed'] ) || ! empty( $section['updated'] ) ) : ?> <span class="badge <?php echo $badge_class; ?>"> <?php echo $badge_title; ?></span> <?php endif; ?> <span class="icon"></span> </button> </h4> <div id="privacy-settings-accordion-block-<?php echo $sanitized_policy_name; ?>" class="privacy-settings-accordion-panel privacy-text-box-body" hidden="hidden"> <?php echo $removed; echo $section['policy_text']; ?> <?php if ( empty( $section['removed'] ) ) : ?> <div class="privacy-settings-accordion-actions"> <span class="success" aria-hidden="true"><?php _e( 'Copied!' ); ?></span> <button type="button" class="privacy-text-copy button"> <span aria-hidden="true"><?php _e( 'Copy suggested policy text to clipboard' ); ?></span> <span class="screen-reader-text"> <?php /* translators: %s: Plugin name. */ printf( __( 'Copy suggested policy text from %s.' ), $plugin_name ); ?> </span> </button> </div> <?php endif; ?> </div> <?php } } ``` | Uses | Description | | --- | --- | | [WP\_Privacy\_Policy\_Content::get\_suggested\_policy\_text()](get_suggested_policy_text) wp-admin/includes/class-wp-privacy-policy-content.php | Check for updated, added or removed privacy policy information from plugins. | | [sanitize\_title\_with\_dashes()](../../functions/sanitize_title_with_dashes) wp-includes/formatting.php | Sanitizes a title, replacing whitespace and a few other characters with dashes. | | [date\_i18n()](../../functions/date_i18n) wp-includes/functions.php | Retrieves the date in localized format, based on a sum of Unix timestamp and timezone offset in seconds. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Privacy_Policy_Content::policy_text_changed_notice() WP\_Privacy\_Policy\_Content::policy\_text\_changed\_notice() ============================================================= Output a warning when some privacy info has changed. File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` public static function policy_text_changed_notice() { global $post; $screen = get_current_screen()->id; if ( 'privacy' !== $screen ) { return; } ?> <div class="policy-text-updated notice notice-warning is-dismissible"> <p> <?php printf( /* translators: %s: Privacy Policy Guide URL. */ __( 'The suggested privacy policy text has changed. Please <a href="%s">review the guide</a> and update your privacy policy.' ), esc_url( admin_url( 'privacy-policy-guide.php?tab=policyguide' ) ) ); ?> </p> </div> <?php } ``` | Uses | Description | | --- | --- | | [get\_current\_screen()](../../functions/get_current_screen) wp-admin/includes/screen.php | Get the current screen object | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Privacy_Policy_Content::notice( WP_Post|null $post = null ) WP\_Privacy\_Policy\_Content::notice( WP\_Post|null $post = null ) ================================================================== Add a notice with a link to the guide when editing the privacy policy page. `$post` [WP\_Post](../wp_post)|null Optional The currently edited post. Default: `null` File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` public static function notice( $post = null ) { if ( is_null( $post ) ) { global $post; } else { $post = get_post( $post ); } if ( ! ( $post instanceof WP_Post ) ) { return; } if ( ! current_user_can( 'manage_privacy_options' ) ) { return; } $current_screen = get_current_screen(); $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); if ( 'post' !== $current_screen->base || $policy_page_id !== $post->ID ) { return; } $message = __( 'Need help putting together your new Privacy Policy page? Check out our guide for recommendations on what content to include, along with policies suggested by your plugins and theme.' ); $url = esc_url( admin_url( 'options-privacy.php?tab=policyguide' ) ); $label = __( 'View Privacy Policy Guide.' ); if ( get_current_screen()->is_block_editor() ) { wp_enqueue_script( 'wp-notices' ); $action = array( 'url' => $url, 'label' => $label, ); wp_add_inline_script( 'wp-notices', sprintf( 'wp.data.dispatch( "core/notices" ).createWarningNotice( "%s", { actions: [ %s ], isDismissible: false } )', $message, wp_json_encode( $action ) ), 'after' ); } else { ?> <div class="notice notice-warning inline wp-pp-notice"> <p> <?php echo $message; printf( ' <a href="%s" target="_blank">%s <span class="screen-reader-text">%s</span></a>', $url, $label, /* translators: Accessibility text. */ __( '(opens in a new tab)' ) ); ?> </p> </div> <?php } } ``` | Uses | Description | | --- | --- | | [WP\_Screen::is\_block\_editor()](../wp_screen/is_block_editor) wp-admin/includes/class-wp-screen.php | Sets or returns whether the block editor is loading on the current screen. | | [wp\_add\_inline\_script()](../../functions/wp_add_inline_script) wp-includes/functions.wp-scripts.php | Adds extra code to a registered script. | | [get\_current\_screen()](../../functions/get_current_screen) wp-admin/includes/screen.php | Get the current screen object | | [wp\_enqueue\_script()](../../functions/wp_enqueue_script) wp-includes/functions.wp-scripts.php | Enqueue a script. | | [wp\_json\_encode()](../../functions/wp_json_encode) wp-includes/functions.php | Encodes a variable into JSON, with some sanity checks. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | The `$post` parameter was made optional. | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Privacy_Policy_Content::text_change_check() WP\_Privacy\_Policy\_Content::text\_change\_check() =================================================== Quick check if any privacy info has changed. File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` public static function text_change_check() { $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); // The site doesn't have a privacy policy. if ( empty( $policy_page_id ) ) { return false; } if ( ! current_user_can( 'edit_post', $policy_page_id ) ) { return false; } $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); // Updates are not relevant if the user has not reviewed any suggestions yet. if ( empty( $old ) ) { return false; } $cached = get_option( '_wp_suggested_policy_text_has_changed' ); /* * When this function is called before `admin_init`, `self::$policy_content` * has not been populated yet, so use the cached result from the last * execution instead. */ if ( ! did_action( 'admin_init' ) ) { return 'changed' === $cached; } $new = self::$policy_content; // Remove the extra values added to the meta. foreach ( $old as $key => $data ) { if ( ! is_array( $data ) || ! empty( $data['removed'] ) ) { unset( $old[ $key ] ); continue; } $old[ $key ] = array( 'plugin_name' => $data['plugin_name'], 'policy_text' => $data['policy_text'], ); } // Normalize the order of texts, to facilitate comparison. sort( $old ); sort( $new ); // The == operator (equal, not identical) was used intentionally. // See http://php.net/manual/en/language.operators.array.php if ( $new != $old ) { // A plugin was activated or deactivated, or some policy text has changed. // Show a notice on the relevant screens to inform the admin. add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) ); $state = 'changed'; } else { $state = 'not-changed'; } // Cache the result for use before `admin_init` (see above). if ( $cached !== $state ) { update_option( '_wp_suggested_policy_text_has_changed', $state ); } return 'changed' === $state; } ``` | Uses | Description | | --- | --- | | [did\_action()](../../functions/did_action) wp-includes/plugin.php | Retrieves the number of times an action has been fired during the current request. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [update\_option()](../../functions/update_option) wp-includes/option.php | Updates the value of an option that was already added. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [get\_post\_meta()](../../functions/get_post_meta) wp-includes/post.php | Retrieves a post meta field for the given post ID. | | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Privacy_Policy_Content::add_suggested_content() WP\_Privacy\_Policy\_Content::add\_suggested\_content() ======================================================= Add the suggested privacy policy text to the policy postbox. File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` public static function add_suggested_content() { $content = self::get_default_content( false, false ); wp_add_privacy_policy_content( __( 'WordPress' ), $content ); } ``` | Uses | Description | | --- | --- | | [WP\_Privacy\_Policy\_Content::get\_default\_content()](get_default_content) wp-admin/includes/class-wp-privacy-policy-content.php | Return the default suggested privacy policy content. | | [wp\_add\_privacy\_policy\_content()](../../functions/wp_add_privacy_policy_content) wp-admin/includes/plugin.php | Declares a helper function for adding content to the Privacy Policy Guide. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. |
programming_docs
wordpress WP_Privacy_Policy_Content::__construct() WP\_Privacy\_Policy\_Content::\_\_construct() ============================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Constructor File: `wp-admin/includes/class-wp-privacy-policy-content.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-policy-content.php/) ``` private function __construct() {} ``` | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Widget_Meta::form( array $instance ) WP\_Widget\_Meta::form( array $instance ) ========================================= Outputs the settings form for the Meta widget. `$instance` array Required Current settings. File: `wp-includes/widgets/class-wp-widget-meta.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-meta.php/) ``` public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /> </p> <?php } ``` | Uses | Description | | --- | --- | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Meta::update( array $new_instance, array $old_instance ): array WP\_Widget\_Meta::update( array $new\_instance, array $old\_instance ): array ============================================================================= Handles updating settings for the current Meta widget instance. `$new_instance` array Required New settings for this instance as input by the user via [WP\_Widget::form()](../wp_widget/form). `$old_instance` array Required Old settings for this instance. array Updated settings to save. File: `wp-includes/widgets/class-wp-widget-meta.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-meta.php/) ``` public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = sanitize_text_field( $new_instance['title'] ); return $instance; } ``` | Uses | Description | | --- | --- | | [sanitize\_text\_field()](../../functions/sanitize_text_field) wp-includes/formatting.php | Sanitizes a string from user input or from the database. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Meta::__construct() WP\_Widget\_Meta::\_\_construct() ================================= Sets up a new Meta widget instance. File: `wp-includes/widgets/class-wp-widget-meta.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-meta.php/) ``` public function __construct() { $widget_ops = array( 'classname' => 'widget_meta', 'description' => __( 'Login, RSS, &amp; WordPress.org links.' ), 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, ); parent::__construct( 'meta', __( 'Meta' ), $widget_ops ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget::\_\_construct()](../wp_widget/__construct) wp-includes/class-wp-widget.php | PHP5 constructor. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Meta::widget( array $args, array $instance ) WP\_Widget\_Meta::widget( array $args, array $instance ) ======================================================== Outputs the content for the current Meta widget instance. `$args` array Required Display arguments including `'before_title'`, `'after_title'`, `'before_widget'`, and `'after_widget'`. `$instance` array Required Settings for the current Meta widget instance. File: `wp-includes/widgets/class-wp-widget-meta.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-meta.php/) ``` public function widget( $args, $instance ) { $default_title = __( 'Meta' ); $title = ! empty( $instance['title'] ) ? $instance['title'] : $default_title; /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml'; /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */ $format = apply_filters( 'navigation_widgets_format', $format ); if ( 'html5' === $format ) { // The title may be filtered: Strip out HTML and make sure the aria-label is never empty. $title = trim( strip_tags( $title ) ); $aria_label = $title ? $title : $default_title; echo '<nav aria-label="' . esc_attr( $aria_label ) . '">'; } ?> <ul> <?php wp_register(); ?> <li><?php wp_loginout(); ?></li> <li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e( 'Entries feed' ); ?></a></li> <li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e( 'Comments feed' ); ?></a></li> <?php /** * Filters the "WordPress.org" list item HTML in the Meta widget. * * @since 3.6.0 * @since 4.9.0 Added the `$instance` parameter. * * @param string $html Default HTML for the WordPress.org list item. * @param array $instance Array of settings for the current widget. */ echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%1$s">%2$s</a></li>', esc_url( __( 'https://wordpress.org/' ) ), __( 'WordPress.org' ) ), $instance ); wp_meta(); ?> </ul> <?php if ( 'html5' === $format ) { echo '</nav>'; } echo $args['after_widget']; } ``` [apply\_filters( 'navigation\_widgets\_format', string $format )](../../hooks/navigation_widgets_format) Filters the HTML format of widgets with navigation links. [apply\_filters( 'widget\_meta\_poweredby', string $html, array $instance )](../../hooks/widget_meta_poweredby) Filters the “WordPress.org” list item HTML in the Meta widget. [apply\_filters( 'widget\_title', string $title, array $instance, mixed $id\_base )](../../hooks/widget_title) Filters the widget title. | Uses | Description | | --- | --- | | [wp\_meta()](../../functions/wp_meta) wp-includes/general-template.php | Theme container function for the ‘wp\_meta’ action. | | [wp\_register()](../../functions/wp_register) wp-includes/general-template.php | Displays the Registration or Admin link. | | [wp\_loginout()](../../functions/wp_loginout) wp-includes/general-template.php | Displays the Log In/Out link. | | [current\_theme\_supports()](../../functions/current_theme_supports) wp-includes/theme.php | Checks a theme’s support for a given feature. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Block_Editor_Context::__construct( array $settings = array() ) WP\_Block\_Editor\_Context::\_\_construct( array $settings = array() ) ====================================================================== Constructor. Populates optional properties for a given block editor context. `$settings` array Optional The list of optional settings to expose in a given context. Default: `array()` File: `wp-includes/class-wp-block-editor-context.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-block-editor-context.php/) ``` public function __construct( array $settings = array() ) { if ( isset( $settings['name'] ) ) { $this->name = $settings['name']; } if ( isset( $settings['post'] ) ) { $this->post = $settings['post']; } } ``` | Used By | Description | | --- | --- | | [get\_block\_categories()](../../functions/get_block_categories) wp-includes/block-editor.php | Returns all the categories for block types that will be shown in the block editor. | | [WP\_Customize\_Widgets::enqueue\_scripts()](../wp_customize_widgets/enqueue_scripts) wp-includes/class-wp-customize-widgets.php | Enqueues scripts and styles for Customizer panel and export data to JavaScript. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::check_read_sidebar_permission( string $sidebar_id ): bool WP\_REST\_Widgets\_Controller::check\_read\_sidebar\_permission( string $sidebar\_id ): bool ============================================================================================ Checks if a sidebar can be read publicly. `$sidebar_id` string Required The sidebar ID. bool Whether the sidebar can be read. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` protected function check_read_sidebar_permission( $sidebar_id ) { $sidebar = wp_get_sidebar( $sidebar_id ); return ! empty( $sidebar['show_in_rest'] ); } ``` | Uses | Description | | --- | --- | | [wp\_get\_sidebar()](../../functions/wp_get_sidebar) wp-includes/widgets.php | Retrieves the registered sidebar with the given ID. | | Used By | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::get\_items\_permissions\_check()](get_items_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a given request has access to get widgets. | | [WP\_REST\_Widgets\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Retrieves a collection of widgets. | | [WP\_REST\_Widgets\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a given request has access to get a widget. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::get_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Widgets\_Controller::get\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ==================================================================================================== Gets an individual widget. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function get_item( $request ) { $this->retrieve_widgets(); $widget_id = $request['id']; $sidebar_id = wp_find_widgets_sidebar( $widget_id ); if ( is_null( $sidebar_id ) ) { return new WP_Error( 'rest_widget_not_found', __( 'No widget was found with that id.' ), array( 'status' => 404 ) ); } return $this->prepare_item_for_response( compact( 'widget_id', 'sidebar_id' ), $request ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::retrieve\_widgets()](retrieve_widgets) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Looks for “lost” widgets once per request. | | [WP\_REST\_Widgets\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Prepares the widget for the REST response. | | [wp\_find\_widgets\_sidebar()](../../functions/wp_find_widgets_sidebar) wp-includes/widgets.php | Finds the sidebar that a given widget belongs to. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::prepare_item_for_response( array $item, WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Widgets\_Controller::prepare\_item\_for\_response( array $item, WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ==================================================================================================================================== Prepares the widget for the REST response. `$item` array Required An array containing a widget\_id and sidebar\_id. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request object. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function prepare_item_for_response( $item, $request ) { global $wp_widget_factory, $wp_registered_widgets; $widget_id = $item['widget_id']; $sidebar_id = $item['sidebar_id']; if ( ! isset( $wp_registered_widgets[ $widget_id ] ) ) { return new WP_Error( 'rest_invalid_widget', __( 'The requested widget is invalid.' ), array( 'status' => 500 ) ); } $widget = $wp_registered_widgets[ $widget_id ]; $parsed_id = wp_parse_widget_id( $widget_id ); $fields = $this->get_fields_for_response( $request ); $prepared = array( 'id' => $widget_id, 'id_base' => $parsed_id['id_base'], 'sidebar' => $sidebar_id, 'rendered' => '', 'rendered_form' => null, 'instance' => null, ); if ( rest_is_field_included( 'rendered', $fields ) && 'wp_inactive_widgets' !== $sidebar_id ) { $prepared['rendered'] = trim( wp_render_widget( $widget_id, $sidebar_id ) ); } if ( rest_is_field_included( 'rendered_form', $fields ) ) { $rendered_form = wp_render_widget_control( $widget_id ); if ( ! is_null( $rendered_form ) ) { $prepared['rendered_form'] = trim( $rendered_form ); } } if ( rest_is_field_included( 'instance', $fields ) ) { $widget_object = $wp_widget_factory->get_widget_object( $parsed_id['id_base'] ); if ( $widget_object && isset( $parsed_id['number'] ) ) { $all_instances = $widget_object->get_settings(); $instance = $all_instances[ $parsed_id['number'] ]; $serialized_instance = serialize( $instance ); $prepared['instance']['encoded'] = base64_encode( $serialized_instance ); $prepared['instance']['hash'] = wp_hash( $serialized_instance ); if ( ! empty( $widget_object->widget_options['show_instance_in_rest'] ) ) { // Use new stdClass so that JSON result is {} and not []. $prepared['instance']['raw'] = empty( $instance ) ? new stdClass : $instance; } } } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $prepared = $this->add_additional_fields_to_object( $prepared, $request ); $prepared = $this->filter_response_by_context( $prepared, $context ); $response = rest_ensure_response( $prepared ); if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $response->add_links( $this->prepare_links( $prepared ) ); } /** * Filters the REST API response for a widget. * * @since 5.8.0 * * @param WP_REST_Response|WP_Error $response The response object, or WP_Error object on failure. * @param array $widget The registered widget data. * @param WP_REST_Request $request Request used to generate the response. */ return apply_filters( 'rest_prepare_widget', $response, $widget, $request ); } ``` [apply\_filters( 'rest\_prepare\_widget', WP\_REST\_Response|WP\_Error $response, array $widget, WP\_REST\_Request $request )](../../hooks/rest_prepare_widget) Filters the REST API response for a widget. | Uses | Description | | --- | --- | | [WP\_Widget\_Factory::get\_widget\_object()](../wp_widget_factory/get_widget_object) wp-includes/class-wp-widget-factory.php | Returns the registered [WP\_Widget](../wp_widget) object for the given widget type. | | [WP\_REST\_Widgets\_Controller::prepare\_links()](prepare_links) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Prepares links for the widget. | | [wp\_render\_widget()](../../functions/wp_render_widget) wp-includes/widgets.php | Calls the render callback of a widget and returns the output. | | [wp\_render\_widget\_control()](../../functions/wp_render_widget_control) wp-includes/widgets.php | Calls the control callback of a widget and returns the output. | | [wp\_parse\_widget\_id()](../../functions/wp_parse_widget_id) wp-includes/widgets.php | Converts a widget ID into its id\_base and number components. | | [rest\_is\_field\_included()](../../functions/rest_is_field_included) wp-includes/rest-api.php | Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body. | | [wp\_hash()](../../functions/wp_hash) wp-includes/pluggable.php | Gets hash of given string. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Retrieves a collection of widgets. | | [WP\_REST\_Widgets\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Gets an individual widget. | | [WP\_REST\_Widgets\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Creates a widget. | | [WP\_REST\_Widgets\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Updates an existing widget. | | [WP\_REST\_Widgets\_Controller::delete\_item()](delete_item) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Deletes a widget. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |
programming_docs
wordpress WP_REST_Widgets_Controller::prepare_links( array $prepared ): array WP\_REST\_Widgets\_Controller::prepare\_links( array $prepared ): array ======================================================================= Prepares links for the widget. `$prepared` array Required Widget. array Links for the given widget. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` protected function prepare_links( $prepared ) { $id_base = ! empty( $prepared['id_base'] ) ? $prepared['id_base'] : $prepared['id']; return array( 'self' => array( 'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $prepared['id'] ) ), ), 'collection' => array( 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), ), 'about' => array( 'href' => rest_url( sprintf( 'wp/v2/widget-types/%s', $id_base ) ), 'embeddable' => true, ), 'https://api.w.org/sidebar' => array( 'href' => rest_url( sprintf( 'wp/v2/sidebars/%s/', $prepared['sidebar'] ) ), ), ); } ``` | Uses | Description | | --- | --- | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | Used By | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Prepares the widget for the REST response. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Widgets\_Controller::get\_items( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ===================================================================================================== Retrieves a collection of widgets. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function get_items( $request ) { $this->retrieve_widgets(); $prepared = array(); $permissions_check = $this->permissions_check( $request ); foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) { if ( isset( $request['sidebar'] ) && $sidebar_id !== $request['sidebar'] ) { continue; } if ( is_wp_error( $permissions_check ) && ! $this->check_read_sidebar_permission( $sidebar_id ) ) { continue; } foreach ( $widget_ids as $widget_id ) { $response = $this->prepare_item_for_response( compact( 'sidebar_id', 'widget_id' ), $request ); if ( ! is_wp_error( $response ) ) { $prepared[] = $this->prepare_response_for_collection( $response ); } } } return new WP_REST_Response( $prepared ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::retrieve\_widgets()](retrieve_widgets) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Looks for “lost” widgets once per request. | | [WP\_REST\_Widgets\_Controller::check\_read\_sidebar\_permission()](check_read_sidebar_permission) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a sidebar can be read publicly. | | [WP\_REST\_Widgets\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Prepares the widget for the REST response. | | [WP\_REST\_Widgets\_Controller::permissions\_check()](permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Performs a permissions check for managing widgets. | | [wp\_get\_sidebars\_widgets()](../../functions/wp_get_sidebars_widgets) wp-includes/widgets.php | Retrieve full list of sidebars and their widget instance IDs. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::create_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Widgets\_Controller::create\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ======================================================================================================= Creates a widget. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function create_item( $request ) { $sidebar_id = $request['sidebar']; $widget_id = $this->save_widget( $request, $sidebar_id ); if ( is_wp_error( $widget_id ) ) { return $widget_id; } wp_assign_widget_to_sidebar( $widget_id, $sidebar_id ); $request['context'] = 'edit'; $response = $this->prepare_item_for_response( compact( 'sidebar_id', 'widget_id' ), $request ); if ( is_wp_error( $response ) ) { return $response; } $response->set_status( 201 ); return $response; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Prepares the widget for the REST response. | | [WP\_REST\_Widgets\_Controller::save\_widget()](save_widget) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Saves the widget in the request object. | | [wp\_assign\_widget\_to\_sidebar()](../../functions/wp_assign_widget_to_sidebar) wp-includes/widgets.php | Assigns a widget to the given sidebar. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::update_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Widgets\_Controller::update\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ======================================================================================================= Updates an existing widget. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function update_item( $request ) { global $wp_widget_factory; /* * retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the * wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global. * * When batch requests are processed, this global is not properly updated by previous * calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets * sidebar. * * See https://core.trac.wordpress.org/ticket/53657. */ wp_get_sidebars_widgets(); $this->retrieve_widgets(); $widget_id = $request['id']; $sidebar_id = wp_find_widgets_sidebar( $widget_id ); // Allow sidebar to be unset or missing when widget is not a WP_Widget. $parsed_id = wp_parse_widget_id( $widget_id ); $widget_object = $wp_widget_factory->get_widget_object( $parsed_id['id_base'] ); if ( is_null( $sidebar_id ) && $widget_object ) { return new WP_Error( 'rest_widget_not_found', __( 'No widget was found with that id.' ), array( 'status' => 404 ) ); } if ( $request->has_param( 'instance' ) || $request->has_param( 'form_data' ) ) { $maybe_error = $this->save_widget( $request, $sidebar_id ); if ( is_wp_error( $maybe_error ) ) { return $maybe_error; } } if ( $request->has_param( 'sidebar' ) ) { if ( $sidebar_id !== $request['sidebar'] ) { $sidebar_id = $request['sidebar']; wp_assign_widget_to_sidebar( $widget_id, $sidebar_id ); } } $request['context'] = 'edit'; return $this->prepare_item_for_response( compact( 'widget_id', 'sidebar_id' ), $request ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::retrieve\_widgets()](retrieve_widgets) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Looks for “lost” widgets once per request. | | [WP\_Widget\_Factory::get\_widget\_object()](../wp_widget_factory/get_widget_object) wp-includes/class-wp-widget-factory.php | Returns the registered [WP\_Widget](../wp_widget) object for the given widget type. | | [WP\_REST\_Widgets\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Prepares the widget for the REST response. | | [WP\_REST\_Widgets\_Controller::save\_widget()](save_widget) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Saves the widget in the request object. | | [wp\_find\_widgets\_sidebar()](../../functions/wp_find_widgets_sidebar) wp-includes/widgets.php | Finds the sidebar that a given widget belongs to. | | [wp\_assign\_widget\_to\_sidebar()](../../functions/wp_assign_widget_to_sidebar) wp-includes/widgets.php | Assigns a widget to the given sidebar. | | [wp\_parse\_widget\_id()](../../functions/wp_parse_widget_id) wp-includes/widgets.php | Converts a widget ID into its id\_base and number components. | | [wp\_get\_sidebars\_widgets()](../../functions/wp_get_sidebars_widgets) wp-includes/widgets.php | Retrieve full list of sidebars and their widget instance IDs. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::delete_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Widgets\_Controller::delete\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ============================================================================================================= Checks if a given request has access to delete widgets. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function delete_item_permissions_check( $request ) { return $this->permissions_check( $request ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::permissions\_check()](permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Performs a permissions check for managing widgets. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::get_items_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Widgets\_Controller::get\_items\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error =========================================================================================================== Checks if a given request has access to get widgets. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function get_items_permissions_check( $request ) { $this->retrieve_widgets(); if ( isset( $request['sidebar'] ) && $this->check_read_sidebar_permission( $request['sidebar'] ) ) { return true; } foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) { if ( $this->check_read_sidebar_permission( $sidebar_id ) ) { return true; } } return $this->permissions_check( $request ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::retrieve\_widgets()](retrieve_widgets) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Looks for “lost” widgets once per request. | | [WP\_REST\_Widgets\_Controller::check\_read\_sidebar\_permission()](check_read_sidebar_permission) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a sidebar can be read publicly. | | [WP\_REST\_Widgets\_Controller::permissions\_check()](permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Performs a permissions check for managing widgets. | | [wp\_get\_sidebars\_widgets()](../../functions/wp_get_sidebars_widgets) wp-includes/widgets.php | Retrieve full list of sidebars and their widget instance IDs. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::update_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Widgets\_Controller::update\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ============================================================================================================= Checks if a given request has access to update widgets. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function update_item_permissions_check( $request ) { return $this->permissions_check( $request ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::permissions\_check()](permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Performs a permissions check for managing widgets. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::register_routes() WP\_REST\_Widgets\_Controller::register\_routes() ================================================= Registers the widget routes for the controller. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function register_routes() { register_rest_route( $this->namespace, $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'create_item' ), 'permission_callback' => array( $this, 'create_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema(), ), 'allow_batch' => $this->allow_batch, 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, $this->rest_base . '/(?P<id>[\w\-]+)', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_item' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), ), array( 'methods' => WP_REST_Server::DELETABLE, 'callback' => array( $this, 'delete_item' ), 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 'args' => array( 'force' => array( 'description' => __( 'Whether to force removal of the widget, or move it to the inactive sidebar.' ), 'type' => 'boolean', ), ), ), 'allow_batch' => $this->allow_batch, 'schema' => array( $this, 'get_public_item_schema' ), ) ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::get\_collection\_params()](get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Gets the list of collection params. | | [register\_rest\_route()](../../functions/register_rest_route) wp-includes/rest-api.php | Registers a REST API route. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::get_collection_params(): array[] WP\_REST\_Widgets\_Controller::get\_collection\_params(): array[] ================================================================= Gets the list of collection params. array[] File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function get_collection_params() { return array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 'sidebar' => array( 'description' => __( 'The sidebar to return widgets for.' ), 'type' => 'string', ), ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::register\_routes()](register_routes) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Registers the widget routes for the controller. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |
programming_docs
wordpress WP_REST_Widgets_Controller::save_widget( WP_REST_Request $request, string $sidebar_id ): string|WP_Error WP\_REST\_Widgets\_Controller::save\_widget( WP\_REST\_Request $request, string $sidebar\_id ): string|WP\_Error ================================================================================================================ Saves the widget in the request object. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. `$sidebar_id` string Required ID of the sidebar the widget belongs to. string|[WP\_Error](../wp_error) The saved widget ID. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` protected function save_widget( $request, $sidebar_id ) { global $wp_widget_factory, $wp_registered_widget_updates; require_once ABSPATH . 'wp-admin/includes/widgets.php'; // For next_widget_id_number(). if ( isset( $request['id'] ) ) { // Saving an existing widget. $id = $request['id']; $parsed_id = wp_parse_widget_id( $id ); $id_base = $parsed_id['id_base']; $number = isset( $parsed_id['number'] ) ? $parsed_id['number'] : null; $widget_object = $wp_widget_factory->get_widget_object( $id_base ); $creating = false; } elseif ( $request['id_base'] ) { // Saving a new widget. $id_base = $request['id_base']; $widget_object = $wp_widget_factory->get_widget_object( $id_base ); $number = $widget_object ? next_widget_id_number( $id_base ) : null; $id = $widget_object ? $id_base . '-' . $number : $id_base; $creating = true; } else { return new WP_Error( 'rest_invalid_widget', __( 'Widget type (id_base) is required.' ), array( 'status' => 400 ) ); } if ( ! isset( $wp_registered_widget_updates[ $id_base ] ) ) { return new WP_Error( 'rest_invalid_widget', __( 'The provided widget type (id_base) cannot be updated.' ), array( 'status' => 400 ) ); } if ( isset( $request['instance'] ) ) { if ( ! $widget_object ) { return new WP_Error( 'rest_invalid_widget', __( 'Cannot set instance on a widget that does not extend WP_Widget.' ), array( 'status' => 400 ) ); } if ( isset( $request['instance']['raw'] ) ) { if ( empty( $widget_object->widget_options['show_instance_in_rest'] ) ) { return new WP_Error( 'rest_invalid_widget', __( 'Widget type does not support raw instances.' ), array( 'status' => 400 ) ); } $instance = $request['instance']['raw']; } elseif ( isset( $request['instance']['encoded'], $request['instance']['hash'] ) ) { $serialized_instance = base64_decode( $request['instance']['encoded'] ); if ( ! hash_equals( wp_hash( $serialized_instance ), $request['instance']['hash'] ) ) { return new WP_Error( 'rest_invalid_widget', __( 'The provided instance is malformed.' ), array( 'status' => 400 ) ); } $instance = unserialize( $serialized_instance ); } else { return new WP_Error( 'rest_invalid_widget', __( 'The provided instance is invalid. Must contain raw OR encoded and hash.' ), array( 'status' => 400 ) ); } $form_data = array( "widget-$id_base" => array( $number => $instance, ), 'sidebar' => $sidebar_id, ); } elseif ( isset( $request['form_data'] ) ) { $form_data = $request['form_data']; } else { $form_data = array(); } $original_post = $_POST; $original_request = $_REQUEST; foreach ( $form_data as $key => $value ) { $slashed_value = wp_slash( $value ); $_POST[ $key ] = $slashed_value; $_REQUEST[ $key ] = $slashed_value; } $callback = $wp_registered_widget_updates[ $id_base ]['callback']; $params = $wp_registered_widget_updates[ $id_base ]['params']; if ( is_callable( $callback ) ) { ob_start(); call_user_func_array( $callback, $params ); ob_end_clean(); } $_POST = $original_post; $_REQUEST = $original_request; if ( $widget_object ) { // Register any multi-widget that the update callback just created. $widget_object->_set( $number ); $widget_object->_register_one( $number ); /* * WP_Widget sets `updated = true` after an update to prevent more than one widget * from being saved per request. This isn't what we want in the REST API, though, * as we support batch requests. */ $widget_object->updated = false; } /** * Fires after a widget is created or updated via the REST API. * * @since 5.8.0 * * @param string $id ID of the widget being saved. * @param string $sidebar_id ID of the sidebar containing the widget being saved. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a widget, false when updating. */ do_action( 'rest_after_save_widget', $id, $sidebar_id, $request, $creating ); return $id; } ``` [do\_action( 'rest\_after\_save\_widget', string $id, string $sidebar\_id, WP\_REST\_Request $request, bool $creating )](../../hooks/rest_after_save_widget) Fires after a widget is created or updated via the REST API. | Uses | Description | | --- | --- | | [WP\_Widget\_Factory::get\_widget\_object()](../wp_widget_factory/get_widget_object) wp-includes/class-wp-widget-factory.php | Returns the registered [WP\_Widget](../wp_widget) object for the given widget type. | | [wp\_parse\_widget\_id()](../../functions/wp_parse_widget_id) wp-includes/widgets.php | Converts a widget ID into its id\_base and number components. | | [next\_widget\_id\_number()](../../functions/next_widget_id_number) wp-admin/includes/widgets.php | | | [wp\_hash()](../../functions/wp_hash) wp-includes/pluggable.php | Gets hash of given string. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_slash()](../../functions/wp_slash) wp-includes/formatting.php | Adds slashes to a string or recursively adds slashes to strings within an array. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::create\_item()](create_item) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Creates a widget. | | [WP\_REST\_Widgets\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Updates an existing widget. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::__construct() WP\_REST\_Widgets\_Controller::\_\_construct() ============================================== Widgets controller constructor. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function __construct() { $this->namespace = 'wp/v2'; $this->rest_base = 'widgets'; } ``` | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::get_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Widgets\_Controller::get\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ========================================================================================================== Checks if a given request has access to get a widget. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function get_item_permissions_check( $request ) { $this->retrieve_widgets(); $widget_id = $request['id']; $sidebar_id = wp_find_widgets_sidebar( $widget_id ); if ( $sidebar_id && $this->check_read_sidebar_permission( $sidebar_id ) ) { return true; } return $this->permissions_check( $request ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::retrieve\_widgets()](retrieve_widgets) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Looks for “lost” widgets once per request. | | [WP\_REST\_Widgets\_Controller::check\_read\_sidebar\_permission()](check_read_sidebar_permission) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a sidebar can be read publicly. | | [WP\_REST\_Widgets\_Controller::permissions\_check()](permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Performs a permissions check for managing widgets. | | [wp\_find\_widgets\_sidebar()](../../functions/wp_find_widgets_sidebar) wp-includes/widgets.php | Finds the sidebar that a given widget belongs to. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Widgets\_Controller::permissions\_check( WP\_REST\_Request $request ): true|WP\_Error =============================================================================================== Performs a permissions check for managing widgets. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` protected function permissions_check( $request ) { if ( ! current_user_can( 'edit_theme_options' ) ) { return new WP_Error( 'rest_cannot_manage_widgets', __( 'Sorry, you are not allowed to manage widgets on this site.' ), array( 'status' => rest_authorization_required_code(), ) ); } return true; } ``` | Uses | Description | | --- | --- | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::get\_items\_permissions\_check()](get_items_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a given request has access to get widgets. | | [WP\_REST\_Widgets\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Retrieves a collection of widgets. | | [WP\_REST\_Widgets\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a given request has access to get a widget. | | [WP\_REST\_Widgets\_Controller::create\_item\_permissions\_check()](create_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a given request has access to create widgets. | | [WP\_REST\_Widgets\_Controller::update\_item\_permissions\_check()](update_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a given request has access to update widgets. | | [WP\_REST\_Widgets\_Controller::delete\_item\_permissions\_check()](delete_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a given request has access to delete widgets. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::create_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Widgets\_Controller::create\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ============================================================================================================= Checks if a given request has access to create widgets. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function create_item_permissions_check( $request ) { return $this->permissions_check( $request ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::permissions\_check()](permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Performs a permissions check for managing widgets. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::delete_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Widgets\_Controller::delete\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ======================================================================================================= Deletes a widget. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function delete_item( $request ) { global $wp_widget_factory, $wp_registered_widget_updates; /* * retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the * wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global. * * When batch requests are processed, this global is not properly updated by previous * calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets * sidebar. * * See https://core.trac.wordpress.org/ticket/53657. */ wp_get_sidebars_widgets(); $this->retrieve_widgets(); $widget_id = $request['id']; $sidebar_id = wp_find_widgets_sidebar( $widget_id ); if ( is_null( $sidebar_id ) ) { return new WP_Error( 'rest_widget_not_found', __( 'No widget was found with that id.' ), array( 'status' => 404 ) ); } $request['context'] = 'edit'; if ( $request['force'] ) { $response = $this->prepare_item_for_response( compact( 'widget_id', 'sidebar_id' ), $request ); $parsed_id = wp_parse_widget_id( $widget_id ); $id_base = $parsed_id['id_base']; $original_post = $_POST; $original_request = $_REQUEST; $_POST = array( 'sidebar' => $sidebar_id, "widget-$id_base" => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1', ); $_REQUEST = $_POST; /** This action is documented in wp-admin/widgets-form.php */ do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base ); $callback = $wp_registered_widget_updates[ $id_base ]['callback']; $params = $wp_registered_widget_updates[ $id_base ]['params']; if ( is_callable( $callback ) ) { ob_start(); call_user_func_array( $callback, $params ); ob_end_clean(); } $_POST = $original_post; $_REQUEST = $original_request; $widget_object = $wp_widget_factory->get_widget_object( $id_base ); if ( $widget_object ) { /* * WP_Widget sets `updated = true` after an update to prevent more than one widget * from being saved per request. This isn't what we want in the REST API, though, * as we support batch requests. */ $widget_object->updated = false; } wp_assign_widget_to_sidebar( $widget_id, '' ); $response->set_data( array( 'deleted' => true, 'previous' => $response->get_data(), ) ); } else { wp_assign_widget_to_sidebar( $widget_id, 'wp_inactive_widgets' ); $response = $this->prepare_item_for_response( array( 'sidebar_id' => 'wp_inactive_widgets', 'widget_id' => $widget_id, ), $request ); } /** * Fires after a widget is deleted via the REST API. * * @since 5.8.0 * * @param string $widget_id ID of the widget marked for deletion. * @param string $sidebar_id ID of the sidebar the widget was deleted from. * @param WP_REST_Response|WP_Error $response The response data, or WP_Error object on failure. * @param WP_REST_Request $request The request sent to the API. */ do_action( 'rest_delete_widget', $widget_id, $sidebar_id, $response, $request ); return $response; } ``` [do\_action( 'delete\_widget', string $widget\_id, string $sidebar\_id, string $id\_base )](../../hooks/delete_widget) Fires immediately after a widget has been marked for deletion. [do\_action( 'rest\_delete\_widget', string $widget\_id, string $sidebar\_id, WP\_REST\_Response|WP\_Error $response, WP\_REST\_Request $request )](../../hooks/rest_delete_widget) Fires after a widget is deleted via the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::retrieve\_widgets()](retrieve_widgets) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Looks for “lost” widgets once per request. | | [WP\_Widget\_Factory::get\_widget\_object()](../wp_widget_factory/get_widget_object) wp-includes/class-wp-widget-factory.php | Returns the registered [WP\_Widget](../wp_widget) object for the given widget type. | | [WP\_REST\_Widgets\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Prepares the widget for the REST response. | | [wp\_find\_widgets\_sidebar()](../../functions/wp_find_widgets_sidebar) wp-includes/widgets.php | Finds the sidebar that a given widget belongs to. | | [wp\_assign\_widget\_to\_sidebar()](../../functions/wp_assign_widget_to_sidebar) wp-includes/widgets.php | Assigns a widget to the given sidebar. | | [wp\_parse\_widget\_id()](../../functions/wp_parse_widget_id) wp-includes/widgets.php | Converts a widget ID into its id\_base and number components. | | [wp\_get\_sidebars\_widgets()](../../functions/wp_get_sidebars_widgets) wp-includes/widgets.php | Retrieve full list of sidebars and their widget instance IDs. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |
programming_docs
wordpress WP_REST_Widgets_Controller::get_item_schema(): array WP\_REST\_Widgets\_Controller::get\_item\_schema(): array ========================================================= Retrieves the widget’s schema, conforming to JSON Schema. array Item schema data. File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $this->schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'widget', 'type' => 'object', 'properties' => array( 'id' => array( 'description' => __( 'Unique identifier for the widget.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), ), 'id_base' => array( 'description' => __( 'The type of the widget. Corresponds to ID in widget-types endpoint.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), ), 'sidebar' => array( 'description' => __( 'The sidebar the widget belongs to.' ), 'type' => 'string', 'default' => 'wp_inactive_widgets', 'required' => true, 'context' => array( 'view', 'edit', 'embed' ), ), 'rendered' => array( 'description' => __( 'HTML representation of the widget.' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'rendered_form' => array( 'description' => __( 'HTML representation of the widget admin form.' ), 'type' => 'string', 'context' => array( 'edit' ), 'readonly' => true, ), 'instance' => array( 'description' => __( 'Instance settings of the widget, if supported.' ), 'type' => 'object', 'context' => array( 'edit' ), 'default' => null, 'properties' => array( 'encoded' => array( 'description' => __( 'Base64 encoded representation of the instance settings.' ), 'type' => 'string', 'context' => array( 'edit' ), ), 'hash' => array( 'description' => __( 'Cryptographic hash of the instance settings.' ), 'type' => 'string', 'context' => array( 'edit' ), ), 'raw' => array( 'description' => __( 'Unencoded instance settings, if supported.' ), 'type' => 'object', 'context' => array( 'edit' ), ), ), ), 'form_data' => array( 'description' => __( 'URL-encoded form data from the widget admin form. Used to update a widget that does not support instance. Write only.' ), 'type' => 'string', 'context' => array(), 'arg_options' => array( 'sanitize_callback' => static function( $string ) { $array = array(); wp_parse_str( $string, $array ); return $array; }, ), ), ), ); return $this->add_additional_fields_schema( $this->schema ); } ``` | Uses | Description | | --- | --- | | [wp\_parse\_str()](../../functions/wp_parse_str) wp-includes/formatting.php | Parses a string into variables to be stored in an array. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_Widgets_Controller::retrieve_widgets() WP\_REST\_Widgets\_Controller::retrieve\_widgets() ================================================== Looks for “lost” widgets once per request. * [retrieve\_widgets()](../../functions/retrieve_widgets) File: `wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php/) ``` protected function retrieve_widgets() { if ( ! $this->widgets_retrieved ) { retrieve_widgets(); $this->widgets_retrieved = true; } } ``` | Uses | Description | | --- | --- | | [retrieve\_widgets()](../../functions/retrieve_widgets) wp-includes/widgets.php | Validates and remaps any “orphaned” widgets to wp\_inactive\_widgets sidebar, and saves the widget settings. This has to run at least on each theme change. | | Used By | Description | | --- | --- | | [WP\_REST\_Widgets\_Controller::get\_items\_permissions\_check()](get_items_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a given request has access to get widgets. | | [WP\_REST\_Widgets\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Retrieves a collection of widgets. | | [WP\_REST\_Widgets\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Checks if a given request has access to get a widget. | | [WP\_REST\_Widgets\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Gets an individual widget. | | [WP\_REST\_Widgets\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Updates an existing widget. | | [WP\_REST\_Widgets\_Controller::delete\_item()](delete_item) wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php | Deletes a widget. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Customize_Setting::is_current_blog_previewed(): bool WP\_Customize\_Setting::is\_current\_blog\_previewed(): bool ============================================================ Return true if the current site is not the same as the previewed site. bool If preview() has been called. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` public function is_current_blog_previewed() { if ( ! isset( $this->_previewed_blog_id ) ) { return false; } return ( get_current_blog_id() === $this->_previewed_blog_id ); } ``` | Uses | Description | | --- | --- | | [get\_current\_blog\_id()](../../functions/get_current_blog_id) wp-includes/load.php | Retrieve the current site ID. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::\_multidimensional\_preview\_filter()](_multidimensional_preview_filter) wp-includes/class-wp-customize-setting.php | Callback function to filter multidimensional theme mods and options. | | [WP\_Customize\_Setting::\_preview\_filter()](_preview_filter) wp-includes/class-wp-customize-setting.php | Callback function to filter non-multidimensional theme mods and options. | | Version | Description | | --- | --- | | [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Introduced. | wordpress WP_Customize_Setting::_multidimensional_preview_filter( mixed $original ): mixed WP\_Customize\_Setting::\_multidimensional\_preview\_filter( mixed $original ): mixed ===================================================================================== Callback function to filter multidimensional theme mods and options. For all multidimensional settings of a given type, the preview filter for the first setting previewed will be used to apply the values for the others. * WP\_Customize\_Setting::$aggregated\_multidimensionals `$original` mixed Required Original root value. mixed New or old value. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final public function _multidimensional_preview_filter( $original ) { if ( ! $this->is_current_blog_previewed() ) { return $original; } $id_base = $this->id_data['base']; // If no settings have been previewed yet (which should not be the case, since $this is), just pass through the original value. if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) { return $original; } foreach ( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] as $previewed_setting ) { // Skip applying previewed value for any settings that have already been applied. if ( ! empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['preview_applied_instances'][ $previewed_setting->id ] ) ) { continue; } // Do the replacements of the posted/default sub value into the root value. $value = $previewed_setting->post_value( $previewed_setting->default ); $root = self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value']; $root = $previewed_setting->multidimensional_replace( $root, $previewed_setting->id_data['keys'], $value ); self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['root_value'] = $root; // Mark this setting having been applied so that it will be skipped when the filter is called again. self::$aggregated_multidimensionals[ $previewed_setting->type ][ $id_base ]['preview_applied_instances'][ $previewed_setting->id ] = true; } return self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::is\_current\_blog\_previewed()](is_current_blog_previewed) wp-includes/class-wp-customize-setting.php | Return true if the current site is not the same as the previewed site. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Customize_Setting::preview(): bool WP\_Customize\_Setting::preview(): bool ======================================= Add filters to supply the setting’s value when accessed. If the setting already has a pre-existing value and there is no incoming post value for the setting, then this method will short-circuit since there is no change to preview. bool False when preview short-circuits due no change needing to be previewed. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` public function preview() { if ( ! isset( $this->_previewed_blog_id ) ) { $this->_previewed_blog_id = get_current_blog_id(); } // Prevent re-previewing an already-previewed setting. if ( $this->is_previewed ) { return true; } $id_base = $this->id_data['base']; $is_multidimensional = ! empty( $this->id_data['keys'] ); $multidimensional_filter = array( $this, '_multidimensional_preview_filter' ); /* * Check if the setting has a pre-existing value (an isset check), * and if doesn't have any incoming post value. If both checks are true, * then the preview short-circuits because there is nothing that needs * to be previewed. */ $undefined = new stdClass(); $needs_preview = ( $undefined !== $this->post_value( $undefined ) ); $value = null; // Since no post value was defined, check if we have an initial value set. if ( ! $needs_preview ) { if ( $this->is_multidimensional_aggregated ) { $root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; $value = $this->multidimensional_get( $root, $this->id_data['keys'], $undefined ); } else { $default = $this->default; $this->default = $undefined; // Temporarily set default to undefined so we can detect if existing value is set. $value = $this->value(); $this->default = $default; } $needs_preview = ( $undefined === $value ); // Because the default needs to be supplied. } // If the setting does not need previewing now, defer to when it has a value to preview. if ( ! $needs_preview ) { if ( ! has_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) ) ) { add_action( "customize_post_value_set_{$this->id}", array( $this, 'preview' ) ); } return false; } switch ( $this->type ) { case 'theme_mod': if ( ! $is_multidimensional ) { add_filter( "theme_mod_{$id_base}", array( $this, '_preview_filter' ) ); } else { if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) { // Only add this filter once for this ID base. add_filter( "theme_mod_{$id_base}", $multidimensional_filter ); } self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this; } break; case 'option': if ( ! $is_multidimensional ) { add_filter( "pre_option_{$id_base}", array( $this, '_preview_filter' ) ); } else { if ( empty( self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'] ) ) { // Only add these filters once for this ID base. add_filter( "option_{$id_base}", $multidimensional_filter ); add_filter( "default_option_{$id_base}", $multidimensional_filter ); } self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['previewed_instances'][ $this->id ] = $this; } break; default: /** * Fires when the WP_Customize_Setting::preview() method is called for settings * not handled as theme_mods or options. * * The dynamic portion of the hook name, `$this->id`, refers to the setting ID. * * @since 3.4.0 * * @param WP_Customize_Setting $setting WP_Customize_Setting instance. */ do_action( "customize_preview_{$this->id}", $this ); /** * Fires when the WP_Customize_Setting::preview() method is called for settings * not handled as theme_mods or options. * * The dynamic portion of the hook name, `$this->type`, refers to the setting type. * * @since 4.1.0 * * @param WP_Customize_Setting $setting WP_Customize_Setting instance. */ do_action( "customize_preview_{$this->type}", $this ); } $this->is_previewed = true; return true; } ``` [do\_action( "customize\_preview\_{$this->id}", WP\_Customize\_Setting $setting )](../../hooks/customize_preview_this-id) Fires when the [WP\_Customize\_Setting::preview()](preview) method is called for settings not handled as theme\_mods or options. [do\_action( "customize\_preview\_{$this->type}", WP\_Customize\_Setting $setting )](../../hooks/customize_preview_this-type) Fires when the [WP\_Customize\_Setting::preview()](preview) method is called for settings not handled as theme\_mods or options. | Uses | Description | | --- | --- | | [has\_action()](../../functions/has_action) wp-includes/plugin.php | Checks if any action has been registered for a hook. | | [WP\_Customize\_Setting::multidimensional\_get()](multidimensional_get) wp-includes/class-wp-customize-setting.php | Will attempt to fetch a specific value from a multidimensional array. | | [WP\_Customize\_Setting::value()](value) wp-includes/class-wp-customize-setting.php | Fetch the value of the setting. | | [WP\_Customize\_Setting::post\_value()](post_value) wp-includes/class-wp-customize-setting.php | Fetch and sanitize the $\_POST value for the setting. | | [get\_current\_blog\_id()](../../functions/get_current_blog_id) wp-includes/load.php | Retrieve the current site ID. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Added boolean return value. | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::set_root_value( mixed $value ): bool WP\_Customize\_Setting::set\_root\_value( mixed $value ): bool ============================================================== Set the root value for a setting, especially for multidimensional ones. `$value` mixed Required Value to set as root of multidimensional setting. bool Whether the multidimensional root was updated successfully. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` protected function set_root_value( $value ) { $id_base = $this->id_data['base']; if ( 'option' === $this->type ) { $autoload = true; if ( isset( self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] ) ) { $autoload = self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload']; } return update_option( $id_base, $value, $autoload ); } elseif ( 'theme_mod' === $this->type ) { set_theme_mod( $id_base, $value ); return true; } else { /* * Any WP_Customize_Setting subclass implementing aggregate multidimensional * will need to override this method to obtain the data from the appropriate * location. */ return false; } } ``` | Uses | Description | | --- | --- | | [set\_theme\_mod()](../../functions/set_theme_mod) wp-includes/theme.php | Updates theme modification value for the active theme. | | [update\_option()](../../functions/update_option) wp-includes/option.php | Updates the value of an option that was already added. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::update()](update) wp-includes/class-wp-customize-setting.php | Save the value of the setting, using the related API. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Customize_Setting::update( mixed $value ): bool WP\_Customize\_Setting::update( mixed $value ): bool ==================================================== Save the value of the setting, using the related API. `$value` mixed Required The value to update. bool The result of saving the value. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` protected function update( $value ) { $id_base = $this->id_data['base']; if ( 'option' === $this->type || 'theme_mod' === $this->type ) { if ( ! $this->is_multidimensional_aggregated ) { return $this->set_root_value( $value ); } else { $root = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; $root = $this->multidimensional_replace( $root, $this->id_data['keys'], $value ); self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value'] = $root; return $this->set_root_value( $root ); } } else { /** * Fires when the WP_Customize_Setting::update() method is called for settings * not handled as theme_mods or options. * * The dynamic portion of the hook name, `$this->type`, refers to the type of setting. * * @since 3.4.0 * * @param mixed $value Value of the setting. * @param WP_Customize_Setting $setting WP_Customize_Setting instance. */ do_action( "customize_update_{$this->type}", $value, $this ); return has_action( "customize_update_{$this->type}" ); } } ``` [do\_action( "customize\_update\_{$this->type}", mixed $value, WP\_Customize\_Setting $setting )](../../hooks/customize_update_this-type) Fires when the [WP\_Customize\_Setting::update()](update) method is called for settings not handled as theme\_mods or options. | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::set\_root\_value()](set_root_value) wp-includes/class-wp-customize-setting.php | Set the root value for a setting, especially for multidimensional ones. | | [has\_action()](../../functions/has_action) wp-includes/plugin.php | Checks if any action has been registered for a hook. | | [WP\_Customize\_Setting::multidimensional\_replace()](multidimensional_replace) wp-includes/class-wp-customize-setting.php | Will attempt to replace a specific value in a multidimensional array. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::save()](save) wp-includes/class-wp-customize-setting.php | Checks user capabilities and theme supports, and then saves the value of the setting. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. |
programming_docs
wordpress WP_Customize_Setting::multidimensional_get( array $root, array $keys, mixed $default_value = null ): mixed WP\_Customize\_Setting::multidimensional\_get( array $root, array $keys, mixed $default\_value = null ): mixed ============================================================================================================== Will attempt to fetch a specific value from a multidimensional array. `$root` array Required `$keys` array Required `$default_value` mixed Optional A default value which is used as a fallback. Default: `null` mixed The requested value or the default value. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final protected function multidimensional_get( $root, $keys, $default_value = null ) { if ( empty( $keys ) ) { // If there are no keys, test the root. return isset( $root ) ? $root : $default_value; } $result = $this->multidimensional( $root, $keys ); return isset( $result ) ? $result['node'][ $result['key'] ] : $default_value; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::multidimensional()](multidimensional) wp-includes/class-wp-customize-setting.php | Multidimensional helper function. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::value()](value) wp-includes/class-wp-customize-setting.php | Fetch the value of the setting. | | [WP\_Customize\_Setting::multidimensional\_isset()](multidimensional_isset) wp-includes/class-wp-customize-setting.php | Will attempt to check if a specific value in a multidimensional array is set. | | [WP\_Customize\_Setting::preview()](preview) wp-includes/class-wp-customize-setting.php | Add filters to supply the setting’s value when accessed. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::_update_theme_mod() WP\_Customize\_Setting::\_update\_theme\_mod() ============================================== This method has been deprecated. Deprecated in favor of update() method instead. Deprecated method. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` protected function _update_theme_mod() { _deprecated_function( __METHOD__, '4.4.0', __CLASS__ . '::update()' ); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Deprecated in favor of update() method. | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::json(): array WP\_Customize\_Setting::json(): array ===================================== Retrieves the data to export to the client via JSON. array Array of parameters passed to JavaScript. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` public function json() { return array( 'value' => $this->js_value(), 'transport' => $this->transport, 'dirty' => $this->dirty, 'type' => $this->type, ); } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::js\_value()](js_value) wp-includes/class-wp-customize-setting.php | Sanitize the setting’s value for use in JavaScript. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Customize_Setting::_preview_filter( mixed $original ): mixed WP\_Customize\_Setting::\_preview\_filter( mixed $original ): mixed =================================================================== Callback function to filter non-multidimensional theme mods and options. If [switch\_to\_blog()](../../functions/switch_to_blog) was called after the preview() method, and the current site is now not the same site, then this method does a no-op and returns the original value. `$original` mixed Required Old value. mixed New or old value. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` public function _preview_filter( $original ) { if ( ! $this->is_current_blog_previewed() ) { return $original; } $undefined = new stdClass(); // Symbol hack. $post_value = $this->post_value( $undefined ); if ( $undefined !== $post_value ) { $value = $post_value; } else { /* * Note that we don't use $original here because preview() will * not add the filter in the first place if it has an initial value * and there is no post value. */ $value = $this->default; } return $value; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::is\_current\_blog\_previewed()](is_current_blog_previewed) wp-includes/class-wp-customize-setting.php | Return true if the current site is not the same as the previewed site. | | [WP\_Customize\_Setting::post\_value()](post_value) wp-includes/class-wp-customize-setting.php | Fetch and sanitize the $\_POST value for the setting. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::_update_option() WP\_Customize\_Setting::\_update\_option() ========================================== This method has been deprecated. Deprecated in favor of update() method instead. Deprecated method. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` protected function _update_option() { _deprecated_function( __METHOD__, '4.4.0', __CLASS__ . '::update()' ); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Deprecated in favor of update() method. | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::sanitize( string|array $value ): string|array|null|WP_Error WP\_Customize\_Setting::sanitize( string|array $value ): string|array|null|WP\_Error ==================================================================================== Sanitize an input. `$value` string|array Required The value to sanitize. string|array|null|[WP\_Error](../wp_error) Sanitized value, or `null`/`WP_Error` if invalid. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` public function sanitize( $value ) { /** * Filters a Customize setting value in un-slashed form. * * @since 3.4.0 * * @param mixed $value Value of the setting. * @param WP_Customize_Setting $setting WP_Customize_Setting instance. */ return apply_filters( "customize_sanitize_{$this->id}", $value, $this ); } ``` [apply\_filters( "customize\_sanitize\_{$this->id}", mixed $value, WP\_Customize\_Setting $setting )](../../hooks/customize_sanitize_this-id) Filters a Customize setting value in un-slashed form. | Uses | Description | | --- | --- | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::multidimensional( array $root, array $keys, bool $create = false ): array|void WP\_Customize\_Setting::multidimensional( array $root, array $keys, bool $create = false ): array|void ====================================================================================================== Multidimensional helper function. `$root` array Required `$keys` array Required `$create` bool Optional Default: `false` array|void Keys are `'root'`, `'node'`, and `'key'`. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final protected function multidimensional( &$root, $keys, $create = false ) { if ( $create && empty( $root ) ) { $root = array(); } if ( ! isset( $root ) || empty( $keys ) ) { return; } $last = array_pop( $keys ); $node = &$root; foreach ( $keys as $key ) { if ( $create && ! isset( $node[ $key ] ) ) { $node[ $key ] = array(); } if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) { return; } $node = &$node[ $key ]; } if ( $create ) { if ( ! is_array( $node ) ) { // Account for an array overriding a string or object value. $node = array(); } if ( ! isset( $node[ $last ] ) ) { $node[ $last ] = array(); } } if ( ! isset( $node[ $last ] ) ) { return; } return array( 'root' => &$root, 'node' => &$node, 'key' => $last, ); } ``` | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::multidimensional\_replace()](multidimensional_replace) wp-includes/class-wp-customize-setting.php | Will attempt to replace a specific value in a multidimensional array. | | [WP\_Customize\_Setting::multidimensional\_get()](multidimensional_get) wp-includes/class-wp-customize-setting.php | Will attempt to fetch a specific value from a multidimensional array. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::get_root_value( mixed $default_value = null ): mixed WP\_Customize\_Setting::get\_root\_value( mixed $default\_value = null ): mixed =============================================================================== Get the root value for a setting, especially for multidimensional ones. `$default_value` mixed Optional Value to return if root does not exist. Default: `null` mixed File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` protected function get_root_value( $default_value = null ) { $id_base = $this->id_data['base']; if ( 'option' === $this->type ) { return get_option( $id_base, $default_value ); } elseif ( 'theme_mod' === $this->type ) { return get_theme_mod( $id_base, $default_value ); } else { /* * Any WP_Customize_Setting subclass implementing aggregate multidimensional * will need to override this method to obtain the data from the appropriate * location. */ return $default_value; } } ``` | Uses | Description | | --- | --- | | [get\_theme\_mod()](../../functions/get_theme_mod) wp-includes/theme.php | Retrieves theme modification value for the active theme. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::aggregate\_multidimensional()](aggregate_multidimensional) wp-includes/class-wp-customize-setting.php | Set up the setting for aggregated multidimensional values. | | [WP\_Customize\_Setting::value()](value) wp-includes/class-wp-customize-setting.php | Fetch the value of the setting. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Customize_Setting::js_value(): mixed WP\_Customize\_Setting::js\_value(): mixed ========================================== Sanitize the setting’s value for use in JavaScript. mixed The requested escaped value. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` public function js_value() { /** * Filters a Customize setting value for use in JavaScript. * * The dynamic portion of the hook name, `$this->id`, refers to the setting ID. * * @since 3.4.0 * * @param mixed $value The setting value. * @param WP_Customize_Setting $setting WP_Customize_Setting instance. */ $value = apply_filters( "customize_sanitize_js_{$this->id}", $this->value(), $this ); if ( is_string( $value ) ) { return html_entity_decode( $value, ENT_QUOTES, 'UTF-8' ); } return $value; } ``` [apply\_filters( "customize\_sanitize\_js\_{$this->id}", mixed $value, WP\_Customize\_Setting $setting )](../../hooks/customize_sanitize_js_this-id) Filters a Customize setting value for use in JavaScript. | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::value()](value) wp-includes/class-wp-customize-setting.php | Fetch the value of the setting. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::json()](json) wp-includes/class-wp-customize-setting.php | Retrieves the data to export to the client via JSON. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::post_value( mixed $default_value = null ): mixed WP\_Customize\_Setting::post\_value( mixed $default\_value = null ): mixed ========================================================================== Fetch and sanitize the $\_POST value for the setting. During a save request prior to save, post\_value() provides the new value while value() does not. `$default_value` mixed Optional A default value which is used as a fallback. Default: `null` mixed The default value on failure, otherwise the sanitized and validated value. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final public function post_value( $default_value = null ) { return $this->manager->post_value( $this, $default_value ); } ``` | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::value()](value) wp-includes/class-wp-customize-setting.php | Fetch the value of the setting. | | [WP\_Customize\_Setting::preview()](preview) wp-includes/class-wp-customize-setting.php | Add filters to supply the setting’s value when accessed. | | [WP\_Customize\_Setting::\_preview\_filter()](_preview_filter) wp-includes/class-wp-customize-setting.php | Callback function to filter non-multidimensional theme mods and options. | | [WP\_Customize\_Setting::save()](save) wp-includes/class-wp-customize-setting.php | Checks user capabilities and theme supports, and then saves the value of the setting. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::save(): void|false WP\_Customize\_Setting::save(): void|false ========================================== Checks user capabilities and theme supports, and then saves the value of the setting. void|false Void on success, false if cap check fails or value isn't set or is invalid. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final public function save() { $value = $this->post_value(); if ( ! $this->check_capabilities() || ! isset( $value ) ) { return false; } $id_base = $this->id_data['base']; /** * Fires when the WP_Customize_Setting::save() method is called. * * The dynamic portion of the hook name, `$id_base` refers to * the base slug of the setting name. * * @since 3.4.0 * * @param WP_Customize_Setting $setting WP_Customize_Setting instance. */ do_action( "customize_save_{$id_base}", $this ); $this->update( $value ); } ``` [do\_action( "customize\_save\_{$id\_base}", WP\_Customize\_Setting $setting )](../../hooks/customize_save_id_base) Fires when the [WP\_Customize\_Setting::save()](save) method is called. | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::post\_value()](post_value) wp-includes/class-wp-customize-setting.php | Fetch and sanitize the $\_POST value for the setting. | | [WP\_Customize\_Setting::check\_capabilities()](check_capabilities) wp-includes/class-wp-customize-setting.php | Validate user capabilities whether the theme supports the setting. | | [WP\_Customize\_Setting::update()](update) wp-includes/class-wp-customize-setting.php | Save the value of the setting, using the related API. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::multidimensional_isset( array $root, array $keys ): bool WP\_Customize\_Setting::multidimensional\_isset( array $root, array $keys ): bool ================================================================================= Will attempt to check if a specific value in a multidimensional array is set. `$root` array Required `$keys` array Required bool True if value is set, false if not. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final protected function multidimensional_isset( $root, $keys ) { $result = $this->multidimensional_get( $root, $keys ); return isset( $result ); } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::multidimensional\_get()](multidimensional_get) wp-includes/class-wp-customize-setting.php | Will attempt to fetch a specific value from a multidimensional array. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::validate( mixed $value ): true|WP_Error WP\_Customize\_Setting::validate( mixed $value ): true|WP\_Error ================================================================ Validates an input. * [WP\_REST\_Request::has\_valid\_params()](../wp_rest_request/has_valid_params) `$value` mixed Required Value to validate. true|[WP\_Error](../wp_error) True if the input was validated, otherwise [WP\_Error](../wp_error). File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` public function validate( $value ) { if ( is_wp_error( $value ) ) { return $value; } if ( is_null( $value ) ) { return new WP_Error( 'invalid_value', __( 'Invalid value.' ) ); } $validity = new WP_Error(); /** * Validates a Customize setting value. * * Plugins should amend the `$validity` object via its `WP_Error::add()` method. * * The dynamic portion of the hook name, `$this->ID`, refers to the setting ID. * * @since 4.6.0 * * @param WP_Error $validity Filtered from `true` to `WP_Error` when invalid. * @param mixed $value Value of the setting. * @param WP_Customize_Setting $setting WP_Customize_Setting instance. */ $validity = apply_filters( "customize_validate_{$this->id}", $validity, $value, $this ); if ( is_wp_error( $validity ) && ! $validity->has_errors() ) { $validity = true; } return $validity; } ``` [apply\_filters( "customize\_validate\_{$this->id}", WP\_Error $validity, mixed $value, WP\_Customize\_Setting $setting )](../../hooks/customize_validate_this-id) Validates a Customize setting value. | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_Customize\_Custom\_CSS\_Setting::validate()](../wp_customize_custom_css_setting/validate) wp-includes/customize/class-wp-customize-custom-css-setting.php | Validate a received value for being valid CSS. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. |
programming_docs
wordpress WP_Customize_Setting::_clear_aggregated_multidimensional_preview_applied_flag() WP\_Customize\_Setting::\_clear\_aggregated\_multidimensional\_preview\_applied\_flag() ======================================================================================= Clear out the previewed-applied flag for a multidimensional-aggregated value whenever its post value is updated. This ensures that the new value will get sanitized and used the next time that `WP_Customize_Setting::_multidimensional_preview_filter()` is called for this setting. * [WP\_Customize\_Manager::set\_post\_value()](../wp_customize_manager/set_post_value) * [WP\_Customize\_Setting::\_multidimensional\_preview\_filter()](../wp_customize_setting/_multidimensional_preview_filter) File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final public function _clear_aggregated_multidimensional_preview_applied_flag() { unset( self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['preview_applied_instances'][ $this->id ] ); } ``` | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Customize_Setting::value(): mixed WP\_Customize\_Setting::value(): mixed ====================================== Fetch the value of the setting. mixed The value. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` public function value() { $id_base = $this->id_data['base']; $is_core_type = ( 'option' === $this->type || 'theme_mod' === $this->type ); if ( ! $is_core_type && ! $this->is_multidimensional_aggregated ) { // Use post value if previewed and a post value is present. if ( $this->is_previewed ) { $value = $this->post_value( null ); if ( null !== $value ) { return $value; } } $value = $this->get_root_value( $this->default ); /** * Filters a Customize setting value not handled as a theme_mod or option. * * The dynamic portion of the hook name, `$id_base`, refers to * the base slug of the setting name, initialized from `$this->id_data['base']`. * * For settings handled as theme_mods or options, see those corresponding * functions for available hooks. * * @since 3.4.0 * @since 4.6.0 Added the `$this` setting instance as the second parameter. * * @param mixed $default_value The setting default value. Default empty. * @param WP_Customize_Setting $setting The setting instance. */ $value = apply_filters( "customize_value_{$id_base}", $value, $this ); } elseif ( $this->is_multidimensional_aggregated ) { $root_value = self::$aggregated_multidimensionals[ $this->type ][ $id_base ]['root_value']; $value = $this->multidimensional_get( $root_value, $this->id_data['keys'], $this->default ); // Ensure that the post value is used if the setting is previewed, since preview filters aren't applying on cached $root_value. if ( $this->is_previewed ) { $value = $this->post_value( $value ); } } else { $value = $this->get_root_value( $this->default ); } return $value; } ``` [apply\_filters( "customize\_value\_{$id\_base}", mixed $default\_value, WP\_Customize\_Setting $setting )](../../hooks/customize_value_id_base) Filters a Customize setting value not handled as a theme\_mod or option. | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::get\_root\_value()](get_root_value) wp-includes/class-wp-customize-setting.php | Get the root value for a setting, especially for multidimensional ones. | | [WP\_Customize\_Setting::multidimensional\_get()](multidimensional_get) wp-includes/class-wp-customize-setting.php | Will attempt to fetch a specific value from a multidimensional array. | | [WP\_Customize\_Setting::post\_value()](post_value) wp-includes/class-wp-customize-setting.php | Fetch and sanitize the $\_POST value for the setting. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::js\_value()](js_value) wp-includes/class-wp-customize-setting.php | Sanitize the setting’s value for use in JavaScript. | | [WP\_Customize\_Setting::preview()](preview) wp-includes/class-wp-customize-setting.php | Add filters to supply the setting’s value when accessed. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::__construct( WP_Customize_Manager $manager, string $id, array $args = array() ) WP\_Customize\_Setting::\_\_construct( WP\_Customize\_Manager $manager, string $id, array $args = array() ) =========================================================================================================== Constructor. Any supplied $args override class property defaults. `$manager` [WP\_Customize\_Manager](../wp_customize_manager) Required Customizer bootstrap instance. `$id` string Required A specific ID of the setting. Can be a theme mod or option name. `$args` array Optional Array of properties for the new Setting object. * `type`stringType of the setting. Default `'theme_mod'`. * `capability`stringCapability required for the setting. Default `'edit_theme_options'` * `theme_supports`string|string[]Theme features required to support the panel. Default is none. * `default`stringDefault value for the setting. Default is empty string. * `transport`stringOptions for rendering the live preview of changes in Customizer. Using `'refresh'` makes the change visible by reloading the whole preview. Using `'postMessage'` allows a custom JavaScript to handle live changes. Default is `'refresh'`. * `validate_callback`callableServer-side validation callback for the setting's value. * `sanitize_callback`callableCallback to filter a Customize setting value in un-slashed form. * `sanitize_js_callback`callableCallback to convert a Customize PHP setting value to a value that is JSON serializable. * `dirty`boolWhether or not the setting is initially dirty when created. Default: `array()` File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` public function __construct( $manager, $id, $args = array() ) { $keys = array_keys( get_object_vars( $this ) ); foreach ( $keys as $key ) { if ( isset( $args[ $key ] ) ) { $this->$key = $args[ $key ]; } } $this->manager = $manager; $this->id = $id; // Parse the ID for array keys. $this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) ); $this->id_data['base'] = array_shift( $this->id_data['keys'] ); // Rebuild the ID. $this->id = $this->id_data['base']; if ( ! empty( $this->id_data['keys'] ) ) { $this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']'; } if ( $this->validate_callback ) { add_filter( "customize_validate_{$this->id}", $this->validate_callback, 10, 3 ); } if ( $this->sanitize_callback ) { add_filter( "customize_sanitize_{$this->id}", $this->sanitize_callback, 10, 2 ); } if ( $this->sanitize_js_callback ) { add_filter( "customize_sanitize_js_{$this->id}", $this->sanitize_js_callback, 10, 2 ); } if ( 'option' === $this->type || 'theme_mod' === $this->type ) { // Other setting types can opt-in to aggregate multidimensional explicitly. $this->aggregate_multidimensional(); // Allow option settings to indicate whether they should be autoloaded. if ( 'option' === $this->type && isset( $args['autoload'] ) ) { self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] = $args['autoload']; } } } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::aggregate\_multidimensional()](aggregate_multidimensional) wp-includes/class-wp-customize-setting.php | Set up the setting for aggregated multidimensional values. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | Used By | Description | | --- | --- | | [WP\_Customize\_Custom\_CSS\_Setting::\_\_construct()](../wp_customize_custom_css_setting/__construct) wp-includes/customize/class-wp-customize-custom-css-setting.php | [WP\_Customize\_Custom\_CSS\_Setting](../wp_customize_custom_css_setting) constructor. | | [WP\_Customize\_Nav\_Menu\_Setting::\_\_construct()](../wp_customize_nav_menu_setting/__construct) wp-includes/customize/class-wp-customize-nav-menu-setting.php | Constructor. | | [WP\_Customize\_Nav\_Menu\_Item\_Setting::\_\_construct()](../wp_customize_nav_menu_item_setting/__construct) wp-includes/customize/class-wp-customize-nav-menu-item-setting.php | Constructor. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::id_data(): array WP\_Customize\_Setting::id\_data(): array ========================================= Get parsed ID data for multidimensional setting. array ID data for multidimensional setting. * `base`stringID base * `keys`arrayKeys for multidimensional array. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final public function id_data() { return $this->id_data; } ``` | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress WP_Customize_Setting::check_capabilities(): bool WP\_Customize\_Setting::check\_capabilities(): bool =================================================== Validate user capabilities whether the theme supports the setting. bool False if theme doesn't support the setting or user can't change setting, otherwise true. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final public function check_capabilities() { if ( $this->capability && ! current_user_can( $this->capability ) ) { return false; } if ( $this->theme_supports && ! current_theme_supports( ... (array) $this->theme_supports ) ) { return false; } return true; } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [current\_theme\_supports()](../../functions/current_theme_supports) wp-includes/theme.php | Checks a theme’s support for a given feature. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::save()](save) wp-includes/class-wp-customize-setting.php | Checks user capabilities and theme supports, and then saves the value of the setting. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::multidimensional_replace( array $root, array $keys, mixed $value ): mixed WP\_Customize\_Setting::multidimensional\_replace( array $root, array $keys, mixed $value ): mixed ================================================================================================== Will attempt to replace a specific value in a multidimensional array. `$root` array Required `$keys` array Required `$value` mixed Required The value to update. mixed File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` final protected function multidimensional_replace( $root, $keys, $value ) { if ( ! isset( $value ) ) { return $root; } elseif ( empty( $keys ) ) { // If there are no keys, we're replacing the root. return $value; } $result = $this->multidimensional( $root, $keys, true ); if ( isset( $result ) ) { $result['node'][ $result['key'] ] = $value; } return $root; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::multidimensional()](multidimensional) wp-includes/class-wp-customize-setting.php | Multidimensional helper function. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::update()](update) wp-includes/class-wp-customize-setting.php | Save the value of the setting, using the related API. | | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Setting::aggregate_multidimensional() WP\_Customize\_Setting::aggregate\_multidimensional() ===================================================== Set up the setting for aggregated multidimensional values. When a multidimensional setting gets aggregated, all of its preview and update calls get combined into one call, greatly improving performance. File: `wp-includes/class-wp-customize-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-setting.php/) ``` protected function aggregate_multidimensional() { $id_base = $this->id_data['base']; if ( ! isset( self::$aggregated_multidimensionals[ $this->type ] ) ) { self::$aggregated_multidimensionals[ $this->type ] = array(); } if ( ! isset( self::$aggregated_multidimensionals[ $this->type ][ $id_base ] ) ) { self::$aggregated_multidimensionals[ $this->type ][ $id_base ] = array( 'previewed_instances' => array(), // Calling preview() will add the $setting to the array. 'preview_applied_instances' => array(), // Flags for which settings have had their values applied. 'root_value' => $this->get_root_value( array() ), // Root value for initial state, manipulated by preview and update calls. ); } if ( ! empty( $this->id_data['keys'] ) ) { // Note the preview-applied flag is cleared at priority 9 to ensure it is cleared before a deferred-preview runs. add_action( "customize_post_value_set_{$this->id}", array( $this, '_clear_aggregated_multidimensional_preview_applied_flag' ), 9 ); $this->is_multidimensional_aggregated = true; } } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::get\_root\_value()](get_root_value) wp-includes/class-wp-customize-setting.php | Get the root value for a setting, especially for multidimensional ones. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | Used By | Description | | --- | --- | | [WP\_Customize\_Setting::\_\_construct()](__construct) wp-includes/class-wp-customize-setting.php | Constructor. | | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. | wordpress Walker_Comment::start_lvl( string $output, int $depth, array $args = array() ) Walker\_Comment::start\_lvl( string $output, int $depth, array $args = array() ) ================================================================================ Starts the list before the elements are added. * [Walker::start\_lvl()](../walker/start_lvl) `$output` string Required Used to append additional content (passed by reference). `$depth` int Optional Depth of the current comment. Default 0. `$args` array Optional Uses `'style'` argument for type of HTML list. Default: `array()` File: `wp-includes/class-walker-comment.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-comment.php/) ``` public function start_lvl( &$output, $depth = 0, $args = array() ) { $GLOBALS['comment_depth'] = $depth + 1; switch ( $args['style'] ) { case 'div': break; case 'ol': $output .= '<ol class="children">' . "\n"; break; case 'ul': default: $output .= '<ul class="children">' . "\n"; break; } } ``` | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress Walker_Comment::start_el( string $output, WP_Comment $data_object, int $depth, array $args = array(), int $current_object_id ) Walker\_Comment::start\_el( string $output, WP\_Comment $data\_object, int $depth, array $args = array(), int $current\_object\_id ) ==================================================================================================================================== Starts the element output. * [Walker::start\_el()](../walker/start_el) * [wp\_list\_comments()](../../functions/wp_list_comments) `$output` string Required Used to append additional content. Passed by reference. `$data_object` [WP\_Comment](../wp_comment) Required Comment data object. `$depth` int Optional Depth of the current comment in reference to parents. Default 0. `$args` array Optional An array of arguments. Default: `array()` `$current_object_id` int Optional ID of the current comment. Default 0. File: `wp-includes/class-walker-comment.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-comment.php/) ``` public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) { // Restores the more descriptive, specific name for use within this method. $comment = $data_object; $depth++; $GLOBALS['comment_depth'] = $depth; $GLOBALS['comment'] = $comment; if ( ! empty( $args['callback'] ) ) { ob_start(); call_user_func( $args['callback'], $comment, $args, $depth ); $output .= ob_get_clean(); return; } if ( 'comment' === $comment->comment_type ) { add_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 ); } if ( ( 'pingback' === $comment->comment_type || 'trackback' === $comment->comment_type ) && $args['short_ping'] ) { ob_start(); $this->ping( $comment, $depth, $args ); $output .= ob_get_clean(); } elseif ( 'html5' === $args['format'] ) { ob_start(); $this->html5_comment( $comment, $depth, $args ); $output .= ob_get_clean(); } else { ob_start(); $this->comment( $comment, $depth, $args ); $output .= ob_get_clean(); } if ( 'comment' === $comment->comment_type ) { remove_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40 ); } } ``` | Uses | Description | | --- | --- | | [Walker\_Comment::html5\_comment()](html5_comment) wp-includes/class-walker-comment.php | Outputs a comment in the HTML5 format. | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [Walker\_Comment::comment()](comment) wp-includes/class-walker-comment.php | Outputs a single comment. | | [Walker\_Comment::ping()](ping) wp-includes/class-walker-comment.php | Outputs a pingback comment. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$comment` to `$data_object` and `$id` to `$current_object_id` to match parent class for PHP 8 named parameter support. | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress Walker_Comment::ping( WP_Comment $comment, int $depth, array $args ) Walker\_Comment::ping( WP\_Comment $comment, int $depth, array $args ) ====================================================================== Outputs a pingback comment. * [wp\_list\_comments()](../../functions/wp_list_comments) `$comment` [WP\_Comment](../wp_comment) Required The comment object. `$depth` int Required Depth of the current comment. `$args` array Required An array of arguments. File: `wp-includes/class-walker-comment.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-comment.php/) ``` protected function ping( $comment, $depth, $args ) { $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; ?> <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( '', $comment ); ?>> <div class="comment-body"> <?php _e( 'Pingback:' ); ?> <?php comment_author_link( $comment ); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?> </div> <?php } ``` | Uses | Description | | --- | --- | | [edit\_comment\_link()](../../functions/edit_comment_link) wp-includes/link-template.php | Displays the edit comment link with formatting. | | [comment\_ID()](../../functions/comment_id) wp-includes/comment-template.php | Displays the comment ID of the current comment. | | [comment\_class()](../../functions/comment_class) wp-includes/comment-template.php | Generates semantic classes for each comment element. | | [comment\_author\_link()](../../functions/comment_author_link) wp-includes/comment-template.php | Displays the HTML link to the URL of the author of the current comment. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [Walker\_Comment::start\_el()](start_el) wp-includes/class-walker-comment.php | Starts the element output. | | Version | Description | | --- | --- | | [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. |
programming_docs
wordpress Walker_Comment::display_element( WP_Comment $element, array $children_elements, int $max_depth, int $depth, array $args, string $output ) Walker\_Comment::display\_element( WP\_Comment $element, array $children\_elements, int $max\_depth, int $depth, array $args, string $output ) ============================================================================================================================================== Traverses elements to create list from elements. This function is designed to enhance [Walker::display\_element()](../walker/display_element) to display children of higher nesting levels than selected inline on the highest depth level displayed. This prevents them being orphaned at the end of the comment list. Example: max\_depth = 2, with 5 levels of nested content. 1 1.1 1.1.1 1.1.1.1 1.1.1.1.1 1.1.2 1.1.2.1 2 2.2 * [Walker::display\_element()](../walker/display_element) * [wp\_list\_comments()](../../functions/wp_list_comments) `$element` [WP\_Comment](../wp_comment) Required Comment data object. `$children_elements` array Required List of elements to continue traversing. Passed by reference. `$max_depth` int Required Max depth to traverse. `$depth` int Required Depth of the current element. `$args` array Required An array of arguments. `$output` string Required Used to append additional content. Passed by reference. File: `wp-includes/class-walker-comment.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-comment.php/) ``` public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { if ( ! $element ) { return; } $id_field = $this->db_fields['id']; $id = $element->$id_field; parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); /* * If at the max depth, and the current element still has children, loop over those * and display them at this level. This is to prevent them being orphaned to the end * of the list. */ if ( $max_depth <= $depth + 1 && isset( $children_elements[ $id ] ) ) { foreach ( $children_elements[ $id ] as $child ) { $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output ); } unset( $children_elements[ $id ] ); } } ``` | Uses | Description | | --- | --- | | [Walker::display\_element()](../walker/display_element) wp-includes/class-wp-walker.php | Traverses elements to create list from elements. | | [Walker\_Comment::display\_element()](display_element) wp-includes/class-walker-comment.php | Traverses elements to create list from elements. | | Used By | Description | | --- | --- | | [Walker\_Comment::display\_element()](display_element) wp-includes/class-walker-comment.php | Traverses elements to create list from elements. | | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress Walker_Comment::end_lvl( string $output, int $depth, array $args = array() ) Walker\_Comment::end\_lvl( string $output, int $depth, array $args = array() ) ============================================================================== Ends the list of items after the elements are added. * [Walker::end\_lvl()](../walker/end_lvl) `$output` string Required Used to append additional content (passed by reference). `$depth` int Optional Depth of the current comment. Default 0. `$args` array Optional Will only append content if style argument value is `'ol'` or `'ul'`. Default: `array()` File: `wp-includes/class-walker-comment.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-comment.php/) ``` public function end_lvl( &$output, $depth = 0, $args = array() ) { $GLOBALS['comment_depth'] = $depth + 1; switch ( $args['style'] ) { case 'div': break; case 'ol': $output .= "</ol><!-- .children -->\n"; break; case 'ul': default: $output .= "</ul><!-- .children -->\n"; break; } } ``` | Version | Description | | --- | --- | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress Walker_Comment::html5_comment( WP_Comment $comment, int $depth, array $args ) Walker\_Comment::html5\_comment( WP\_Comment $comment, int $depth, array $args ) ================================================================================ Outputs a comment in the HTML5 format. * [wp\_list\_comments()](../../functions/wp_list_comments) `$comment` [WP\_Comment](../wp_comment) Required Comment to display. `$depth` int Required Depth of the current comment. `$args` array Required An array of arguments. File: `wp-includes/class-walker-comment.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-comment.php/) ``` protected function html5_comment( $comment, $depth, $args ) { $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; $commenter = wp_get_current_commenter(); $show_pending_links = ! empty( $commenter['comment_author'] ); if ( $commenter['comment_author_email'] ) { $moderation_note = __( 'Your comment is awaiting moderation.' ); } else { $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.' ); } ?> <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>> <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> <footer class="comment-meta"> <div class="comment-author vcard"> <?php if ( 0 != $args['avatar_size'] ) { echo get_avatar( $comment, $args['avatar_size'] ); } ?> <?php $comment_author = get_comment_author_link( $comment ); if ( '0' == $comment->comment_approved && ! $show_pending_links ) { $comment_author = get_comment_author( $comment ); } printf( /* translators: %s: Comment author link. */ __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', $comment_author ) ); ?> </div><!-- .comment-author --> <div class="comment-metadata"> <?php printf( '<a href="%s"><time datetime="%s">%s</time></a>', esc_url( get_comment_link( $comment, $args ) ), get_comment_time( 'c' ), sprintf( /* translators: 1: Comment date, 2: Comment time. */ __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() ) ); edit_comment_link( __( 'Edit' ), ' <span class="edit-link">', '</span>' ); ?> </div><!-- .comment-metadata --> <?php if ( '0' == $comment->comment_approved ) : ?> <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em> <?php endif; ?> </footer><!-- .comment-meta --> <div class="comment-content"> <?php comment_text(); ?> </div><!-- .comment-content --> <?php if ( '1' == $comment->comment_approved || $show_pending_links ) { comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => '<div class="reply">', 'after' => '</div>', ) ) ); } ?> </article><!-- .comment-body --> <?php } ``` | Uses | Description | | --- | --- | | [get\_avatar()](../../functions/get_avatar) wp-includes/pluggable.php | Retrieves the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post. | | [edit\_comment\_link()](../../functions/edit_comment_link) wp-includes/link-template.php | Displays the edit comment link with formatting. | | [comment\_reply\_link()](../../functions/comment_reply_link) wp-includes/comment-template.php | Displays the HTML content for reply to comment link. | | [comment\_ID()](../../functions/comment_id) wp-includes/comment-template.php | Displays the comment ID of the current comment. | | [get\_comment\_link()](../../functions/get_comment_link) wp-includes/comment-template.php | Retrieves the link to a given comment. | | [get\_comment\_time()](../../functions/get_comment_time) wp-includes/comment-template.php | Retrieves the comment time of the current comment. | | [comment\_text()](../../functions/comment_text) wp-includes/comment-template.php | Displays the text of the current comment. | | [comment\_class()](../../functions/comment_class) wp-includes/comment-template.php | Generates semantic classes for each comment element. | | [get\_comment\_date()](../../functions/get_comment_date) wp-includes/comment-template.php | Retrieves the comment date of the current comment. | | [get\_comment\_author\_link()](../../functions/get_comment_author_link) wp-includes/comment-template.php | Retrieves the HTML link to the URL of the author of the current comment. | | [get\_comment\_author()](../../functions/get_comment_author) wp-includes/comment-template.php | Retrieves the author of the current comment. | | [wp\_get\_current\_commenter()](../../functions/wp_get_current_commenter) wp-includes/comment.php | Gets current commenter’s name, email, and URL. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | Used By | Description | | --- | --- | | [Walker\_Comment::start\_el()](start_el) wp-includes/class-walker-comment.php | Starts the element output. | | Version | Description | | --- | --- | | [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. | wordpress Walker_Comment::filter_comment_text( string $comment_text, WP_Comment|null $comment ): string Walker\_Comment::filter\_comment\_text( string $comment\_text, WP\_Comment|null $comment ): string ================================================================================================== Filters the comment text. Removes links from the pending comment’s text if the commenter did not consent to the comment cookies. `$comment_text` string Required Text of the current comment. `$comment` [WP\_Comment](../wp_comment)|null Required The comment object. Null if not found. string Filtered text of the current comment. File: `wp-includes/class-walker-comment.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-comment.php/) ``` public function filter_comment_text( $comment_text, $comment ) { $commenter = wp_get_current_commenter(); $show_pending_links = ! empty( $commenter['comment_author'] ); if ( $comment && '0' == $comment->comment_approved && ! $show_pending_links ) { $comment_text = wp_kses( $comment_text, array() ); } return $comment_text; } ``` | Uses | Description | | --- | --- | | [wp\_kses()](../../functions/wp_kses) wp-includes/kses.php | Filters text content and strips out disallowed HTML. | | [wp\_get\_current\_commenter()](../../functions/wp_get_current_commenter) wp-includes/comment.php | Gets current commenter’s name, email, and URL. | | Version | Description | | --- | --- | | [5.4.2](https://developer.wordpress.org/reference/since/5.4.2/) | Introduced. | wordpress Walker_Comment::comment( WP_Comment $comment, int $depth, array $args ) Walker\_Comment::comment( WP\_Comment $comment, int $depth, array $args ) ========================================================================= Outputs a single comment. * [wp\_list\_comments()](../../functions/wp_list_comments) `$comment` [WP\_Comment](../wp_comment) Required Comment to display. `$depth` int Required Depth of the current comment. `$args` array Required An array of arguments. File: `wp-includes/class-walker-comment.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-comment.php/) ``` protected function comment( $comment, $depth, $args ) { if ( 'div' === $args['style'] ) { $tag = 'div'; $add_below = 'comment'; } else { $tag = 'li'; $add_below = 'div-comment'; } $commenter = wp_get_current_commenter(); $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author']; if ( $commenter['comment_author_email'] ) { $moderation_note = __( 'Your comment is awaiting moderation.' ); } else { $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.' ); } ?> <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>"> <?php if ( 'div' !== $args['style'] ) : ?> <div id="div-comment-<?php comment_ID(); ?>" class="comment-body"> <?php endif; ?> <div class="comment-author vcard"> <?php if ( 0 != $args['avatar_size'] ) { echo get_avatar( $comment, $args['avatar_size'] ); } ?> <?php $comment_author = get_comment_author_link( $comment ); if ( '0' == $comment->comment_approved && ! $show_pending_links ) { $comment_author = get_comment_author( $comment ); } printf( /* translators: %s: Comment author link. */ __( '%s <span class="says">says:</span>' ), sprintf( '<cite class="fn">%s</cite>', $comment_author ) ); ?> </div> <?php if ( '0' == $comment->comment_approved ) : ?> <em class="comment-awaiting-moderation"><?php echo $moderation_note; ?></em> <br /> <?php endif; ?> <div class="comment-meta commentmetadata"> <?php printf( '<a href="%s">%s</a>', esc_url( get_comment_link( $comment, $args ) ), sprintf( /* translators: 1: Comment date, 2: Comment time. */ __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() ) ); edit_comment_link( __( '(Edit)' ), ' &nbsp;&nbsp;', '' ); ?> </div> <?php comment_text( $comment, array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'], ) ) ); ?> <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => '<div class="reply">', 'after' => '</div>', ) ) ); ?> <?php if ( 'div' !== $args['style'] ) : ?> </div> <?php endif; ?> <?php } ``` | Uses | Description | | --- | --- | | [get\_avatar()](../../functions/get_avatar) wp-includes/pluggable.php | Retrieves the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post. | | [edit\_comment\_link()](../../functions/edit_comment_link) wp-includes/link-template.php | Displays the edit comment link with formatting. | | [comment\_reply\_link()](../../functions/comment_reply_link) wp-includes/comment-template.php | Displays the HTML content for reply to comment link. | | [comment\_ID()](../../functions/comment_id) wp-includes/comment-template.php | Displays the comment ID of the current comment. | | [get\_comment\_link()](../../functions/get_comment_link) wp-includes/comment-template.php | Retrieves the link to a given comment. | | [get\_comment\_time()](../../functions/get_comment_time) wp-includes/comment-template.php | Retrieves the comment time of the current comment. | | [comment\_text()](../../functions/comment_text) wp-includes/comment-template.php | Displays the text of the current comment. | | [comment\_class()](../../functions/comment_class) wp-includes/comment-template.php | Generates semantic classes for each comment element. | | [get\_comment\_date()](../../functions/get_comment_date) wp-includes/comment-template.php | Retrieves the comment date of the current comment. | | [get\_comment\_author\_link()](../../functions/get_comment_author_link) wp-includes/comment-template.php | Retrieves the HTML link to the URL of the author of the current comment. | | [get\_comment\_author()](../../functions/get_comment_author) wp-includes/comment-template.php | Retrieves the author of the current comment. | | [wp\_get\_current\_commenter()](../../functions/wp_get_current_commenter) wp-includes/comment.php | Gets current commenter’s name, email, and URL. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | Used By | Description | | --- | --- | | [Walker\_Comment::start\_el()](start_el) wp-includes/class-walker-comment.php | Starts the element output. | | Version | Description | | --- | --- | | [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. | wordpress Walker_Comment::end_el( string $output, WP_Comment $data_object, int $depth, array $args = array() ) Walker\_Comment::end\_el( string $output, WP\_Comment $data\_object, int $depth, array $args = array() ) ======================================================================================================== Ends the element output, if needed. * [Walker::end\_el()](../walker/end_el) * [wp\_list\_comments()](../../functions/wp_list_comments) `$output` string Required Used to append additional content. Passed by reference. `$data_object` [WP\_Comment](../wp_comment) Required Comment data object. `$depth` int Optional Depth of the current comment. Default 0. `$args` array Optional An array of arguments. Default: `array()` File: `wp-includes/class-walker-comment.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-walker-comment.php/) ``` public function end_el( &$output, $data_object, $depth = 0, $args = array() ) { if ( ! empty( $args['end-callback'] ) ) { ob_start(); call_user_func( $args['end-callback'], $data_object, // The current comment object. $args, $depth ); $output .= ob_get_clean(); return; } if ( 'div' === $args['style'] ) { $output .= "</div><!-- #comment-## -->\n"; } else { $output .= "</li><!-- #comment-## -->\n"; } } ``` | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$comment` to `$data_object` to match parent class for PHP 8 named parameter support. | | [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. | wordpress Core_Upgrader::upgrade( object $current, array $args = array() ): string|false|WP_Error Core\_Upgrader::upgrade( object $current, array $args = array() ): string|false|WP\_Error ========================================================================================= Upgrade WordPress core. `$current` object Required Response object for whether WordPress is current. `$args` array Optional Arguments for upgrading WordPress core. * `pre_check_md5`boolWhether to check the file checksums before attempting the upgrade. Default true. * `attempt_rollback`boolWhether to attempt to rollback the chances if there is a problem. Default false. * `do_rollback`boolWhether to perform this "upgrade" as a rollback. Default false. Default: `array()` string|false|[WP\_Error](../wp_error) New WordPress version on success, false or [WP\_Error](../wp_error) on failure. File: `wp-admin/includes/class-core-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-core-upgrader.php/) ``` public function upgrade( $current, $args = array() ) { global $wp_filesystem; require ABSPATH . WPINC . '/version.php'; // $wp_version; $start_time = time(); $defaults = array( 'pre_check_md5' => true, 'attempt_rollback' => false, 'do_rollback' => false, 'allow_relaxed_file_ownership' => false, ); $parsed_args = wp_parse_args( $args, $defaults ); $this->init(); $this->upgrade_strings(); // Is an update available? if ( ! isset( $current->response ) || 'latest' === $current->response ) { return new WP_Error( 'up_to_date', $this->strings['up_to_date'] ); } $res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] ); if ( ! $res || is_wp_error( $res ) ) { return $res; } $wp_dir = trailingslashit( $wp_filesystem->abspath() ); $partial = true; if ( $parsed_args['do_rollback'] ) { $partial = false; } elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) { $partial = false; } /* * If partial update is returned from the API, use that, unless we're doing * a reinstallation. If we cross the new_bundled version number, then use * the new_bundled zip. Don't though if the constant is set to skip bundled items. * If the API returns a no_content zip, go with it. Finally, default to the full zip. */ if ( $parsed_args['do_rollback'] && $current->packages->rollback ) { $to_download = 'rollback'; } elseif ( $current->packages->partial && 'reinstall' !== $current->response && $wp_version === $current->partial_version && $partial ) { $to_download = 'partial'; } elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' ) && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) { $to_download = 'new_bundled'; } elseif ( $current->packages->no_content ) { $to_download = 'no_content'; } else { $to_download = 'full'; } // Lock to prevent multiple Core Updates occurring. $lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS ); if ( ! $lock ) { return new WP_Error( 'locked', $this->strings['locked'] ); } $download = $this->download_package( $current->packages->$to_download, true ); // Allow for signature soft-fail. // WARNING: This may be removed in the future. if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) { // Output the failure error as a normal feedback, and not as an error: /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', $download->get_error_message() ); // Report this failure back to WordPress.org for debugging purposes. wp_version_check( array( 'signature_failure_code' => $download->get_error_code(), 'signature_failure_data' => $download->get_error_data(), ) ); // Pretend this error didn't happen. $download = $download->get_error_data( 'softfail-filename' ); } if ( is_wp_error( $download ) ) { WP_Upgrader::release_lock( 'core_updater' ); return $download; } $working_dir = $this->unpack_package( $download ); if ( is_wp_error( $working_dir ) ) { WP_Upgrader::release_lock( 'core_updater' ); return $working_dir; } // Copy update-core.php from the new version into place. if ( ! $wp_filesystem->copy( $working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true ) ) { $wp_filesystem->delete( $working_dir, true ); WP_Upgrader::release_lock( 'core_updater' ); return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php' ); } $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE ); wp_opcache_invalidate( ABSPATH . 'wp-admin/includes/update-core.php' ); require_once ABSPATH . 'wp-admin/includes/update-core.php'; if ( ! function_exists( 'update_core' ) ) { WP_Upgrader::release_lock( 'core_updater' ); return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] ); } $result = update_core( $working_dir, $wp_dir ); // In the event of an issue, we may be able to roll back. if ( $parsed_args['attempt_rollback'] && $current->packages->rollback && ! $parsed_args['do_rollback'] ) { $try_rollback = false; if ( is_wp_error( $result ) ) { $error_code = $result->get_error_code(); /* * Not all errors are equal. These codes are critical: copy_failed__copy_dir, * mkdir_failed__copy_dir, copy_failed__copy_dir_retry, and disk_full. * do_rollback allows for update_core() to trigger a rollback if needed. */ if ( false !== strpos( $error_code, 'do_rollback' ) ) { $try_rollback = true; } elseif ( false !== strpos( $error_code, '__copy_dir' ) ) { $try_rollback = true; } elseif ( 'disk_full' === $error_code ) { $try_rollback = true; } } if ( $try_rollback ) { /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', $result ); /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', $this->strings['start_rollback'] ); $rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) ); $original_result = $result; $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'], (object) array( 'update' => $original_result, 'rollback' => $rollback_result, ) ); } } /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core', ) ); // Clear the current updates. delete_site_transient( 'update_core' ); if ( ! $parsed_args['do_rollback'] ) { $stats = array( 'update_type' => $current->response, 'success' => true, 'fs_method' => $wp_filesystem->method, 'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ), 'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '', 'time_taken' => time() - $start_time, 'reported' => $wp_version, 'attempted' => $current->version, ); if ( is_wp_error( $result ) ) { $stats['success'] = false; // Did a rollback occur? if ( ! empty( $try_rollback ) ) { $stats['error_code'] = $original_result->get_error_code(); $stats['error_data'] = $original_result->get_error_data(); // Was the rollback successful? If not, collect its error too. $stats['rollback'] = ! is_wp_error( $rollback_result ); if ( is_wp_error( $rollback_result ) ) { $stats['rollback_code'] = $rollback_result->get_error_code(); $stats['rollback_data'] = $rollback_result->get_error_data(); } } else { $stats['error_code'] = $result->get_error_code(); $stats['error_data'] = $result->get_error_data(); } } wp_version_check( $stats ); } WP_Upgrader::release_lock( 'core_updater' ); return $result; } ``` [apply\_filters( 'update\_feedback', string $feedback )](../../hooks/update_feedback) Filters feedback messages displayed during the core update process. [do\_action( 'upgrader\_process\_complete', WP\_Upgrader $upgrader, array $hook\_extra )](../../hooks/upgrader_process_complete) Fires when the upgrader process is complete. | Uses | Description | | --- | --- | | [wp\_opcache\_invalidate()](../../functions/wp_opcache_invalidate) wp-admin/includes/file.php | Attempts to clear the opcode cache for an individual PHP file. | | [has\_filter()](../../functions/has_filter) wp-includes/plugin.php | Checks if any filter has been registered for a hook. | | [WP\_Upgrader::release\_lock()](../wp_upgrader/release_lock) wp-admin/includes/class-wp-upgrader.php | Releases an upgrader lock. | | [Core\_Upgrader::check\_files()](check_files) wp-admin/includes/class-core-upgrader.php | Compare the disk file checksums against the expected checksums. | | [Core\_Upgrader::upgrade\_strings()](upgrade_strings) wp-admin/includes/class-core-upgrader.php | Initialize the upgrade strings. | | [Core\_Upgrader::upgrade()](upgrade) wp-admin/includes/class-core-upgrader.php | Upgrade WordPress core. | | [update\_core()](../../functions/update_core) wp-admin/includes/update-core.php | Upgrades the core of WordPress. | | [WP\_Upgrader::create\_lock()](../wp_upgrader/create_lock) wp-admin/includes/class-wp-upgrader.php | Creates a lock using WordPress options. | | [delete\_site\_transient()](../../functions/delete_site_transient) wp-includes/option.php | Deletes a site transient. | | [wp\_version\_check()](../../functions/wp_version_check) wp-includes/update.php | Checks WordPress version against the newest version. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [trailingslashit()](../../functions/trailingslashit) wp-includes/formatting.php | Appends a trailing slash. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [Core\_Upgrader::upgrade()](upgrade) wp-admin/includes/class-core-upgrader.php | Upgrade WordPress core. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |
programming_docs
wordpress Core_Upgrader::upgrade_strings() Core\_Upgrader::upgrade\_strings() ================================== Initialize the upgrade strings. File: `wp-admin/includes/class-core-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-core-upgrader.php/) ``` public function upgrade_strings() { $this->strings['up_to_date'] = __( 'WordPress is at the latest version.' ); $this->strings['locked'] = __( 'Another update is currently in progress.' ); $this->strings['no_package'] = __( 'Update package not available.' ); /* translators: %s: Package URL. */ $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' ); $this->strings['unpack_package'] = __( 'Unpacking the update&#8230;' ); $this->strings['copy_failed'] = __( 'Could not copy files.' ); $this->strings['copy_failed_space'] = __( 'Could not copy files. You may have run out of disk space.' ); $this->strings['start_rollback'] = __( 'Attempting to roll back to previous version.' ); $this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has rolled back to your previous version.' ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [Core\_Upgrader::upgrade()](upgrade) wp-admin/includes/class-core-upgrader.php | Upgrade WordPress core. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress Core_Upgrader::should_update_to_version( string $offered_ver ): bool Core\_Upgrader::should\_update\_to\_version( string $offered\_ver ): bool ========================================================================= Determines if this WordPress Core version should update to an offered version or not. `$offered_ver` string Required The offered version, of the format x.y.z. bool True if we should update to the offered version, otherwise false. File: `wp-admin/includes/class-core-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-core-upgrader.php/) ``` public static function should_update_to_version( $offered_ver ) { require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y $current_is_development_version = (bool) strpos( $wp_version, '-' ); // Defaults: $upgrade_dev = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled'; $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled'; $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled'; // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false. if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { if ( false === WP_AUTO_UPDATE_CORE ) { // Defaults to turned off, unless a filter allows it. $upgrade_dev = false; $upgrade_minor = false; $upgrade_major = false; } elseif ( true === WP_AUTO_UPDATE_CORE || in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true ) ) { // ALL updates for core. $upgrade_dev = true; $upgrade_minor = true; $upgrade_major = true; } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) { // Only minor updates for core. $upgrade_dev = false; $upgrade_minor = true; $upgrade_major = false; } } // 1: If we're already on that version, not much point in updating? if ( $offered_ver === $wp_version ) { return false; } // 2: If we're running a newer version, that's a nope. if ( version_compare( $wp_version, $offered_ver, '>' ) ) { return false; } $failure_data = get_site_option( 'auto_core_update_failed' ); if ( $failure_data ) { // If this was a critical update failure, cannot update. if ( ! empty( $failure_data['critical'] ) ) { return false; } // Don't claim we can update on update-core.php if we have a non-critical failure logged. if ( $wp_version === $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) { return false; } /* * Cannot update if we're retrying the same A to B update that caused a non-critical failure. * Some non-critical failures do allow retries, like download_failed. * 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2. */ if ( empty( $failure_data['retry'] ) && $wp_version === $failure_data['current'] && $offered_ver === $failure_data['attempted'] ) { return false; } } // 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2. if ( $current_is_development_version ) { /** * Filters whether to enable automatic core updates for development versions. * * @since 3.7.0 * * @param bool $upgrade_dev Whether to enable automatic updates for * development versions. */ if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) { return false; } // Else fall through to minor + major branches below. } // 4: Minor in-branch updates (3.7.0 -> 3.7.1 -> 3.7.2 -> 3.7.4). if ( $current_branch === $new_branch ) { /** * Filters whether to enable minor automatic core updates. * * @since 3.7.0 * * @param bool $upgrade_minor Whether to enable minor automatic core updates. */ return apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor ); } // 5: Major version updates (3.7.0 -> 3.8.0 -> 3.9.1). if ( version_compare( $new_branch, $current_branch, '>' ) ) { /** * Filters whether to enable major automatic core updates. * * @since 3.7.0 * * @param bool $upgrade_major Whether to enable major automatic core updates. */ return apply_filters( 'allow_major_auto_core_updates', $upgrade_major ); } // If we're not sure, we don't want it. return false; } ``` [apply\_filters( 'allow\_dev\_auto\_core\_updates', bool $upgrade\_dev )](../../hooks/allow_dev_auto_core_updates) Filters whether to enable automatic core updates for development versions. [apply\_filters( 'allow\_major\_auto\_core\_updates', bool $upgrade\_major )](../../hooks/allow_major_auto_core_updates) Filters whether to enable major automatic core updates. [apply\_filters( 'allow\_minor\_auto\_core\_updates', bool $upgrade\_minor )](../../hooks/allow_minor_auto_core_updates) Filters whether to enable minor automatic core updates. | Uses | Description | | --- | --- | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_site\_option()](../../functions/get_site_option) wp-includes/option.php | Retrieve an option value for the current network based on name of option. | | Used By | Description | | --- | --- | | [WP\_Automatic\_Updater::should\_update()](../wp_automatic_updater/should_update) wp-admin/includes/class-wp-automatic-updater.php | Tests to see if we can and should update a specific item. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress Core_Upgrader::check_files(): bool Core\_Upgrader::check\_files(): bool ==================================== Compare the disk file checksums against the expected checksums. bool True if the checksums match, otherwise false. File: `wp-admin/includes/class-core-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-core-upgrader.php/) ``` public function check_files() { global $wp_version, $wp_local_package; $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' ); if ( ! is_array( $checksums ) ) { return false; } foreach ( $checksums as $file => $checksum ) { // Skip files which get updated. if ( 'wp-content' === substr( $file, 0, 10 ) ) { continue; } if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) { return false; } } return true; } ``` | Uses | Description | | --- | --- | | [get\_core\_checksums()](../../functions/get_core_checksums) wp-admin/includes/update.php | Gets and caches the checksums for the given version of WordPress. | | Used By | Description | | --- | --- | | [Core\_Upgrader::upgrade()](upgrade) wp-admin/includes/class-core-upgrader.php | Upgrade WordPress core. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress WP_Session_Tokens::drop_sessions() WP\_Session\_Tokens::drop\_sessions() ===================================== Destroys all sessions for all users. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` public static function drop_sessions() {} ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::destroy_all_for_all_users() WP\_Session\_Tokens::destroy\_all\_for\_all\_users() ==================================================== Destroys all sessions for all users. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public static function destroy_all_for_all_users() { /** This filter is documented in wp-includes/class-wp-session-tokens.php */ $manager = apply_filters( 'session_token_manager', 'WP_User_Meta_Session_Tokens' ); call_user_func( array( $manager, 'drop_sessions' ) ); } ``` [apply\_filters( 'session\_token\_manager', string $session )](../../hooks/session_token_manager) Filters the class name for the session token manager. | Uses | Description | | --- | --- | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::get_all(): array WP\_Session\_Tokens::get\_all(): array ====================================== Retrieves all sessions for a user. array Sessions for a user. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public function get_all() { return array_values( $this->get_sessions() ); } ``` | Uses | Description | | --- | --- | | [WP\_Session\_Tokens::get\_sessions()](get_sessions) wp-includes/class-wp-session-tokens.php | Retrieves all sessions of the user. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::update( string $token, array $session ) WP\_Session\_Tokens::update( string $token, array $session ) ============================================================ Updates the data for the session with the given token. `$token` string Required Session token to update. `$session` array Required Session information. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public function update( $token, $session ) { $verifier = $this->hash_token( $token ); $this->update_session( $verifier, $session ); } ``` | Uses | Description | | --- | --- | | [WP\_Session\_Tokens::update\_session()](update_session) wp-includes/class-wp-session-tokens.php | Updates a session based on its verifier (token hash). | | [WP\_Session\_Tokens::hash\_token()](hash_token) wp-includes/class-wp-session-tokens.php | Hashes the given session token for storage. | | Used By | Description | | --- | --- | | [WP\_Session\_Tokens::create()](create) wp-includes/class-wp-session-tokens.php | Generates a session token and attaches session information to it. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::hash_token( string $token ): string WP\_Session\_Tokens::hash\_token( string $token ): string ========================================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Hashes the given session token for storage. `$token` string Required Session token to hash. string A hash of the session token (a verifier). File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` private function hash_token( $token ) { // If ext/hash is not present, use sha1() instead. if ( function_exists( 'hash' ) ) { return hash( 'sha256', $token ); } else { return sha1( $token ); } } ``` | Used By | Description | | --- | --- | | [WP\_Session\_Tokens::get()](get) wp-includes/class-wp-session-tokens.php | Retrieves a user’s session for the given token. | | [WP\_Session\_Tokens::verify()](verify) wp-includes/class-wp-session-tokens.php | Validates the given session token for authenticity and validity. | | [WP\_Session\_Tokens::update()](update) wp-includes/class-wp-session-tokens.php | Updates the data for the session with the given token. | | [WP\_Session\_Tokens::destroy()](destroy) wp-includes/class-wp-session-tokens.php | Destroys the session with the given token. | | [WP\_Session\_Tokens::destroy\_others()](destroy_others) wp-includes/class-wp-session-tokens.php | Destroys all sessions for this user except the one with the given token (presumably the one in use). | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::destroy_all() WP\_Session\_Tokens::destroy\_all() =================================== Destroys all sessions for a user. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public function destroy_all() { $this->destroy_all_sessions(); } ``` | Uses | Description | | --- | --- | | [WP\_Session\_Tokens::destroy\_all\_sessions()](destroy_all_sessions) wp-includes/class-wp-session-tokens.php | Destroys all sessions for the user. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::get_session( string $verifier ): array|null WP\_Session\_Tokens::get\_session( string $verifier ): array|null ================================================================= Retrieves a session based on its verifier (token hash). `$verifier` string Required Verifier for the session to retrieve. array|null The session, or null if it does not exist. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` abstract protected function get_session( $verifier ); ``` | Used By | Description | | --- | --- | | [WP\_Session\_Tokens::get()](get) wp-includes/class-wp-session-tokens.php | Retrieves a user’s session for the given token. | | [WP\_Session\_Tokens::verify()](verify) wp-includes/class-wp-session-tokens.php | Validates the given session token for authenticity and validity. | | [WP\_Session\_Tokens::destroy\_others()](destroy_others) wp-includes/class-wp-session-tokens.php | Destroys all sessions for this user except the one with the given token (presumably the one in use). | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::destroy_other_sessions( string $verifier ) WP\_Session\_Tokens::destroy\_other\_sessions( string $verifier ) ================================================================= Destroys all sessions for this user, except the single session with the given verifier. `$verifier` string Required Verifier of the session to keep. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` abstract protected function destroy_other_sessions( $verifier ); ``` | Used By | Description | | --- | --- | | [WP\_Session\_Tokens::destroy\_others()](destroy_others) wp-includes/class-wp-session-tokens.php | Destroys all sessions for this user except the one with the given token (presumably the one in use). | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::create( int $expiration ): string WP\_Session\_Tokens::create( int $expiration ): string ====================================================== Generates a session token and attaches session information to it. A session token is a long, random string. It is used in a cookie to link that cookie to an expiration time and to ensure the cookie becomes invalidated when the user logs out. This function generates a token and stores it with the associated expiration time (and potentially other session information via the [‘attach\_session\_information’](../../hooks/attach_session_information) filter). `$expiration` int Required Session expiration timestamp. string Session token. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public function create( $expiration ) { /** * Filters the information attached to the newly created session. * * Can be used to attach further information to a session. * * @since 4.0.0 * * @param array $session Array of extra data. * @param int $user_id User ID. */ $session = apply_filters( 'attach_session_information', array(), $this->user_id ); $session['expiration'] = $expiration; // IP address. if ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) { $session['ip'] = $_SERVER['REMOTE_ADDR']; } // User-agent. if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { $session['ua'] = wp_unslash( $_SERVER['HTTP_USER_AGENT'] ); } // Timestamp. $session['login'] = time(); $token = wp_generate_password( 43, false, false ); $this->update( $token, $session ); return $token; } ``` [apply\_filters( 'attach\_session\_information', array $session, int $user\_id )](../../hooks/attach_session_information) Filters the information attached to the newly created session. | Uses | Description | | --- | --- | | [WP\_Session\_Tokens::update()](update) wp-includes/class-wp-session-tokens.php | Updates the data for the session with the given token. | | [wp\_generate\_password()](../../functions/wp_generate_password) wp-includes/pluggable.php | Generates a random password drawn from the defined set of characters. | | [wp\_unslash()](../../functions/wp_unslash) wp-includes/formatting.php | Removes slashes from a string or recursively removes slashes from strings within an array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. |
programming_docs
wordpress WP_Session_Tokens::is_still_valid( array $session ): bool WP\_Session\_Tokens::is\_still\_valid( array $session ): bool ============================================================= Determines whether a session is still valid, based on its expiration timestamp. `$session` array Required Session to check. bool Whether session is valid. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final protected function is_still_valid( $session ) { return $session['expiration'] >= time(); } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::destroy_all_sessions() WP\_Session\_Tokens::destroy\_all\_sessions() ============================================= Destroys all sessions for the user. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` abstract protected function destroy_all_sessions(); ``` | Used By | Description | | --- | --- | | [WP\_Session\_Tokens::destroy\_others()](destroy_others) wp-includes/class-wp-session-tokens.php | Destroys all sessions for this user except the one with the given token (presumably the one in use). | | [WP\_Session\_Tokens::destroy\_all()](destroy_all) wp-includes/class-wp-session-tokens.php | Destroys all sessions for a user. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::destroy_others( string $token_to_keep ) WP\_Session\_Tokens::destroy\_others( string $token\_to\_keep ) =============================================================== Destroys all sessions for this user except the one with the given token (presumably the one in use). `$token_to_keep` string Required Session token to keep. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public function destroy_others( $token_to_keep ) { $verifier = $this->hash_token( $token_to_keep ); $session = $this->get_session( $verifier ); if ( $session ) { $this->destroy_other_sessions( $verifier ); } else { $this->destroy_all_sessions(); } } ``` | Uses | Description | | --- | --- | | [WP\_Session\_Tokens::get\_session()](get_session) wp-includes/class-wp-session-tokens.php | Retrieves a session based on its verifier (token hash). | | [WP\_Session\_Tokens::destroy\_other\_sessions()](destroy_other_sessions) wp-includes/class-wp-session-tokens.php | Destroys all sessions for this user, except the single session with the given verifier. | | [WP\_Session\_Tokens::destroy\_all\_sessions()](destroy_all_sessions) wp-includes/class-wp-session-tokens.php | Destroys all sessions for the user. | | [WP\_Session\_Tokens::hash\_token()](hash_token) wp-includes/class-wp-session-tokens.php | Hashes the given session token for storage. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::destroy( string $token ) WP\_Session\_Tokens::destroy( string $token ) ============================================= Destroys the session with the given token. `$token` string Required Session token to destroy. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public function destroy( $token ) { $verifier = $this->hash_token( $token ); $this->update_session( $verifier, null ); } ``` | Uses | Description | | --- | --- | | [WP\_Session\_Tokens::update\_session()](update_session) wp-includes/class-wp-session-tokens.php | Updates a session based on its verifier (token hash). | | [WP\_Session\_Tokens::hash\_token()](hash_token) wp-includes/class-wp-session-tokens.php | Hashes the given session token for storage. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::get_sessions(): array WP\_Session\_Tokens::get\_sessions(): array =========================================== Retrieves all sessions of the user. array Sessions of the user. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` abstract protected function get_sessions(); ``` | Used By | Description | | --- | --- | | [WP\_Session\_Tokens::get\_all()](get_all) wp-includes/class-wp-session-tokens.php | Retrieves all sessions for a user. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::__construct( int $user_id ) WP\_Session\_Tokens::\_\_construct( int $user\_id ) =================================================== Protected constructor. Use the `get_instance()` method to get the instance. `$user_id` int Required User whose session to manage. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` protected function __construct( $user_id ) { $this->user_id = $user_id; } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::verify( string $token ): bool WP\_Session\_Tokens::verify( string $token ): bool ================================================== Validates the given session token for authenticity and validity. Checks that the given token is present and hasn’t expired. `$token` string Required Token to verify. bool Whether the token is valid for the user. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public function verify( $token ) { $verifier = $this->hash_token( $token ); return (bool) $this->get_session( $verifier ); } ``` | Uses | Description | | --- | --- | | [WP\_Session\_Tokens::get\_session()](get_session) wp-includes/class-wp-session-tokens.php | Retrieves a session based on its verifier (token hash). | | [WP\_Session\_Tokens::hash\_token()](hash_token) wp-includes/class-wp-session-tokens.php | Hashes the given session token for storage. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::get_instance( int $user_id ): WP_Session_Tokens WP\_Session\_Tokens::get\_instance( int $user\_id ): WP\_Session\_Tokens ======================================================================== Retrieves a session manager instance for a user. This method contains a [‘session\_token\_manager’](../../hooks/session_token_manager) filter, allowing a plugin to swap out the session manager for a subclass of `WP_Session_Tokens`. `$user_id` int Required User whose session to manage. [WP\_Session\_Tokens](../wp_session_tokens) The session object, which is by default an instance of the `WP_User_Meta_Session_Tokens` class. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public static function get_instance( $user_id ) { /** * Filters the class name for the session token manager. * * @since 4.0.0 * * @param string $session Name of class to use as the manager. * Default 'WP_User_Meta_Session_Tokens'. */ $manager = apply_filters( 'session_token_manager', 'WP_User_Meta_Session_Tokens' ); return new $manager( $user_id ); } ``` [apply\_filters( 'session\_token\_manager', string $session )](../../hooks/session_token_manager) Filters the class name for the session token manager. | Uses | Description | | --- | --- | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [wp\_ajax\_destroy\_sessions()](../../functions/wp_ajax_destroy_sessions) wp-admin/includes/ajax-actions.php | Ajax handler for destroying multiple open sessions for a user. | | [wp\_destroy\_all\_sessions()](../../functions/wp_destroy_all_sessions) wp-includes/user.php | Removes all session tokens for the current user from the database. | | [wp\_get\_all\_sessions()](../../functions/wp_get_all_sessions) wp-includes/user.php | Retrieves a list of sessions for the current user. | | [wp\_destroy\_current\_session()](../../functions/wp_destroy_current_session) wp-includes/user.php | Removes the current session token from the database. | | [wp\_destroy\_other\_sessions()](../../functions/wp_destroy_other_sessions) wp-includes/user.php | Removes all but the current session token for the current user for the database. | | [wp\_set\_auth\_cookie()](../../functions/wp_set_auth_cookie) wp-includes/pluggable.php | Sets the authentication cookies based on user ID. | | [wp\_validate\_auth\_cookie()](../../functions/wp_validate_auth_cookie) wp-includes/pluggable.php | Validates authentication cookie. | | [wp\_generate\_auth\_cookie()](../../functions/wp_generate_auth_cookie) wp-includes/pluggable.php | Generates authentication cookie contents. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::get( string $token ): array|null WP\_Session\_Tokens::get( string $token ): array|null ===================================================== Retrieves a user’s session for the given token. `$token` string Required Session token. array|null The session, or null if it does not exist. File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` final public function get( $token ) { $verifier = $this->hash_token( $token ); return $this->get_session( $verifier ); } ``` | Uses | Description | | --- | --- | | [WP\_Session\_Tokens::get\_session()](get_session) wp-includes/class-wp-session-tokens.php | Retrieves a session based on its verifier (token hash). | | [WP\_Session\_Tokens::hash\_token()](hash_token) wp-includes/class-wp-session-tokens.php | Hashes the given session token for storage. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Session_Tokens::update_session( string $verifier, array $session = null ) WP\_Session\_Tokens::update\_session( string $verifier, array $session = null ) =============================================================================== Updates a session based on its verifier (token hash). Omitting the second argument destroys the session. `$verifier` string Required Verifier for the session to update. `$session` array Optional Session. Omitting this argument destroys the session. Default: `null` File: `wp-includes/class-wp-session-tokens.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-session-tokens.php/) ``` abstract protected function update_session( $verifier, $session = null ); ``` | Used By | Description | | --- | --- | | [WP\_Session\_Tokens::update()](update) wp-includes/class-wp-session-tokens.php | Updates the data for the session with the given token. | | [WP\_Session\_Tokens::destroy()](destroy) wp-includes/class-wp-session-tokens.php | Destroys the session with the given token. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_Privacy_Data_Export_Requests_List_Table::column_email( WP_User_Request $item ): string WP\_Privacy\_Data\_Export\_Requests\_List\_Table::column\_email( WP\_User\_Request $item ): string ================================================================================================== Actions column. `$item` [WP\_User\_Request](../wp_user_request) Required Item being shown. string Email column markup. File: `wp-admin/includes/class-wp-privacy-data-export-requests-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-data-export-requests-list-table.php/) ``` public function column_email( $item ) { /** This filter is documented in wp-admin/includes/ajax-actions.php */ $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); $exporters_count = count( $exporters ); $status = $item->status; $request_id = $item->ID; $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); $download_data_markup = '<span class="export-personal-data" ' . 'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' . 'data-request-id="' . esc_attr( $request_id ) . '" ' . 'data-nonce="' . esc_attr( $nonce ) . '">'; $download_data_markup .= '<span class="export-personal-data-idle"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download personal data' ) . '</button></span>' . '<span class="export-personal-data-processing hidden">' . __( 'Downloading data...' ) . ' <span class="export-progress"></span></span>' . '<span class="export-personal-data-success hidden"><button type="button" class="button-link export-personal-data-handle">' . __( 'Download personal data again' ) . '</button></span>' . '<span class="export-personal-data-failed hidden">' . __( 'Download failed.' ) . ' <button type="button" class="button-link export-personal-data-handle">' . __( 'Retry' ) . '</button></span>'; $download_data_markup .= '</span>'; $row_actions['download-data'] = $download_data_markup; if ( 'request-completed' !== $status ) { $complete_request_markup = '<span>'; $complete_request_markup .= sprintf( '<a href="%s" class="complete-request" aria-label="%s">%s</a>', esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'complete', 'request_id' => array( $request_id ), ), admin_url( 'export-personal-data.php' ) ), 'bulk-privacy_requests' ) ), esc_attr( sprintf( /* translators: %s: Request email. */ __( 'Mark export request for &#8220;%s&#8221; as completed.' ), $item->email ) ), __( 'Complete request' ) ); $complete_request_markup .= '</span>'; } if ( ! empty( $complete_request_markup ) ) { $row_actions['complete-request'] = $complete_request_markup; } return sprintf( '<a href="%1$s">%2$s</a> %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); } ``` [apply\_filters( 'wp\_privacy\_personal\_data\_exporters', array $args )](../../hooks/wp_privacy_personal_data_exporters) Filters the array of exporter callbacks. | Uses | Description | | --- | --- | | [wp\_create\_nonce()](../../functions/wp_create_nonce) wp-includes/pluggable.php | Creates a cryptographic token tied to a specific action, user, user session, and window of time. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. | wordpress WP_Privacy_Data_Export_Requests_List_Table::column_next_steps( WP_User_Request $item ) WP\_Privacy\_Data\_Export\_Requests\_List\_Table::column\_next\_steps( WP\_User\_Request $item ) ================================================================================================ Displays the next steps column. `$item` [WP\_User\_Request](../wp_user_request) Required Item being shown. File: `wp-admin/includes/class-wp-privacy-data-export-requests-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-privacy-data-export-requests-list-table.php/) ``` public function column_next_steps( $item ) { $status = $item->status; switch ( $status ) { case 'request-pending': esc_html_e( 'Waiting for confirmation' ); break; case 'request-confirmed': /** This filter is documented in wp-admin/includes/ajax-actions.php */ $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); $exporters_count = count( $exporters ); $request_id = $item->ID; $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); echo '<div class="export-personal-data" ' . 'data-send-as-email="1" ' . 'data-exporters-count="' . esc_attr( $exporters_count ) . '" ' . 'data-request-id="' . esc_attr( $request_id ) . '" ' . 'data-nonce="' . esc_attr( $nonce ) . '">'; ?> <span class="export-personal-data-idle"><button type="button" class="button-link export-personal-data-handle"><?php _e( 'Send export link' ); ?></button></span> <span class="export-personal-data-processing hidden"><?php _e( 'Sending email...' ); ?> <span class="export-progress"></span></span> <span class="export-personal-data-success success-message hidden"><?php _e( 'Email sent.' ); ?></span> <span class="export-personal-data-failed hidden"><?php _e( 'Email could not be sent.' ); ?> <button type="button" class="button-link export-personal-data-handle"><?php _e( 'Retry' ); ?></button></span> <?php echo '</div>'; break; case 'request-failed': echo '<button type="submit" class="button-link" name="privacy_action_email_retry[' . $item->ID . ']" id="privacy_action_email_retry[' . $item->ID . ']">' . __( 'Retry' ) . '</button>'; break; case 'request-completed': echo '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'request_id' => array( $item->ID ), ), admin_url( 'export-personal-data.php' ) ), 'bulk-privacy_requests' ) ) . '">' . esc_html__( 'Remove request' ) . '</a>'; break; } } ``` [apply\_filters( 'wp\_privacy\_personal\_data\_exporters', array $args )](../../hooks/wp_privacy_personal_data_exporters) Filters the array of exporter callbacks. | Uses | Description | | --- | --- | | [esc\_html\_e()](../../functions/esc_html_e) wp-includes/l10n.php | Displays translated text that has been escaped for safe use in HTML output. | | [esc\_html\_\_()](../../functions/esc_html__) wp-includes/l10n.php | Retrieves the translation of $text and escapes it for safe use in HTML output. | | [wp\_create\_nonce()](../../functions/wp_create_nonce) wp-includes/pluggable.php | Creates a cryptographic token tied to a specific action, user, user session, and window of time. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [4.9.6](https://developer.wordpress.org/reference/since/4.9.6/) | Introduced. |
programming_docs
wordpress WP_oEmbed::_parse_xml( string $response_body ): object|false WP\_oEmbed::\_parse\_xml( string $response\_body ): object|false ================================================================ This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Parses an XML response body. `$response_body` string Required object|false File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` private function _parse_xml( $response_body ) { if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { return false; } if ( PHP_VERSION_ID < 80000 ) { // This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading // is disabled by default, so this function is no longer needed to protect against XXE attacks. // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.libxml_disable_entity_loaderDeprecated $loader = libxml_disable_entity_loader( true ); } $errors = libxml_use_internal_errors( true ); $return = $this->_parse_xml_body( $response_body ); libxml_use_internal_errors( $errors ); if ( PHP_VERSION_ID < 80000 && isset( $loader ) ) { // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.libxml_disable_entity_loaderDeprecated libxml_disable_entity_loader( $loader ); } return $return; } ``` | Uses | Description | | --- | --- | | [WP\_oEmbed::\_parse\_xml\_body()](_parse_xml_body) wp-includes/class-wp-oembed.php | Serves as a helper function for parsing an XML response body. | | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress WP_oEmbed::_strip_newlines( string $html, object $data, string $url ): string WP\_oEmbed::\_strip\_newlines( string $html, object $data, string $url ): string ================================================================================ Strips any new lines from the HTML. `$html` string Required Existing HTML. `$data` object Required Data object from [WP\_oEmbed::data2html()](data2html) More Arguments from WP\_oEmbed::data2html( ... $data ) A data object result from an oEmbed provider. `$url` string Required The original URL passed to oEmbed. string Possibly modified $html File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public function _strip_newlines( $html, $data, $url ) { if ( false === strpos( $html, "\n" ) ) { return $html; } $count = 1; $found = array(); $token = '__PRE__'; $search = array( "\t", "\n", "\r", ' ' ); $replace = array( '__TAB__', '__NL__', '__CR__', '__SPACE__' ); $tokenized = str_replace( $search, $replace, $html ); preg_match_all( '#(<pre[^>]*>.+?</pre>)#i', $tokenized, $matches, PREG_SET_ORDER ); foreach ( $matches as $i => $match ) { $tag_html = str_replace( $replace, $search, $match[0] ); $tag_token = $token . $i; $found[ $tag_token ] = $tag_html; $html = str_replace( $tag_html, $tag_token, $html, $count ); } $replaced = str_replace( $replace, $search, $html ); $stripped = str_replace( array( "\r\n", "\n" ), '', $replaced ); $pre = array_values( $found ); $tokens = array_keys( $found ); return str_replace( $tokens, $pre, $stripped ); } ``` | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | | | [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. | wordpress WP_oEmbed::get_provider( string $url, string|array $args = '' ): string|false WP\_oEmbed::get\_provider( string $url, string|array $args = '' ): string|false =============================================================================== Takes a URL and returns the corresponding oEmbed provider’s URL, if there is one. * [WP\_oEmbed::discover()](../wp_oembed/discover) `$url` string Required The URL to the content. `$args` string|array Optional Additional provider arguments. * `discover`boolOptional. Determines whether to attempt to discover link tags at the given URL for an oEmbed provider when the provider URL is not found in the built-in providers list. Default true. Default: `''` string|false The oEmbed provider URL on success, false on failure. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public function get_provider( $url, $args = '' ) { $args = wp_parse_args( $args ); $provider = false; if ( ! isset( $args['discover'] ) ) { $args['discover'] = true; } foreach ( $this->providers as $matchmask => $data ) { list( $providerurl, $regex ) = $data; // Turn the asterisk-type provider URLs into regex. if ( ! $regex ) { $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i'; $matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask ); } if ( preg_match( $matchmask, $url ) ) { $provider = str_replace( '{format}', 'json', $providerurl ); // JSON is easier to deal with than XML. break; } } if ( ! $provider && $args['discover'] ) { $provider = $this->discover( $url ); } return $provider; } ``` | Uses | Description | | --- | --- | | [WP\_oEmbed::discover()](discover) wp-includes/class-wp-oembed.php | Attempts to discover link tags at the given URL for an oEmbed provider. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Used By | Description | | --- | --- | | [WP\_oEmbed::get\_data()](get_data) wp-includes/class-wp-oembed.php | Takes a URL and attempts to return the oEmbed data. | | [wp\_filter\_oembed\_result()](../../functions/wp_filter_oembed_result) wp-includes/embed.php | Filters the given oEmbed HTML. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_oEmbed::_parse_json( string $response_body ): object|false WP\_oEmbed::\_parse\_json( string $response\_body ): object|false ================================================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Parses a json response body. `$response_body` string Required object|false File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` private function _parse_json( $response_body ) { $data = json_decode( trim( $response_body ) ); return ( $data && is_object( $data ) ) ? $data : false; } ``` | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress WP_oEmbed::__call( string $name, array $arguments ): mixed|false WP\_oEmbed::\_\_call( string $name, array $arguments ): mixed|false =================================================================== Exposes private/protected methods for backward compatibility. `$name` string Required Method to call. `$arguments` array Required Arguments to pass when calling. mixed|false Return value of the callback, false otherwise. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public function __call( $name, $arguments ) { if ( in_array( $name, $this->compat_methods, true ) ) { return $this->$name( ...$arguments ); } return false; } ``` | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_oEmbed::_fetch_with_format( string $provider_url_with_args, string $format ): object|false|WP_Error WP\_oEmbed::\_fetch\_with\_format( string $provider\_url\_with\_args, string $format ): object|false|WP\_Error ============================================================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Fetches result from an oEmbed provider for a specific format and complete provider URL `$provider_url_with_args` string Required URL to the provider with full arguments list (url, maxheight, etc.) `$format` string Required Format to use. object|false|[WP\_Error](../wp_error) The result in the form of an object on success, false on failure. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` private function _fetch_with_format( $provider_url_with_args, $format ) { $provider_url_with_args = add_query_arg( 'format', $format, $provider_url_with_args ); /** This filter is documented in wp-includes/class-wp-oembed.php */ $args = apply_filters( 'oembed_remote_get_args', array(), $provider_url_with_args ); $response = wp_safe_remote_get( $provider_url_with_args, $args ); if ( 501 == wp_remote_retrieve_response_code( $response ) ) { return new WP_Error( 'not-implemented' ); } $body = wp_remote_retrieve_body( $response ); if ( ! $body ) { return false; } $parse_method = "_parse_$format"; return $this->$parse_method( $body ); } ``` [apply\_filters( 'oembed\_remote\_get\_args', array $args, string $url )](../../hooks/oembed_remote_get_args) Filters oEmbed remote get arguments. | Uses | Description | | --- | --- | | [wp\_safe\_remote\_get()](../../functions/wp_safe_remote_get) wp-includes/http.php | Retrieve the raw response from a safe HTTP request using the GET method. | | [wp\_remote\_retrieve\_response\_code()](../../functions/wp_remote_retrieve_response_code) wp-includes/http.php | Retrieve only the response code from the raw response. | | [wp\_remote\_retrieve\_body()](../../functions/wp_remote_retrieve_body) wp-includes/http.php | Retrieve only the body from the raw response. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_oEmbed::fetch()](fetch) wp-includes/class-wp-oembed.php | Connects to a oEmbed provider and returns the result. | | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress WP_oEmbed::fetch( string $provider, string $url, string|array $args = '' ): object|false WP\_oEmbed::fetch( string $provider, string $url, string|array $args = '' ): object|false ========================================================================================= Connects to a oEmbed provider and returns the result. `$provider` string Required The URL to the oEmbed provider. `$url` string Required The URL to the content that is desired to be embedded. `$args` string|array Optional Additional arguments for retrieving embed HTML. See [wp\_oembed\_get()](../../functions/wp_oembed_get) for accepted arguments. More Arguments from wp\_oembed\_get( ... $args ) Additional arguments for retrieving embed HTML. * `width`int|stringOptional. The `maxwidth` value passed to the provider URL. * `height`int|stringOptional. The `maxheight` value passed to the provider URL. * `discover`boolOptional. Determines whether to attempt to discover link tags at the given URL for an oEmbed provider when the provider URL is not found in the built-in providers list. Default true. Default: `''` object|false The result in the form of an object on success, false on failure. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public function fetch( $provider, $url, $args = '' ) { $args = wp_parse_args( $args, wp_embed_defaults( $url ) ); $provider = add_query_arg( 'maxwidth', (int) $args['width'], $provider ); $provider = add_query_arg( 'maxheight', (int) $args['height'], $provider ); $provider = add_query_arg( 'url', urlencode( $url ), $provider ); $provider = add_query_arg( 'dnt', 1, $provider ); /** * Filters the oEmbed URL to be fetched. * * @since 2.9.0 * @since 4.9.0 The `dnt` (Do Not Track) query parameter was added to all oEmbed provider URLs. * * @param string $provider URL of the oEmbed provider. * @param string $url URL of the content to be embedded. * @param array $args Optional. Additional arguments for retrieving embed HTML. * See wp_oembed_get() for accepted arguments. Default empty. */ $provider = apply_filters( 'oembed_fetch_url', $provider, $url, $args ); foreach ( array( 'json', 'xml' ) as $format ) { $result = $this->_fetch_with_format( $provider, $format ); if ( is_wp_error( $result ) && 'not-implemented' === $result->get_error_code() ) { continue; } return ( $result && ! is_wp_error( $result ) ) ? $result : false; } return false; } ``` [apply\_filters( 'oembed\_fetch\_url', string $provider, string $url, array $args )](../../hooks/oembed_fetch_url) Filters the oEmbed URL to be fetched. | Uses | Description | | --- | --- | | [WP\_oEmbed::\_fetch\_with\_format()](_fetch_with_format) wp-includes/class-wp-oembed.php | Fetches result from an oEmbed provider for a specific format and complete provider URL | | [wp\_embed\_defaults()](../../functions/wp_embed_defaults) wp-includes/embed.php | Creates default array of embed parameters. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [WP\_oEmbed::get\_data()](get_data) wp-includes/class-wp-oembed.php | Takes a URL and attempts to return the oEmbed data. | | Version | Description | | --- | --- | | [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. | wordpress WP_oEmbed::_add_provider_early( string $format, string $provider, bool $regex = false ) WP\_oEmbed::\_add\_provider\_early( string $format, string $provider, bool $regex = false ) =========================================================================================== Adds an oEmbed provider. The provider is added just-in-time when [wp\_oembed\_add\_provider()](../../functions/wp_oembed_add_provider) is called before the [‘plugins\_loaded’](../../hooks/plugins_loaded) hook. The just-in-time addition is for the benefit of the [‘oembed\_providers’](../../hooks/oembed_providers) filter. * [wp\_oembed\_add\_provider()](../../functions/wp_oembed_add_provider) `$format` string Required Format of URL that this provider can handle. You can use asterisks as wildcards. `$provider` string Required The URL to the oEmbed provider.. `$regex` bool Optional Whether the $format parameter is in a regex format. Default: `false` File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public static function _add_provider_early( $format, $provider, $regex = false ) { if ( empty( self::$early_providers['add'] ) ) { self::$early_providers['add'] = array(); } self::$early_providers['add'][ $format ] = array( $provider, $regex ); } ``` | Used By | Description | | --- | --- | | [wp\_oembed\_add\_provider()](../../functions/wp_oembed_add_provider) wp-includes/embed.php | Adds a URL format and oEmbed provider URL pair. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. | wordpress WP_oEmbed::get_data( string $url, string|array $args = '' ): object|false WP\_oEmbed::get\_data( string $url, string|array $args = '' ): object|false =========================================================================== Takes a URL and attempts to return the oEmbed data. * [WP\_oEmbed::fetch()](../wp_oembed/fetch) `$url` string Required The URL to the content that should be attempted to be embedded. `$args` string|array Optional Additional arguments for retrieving embed HTML. See [wp\_oembed\_get()](../../functions/wp_oembed_get) for accepted arguments. More Arguments from wp\_oembed\_get( ... $args ) Additional arguments for retrieving embed HTML. * `width`int|stringOptional. The `maxwidth` value passed to the provider URL. * `height`int|stringOptional. The `maxheight` value passed to the provider URL. * `discover`boolOptional. Determines whether to attempt to discover link tags at the given URL for an oEmbed provider when the provider URL is not found in the built-in providers list. Default true. Default: `''` object|false The result in the form of an object on success, false on failure. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public function get_data( $url, $args = '' ) { $args = wp_parse_args( $args ); $provider = $this->get_provider( $url, $args ); if ( ! $provider ) { return false; } $data = $this->fetch( $provider, $url, $args ); if ( false === $data ) { return false; } return $data; } ``` | Uses | Description | | --- | --- | | [WP\_oEmbed::get\_provider()](get_provider) wp-includes/class-wp-oembed.php | Takes a URL and returns the corresponding oEmbed provider’s URL, if there is one. | | [WP\_oEmbed::fetch()](fetch) wp-includes/class-wp-oembed.php | Connects to a oEmbed provider and returns the result. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Used By | Description | | --- | --- | | [WP\_oEmbed::get\_html()](get_html) wp-includes/class-wp-oembed.php | The do-it-all function that takes a URL and attempts to return the HTML. | | Version | Description | | --- | --- | | [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | Introduced. | wordpress WP_oEmbed::_remove_provider_early( string $format ) WP\_oEmbed::\_remove\_provider\_early( string $format ) ======================================================= Removes an oEmbed provider. The provider is removed just-in-time when [wp\_oembed\_remove\_provider()](../../functions/wp_oembed_remove_provider) is called before the [‘plugins\_loaded’](../../hooks/plugins_loaded) hook. The just-in-time removal is for the benefit of the [‘oembed\_providers’](../../hooks/oembed_providers) filter. * [wp\_oembed\_remove\_provider()](../../functions/wp_oembed_remove_provider) `$format` string Required The format of URL that this provider can handle. You can use asterisks as wildcards. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public static function _remove_provider_early( $format ) { if ( empty( self::$early_providers['remove'] ) ) { self::$early_providers['remove'] = array(); } self::$early_providers['remove'][] = $format; } ``` | Used By | Description | | --- | --- | | [wp\_oembed\_remove\_provider()](../../functions/wp_oembed_remove_provider) wp-includes/embed.php | Removes an oEmbed provider. | | Version | Description | | --- | --- | | [4.0.0](https://developer.wordpress.org/reference/since/4.0.0/) | Introduced. |
programming_docs
wordpress WP_oEmbed::discover( string $url ): string|false WP\_oEmbed::discover( string $url ): string|false ================================================= Attempts to discover link tags at the given URL for an oEmbed provider. `$url` string Required The URL that should be inspected for discovery `<link>` tags. string|false The oEmbed provider URL on success, false on failure. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public function discover( $url ) { $providers = array(); $args = array( 'limit_response_size' => 153600, // 150 KB ); /** * Filters oEmbed remote get arguments. * * @since 4.0.0 * * @see WP_Http::request() * * @param array $args oEmbed remote get arguments. * @param string $url URL to be inspected. */ $args = apply_filters( 'oembed_remote_get_args', $args, $url ); // Fetch URL content. $request = wp_safe_remote_get( $url, $args ); $html = wp_remote_retrieve_body( $request ); if ( $html ) { /** * Filters the link types that contain oEmbed provider URLs. * * @since 2.9.0 * * @param string[] $format Array of oEmbed link types. Accepts 'application/json+oembed', * 'text/xml+oembed', and 'application/xml+oembed' (incorrect, * used by at least Vimeo). */ $linktypes = apply_filters( 'oembed_linktypes', array( 'application/json+oembed' => 'json', 'text/xml+oembed' => 'xml', 'application/xml+oembed' => 'xml', ) ); // Strip <body>. $html_head_end = stripos( $html, '</head>' ); if ( $html_head_end ) { $html = substr( $html, 0, $html_head_end ); } // Do a quick check. $tagfound = false; foreach ( $linktypes as $linktype => $format ) { if ( stripos( $html, $linktype ) ) { $tagfound = true; break; } } if ( $tagfound && preg_match_all( '#<link([^<>]+)/?>#iU', $html, $links ) ) { foreach ( $links[1] as $link ) { $atts = shortcode_parse_atts( $link ); if ( ! empty( $atts['type'] ) && ! empty( $linktypes[ $atts['type'] ] ) && ! empty( $atts['href'] ) ) { $providers[ $linktypes[ $atts['type'] ] ] = htmlspecialchars_decode( $atts['href'] ); // Stop here if it's JSON (that's all we need). if ( 'json' === $linktypes[ $atts['type'] ] ) { break; } } } } } // JSON is preferred to XML. if ( ! empty( $providers['json'] ) ) { return $providers['json']; } elseif ( ! empty( $providers['xml'] ) ) { return $providers['xml']; } else { return false; } } ``` [apply\_filters( 'oembed\_linktypes', string[] $format )](../../hooks/oembed_linktypes) Filters the link types that contain oEmbed provider URLs. [apply\_filters( 'oembed\_remote\_get\_args', array $args, string $url )](../../hooks/oembed_remote_get_args) Filters oEmbed remote get arguments. | Uses | Description | | --- | --- | | [stripos()](../../functions/stripos) wp-includes/class-pop3.php | | | [wp\_safe\_remote\_get()](../../functions/wp_safe_remote_get) wp-includes/http.php | Retrieve the raw response from a safe HTTP request using the GET method. | | [wp\_remote\_retrieve\_body()](../../functions/wp_remote_retrieve_body) wp-includes/http.php | Retrieve only the body from the raw response. | | [shortcode\_parse\_atts()](../../functions/shortcode_parse_atts) wp-includes/shortcodes.php | Retrieves all attributes from the shortcodes tag. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_oEmbed::get\_provider()](get_provider) wp-includes/class-wp-oembed.php | Takes a URL and returns the corresponding oEmbed provider’s URL, if there is one. | | Version | Description | | --- | --- | | [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. | wordpress WP_oEmbed::__construct() WP\_oEmbed::\_\_construct() =========================== Constructor. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public function __construct() { $host = urlencode( home_url() ); $providers = array( '#https?://((m|www)\.)?youtube\.com/watch.*#i' => array( 'https://www.youtube.com/oembed', true ), '#https?://((m|www)\.)?youtube\.com/playlist.*#i' => array( 'https://www.youtube.com/oembed', true ), '#https?://((m|www)\.)?youtube\.com/shorts/*#i' => array( 'https://www.youtube.com/oembed', true ), '#https?://youtu\.be/.*#i' => array( 'https://www.youtube.com/oembed', true ), '#https?://(.+\.)?vimeo\.com/.*#i' => array( 'https://vimeo.com/api/oembed.{format}', true ), '#https?://(www\.)?dailymotion\.com/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ), '#https?://dai\.ly/.*#i' => array( 'https://www.dailymotion.com/services/oembed', true ), '#https?://(www\.)?flickr\.com/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ), '#https?://flic\.kr/.*#i' => array( 'https://www.flickr.com/services/oembed/', true ), '#https?://(.+\.)?smugmug\.com/.*#i' => array( 'https://api.smugmug.com/services/oembed/', true ), '#https?://(www\.)?scribd\.com/(doc|document)/.*#i' => array( 'https://www.scribd.com/services/oembed', true ), '#https?://wordpress\.tv/.*#i' => array( 'https://wordpress.tv/oembed/', true ), '#https?://(.+\.)?polldaddy\.com/.*#i' => array( 'https://api.crowdsignal.com/oembed', true ), '#https?://poll\.fm/.*#i' => array( 'https://api.crowdsignal.com/oembed', true ), '#https?://(.+\.)?survey\.fm/.*#i' => array( 'https://api.crowdsignal.com/oembed', true ), '#https?://(www\.)?twitter\.com/\w{1,15}/status(es)?/.*#i' => array( 'https://publish.twitter.com/oembed', true ), '#https?://(www\.)?twitter\.com/\w{1,15}$#i' => array( 'https://publish.twitter.com/oembed', true ), '#https?://(www\.)?twitter\.com/\w{1,15}/likes$#i' => array( 'https://publish.twitter.com/oembed', true ), '#https?://(www\.)?twitter\.com/\w{1,15}/lists/.*#i' => array( 'https://publish.twitter.com/oembed', true ), '#https?://(www\.)?twitter\.com/\w{1,15}/timelines/.*#i' => array( 'https://publish.twitter.com/oembed', true ), '#https?://(www\.)?twitter\.com/i/moments/.*#i' => array( 'https://publish.twitter.com/oembed', true ), '#https?://(www\.)?soundcloud\.com/.*#i' => array( 'https://soundcloud.com/oembed', true ), '#https?://(.+?\.)?slideshare\.net/.*#i' => array( 'https://www.slideshare.net/api/oembed/2', true ), '#https?://(open|play)\.spotify\.com/.*#i' => array( 'https://embed.spotify.com/oembed/', true ), '#https?://(.+\.)?imgur\.com/.*#i' => array( 'https://api.imgur.com/oembed', true ), '#https?://(www\.)?issuu\.com/.+/docs/.+#i' => array( 'https://issuu.com/oembed_wp', true ), '#https?://(www\.)?mixcloud\.com/.*#i' => array( 'https://www.mixcloud.com/oembed', true ), '#https?://(www\.|embed\.)?ted\.com/talks/.*#i' => array( 'https://www.ted.com/services/v1/oembed.{format}', true ), '#https?://(www\.)?(animoto|video214)\.com/play/.*#i' => array( 'https://animoto.com/oembeds/create', true ), '#https?://(.+)\.tumblr\.com/.*#i' => array( 'https://www.tumblr.com/oembed/1.0', true ), '#https?://(www\.)?kickstarter\.com/projects/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ), '#https?://kck\.st/.*#i' => array( 'https://www.kickstarter.com/services/oembed', true ), '#https?://cloudup\.com/.*#i' => array( 'https://cloudup.com/oembed', true ), '#https?://(www\.)?reverbnation\.com/.*#i' => array( 'https://www.reverbnation.com/oembed', true ), '#https?://videopress\.com/v/.*#' => array( 'https://public-api.wordpress.com/oembed/?for=' . $host, true ), '#https?://(www\.)?reddit\.com/r/[^/]+/comments/.*#i' => array( 'https://www.reddit.com/oembed', true ), '#https?://(www\.)?speakerdeck\.com/.*#i' => array( 'https://speakerdeck.com/oembed.{format}', true ), '#https?://(www\.)?screencast\.com/.*#i' => array( 'https://api.screencast.com/external/oembed', true ), '#https?://([a-z0-9-]+\.)?amazon\.(com|com\.mx|com\.br|ca)/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), '#https?://([a-z0-9-]+\.)?amazon\.(co\.uk|de|fr|it|es|in|nl|ru)/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ), '#https?://([a-z0-9-]+\.)?amazon\.(co\.jp|com\.au)/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ), '#https?://([a-z0-9-]+\.)?amazon\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ), '#https?://(www\.)?a\.co/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), '#https?://(www\.)?amzn\.to/.*#i' => array( 'https://read.amazon.com/kp/api/oembed', true ), '#https?://(www\.)?amzn\.eu/.*#i' => array( 'https://read.amazon.co.uk/kp/api/oembed', true ), '#https?://(www\.)?amzn\.in/.*#i' => array( 'https://read.amazon.in/kp/api/oembed', true ), '#https?://(www\.)?amzn\.asia/.*#i' => array( 'https://read.amazon.com.au/kp/api/oembed', true ), '#https?://(www\.)?z\.cn/.*#i' => array( 'https://read.amazon.cn/kp/api/oembed', true ), '#https?://www\.someecards\.com/.+-cards/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), '#https?://www\.someecards\.com/usercards/viewcard/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), '#https?://some\.ly\/.+#i' => array( 'https://www.someecards.com/v2/oembed/', true ), '#https?://(www\.)?tiktok\.com/.*/video/.*#i' => array( 'https://www.tiktok.com/oembed', true ), '#https?://([a-z]{2}|www)\.pinterest\.com(\.(au|mx))?/.*#i' => array( 'https://www.pinterest.com/oembed.json', true ), '#https?://(www\.)?wolframcloud\.com/obj/.+#i' => array( 'https://www.wolframcloud.com/oembed', true ), '#https?://pca\.st/.+#i' => array( 'https://pca.st/oembed.json', true ), ); if ( ! empty( self::$early_providers['add'] ) ) { foreach ( self::$early_providers['add'] as $format => $data ) { $providers[ $format ] = $data; } } if ( ! empty( self::$early_providers['remove'] ) ) { foreach ( self::$early_providers['remove'] as $format ) { unset( $providers[ $format ] ); } } self::$early_providers = array(); /** * Filters the list of sanctioned oEmbed providers. * * Since WordPress 4.4, oEmbed discovery is enabled for all users and allows embedding of sanitized * iframes. The providers in this list are sanctioned, meaning they are trusted and allowed to * embed any content, such as iframes, videos, JavaScript, and arbitrary HTML. * * Supported providers: * * | Provider | Flavor | Since | * | ------------ | ----------------------------------------- | ------- | * | Dailymotion | dailymotion.com | 2.9.0 | * | Flickr | flickr.com | 2.9.0 | * | Scribd | scribd.com | 2.9.0 | * | Vimeo | vimeo.com | 2.9.0 | * | WordPress.tv | wordpress.tv | 2.9.0 | * | YouTube | youtube.com/watch | 2.9.0 | * | Crowdsignal | polldaddy.com | 3.0.0 | * | SmugMug | smugmug.com | 3.0.0 | * | YouTube | youtu.be | 3.0.0 | * | Twitter | twitter.com | 3.4.0 | * | Slideshare | slideshare.net | 3.5.0 | * | SoundCloud | soundcloud.com | 3.5.0 | * | Dailymotion | dai.ly | 3.6.0 | * | Flickr | flic.kr | 3.6.0 | * | Spotify | spotify.com | 3.6.0 | * | Imgur | imgur.com | 3.9.0 | * | Animoto | animoto.com | 4.0.0 | * | Animoto | video214.com | 4.0.0 | * | Issuu | issuu.com | 4.0.0 | * | Mixcloud | mixcloud.com | 4.0.0 | * | Crowdsignal | poll.fm | 4.0.0 | * | TED | ted.com | 4.0.0 | * | YouTube | youtube.com/playlist | 4.0.0 | * | Tumblr | tumblr.com | 4.2.0 | * | Kickstarter | kickstarter.com | 4.2.0 | * | Kickstarter | kck.st | 4.2.0 | * | Cloudup | cloudup.com | 4.3.0 | * | ReverbNation | reverbnation.com | 4.4.0 | * | VideoPress | videopress.com | 4.4.0 | * | Reddit | reddit.com | 4.4.0 | * | Speaker Deck | speakerdeck.com | 4.4.0 | * | Twitter | twitter.com/timelines | 4.5.0 | * | Twitter | twitter.com/moments | 4.5.0 | * | Twitter | twitter.com/user | 4.7.0 | * | Twitter | twitter.com/likes | 4.7.0 | * | Twitter | twitter.com/lists | 4.7.0 | * | Screencast | screencast.com | 4.8.0 | * | Amazon | amazon.com (com.mx, com.br, ca) | 4.9.0 | * | Amazon | amazon.de (fr, it, es, in, nl, ru, co.uk) | 4.9.0 | * | Amazon | amazon.co.jp (com.au) | 4.9.0 | * | Amazon | amazon.cn | 4.9.0 | * | Amazon | a.co | 4.9.0 | * | Amazon | amzn.to (eu, in, asia) | 4.9.0 | * | Amazon | z.cn | 4.9.0 | * | Someecards | someecards.com | 4.9.0 | * | Someecards | some.ly | 4.9.0 | * | Crowdsignal | survey.fm | 5.1.0 | * | TikTok | tiktok.com | 5.4.0 | * | Pinterest | pinterest.com | 5.9.0 | * | WolframCloud | wolframcloud.com | 5.9.0 | * | Pocket Casts | pocketcasts.com | 6.1.0 | * * No longer supported providers: * * | Provider | Flavor | Since | Removed | * | ------------ | -------------------- | --------- | --------- | * | Qik | qik.com | 2.9.0 | 3.9.0 | * | Viddler | viddler.com | 2.9.0 | 4.0.0 | * | Revision3 | revision3.com | 2.9.0 | 4.2.0 | * | Blip | blip.tv | 2.9.0 | 4.4.0 | * | Rdio | rdio.com | 3.6.0 | 4.4.1 | * | Rdio | rd.io | 3.6.0 | 4.4.1 | * | Vine | vine.co | 4.1.0 | 4.9.0 | * | Photobucket | photobucket.com | 2.9.0 | 5.1.0 | * | Funny or Die | funnyordie.com | 3.0.0 | 5.1.0 | * | CollegeHumor | collegehumor.com | 4.0.0 | 5.3.1 | * | Hulu | hulu.com | 2.9.0 | 5.5.0 | * | Instagram | instagram.com | 3.5.0 | 5.5.2 | * | Instagram | instagr.am | 3.5.0 | 5.5.2 | * | Instagram TV | instagram.com | 5.1.0 | 5.5.2 | * | Instagram TV | instagr.am | 5.1.0 | 5.5.2 | * | Facebook | facebook.com | 4.7.0 | 5.5.2 | * | Meetup.com | meetup.com | 3.9.0 | 6.0.1 | * | Meetup.com | meetu.ps | 3.9.0 | 6.0.1 | * * @see wp_oembed_add_provider() * * @since 2.9.0 * * @param array[] $providers An array of arrays containing data about popular oEmbed providers. */ $this->providers = apply_filters( 'oembed_providers', $providers ); // Fix any embeds that contain new lines in the middle of the HTML which breaks wpautop(). add_filter( 'oembed_dataparse', array( $this, '_strip_newlines' ), 10, 3 ); } ``` [apply\_filters( 'oembed\_providers', array[] $providers )](../../hooks/oembed_providers) Filters the list of sanctioned oEmbed providers. | Uses | Description | | --- | --- | | [home\_url()](../../functions/home_url) wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | Used By | Description | | --- | --- | | [\_wp\_oembed\_get\_object()](../../functions/_wp_oembed_get_object) wp-includes/embed.php | Returns the initialized [WP\_oEmbed](../wp_oembed) object. | | Version | Description | | --- | --- | | [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. | wordpress WP_oEmbed::get_html( string $url, string|array $args = '' ): string|false WP\_oEmbed::get\_html( string $url, string|array $args = '' ): string|false =========================================================================== The do-it-all function that takes a URL and attempts to return the HTML. * [WP\_oEmbed::fetch()](../wp_oembed/fetch) * [WP\_oEmbed::data2html()](../wp_oembed/data2html) `$url` string Required The URL to the content that should be attempted to be embedded. `$args` string|array Optional Additional arguments for retrieving embed HTML. See [wp\_oembed\_get()](../../functions/wp_oembed_get) for accepted arguments. More Arguments from wp\_oembed\_get( ... $args ) Additional arguments for retrieving embed HTML. * `width`int|stringOptional. The `maxwidth` value passed to the provider URL. * `height`int|stringOptional. The `maxheight` value passed to the provider URL. * `discover`boolOptional. Determines whether to attempt to discover link tags at the given URL for an oEmbed provider when the provider URL is not found in the built-in providers list. Default true. Default: `''` string|false The UNSANITIZED (and potentially unsafe) HTML that should be used to embed on success, false on failure. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public function get_html( $url, $args = '' ) { /** * Filters the oEmbed result before any HTTP requests are made. * * This allows one to short-circuit the default logic, perhaps by * replacing it with a routine that is more optimal for your setup. * * Returning a non-null value from the filter will effectively short-circuit retrieval * and return the passed value instead. * * @since 4.5.3 * * @param null|string $result The UNSANITIZED (and potentially unsafe) HTML that should be used to embed. * Default null to continue retrieving the result. * @param string $url The URL to the content that should be attempted to be embedded. * @param string|array $args Optional. Additional arguments for retrieving embed HTML. * See wp_oembed_get() for accepted arguments. Default empty. */ $pre = apply_filters( 'pre_oembed_result', null, $url, $args ); if ( null !== $pre ) { return $pre; } $data = $this->get_data( $url, $args ); if ( false === $data ) { return false; } /** * Filters the HTML returned by the oEmbed provider. * * @since 2.9.0 * * @param string|false $data The returned oEmbed HTML (false if unsafe). * @param string $url URL of the content to be embedded. * @param string|array $args Optional. Additional arguments for retrieving embed HTML. * See wp_oembed_get() for accepted arguments. Default empty. */ return apply_filters( 'oembed_result', $this->data2html( $data, $url ), $url, $args ); } ``` [apply\_filters( 'oembed\_result', string|false $data, string $url, string|array $args )](../../hooks/oembed_result) Filters the HTML returned by the oEmbed provider. [apply\_filters( 'pre\_oembed\_result', null|string $result, string $url, string|array $args )](../../hooks/pre_oembed_result) Filters the oEmbed result before any HTTP requests are made. | Uses | Description | | --- | --- | | [WP\_oEmbed::get\_data()](get_data) wp-includes/class-wp-oembed.php | Takes a URL and attempts to return the oEmbed data. | | [WP\_oEmbed::data2html()](data2html) wp-includes/class-wp-oembed.php | Converts a data object from [WP\_oEmbed::fetch()](fetch) and returns the HTML. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |
programming_docs
wordpress WP_oEmbed::data2html( object $data, string $url ): string|false WP\_oEmbed::data2html( object $data, string $url ): string|false ================================================================ Converts a data object from [WP\_oEmbed::fetch()](fetch) and returns the HTML. `$data` object Required A data object result from an oEmbed provider. `$url` string Required The URL to the content that is desired to be embedded. string|false The HTML needed to embed on success, false on failure. File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` public function data2html( $data, $url ) { if ( ! is_object( $data ) || empty( $data->type ) ) { return false; } $return = false; switch ( $data->type ) { case 'photo': if ( empty( $data->url ) || empty( $data->width ) || empty( $data->height ) ) { break; } if ( ! is_string( $data->url ) || ! is_numeric( $data->width ) || ! is_numeric( $data->height ) ) { break; } $title = ! empty( $data->title ) && is_string( $data->title ) ? $data->title : ''; $return = '<a href="' . esc_url( $url ) . '"><img src="' . esc_url( $data->url ) . '" alt="' . esc_attr( $title ) . '" width="' . esc_attr( $data->width ) . '" height="' . esc_attr( $data->height ) . '" /></a>'; break; case 'video': case 'rich': if ( ! empty( $data->html ) && is_string( $data->html ) ) { $return = $data->html; } break; case 'link': if ( ! empty( $data->title ) && is_string( $data->title ) ) { $return = '<a href="' . esc_url( $url ) . '">' . esc_html( $data->title ) . '</a>'; } break; default: $return = false; } /** * Filters the returned oEmbed HTML. * * Use this filter to add support for custom data types, or to filter the result. * * @since 2.9.0 * * @param string $return The returned oEmbed HTML. * @param object $data A data object result from an oEmbed provider. * @param string $url The URL of the content to be embedded. */ return apply_filters( 'oembed_dataparse', $return, $data, $url ); } ``` [apply\_filters( 'oembed\_dataparse', string $return, object $data, string $url )](../../hooks/oembed_dataparse) Filters the returned oEmbed HTML. | Uses | Description | | --- | --- | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_oEmbed::get\_html()](get_html) wp-includes/class-wp-oembed.php | The do-it-all function that takes a URL and attempts to return the HTML. | | Version | Description | | --- | --- | | [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. | wordpress WP_oEmbed::_parse_xml_body( string $response_body ): stdClass|false WP\_oEmbed::\_parse\_xml\_body( string $response\_body ): stdClass|false ======================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Serves as a helper function for parsing an XML response body. `$response_body` string Required stdClass|false File: `wp-includes/class-wp-oembed.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-oembed.php/) ``` private function _parse_xml_body( $response_body ) { if ( ! function_exists( 'simplexml_import_dom' ) || ! class_exists( 'DOMDocument', false ) ) { return false; } $dom = new DOMDocument; $success = $dom->loadXML( $response_body ); if ( ! $success ) { return false; } if ( isset( $dom->doctype ) ) { return false; } foreach ( $dom->childNodes as $child ) { if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) { return false; } } $xml = simplexml_import_dom( $dom ); if ( ! $xml ) { return false; } $return = new stdClass; foreach ( $xml as $key => $value ) { $return->$key = (string) $value; } return $return; } ``` | Used By | Description | | --- | --- | | [WP\_oEmbed::\_parse\_xml()](_parse_xml) wp-includes/class-wp-oembed.php | Parses an XML response body. | | Version | Description | | --- | --- | | [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. | wordpress WP_Customize_Code_Editor_Control::content_template() WP\_Customize\_Code\_Editor\_Control::content\_template() ========================================================= Render a JS template for control display. File: `wp-includes/customize/class-wp-customize-code-editor-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-code-editor-control.php/) ``` public function content_template() { ?> <# var elementIdPrefix = 'el' + String( Math.random() ); #> <# if ( data.label ) { #> <label for="{{ elementIdPrefix }}_editor" class="customize-control-title"> {{ data.label }} </label> <# } #> <# if ( data.description ) { #> <span class="description customize-control-description">{{{ data.description }}}</span> <# } #> <div class="customize-control-notifications-container"></div> <textarea id="{{ elementIdPrefix }}_editor" <# _.each( _.extend( { 'class': 'code' }, data.input_attrs ), function( value, key ) { #> {{{ key }}}="{{ value }}" <# }); #> ></textarea> <?php } ``` | Version | Description | | --- | --- | | [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced. | wordpress WP_Customize_Code_Editor_Control::json(): array WP\_Customize\_Code\_Editor\_Control::json(): array =================================================== Refresh the parameters passed to the JavaScript via JSON. * [WP\_Customize\_Control::json()](../wp_customize_control/json) array Array of parameters passed to the JavaScript. File: `wp-includes/customize/class-wp-customize-code-editor-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-code-editor-control.php/) ``` public function json() { $json = parent::json(); $json['editor_settings'] = $this->editor_settings; $json['input_attrs'] = $this->input_attrs; return $json; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Control::json()](../wp_customize_control/json) wp-includes/class-wp-customize-control.php | Get the data to export to the client via JSON. | | Version | Description | | --- | --- | | [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced. | wordpress WP_Customize_Code_Editor_Control::render_content() WP\_Customize\_Code\_Editor\_Control::render\_content() ======================================================= Don’t render the control content from PHP, as it’s rendered via JS on load. File: `wp-includes/customize/class-wp-customize-code-editor-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-code-editor-control.php/) ``` public function render_content() {} ``` | Version | Description | | --- | --- | | [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced. | wordpress WP_Customize_Code_Editor_Control::enqueue() WP\_Customize\_Code\_Editor\_Control::enqueue() =============================================== Enqueue control related scripts/styles. File: `wp-includes/customize/class-wp-customize-code-editor-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-code-editor-control.php/) ``` public function enqueue() { $this->editor_settings = wp_enqueue_code_editor( array_merge( array( 'type' => $this->code_type, 'codemirror' => array( 'indentUnit' => 2, 'tabSize' => 2, ), ), $this->editor_settings ) ); } ``` | Uses | Description | | --- | --- | | [wp\_enqueue\_code\_editor()](../../functions/wp_enqueue_code_editor) wp-includes/general-template.php | Enqueues assets needed by the code editor for the given settings. | | Version | Description | | --- | --- | | [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced. | wordpress Language_Pack_Upgrader::get_name_for_update( object $update ): string Language\_Pack\_Upgrader::get\_name\_for\_update( object $update ): string ========================================================================== Get the name of an item being updated. `$update` object Required The data for an update. string The name of the item being updated. File: `wp-admin/includes/class-language-pack-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-language-pack-upgrader.php/) ``` public function get_name_for_update( $update ) { switch ( $update->type ) { case 'core': return 'WordPress'; // Not translated. case 'theme': $theme = wp_get_theme( $update->slug ); if ( $theme->exists() ) { return $theme->Get( 'Name' ); } break; case 'plugin': $plugin_data = get_plugins( '/' . $update->slug ); $plugin_data = reset( $plugin_data ); if ( $plugin_data ) { return $plugin_data['Name']; } break; } return ''; } ``` | Uses | Description | | --- | --- | | [get\_plugins()](../../functions/get_plugins) wp-admin/includes/plugin.php | Checks the plugins directory and retrieve all plugin files with plugin data. | | [wp\_get\_theme()](../../functions/wp_get_theme) wp-includes/theme.php | Gets a [WP\_Theme](../wp_theme) object for a theme. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress Language_Pack_Upgrader::bulk_upgrade( object[] $language_updates = array(), array $args = array() ): array|bool|WP_Error Language\_Pack\_Upgrader::bulk\_upgrade( object[] $language\_updates = array(), array $args = array() ): array|bool|WP\_Error ============================================================================================================================= Bulk upgrade language packs. `$language_updates` object[] Optional Array of language packs to update. @see [wp\_get\_translation\_updates()](../../functions/wp_get_translation_updates) . Default: `array()` `$args` array Optional Other arguments for upgrading multiple language packs. * `clear_update_cache`boolWhether to clear the update cache when done. Default true. Default: `array()` array|bool|[WP\_Error](../wp_error) Will return an array of results, or true if there are no updates, false or [WP\_Error](../wp_error) for initial errors. File: `wp-admin/includes/class-language-pack-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-language-pack-upgrader.php/) ``` public function bulk_upgrade( $language_updates = array(), $args = array() ) { global $wp_filesystem; $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); $this->init(); $this->upgrade_strings(); if ( ! $language_updates ) { $language_updates = wp_get_translation_updates(); } if ( empty( $language_updates ) ) { $this->skin->header(); $this->skin->set_result( true ); $this->skin->feedback( 'up_to_date' ); $this->skin->bulk_footer(); $this->skin->footer(); return true; } if ( 'upgrader_process_complete' === current_filter() ) { $this->skin->feedback( 'starting_upgrade' ); } // Remove any existing upgrade filters from the plugin/theme upgraders #WP29425 & #WP29230. remove_all_filters( 'upgrader_pre_install' ); remove_all_filters( 'upgrader_clear_destination' ); remove_all_filters( 'upgrader_post_install' ); remove_all_filters( 'upgrader_source_selection' ); add_filter( 'upgrader_source_selection', array( $this, 'check_package' ), 10, 2 ); $this->skin->header(); // Connect to the filesystem first. $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) ); if ( ! $res ) { $this->skin->footer(); return false; } $results = array(); $this->update_count = count( $language_updates ); $this->update_current = 0; /* * The filesystem's mkdir() is not recursive. Make sure WP_LANG_DIR exists, * as we then may need to create a /plugins or /themes directory inside of it. */ $remote_destination = $wp_filesystem->find_folder( WP_LANG_DIR ); if ( ! $wp_filesystem->exists( $remote_destination ) ) { if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) { return new WP_Error( 'mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination ); } } $language_updates_results = array(); foreach ( $language_updates as $language_update ) { $this->skin->language_update = $language_update; $destination = WP_LANG_DIR; if ( 'plugin' === $language_update->type ) { $destination .= '/plugins'; } elseif ( 'theme' === $language_update->type ) { $destination .= '/themes'; } $this->update_current++; $options = array( 'package' => $language_update->package, 'destination' => $destination, 'clear_destination' => true, 'abort_if_destination_exists' => false, // We expect the destination to exist. 'clear_working' => true, 'is_multi' => true, 'hook_extra' => array( 'language_update_type' => $language_update->type, 'language_update' => $language_update, ), ); $result = $this->run( $options ); $results[] = $this->result; // Prevent credentials auth screen from displaying multiple times. if ( false === $result ) { break; } $language_updates_results[] = array( 'language' => $language_update->language, 'type' => $language_update->type, 'slug' => isset( $language_update->slug ) ? $language_update->slug : 'default', 'version' => $language_update->version, ); } // Remove upgrade hooks which are not required for translation updates. remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 ); remove_action( 'upgrader_process_complete', 'wp_version_check' ); remove_action( 'upgrader_process_complete', 'wp_update_plugins' ); remove_action( 'upgrader_process_complete', 'wp_update_themes' ); /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'translation', 'bulk' => true, 'translations' => $language_updates_results, ) ); // Re-add upgrade hooks. add_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 ); add_action( 'upgrader_process_complete', 'wp_version_check', 10, 0 ); add_action( 'upgrader_process_complete', 'wp_update_plugins', 10, 0 ); add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 ); $this->skin->bulk_footer(); $this->skin->footer(); // Clean up our hooks, in case something else does an upgrade on this connection. remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); if ( $parsed_args['clear_update_cache'] ) { wp_clean_update_cache(); } return $results; } ``` [do\_action( 'upgrader\_process\_complete', WP\_Upgrader $upgrader, array $hook\_extra )](../../hooks/upgrader_process_complete) Fires when the upgrader process is complete. | Uses | Description | | --- | --- | | [wp\_clean\_update\_cache()](../../functions/wp_clean_update_cache) wp-includes/update.php | Clears existing update caches for plugins, themes, and core. | | [Language\_Pack\_Upgrader::upgrade\_strings()](upgrade_strings) wp-admin/includes/class-language-pack-upgrader.php | Initialize the upgrade strings. | | [wp\_get\_translation\_updates()](../../functions/wp_get_translation_updates) wp-includes/update.php | Retrieves a list of all language updates available. | | [remove\_action()](../../functions/remove_action) wp-includes/plugin.php | Removes a callback function from an action hook. | | [current\_filter()](../../functions/current_filter) wp-includes/plugin.php | Retrieves the name of the current filter hook. | | [remove\_all\_filters()](../../functions/remove_all_filters) wp-includes/plugin.php | Removes all of the callback functions from a filter hook. | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [Language\_Pack\_Upgrader::upgrade()](upgrade) wp-admin/includes/class-language-pack-upgrader.php | Upgrade a language pack. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress Language_Pack_Upgrader::check_package( string|WP_Error $source, string $remote_source ): string|WP_Error Language\_Pack\_Upgrader::check\_package( string|WP\_Error $source, string $remote\_source ): string|WP\_Error ============================================================================================================== Checks that the package source contains .mo and .po files. Hooked to the [‘upgrader\_source\_selection’](../../hooks/upgrader_source_selection) filter by [Language\_Pack\_Upgrader::bulk\_upgrade()](bulk_upgrade). `$source` string|[WP\_Error](../wp_error) Required The path to the downloaded package source. `$remote_source` string Required Remote file source location. string|[WP\_Error](../wp_error) The source as passed, or a [WP\_Error](../wp_error) object on failure. File: `wp-admin/includes/class-language-pack-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-language-pack-upgrader.php/) ``` public function check_package( $source, $remote_source ) { global $wp_filesystem; if ( is_wp_error( $source ) ) { return $source; } // Check that the folder contains a valid language. $files = $wp_filesystem->dirlist( $remote_source ); // Check to see if a .po and .mo exist in the folder. $po = false; $mo = false; foreach ( (array) $files as $file => $filedata ) { if ( '.po' === substr( $file, -3 ) ) { $po = true; } elseif ( '.mo' === substr( $file, -3 ) ) { $mo = true; } } if ( ! $mo || ! $po ) { return new WP_Error( 'incompatible_archive_pomo', $this->strings['incompatible_archive'], sprintf( /* translators: 1: .po, 2: .mo */ __( 'The language pack is missing either the %1$s or %2$s files.' ), '<code>.po</code>', '<code>.mo</code>' ) ); } return $source; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. |
programming_docs
wordpress Language_Pack_Upgrader::async_upgrade( false|WP_Upgrader $upgrader = false ) Language\_Pack\_Upgrader::async\_upgrade( false|WP\_Upgrader $upgrader = false ) ================================================================================ Asynchronously upgrades language packs after other upgrades have been made. Hooked to the [‘upgrader\_process\_complete’](../../hooks/upgrader_process_complete) action by default. `$upgrader` false|[WP\_Upgrader](../wp_upgrader) Optional [WP\_Upgrader](../wp_upgrader) instance or false. If `$upgrader` is a [Language\_Pack\_Upgrader](../language_pack_upgrader) instance, the method will bail to avoid recursion. Otherwise unused. Default: `false` File: `wp-admin/includes/class-language-pack-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-language-pack-upgrader.php/) ``` public static function async_upgrade( $upgrader = false ) { // Avoid recursion. if ( $upgrader && $upgrader instanceof Language_Pack_Upgrader ) { return; } // Nothing to do? $language_updates = wp_get_translation_updates(); if ( ! $language_updates ) { return; } /* * Avoid messing with VCS installations, at least for now. * Noted: this is not the ideal way to accomplish this. */ $check_vcs = new WP_Automatic_Updater; if ( $check_vcs->is_vcs_checkout( WP_CONTENT_DIR ) ) { return; } foreach ( $language_updates as $key => $language_update ) { $update = ! empty( $language_update->autoupdate ); /** * Filters whether to asynchronously update translation for core, a plugin, or a theme. * * @since 4.0.0 * * @param bool $update Whether to update. * @param object $language_update The update offer. */ $update = apply_filters( 'async_update_translation', $update, $language_update ); if ( ! $update ) { unset( $language_updates[ $key ] ); } } if ( empty( $language_updates ) ) { return; } // Re-use the automatic upgrader skin if the parent upgrader is using it. if ( $upgrader && $upgrader->skin instanceof Automatic_Upgrader_Skin ) { $skin = $upgrader->skin; } else { $skin = new Language_Pack_Upgrader_Skin( array( 'skip_header_footer' => true, ) ); } $lp_upgrader = new Language_Pack_Upgrader( $skin ); $lp_upgrader->bulk_upgrade( $language_updates ); } ``` [apply\_filters( 'async\_update\_translation', bool $update, object $language\_update )](../../hooks/async_update_translation) Filters whether to asynchronously update translation for core, a plugin, or a theme. | Uses | Description | | --- | --- | | [Language\_Pack\_Upgrader\_Skin::\_\_construct()](../language_pack_upgrader_skin/__construct) wp-admin/includes/class-language-pack-upgrader-skin.php | | | [wp\_get\_translation\_updates()](../../functions/wp_get_translation_updates) wp-includes/update.php | Retrieves a list of all language updates available. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress Language_Pack_Upgrader::upgrade( string|false $update = false, array $args = array() ): array|bool|WP_Error Language\_Pack\_Upgrader::upgrade( string|false $update = false, array $args = array() ): array|bool|WP\_Error ============================================================================================================== Upgrade a language pack. `$update` string|false Optional Whether an update offer is available. Default: `false` `$args` array Optional Other optional arguments, see [Language\_Pack\_Upgrader::bulk\_upgrade()](bulk_upgrade). More Arguments from Language\_Pack\_Upgrader::bulk\_upgrade( ... $args ) Other arguments for upgrading multiple language packs. * `clear_update_cache`boolWhether to clear the update cache when done. Default true. Default: `array()` array|bool|[WP\_Error](../wp_error) The result of the upgrade, or a [WP\_Error](../wp_error) object instead. File: `wp-admin/includes/class-language-pack-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-language-pack-upgrader.php/) ``` public function upgrade( $update = false, $args = array() ) { if ( $update ) { $update = array( $update ); } $results = $this->bulk_upgrade( $update, $args ); if ( ! is_array( $results ) ) { return $results; } return $results[0]; } ``` | Uses | Description | | --- | --- | | [Language\_Pack\_Upgrader::bulk\_upgrade()](bulk_upgrade) wp-admin/includes/class-language-pack-upgrader.php | Bulk upgrade language packs. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress Language_Pack_Upgrader::upgrade_strings() Language\_Pack\_Upgrader::upgrade\_strings() ============================================ Initialize the upgrade strings. File: `wp-admin/includes/class-language-pack-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-language-pack-upgrader.php/) ``` public function upgrade_strings() { $this->strings['starting_upgrade'] = __( 'Some of your translations need updating. Sit tight for a few more seconds while they are updated as well.' ); $this->strings['up_to_date'] = __( 'Your translations are all up to date.' ); $this->strings['no_package'] = __( 'Update package not available.' ); /* translators: %s: Package URL. */ $this->strings['downloading_package'] = sprintf( __( 'Downloading translation from %s&#8230;' ), '<span class="code">%s</span>' ); $this->strings['unpack_package'] = __( 'Unpacking the update&#8230;' ); $this->strings['process_failed'] = __( 'Translation update failed.' ); $this->strings['process_success'] = __( 'Translation updated successfully.' ); $this->strings['remove_old'] = __( 'Removing the old version of the translation&#8230;' ); $this->strings['remove_old_failed'] = __( 'Could not remove the old translation.' ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [Language\_Pack\_Upgrader::bulk\_upgrade()](bulk_upgrade) wp-admin/includes/class-language-pack-upgrader.php | Bulk upgrade language packs. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. | wordpress Language_Pack_Upgrader::clear_destination( string $remote_destination ): bool|WP_Error Language\_Pack\_Upgrader::clear\_destination( string $remote\_destination ): bool|WP\_Error =========================================================================================== Clears existing translations where this item is going to be installed into. `$remote_destination` string Required The location on the remote filesystem to be cleared. bool|[WP\_Error](../wp_error) True upon success, [WP\_Error](../wp_error) on failure. File: `wp-admin/includes/class-language-pack-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-language-pack-upgrader.php/) ``` public function clear_destination( $remote_destination ) { global $wp_filesystem; $language_update = $this->skin->language_update; $language_directory = WP_LANG_DIR . '/'; // Local path for use with glob(). if ( 'core' === $language_update->type ) { $files = array( $remote_destination . $language_update->language . '.po', $remote_destination . $language_update->language . '.mo', $remote_destination . 'admin-' . $language_update->language . '.po', $remote_destination . 'admin-' . $language_update->language . '.mo', $remote_destination . 'admin-network-' . $language_update->language . '.po', $remote_destination . 'admin-network-' . $language_update->language . '.mo', $remote_destination . 'continents-cities-' . $language_update->language . '.po', $remote_destination . 'continents-cities-' . $language_update->language . '.mo', ); $json_translation_files = glob( $language_directory . $language_update->language . '-*.json' ); if ( $json_translation_files ) { foreach ( $json_translation_files as $json_translation_file ) { $files[] = str_replace( $language_directory, $remote_destination, $json_translation_file ); } } } else { $files = array( $remote_destination . $language_update->slug . '-' . $language_update->language . '.po', $remote_destination . $language_update->slug . '-' . $language_update->language . '.mo', ); $language_directory = $language_directory . $language_update->type . 's/'; $json_translation_files = glob( $language_directory . $language_update->slug . '-' . $language_update->language . '-*.json' ); if ( $json_translation_files ) { foreach ( $json_translation_files as $json_translation_file ) { $files[] = str_replace( $language_directory, $remote_destination, $json_translation_file ); } } } $files = array_filter( $files, array( $wp_filesystem, 'exists' ) ); // No files to delete. if ( ! $files ) { return true; } // Check all files are writable before attempting to clear the destination. $unwritable_files = array(); // Check writability. foreach ( $files as $file ) { if ( ! $wp_filesystem->is_writable( $file ) ) { // Attempt to alter permissions to allow writes and try again. $wp_filesystem->chmod( $file, FS_CHMOD_FILE ); if ( ! $wp_filesystem->is_writable( $file ) ) { $unwritable_files[] = $file; } } } if ( ! empty( $unwritable_files ) ) { return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) ); } foreach ( $files as $file ) { if ( ! $wp_filesystem->delete( $file ) ) { return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] ); } } return true; } ``` | Uses | Description | | --- | --- | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.1.0](https://developer.wordpress.org/reference/since/5.1.0/) | Introduced. | wordpress WP_Customize_Filter_Setting::update( mixed $value ) WP\_Customize\_Filter\_Setting::update( mixed $value ) ====================================================== Saves the value of the setting, using the related API. `$value` mixed Required The value to update. File: `wp-includes/customize/class-wp-customize-filter-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-filter-setting.php/) ``` public function update( $value ) {} ``` | Version | Description | | --- | --- | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::get_directory_sizes(): array|WP_Error WP\_REST\_Site\_Health\_Controller::get\_directory\_sizes(): array|WP\_Error ============================================================================ Gets the current directory sizes for this install. array|[WP\_Error](../wp_error) File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function get_directory_sizes() { if ( ! class_exists( 'WP_Debug_Data' ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php'; } $this->load_admin_textdomain(); $sizes_data = WP_Debug_Data::get_sizes(); $all_sizes = array( 'raw' => 0 ); foreach ( $sizes_data as $name => $value ) { $name = sanitize_text_field( $name ); $data = array(); if ( isset( $value['size'] ) ) { if ( is_string( $value['size'] ) ) { $data['size'] = sanitize_text_field( $value['size'] ); } else { $data['size'] = (int) $value['size']; } } if ( isset( $value['debug'] ) ) { if ( is_string( $value['debug'] ) ) { $data['debug'] = sanitize_text_field( $value['debug'] ); } else { $data['debug'] = (int) $value['debug']; } } if ( ! empty( $value['raw'] ) ) { $data['raw'] = (int) $value['raw']; } $all_sizes[ $name ] = $data; } if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) { return new WP_Error( 'not_available', __( 'Directory sizes could not be returned.' ), array( 'status' => 500 ) ); } return $all_sizes; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::load\_admin\_textdomain()](load_admin_textdomain) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Loads the admin textdomain for Site Health tests. | | [WP\_Debug\_Data::get\_sizes()](../wp_debug_data/get_sizes) wp-admin/includes/class-wp-debug-data.php | Fetches the sizes of the WordPress directories: `wordpress` (ABSPATH), `plugins`, `themes`, and `uploads`. | | [sanitize\_text\_field()](../../functions/sanitize_text_field) wp-includes/formatting.php | Sanitizes a string from user input or from the database. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::load_admin_textdomain() WP\_REST\_Site\_Health\_Controller::load\_admin\_textdomain() ============================================================= Loads the admin textdomain for Site Health tests. The [WP\_Site\_Health](../wp_site_health) class is defined in WP-Admin, while the REST API operates in a front-end context. This means that the translations for Site Health won’t be loaded by default in [load\_default\_textdomain()](../../functions/load_default_textdomain) . File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` protected function load_admin_textdomain() { // Accounts for inner REST API requests in the admin. if ( ! is_admin() ) { $locale = determine_locale(); load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" ); } } ``` | Uses | Description | | --- | --- | | [determine\_locale()](../../functions/determine_locale) wp-includes/l10n.php | Determines the current locale desired for the request. | | [load\_textdomain()](../../functions/load_textdomain) wp-includes/l10n.php | Loads a .mo file into the text domain $domain. | | [is\_admin()](../../functions/is_admin) wp-includes/load.php | Determines whether the current request is for an administrative interface page. | | Used By | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::test\_page\_cache()](test_page_cache) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Checks that full page cache is active. | | [WP\_REST\_Site\_Health\_Controller::test\_https\_status()](test_https_status) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Checks that the site’s frontend can be accessed over HTTPS. | | [WP\_REST\_Site\_Health\_Controller::test\_background\_updates()](test_background_updates) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Checks if background updates work as expected. | | [WP\_REST\_Site\_Health\_Controller::test\_dotorg\_communication()](test_dotorg_communication) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Checks that the site can reach the WordPress.org API. | | [WP\_REST\_Site\_Health\_Controller::test\_loopback\_requests()](test_loopback_requests) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Checks that loopbacks can be performed. | | [WP\_REST\_Site\_Health\_Controller::test\_authorization\_header()](test_authorization_header) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Checks that the authorization header is valid. | | [WP\_REST\_Site\_Health\_Controller::get\_directory\_sizes()](get_directory_sizes) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Gets the current directory sizes for this install. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::test_dotorg_communication(): array WP\_REST\_Site\_Health\_Controller::test\_dotorg\_communication(): array ======================================================================== Checks that the site can reach the WordPress.org API. array File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function test_dotorg_communication() { $this->load_admin_textdomain(); return $this->site_health->get_test_dotorg_communication(); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::load\_admin\_textdomain()](../wp_rest_site_health_controller/load_admin_textdomain) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Loads the admin textdomain for Site Health tests. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::test_loopback_requests(): array WP\_REST\_Site\_Health\_Controller::test\_loopback\_requests(): array ===================================================================== Checks that loopbacks can be performed. array File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function test_loopback_requests() { $this->load_admin_textdomain(); return $this->site_health->get_test_loopback_requests(); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::load\_admin\_textdomain()](../wp_rest_site_health_controller/load_admin_textdomain) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Loads the admin textdomain for Site Health tests. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::validate_request_permission( string $check ): bool WP\_REST\_Site\_Health\_Controller::validate\_request\_permission( string $check ): bool ======================================================================================== Validates if the current user can request this REST endpoint. `$check` string Required The endpoint check being ran. bool File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` protected function validate_request_permission( $check ) { $default_capability = 'view_site_health_checks'; /** * Filters the capability needed to run a given Site Health check. * * @since 5.6.0 * * @param string $default_capability The default capability required for this check. * @param string $check The Site Health check being performed. */ $capability = apply_filters( "site_health_test_rest_capability_{$check}", $default_capability, $check ); return current_user_can( $capability ); } ``` [apply\_filters( "site\_health\_test\_rest\_capability\_{$check}", string $default\_capability, string $check )](../../hooks/site_health_test_rest_capability_check) Filters the capability needed to run a given Site Health check. | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::register\_routes()](register_routes) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Registers API routes. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. |
programming_docs
wordpress WP_REST_Site_Health_Controller::register_routes() WP\_REST\_Site\_Health\_Controller::register\_routes() ====================================================== Registers API routes. * [register\_rest\_route()](../../functions/register_rest_route) File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function register_routes() { register_rest_route( $this->namespace, sprintf( '/%s/%s', $this->rest_base, 'background-updates' ), array( array( 'methods' => 'GET', 'callback' => array( $this, 'test_background_updates' ), 'permission_callback' => function () { return $this->validate_request_permission( 'background_updates' ); }, ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, sprintf( '/%s/%s', $this->rest_base, 'loopback-requests' ), array( array( 'methods' => 'GET', 'callback' => array( $this, 'test_loopback_requests' ), 'permission_callback' => function () { return $this->validate_request_permission( 'loopback_requests' ); }, ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, sprintf( '/%s/%s', $this->rest_base, 'https-status' ), array( array( 'methods' => 'GET', 'callback' => array( $this, 'test_https_status' ), 'permission_callback' => function () { return $this->validate_request_permission( 'https_status' ); }, ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, sprintf( '/%s/%s', $this->rest_base, 'dotorg-communication' ), array( array( 'methods' => 'GET', 'callback' => array( $this, 'test_dotorg_communication' ), 'permission_callback' => function () { return $this->validate_request_permission( 'dotorg_communication' ); }, ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, sprintf( '/%s/%s', $this->rest_base, 'authorization-header' ), array( array( 'methods' => 'GET', 'callback' => array( $this, 'test_authorization_header' ), 'permission_callback' => function () { return $this->validate_request_permission( 'authorization_header' ); }, ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, sprintf( '/%s', 'directory-sizes' ), array( 'methods' => 'GET', 'callback' => array( $this, 'get_directory_sizes' ), 'permission_callback' => function() { return $this->validate_request_permission( 'debug_enabled' ) && ! is_multisite(); }, ) ); register_rest_route( $this->namespace, sprintf( '/%s/%s', $this->rest_base, 'page-cache' ), array( array( 'methods' => 'GET', 'callback' => array( $this, 'test_page_cache' ), 'permission_callback' => function () { return $this->validate_request_permission( 'view_site_health_checks' ); }, ), ) ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::validate\_request\_permission()](validate_request_permission) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Validates if the current user can request this REST endpoint. | | [register\_rest\_route()](../../functions/register_rest_route) wp-includes/rest-api.php | Registers a REST API route. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Adds page-cache async test. | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::__construct( WP_Site_Health $site_health ) WP\_REST\_Site\_Health\_Controller::\_\_construct( WP\_Site\_Health $site\_health ) =================================================================================== Site Health controller constructor. `$site_health` [WP\_Site\_Health](../wp_site_health) Required An instance of the site health class. File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function __construct( $site_health ) { $this->namespace = 'wp-site-health/v1'; $this->rest_base = 'tests'; $this->site_health = $site_health; } ``` | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::test_authorization_header(): array WP\_REST\_Site\_Health\_Controller::test\_authorization\_header(): array ======================================================================== Checks that the authorization header is valid. array File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function test_authorization_header() { $this->load_admin_textdomain(); return $this->site_health->get_test_authorization_header(); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::load\_admin\_textdomain()](load_admin_textdomain) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Loads the admin textdomain for Site Health tests. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::test_page_cache(): array WP\_REST\_Site\_Health\_Controller::test\_page\_cache(): array ============================================================== Checks that full page cache is active. array The test result. File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function test_page_cache() { $this->load_admin_textdomain(); return $this->site_health->get_test_page_cache(); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::load\_admin\_textdomain()](load_admin_textdomain) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Loads the admin textdomain for Site Health tests. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::test_background_updates(): array WP\_REST\_Site\_Health\_Controller::test\_background\_updates(): array ====================================================================== Checks if background updates work as expected. array File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function test_background_updates() { $this->load_admin_textdomain(); return $this->site_health->get_test_background_updates(); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::load\_admin\_textdomain()](../wp_rest_site_health_controller/load_admin_textdomain) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Loads the admin textdomain for Site Health tests. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::get_item_schema(): array WP\_REST\_Site\_Health\_Controller::get\_item\_schema(): array ============================================================== Gets the schema for each site health test. array The test schema. File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->schema; } $this->schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'wp-site-health-test', 'type' => 'object', 'properties' => array( 'test' => array( 'type' => 'string', 'description' => __( 'The name of the test being run.' ), 'readonly' => true, ), 'label' => array( 'type' => 'string', 'description' => __( 'A label describing the test.' ), 'readonly' => true, ), 'status' => array( 'type' => 'string', 'description' => __( 'The status of the test.' ), 'enum' => array( 'good', 'recommended', 'critical' ), 'readonly' => true, ), 'badge' => array( 'type' => 'object', 'description' => __( 'The category this test is grouped in.' ), 'properties' => array( 'label' => array( 'type' => 'string', 'readonly' => true, ), 'color' => array( 'type' => 'string', 'enum' => array( 'blue', 'orange', 'red', 'green', 'purple', 'gray' ), 'readonly' => true, ), ), 'readonly' => true, ), 'description' => array( 'type' => 'string', 'description' => __( 'A more descriptive explanation of what the test looks for, and why it is important for the user.' ), 'readonly' => true, ), 'actions' => array( 'type' => 'string', 'description' => __( 'HTML containing an action to direct the user to where they can resolve the issue.' ), 'readonly' => true, ), ), ); return $this->schema; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Introduced. | wordpress WP_REST_Site_Health_Controller::test_https_status(): array WP\_REST\_Site\_Health\_Controller::test\_https\_status(): array ================================================================ Checks that the site’s frontend can be accessed over HTTPS. array File: `wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php/) ``` public function test_https_status() { $this->load_admin_textdomain(); return $this->site_health->get_test_https_status(); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Site\_Health\_Controller::load\_admin\_textdomain()](load_admin_textdomain) wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php | Loads the admin textdomain for Site Health tests. | | Version | Description | | --- | --- | | [5.7.0](https://developer.wordpress.org/reference/since/5.7.0/) | Introduced. | wordpress Plugin_Upgrader::install( string $package, array $args = array() ): bool|WP_Error Plugin\_Upgrader::install( string $package, array $args = array() ): bool|WP\_Error =================================================================================== Install a plugin package. `$package` string Required The full local path or URI of the package. `$args` array Optional Other arguments for installing a plugin package. * `clear_update_cache`boolWhether to clear the plugin updates cache if successful. Default true. Default: `array()` bool|[WP\_Error](../wp_error) True if the installation was successful, false or a [WP\_Error](../wp_error) otherwise. File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function install( $package, $args = array() ) { $defaults = array( 'clear_update_cache' => true, 'overwrite_package' => false, // Do not overwrite files. ); $parsed_args = wp_parse_args( $args, $defaults ); $this->init(); $this->install_strings(); add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); if ( $parsed_args['clear_update_cache'] ) { // Clear cache so wp_update_plugins() knows about the new plugin. add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 ); } $this->run( array( 'package' => $package, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => $parsed_args['overwrite_package'], 'clear_working' => true, 'hook_extra' => array( 'type' => 'plugin', 'action' => 'install', ), ) ); remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 ); remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) ); if ( ! $this->result || is_wp_error( $this->result ) ) { return $this->result; } // Force refresh of plugin update information. wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); if ( $parsed_args['overwrite_package'] ) { /** * Fires when the upgrader has successfully overwritten a currently installed * plugin or theme with an uploaded zip package. * * @since 5.5.0 * * @param string $package The package file. * @param array $data The new plugin or theme data. * @param string $package_type The package type ('plugin' or 'theme'). */ do_action( 'upgrader_overwrote_package', $package, $this->new_plugin_data, 'plugin' ); } return true; } ``` [do\_action( 'upgrader\_overwrote\_package', string $package, array $data, string $package\_type )](../../hooks/upgrader_overwrote_package) Fires when the upgrader has successfully overwritten a currently installed plugin or theme with an uploaded zip package. | Uses | Description | | --- | --- | | [Plugin\_Upgrader::install\_strings()](install_strings) wp-admin/includes/class-plugin-upgrader.php | Initialize the installation strings. | | [wp\_clean\_plugins\_cache()](../../functions/wp_clean_plugins_cache) wp-admin/includes/plugin.php | Clears the plugins cache used by [get\_plugins()](../../functions/get_plugins) and by default, the plugin updates cache. | | [remove\_action()](../../functions/remove_action) wp-includes/plugin.php | Removes a callback function from an action hook. | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | The `$args` parameter was added, making clearing the plugin update cache optional. | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress Plugin_Upgrader::deactivate_plugin_before_upgrade( bool|WP_Error $response, array $plugin ): bool|WP_Error Plugin\_Upgrader::deactivate\_plugin\_before\_upgrade( bool|WP\_Error $response, array $plugin ): bool|WP\_Error ================================================================================================================ Deactivates a plugin before it is upgraded. Hooked to the [‘upgrader\_pre\_install’](../../hooks/upgrader_pre_install) filter by [Plugin\_Upgrader::upgrade()](upgrade). `$response` bool|[WP\_Error](../wp_error) Required The installation response before the installation has started. `$plugin` array Required Plugin package arguments. bool|[WP\_Error](../wp_error) The original `$response` parameter or [WP\_Error](../wp_error). File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function deactivate_plugin_before_upgrade( $response, $plugin ) { if ( is_wp_error( $response ) ) { // Bypass. return $response; } // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it. if ( wp_doing_cron() ) { return $response; } $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; if ( empty( $plugin ) ) { return new WP_Error( 'bad_request', $this->strings['bad_request'] ); } if ( is_plugin_active( $plugin ) ) { // Deactivate the plugin silently, Prevent deactivation hooks from running. deactivate_plugins( $plugin, true ); } return $response; } ``` | Uses | Description | | --- | --- | | [wp\_doing\_cron()](../../functions/wp_doing_cron) wp-includes/load.php | Determines whether the current request is a WordPress cron request. | | [is\_plugin\_active()](../../functions/is_plugin_active) wp-admin/includes/plugin.php | Determines whether a plugin is active. | | [deactivate\_plugins()](../../functions/deactivate_plugins) wp-admin/includes/plugin.php | Deactivates a single plugin or multiple plugins. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | Added a return value. | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress Plugin_Upgrader::bulk_upgrade( string[] $plugins, array $args = array() ): array|false Plugin\_Upgrader::bulk\_upgrade( string[] $plugins, array $args = array() ): array|false ======================================================================================== Bulk upgrade several plugins at once. `$plugins` string[] Required Array of paths to plugin files relative to the plugins directory. `$args` array Optional Other arguments for upgrading several plugins at once. * `clear_update_cache`boolWhether to clear the plugin updates cache if successful. Default true. Default: `array()` array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem. File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function bulk_upgrade( $plugins, $args = array() ) { $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); $this->init(); $this->bulk = true; $this->upgrade_strings(); $current = get_site_transient( 'update_plugins' ); add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 ); $this->skin->header(); // Connect to the filesystem first. $res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) ); if ( ! $res ) { $this->skin->footer(); return false; } $this->skin->bulk_header(); /* * Only start maintenance mode if: * - running Multisite and there are one or more plugins specified, OR * - a plugin with an update available is currently active. * @todo For multisite, maintenance mode should only kick in for individual sites if at all possible. */ $maintenance = ( is_multisite() && ! empty( $plugins ) ); foreach ( $plugins as $plugin ) { $maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) ); } if ( $maintenance ) { $this->maintenance_mode( true ); } $results = array(); $this->update_count = count( $plugins ); $this->update_current = 0; foreach ( $plugins as $plugin ) { $this->update_current++; $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true ); if ( ! isset( $current->response[ $plugin ] ) ) { $this->skin->set_result( 'up_to_date' ); $this->skin->before(); $this->skin->feedback( 'up_to_date' ); $this->skin->after(); $results[ $plugin ] = true; continue; } // Get the URL to the zip file. $r = $current->response[ $plugin ]; $this->skin->plugin_active = is_plugin_active( $plugin ); $result = $this->run( array( 'package' => $r->package, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'is_multi' => true, 'hook_extra' => array( 'plugin' => $plugin, ), ) ); $results[ $plugin ] = $result; // Prevent credentials auth screen from displaying multiple times. if ( false === $result ) { break; } } // End foreach $plugins. $this->maintenance_mode( false ); // Force refresh of plugin update information. wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'plugin', 'bulk' => true, 'plugins' => $plugins, ) ); $this->skin->bulk_footer(); $this->skin->footer(); // Cleanup our hooks, in case something else does a upgrade on this connection. remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) ); // Ensure any future auto-update failures trigger a failure email by removing // the last failure notification from the list when plugins update successfully. $past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() ); foreach ( $results as $plugin => $result ) { // Maintain last failure notification when plugins failed to update manually. if ( ! $result || is_wp_error( $result ) || ! isset( $past_failure_emails[ $plugin ] ) ) { continue; } unset( $past_failure_emails[ $plugin ] ); } update_option( 'auto_plugin_theme_update_emails', $past_failure_emails ); return $results; } ``` [do\_action( 'upgrader\_process\_complete', WP\_Upgrader $upgrader, array $hook\_extra )](../../hooks/upgrader_process_complete) Fires when the upgrader process is complete. | Uses | Description | | --- | --- | | [Plugin\_Upgrader::upgrade\_strings()](upgrade_strings) wp-admin/includes/class-plugin-upgrader.php | Initialize the upgrade strings. | | [wp\_clean\_plugins\_cache()](../../functions/wp_clean_plugins_cache) wp-admin/includes/plugin.php | Clears the plugins cache used by [get\_plugins()](../../functions/get_plugins) and by default, the plugin updates cache. | | [is\_plugin\_active()](../../functions/is_plugin_active) wp-admin/includes/plugin.php | Determines whether a plugin is active. | | [get\_plugin\_data()](../../functions/get_plugin_data) wp-admin/includes/plugin.php | Parses the plugin contents to retrieve plugin’s metadata. | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [get\_site\_transient()](../../functions/get_site_transient) wp-includes/option.php | Retrieves the value of a site transient. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [update\_option()](../../functions/update_option) wp-includes/option.php | Updates the value of an option that was already added. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | The `$args` parameter was added, making clearing the plugin update cache optional. | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |
programming_docs
wordpress Plugin_Upgrader::check_package( string $source ): string|WP_Error Plugin\_Upgrader::check\_package( string $source ): string|WP\_Error ==================================================================== Checks that the source package contains a valid plugin. Hooked to the [‘upgrader\_source\_selection’](../../hooks/upgrader_source_selection) filter by [Plugin\_Upgrader::install()](install). `$source` string Required The path to the downloaded package source. string|[WP\_Error](../wp_error) The source as passed, or a [WP\_Error](../wp_error) object on failure. File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function check_package( $source ) { global $wp_filesystem, $wp_version; $this->new_plugin_data = array(); if ( is_wp_error( $source ) ) { return $source; } $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source ); if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation. return $source; } // Check that the folder contains at least 1 valid plugin. $files = glob( $working_directory . '*.php' ); if ( $files ) { foreach ( $files as $file ) { $info = get_plugin_data( $file, false, false ); if ( ! empty( $info['Name'] ) ) { $this->new_plugin_data = $info; break; } } } if ( empty( $this->new_plugin_data ) ) { return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) ); } $requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null; $requires_wp = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null; if ( ! is_php_version_compatible( $requires_php ) ) { $error = sprintf( /* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */ __( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ), PHP_VERSION, $requires_php ); return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error ); } if ( ! is_wp_version_compatible( $requires_wp ) ) { $error = sprintf( /* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */ __( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ), $wp_version, $requires_wp ); return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error ); } return $source; } ``` | Uses | Description | | --- | --- | | [is\_php\_version\_compatible()](../../functions/is_php_version_compatible) wp-includes/functions.php | Checks compatibility with the current PHP version. | | [is\_wp\_version\_compatible()](../../functions/is_wp_version_compatible) wp-includes/functions.php | Checks compatibility with the current WordPress version. | | [get\_plugin\_data()](../../functions/get_plugin_data) wp-admin/includes/plugin.php | Parses the plugin contents to retrieve plugin’s metadata. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [trailingslashit()](../../functions/trailingslashit) wp-includes/formatting.php | Appends a trailing slash. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress Plugin_Upgrader::active_before( bool|WP_Error $response, array $plugin ): bool|WP_Error Plugin\_Upgrader::active\_before( bool|WP\_Error $response, array $plugin ): bool|WP\_Error =========================================================================================== Turns on maintenance mode before attempting to background update an active plugin. Hooked to the [‘upgrader\_pre\_install’](../../hooks/upgrader_pre_install) filter by [Plugin\_Upgrader::upgrade()](upgrade). `$response` bool|[WP\_Error](../wp_error) Required The installation response before the installation has started. `$plugin` array Required Plugin package arguments. bool|[WP\_Error](../wp_error) The original `$response` parameter or [WP\_Error](../wp_error). File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function active_before( $response, $plugin ) { if ( is_wp_error( $response ) ) { return $response; } // Only enable maintenance mode when in cron (background update). if ( ! wp_doing_cron() ) { return $response; } $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; // Only run if plugin is active. if ( ! is_plugin_active( $plugin ) ) { return $response; } // Change to maintenance mode. Bulk edit handles this separately. if ( ! $this->bulk ) { $this->maintenance_mode( true ); } return $response; } ``` | Uses | Description | | --- | --- | | [wp\_doing\_cron()](../../functions/wp_doing_cron) wp-includes/load.php | Determines whether the current request is a WordPress cron request. | | [is\_plugin\_active()](../../functions/is_plugin_active) wp-admin/includes/plugin.php | Determines whether a plugin is active. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.4.0](https://developer.wordpress.org/reference/since/5.4.0/) | Introduced. | wordpress Plugin_Upgrader::active_after( bool|WP_Error $response, array $plugin ): bool|WP_Error Plugin\_Upgrader::active\_after( bool|WP\_Error $response, array $plugin ): bool|WP\_Error ========================================================================================== Turns off maintenance mode after upgrading an active plugin. Hooked to the [‘upgrader\_post\_install’](../../hooks/upgrader_post_install) filter by [Plugin\_Upgrader::upgrade()](upgrade). `$response` bool|[WP\_Error](../wp_error) Required The installation response after the installation has finished. `$plugin` array Required Plugin package arguments. bool|[WP\_Error](../wp_error) The original `$response` parameter or [WP\_Error](../wp_error). File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function active_after( $response, $plugin ) { if ( is_wp_error( $response ) ) { return $response; } // Only disable maintenance mode when in cron (background update). if ( ! wp_doing_cron() ) { return $response; } $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; // Only run if plugin is active. if ( ! is_plugin_active( $plugin ) ) { return $response; } // Time to remove maintenance mode. Bulk edit handles this separately. if ( ! $this->bulk ) { $this->maintenance_mode( false ); } return $response; } ``` | Uses | Description | | --- | --- | | [wp\_doing\_cron()](../../functions/wp_doing_cron) wp-includes/load.php | Determines whether the current request is a WordPress cron request. | | [is\_plugin\_active()](../../functions/is_plugin_active) wp-admin/includes/plugin.php | Determines whether a plugin is active. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.4.0](https://developer.wordpress.org/reference/since/5.4.0/) | Introduced. | wordpress Plugin_Upgrader::upgrade( string $plugin, array $args = array() ): bool|WP_Error Plugin\_Upgrader::upgrade( string $plugin, array $args = array() ): bool|WP\_Error ================================================================================== Upgrade a plugin. `$plugin` string Required Path to the plugin file relative to the plugins directory. `$args` array Optional Other arguments for upgrading a plugin package. * `clear_update_cache`boolWhether to clear the plugin updates cache if successful. Default true. Default: `array()` bool|[WP\_Error](../wp_error) True if the upgrade was successful, false or a [WP\_Error](../wp_error) object otherwise. File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function upgrade( $plugin, $args = array() ) { $defaults = array( 'clear_update_cache' => true, ); $parsed_args = wp_parse_args( $args, $defaults ); $this->init(); $this->upgrade_strings(); $current = get_site_transient( 'update_plugins' ); if ( ! isset( $current->response[ $plugin ] ) ) { $this->skin->before(); $this->skin->set_result( false ); $this->skin->error( 'up_to_date' ); $this->skin->after(); return false; } // Get the URL to the zip file. $r = $current->response[ $plugin ]; add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 ); add_filter( 'upgrader_pre_install', array( $this, 'active_before' ), 10, 2 ); add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 ); add_filter( 'upgrader_post_install', array( $this, 'active_after' ), 10, 2 ); // There's a Trac ticket to move up the directory for zips which are made a bit differently, useful for non-.org plugins. // 'source_selection' => array( $this, 'source_selection' ), if ( $parsed_args['clear_update_cache'] ) { // Clear cache so wp_update_plugins() knows about the new plugin. add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 ); } $this->run( array( 'package' => $r->package, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array( 'plugin' => $plugin, 'type' => 'plugin', 'action' => 'update', ), ) ); // Cleanup our hooks, in case something else does a upgrade on this connection. remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 ); remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) ); remove_filter( 'upgrader_pre_install', array( $this, 'active_before' ) ); remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) ); remove_filter( 'upgrader_post_install', array( $this, 'active_after' ) ); if ( ! $this->result || is_wp_error( $this->result ) ) { return $this->result; } // Force refresh of plugin update information. wp_clean_plugins_cache( $parsed_args['clear_update_cache'] ); // Ensure any future auto-update failures trigger a failure email by removing // the last failure notification from the list when plugins update successfully. $past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() ); if ( isset( $past_failure_emails[ $plugin ] ) ) { unset( $past_failure_emails[ $plugin ] ); update_option( 'auto_plugin_theme_update_emails', $past_failure_emails ); } return true; } ``` | Uses | Description | | --- | --- | | [Plugin\_Upgrader::upgrade\_strings()](upgrade_strings) wp-admin/includes/class-plugin-upgrader.php | Initialize the upgrade strings. | | [wp\_clean\_plugins\_cache()](../../functions/wp_clean_plugins_cache) wp-admin/includes/plugin.php | Clears the plugins cache used by [get\_plugins()](../../functions/get_plugins) and by default, the plugin updates cache. | | [remove\_action()](../../functions/remove_action) wp-includes/plugin.php | Removes a callback function from an action hook. | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [get\_site\_transient()](../../functions/get_site_transient) wp-includes/option.php | Retrieves the value of a site transient. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [update\_option()](../../functions/update_option) wp-includes/option.php | Updates the value of an option that was already added. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | The `$args` parameter was added, making clearing the plugin update cache optional. | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress Plugin_Upgrader::install_strings() Plugin\_Upgrader::install\_strings() ==================================== Initialize the installation strings. File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function install_strings() { $this->strings['no_package'] = __( 'Installation package not available.' ); /* translators: %s: Package URL. */ $this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s&#8230;' ), '<span class="code">%s</span>' ); $this->strings['unpack_package'] = __( 'Unpacking the package&#8230;' ); $this->strings['installing_package'] = __( 'Installing the plugin&#8230;' ); $this->strings['remove_old'] = __( 'Removing the current plugin&#8230;' ); $this->strings['remove_old_failed'] = __( 'Could not remove the current plugin.' ); $this->strings['no_files'] = __( 'The plugin contains no files.' ); $this->strings['process_failed'] = __( 'Plugin installation failed.' ); $this->strings['process_success'] = __( 'Plugin installed successfully.' ); /* translators: 1: Plugin name, 2: Plugin version. */ $this->strings['process_success_specific'] = __( 'Successfully installed the plugin <strong>%1$s %2$s</strong>.' ); if ( ! empty( $this->skin->overwrite ) ) { if ( 'update-plugin' === $this->skin->overwrite ) { $this->strings['installing_package'] = __( 'Updating the plugin&#8230;' ); $this->strings['process_failed'] = __( 'Plugin update failed.' ); $this->strings['process_success'] = __( 'Plugin updated successfully.' ); } if ( 'downgrade-plugin' === $this->skin->overwrite ) { $this->strings['installing_package'] = __( 'Downgrading the plugin&#8230;' ); $this->strings['process_failed'] = __( 'Plugin downgrade failed.' ); $this->strings['process_success'] = __( 'Plugin downgraded successfully.' ); } } } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [Plugin\_Upgrader::install()](install) wp-admin/includes/class-plugin-upgrader.php | Install a plugin package. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress Plugin_Upgrader::upgrade_strings() Plugin\_Upgrader::upgrade\_strings() ==================================== Initialize the upgrade strings. File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function upgrade_strings() { $this->strings['up_to_date'] = __( 'The plugin is at the latest version.' ); $this->strings['no_package'] = __( 'Update package not available.' ); /* translators: %s: Package URL. */ $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s&#8230;' ), '<span class="code">%s</span>' ); $this->strings['unpack_package'] = __( 'Unpacking the update&#8230;' ); $this->strings['remove_old'] = __( 'Removing the old version of the plugin&#8230;' ); $this->strings['remove_old_failed'] = __( 'Could not remove the old plugin.' ); $this->strings['process_failed'] = __( 'Plugin update failed.' ); $this->strings['process_success'] = __( 'Plugin updated successfully.' ); $this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [Plugin\_Upgrader::bulk\_upgrade()](bulk_upgrade) wp-admin/includes/class-plugin-upgrader.php | Bulk upgrade several plugins at once. | | [Plugin\_Upgrader::upgrade()](upgrade) wp-admin/includes/class-plugin-upgrader.php | Upgrade a plugin. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress Plugin_Upgrader::delete_old_plugin( bool|WP_Error $removed, string $local_destination, string $remote_destination, array $plugin ): bool|WP_Error Plugin\_Upgrader::delete\_old\_plugin( bool|WP\_Error $removed, string $local\_destination, string $remote\_destination, array $plugin ): bool|WP\_Error ======================================================================================================================================================== Deletes the old plugin during an upgrade. Hooked to the [‘upgrader\_clear\_destination’](../../hooks/upgrader_clear_destination) filter by [Plugin\_Upgrader::upgrade()](upgrade) and [Plugin\_Upgrader::bulk\_upgrade()](bulk_upgrade). `$removed` bool|[WP\_Error](../wp_error) Required Whether the destination was cleared. True on success, [WP\_Error](../wp_error) on failure. `$local_destination` string Required The local package destination. `$remote_destination` string Required The remote package destination. `$plugin` array Required Extra arguments passed to hooked filters. bool|[WP\_Error](../wp_error) File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) { global $wp_filesystem; if ( is_wp_error( $removed ) ) { return $removed; // Pass errors through. } $plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : ''; if ( empty( $plugin ) ) { return new WP_Error( 'bad_request', $this->strings['bad_request'] ); } $plugins_dir = $wp_filesystem->wp_plugins_dir(); $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) ); if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { // If it's already vanished. return $removed; } // If plugin is in its own directory, recursively delete the directory. // Base check on if plugin includes directory separator AND that it's not the root plugin folder. if ( strpos( $plugin, '/' ) && $this_plugin_dir !== $plugins_dir ) { $deleted = $wp_filesystem->delete( $this_plugin_dir, true ); } else { $deleted = $wp_filesystem->delete( $plugins_dir . $plugin ); } if ( ! $deleted ) { return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] ); } return true; } ``` | Uses | Description | | --- | --- | | [trailingslashit()](../../functions/trailingslashit) wp-includes/formatting.php | Appends a trailing slash. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |
programming_docs
wordpress Plugin_Upgrader::plugin_info(): string|false Plugin\_Upgrader::plugin\_info(): string|false ============================================== Retrieve the path to the file that contains the plugin info. This isn’t used internally in the class, but is called by the skins. string|false The full path to the main plugin file, or false. File: `wp-admin/includes/class-plugin-upgrader.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-plugin-upgrader.php/) ``` public function plugin_info() { if ( ! is_array( $this->result ) ) { return false; } if ( empty( $this->result['destination_name'] ) ) { return false; } // Ensure to pass with leading slash. $plugin = get_plugins( '/' . $this->result['destination_name'] ); if ( empty( $plugin ) ) { return false; } // Assume the requested plugin is the first in the list. $pluginfiles = array_keys( $plugin ); return $this->result['destination_name'] . '/' . $pluginfiles[0]; } ``` | Uses | Description | | --- | --- | | [get\_plugins()](../../functions/get_plugins) wp-admin/includes/plugin.php | Checks the plugins directory and retrieve all plugin files with plugin data. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_REST_Post_Search_Handler::search_items( WP_REST_Request $request ): array WP\_REST\_Post\_Search\_Handler::search\_items( WP\_REST\_Request $request ): array =================================================================================== Searches the object type content for a given search request. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full REST request. array Associative array containing an `WP_REST_Search_Handler::RESULT_IDS` containing an array of found IDs and `WP_REST_Search_Handler::RESULT_TOTAL` containing the total count for the matching search results. File: `wp-includes/rest-api/search/class-wp-rest-post-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php/) ``` public function search_items( WP_REST_Request $request ) { // Get the post types to search for the current request. $post_types = $request[ WP_REST_Search_Controller::PROP_SUBTYPE ]; if ( in_array( WP_REST_Search_Controller::TYPE_ANY, $post_types, true ) ) { $post_types = $this->subtypes; } $query_args = array( 'post_type' => $post_types, 'post_status' => 'publish', 'paged' => (int) $request['page'], 'posts_per_page' => (int) $request['per_page'], 'ignore_sticky_posts' => true, ); if ( ! empty( $request['search'] ) ) { $query_args['s'] = $request['search']; } if ( ! empty( $request['exclude'] ) ) { $query_args['post__not_in'] = $request['exclude']; } if ( ! empty( $request['include'] ) ) { $query_args['post__in'] = $request['include']; } /** * Filters the query arguments for a REST API search request. * * Enables adding extra arguments or setting defaults for a post search request. * * @since 5.1.0 * * @param array $query_args Key value array of query var to query value. * @param WP_REST_Request $request The request used. */ $query_args = apply_filters( 'rest_post_search_query', $query_args, $request ); $query = new WP_Query(); $posts = $query->query( $query_args ); // Querying the whole post object will warm the object cache, avoiding an extra query per result. $found_ids = wp_list_pluck( $posts, 'ID' ); $total = $query->found_posts; return array( self::RESULT_IDS => $found_ids, self::RESULT_TOTAL => $total, ); } ``` [apply\_filters( 'rest\_post\_search\_query', array $query\_args, WP\_REST\_Request $request )](../../hooks/rest_post_search_query) Filters the query arguments for a REST API search request. | Uses | Description | | --- | --- | | [WP\_Query::\_\_construct()](../wp_query/__construct) wp-includes/class-wp-query.php | Constructor. | | [wp\_list\_pluck()](../../functions/wp_list_pluck) wp-includes/functions.php | Plucks a certain field out of each object or array in an array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Post_Search_Handler::protected_title_format(): string WP\_REST\_Post\_Search\_Handler::protected\_title\_format(): string =================================================================== Overwrites the default protected title format. By default, WordPress will show password protected posts with a title of "Protected: %s". As the REST API communicates the protected status of a post in a machine readable format, we remove the "Protected: " prefix. string Protected title format. File: `wp-includes/rest-api/search/class-wp-rest-post-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php/) ``` public function protected_title_format() { return '%s'; } ``` | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Post_Search_Handler::prepare_item( int $id, array $fields ): array WP\_REST\_Post\_Search\_Handler::prepare\_item( int $id, array $fields ): array =============================================================================== Prepares the search result for a given ID. `$id` int Required Item ID. `$fields` array Required Fields to include for the item. array Associative array containing all fields for the item. File: `wp-includes/rest-api/search/class-wp-rest-post-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php/) ``` public function prepare_item( $id, array $fields ) { $post = get_post( $id ); $data = array(); if ( in_array( WP_REST_Search_Controller::PROP_ID, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_ID ] = (int) $post->ID; } if ( in_array( WP_REST_Search_Controller::PROP_TITLE, $fields, true ) ) { if ( post_type_supports( $post->post_type, 'title' ) ) { add_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); $data[ WP_REST_Search_Controller::PROP_TITLE ] = get_the_title( $post->ID ); remove_filter( 'protected_title_format', array( $this, 'protected_title_format' ) ); } else { $data[ WP_REST_Search_Controller::PROP_TITLE ] = ''; } } if ( in_array( WP_REST_Search_Controller::PROP_URL, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_URL ] = get_permalink( $post->ID ); } if ( in_array( WP_REST_Search_Controller::PROP_TYPE, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_TYPE ] = $this->type; } if ( in_array( WP_REST_Search_Controller::PROP_SUBTYPE, $fields, true ) ) { $data[ WP_REST_Search_Controller::PROP_SUBTYPE ] = $post->post_type; } return $data; } ``` | Uses | Description | | --- | --- | | [remove\_filter()](../../functions/remove_filter) wp-includes/plugin.php | Removes a callback function from a filter hook. | | [get\_the\_title()](../../functions/get_the_title) wp-includes/post-template.php | Retrieves the post title. | | [post\_type\_supports()](../../functions/post_type_supports) wp-includes/post.php | Checks a post type’s support for a given feature. | | [get\_permalink()](../../functions/get_permalink) wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Post_Search_Handler::detect_rest_item_route( WP_Post $post ): string WP\_REST\_Post\_Search\_Handler::detect\_rest\_item\_route( WP\_Post $post ): string ==================================================================================== This method has been deprecated. Use [rest\_get\_route\_for\_post()](../../functions/rest_get_route_for_post) instead. Attempts to detect the route to access a single item. * [rest\_get\_route\_for\_post()](../../functions/rest_get_route_for_post) `$post` [WP\_Post](../wp_post) Required Post object. string REST route relative to the REST base URI, or empty string if unknown. File: `wp-includes/rest-api/search/class-wp-rest-post-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php/) ``` protected function detect_rest_item_route( $post ) { _deprecated_function( __METHOD__, '5.5.0', 'rest_get_route_for_post()' ); return rest_get_route_for_post( $post ); } ``` | Uses | Description | | --- | --- | | [rest\_get\_route\_for\_post()](../../functions/rest_get_route_for_post) wp-includes/rest-api.php | Gets the REST API route for a post. | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Use [rest\_get\_route\_for\_post()](../../functions/rest_get_route_for_post) | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Post_Search_Handler::__construct() WP\_REST\_Post\_Search\_Handler::\_\_construct() ================================================ Constructor. File: `wp-includes/rest-api/search/class-wp-rest-post-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php/) ``` public function __construct() { $this->type = 'post'; // Support all public post types except attachments. $this->subtypes = array_diff( array_values( get_post_types( array( 'public' => true, 'show_in_rest' => true, ), 'names' ) ), array( 'attachment' ) ); } ``` | Uses | Description | | --- | --- | | [get\_post\_types()](../../functions/get_post_types) wp-includes/post.php | Gets a list of all registered post type objects. | | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Post_Search_Handler::prepare_item_links( int $id ): array WP\_REST\_Post\_Search\_Handler::prepare\_item\_links( int $id ): array ======================================================================= Prepares links for the search result of a given ID. `$id` int Required Item ID. array Links for the given item. File: `wp-includes/rest-api/search/class-wp-rest-post-search-handler.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php/) ``` public function prepare_item_links( $id ) { $post = get_post( $id ); $links = array(); $item_route = rest_get_route_for_post( $post ); if ( ! empty( $item_route ) ) { $links['self'] = array( 'href' => rest_url( $item_route ), 'embeddable' => true, ); } $links['about'] = array( 'href' => rest_url( 'wp/v2/types/' . $post->post_type ), ); return $links; } ``` | Uses | Description | | --- | --- | | [rest\_get\_route\_for\_post()](../../functions/rest_get_route_for_post) wp-includes/rest-api.php | Gets the REST API route for a post. | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | Version | Description | | --- | --- | | [5.0.0](https://developer.wordpress.org/reference/since/5.0.0/) | Introduced. | wordpress WP_REST_Post_Statuses_Controller::get_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Post\_Statuses\_Controller::get\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error =========================================================================================================== Retrieves a specific post status. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` public function get_item( $request ) { $obj = get_post_status_object( $request['status'] ); if ( empty( $obj ) ) { return new WP_Error( 'rest_status_invalid', __( 'Invalid status.' ), array( 'status' => 404 ) ); } $data = $this->prepare_item_for_response( $obj, $request ); return rest_ensure_response( $data ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Post\_Statuses\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Prepares a post status object for serialization. | | [get\_post\_status\_object()](../../functions/get_post_status_object) wp-includes/post.php | Retrieves a post status object by name. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Post_Statuses_Controller::prepare_item_for_response( stdClass $item, WP_REST_Request $request ): WP_REST_Response WP\_REST\_Post\_Statuses\_Controller::prepare\_item\_for\_response( stdClass $item, WP\_REST\_Request $request ): WP\_REST\_Response ==================================================================================================================================== Prepares a post status object for serialization. `$item` stdClass Required Post status data. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response) Post status data. File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` public function prepare_item_for_response( $item, $request ) { // Restores the more descriptive, specific name for use within this method. $status = $item; $fields = $this->get_fields_for_response( $request ); $data = array(); if ( in_array( 'name', $fields, true ) ) { $data['name'] = $status->label; } if ( in_array( 'private', $fields, true ) ) { $data['private'] = (bool) $status->private; } if ( in_array( 'protected', $fields, true ) ) { $data['protected'] = (bool) $status->protected; } if ( in_array( 'public', $fields, true ) ) { $data['public'] = (bool) $status->public; } if ( in_array( 'queryable', $fields, true ) ) { $data['queryable'] = (bool) $status->publicly_queryable; } if ( in_array( 'show_in_list', $fields, true ) ) { $data['show_in_list'] = (bool) $status->show_in_admin_all_list; } if ( in_array( 'slug', $fields, true ) ) { $data['slug'] = $status->name; } if ( in_array( 'date_floating', $fields, true ) ) { $data['date_floating'] = $status->date_floating; } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); $rest_url = rest_url( rest_get_route_for_post_type_items( 'post' ) ); if ( 'publish' === $status->name ) { $response->add_link( 'archives', $rest_url ); } else { $response->add_link( 'archives', add_query_arg( 'status', $status->name, $rest_url ) ); } /** * Filters a post status returned from the REST API. * * Allows modification of the status data right before it is returned. * * @since 4.7.0 * * @param WP_REST_Response $response The response object. * @param object $status The original post status object. * @param WP_REST_Request $request Request used to generate the response. */ return apply_filters( 'rest_prepare_status', $response, $status, $request ); } ``` [apply\_filters( 'rest\_prepare\_status', WP\_REST\_Response $response, object $status, WP\_REST\_Request $request )](../../hooks/rest_prepare_status) Filters a post status returned from the REST API. | Uses | Description | | --- | --- | | [rest\_get\_route\_for\_post\_type\_items()](../../functions/rest_get_route_for_post_type_items) wp-includes/rest-api.php | Gets the REST API route for a post type. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [rest\_url()](../../functions/rest_url) wp-includes/rest-api.php | Retrieves the URL to a REST endpoint. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_REST\_Post\_Statuses\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Retrieves all post statuses, depending on user context. | | [WP\_REST\_Post\_Statuses\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Retrieves a specific post status. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$status` to `$item` to match parent class for PHP 8 named parameter support. | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Post_Statuses_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Post\_Statuses\_Controller::get\_items( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ============================================================================================================ Retrieves all post statuses, depending on user context. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` public function get_items( $request ) { $data = array(); $statuses = get_post_stati( array( 'internal' => false ), 'object' ); $statuses['trash'] = get_post_status_object( 'trash' ); foreach ( $statuses as $slug => $obj ) { $ret = $this->check_read_permission( $obj ); if ( ! $ret ) { continue; } $status = $this->prepare_item_for_response( $obj, $request ); $data[ $obj->name ] = $this->prepare_response_for_collection( $status ); } return rest_ensure_response( $data ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Post\_Statuses\_Controller::check\_read\_permission()](check_read_permission) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Checks whether a given post status should be visible. | | [WP\_REST\_Post\_Statuses\_Controller::prepare\_item\_for\_response()](prepare_item_for_response) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Prepares a post status object for serialization. | | [get\_post\_stati()](../../functions/get_post_stati) wp-includes/post.php | Gets a list of post statuses. | | [get\_post\_status\_object()](../../functions/get_post_status_object) wp-includes/post.php | Retrieves a post status object by name. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |
programming_docs
wordpress WP_REST_Post_Statuses_Controller::get_items_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Post\_Statuses\_Controller::get\_items\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ================================================================================================================== Checks whether a given request has permission to read post statuses. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` public function get_items_permissions_check( $request ) { if ( 'edit' === $request['context'] ) { $types = get_post_types( array( 'show_in_rest' => true ), 'objects' ); foreach ( $types as $type ) { if ( current_user_can( $type->cap->edit_posts ) ) { return true; } } return new WP_Error( 'rest_cannot_view', __( 'Sorry, you are not allowed to manage post statuses.' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } ``` | Uses | Description | | --- | --- | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post\_types()](../../functions/get_post_types) wp-includes/post.php | Gets a list of all registered post type objects. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Post_Statuses_Controller::register_routes() WP\_REST\_Post\_Statuses\_Controller::register\_routes() ======================================================== Registers the routes for post statuses. * [register\_rest\_route()](../../functions/register_rest_route) File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), 'permission_callback' => array( $this, 'get_items_permissions_check' ), 'args' => $this->get_collection_params(), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<status>[\w-]+)', array( 'args' => array( 'status' => array( 'description' => __( 'An alphanumeric identifier for the status.' ), 'type' => 'string', ), ), array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), 'args' => array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Post\_Statuses\_Controller::get\_collection\_params()](get_collection_params) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Retrieves the query params for collections. | | [register\_rest\_route()](../../functions/register_rest_route) wp-includes/rest-api.php | Registers a REST API route. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Post_Statuses_Controller::get_collection_params(): array WP\_REST\_Post\_Statuses\_Controller::get\_collection\_params(): array ====================================================================== Retrieves the query params for collections. array Collection parameters. File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` public function get_collection_params() { return array( 'context' => $this->get_context_param( array( 'default' => 'view' ) ), ); } ``` | Used By | Description | | --- | --- | | [WP\_REST\_Post\_Statuses\_Controller::register\_routes()](register_routes) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Registers the routes for post statuses. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Post_Statuses_Controller::check_read_permission( object $status ): bool WP\_REST\_Post\_Statuses\_Controller::check\_read\_permission( object $status ): bool ===================================================================================== Checks whether a given post status should be visible. `$status` object Required Post status. bool True if the post status is visible, otherwise false. File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` protected function check_read_permission( $status ) { if ( true === $status->public ) { return true; } if ( false === $status->internal || 'trash' === $status->name ) { $types = get_post_types( array( 'show_in_rest' => true ), 'objects' ); foreach ( $types as $type ) { if ( current_user_can( $type->cap->edit_posts ) ) { return true; } } } return false; } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [get\_post\_types()](../../functions/get_post_types) wp-includes/post.php | Gets a list of all registered post type objects. | | Used By | Description | | --- | --- | | [WP\_REST\_Post\_Statuses\_Controller::get\_items()](get_items) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Retrieves all post statuses, depending on user context. | | [WP\_REST\_Post\_Statuses\_Controller::get\_item\_permissions\_check()](get_item_permissions_check) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Checks if a given request has access to read a post status. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Post_Statuses_Controller::__construct() WP\_REST\_Post\_Statuses\_Controller::\_\_construct() ===================================================== Constructor. File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` public function __construct() { $this->namespace = 'wp/v2'; $this->rest_base = 'statuses'; } ``` | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Post_Statuses_Controller::get_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Post\_Statuses\_Controller::get\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ================================================================================================================= Checks if a given request has access to read a post status. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has read access for the item, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` public function get_item_permissions_check( $request ) { $status = get_post_status_object( $request['status'] ); if ( empty( $status ) ) { return new WP_Error( 'rest_status_invalid', __( 'Invalid status.' ), array( 'status' => 404 ) ); } $check = $this->check_read_permission( $status ); if ( ! $check ) { return new WP_Error( 'rest_cannot_read_status', __( 'Cannot view status.' ), array( 'status' => rest_authorization_required_code() ) ); } return true; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Post\_Statuses\_Controller::check\_read\_permission()](check_read_permission) wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Checks whether a given post status should be visible. | | [get\_post\_status\_object()](../../functions/get_post_status_object) wp-includes/post.php | Retrieves a post status object by name. | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Post_Statuses_Controller::get_item_schema(): array WP\_REST\_Post\_Statuses\_Controller::get\_item\_schema(): array ================================================================ Retrieves the post status’ schema, conforming to JSON Schema. array Item schema data. File: `wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'status', 'type' => 'object', 'properties' => array( 'name' => array( 'description' => __( 'The title for the status.' ), 'type' => 'string', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'private' => array( 'description' => __( 'Whether posts with this status should be private.' ), 'type' => 'boolean', 'context' => array( 'edit' ), 'readonly' => true, ), 'protected' => array( 'description' => __( 'Whether posts with this status should be protected.' ), 'type' => 'boolean', 'context' => array( 'edit' ), 'readonly' => true, ), 'public' => array( 'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'queryable' => array( 'description' => __( 'Whether posts with this status should be publicly-queryable.' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'show_in_list' => array( 'description' => __( 'Whether to include posts in the edit listing for their post type.' ), 'type' => 'boolean', 'context' => array( 'edit' ), 'readonly' => true, ), 'slug' => array( 'description' => __( 'An alphanumeric identifier for the status.' ), 'type' => 'string', 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), 'date_floating' => array( 'description' => __( 'Whether posts of this status may have floating published dates.' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, ), ), ); $this->schema = $schema; return $this->add_additional_fields_schema( $this->schema ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Style_Engine_CSS_Rules_Store::add_rule( string $selector ): WP_Style_Engine_CSS_Rule|void WP\_Style\_Engine\_CSS\_Rules\_Store::add\_rule( string $selector ): WP\_Style\_Engine\_CSS\_Rule|void ====================================================================================================== Gets a [WP\_Style\_Engine\_CSS\_Rule](../wp_style_engine_css_rule) object by its selector. If the rule does not exist, it will be created. `$selector` string Required The CSS selector. [WP\_Style\_Engine\_CSS\_Rule](../wp_style_engine_css_rule)|void Returns a [WP\_Style\_Engine\_CSS\_Rule](../wp_style_engine_css_rule) object, or null if the selector is empty. File: `wp-includes/style-engine/class-wp-style-engine-css-rules-store.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php/) ``` public function add_rule( $selector ) { $selector = trim( $selector ); // Bail early if there is no selector. if ( empty( $selector ) ) { return; } // Create the rule if it doesn't exist. if ( empty( $this->rules[ $selector ] ) ) { $this->rules[ $selector ] = new WP_Style_Engine_CSS_Rule( $selector ); } return $this->rules[ $selector ]; } ``` | Uses | Description | | --- | --- | | [WP\_Style\_Engine\_CSS\_Rule::\_\_construct()](../wp_style_engine_css_rule/__construct) wp-includes/style-engine/class-wp-style-engine-css-rule.php | Constructor | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Style_Engine_CSS_Rules_Store::get_all_rules(): WP_Style_Engine_CSS_Rule[] WP\_Style\_Engine\_CSS\_Rules\_Store::get\_all\_rules(): WP\_Style\_Engine\_CSS\_Rule[] ======================================================================================= Gets an array of all rules. [WP\_Style\_Engine\_CSS\_Rule](../wp_style_engine_css_rule)[] File: `wp-includes/style-engine/class-wp-style-engine-css-rules-store.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php/) ``` public function get_all_rules() { return $this->rules; } ``` | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Style_Engine_CSS_Rules_Store::get_name(): string WP\_Style\_Engine\_CSS\_Rules\_Store::get\_name(): string ========================================================= Gets the store name. string File: `wp-includes/style-engine/class-wp-style-engine-css-rules-store.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php/) ``` public function get_name() { return $this->name; } ``` | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Style_Engine_CSS_Rules_Store::remove_rule( string $selector ): void WP\_Style\_Engine\_CSS\_Rules\_Store::remove\_rule( string $selector ): void ============================================================================ Removes a selector from the store. `$selector` string Required The CSS selector. void File: `wp-includes/style-engine/class-wp-style-engine-css-rules-store.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php/) ``` public function remove_rule( $selector ) { unset( $this->rules[ $selector ] ); } ``` | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Style_Engine_CSS_Rules_Store::get_store( string $store_name = 'default' ): WP_Style_Engine_CSS_Rules_Store|void WP\_Style\_Engine\_CSS\_Rules\_Store::get\_store( string $store\_name = 'default' ): WP\_Style\_Engine\_CSS\_Rules\_Store|void ============================================================================================================================== Gets an instance of the store. `$store_name` string Optional The name of the store. Default: `'default'` [WP\_Style\_Engine\_CSS\_Rules\_Store](../wp_style_engine_css_rules_store)|void File: `wp-includes/style-engine/class-wp-style-engine-css-rules-store.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php/) ``` public static function get_store( $store_name = 'default' ) { if ( ! is_string( $store_name ) || empty( $store_name ) ) { return; } if ( ! isset( static::$stores[ $store_name ] ) ) { static::$stores[ $store_name ] = new static(); // Set the store name. static::$stores[ $store_name ]->set_name( $store_name ); } return static::$stores[ $store_name ]; } ``` | Used By | Description | | --- | --- | | [WP\_Style\_Engine::get\_store()](../wp_style_engine/get_store) wp-includes/style-engine/class-wp-style-engine.php | Returns a store by store key. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Style_Engine_CSS_Rules_Store::set_name( string $name ): void WP\_Style\_Engine\_CSS\_Rules\_Store::set\_name( string $name ): void ===================================================================== Sets the store name. `$name` string Required The store name. void File: `wp-includes/style-engine/class-wp-style-engine-css-rules-store.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php/) ``` public function set_name( $name ) { $this->name = $name; } ``` | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Style_Engine_CSS_Rules_Store::remove_all_stores(): void WP\_Style\_Engine\_CSS\_Rules\_Store::remove\_all\_stores(): void ================================================================= Clears all stores from static::$stores. void File: `wp-includes/style-engine/class-wp-style-engine-css-rules-store.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php/) ``` public static function remove_all_stores() { static::$stores = array(); } ``` | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. |
programming_docs
wordpress WP_Style_Engine_CSS_Rules_Store::get_stores(): WP_Style_Engine_CSS_Rules_Store[] WP\_Style\_Engine\_CSS\_Rules\_Store::get\_stores(): WP\_Style\_Engine\_CSS\_Rules\_Store[] =========================================================================================== Gets an array of all available stores. [WP\_Style\_Engine\_CSS\_Rules\_Store](../wp_style_engine_css_rules_store)[] File: `wp-includes/style-engine/class-wp-style-engine-css-rules-store.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/style-engine/class-wp-style-engine-css-rules-store.php/) ``` public static function get_stores() { return static::$stores; } ``` | Used By | Description | | --- | --- | | [wp\_enqueue\_stored\_styles()](../../functions/wp_enqueue_stored_styles) wp-includes/script-loader.php | Fetches, processes and compiles stored core styles, then combines and renders them to the page. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Post_Type::register_meta_boxes() WP\_Post\_Type::register\_meta\_boxes() ======================================= Registers the post type meta box if a custom callback was specified. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function register_meta_boxes() { if ( $this->register_meta_box_cb ) { add_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10, 1 ); } } ``` | Uses | Description | | --- | --- | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::register_taxonomies() WP\_Post\_Type::register\_taxonomies() ====================================== Registers the taxonomies for the post type. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function register_taxonomies() { foreach ( $this->taxonomies as $taxonomy ) { register_taxonomy_for_object_type( $taxonomy, $this->name ); } } ``` | Uses | Description | | --- | --- | | [register\_taxonomy\_for\_object\_type()](../../functions/register_taxonomy_for_object_type) wp-includes/taxonomy.php | Adds an already registered taxonomy to an object type. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::reset_default_labels() WP\_Post\_Type::reset\_default\_labels() ======================================== Resets the cache for the default labels. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public static function reset_default_labels() { self::$default_labels = array(); } ``` | Used By | Description | | --- | --- | | [create\_initial\_post\_types()](../../functions/create_initial_post_types) wp-includes/post.php | Creates the initial post types when ‘init’ action is fired. | | Version | Description | | --- | --- | | [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Introduced. | wordpress WP_Post_Type::get_rest_controller(): WP_REST_Controller|null WP\_Post\_Type::get\_rest\_controller(): WP\_REST\_Controller|null ================================================================== Gets the REST API controller for this post type. Will only instantiate the controller class once per request. [WP\_REST\_Controller](../wp_rest_controller)|null The controller instance, or null if the post type is set not to show in rest. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function get_rest_controller() { if ( ! $this->show_in_rest ) { return null; } $class = $this->rest_controller_class ? $this->rest_controller_class : WP_REST_Posts_Controller::class; if ( ! class_exists( $class ) ) { return null; } if ( ! is_subclass_of( $class, WP_REST_Controller::class ) ) { return null; } if ( ! $this->rest_controller ) { $this->rest_controller = new $class( $this->name ); } if ( ! ( $this->rest_controller instanceof $class ) ) { return null; } return $this->rest_controller; } ``` | Version | Description | | --- | --- | | [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Introduced. | wordpress WP_Post_Type::get_default_labels(): (string|null)[][] WP\_Post\_Type::get\_default\_labels(): (string|null)[][] ========================================================= Returns the default labels for post types. (string|null)[][] The default labels for post types. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public static function get_default_labels() { if ( ! empty( self::$default_labels ) ) { return self::$default_labels; } self::$default_labels = array( 'name' => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ), 'singular_name' => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ), 'add_new' => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ), 'add_new_item' => array( __( 'Add New Post' ), __( 'Add New Page' ) ), 'edit_item' => array( __( 'Edit Post' ), __( 'Edit Page' ) ), 'new_item' => array( __( 'New Post' ), __( 'New Page' ) ), 'view_item' => array( __( 'View Post' ), __( 'View Page' ) ), 'view_items' => array( __( 'View Posts' ), __( 'View Pages' ) ), 'search_items' => array( __( 'Search Posts' ), __( 'Search Pages' ) ), 'not_found' => array( __( 'No posts found.' ), __( 'No pages found.' ) ), 'not_found_in_trash' => array( __( 'No posts found in Trash.' ), __( 'No pages found in Trash.' ) ), 'parent_item_colon' => array( null, __( 'Parent Page:' ) ), 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ), 'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ), 'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ), 'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ), 'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ), 'featured_image' => array( _x( 'Featured image', 'post' ), _x( 'Featured image', 'page' ) ), 'set_featured_image' => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ), 'remove_featured_image' => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ), 'use_featured_image' => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ), 'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ), 'filter_by_date' => array( __( 'Filter by date' ), __( 'Filter by date' ) ), 'items_list_navigation' => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ), 'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ), 'item_published' => array( __( 'Post published.' ), __( 'Page published.' ) ), 'item_published_privately' => array( __( 'Post published privately.' ), __( 'Page published privately.' ) ), 'item_reverted_to_draft' => array( __( 'Post reverted to draft.' ), __( 'Page reverted to draft.' ) ), 'item_scheduled' => array( __( 'Post scheduled.' ), __( 'Page scheduled.' ) ), 'item_updated' => array( __( 'Post updated.' ), __( 'Page updated.' ) ), 'item_link' => array( _x( 'Post Link', 'navigation link block title' ), _x( 'Page Link', 'navigation link block title' ), ), 'item_link_description' => array( _x( 'A link to a post.', 'navigation link block description' ), _x( 'A link to a page.', 'navigation link block description' ), ), ); return self::$default_labels; } ``` | Uses | Description | | --- | --- | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [get\_post\_type\_labels()](../../functions/get_post_type_labels) wp-includes/post.php | Builds an object with all post type labels out of a post type object. | | Version | Description | | --- | --- | | [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Introduced. | wordpress WP_Post_Type::add_hooks() WP\_Post\_Type::add\_hooks() ============================ Adds the future post hook action for the post type. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function add_hooks() { add_action( 'future_' . $this->name, '_future_post_hook', 5, 2 ); } ``` | Uses | Description | | --- | --- | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::add_rewrite_rules() WP\_Post\_Type::add\_rewrite\_rules() ===================================== Adds the necessary rewrite rules for the post type. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function add_rewrite_rules() { global $wp_rewrite, $wp; if ( false !== $this->query_var && $wp && is_post_type_viewable( $this ) ) { $wp->add_query_var( $this->query_var ); } if ( false !== $this->rewrite && ( is_admin() || get_option( 'permalink_structure' ) ) ) { if ( $this->hierarchical ) { add_rewrite_tag( "%$this->name%", '(.+?)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&pagename=" ); } else { add_rewrite_tag( "%$this->name%", '([^/]+)', $this->query_var ? "{$this->query_var}=" : "post_type=$this->name&name=" ); } if ( $this->has_archive ) { $archive_slug = true === $this->has_archive ? $this->rewrite['slug'] : $this->has_archive; if ( $this->rewrite['with_front'] ) { $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug; } else { $archive_slug = $wp_rewrite->root . $archive_slug; } add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$this->name", 'top' ); if ( $this->rewrite['feeds'] && $wp_rewrite->feeds ) { $feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')'; add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' ); add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$this->name" . '&feed=$matches[1]', 'top' ); } if ( $this->rewrite['pages'] ) { add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$this->name" . '&paged=$matches[1]', 'top' ); } } $permastruct_args = $this->rewrite; $permastruct_args['feed'] = $permastruct_args['feeds']; add_permastruct( $this->name, "{$this->rewrite['slug']}/%$this->name%", $permastruct_args ); } } ``` | Uses | Description | | --- | --- | | [is\_post\_type\_viewable()](../../functions/is_post_type_viewable) wp-includes/post.php | Determines whether a post type is considered “viewable”. | | [WP::add\_query\_var()](../wp/add_query_var) wp-includes/class-wp.php | Adds a query variable to the list of public query variables. | | [add\_rewrite\_tag()](../../functions/add_rewrite_tag) wp-includes/rewrite.php | Adds a new rewrite tag (like %postname%). | | [add\_rewrite\_rule()](../../functions/add_rewrite_rule) wp-includes/rewrite.php | Adds a rewrite rule that transforms a URL structure to a set of query vars. | | [add\_permastruct()](../../functions/add_permastruct) wp-includes/rewrite.php | Adds a permalink structure. | | [is\_admin()](../../functions/is_admin) wp-includes/load.php | Determines whether the current request is for an administrative interface page. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::remove_hooks() WP\_Post\_Type::remove\_hooks() =============================== Removes the future post hook action for the post type. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function remove_hooks() { remove_action( 'future_' . $this->name, '_future_post_hook', 5 ); } ``` | Uses | Description | | --- | --- | | [remove\_action()](../../functions/remove_action) wp-includes/plugin.php | Removes a callback function from an action hook. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::remove_supports() WP\_Post\_Type::remove\_supports() ================================== Removes the features support for the post type. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function remove_supports() { global $_wp_post_type_features; unset( $_wp_post_type_features[ $this->name ] ); } ``` | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::add_supports() WP\_Post\_Type::add\_supports() =============================== Sets the features support for the post type. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function add_supports() { if ( ! empty( $this->supports ) ) { foreach ( $this->supports as $feature => $args ) { if ( is_array( $args ) ) { add_post_type_support( $this->name, $feature, $args ); } else { add_post_type_support( $this->name, $args ); } } unset( $this->supports ); } elseif ( false !== $this->supports ) { // Add default features. add_post_type_support( $this->name, array( 'title', 'editor' ) ); } } ``` | Uses | Description | | --- | --- | | [add\_post\_type\_support()](../../functions/add_post_type_support) wp-includes/post.php | Registers support of certain features for a post type. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::__construct( string $post_type, array|string $args = array() ) WP\_Post\_Type::\_\_construct( string $post\_type, array|string $args = array() ) ================================================================================= Constructor. See the [register\_post\_type()](../../functions/register_post_type) function for accepted arguments for `$args`. Will populate object properties from the provided arguments and assign other default properties based on that information. * [register\_post\_type()](../../functions/register_post_type) `$post_type` string Required Post type key. `$args` array|string Optional Array or string of arguments for registering a post type. Default: `array()` File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function __construct( $post_type, $args = array() ) { $this->name = $post_type; $this->set_props( $args ); } ``` | Uses | Description | | --- | --- | | [WP\_Post\_Type::set\_props()](set_props) wp-includes/class-wp-post-type.php | Sets post type properties. | | Used By | Description | | --- | --- | | [register\_post\_type()](../../functions/register_post_type) wp-includes/post.php | Registers a post type. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::set_props( array|string $args ) WP\_Post\_Type::set\_props( array|string $args ) ================================================ Sets post type properties. See the [register\_post\_type()](../../functions/register_post_type) function for accepted arguments for `$args`. `$args` array|string Required Array or string of arguments for registering a post type. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function set_props( $args ) { $args = wp_parse_args( $args ); /** * Filters the arguments for registering a post type. * * @since 4.4.0 * * @param array $args Array of arguments for registering a post type. * See the register_post_type() function for accepted arguments. * @param string $post_type Post type key. */ $args = apply_filters( 'register_post_type_args', $args, $this->name ); $post_type = $this->name; /** * Filters the arguments for registering a specific post type. * * The dynamic portion of the filter name, `$post_type`, refers to the post type key. * * Possible hook names include: * * - `register_post_post_type_args` * - `register_page_post_type_args` * * @since 6.0.0 * * @param array $args Array of arguments for registering a post type. * See the register_post_type() function for accepted arguments. * @param string $post_type Post type key. */ $args = apply_filters( "register_{$post_type}_post_type_args", $args, $this->name ); $has_edit_link = ! empty( $args['_edit_link'] ); // Args prefixed with an underscore are reserved for internal use. $defaults = array( 'labels' => array(), 'description' => '', 'public' => false, 'hierarchical' => false, 'exclude_from_search' => null, 'publicly_queryable' => null, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_in_admin_bar' => null, 'menu_position' => null, 'menu_icon' => null, 'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null, 'supports' => array(), 'register_meta_box_cb' => null, 'taxonomies' => array(), 'has_archive' => false, 'rewrite' => true, 'query_var' => true, 'can_export' => true, 'delete_with_user' => null, 'show_in_rest' => false, 'rest_base' => false, 'rest_namespace' => false, 'rest_controller_class' => false, 'template' => array(), 'template_lock' => false, '_builtin' => false, '_edit_link' => 'post.php?post=%d', ); $args = array_merge( $defaults, $args ); $args['name'] = $this->name; // If not set, default to the setting for 'public'. if ( null === $args['publicly_queryable'] ) { $args['publicly_queryable'] = $args['public']; } // If not set, default to the setting for 'public'. if ( null === $args['show_ui'] ) { $args['show_ui'] = $args['public']; } // If not set, default rest_namespace to wp/v2 if show_in_rest is true. if ( false === $args['rest_namespace'] && ! empty( $args['show_in_rest'] ) ) { $args['rest_namespace'] = 'wp/v2'; } // If not set, default to the setting for 'show_ui'. if ( null === $args['show_in_menu'] || ! $args['show_ui'] ) { $args['show_in_menu'] = $args['show_ui']; } // If not set, default to the setting for 'show_in_menu'. if ( null === $args['show_in_admin_bar'] ) { $args['show_in_admin_bar'] = (bool) $args['show_in_menu']; } // If not set, default to the setting for 'public'. if ( null === $args['show_in_nav_menus'] ) { $args['show_in_nav_menus'] = $args['public']; } // If not set, default to true if not public, false if public. if ( null === $args['exclude_from_search'] ) { $args['exclude_from_search'] = ! $args['public']; } // Back compat with quirky handling in version 3.0. #14122. if ( empty( $args['capabilities'] ) && null === $args['map_meta_cap'] && in_array( $args['capability_type'], array( 'post', 'page' ), true ) ) { $args['map_meta_cap'] = true; } // If not set, default to false. if ( null === $args['map_meta_cap'] ) { $args['map_meta_cap'] = false; } // If there's no specified edit link and no UI, remove the edit link. if ( ! $args['show_ui'] && ! $has_edit_link ) { $args['_edit_link'] = ''; } $this->cap = get_post_type_capabilities( (object) $args ); unset( $args['capabilities'] ); if ( is_array( $args['capability_type'] ) ) { $args['capability_type'] = $args['capability_type'][0]; } if ( false !== $args['query_var'] ) { if ( true === $args['query_var'] ) { $args['query_var'] = $this->name; } else { $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] ); } } if ( false !== $args['rewrite'] && ( is_admin() || get_option( 'permalink_structure' ) ) ) { if ( ! is_array( $args['rewrite'] ) ) { $args['rewrite'] = array(); } if ( empty( $args['rewrite']['slug'] ) ) { $args['rewrite']['slug'] = $this->name; } if ( ! isset( $args['rewrite']['with_front'] ) ) { $args['rewrite']['with_front'] = true; } if ( ! isset( $args['rewrite']['pages'] ) ) { $args['rewrite']['pages'] = true; } if ( ! isset( $args['rewrite']['feeds'] ) || ! $args['has_archive'] ) { $args['rewrite']['feeds'] = (bool) $args['has_archive']; } if ( ! isset( $args['rewrite']['ep_mask'] ) ) { if ( isset( $args['permalink_epmask'] ) ) { $args['rewrite']['ep_mask'] = $args['permalink_epmask']; } else { $args['rewrite']['ep_mask'] = EP_PERMALINK; } } } foreach ( $args as $property_name => $property_value ) { $this->$property_name = $property_value; } $this->labels = get_post_type_labels( $this ); $this->label = $this->labels->name; } ``` [apply\_filters( 'register\_post\_type\_args', array $args, string $post\_type )](../../hooks/register_post_type_args) Filters the arguments for registering a post type. [apply\_filters( "register\_{$post\_type}\_post\_type\_args", array $args, string $post\_type )](../../hooks/register_post_type_post_type_args) Filters the arguments for registering a specific post type. | Uses | Description | | --- | --- | | [sanitize\_title\_with\_dashes()](../../functions/sanitize_title_with_dashes) wp-includes/formatting.php | Sanitizes a title, replacing whitespace and a few other characters with dashes. | | [get\_post\_type\_capabilities()](../../functions/get_post_type_capabilities) wp-includes/post.php | Builds an object with all post type capabilities out of a post type object | | [get\_post\_type\_labels()](../../functions/get_post_type_labels) wp-includes/post.php | Builds an object with all post type labels out of a post type object. | | [is\_admin()](../../functions/is_admin) wp-includes/load.php | Determines whether the current request is for an administrative interface page. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Used By | Description | | --- | --- | | [WP\_Post\_Type::\_\_construct()](__construct) wp-includes/class-wp-post-type.php | Constructor. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. |
programming_docs
wordpress WP_Post_Type::unregister_meta_boxes() WP\_Post\_Type::unregister\_meta\_boxes() ========================================= Unregisters the post type meta box if a custom callback was specified. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function unregister_meta_boxes() { if ( $this->register_meta_box_cb ) { remove_action( 'add_meta_boxes_' . $this->name, $this->register_meta_box_cb, 10 ); } } ``` | Uses | Description | | --- | --- | | [remove\_action()](../../functions/remove_action) wp-includes/plugin.php | Removes a callback function from an action hook. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::remove_rewrite_rules() WP\_Post\_Type::remove\_rewrite\_rules() ======================================== Removes any rewrite rules, permastructs, and rules for the post type. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function remove_rewrite_rules() { global $wp, $wp_rewrite, $post_type_meta_caps; // Remove query var. if ( false !== $this->query_var ) { $wp->remove_query_var( $this->query_var ); } // Remove any rewrite rules, permastructs, and rules. if ( false !== $this->rewrite ) { remove_rewrite_tag( "%$this->name%" ); remove_permastruct( $this->name ); foreach ( $wp_rewrite->extra_rules_top as $regex => $query ) { if ( false !== strpos( $query, "index.php?post_type=$this->name" ) ) { unset( $wp_rewrite->extra_rules_top[ $regex ] ); } } } // Remove registered custom meta capabilities. foreach ( $this->cap as $cap ) { unset( $post_type_meta_caps[ $cap ] ); } } ``` | Uses | Description | | --- | --- | | [WP::remove\_query\_var()](../wp/remove_query_var) wp-includes/class-wp.php | Removes a query variable from a list of public query variables. | | [remove\_rewrite\_tag()](../../functions/remove_rewrite_tag) wp-includes/rewrite.php | Removes an existing rewrite tag (like %postname%). | | [remove\_permastruct()](../../functions/remove_permastruct) wp-includes/rewrite.php | Removes a permalink structure. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Post_Type::unregister_taxonomies() WP\_Post\_Type::unregister\_taxonomies() ======================================== Removes the post type from all taxonomies. File: `wp-includes/class-wp-post-type.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-post-type.php/) ``` public function unregister_taxonomies() { foreach ( get_object_taxonomies( $this->name ) as $taxonomy ) { unregister_taxonomy_for_object_type( $taxonomy, $this->name ); } } ``` | Uses | Description | | --- | --- | | [get\_object\_taxonomies()](../../functions/get_object_taxonomies) wp-includes/taxonomy.php | Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name. | | [unregister\_taxonomy\_for\_object\_type()](../../functions/unregister_taxonomy_for_object_type) wp-includes/taxonomy.php | Removes an already registered taxonomy from an object type. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_REST_Settings_Controller::get_item( WP_REST_Request $request ): array|WP_Error WP\_REST\_Settings\_Controller::get\_item( WP\_REST\_Request $request ): array|WP\_Error ======================================================================================== Retrieves the settings. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. array|[WP\_Error](../wp_error) Array on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` public function get_item( $request ) { $options = $this->get_registered_options(); $response = array(); foreach ( $options as $name => $args ) { /** * Filters the value of a setting recognized by the REST API. * * Allow hijacking the setting value and overriding the built-in behavior by returning a * non-null value. The returned value will be presented as the setting value instead. * * @since 4.7.0 * * @param mixed $result Value to use for the requested setting. Can be a scalar * matching the registered schema for the setting, or null to * follow the default get_option() behavior. * @param string $name Setting name (as shown in REST API responses). * @param array $args Arguments passed to register_setting() for this setting. */ $response[ $name ] = apply_filters( 'rest_pre_get_setting', null, $name, $args ); if ( is_null( $response[ $name ] ) ) { // Default to a null value as "null" in the response means "not set". $response[ $name ] = get_option( $args['option_name'], $args['schema']['default'] ); } /* * Because get_option() is lossy, we have to * cast values to the type they are registered with. */ $response[ $name ] = $this->prepare_value( $response[ $name ], $args['schema'] ); } return $response; } ``` [apply\_filters( 'rest\_pre\_get\_setting', mixed $result, string $name, array $args )](../../hooks/rest_pre_get_setting) Filters the value of a setting recognized by the REST API. | Uses | Description | | --- | --- | | [WP\_REST\_Settings\_Controller::get\_registered\_options()](get_registered_options) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Retrieves all of the registered options for the Settings API. | | [WP\_REST\_Settings\_Controller::prepare\_value()](prepare_value) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Prepares a value for output based off a schema array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Used By | Description | | --- | --- | | [WP\_REST\_Settings\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Updates settings for the settings object. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Settings_Controller::get_registered_options(): array WP\_REST\_Settings\_Controller::get\_registered\_options(): array ================================================================= Retrieves all of the registered options for the Settings API. array Array of registered options. File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` protected function get_registered_options() { $rest_options = array(); foreach ( get_registered_settings() as $name => $args ) { if ( empty( $args['show_in_rest'] ) ) { continue; } $rest_args = array(); if ( is_array( $args['show_in_rest'] ) ) { $rest_args = $args['show_in_rest']; } $defaults = array( 'name' => ! empty( $rest_args['name'] ) ? $rest_args['name'] : $name, 'schema' => array(), ); $rest_args = array_merge( $defaults, $rest_args ); $default_schema = array( 'type' => empty( $args['type'] ) ? null : $args['type'], 'description' => empty( $args['description'] ) ? '' : $args['description'], 'default' => isset( $args['default'] ) ? $args['default'] : null, ); $rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] ); $rest_args['option_name'] = $name; // Skip over settings that don't have a defined type in the schema. if ( empty( $rest_args['schema']['type'] ) ) { continue; } /* * Allow the supported types for settings, as we don't want invalid types * to be updated with arbitrary values that we can't do decent sanitizing for. */ if ( ! in_array( $rest_args['schema']['type'], array( 'number', 'integer', 'string', 'boolean', 'array', 'object' ), true ) ) { continue; } $rest_args['schema'] = rest_default_additional_properties_to_false( $rest_args['schema'] ); $rest_options[ $rest_args['name'] ] = $rest_args; } return $rest_options; } ``` | Uses | Description | | --- | --- | | [rest\_default\_additional\_properties\_to\_false()](../../functions/rest_default_additional_properties_to_false) wp-includes/rest-api.php | Sets the “additionalProperties” to false by default for all object definitions in the schema. | | [get\_registered\_settings()](../../functions/get_registered_settings) wp-includes/option.php | Retrieves an array of registered settings. | | Used By | Description | | --- | --- | | [WP\_REST\_Settings\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Retrieves the site setting schema, conforming to JSON Schema. | | [WP\_REST\_Settings\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Retrieves the settings. | | [WP\_REST\_Settings\_Controller::update\_item()](update_item) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Updates settings for the settings object. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Settings_Controller::sanitize_callback( mixed $value, WP_REST_Request $request, string $param ): mixed|WP_Error WP\_REST\_Settings\_Controller::sanitize\_callback( mixed $value, WP\_REST\_Request $request, string $param ): mixed|WP\_Error ============================================================================================================================== Custom sanitize callback used for all options to allow the use of ‘null’. By default, the schema of settings will throw an error if a value is set to `null` as it’s not a valid value for something like "type => string". We provide a wrapper sanitizer to allow the use of `null`. `$value` mixed Required The value for the setting. `$request` [WP\_REST\_Request](../wp_rest_request) Required The request object. `$param` string Required The parameter name. mixed|[WP\_Error](../wp_error) File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` public function sanitize_callback( $value, $request, $param ) { if ( is_null( $value ) ) { return $value; } return rest_parse_request_arg( $value, $request, $param ); } ``` | Uses | Description | | --- | --- | | [rest\_parse\_request\_arg()](../../functions/rest_parse_request_arg) wp-includes/rest-api.php | Parse a request argument based on details registered to the route. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Settings_Controller::update_item( WP_REST_Request $request ): array|WP_Error WP\_REST\_Settings\_Controller::update\_item( WP\_REST\_Request $request ): array|WP\_Error =========================================================================================== Updates settings for the settings object. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. array|[WP\_Error](../wp_error) Array on success, or error object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` public function update_item( $request ) { $options = $this->get_registered_options(); $params = $request->get_params(); foreach ( $options as $name => $args ) { if ( ! array_key_exists( $name, $params ) ) { continue; } /** * Filters whether to preempt a setting value update via the REST API. * * Allows hijacking the setting update logic and overriding the built-in behavior by * returning true. * * @since 4.7.0 * * @param bool $result Whether to override the default behavior for updating the * value of a setting. * @param string $name Setting name (as shown in REST API responses). * @param mixed $value Updated setting value. * @param array $args Arguments passed to register_setting() for this setting. */ $updated = apply_filters( 'rest_pre_update_setting', false, $name, $request[ $name ], $args ); if ( $updated ) { continue; } /* * A null value for an option would have the same effect as * deleting the option from the database, and relying on the * default value. */ if ( is_null( $request[ $name ] ) ) { /* * A null value is returned in the response for any option * that has a non-scalar value. * * To protect clients from accidentally including the null * values from a response object in a request, we do not allow * options with values that don't pass validation to be updated to null. * Without this added protection a client could mistakenly * delete all options that have invalid values from the * database. */ if ( is_wp_error( rest_validate_value_from_schema( get_option( $args['option_name'], false ), $args['schema'] ) ) ) { return new WP_Error( 'rest_invalid_stored_value', /* translators: %s: Property name. */ sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) ); } delete_option( $args['option_name'] ); } else { update_option( $args['option_name'], $request[ $name ] ); } } return $this->get_item( $request ); } ``` [apply\_filters( 'rest\_pre\_update\_setting', bool $result, string $name, mixed $value, array $args )](../../hooks/rest_pre_update_setting) Filters whether to preempt a setting value update via the REST API. | Uses | Description | | --- | --- | | [rest\_validate\_value\_from\_schema()](../../functions/rest_validate_value_from_schema) wp-includes/rest-api.php | Validate a value based on a schema. | | [WP\_REST\_Settings\_Controller::get\_registered\_options()](get_registered_options) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Retrieves all of the registered options for the Settings API. | | [WP\_REST\_Settings\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Retrieves the settings. | | [delete\_option()](../../functions/delete_option) wp-includes/option.php | Removes option by name. Prevents removal of protected WordPress options. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [update\_option()](../../functions/update_option) wp-includes/option.php | Updates the value of an option that was already added. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Settings_Controller::set_additional_properties_to_false( array $schema ): array WP\_REST\_Settings\_Controller::set\_additional\_properties\_to\_false( array $schema ): array ============================================================================================== This method has been deprecated. Use [rest\_default\_additional\_properties\_to\_false()](../../functions/rest_default_additional_properties_to_false) instead. Recursively add additionalProperties = false to all objects in a schema if no additionalProperties setting is specified. This is needed to restrict properties of objects in settings values to only registered items, as the REST API will allow additional properties by default. `$schema` array Required The schema array. array File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` protected function set_additional_properties_to_false( $schema ) { _deprecated_function( __METHOD__, '6.1.0', 'rest_default_additional_properties_to_false()' ); return rest_default_additional_properties_to_false( $schema ); } ``` | Uses | Description | | --- | --- | | [rest\_default\_additional\_properties\_to\_false()](../../functions/rest_default_additional_properties_to_false) wp-includes/rest-api.php | Sets the “additionalProperties” to false by default for all object definitions in the schema. | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Use [rest\_default\_additional\_properties\_to\_false()](../../functions/rest_default_additional_properties_to_false) instead. | | [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced. | wordpress WP_REST_Settings_Controller::prepare_value( mixed $value, array $schema ): mixed WP\_REST\_Settings\_Controller::prepare\_value( mixed $value, array $schema ): mixed ==================================================================================== Prepares a value for output based off a schema array. `$value` mixed Required Value to prepare. `$schema` array Required Schema to match. mixed The prepared value. File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` protected function prepare_value( $value, $schema ) { /* * If the value is not valid by the schema, set the value to null. * Null values are specifically non-destructive, so this will not cause * overwriting the current invalid value to null. */ if ( is_wp_error( rest_validate_value_from_schema( $value, $schema ) ) ) { return null; } return rest_sanitize_value_from_schema( $value, $schema ); } ``` | Uses | Description | | --- | --- | | [rest\_sanitize\_value\_from\_schema()](../../functions/rest_sanitize_value_from_schema) wp-includes/rest-api.php | Sanitize a value based on a schema. | | [rest\_validate\_value\_from\_schema()](../../functions/rest_validate_value_from_schema) wp-includes/rest-api.php | Validate a value based on a schema. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [WP\_REST\_Settings\_Controller::get\_item()](get_item) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Retrieves the settings. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |
programming_docs
wordpress WP_REST_Settings_Controller::register_routes() WP\_REST\_Settings\_Controller::register\_routes() ================================================== Registers the routes for the site’s settings. * [register\_rest\_route()](../../functions/register_rest_route) File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'args' => array(), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_item' ), 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); } ``` | Uses | Description | | --- | --- | | [register\_rest\_route()](../../functions/register_rest_route) wp-includes/rest-api.php | Registers a REST API route. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Settings_Controller::__construct() WP\_REST\_Settings\_Controller::\_\_construct() =============================================== Constructor. File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` public function __construct() { $this->namespace = 'wp/v2'; $this->rest_base = 'settings'; } ``` | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Settings_Controller::get_item_permissions_check( WP_REST_Request $request ): bool WP\_REST\_Settings\_Controller::get\_item\_permissions\_check( WP\_REST\_Request $request ): bool ================================================================================================= Checks if a given request has access to read and manage settings. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. bool True if the request has read access for the item, otherwise false. File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` public function get_item_permissions_check( $request ) { return current_user_can( 'manage_options' ); } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Settings_Controller::get_item_schema(): array WP\_REST\_Settings\_Controller::get\_item\_schema(): array ========================================================== Retrieves the site setting schema, conforming to JSON Schema. array Item schema data. File: `wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $options = $this->get_registered_options(); $schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'settings', 'type' => 'object', 'properties' => array(), ); foreach ( $options as $option_name => $option ) { $schema['properties'][ $option_name ] = $option['schema']; $schema['properties'][ $option_name ]['arg_options'] = array( 'sanitize_callback' => array( $this, 'sanitize_callback' ), ); } $this->schema = $schema; return $this->add_additional_fields_schema( $this->schema ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Settings\_Controller::get\_registered\_options()](get_registered_options) wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php | Retrieves all of the registered options for the Settings API. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress Walker_Nav_Menu_Edit::start_lvl( string $output, int $depth, stdClass $args = null ) Walker\_Nav\_Menu\_Edit::start\_lvl( string $output, int $depth, stdClass $args = null ) ======================================================================================== Starts the list before the elements are added. * [Walker\_Nav\_Menu::start\_lvl()](../walker_nav_menu/start_lvl) `$output` string Required Passed by reference. `$depth` int Required Depth of menu item. Used for padding. `$args` stdClass Optional Not used. Default: `null` File: `wp-admin/includes/class-walker-nav-menu-edit.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-walker-nav-menu-edit.php/) ``` public function start_lvl( &$output, $depth = 0, $args = null ) {} ``` | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress Walker_Nav_Menu_Edit::start_el( string $output, WP_Post $data_object, int $depth, stdClass $args = null, int $current_object_id ) Walker\_Nav\_Menu\_Edit::start\_el( string $output, WP\_Post $data\_object, int $depth, stdClass $args = null, int $current\_object\_id ) ========================================================================================================================================= Start the element output. * [Walker\_Nav\_Menu::start\_el()](../walker_nav_menu/start_el) `$output` string Required Used to append additional content (passed by reference). `$data_object` [WP\_Post](../wp_post) Required Menu item data object. `$depth` int Required Depth of menu item. Used for padding. `$args` stdClass Optional Not used. Default: `null` `$current_object_id` int Optional ID of the current menu item. Default 0. File: `wp-admin/includes/class-walker-nav-menu-edit.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-walker-nav-menu-edit.php/) ``` public function start_el( &$output, $data_object, $depth = 0, $args = null, $current_object_id = 0 ) { global $_wp_nav_menu_max_depth; // Restores the more descriptive, specific name for use within this method. $menu_item = $data_object; $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; ob_start(); $item_id = esc_attr( $menu_item->ID ); $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce', ); $original_title = false; if ( 'taxonomy' === $menu_item->type ) { $original_object = get_term( (int) $menu_item->object_id, $menu_item->object ); if ( $original_object && ! is_wp_error( $original_object ) ) { $original_title = $original_object->name; } } elseif ( 'post_type' === $menu_item->type ) { $original_object = get_post( $menu_item->object_id ); if ( $original_object ) { $original_title = get_the_title( $original_object->ID ); } } elseif ( 'post_type_archive' === $menu_item->type ) { $original_object = get_post_type_object( $menu_item->object ); if ( $original_object ) { $original_title = $original_object->labels->archives; } } $classes = array( 'menu-item menu-item-depth-' . $depth, 'menu-item-' . esc_attr( $menu_item->object ), 'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ), ); $title = $menu_item->title; if ( ! empty( $menu_item->_invalid ) ) { $classes[] = 'menu-item-invalid'; /* translators: %s: Title of an invalid menu item. */ $title = sprintf( __( '%s (Invalid)' ), $menu_item->title ); } elseif ( isset( $menu_item->post_status ) && 'draft' === $menu_item->post_status ) { $classes[] = 'pending'; /* translators: %s: Title of a menu item in draft status. */ $title = sprintf( __( '%s (Pending)' ), $menu_item->title ); } $title = ( ! isset( $menu_item->label ) || '' === $menu_item->label ) ? $title : $menu_item->label; $submenu_text = ''; if ( 0 === $depth ) { $submenu_text = 'style="display: none;"'; } ?> <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>"> <div class="menu-item-bar"> <div class="menu-item-handle"> <label class="item-title" for="menu-item-checkbox-<?php echo $item_id; ?>"> <input id="menu-item-checkbox-<?php echo $item_id; ?>" type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo $item_id; ?>" disabled="disabled" /> <span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span> </label> <span class="item-controls"> <span class="item-type"><?php echo esc_html( $menu_item->type_label ); ?></span> <span class="item-order hide-if-js"> <?php printf( '<a href="%s" class="item-move-up" aria-label="%s">&#8593;</a>', wp_nonce_url( add_query_arg( array( 'action' => 'move-up-menu-item', 'menu-item' => $item_id, ), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) ), 'move-menu_item' ), esc_attr__( 'Move up' ) ); ?> | <?php printf( '<a href="%s" class="item-move-down" aria-label="%s">&#8595;</a>', wp_nonce_url( add_query_arg( array( 'action' => 'move-down-menu-item', 'menu-item' => $item_id, ), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) ) ), 'move-menu_item' ), esc_attr__( 'Move down' ) ); ?> </span> <?php if ( isset( $_GET['edit-menu-item'] ) && $item_id === $_GET['edit-menu-item'] ) { $edit_url = admin_url( 'nav-menus.php' ); } else { $edit_url = add_query_arg( array( 'edit-menu-item' => $item_id, ), remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) ); } printf( '<a class="item-edit" id="edit-%s" href="%s" aria-label="%s"><span class="screen-reader-text">%s</span></a>', $item_id, $edit_url, esc_attr__( 'Edit menu item' ), __( 'Edit' ) ); ?> </span> </div> </div> <div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>"> <?php if ( 'custom' === $menu_item->type ) : ?> <p class="field-url description description-wide"> <label for="edit-menu-item-url-<?php echo $item_id; ?>"> <?php _e( 'URL' ); ?><br /> <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->url ); ?>" /> </label> </p> <?php endif; ?> <p class="description description-wide"> <label for="edit-menu-item-title-<?php echo $item_id; ?>"> <?php _e( 'Navigation Label' ); ?><br /> <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->title ); ?>" /> </label> </p> <p class="field-title-attribute field-attr-title description description-wide"> <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>"> <?php _e( 'Title Attribute' ); ?><br /> <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->post_excerpt ); ?>" /> </label> </p> <p class="field-link-target description"> <label for="edit-menu-item-target-<?php echo $item_id; ?>"> <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $menu_item->target, '_blank' ); ?> /> <?php _e( 'Open link in a new tab' ); ?> </label> </p> <p class="field-css-classes description description-thin"> <label for="edit-menu-item-classes-<?php echo $item_id; ?>"> <?php _e( 'CSS Classes (optional)' ); ?><br /> <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode( ' ', $menu_item->classes ) ); ?>" /> </label> </p> <p class="field-xfn description description-thin"> <label for="edit-menu-item-xfn-<?php echo $item_id; ?>"> <?php _e( 'Link Relationship (XFN)' ); ?><br /> <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->xfn ); ?>" /> </label> </p> <p class="field-description description description-wide"> <label for="edit-menu-item-description-<?php echo $item_id; ?>"> <?php _e( 'Description' ); ?><br /> <textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $menu_item->description ); // textarea_escaped ?></textarea> <span class="description"><?php _e( 'The description will be displayed in the menu if the active theme supports it.' ); ?></span> </label> </p> <?php /** * Fires just before the move buttons of a nav menu item in the menu editor. * * @since 5.4.0 * * @param string $item_id Menu item ID as a numeric string. * @param WP_Post $menu_item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param stdClass|null $args An object of menu item arguments. * @param int $current_object_id Nav menu ID. */ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $menu_item, $depth, $args, $current_object_id ); ?> <fieldset class="field-move hide-if-no-js description description-wide"> <span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move' ); ?></span> <button type="button" class="button-link menus-move menus-move-up" data-dir="up"><?php _e( 'Up one' ); ?></button> <button type="button" class="button-link menus-move menus-move-down" data-dir="down"><?php _e( 'Down one' ); ?></button> <button type="button" class="button-link menus-move menus-move-left" data-dir="left"></button> <button type="button" class="button-link menus-move menus-move-right" data-dir="right"></button> <button type="button" class="button-link menus-move menus-move-top" data-dir="top"><?php _e( 'To the top' ); ?></button> </fieldset> <div class="menu-item-actions description-wide submitbox"> <?php if ( 'custom' !== $menu_item->type && false !== $original_title ) : ?> <p class="link-to-original"> <?php /* translators: %s: Link to menu item's original object. */ printf( __( 'Original: %s' ), '<a href="' . esc_url( $menu_item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?> </p> <?php endif; ?> <?php printf( '<a class="item-delete submitdelete deletion" id="delete-%s" href="%s">%s</a>', $item_id, wp_nonce_url( add_query_arg( array( 'action' => 'delete-menu-item', 'menu-item' => $item_id, ), admin_url( 'nav-menus.php' ) ), 'delete-menu_item_' . $item_id ), __( 'Remove' ) ); ?> <span class="meta-sep hide-if-no-js"> | </span> <?php printf( '<a class="item-cancel submitcancel hide-if-no-js" id="cancel-%s" href="%s#menu-item-settings-%s">%s</a>', $item_id, esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time(), ), admin_url( 'nav-menus.php' ) ) ), $item_id, __( 'Cancel' ) ); ?> </div> <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>" /> <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->object_id ); ?>" /> <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->object ); ?>" /> <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->menu_item_parent ); ?>" /> <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->menu_order ); ?>" /> <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->type ); ?>" /> </div><!-- .menu-item-settings--> <ul class="menu-item-transport"></ul> <?php $output .= ob_get_clean(); } ``` [do\_action( 'wp\_nav\_menu\_item\_custom\_fields', string $item\_id, WP\_Post $menu\_item, int $depth, stdClass|null $args, int $current\_object\_id )](../../hooks/wp_nav_menu_item_custom_fields) Fires just before the move buttons of a nav menu item in the menu editor. | Uses | Description | | --- | --- | | [remove\_query\_arg()](../../functions/remove_query_arg) wp-includes/functions.php | Removes an item or items from a query string. | | [esc\_attr\_\_()](../../functions/esc_attr__) wp-includes/l10n.php | Retrieves the translation of $text and escapes it for safe use in an attribute. | | [get\_the\_title()](../../functions/get_the_title) wp-includes/post-template.php | Retrieves the post title. | | [checked()](../../functions/checked) wp-includes/general-template.php | Outputs the HTML checked attribute. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post\_type\_object()](../../functions/get_post_type_object) wp-includes/post.php | Retrieves a post type object by name. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [admin\_url()](../../functions/admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. | | [add\_query\_arg()](../../functions/add_query_arg) wp-includes/functions.php | Retrieves a modified URL query string. | | [get\_term()](../../functions/get_term) wp-includes/taxonomy.php | Gets all term data from database by term ID. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$item` to `$data_object` and `$id` to `$current_object_id` to match parent class for PHP 8 named parameter support. | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |
programming_docs
wordpress Walker_Nav_Menu_Edit::end_lvl( string $output, int $depth, stdClass $args = null ) Walker\_Nav\_Menu\_Edit::end\_lvl( string $output, int $depth, stdClass $args = null ) ====================================================================================== Ends the list of after the elements are added. * [Walker\_Nav\_Menu::end\_lvl()](../walker_nav_menu/end_lvl) `$output` string Required Passed by reference. `$depth` int Required Depth of menu item. Used for padding. `$args` stdClass Optional Not used. Default: `null` File: `wp-admin/includes/class-walker-nav-menu-edit.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-walker-nav-menu-edit.php/) ``` public function end_lvl( &$output, $depth = 0, $args = null ) {} ``` | Version | Description | | --- | --- | | [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. | wordpress WP_Links_List_Table::extra_tablenav( string $which ) WP\_Links\_List\_Table::extra\_tablenav( string $which ) ======================================================== `$which` string Required File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` protected function extra_tablenav( $which ) { global $cat_id; if ( 'top' !== $which ) { return; } ?> <div class="alignleft actions"> <?php $dropdown_options = array( 'selected' => $cat_id, 'name' => 'cat_id', 'taxonomy' => 'link_category', 'show_option_all' => get_taxonomy( 'link_category' )->labels->all_items, 'hide_empty' => true, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', ); echo '<label class="screen-reader-text" for="cat_id">' . get_taxonomy( 'link_category' )->labels->filter_by_item . '</label>'; wp_dropdown_categories( $dropdown_options ); submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); ?> </div> <?php } ``` | Uses | Description | | --- | --- | | [submit\_button()](../../functions/submit_button) wp-admin/includes/template.php | Echoes a submit button, with provided text and appropriate class(es). | | [wp\_dropdown\_categories()](../../functions/wp_dropdown_categories) wp-includes/category-template.php | Displays or retrieves the HTML dropdown list of categories. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_taxonomy()](../../functions/get_taxonomy) wp-includes/taxonomy.php | Retrieves the taxonomy object of $taxonomy. | wordpress WP_Links_List_Table::prepare_items() WP\_Links\_List\_Table::prepare\_items() ======================================== File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function prepare_items() { global $cat_id, $s, $orderby, $order; wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) ); $args = array( 'hide_invisible' => 0, 'hide_empty' => 0, ); if ( 'all' !== $cat_id ) { $args['category'] = $cat_id; } if ( ! empty( $s ) ) { $args['search'] = $s; } if ( ! empty( $orderby ) ) { $args['orderby'] = $orderby; } if ( ! empty( $order ) ) { $args['order'] = $order; } $this->items = get_bookmarks( $args ); } ``` | Uses | Description | | --- | --- | | [wp\_reset\_vars()](../../functions/wp_reset_vars) wp-admin/includes/misc.php | Resets global variables based on $\_GET and $\_POST. | | [get\_bookmarks()](../../functions/get_bookmarks) wp-includes/bookmark.php | Retrieves the list of bookmarks. | wordpress WP_Links_List_Table::ajax_user_can(): bool WP\_Links\_List\_Table::ajax\_user\_can(): bool =============================================== bool File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function ajax_user_can() { return current_user_can( 'manage_links' ); } ``` | Uses | Description | | --- | --- | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | wordpress WP_Links_List_Table::column_categories( object $link ) WP\_Links\_List\_Table::column\_categories( object $link ) ========================================================== Handles the link categories column output. `$link` object Required The current link object. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function column_categories( $link ) { global $cat_id; $cat_names = array(); foreach ( $link->link_category as $category ) { $cat = get_term( $category, 'link_category', OBJECT, 'display' ); if ( is_wp_error( $cat ) ) { echo $cat->get_error_message(); } $cat_name = $cat->name; if ( (int) $cat_id !== $category ) { $cat_name = "<a href='link-manager.php?cat_id=$category'>$cat_name</a>"; } $cat_names[] = $cat_name; } echo implode( ', ', $cat_names ); } ``` | Uses | Description | | --- | --- | | [get\_term()](../../functions/get_term) wp-includes/taxonomy.php | Gets all term data from database by term ID. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Links_List_Table::display_rows() WP\_Links\_List\_Table::display\_rows() ======================================= File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function display_rows() { foreach ( $this->items as $link ) { $link = sanitize_bookmark( $link ); $link->link_name = esc_attr( $link->link_name ); $link->link_category = wp_get_link_cats( $link->link_id ); ?> <tr id="link-<?php echo $link->link_id; ?>"> <?php $this->single_row_columns( $link ); ?> </tr> <?php } } ``` | Uses | Description | | --- | --- | | [wp\_get\_link\_cats()](../../functions/wp_get_link_cats) wp-admin/includes/bookmark.php | Retrieves the link category IDs associated with the link specified. | | [sanitize\_bookmark()](../../functions/sanitize_bookmark) wp-includes/bookmark.php | Sanitizes all bookmark fields. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | wordpress WP_Links_List_Table::no_items() WP\_Links\_List\_Table::no\_items() =================================== File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function no_items() { _e( 'No links found.' ); } ``` | Uses | Description | | --- | --- | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | wordpress WP_Links_List_Table::column_visible( object $link ) WP\_Links\_List\_Table::column\_visible( object $link ) ======================================================= Handles the link visibility column output. `$link` object Required The current link object. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function column_visible( $link ) { if ( 'Y' === $link->link_visible ) { _e( 'Yes' ); } else { _e( 'No' ); } } ``` | Uses | Description | | --- | --- | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Links_List_Table::get_default_primary_column_name(): string WP\_Links\_List\_Table::get\_default\_primary\_column\_name(): string ===================================================================== Get the name of the default primary column. string Name of the default primary column, in this case, `'name'`. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` protected function get_default_primary_column_name() { return 'name'; } ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Links_List_Table::handle_row_actions( object $item, string $column_name, string $primary ): string WP\_Links\_List\_Table::handle\_row\_actions( object $item, string $column\_name, string $primary ): string =========================================================================================================== Generates and displays row action links. `$item` object Required Link being acted upon. `$column_name` string Required Current column name. `$primary` string Required Primary column name. string Row actions output for links, or an empty string if the current column is not the primary column. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` protected function handle_row_actions( $item, $column_name, $primary ) { if ( $primary !== $column_name ) { return ''; } // Restores the more descriptive, specific name for use within this method. $link = $item; $edit_link = get_edit_bookmark_link( $link ); $actions = array(); $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; $actions['delete'] = sprintf( '<a class="submitdelete" href="%s" onclick="return confirm( \'%s\' );">%s</a>', wp_nonce_url( "link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ), /* translators: %s: Link name. */ esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ), __( 'Delete' ) ); return $this->row_actions( $actions ); } ``` | Uses | Description | | --- | --- | | [esc\_js()](../../functions/esc_js) wp-includes/formatting.php | Escapes single quotes, `"`, , `&amp;`, and fixes line endings. | | [get\_edit\_bookmark\_link()](../../functions/get_edit_bookmark_link) wp-includes/link-template.php | Displays the edit bookmark link. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [wp\_nonce\_url()](../../functions/wp_nonce_url) wp-includes/functions.php | Retrieves URL with nonce added to URL query. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$link` to `$item` to match parent class for PHP 8 named parameter support. | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Links_List_Table::get_sortable_columns(): array WP\_Links\_List\_Table::get\_sortable\_columns(): array ======================================================= array File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` protected function get_sortable_columns() { return array( 'name' => 'name', 'url' => 'url', 'visible' => 'visible', 'rating' => 'rating', ); } ``` wordpress WP_Links_List_Table::column_cb( object $item ) WP\_Links\_List\_Table::column\_cb( object $item ) ================================================== Handles the checkbox column output. `$item` object Required The current link object. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function column_cb( $item ) { // Restores the more descriptive, specific name for use within this method. $link = $item; ?> <label class="screen-reader-text" for="cb-select-<?php echo $link->link_id; ?>"> <?php /* translators: %s: Link name. */ printf( __( 'Select %s' ), $link->link_name ); ?> </label> <input type="checkbox" name="linkcheck[]" id="cb-select-<?php echo $link->link_id; ?>" value="<?php echo esc_attr( $link->link_id ); ?>" /> <?php } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$link` to `$item` to match parent class for PHP 8 named parameter support. | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Links_List_Table::get_columns(): array WP\_Links\_List\_Table::get\_columns(): array ============================================= array File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function get_columns() { return array( 'cb' => '<input type="checkbox" />', 'name' => _x( 'Name', 'link name' ), 'url' => __( 'URL' ), 'categories' => __( 'Categories' ), 'rel' => __( 'Relationship' ), 'visible' => __( 'Visible' ), 'rating' => __( 'Rating' ), ); } ``` | Uses | Description | | --- | --- | | [\_x()](../../functions/_x) wp-includes/l10n.php | Retrieves translated string with gettext context. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | wordpress WP_Links_List_Table::get_bulk_actions(): array WP\_Links\_List\_Table::get\_bulk\_actions(): array =================================================== array File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` protected function get_bulk_actions() { $actions = array(); $actions['delete'] = __( 'Delete' ); return $actions; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | wordpress WP_Links_List_Table::__construct( array $args = array() ) WP\_Links\_List\_Table::\_\_construct( array $args = array() ) ============================================================== Constructor. * [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct): for more information on default arguments. `$args` array Optional An associative array of arguments. Default: `array()` File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function __construct( $args = array() ) { parent::__construct( array( 'plural' => 'bookmarks', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } ``` | Uses | Description | | --- | --- | | [WP\_List\_Table::\_\_construct()](../wp_list_table/__construct) wp-admin/includes/class-wp-list-table.php | Constructor. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Links_List_Table::column_url( object $link ) WP\_Links\_List\_Table::column\_url( object $link ) =================================================== Handles the link URL column output. `$link` object Required The current link object. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function column_url( $link ) { $short_url = url_shorten( $link->link_url ); echo "<a href='$link->link_url'>$short_url</a>"; } ``` | Uses | Description | | --- | --- | | [url\_shorten()](../../functions/url_shorten) wp-includes/formatting.php | Shortens a URL, to be used as link text. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Links_List_Table::column_name( object $link ) WP\_Links\_List\_Table::column\_name( object $link ) ==================================================== Handles the link name column output. `$link` object Required The current link object. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function column_name( $link ) { $edit_link = get_edit_bookmark_link( $link ); printf( '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong>', $edit_link, /* translators: %s: Link name. */ esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $link->link_name ) ), $link->link_name ); } ``` | Uses | Description | | --- | --- | | [get\_edit\_bookmark\_link()](../../functions/get_edit_bookmark_link) wp-includes/link-template.php | Displays the edit bookmark link. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Links_List_Table::column_rating( object $link ) WP\_Links\_List\_Table::column\_rating( object $link ) ====================================================== Handles the link rating column output. `$link` object Required The current link object. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function column_rating( $link ) { echo $link->link_rating; } ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Links_List_Table::column_default( object $item, string $column_name ) WP\_Links\_List\_Table::column\_default( object $item, string $column\_name ) ============================================================================= Handles the default column output. `$item` object Required Link object. `$column_name` string Required Current column name. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function column_default( $item, $column_name ) { /** * Fires for each registered custom link column. * * @since 2.1.0 * * @param string $column_name Name of the custom column. * @param int $link_id Link ID. */ do_action( 'manage_link_custom_column', $column_name, $item->link_id ); } ``` [do\_action( 'manage\_link\_custom\_column', string $column\_name, int $link\_id )](../../hooks/manage_link_custom_column) Fires for each registered custom link column. | Uses | Description | | --- | --- | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$link` to `$item` to match parent class for PHP 8 named parameter support. | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |
programming_docs
wordpress WP_Links_List_Table::column_rel( object $link ) WP\_Links\_List\_Table::column\_rel( object $link ) =================================================== Handles the link relation column output. `$link` object Required The current link object. File: `wp-admin/includes/class-wp-links-list-table.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-links-list-table.php/) ``` public function column_rel( $link ) { echo empty( $link->link_rel ) ? '<br />' : $link->link_rel; } ``` | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. | wordpress WP_Customize_Custom_CSS_Setting::preview(): bool WP\_Customize\_Custom\_CSS\_Setting::preview(): bool ==================================================== Add filter to preview post value. bool False when preview short-circuits due no change needing to be previewed. File: `wp-includes/customize/class-wp-customize-custom-css-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-custom-css-setting.php/) ``` public function preview() { if ( $this->is_previewed ) { return false; } $this->is_previewed = true; add_filter( 'wp_get_custom_css', array( $this, 'filter_previewed_wp_get_custom_css' ), 9, 2 ); return true; } ``` | Uses | Description | | --- | --- | | [add\_filter()](../../functions/add_filter) wp-includes/plugin.php | Adds a callback function to a filter hook. | | Version | Description | | --- | --- | | [4.7.9](https://developer.wordpress.org/reference/since/4.7.9/) | Introduced. | wordpress WP_Customize_Custom_CSS_Setting::update( string $value ): int|false WP\_Customize\_Custom\_CSS\_Setting::update( string $value ): int|false ======================================================================= Store the CSS setting value in the custom\_css custom post type for the stylesheet. `$value` string Required CSS to update. int|false The post ID or false if the value could not be saved. File: `wp-includes/customize/class-wp-customize-custom-css-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-custom-css-setting.php/) ``` public function update( $value ) { // Restores the more descriptive, specific name for use within this method. $css = $value; if ( empty( $css ) ) { $css = ''; } $r = wp_update_custom_css_post( $css, array( 'stylesheet' => $this->stylesheet, ) ); if ( $r instanceof WP_Error ) { return false; } $post_id = $r->ID; // Cache post ID in theme mod for performance to avoid additional DB query. if ( $this->manager->get_stylesheet() === $this->stylesheet ) { set_theme_mod( 'custom_css_post_id', $post_id ); } return $post_id; } ``` | Uses | Description | | --- | --- | | [wp\_update\_custom\_css\_post()](../../functions/wp_update_custom_css_post) wp-includes/theme.php | Updates the `custom_css` post for a given theme. | | [set\_theme\_mod()](../../functions/set_theme_mod) wp-includes/theme.php | Updates theme modification value for the active theme. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$css` to `$value` for PHP 8 named parameter support. | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Custom_CSS_Setting::filter_previewed_wp_get_custom_css( string $css, string $stylesheet ): string WP\_Customize\_Custom\_CSS\_Setting::filter\_previewed\_wp\_get\_custom\_css( string $css, string $stylesheet ): string ======================================================================================================================= Filters `wp_get_custom_css` for applying the customized value. This is used in the preview when `wp_get_custom_css()` is called for rendering the styles. * [wp\_get\_custom\_css()](../../functions/wp_get_custom_css) `$css` string Required Original CSS. `$stylesheet` string Required Current stylesheet. string CSS. File: `wp-includes/customize/class-wp-customize-custom-css-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-custom-css-setting.php/) ``` public function filter_previewed_wp_get_custom_css( $css, $stylesheet ) { if ( $stylesheet === $this->stylesheet ) { $customized_value = $this->post_value( null ); if ( ! is_null( $customized_value ) ) { $css = $customized_value; } } return $css; } ``` | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Custom_CSS_Setting::validate( string $value ): true|WP_Error WP\_Customize\_Custom\_CSS\_Setting::validate( string $value ): true|WP\_Error ============================================================================== Validate a received value for being valid CSS. Checks for imbalanced braces, brackets, and comments. Notifications are rendered when the customizer state is saved. `$value` string Required CSS to validate. true|[WP\_Error](../wp_error) True if the input was validated, otherwise [WP\_Error](../wp_error). File: `wp-includes/customize/class-wp-customize-custom-css-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-custom-css-setting.php/) ``` public function validate( $value ) { // Restores the more descriptive, specific name for use within this method. $css = $value; $validity = new WP_Error(); if ( preg_match( '#</?\w+#', $css ) ) { $validity->add( 'illegal_markup', __( 'Markup is not allowed in CSS.' ) ); } if ( ! $validity->has_errors() ) { $validity = parent::validate( $css ); } return $validity; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::validate()](../wp_customize_setting/validate) wp-includes/class-wp-customize-setting.php | Validates an input. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$css` to `$value` for PHP 8 named parameter support. | | [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Checking for balanced characters has been moved client-side via linting in code editor. | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Custom_CSS_Setting::value(): string WP\_Customize\_Custom\_CSS\_Setting::value(): string ==================================================== Fetch the value of the setting. Will return the previewed value when `preview()` is called. * [WP\_Customize\_Setting::value()](../wp_customize_setting/value) string File: `wp-includes/customize/class-wp-customize-custom-css-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-custom-css-setting.php/) ``` public function value() { if ( $this->is_previewed ) { $post_value = $this->post_value( null ); if ( null !== $post_value ) { return $post_value; } } $id_base = $this->id_data['base']; $value = ''; $post = wp_get_custom_css_post( $this->stylesheet ); if ( $post ) { $value = $post->post_content; } if ( empty( $value ) ) { $value = $this->default; } /** This filter is documented in wp-includes/class-wp-customize-setting.php */ $value = apply_filters( "customize_value_{$id_base}", $value, $this ); return $value; } ``` [apply\_filters( "customize\_value\_{$id\_base}", mixed $default\_value, WP\_Customize\_Setting $setting )](../../hooks/customize_value_id_base) Filters a Customize setting value not handled as a theme\_mod or option. | Uses | Description | | --- | --- | | [wp\_get\_custom\_css\_post()](../../functions/wp_get_custom_css_post) wp-includes/theme.php | Fetches the `custom_css` post for a given theme. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Customize_Custom_CSS_Setting::__construct( WP_Customize_Manager $manager, string $id, array $args = array() ) WP\_Customize\_Custom\_CSS\_Setting::\_\_construct( WP\_Customize\_Manager $manager, string $id, array $args = array() ) ======================================================================================================================== [WP\_Customize\_Custom\_CSS\_Setting](../wp_customize_custom_css_setting) constructor. `$manager` [WP\_Customize\_Manager](../wp_customize_manager) Required Customizer bootstrap instance. `$id` string Required A specific ID of the setting. Can be a theme mod or option name. `$args` array Optional Setting arguments. Default: `array()` File: `wp-includes/customize/class-wp-customize-custom-css-setting.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-custom-css-setting.php/) ``` public function __construct( $manager, $id, $args = array() ) { parent::__construct( $manager, $id, $args ); if ( 'custom_css' !== $this->id_data['base'] ) { throw new Exception( 'Expected custom_css id_base.' ); } if ( 1 !== count( $this->id_data['keys'] ) || empty( $this->id_data['keys'][0] ) ) { throw new Exception( 'Expected single stylesheet key.' ); } $this->stylesheet = $this->id_data['keys'][0]; } ``` | Uses | Description | | --- | --- | | [WP\_Customize\_Setting::\_\_construct()](../wp_customize_setting/__construct) wp-includes/class-wp-customize-setting.php | Constructor. | | Used By | Description | | --- | --- | | [WP\_Customize\_Manager::register\_controls()](../wp_customize_manager/register_controls) wp-includes/class-wp-customize-manager.php | Registers some default controls. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_Admin_Bar::_render_container( object $node ) WP\_Admin\_Bar::\_render\_container( object $node ) =================================================== `$node` object Required File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final protected function _render_container( $node ) { if ( 'container' !== $node->type || empty( $node->children ) ) { return; } echo '<div id="' . esc_attr( 'wp-admin-bar-' . $node->id ) . '" class="ab-group-container">'; foreach ( $node->children as $group ) { $this->_render_group( $group ); } echo '</div>'; } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::\_render\_group()](_render_group) wp-includes/class-wp-admin-bar.php | | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::\_render\_group()](_render_group) wp-includes/class-wp-admin-bar.php | | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::_render_item( object $node ) WP\_Admin\_Bar::\_render\_item( object $node ) ============================================== `$node` object Required File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final protected function _render_item( $node ) { if ( 'item' !== $node->type ) { return; } $is_parent = ! empty( $node->children ); $has_link = ! empty( $node->href ); $is_root_top_item = 'root-default' === $node->parent; $is_top_secondary_item = 'top-secondary' === $node->parent; // Allow only numeric values, then casted to integers, and allow a tabindex value of `0` for a11y. $tabindex = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : ''; $aria_attributes = ( '' !== $tabindex ) ? ' tabindex="' . $tabindex . '"' : ''; $menuclass = ''; $arrow = ''; if ( $is_parent ) { $menuclass = 'menupop '; $aria_attributes .= ' aria-haspopup="true"'; } if ( ! empty( $node->meta['class'] ) ) { $menuclass .= $node->meta['class']; } // Print the arrow icon for the menu children with children. if ( ! $is_root_top_item && ! $is_top_secondary_item && $is_parent ) { $arrow = '<span class="wp-admin-bar-arrow" aria-hidden="true"></span>'; } if ( $menuclass ) { $menuclass = ' class="' . esc_attr( trim( $menuclass ) ) . '"'; } echo "<li id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$menuclass>"; if ( $has_link ) { $attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' ); echo "<a class='ab-item'$aria_attributes href='" . esc_url( $node->href ) . "'"; } else { $attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' ); echo '<div class="ab-item ab-empty-item"' . $aria_attributes; } foreach ( $attributes as $attribute ) { if ( empty( $node->meta[ $attribute ] ) ) { continue; } if ( 'onclick' === $attribute ) { echo " $attribute='" . esc_js( $node->meta[ $attribute ] ) . "'"; } else { echo " $attribute='" . esc_attr( $node->meta[ $attribute ] ) . "'"; } } echo ">{$arrow}{$node->title}"; if ( $has_link ) { echo '</a>'; } else { echo '</div>'; } if ( $is_parent ) { echo '<div class="ab-sub-wrapper">'; foreach ( $node->children as $group ) { $this->_render_group( $group ); } echo '</div>'; } if ( ! empty( $node->meta['html'] ) ) { echo $node->meta['html']; } echo '</li>'; } ``` | Uses | Description | | --- | --- | | [esc\_js()](../../functions/esc_js) wp-includes/formatting.php | Escapes single quotes, `"`, , `&amp;`, and fixes line endings. | | [WP\_Admin\_Bar::\_render\_group()](_render_group) wp-includes/class-wp-admin-bar.php | | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::\_render\_group()](_render_group) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::recursive\_render()](recursive_render) wp-includes/class-wp-admin-bar.php | Renders toolbar items recursively. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::_render_group( object $node ) WP\_Admin\_Bar::\_render\_group( object $node ) =============================================== `$node` object Required File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final protected function _render_group( $node ) { if ( 'container' === $node->type ) { $this->_render_container( $node ); return; } if ( 'group' !== $node->type || empty( $node->children ) ) { return; } if ( ! empty( $node->meta['class'] ) ) { $class = ' class="' . esc_attr( trim( $node->meta['class'] ) ) . '"'; } else { $class = ''; } echo "<ul id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$class>"; foreach ( $node->children as $item ) { $this->_render_item( $item ); } echo '</ul>'; } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::\_render\_item()](_render_item) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::\_render\_container()](_render_container) wp-includes/class-wp-admin-bar.php | | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::\_render()](_render) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::\_render\_container()](_render_container) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::\_render\_item()](_render_item) wp-includes/class-wp-admin-bar.php | | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::initialize() WP\_Admin\_Bar::initialize() ============================ Initializes the admin bar. File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` public function initialize() { $this->user = new stdClass; if ( is_user_logged_in() ) { /* Populate settings we need for the menu based on the current user. */ $this->user->blogs = get_blogs_of_user( get_current_user_id() ); if ( is_multisite() ) { $this->user->active_blog = get_active_blog_for_user( get_current_user_id() ); $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) ); $this->user->account_domain = $this->user->domain; } else { $this->user->active_blog = $this->user->blogs[ get_current_blog_id() ]; $this->user->domain = trailingslashit( home_url() ); $this->user->account_domain = $this->user->domain; } } add_action( 'wp_head', 'wp_admin_bar_header' ); add_action( 'admin_head', 'wp_admin_bar_header' ); if ( current_theme_supports( 'admin-bar' ) ) { /** * To remove the default padding styles from WordPress for the Toolbar, use the following code: * add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) ); */ $admin_bar_args = get_theme_support( 'admin-bar' ); $header_callback = $admin_bar_args[0]['callback']; } if ( empty( $header_callback ) ) { $header_callback = '_admin_bar_bump_cb'; } add_action( 'wp_head', $header_callback ); wp_enqueue_script( 'admin-bar' ); wp_enqueue_style( 'admin-bar' ); /** * Fires after WP_Admin_Bar is initialized. * * @since 3.1.0 */ do_action( 'admin_bar_init' ); } ``` [do\_action( 'admin\_bar\_init' )](../../hooks/admin_bar_init) Fires after [WP\_Admin\_Bar](../wp_admin_bar) is initialized. | Uses | Description | | --- | --- | | [wp\_enqueue\_script()](../../functions/wp_enqueue_script) wp-includes/functions.wp-scripts.php | Enqueue a script. | | [get\_theme\_support()](../../functions/get_theme_support) wp-includes/theme.php | Gets the theme support arguments passed when registering that support. | | [user\_admin\_url()](../../functions/user_admin_url) wp-includes/link-template.php | Retrieves the URL to the admin area for the current user. | | [get\_home\_url()](../../functions/get_home_url) wp-includes/link-template.php | Retrieves the URL for a given site where the front end is accessible. | | [wp\_enqueue\_style()](../../functions/wp_enqueue_style) wp-includes/functions.wp-styles.php | Enqueue a CSS stylesheet. | | [get\_blogs\_of\_user()](../../functions/get_blogs_of_user) wp-includes/user.php | Gets the sites a user belongs to. | | [get\_active\_blog\_for\_user()](../../functions/get_active_blog_for_user) wp-includes/ms-functions.php | Gets one of a user’s active blogs. | | [current\_theme\_supports()](../../functions/current_theme_supports) wp-includes/theme.php | Checks a theme’s support for a given feature. | | [trailingslashit()](../../functions/trailingslashit) wp-includes/formatting.php | Appends a trailing slash. | | [is\_user\_logged\_in()](../../functions/is_user_logged_in) wp-includes/pluggable.php | Determines whether the current visitor is a logged in user. | | [is\_multisite()](../../functions/is_multisite) wp-includes/load.php | If Multisite is enabled. | | [get\_current\_blog\_id()](../../functions/get_current_blog_id) wp-includes/load.php | Retrieve the current site ID. | | [home\_url()](../../functions/home_url) wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | [get\_current\_user\_id()](../../functions/get_current_user_id) wp-includes/user.php | Gets the current user’s ID. | | Used By | Description | | --- | --- | | [\_wp\_admin\_bar\_init()](../../functions/_wp_admin_bar_init) wp-includes/admin-bar.php | Instantiates the admin bar object and set it up as a global for access elsewhere. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |
programming_docs
wordpress WP_Admin_Bar::recursive_render( string $id, object $node ) WP\_Admin\_Bar::recursive\_render( string $id, object $node ) ============================================================= This method has been deprecated. Use [WP\_Admin\_Bar::\_render\_item()](../wp_admin_bar/_render_item) instead. Renders toolbar items recursively. * [WP\_Admin\_Bar::\_render\_item()](../wp_admin_bar/_render_item) * [WP\_Admin\_Bar::render()](../wp_admin_bar/render) `$id` string Required Unused. `$node` object Required File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` public function recursive_render( $id, $node ) { _deprecated_function( __METHOD__, '3.3.0', 'WP_Admin_bar::render(), WP_Admin_Bar::_render_item()' ); $this->_render_item( $node ); } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::\_render\_item()](_render_item) wp-includes/class-wp-admin-bar.php | | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Use [WP\_Admin\_Bar::\_render\_item()](_render_item) or [WP\_Admin\_bar::render()](render) instead. | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Admin_Bar::_set_node( array $args ) WP\_Admin\_Bar::\_set\_node( array $args ) ========================================== `$args` array Required File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final protected function _set_node( $args ) { $this->nodes[ $args['id'] ] = (object) $args; } ``` | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::\_bind()](_bind) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::add\_node()](add_node) wp-includes/class-wp-admin-bar.php | Adds a node to the menu. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::__get( string $name ): string|array|void WP\_Admin\_Bar::\_\_get( string $name ): string|array|void ========================================================== `$name` string Required string|array|void File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` public function __get( $name ) { switch ( $name ) { case 'proto': return is_ssl() ? 'https://' : 'http://'; case 'menu': _deprecated_argument( 'WP_Admin_Bar', '3.3.0', 'Modify admin bar nodes with WP_Admin_Bar::get_node(), WP_Admin_Bar::add_node(), and WP_Admin_Bar::remove_node(), not the <code>menu</code> property.' ); return array(); // Sorry, folks. } } ``` | Uses | Description | | --- | --- | | [is\_ssl()](../../functions/is_ssl) wp-includes/load.php | Determines if SSL is used. | | [\_deprecated\_argument()](../../functions/_deprecated_argument) wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::_unset_node( string $id ) WP\_Admin\_Bar::\_unset\_node( string $id ) =========================================== `$id` string Required File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final protected function _unset_node( $id ) { unset( $this->nodes[ $id ] ); } ``` | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::remove\_node()](remove_node) wp-includes/class-wp-admin-bar.php | Remove a node. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::_get_node( string $id ): object|void WP\_Admin\_Bar::\_get\_node( string $id ): object|void ====================================================== `$id` string Required object|void File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final protected function _get_node( $id ) { if ( $this->bound ) { return; } if ( empty( $id ) ) { $id = 'root'; } if ( isset( $this->nodes[ $id ] ) ) { return $this->nodes[ $id ]; } } ``` | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::\_bind()](_bind) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::get\_node()](get_node) wp-includes/class-wp-admin-bar.php | Gets a node. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::add_menu( array $node ) WP\_Admin\_Bar::add\_menu( array $node ) ======================================== Adds a node (menu item) to the admin bar menu. `$node` array Required The attributes that define the node. Initial items in the Admin Bar are($menu\_id): * my-account-with-avatar – Dashboard, User settings * new-content – Short-cut to all custom post types and original ones * comments – Comments moderation * appearance – Theme selection and Widgets Parameter $node takes an array of arguments: id (*string*) (*required*) The ID of the node. Default: false title (*string*) (*optional*) The text that will be visible in the Toolbar. Including html tags is allowed. Default: false parent (*string*) (*optional*) The ID of the parent node. Default: false href (*string*) (*optional*) The ‘href’ attribute for the link. If ‘href’ is not set the node will be a text node. Default: false group (*boolean*) (*optional*) This will make the node a group (node) if set to ‘true’. Group nodes are not visible in the Toolbar, but nodes added to it are. See [add\_group()](add_group "Function Reference/add group"). Default: false meta (*array*) (*optional*) An array of meta data for the node. Default: array() * ‘html’ – The html used for the node. * ‘class’ – The class attribute for the list item containing the link or text node. * ‘rel’ – The rel attribute. * ‘onclick’ – The onclick attribute for the link. This will only be set if the ‘href’ argument is present. * ‘target’ – The target attribute for the link. This will only be set if the ‘href’ argument is present. * ‘title’ – The title attribute. Will be set to the link or to a div containing a text node. * ‘tabindex’ – The tabindex attribute. Will be set to the link or to a div containing a text node. File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` public function add_menu( $node ) { $this->add_node( $node ); } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::add\_node()](add_node) wp-includes/class-wp-admin-bar.php | Adds a node to the menu. | | Used By | Description | | --- | --- | | [wp\_admin\_bar\_dashboard\_view\_site\_menu()](../../functions/wp_admin_bar_dashboard_view_site_menu) wp-includes/deprecated.php | Add the “Dashboard”/”Visit Site” menu. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::get_nodes(): array|void WP\_Admin\_Bar::get\_nodes(): array|void ======================================== array|void File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final public function get_nodes() { $nodes = $this->_get_nodes(); if ( ! $nodes ) { return; } foreach ( $nodes as &$node ) { $node = clone $node; } return $nodes; } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::\_get\_nodes()](_get_nodes) wp-includes/class-wp-admin-bar.php | | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::_bind(): object|void WP\_Admin\_Bar::\_bind(): object|void ===================================== object|void File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final protected function _bind() { if ( $this->bound ) { return; } // Add the root node. // Clear it first, just in case. Don't mess with The Root. $this->remove_node( 'root' ); $this->add_node( array( 'id' => 'root', 'group' => false, ) ); // Normalize nodes: define internal 'children' and 'type' properties. foreach ( $this->_get_nodes() as $node ) { $node->children = array(); $node->type = ( $node->group ) ? 'group' : 'item'; unset( $node->group ); // The Root wants your orphans. No lonely items allowed. if ( ! $node->parent ) { $node->parent = 'root'; } } foreach ( $this->_get_nodes() as $node ) { if ( 'root' === $node->id ) { continue; } // Fetch the parent node. If it isn't registered, ignore the node. $parent = $this->_get_node( $node->parent ); if ( ! $parent ) { continue; } // Generate the group class (we distinguish between top level and other level groups). $group_class = ( 'root' === $node->parent ) ? 'ab-top-menu' : 'ab-submenu'; if ( 'group' === $node->type ) { if ( empty( $node->meta['class'] ) ) { $node->meta['class'] = $group_class; } else { $node->meta['class'] .= ' ' . $group_class; } } // Items in items aren't allowed. Wrap nested items in 'default' groups. if ( 'item' === $parent->type && 'item' === $node->type ) { $default_id = $parent->id . '-default'; $default = $this->_get_node( $default_id ); // The default group is added here to allow groups that are // added before standard menu items to render first. if ( ! $default ) { // Use _set_node because add_node can be overloaded. // Make sure to specify default settings for all properties. $this->_set_node( array( 'id' => $default_id, 'parent' => $parent->id, 'type' => 'group', 'children' => array(), 'meta' => array( 'class' => $group_class, ), 'title' => false, 'href' => false, ) ); $default = $this->_get_node( $default_id ); $parent->children[] = $default; } $parent = $default; // Groups in groups aren't allowed. Add a special 'container' node. // The container will invisibly wrap both groups. } elseif ( 'group' === $parent->type && 'group' === $node->type ) { $container_id = $parent->id . '-container'; $container = $this->_get_node( $container_id ); // We need to create a container for this group, life is sad. if ( ! $container ) { // Use _set_node because add_node can be overloaded. // Make sure to specify default settings for all properties. $this->_set_node( array( 'id' => $container_id, 'type' => 'container', 'children' => array( $parent ), 'parent' => false, 'title' => false, 'href' => false, 'meta' => array(), ) ); $container = $this->_get_node( $container_id ); // Link the container node if a grandparent node exists. $grandparent = $this->_get_node( $parent->parent ); if ( $grandparent ) { $container->parent = $grandparent->id; $index = array_search( $parent, $grandparent->children, true ); if ( false === $index ) { $grandparent->children[] = $container; } else { array_splice( $grandparent->children, $index, 1, array( $container ) ); } } $parent->parent = $container->id; } $parent = $container; } // Update the parent ID (it might have changed). $node->parent = $parent->id; // Add the node to the tree. $parent->children[] = $node; } $root = $this->_get_node( 'root' ); $this->bound = true; return $root; } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::remove\_node()](remove_node) wp-includes/class-wp-admin-bar.php | Remove a node. | | [WP\_Admin\_Bar::add\_node()](add_node) wp-includes/class-wp-admin-bar.php | Adds a node to the menu. | | [WP\_Admin\_Bar::\_get\_nodes()](_get_nodes) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::\_get\_node()](_get_node) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::\_set\_node()](_set_node) wp-includes/class-wp-admin-bar.php | | | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::render()](render) wp-includes/class-wp-admin-bar.php | | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::_get_nodes(): array|void WP\_Admin\_Bar::\_get\_nodes(): array|void ========================================== array|void File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final protected function _get_nodes() { if ( $this->bound ) { return; } return $this->nodes; } ``` | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::\_bind()](_bind) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::get\_nodes()](get_nodes) wp-includes/class-wp-admin-bar.php | | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::remove_node( string $id ) WP\_Admin\_Bar::remove\_node( string $id ) ========================================== Remove a node. `$id` string Required The ID of the item. This function removes an item from the Toolbar. Toolbar items are also called “nodes”. The node ID’s can be found in the HTML source code of any WordPress page with a Toolbar on it. Find the list items that have ID’s that start with “wp-admin-bar-“. For example, the list item ID for the WordPress Logo on the left in the Toolbar is “wp-admin-bar-wp-logo”: ``` <li id="wp-admin-bar-wp-logo" class="menupop"> … </li> ``` Remove “wp-admin-bar-” from the list item ID to get the node ID. From this example the node ID is “wp-logo”. **Note**: It’s also possible to see all node ID’s with the example from [get\_nodes()](get_nodes "Function Reference/get nodes"). File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` public function remove_node( $id ) { $this->_unset_node( $id ); } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::\_unset\_node()](_unset_node) wp-includes/class-wp-admin-bar.php | | | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::\_bind()](_bind) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::remove\_menu()](remove_menu) wp-includes/class-wp-admin-bar.php | Removes a node from the admin bar. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Admin_Bar::remove_menu( string $id ) WP\_Admin\_Bar::remove\_menu( string $id ) ========================================== Removes a node from the admin bar. `$id` string Required The menu slug to remove. File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` public function remove_menu( $id ) { $this->remove_node( $id ); } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::remove\_node()](remove_node) wp-includes/class-wp-admin-bar.php | Remove a node. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Admin_Bar::render() WP\_Admin\_Bar::render() ======================== File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` public function render() { $root = $this->_bind(); if ( $root ) { $this->_render( $root ); } } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::\_bind()](_bind) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::\_render()](_render) wp-includes/class-wp-admin-bar.php | | | Used By | Description | | --- | --- | | [wp\_admin\_bar\_render()](../../functions/wp_admin_bar_render) wp-includes/admin-bar.php | Renders the admin bar to the page based on the $wp\_admin\_bar->menu member var. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Admin_Bar::get_node( string $id ): object|void WP\_Admin\_Bar::get\_node( string $id ): object|void ==================================================== Gets a node. `$id` string Required object|void Node. This function returns a Toolbar object with all the properties of a single Toolbar item. Toolbar items are also called “nodes”. The parameter $id is the node ID of the Toolbar item you want to get. Default is None. The node ID’s can be found in the HTML source code of any WordPress page with a Toolbar on it. Find the list items that have ID’s that start with “wp-admin-bar-“. For example, the list item ID for the WordPress Logo on the left in the Toolbar is “wp-admin-bar-wp-logo”: ``` <li id="wp-admin-bar-wp-logo" class="menupop"> … </li> ``` Remove “wp-admin-bar-” from the list item ID to get the node ID. From this example the node ID is “wp-logo”. **Note**: It’s also possible to see all node ID’s with example from [get\_nodes()](get_nodes#Display_all_Node_ID.27s_of_the_Current_Page_in_the_Toolbar "Function Reference/get nodes"). File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final public function get_node( $id ) { $node = $this->_get_node( $id ); if ( $node ) { return clone $node; } } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::\_get\_node()](_get_node) wp-includes/class-wp-admin-bar.php | | | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::add\_node()](add_node) wp-includes/class-wp-admin-bar.php | Adds a node to the menu. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::add_node( array $args ) WP\_Admin\_Bar::add\_node( array $args ) ======================================== Adds a node to the menu. `$args` array Required Arguments for adding a node. * `id`stringID of the item. * `title`stringTitle of the node. * `parent`stringOptional. ID of the parent node. * `href`stringOptional. Link for the item. * `group`boolOptional. Whether or not the node is a group. Default false. * `meta`arrayMeta data including the following keys: `'html'`, `'class'`, `'rel'`, `'lang'`, `'dir'`, `'onclick'`, `'target'`, `'title'`, `'tabindex'`. Default empty. * This function is a method of the [WP\_Admin\_Bar](../wp_admin_bar) class and $wp\_admin\_bar global object, which may not exist except during the ‘admin\_bar\_menu’ or ‘[wp\_before\_admin\_bar\_render](../../hooks/wp_before_admin_bar_render)‘ hooks. * <add_menu> is an alias for this method. File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` public function add_node( $args ) { // Shim for old method signature: add_node( $parent_id, $menu_obj, $args ). if ( func_num_args() >= 3 && is_string( $args ) ) { $args = array_merge( array( 'parent' => $args ), func_get_arg( 2 ) ); } if ( is_object( $args ) ) { $args = get_object_vars( $args ); } // Ensure we have a valid title. if ( empty( $args['id'] ) ) { if ( empty( $args['title'] ) ) { return; } _doing_it_wrong( __METHOD__, __( 'The menu ID should not be empty.' ), '3.3.0' ); // Deprecated: Generate an ID from the title. $args['id'] = esc_attr( sanitize_title( trim( $args['title'] ) ) ); } $defaults = array( 'id' => false, 'title' => false, 'parent' => false, 'href' => false, 'group' => false, 'meta' => array(), ); // If the node already exists, keep any data that isn't provided. $maybe_defaults = $this->get_node( $args['id'] ); if ( $maybe_defaults ) { $defaults = get_object_vars( $maybe_defaults ); } // Do the same for 'meta' items. if ( ! empty( $defaults['meta'] ) && ! empty( $args['meta'] ) ) { $args['meta'] = wp_parse_args( $args['meta'], $defaults['meta'] ); } $args = wp_parse_args( $args, $defaults ); $back_compat_parents = array( 'my-account-with-avatar' => array( 'my-account', '3.3' ), 'my-blogs' => array( 'my-sites', '3.3' ), ); if ( isset( $back_compat_parents[ $args['parent'] ] ) ) { list( $new_parent, $version ) = $back_compat_parents[ $args['parent'] ]; _deprecated_argument( __METHOD__, $version, sprintf( 'Use <code>%s</code> as the parent for the <code>%s</code> admin bar node instead of <code>%s</code>.', $new_parent, $args['id'], $args['parent'] ) ); $args['parent'] = $new_parent; } $this->_set_node( $args ); } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::get\_node()](get_node) wp-includes/class-wp-admin-bar.php | Gets a node. | | [sanitize\_title()](../../functions/sanitize_title) wp-includes/formatting.php | Sanitizes a string into a slug, which can be used in URLs or HTML attributes. | | [WP\_Admin\_Bar::\_set\_node()](_set_node) wp-includes/class-wp-admin-bar.php | | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [\_doing\_it\_wrong()](../../functions/_doing_it_wrong) wp-includes/functions.php | Marks something as being incorrectly called. | | [\_deprecated\_argument()](../../functions/_deprecated_argument) wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Used By | Description | | --- | --- | | [wp\_admin\_bar\_edit\_site\_menu()](../../functions/wp_admin_bar_edit_site_menu) wp-includes/admin-bar.php | Adds the “Edit site” link to the Toolbar. | | [wp\_admin\_bar\_recovery\_mode\_menu()](../../functions/wp_admin_bar_recovery_mode_menu) wp-includes/admin-bar.php | Adds a link to exit recovery mode when Recovery Mode is active. | | [wp\_admin\_bar\_customize\_menu()](../../functions/wp_admin_bar_customize_menu) wp-includes/admin-bar.php | Adds the “Customize” link to the Toolbar. | | [WP\_Admin\_Bar::\_bind()](_bind) wp-includes/class-wp-admin-bar.php | | | [WP\_Admin\_Bar::add\_menu()](add_menu) wp-includes/class-wp-admin-bar.php | Adds a node (menu item) to the admin bar menu. | | [WP\_Admin\_Bar::add\_group()](add_group) wp-includes/class-wp-admin-bar.php | Adds a group to a toolbar menu node. | | [wp\_admin\_bar\_wp\_menu()](../../functions/wp_admin_bar_wp_menu) wp-includes/admin-bar.php | Adds the WordPress logo menu. | | [wp\_admin\_bar\_sidebar\_toggle()](../../functions/wp_admin_bar_sidebar_toggle) wp-includes/admin-bar.php | Adds the sidebar toggle button. | | [wp\_admin\_bar\_my\_account\_item()](../../functions/wp_admin_bar_my_account_item) wp-includes/admin-bar.php | Adds the “My Account” item. | | [wp\_admin\_bar\_my\_account\_menu()](../../functions/wp_admin_bar_my_account_menu) wp-includes/admin-bar.php | Adds the “My Account” submenu items. | | [wp\_admin\_bar\_site\_menu()](../../functions/wp_admin_bar_site_menu) wp-includes/admin-bar.php | Adds the “Site Name” menu. | | [wp\_admin\_bar\_my\_sites\_menu()](../../functions/wp_admin_bar_my_sites_menu) wp-includes/admin-bar.php | Adds the “My Sites/[Site Name]” menu and all submenus. | | [wp\_admin\_bar\_shortlink\_menu()](../../functions/wp_admin_bar_shortlink_menu) wp-includes/admin-bar.php | Provides a shortlink. | | [wp\_admin\_bar\_edit\_menu()](../../functions/wp_admin_bar_edit_menu) wp-includes/admin-bar.php | Provides an edit link for posts and terms. | | [wp\_admin\_bar\_new\_content\_menu()](../../functions/wp_admin_bar_new_content_menu) wp-includes/admin-bar.php | Adds “Add New” menu. | | [wp\_admin\_bar\_comments\_menu()](../../functions/wp_admin_bar_comments_menu) wp-includes/admin-bar.php | Adds edit comments link with awaiting moderation count bubble. | | [wp\_admin\_bar\_appearance\_menu()](../../functions/wp_admin_bar_appearance_menu) wp-includes/admin-bar.php | Adds appearance submenu items to the “Site Name” menu. | | [wp\_admin\_bar\_updates\_menu()](../../functions/wp_admin_bar_updates_menu) wp-includes/admin-bar.php | Provides an update link if theme/plugin/core updates are available. | | [wp\_admin\_bar\_search\_menu()](../../functions/wp_admin_bar_search_menu) wp-includes/admin-bar.php | Adds search form. | | Version | Description | | --- | --- | | [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Added the ability to pass `'lang'` and `'dir'` meta data. | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |
programming_docs
wordpress WP_Admin_Bar::add_menus() WP\_Admin\_Bar::add\_menus() ============================ Adds menus to the admin bar. File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` public function add_menus() { // User-related, aligned right. add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 0 ); add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 4 ); add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 7 ); add_action( 'admin_bar_menu', 'wp_admin_bar_recovery_mode_menu', 8 ); // Site-related. add_action( 'admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0 ); add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 ); add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 ); add_action( 'admin_bar_menu', 'wp_admin_bar_site_menu', 30 ); add_action( 'admin_bar_menu', 'wp_admin_bar_edit_site_menu', 40 ); add_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 40 ); add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 50 ); // Content-related. if ( ! is_network_admin() && ! is_user_admin() ) { add_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); add_action( 'admin_bar_menu', 'wp_admin_bar_new_content_menu', 70 ); } add_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 ); add_action( 'admin_bar_menu', 'wp_admin_bar_add_secondary_groups', 200 ); /** * Fires after menus are added to the menu bar. * * @since 3.1.0 */ do_action( 'add_admin_bar_menus' ); } ``` [do\_action( 'add\_admin\_bar\_menus' )](../../hooks/add_admin_bar_menus) Fires after menus are added to the menu bar. | Uses | Description | | --- | --- | | [is\_network\_admin()](../../functions/is_network_admin) wp-includes/load.php | Determines whether the current request is for the network administrative interface. | | [is\_user\_admin()](../../functions/is_user_admin) wp-includes/load.php | Determines whether the current request is for a user admin screen. | | [add\_action()](../../functions/add_action) wp-includes/plugin.php | Adds a callback function to an action hook. | | [do\_action()](../../functions/do_action) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. | | Used By | Description | | --- | --- | | [\_wp\_admin\_bar\_init()](../../functions/_wp_admin_bar_init) wp-includes/admin-bar.php | Instantiates the admin bar object and set it up as a global for access elsewhere. | | Version | Description | | --- | --- | | [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. | wordpress WP_Admin_Bar::add_group( array $args ) WP\_Admin\_Bar::add\_group( array $args ) ========================================= Adds a group to a toolbar menu node. Groups can be used to organize toolbar items into distinct sections of a toolbar menu. `$args` array Required Array of arguments for adding a group. * `id`stringID of the item. * `parent`stringOptional. ID of the parent node. Default `'root'`. * `meta`arrayMeta data for the group including the following keys: `'class'`, `'onclick'`, `'target'`, and `'title'`. * Toolbar items are also called “nodes”. Nodes can be parents for other nodes, which creates dropdown menus. When adding a group you’re actually adding a group node. Group nodes are not visible in the Toolbar, but nodes added to it are. * This function is a method of the [WP\_Admin\_Bar](../wp_admin_bar) class and `$wp_admin_bar global` object, which may not exist except during the ‘`admin_bar_menu`‘ or ‘`[wp\_before\_admin\_bar\_render](../../hooks/wp_before_admin_bar_render)`‘ hooks. * The Toolbar replaces the Admin Bar since WordPress Version 3.3. File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final public function add_group( $args ) { $args['group'] = true; $this->add_node( $args ); } ``` | Uses | Description | | --- | --- | | [WP\_Admin\_Bar::add\_node()](add_node) wp-includes/class-wp-admin-bar.php | Adds a node to the menu. | | Used By | Description | | --- | --- | | [wp\_admin\_bar\_my\_account\_menu()](../../functions/wp_admin_bar_my_account_menu) wp-includes/admin-bar.php | Adds the “My Account” submenu items. | | [wp\_admin\_bar\_my\_sites\_menu()](../../functions/wp_admin_bar_my_sites_menu) wp-includes/admin-bar.php | Adds the “My Sites/[Site Name]” menu and all submenus. | | [wp\_admin\_bar\_appearance\_menu()](../../functions/wp_admin_bar_appearance_menu) wp-includes/admin-bar.php | Adds appearance submenu items to the “Site Name” menu. | | [wp\_admin\_bar\_add\_secondary\_groups()](../../functions/wp_admin_bar_add_secondary_groups) wp-includes/admin-bar.php | Adds secondary menus. | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Admin_Bar::_render( object $root ) WP\_Admin\_Bar::\_render( object $root ) ======================================== `$root` object Required File: `wp-includes/class-wp-admin-bar.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-admin-bar.php/) ``` final protected function _render( $root ) { // Add browser classes. // We have to do this here since admin bar shows on the front end. $class = 'nojq nojs'; if ( wp_is_mobile() ) { $class .= ' mobile'; } ?> <div id="wpadminbar" class="<?php echo $class; ?>"> <?php if ( ! is_admin() && ! did_action( 'wp_body_open' ) ) { ?> <a class="screen-reader-shortcut" href="#wp-toolbar" tabindex="1"><?php _e( 'Skip to toolbar' ); ?></a> <?php } ?> <div class="quicklinks" id="wp-toolbar" role="navigation" aria-label="<?php esc_attr_e( 'Toolbar' ); ?>"> <?php foreach ( $root->children as $group ) { $this->_render_group( $group ); } ?> </div> <?php if ( is_user_logged_in() ) : ?> <a class="screen-reader-shortcut" href="<?php echo esc_url( wp_logout_url() ); ?>"><?php _e( 'Log Out' ); ?></a> <?php endif; ?> </div> <?php } ``` | Uses | Description | | --- | --- | | [esc\_attr\_e()](../../functions/esc_attr_e) wp-includes/l10n.php | Displays translated text that has been escaped for safe use in an attribute. | | [wp\_logout\_url()](../../functions/wp_logout_url) wp-includes/general-template.php | Retrieves the logout URL. | | [wp\_is\_mobile()](../../functions/wp_is_mobile) wp-includes/vars.php | Test if the current browser runs on a mobile device (smart phone, tablet, etc.) | | [WP\_Admin\_Bar::\_render\_group()](_render_group) wp-includes/class-wp-admin-bar.php | | | [did\_action()](../../functions/did_action) wp-includes/plugin.php | Retrieves the number of times an action has been fired during the current request. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_url()](../../functions/esc_url) wp-includes/formatting.php | Checks and cleans a URL. | | [is\_user\_logged\_in()](../../functions/is_user_logged_in) wp-includes/pluggable.php | Determines whether the current visitor is a logged in user. | | [is\_admin()](../../functions/is_admin) wp-includes/load.php | Determines whether the current request is for an administrative interface page. | | Used By | Description | | --- | --- | | [WP\_Admin\_Bar::render()](render) wp-includes/class-wp-admin-bar.php | | | Version | Description | | --- | --- | | [3.3.0](https://developer.wordpress.org/reference/since/3.3.0/) | Introduced. | wordpress WP_Customize_Image_Control::add_tab( string $id, string $label, mixed $callback ) WP\_Customize\_Image\_Control::add\_tab( string $id, string $label, mixed $callback ) ===================================================================================== This method has been deprecated. `$id` string Required `$label` string Required `$callback` mixed Required File: `wp-includes/customize/class-wp-customize-image-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-image-control.php/) ``` public function add_tab( $id, $label, $callback ) { _deprecated_function( __METHOD__, '4.1.0' ); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | This method has been deprecated. | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Image_Control::print_tab_image( string $url, string $thumbnail_url = null ) WP\_Customize\_Image\_Control::print\_tab\_image( string $url, string $thumbnail\_url = null ) ============================================================================================== This method has been deprecated. `$url` string Required `$thumbnail_url` string Optional Default: `null` File: `wp-includes/customize/class-wp-customize-image-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-image-control.php/) ``` public function print_tab_image( $url, $thumbnail_url = null ) { _deprecated_function( __METHOD__, '4.1.0' ); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | This method has been deprecated. | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_Customize_Image_Control::prepare_control() WP\_Customize\_Image\_Control::prepare\_control() ================================================= This method has been deprecated. File: `wp-includes/customize/class-wp-customize-image-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-image-control.php/) ``` public function prepare_control() {} ``` | Version | Description | | --- | --- | | [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | This method has been deprecated. | | [3.4.2](https://developer.wordpress.org/reference/since/3.4.2/) | Introduced. | wordpress WP_Customize_Image_Control::remove_tab( string $id ) WP\_Customize\_Image\_Control::remove\_tab( string $id ) ======================================================== This method has been deprecated. `$id` string Required File: `wp-includes/customize/class-wp-customize-image-control.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-image-control.php/) ``` public function remove_tab( $id ) { _deprecated_function( __METHOD__, '4.1.0' ); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | This method has been deprecated. | | [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. | wordpress WP_SimplePie_File::__construct( string $url, int $timeout = 10, int $redirects = 5, string|array $headers = null, string $useragent = null, bool $force_fsockopen = false ) WP\_SimplePie\_File::\_\_construct( string $url, int $timeout = 10, int $redirects = 5, string|array $headers = null, string $useragent = null, bool $force\_fsockopen = false ) ================================================================================================================================================================================ Constructor. `$url` string Required Remote file URL. `$timeout` int Optional How long the connection should stay open in seconds. Default: `10` `$redirects` int Optional The number of allowed redirects. Default: `5` `$headers` string|array Optional Array or string of headers to send with the request. Default: `null` `$useragent` string Optional User-agent value sent. Default: `null` `$force_fsockopen` bool Optional Whether to force opening internet or unix domain socket connection or not. Default: `false` File: `wp-includes/class-wp-simplepie-file.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-simplepie-file.php/) ``` public function __construct( $url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false ) { $this->url = $url; $this->timeout = $timeout; $this->redirects = $redirects; $this->headers = $headers; $this->useragent = $useragent; $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE; if ( preg_match( '/^http(s)?:\/\//i', $url ) ) { $args = array( 'timeout' => $this->timeout, 'redirection' => $this->redirects, ); if ( ! empty( $this->headers ) ) { $args['headers'] = $this->headers; } if ( SIMPLEPIE_USERAGENT != $this->useragent ) { // Use default WP user agent unless custom has been specified. $args['user-agent'] = $this->useragent; } $res = wp_safe_remote_request( $url, $args ); if ( is_wp_error( $res ) ) { $this->error = 'WP HTTP Error: ' . $res->get_error_message(); $this->success = false; } else { $this->headers = wp_remote_retrieve_headers( $res ); /* * SimplePie expects multiple headers to be stored as a comma-separated string, * but `wp_remote_retrieve_headers()` returns them as an array, so they need * to be converted. * * The only exception to that is the `content-type` header, which should ignore * any previous values and only use the last one. * * @see SimplePie_HTTP_Parser::new_line(). */ foreach ( $this->headers as $name => $value ) { if ( ! is_array( $value ) ) { continue; } if ( 'content-type' === $name ) { $this->headers[ $name ] = array_pop( $value ); } else { $this->headers[ $name ] = implode( ', ', $value ); } } $this->body = wp_remote_retrieve_body( $res ); $this->status_code = wp_remote_retrieve_response_code( $res ); } } else { $this->error = ''; $this->success = false; } } ``` | Uses | Description | | --- | --- | | [wp\_safe\_remote\_request()](../../functions/wp_safe_remote_request) wp-includes/http.php | Retrieve the raw response from a safe HTTP request. | | [wp\_remote\_retrieve\_headers()](../../functions/wp_remote_retrieve_headers) wp-includes/http.php | Retrieve only the headers from the raw response. | | [wp\_remote\_retrieve\_body()](../../functions/wp_remote_retrieve_body) wp-includes/http.php | Retrieve only the body from the raw response. | | [wp\_remote\_retrieve\_response\_code()](../../functions/wp_remote_retrieve_response_code) wp-includes/http.php | Retrieve only the response code from the raw response. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.6.1](https://developer.wordpress.org/reference/since/5.6.1/) | Multiple headers are concatenated into a comma-separated string, rather than remaining an array. | | [3.2.0](https://developer.wordpress.org/reference/since/3.2.0/) | Updated to use a PHP5 constructor. | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::get_user_global_styles_post_id(): integer|null WP\_Theme\_JSON\_Resolver::get\_user\_global\_styles\_post\_id(): integer|null ============================================================================== Returns the ID of the custom post type that stores user data. integer|null File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function get_user_global_styles_post_id() { if ( null !== static::$user_custom_post_type_id ) { return static::$user_custom_post_type_id; } $user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme(), true ); if ( array_key_exists( 'ID', $user_cpt ) ) { static::$user_custom_post_type_id = $user_cpt['ID']; } return static::$user_custom_post_type_id; } ``` | Uses | Description | | --- | --- | | [wp\_get\_theme()](../../functions/wp_get_theme) wp-includes/theme.php | Gets a [WP\_Theme](../wp_theme) object for a theme. | | Used By | Description | | --- | --- | | [WP\_REST\_Themes\_Controller::prepare\_links()](../wp_rest_themes_controller/prepare_links) wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php | Prepares links for the request. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::remove_json_comments( array $array ): array WP\_Theme\_JSON\_Resolver::remove\_json\_comments( array $array ): array ======================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. When given an array, this will remove any keys with the name `//`. `$array` array Required The array to filter. array The filtered array. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` private static function remove_json_comments( $array ) { unset( $array['//'] ); foreach ( $array as $k => $v ) { if ( is_array( $v ) ) { $array[ $k ] = static::remove_json_comments( $v ); } } return $array; } ``` wordpress WP_Theme_JSON_Resolver::clean_cached_data() WP\_Theme\_JSON\_Resolver::clean\_cached\_data() ================================================ Cleans the cached data so it can be recalculated. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function clean_cached_data() { static::$core = null; static::$blocks = null; static::$blocks_cache = array( 'core' => array(), 'blocks' => array(), 'theme' => array(), 'user' => array(), ); static::$theme = null; static::$user = null; static::$user_custom_post_type_id = null; static::$theme_has_support = null; static::$i18n_schema = null; } ``` | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added the `$blocks` and `$blocks_cache` variables to reset. | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added the `$user`, `$user_custom_post_type_id`, and `$i18n_schema` variables to reset. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::get_core_data(): WP_Theme_JSON WP\_Theme\_JSON\_Resolver::get\_core\_data(): WP\_Theme\_JSON ============================================================= Returns core’s origin config. [WP\_Theme\_JSON](../wp_theme_json) Entity that holds core data. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function get_core_data() { if ( null !== static::$core && static::has_same_registered_blocks( 'core' ) ) { return static::$core; } $config = static::read_json_file( __DIR__ . '/theme.json' ); $config = static::translate( $config ); /** * Filters the default data provided by WordPress for global styles & settings. * * @since 6.1.0 * * @param WP_Theme_JSON_Data Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data( $config, 'default' ) ); $config = $theme_json->get_data(); static::$core = new WP_Theme_JSON( $config, 'default' ); return static::$core; } ``` [apply\_filters( 'wp\_theme\_json\_data\_default', WP\_Theme\_JSON\_Data )](../../hooks/wp_theme_json_data_default) Filters the default data provided by WordPress for global styles & settings. | Uses | Description | | --- | --- | | [WP\_Theme\_JSON\_Data::\_\_construct()](../wp_theme_json_data/__construct) wp-includes/class-wp-theme-json-data.php | Constructor. | | [WP\_Theme\_JSON::\_\_construct()](../wp_theme_json/__construct) wp-includes/class-wp-theme-json.php | Constructor. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |
programming_docs
wordpress WP_Theme_JSON_Resolver::get_theme_data( array $deprecated = array(), array $options = array() ): WP_Theme_JSON WP\_Theme\_JSON\_Resolver::get\_theme\_data( array $deprecated = array(), array $options = array() ): WP\_Theme\_JSON ===================================================================================================================== Returns the theme’s data. Data from theme.json will be backfilled from existing theme supports, if any. Note that if the same data is present in theme.json and in theme supports, the theme.json takes precedence. `$deprecated` array Optional Deprecated. Not used. Default: `array()` `$options` array Optional Options arguments. * `with_supports`boolWhether to include theme supports in the data. Default true. Default: `array()` [WP\_Theme\_JSON](../wp_theme_json) Entity that holds theme data. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function get_theme_data( $deprecated = array(), $options = array() ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __METHOD__, '5.9.0' ); } $options = wp_parse_args( $options, array( 'with_supports' => true ) ); if ( null === static::$theme || ! static::has_same_registered_blocks( 'theme' ) ) { $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) ); $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) ); /** * Filters the data provided by the theme for global styles and settings. * * @since 6.1.0 * * @param WP_Theme_JSON_Data Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) ); $theme_json_data = $theme_json->get_data(); static::$theme = new WP_Theme_JSON( $theme_json_data ); } if ( wp_get_theme()->parent() ) { // Get parent theme.json. $parent_theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json', true ) ); $parent_theme_json_data = static::translate( $parent_theme_json_data, wp_get_theme()->parent()->get( 'TextDomain' ) ); $parent_theme = new WP_Theme_JSON( $parent_theme_json_data ); /* * Merge the child theme.json into the parent theme.json. * The child theme takes precedence over the parent. */ $parent_theme->merge( static::$theme ); static::$theme = $parent_theme; } if ( ! $options['with_supports'] ) { return static::$theme; } /* * We want the presets and settings declared in theme.json * to override the ones declared via theme supports. * So we take theme supports, transform it to theme.json shape * and merge the static::$theme upon that. */ $theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_default_block_editor_settings() ); if ( ! static::theme_has_support() ) { if ( ! isset( $theme_support_data['settings']['color'] ) ) { $theme_support_data['settings']['color'] = array(); } $default_palette = false; if ( current_theme_supports( 'default-color-palette' ) ) { $default_palette = true; } if ( ! isset( $theme_support_data['settings']['color']['palette'] ) ) { // If the theme does not have any palette, we still want to show the core one. $default_palette = true; } $theme_support_data['settings']['color']['defaultPalette'] = $default_palette; $default_gradients = false; if ( current_theme_supports( 'default-gradient-presets' ) ) { $default_gradients = true; } if ( ! isset( $theme_support_data['settings']['color']['gradients'] ) ) { // If the theme does not have any gradients, we still want to show the core ones. $default_gradients = true; } $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients; // Classic themes without a theme.json don't support global duotone. $theme_support_data['settings']['color']['defaultDuotone'] = false; } $with_theme_supports = new WP_Theme_JSON( $theme_support_data ); $with_theme_supports->merge( static::$theme ); return $with_theme_supports; } ``` [apply\_filters( 'wp\_theme\_json\_data\_theme', WP\_Theme\_JSON\_Data )](../../hooks/wp_theme_json_data_theme) Filters the data provided by the theme for global styles and settings. | Uses | Description | | --- | --- | | [WP\_Theme\_JSON\_Data::\_\_construct()](../wp_theme_json_data/__construct) wp-includes/class-wp-theme-json-data.php | Constructor. | | [get\_default\_block\_editor\_settings()](../../functions/get_default_block_editor_settings) wp-includes/block-editor.php | Returns the default block editor settings. | | [WP\_Theme\_JSON::get\_from\_editor\_settings()](../wp_theme_json/get_from_editor_settings) wp-includes/class-wp-theme-json.php | Transforms the given editor settings according the add\_theme\_support format to the theme.json format. | | [WP\_Theme\_JSON::\_\_construct()](../wp_theme_json/__construct) wp-includes/class-wp-theme-json.php | Constructor. | | [WP\_Theme::get()](../wp_theme/get) wp-includes/class-wp-theme.php | Gets a raw, unformatted theme header. | | [WP\_Theme::parent()](../wp_theme/parent) wp-includes/class-wp-theme.php | Returns reference to the parent theme. | | [current\_theme\_supports()](../../functions/current_theme_supports) wp-includes/theme.php | Checks a theme’s support for a given feature. | | [wp\_get\_theme()](../../functions/wp_get_theme) wp-includes/theme.php | Gets a [WP\_Theme](../wp_theme) object for a theme. | | [\_deprecated\_argument()](../../functions/_deprecated_argument) wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [\_register\_remote\_theme\_patterns()](../../functions/_register_remote_theme_patterns) wp-includes/block-patterns.php | Registers patterns from Pattern Directory provided by a theme’s `theme.json` file. | | [wp\_generate\_block\_templates\_export\_file()](../../functions/wp_generate_block_templates_export_file) wp-includes/block-template-utils.php | Creates an export of the current templates and template parts from the site editor at the specified path in a ZIP file. | | [\_add\_block\_template\_info()](../../functions/_add_block_template_info) wp-includes/block-template-utils.php | Attempts to add custom template information to the template item. | | [\_add\_block\_template\_part\_area\_info()](../../functions/_add_block_template_part_area_info) wp-includes/block-template-utils.php | Attempts to add the template part’s area information to the input template. | | Version | Description | | --- | --- | | [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Added an `$options` parameter to allow the theme data to be returned without theme supports. | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Theme supports have been inlined and the `$theme_support_data` argument removed. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::get_fields_to_translate(): array WP\_Theme\_JSON\_Resolver::get\_fields\_to\_translate(): array ============================================================== This method has been deprecated. Returns a data structure used in theme.json translation. array An array of theme.json fields that are translatable and the keys that are translatable. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function get_fields_to_translate() { _deprecated_function( __METHOD__, '5.9.0' ); return array(); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_function()](../../functions/_deprecated_function) wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | This method has been deprecated. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::get_style_variations(): array WP\_Theme\_JSON\_Resolver::get\_style\_variations(): array ========================================================== Returns the style variations defined by the theme. array File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function get_style_variations() { $variations = array(); $base_directory = get_stylesheet_directory() . '/styles'; if ( is_dir( $base_directory ) ) { $nested_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base_directory ) ); $nested_html_files = iterator_to_array( new RegexIterator( $nested_files, '/^.+\.json$/i', RecursiveRegexIterator::GET_MATCH ) ); ksort( $nested_html_files ); foreach ( $nested_html_files as $path => $file ) { $decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) ); if ( is_array( $decoded_file ) ) { $translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) ); $variation = ( new WP_Theme_JSON( $translated ) )->get_raw_data(); if ( empty( $variation['title'] ) ) { $variation['title'] = basename( $path, '.json' ); } $variations[] = $variation; } } } return $variations; } ``` | Uses | Description | | --- | --- | | [wp\_json\_file\_decode()](../../functions/wp_json_file_decode) wp-includes/functions.php | Reads and decodes a JSON file. | | [WP\_Theme\_JSON::\_\_construct()](../wp_theme_json/__construct) wp-includes/class-wp-theme-json.php | Constructor. | | [get\_stylesheet\_directory()](../../functions/get_stylesheet_directory) wp-includes/theme.php | Retrieves stylesheet directory path for the active theme. | | [WP\_Theme::get()](../wp_theme/get) wp-includes/class-wp-theme.php | Gets a raw, unformatted theme header. | | [wp\_get\_theme()](../../functions/wp_get_theme) wp-includes/theme.php | Gets a [WP\_Theme](../wp_theme) object for a theme. | | Used By | Description | | --- | --- | | [WP\_REST\_Global\_Styles\_Controller::get\_theme\_items()](../wp_rest_global_styles_controller/get_theme_items) wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php | Returns the given theme global styles variations. | | [\_wp\_theme\_json\_webfonts\_handler()](../../functions/_wp_theme_json_webfonts_handler) wp-includes/script-loader.php | Runs the theme.json webfonts handler. | | Version | Description | | --- | --- | | [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::get_merged_data( string $origin = 'custom' ): WP_Theme_JSON WP\_Theme\_JSON\_Resolver::get\_merged\_data( string $origin = 'custom' ): WP\_Theme\_JSON ========================================================================================== Returns the data merged from multiple origins. There are three sources of data (origins) for a site: default, theme, and custom. The custom’s has higher priority than the theme’s, and the theme’s higher than default’s. Unlike the getters <get_core_data>, <get_theme_data>, and <get_user_data>, this method returns data after it has been merged with the previous origins. This means that if the same piece of data is declared in different origins (user, theme, and core), the last origin overrides the previous. For example, if the user has set a background color for the paragraph block, and the theme has done it as well, the user preference wins. `$origin` string Optional To what level should we merge data. Valid values are `'theme'` or `'custom'`. Default `'custom'`. Default: `'custom'` [WP\_Theme\_JSON](../wp_theme_json) File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function get_merged_data( $origin = 'custom' ) { if ( is_array( $origin ) ) { _deprecated_argument( __FUNCTION__, '5.9.0' ); } $result = static::get_core_data(); $result->merge( static::get_block_data() ); $result->merge( static::get_theme_data() ); if ( 'custom' === $origin ) { $result->merge( static::get_user_data() ); } // Generate the default spacingSizes array based on the merged spacingScale settings. $result->set_spacing_sizes(); return $result; } ``` | Uses | Description | | --- | --- | | [\_deprecated\_argument()](../../functions/_deprecated_argument) wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. | | Used By | Description | | --- | --- | | [wp\_add\_global\_styles\_for\_blocks()](../../functions/wp_add_global_styles_for_blocks) wp-includes/global-styles-and-settings.php | Adds global style rules to the inline style for each block. | | [wp\_get\_global\_styles\_svg\_filters()](../../functions/wp_get_global_styles_svg_filters) wp-includes/global-styles-and-settings.php | Returns a string containing the SVGs to be referenced as filters (duotone). | | [\_wp\_theme\_json\_webfonts\_handler()](../../functions/_wp_theme_json_webfonts_handler) wp-includes/script-loader.php | Runs the theme.json webfonts handler. | | [wp\_get\_global\_settings()](../../functions/wp_get_global_settings) wp-includes/global-styles-and-settings.php | Gets the settings resulting of merging core, theme, and user data. | | [wp\_get\_global\_styles()](../../functions/wp_get_global_styles) wp-includes/global-styles-and-settings.php | Gets the styles resulting of merging core, theme, and user data. | | [wp\_get\_global\_stylesheet()](../../functions/wp_get_global_stylesheet) wp-includes/global-styles-and-settings.php | Returns the stylesheet resulting of merging core, theme, and user data. | | [WP\_REST\_Global\_Styles\_Controller::get\_theme\_item()](../wp_rest_global_styles_controller/get_theme_item) wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php | Returns the given theme global styles config. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added block data and generation of spacingSizes array. | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added user data, removed the `$settings` parameter, added the `$origin` parameter. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::read_json_file( string $file_path ): array WP\_Theme\_JSON\_Resolver::read\_json\_file( string $file\_path ): array ======================================================================== Processes a file that adheres to the theme.json schema and returns an array with its contents, or a void array if none found. `$file_path` string Required Path to file. Empty if no file. array Contents that adhere to the theme.json schema. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` protected static function read_json_file( $file_path ) { if ( $file_path ) { if ( array_key_exists( $file_path, static::$theme_json_file_cache ) ) { return static::$theme_json_file_cache[ $file_path ]; } $decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) ); if ( is_array( $decoded_file ) ) { static::$theme_json_file_cache[ $file_path ] = $decoded_file; return static::$theme_json_file_cache[ $file_path ]; } } return array(); } ``` | Uses | Description | | --- | --- | | [wp\_json\_file\_decode()](../../functions/wp_json_file_decode) wp-includes/functions.php | Reads and decodes a JSON file. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Added caching. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( WP_Theme $theme, bool $create_post = false, array $post_status_filter = array('publish') ): array WP\_Theme\_JSON\_Resolver::get\_user\_data\_from\_wp\_global\_styles( WP\_Theme $theme, bool $create\_post = false, array $post\_status\_filter = array('publish') ): array =========================================================================================================================================================================== Returns the custom post type that contains the user’s origin config for the active theme or a void array if none are found. This can also create and return a new draft custom post type. `$theme` [WP\_Theme](../wp_theme) Required The theme object. If empty, it defaults to the active theme. `$create_post` bool Optional Whether a new custom post type should be created if none are found. Default: `false` `$post_status_filter` array Optional Filter custom post type by post status. Default `array( 'publish' )`, so it only fetches published posts. Default: `array('publish')` array Custom Post Type for the user's origin config. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function get_user_data_from_wp_global_styles( $theme, $create_post = false, $post_status_filter = array( 'publish' ) ) { if ( ! $theme instanceof WP_Theme ) { $theme = wp_get_theme(); } $user_cpt = array(); $post_type_filter = 'wp_global_styles'; $stylesheet = $theme->get_stylesheet(); $args = array( 'posts_per_page' => 1, 'orderby' => 'post_date', 'order' => 'desc', 'post_type' => $post_type_filter, 'post_status' => $post_status_filter, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'tax_query' => array( array( 'taxonomy' => 'wp_theme', 'field' => 'name', 'terms' => $stylesheet, ), ), ); $global_style_query = new WP_Query(); $recent_posts = $global_style_query->query( $args ); if ( count( $recent_posts ) === 1 ) { $user_cpt = get_post( $recent_posts[0], ARRAY_A ); } elseif ( $create_post ) { $cpt_post_id = wp_insert_post( array( 'post_content' => '{"version": ' . WP_Theme_JSON::LATEST_SCHEMA . ', "isGlobalStylesUserThemeJSON": true }', 'post_status' => 'publish', 'post_title' => 'Custom Styles', // Do not make string translatable, see https://core.trac.wordpress.org/ticket/54518. 'post_type' => $post_type_filter, 'post_name' => sprintf( 'wp-global-styles-%s', urlencode( $stylesheet ) ), 'tax_input' => array( 'wp_theme' => array( $stylesheet ), ), ), true ); if ( ! is_wp_error( $cpt_post_id ) ) { $user_cpt = get_post( $cpt_post_id, ARRAY_A ); } } return $user_cpt; } ``` | Uses | Description | | --- | --- | | [wp\_insert\_post()](../../functions/wp_insert_post) wp-includes/post.php | Inserts or update a post. | | [WP\_Query::\_\_construct()](../wp_query/__construct) wp-includes/class-wp-query.php | Constructor. | | [wp\_get\_theme()](../../functions/wp_get_theme) wp-includes/theme.php | Gets a [WP\_Theme](../wp_theme) object for a theme. | | [get\_post()](../../functions/get_post) wp-includes/post.php | Retrieves post data given a post ID or post object. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Used By | Description | | --- | --- | | [WP\_REST\_Themes\_Controller::prepare\_links()](../wp_rest_themes_controller/prepare_links) wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php | Prepares links for the request. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |
programming_docs
wordpress WP_Theme_JSON_Resolver::has_same_registered_blocks( string $origin ): bool WP\_Theme\_JSON\_Resolver::has\_same\_registered\_blocks( string $origin ): bool ================================================================================ Checks whether the registered blocks were already processed for this origin. `$origin` string Required Data source for which to cache the blocks. Valid values are `'core'`, `'blocks'`, `'theme'`, and `'user'`. bool True on success, false otherwise. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` protected static function has_same_registered_blocks( $origin ) { // Bail out if the origin is invalid. if ( ! isset( static::$blocks_cache[ $origin ] ) ) { return false; } $registry = WP_Block_Type_Registry::get_instance(); $blocks = $registry->get_all_registered(); // Is there metadata for all currently registered blocks? $block_diff = array_diff_key( $blocks, static::$blocks_cache[ $origin ] ); if ( empty( $block_diff ) ) { return true; } foreach ( $blocks as $block_name => $block_type ) { static::$blocks_cache[ $origin ][ $block_name ] = true; } return false; } ``` | Uses | Description | | --- | --- | | [WP\_Block\_Type\_Registry::get\_instance()](../wp_block_type_registry/get_instance) wp-includes/class-wp-block-type-registry.php | Utility method to retrieve the main instance of the class. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::translate_theme_json_chunk( array $array_to_translate, string $key, string $context, string $domain ): array WP\_Theme\_JSON\_Resolver::translate\_theme\_json\_chunk( array $array\_to\_translate, string $key, string $context, string $domain ): array ============================================================================================================================================ This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Translates a chunk of the loaded theme.json structure. `$array_to_translate` array Required The chunk of theme.json to translate. `$key` string Required The key of the field that contains the string to translate. `$context` string Required The context to apply in the translation call. `$domain` string Required Text domain. Unique identifier for retrieving translated strings. array Returns the modified $theme\_json chunk. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` * @return WP_Theme_JSON Entity that holds core data. */ public static function get_core_data() { if ( null !== static::$core && static::has_same_registered_blocks( 'core' ) ) { return static::$core; } $config = static::read_json_file( __DIR__ . '/theme.json' ); $config = static::translate( $config ); /** * Filters the default data provided by WordPress for global styles & settings. ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::get_file_path_from_theme( string $file_name, bool $template = false ): string WP\_Theme\_JSON\_Resolver::get\_file\_path\_from\_theme( string $file\_name, bool $template = false ): string ============================================================================================================= Builds the path to the given file and checks that it is readable. If it isn’t, returns an empty string, otherwise returns the whole file path. `$file_name` string Required Name of the file. `$template` bool Optional Use template theme directory. Default: `false` string The whole file path or empty if the file doesn't exist. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` protected static function get_file_path_from_theme( $file_name, $template = false ) { $path = $template ? get_template_directory() : get_stylesheet_directory(); $candidate = $path . '/' . $file_name; return is_readable( $candidate ) ? $candidate : ''; } ``` | Uses | Description | | --- | --- | | [get\_template\_directory()](../../functions/get_template_directory) wp-includes/theme.php | Retrieves template directory path for the active theme. | | [get\_stylesheet\_directory()](../../functions/get_stylesheet_directory) wp-includes/theme.php | Retrieves stylesheet directory path for the active theme. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Adapted to work with child themes, added the `$template` argument. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::theme_has_support(): bool WP\_Theme\_JSON\_Resolver::theme\_has\_support(): bool ====================================================== Determines whether the active theme has a theme.json file. bool File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function theme_has_support() { if ( ! isset( static::$theme_has_support ) ) { static::$theme_has_support = ( is_readable( static::get_file_path_from_theme( 'theme.json' ) ) || is_readable( static::get_file_path_from_theme( 'theme.json', true ) ) ); } return static::$theme_has_support; } ``` | Used By | Description | | --- | --- | | [wp\_enqueue\_classic\_theme\_styles()](../../functions/wp_enqueue_classic_theme_styles) wp-includes/script-loader.php | Loads classic theme styles on classic themes in the frontend. | | [wp\_add\_editor\_classic\_theme\_styles()](../../functions/wp_add_editor_classic_theme_styles) wp-includes/script-loader.php | Loads classic theme styles on classic themes in the editor. | | [wp\_get\_global\_styles\_svg\_filters()](../../functions/wp_get_global_styles_svg_filters) wp-includes/global-styles-and-settings.php | Returns a string containing the SVGs to be referenced as filters (duotone). | | [\_register\_remote\_theme\_patterns()](../../functions/_register_remote_theme_patterns) wp-includes/block-patterns.php | Registers patterns from Pattern Directory provided by a theme’s `theme.json` file. | | [wp\_get\_global\_stylesheet()](../../functions/wp_get_global_stylesheet) wp-includes/global-styles-and-settings.php | Returns the stylesheet resulting of merging core, theme, and user data. | | [\_add\_block\_template\_info()](../../functions/_add_block_template_info) wp-includes/block-template-utils.php | Attempts to add custom template information to the template item. | | [\_add\_block\_template\_part\_area\_info()](../../functions/_add_block_template_part_area_info) wp-includes/block-template-utils.php | Attempts to add the template part’s area information to the input template. | | [wp\_enable\_block\_templates()](../../functions/wp_enable_block_templates) wp-includes/theme-templates.php | Enables the block templates (editor mode) for themes with theme.json by default. | | [get\_block\_editor\_settings()](../../functions/get_block_editor_settings) wp-includes/block-editor.php | Returns the contextualized block editor settings for a selected editor context. | | [wp\_default\_styles()](../../functions/wp_default_styles) wp-includes/script-loader.php | Assigns default styles to $styles object. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added a check in the parent theme. | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::extract_paths_to_translate( array $i18n_partial, array $current_path = array() ): array WP\_Theme\_JSON\_Resolver::extract\_paths\_to\_translate( array $i18n\_partial, array $current\_path = array() ): array ======================================================================================================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Converts a tree as in i18n-theme.json into a linear array containing metadata to translate a theme.json file. For example, given this input: ``` { "settings": { "*": { "typography": { "fontSizes": [ { "name": "Font size name" } ], "fontStyles": [ { "name": "Font size name" } ] } } } } ``` will return this output: ``` [ 0 => [ 'path' => [ 'settings', '*', 'typography', 'fontSizes' ], 'key' => 'name', 'context' => 'Font size name' ], 1 => [ 'path' => [ 'settings', '*', 'typography', 'fontStyles' ], 'key' => 'name', 'context' => 'Font style name' ] ] ``` `$i18n_partial` array Required A tree that follows the format of i18n-theme.json. `$current_path` array Optional Keeps track of the path as we walk down the given tree. Default: `array()` array A linear array containing the paths to translate. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` if ( is_array( $decoded_file ) ) { static::$theme_json_file_cache[ $file_path ] = $decoded_file; return static::$theme_json_file_cache[ $file_path ]; } } return array(); } /** * Returns a data structure used in theme.json translation. * * @since 5.8.0 * @deprecated 5.9.0 * * @return array An array of theme.json fields that are translatable and the keys that are translatable. */ public static function get_fields_to_translate() { _deprecated_function( __METHOD__, '5.9.0' ); return array(); ``` | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::get_user_data(): WP_Theme_JSON WP\_Theme\_JSON\_Resolver::get\_user\_data(): WP\_Theme\_JSON ============================================================= Returns the user’s origin config. [WP\_Theme\_JSON](../wp_theme_json) Entity that holds styles for user data. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function get_user_data() { if ( null !== static::$user && static::has_same_registered_blocks( 'user' ) ) { return static::$user; } $config = array(); $user_cpt = static::get_user_data_from_wp_global_styles( wp_get_theme() ); if ( array_key_exists( 'post_content', $user_cpt ) ) { $decoded_data = json_decode( $user_cpt['post_content'], true ); $json_decoding_error = json_last_error(); if ( JSON_ERROR_NONE !== $json_decoding_error ) { trigger_error( 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() ); /** * Filters the data provided by the user for global styles & settings. * * @since 6.1.0 * * @param WP_Theme_JSON_Data Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); $config = $theme_json->get_data(); return new WP_Theme_JSON( $config, 'custom' ); } // Very important to verify that the flag isGlobalStylesUserThemeJSON is true. // If it's not true then the content was not escaped and is not safe. if ( is_array( $decoded_data ) && isset( $decoded_data['isGlobalStylesUserThemeJSON'] ) && $decoded_data['isGlobalStylesUserThemeJSON'] ) { unset( $decoded_data['isGlobalStylesUserThemeJSON'] ); $config = $decoded_data; } } /** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); $config = $theme_json->get_data(); static::$user = new WP_Theme_JSON( $config, 'custom' ); return static::$user; } ``` [apply\_filters( 'wp\_theme\_json\_data\_user', WP\_Theme\_JSON\_Data )](../../hooks/wp_theme_json_data_user) Filters the data provided by the user for global styles & settings. | Uses | Description | | --- | --- | | [WP\_Theme\_JSON\_Data::\_\_construct()](../wp_theme_json_data/__construct) wp-includes/class-wp-theme-json-data.php | Constructor. | | [WP\_Theme\_JSON::\_\_construct()](../wp_theme_json/__construct) wp-includes/class-wp-theme-json.php | Constructor. | | [wp\_get\_theme()](../../functions/wp_get_theme) wp-includes/theme.php | Gets a [WP\_Theme](../wp_theme) object for a theme. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [wp\_generate\_block\_templates\_export\_file()](../../functions/wp_generate_block_templates_export_file) wp-includes/block-template-utils.php | Creates an export of the current templates and template parts from the site editor at the specified path in a ZIP file. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::get_block_data(): WP_Theme_JSON WP\_Theme\_JSON\_Resolver::get\_block\_data(): WP\_Theme\_JSON ============================================================== Gets the styles for blocks from the block.json file. [WP\_Theme\_JSON](../wp_theme_json) File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` public static function get_block_data() { $registry = WP_Block_Type_Registry::get_instance(); $blocks = $registry->get_all_registered(); if ( null !== static::$blocks && static::has_same_registered_blocks( 'blocks' ) ) { return static::$blocks; } $config = array( 'version' => 2 ); foreach ( $blocks as $block_name => $block_type ) { if ( isset( $block_type->supports['__experimentalStyle'] ) ) { $config['styles']['blocks'][ $block_name ] = static::remove_json_comments( $block_type->supports['__experimentalStyle'] ); } if ( isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ) && null === _wp_array_get( $config, array( 'styles', 'blocks', $block_name, 'spacing', 'blockGap' ), null ) ) { // Ensure an empty placeholder value exists for the block, if it provides a default blockGap value. // The real blockGap value to be used will be determined when the styles are rendered for output. $config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] = null; } } /** * Filters the data provided by the blocks for global styles & settings. * * @since 6.1.0 * * @param WP_Theme_JSON_Data Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) ); $config = $theme_json->get_data(); static::$blocks = new WP_Theme_JSON( $config, 'blocks' ); return static::$blocks; } ``` [apply\_filters( 'wp\_theme\_json\_data\_blocks', WP\_Theme\_JSON\_Data )](../../hooks/wp_theme_json_data_blocks) Filters the data provided by the blocks for global styles & settings. | Uses | Description | | --- | --- | | [WP\_Theme\_JSON\_Data::\_\_construct()](../wp_theme_json_data/__construct) wp-includes/class-wp-theme-json-data.php | Constructor. | | [WP\_Theme\_JSON::\_\_construct()](../wp_theme_json/__construct) wp-includes/class-wp-theme-json.php | Constructor. | | [\_wp\_array\_get()](../../functions/_wp_array_get) wp-includes/functions.php | Accesses an array in depth based on a path of keys. | | [WP\_Block\_Type\_Registry::get\_instance()](../wp_block_type_registry/get_instance) wp-includes/class-wp-block-type-registry.php | Utility method to retrieve the main instance of the class. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | Introduced. | wordpress WP_Theme_JSON_Resolver::translate( array $theme_json, string $domain = 'default' ): array WP\_Theme\_JSON\_Resolver::translate( array $theme\_json, string $domain = 'default' ): array ============================================================================================= Given a theme.json structure modifies it in place to update certain values by its translated strings according to the language set by the user. `$theme_json` array Required The theme.json to translate. `$domain` string Optional Text domain. Unique identifier for retrieving translated strings. Default `'default'`. Default: `'default'` array Returns the modified $theme\_json\_structure. File: `wp-includes/class-wp-theme-json-resolver.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json-resolver.php/) ``` protected static function translate( $theme_json, $domain = 'default' ) { if ( null === static::$i18n_schema ) { $i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' ); static::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema; } return translate_settings_using_i18n_schema( static::$i18n_schema, $theme_json, $domain ); } ``` | Uses | Description | | --- | --- | | [translate\_settings\_using\_i18n\_schema()](../../functions/translate_settings_using_i18n_schema) wp-includes/l10n.php | Translates the provided settings value using its i18n schema. | | [wp\_json\_file\_decode()](../../functions/wp_json_file_decode) wp-includes/functions.php | Reads and decodes a JSON file. | | Version | Description | | --- | --- | | [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::build_cache_key_for_url( string $url ): string WP\_REST\_URL\_Details\_Controller::build\_cache\_key\_for\_url( string $url ): string ====================================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Utility function to build cache key for a given URL. `$url` string Required The URL for which to build a cache key. string The cache key. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function build_cache_key_for_url( $url ) { return 'g_url_details_response_' . md5( $url ); } ``` | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |
programming_docs
wordpress WP_REST_URL_Details_Controller::get_meta_with_content_elements( string $html ): array WP\_REST\_URL\_Details\_Controller::get\_meta\_with\_content\_elements( string $html ): array ============================================================================================= This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Gets all the meta tag elements that have a ‘content’ attribute. `$html` string Required The string of HTML to be parsed. array A multi-dimensional indexed array on success, else empty array. * string[]Meta elements with a content attribute. * `1`string[]Content attribute's opening quotation mark. * `2`string[]Content attribute's value for each meta element. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function get_meta_with_content_elements( $html ) { /* * Parse all meta elements with a content attribute. * * Why first search for the content attribute rather than directly searching for name=description element? * tl;dr The content attribute's value will be truncated when it contains a > symbol. * * The content attribute's value (i.e. the description to get) can have HTML in it and be well-formed as * it's a string to the browser. Imagine what happens when attempting to match for the name=description * first. Hmm, if a > or /> symbol is in the content attribute's value, then it terminates the match * as the element's closing symbol. But wait, it's in the content attribute and is not the end of the * element. This is a limitation of using regex. It can't determine "wait a minute this is inside of quotation". * If this happens, what gets matched is not the entire element or all of the content. * * Why not search for the name=description and then content="(.*)"? * The attribute order could be opposite. Plus, additional attributes may exist including being between * the name and content attributes. * * Why not lookahead? * Lookahead is not constrained to stay within the element. The first <meta it finds may not include * the name or content, but rather could be from a different element downstream. */ $pattern = '#<meta\s' . /* * Allows for additional attributes before the content attribute. * Searches for anything other than > symbol. */ '[^>]*' . /* * Find the content attribute. When found, capture its value (.*). * * Allows for (a) single or double quotes and (b) whitespace in the value. * * Why capture the opening quotation mark, i.e. (["\']), and then backreference, * i.e \1, for the closing quotation mark? * To ensure the closing quotation mark matches the opening one. Why? Attribute values * can contain quotation marks, such as an apostrophe in the content. */ 'content=(["\']??)(.*)\1' . /* * Allows for additional attributes after the content attribute. * Searches for anything other than > symbol. */ '[^>]*' . /* * \/?> searches for the closing > symbol, which can be in either /> or > format. * # ends the pattern. */ '\/?>#' . /* * These are the options: * - i : case insensitive * - s : allows newline characters for the . match (needed for multiline elements) * - U means non-greedy matching */ 'isU'; preg_match_all( $pattern, $html, $elements ); return $elements; } ``` | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::get_document_head( string $html ): string WP\_REST\_URL\_Details\_Controller::get\_document\_head( string $html ): string =============================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Retrieves the head element section. `$html` string Required The string of HTML to parse. string The `<head>..</head>` section on success. Given `$html` if not found. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function get_document_head( $html ) { $head_html = $html; // Find the opening `<head>` tag. $head_start = strpos( $html, '<head' ); if ( false === $head_start ) { // Didn't find it. Return the original HTML. return $html; } // Find the closing `</head>` tag. $head_end = strpos( $head_html, '</head>' ); if ( false === $head_end ) { // Didn't find it. Find the opening `<body>` tag. $head_end = strpos( $head_html, '<body' ); // Didn't find it. Return the original HTML. if ( false === $head_end ) { return $html; } } // Extract the HTML from opening tag to the closing tag. Then add the closing tag. $head_html = substr( $head_html, $head_start, $head_end ); $head_html .= '</head>'; return $head_html; } ``` | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::get_remote_url( string $url ): string|WP_Error WP\_REST\_URL\_Details\_Controller::get\_remote\_url( string $url ): string|WP\_Error ===================================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Retrieves the document title from a remote URL. `$url` string Required The website URL whose HTML to access. string|[WP\_Error](../wp_error) The HTTP response from the remote URL on success. [WP\_Error](../wp_error) if no response or no content. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function get_remote_url( $url ) { /* * Provide a modified UA string to workaround web properties which block WordPress "Pingbacks". * Why? The UA string used for pingback requests contains `WordPress/` which is very similar * to that used as the default UA string by the WP HTTP API. Therefore requests from this * REST endpoint are being unintentionally blocked as they are misidentified as pingback requests. * By slightly modifying the UA string, but still retaining the "WordPress" identification (via "WP") * we are able to work around this issue. * Example UA string: `WP-URLDetails/5.9-alpha-51389 (+http://localhost:8888)`. */ $modified_user_agent = 'WP-URLDetails/' . get_bloginfo( 'version' ) . ' (+' . get_bloginfo( 'url' ) . ')'; $args = array( 'limit_response_size' => 150 * KB_IN_BYTES, 'user-agent' => $modified_user_agent, ); /** * Filters the HTTP request args for URL data retrieval. * * Can be used to adjust response size limit and other WP_Http::request() args. * * @since 5.9.0 * * @param array $args Arguments used for the HTTP request. * @param string $url The attempted URL. */ $args = apply_filters( 'rest_url_details_http_request_args', $args, $url ); $response = wp_safe_remote_get( $url, $args ); if ( WP_Http::OK !== wp_remote_retrieve_response_code( $response ) ) { // Not saving the error response to cache since the error might be temporary. return new WP_Error( 'no_response', __( 'URL not found. Response returned a non-200 status code for this URL.' ), array( 'status' => WP_Http::NOT_FOUND ) ); } $remote_body = wp_remote_retrieve_body( $response ); if ( empty( $remote_body ) ) { return new WP_Error( 'no_content', __( 'Unable to retrieve body from response at this URL.' ), array( 'status' => WP_Http::NOT_FOUND ) ); } return $remote_body; } ``` [apply\_filters( 'rest\_url\_details\_http\_request\_args', array $args, string $url )](../../hooks/rest_url_details_http_request_args) Filters the HTTP request args for URL data retrieval. | Uses | Description | | --- | --- | | [wp\_safe\_remote\_get()](../../functions/wp_safe_remote_get) wp-includes/http.php | Retrieve the raw response from a safe HTTP request using the GET method. | | [wp\_remote\_retrieve\_response\_code()](../../functions/wp_remote_retrieve_response_code) wp-includes/http.php | Retrieve only the response code from the raw response. | | [wp\_remote\_retrieve\_body()](../../functions/wp_remote_retrieve_body) wp-includes/http.php | Retrieve only the body from the raw response. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::set_cache( string $key, string $data = '' ): bool WP\_REST\_URL\_Details\_Controller::set\_cache( string $key, string $data = '' ): bool ====================================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Utility function to cache a given data set at a given cache key. `$key` string Required The cache key under which to store the value. `$data` string Optional The data to be stored at the given cache key. Default: `''` bool True when transient set. False if not set. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function set_cache( $key, $data = '' ) { $ttl = HOUR_IN_SECONDS; /** * Filters the cache expiration. * * Can be used to adjust the time until expiration in seconds for the cache * of the data retrieved for the given URL. * * @since 5.9.0 * * @param int $ttl The time until cache expiration in seconds. */ $cache_expiration = apply_filters( 'rest_url_details_cache_expiration', $ttl ); return set_site_transient( $key, $data, $cache_expiration ); } ``` [apply\_filters( 'rest\_url\_details\_cache\_expiration', int $ttl )](../../hooks/rest_url_details_cache_expiration) Filters the cache expiration. | Uses | Description | | --- | --- | | [set\_site\_transient()](../../functions/set_site_transient) wp-includes/option.php | Sets/updates the value of a site transient. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::prepare_metadata_for_output( string $metadata ): string WP\_REST\_URL\_Details\_Controller::prepare\_metadata\_for\_output( string $metadata ): string ============================================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Prepares the metadata by: – stripping all HTML tags and tag entities. * converting non-tag entities into characters. `$metadata` string Required The metadata content to prepare. string The prepared metadata. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function prepare_metadata_for_output( $metadata ) { $metadata = html_entity_decode( $metadata, ENT_QUOTES, get_bloginfo( 'charset' ) ); $metadata = wp_strip_all_tags( $metadata ); return $metadata; } ``` | Uses | Description | | --- | --- | | [wp\_strip\_all\_tags()](../../functions/wp_strip_all_tags) wp-includes/formatting.php | Properly strips all HTML tags including script and style | | [get\_bloginfo()](../../functions/get_bloginfo) wp-includes/general-template.php | Retrieves information about the current site. | | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::get\_title()](get_title) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Parses the title tag contents from the provided HTML. | | [WP\_REST\_URL\_Details\_Controller::get\_description()](get_description) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Parses the meta description from the provided HTML. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::get_icon( string $html, string $url ): string WP\_REST\_URL\_Details\_Controller::get\_icon( string $html, string $url ): string ================================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Parses the site icon from the provided HTML. `$html` string Required The HTML from the remote website at URL. `$url` string Required The target website URL. string The icon URI on success. Empty string if not found. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function get_icon( $html, $url ) { // Grab the icon's link element. $pattern = '#<link\s[^>]*rel=(?:[\"\']??)\s*(?:icon|shortcut icon|icon shortcut)\s*(?:[\"\']??)[^>]*\/?>#isU'; preg_match( $pattern, $html, $element ); if ( empty( $element[0] ) || ! is_string( $element[0] ) ) { return ''; } $element = trim( $element[0] ); // Get the icon's href value. $pattern = '#href=([\"\']??)([^\" >]*?)\\1[^>]*#isU'; preg_match( $pattern, $element, $icon ); if ( empty( $icon[2] ) || ! is_string( $icon[2] ) ) { return ''; } $icon = trim( $icon[2] ); // If the icon is a data URL, return it. $parsed_icon = parse_url( $icon ); if ( isset( $parsed_icon['scheme'] ) && 'data' === $parsed_icon['scheme'] ) { return $icon; } // Attempt to convert relative URLs to absolute. if ( ! is_string( $url ) || '' === $url ) { return $icon; } $parsed_url = parse_url( $url ); if ( isset( $parsed_url['scheme'] ) && isset( $parsed_url['host'] ) ) { $root_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/'; $icon = WP_Http::make_absolute_url( $icon, $root_url ); } return $icon; } ``` | Uses | Description | | --- | --- | | [WP\_Http::make\_absolute\_url()](../wp_http/make_absolute_url) wp-includes/class-wp-http.php | Converts a relative URL to an absolute URL relative to a given URL. | | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::get_description( array $meta_elements ): string WP\_REST\_URL\_Details\_Controller::get\_description( array $meta\_elements ): string ===================================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Parses the meta description from the provided HTML. `$meta_elements` array Required A multi-dimensional indexed array on success, else empty array. * string[]Meta elements with a content attribute. * `1`string[]Content attribute's opening quotation mark. * `2`string[]Content attribute's value for each meta element. string The meta description contents on success. Empty string if not found. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function get_description( $meta_elements ) { // Bail out if there are no meta elements. if ( empty( $meta_elements[0] ) ) { return ''; } $description = $this->get_metadata_from_meta_element( $meta_elements, 'name', '(?:description|og:description)' ); // Bail out if description not found. if ( '' === $description ) { return ''; } return $this->prepare_metadata_for_output( $description ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::get\_metadata\_from\_meta\_element()](get_metadata_from_meta_element) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Gets the metadata from a target meta element. | | [WP\_REST\_URL\_Details\_Controller::prepare\_metadata\_for\_output()](prepare_metadata_for_output) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Prepares the metadata by: – stripping all HTML tags and tag entities. | | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |
programming_docs
wordpress WP_REST_URL_Details_Controller::register_routes() WP\_REST\_URL\_Details\_Controller::register\_routes() ====================================================== Registers the necessary REST API routes. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'parse_url_details' ), 'args' => array( 'url' => array( 'required' => true, 'description' => __( 'The URL to process.' ), 'validate_callback' => 'wp_http_validate_url', 'sanitize_callback' => 'sanitize_url', 'type' => 'string', 'format' => 'uri', ), ), 'permission_callback' => array( $this, 'permissions_check' ), 'schema' => array( $this, 'get_public_item_schema' ), ), ) ); } ``` | Uses | Description | | --- | --- | | [register\_rest\_route()](../../functions/register_rest_route) wp-includes/rest-api.php | Registers a REST API route. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::get_image( array $meta_elements, string $url ): string WP\_REST\_URL\_Details\_Controller::get\_image( array $meta\_elements, string $url ): string ============================================================================================ This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Parses the Open Graph (OG) Image from the provided HTML. See: <https://ogp.me/>. `$meta_elements` array Required A multi-dimensional indexed array on success, else empty array. * string[]Meta elements with a content attribute. * `1`string[]Content attribute's opening quotation mark. * `2`string[]Content attribute's value for each meta element. `$url` string Required The target website URL. string The OG image on success. Empty string if not found. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function get_image( $meta_elements, $url ) { $image = $this->get_metadata_from_meta_element( $meta_elements, 'property', '(?:og:image|og:image:url)' ); // Bail out if image not found. if ( '' === $image ) { return ''; } // Attempt to convert relative URLs to absolute. $parsed_url = parse_url( $url ); if ( isset( $parsed_url['scheme'] ) && isset( $parsed_url['host'] ) ) { $root_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/'; $image = WP_Http::make_absolute_url( $image, $root_url ); } return $image; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::get\_metadata\_from\_meta\_element()](get_metadata_from_meta_element) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Gets the metadata from a target meta element. | | [WP\_Http::make\_absolute\_url()](../wp_http/make_absolute_url) wp-includes/class-wp-http.php | Converts a relative URL to an absolute URL relative to a given URL. | | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::__construct() WP\_REST\_URL\_Details\_Controller::\_\_construct() =================================================== Constructs the controller. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` public function __construct() { $this->namespace = 'wp-block-editor/v1'; $this->rest_base = 'url-details'; } ``` | Used By | Description | | --- | --- | | [create\_initial\_rest\_routes()](../../functions/create_initial_rest_routes) wp-includes/rest-api.php | Registers default REST API routes. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::get_cache( string $key ): mixed WP\_REST\_URL\_Details\_Controller::get\_cache( string $key ): mixed ==================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Utility function to retrieve a value from the cache at a given key. `$key` string Required The cache key. mixed The value from the cache. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function get_cache( $key ) { return get_site_transient( $key ); } ``` | Uses | Description | | --- | --- | | [get\_site\_transient()](../../functions/get_site_transient) wp-includes/option.php | Retrieves the value of a site transient. | | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::get_metadata_from_meta_element( array $meta_elements, string $attr, string $attr_value ): string WP\_REST\_URL\_Details\_Controller::get\_metadata\_from\_meta\_element( array $meta\_elements, string $attr, string $attr\_value ): string ========================================================================================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Gets the metadata from a target meta element. `$meta_elements` array Required A multi-dimensional indexed array on success, else empty array. * string[]Meta elements with a content attribute. * `1`string[]Content attribute's opening quotation mark. * `2`string[]Content attribute's value for each meta element. `$attr` string Required Attribute that identifies the element with the target metadata. `$attr_value` string Required The attribute's value that identifies the element with the target metadata. string The metadata on success. Empty string if not found. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function get_metadata_from_meta_element( $meta_elements, $attr, $attr_value ) { // Bail out if there are no meta elements. if ( empty( $meta_elements[0] ) ) { return ''; } $metadata = ''; $pattern = '#' . /* * Target this attribute and value to find the metadata element. * * Allows for (a) no, single, double quotes and (b) whitespace in the value. * * Why capture the opening quotation mark, i.e. (["\']), and then backreference, * i.e \1, for the closing quotation mark? * To ensure the closing quotation mark matches the opening one. Why? Attribute values * can contain quotation marks, such as an apostrophe in the content. */ $attr . '=([\"\']??)\s*' . $attr_value . '\s*\1' . /* * These are the options: * - i : case insensitive * - s : allows newline characters for the . match (needed for multiline elements) * - U means non-greedy matching */ '#isU'; // Find the metadata element. foreach ( $meta_elements[0] as $index => $element ) { preg_match( $pattern, $element, $match ); // This is not the metadata element. Skip it. if ( empty( $match ) ) { continue; } /* * Found the metadata element. * Get the metadata from its matching content array. */ if ( isset( $meta_elements[2][ $index ] ) && is_string( $meta_elements[2][ $index ] ) ) { $metadata = trim( $meta_elements[2][ $index ] ); } break; } return $metadata; } ``` | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::get\_description()](get_description) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Parses the meta description from the provided HTML. | | [WP\_REST\_URL\_Details\_Controller::get\_image()](get_image) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Parses the Open Graph (OG) Image from the provided HTML. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::permissions_check(): WP_Error|bool WP\_REST\_URL\_Details\_Controller::permissions\_check(): WP\_Error|bool ======================================================================== Checks whether a given request has permission to read remote URLs. [WP\_Error](../wp_error)|bool True if the request has permission, else [WP\_Error](../wp_error). File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` public function permissions_check() { if ( current_user_can( 'edit_posts' ) ) { return true; } foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) { if ( current_user_can( $post_type->cap->edit_posts ) ) { return true; } } return new WP_Error( 'rest_cannot_view_url_details', __( 'Sorry, you are not allowed to process remote URLs.' ), array( 'status' => rest_authorization_required_code() ) ); } ``` | Uses | Description | | --- | --- | | [rest\_authorization\_required\_code()](../../functions/rest_authorization_required_code) wp-includes/rest-api.php | Returns a contextual HTTP error code for authorization failure. | | [current\_user\_can()](../../functions/current_user_can) wp-includes/capabilities.php | Returns whether the current user has the specified capability. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [get\_post\_types()](../../functions/get_post_types) wp-includes/post.php | Gets a list of all registered post type objects. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::get_item_schema(): array WP\_REST\_URL\_Details\_Controller::get\_item\_schema(): array ============================================================== Retrieves the item’s schema, conforming to JSON Schema. array Item schema data. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $this->schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'url-details', 'type' => 'object', 'properties' => array( 'title' => array( 'description' => sprintf( /* translators: %s: HTML title tag. */ __( 'The contents of the %s element from the URL.' ), '<title>' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'icon' => array( 'description' => sprintf( /* translators: %s: HTML link tag. */ __( 'The favicon image link of the %s element from the URL.' ), '<link rel="icon">' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'description' => array( 'description' => sprintf( /* translators: %s: HTML meta tag. */ __( 'The content of the %s element from the URL.' ), '<meta name="description">' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'image' => array( 'description' => sprintf( /* translators: 1: HTML meta tag, 2: HTML meta tag. */ __( 'The Open Graph image link of the %1$s or %2$s element from the URL.' ), '<meta property="og:image">', '<meta property="og:image:url">' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), ), ); return $this->add_additional_fields_schema( $this->schema ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::get_title( string $html ): string WP\_REST\_URL\_Details\_Controller::get\_title( string $html ): string ====================================================================== This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Parses the title tag contents from the provided HTML. `$html` string Required The HTML from the remote website at URL. string The title tag contents on success. Empty string if not found. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` private function get_title( $html ) { $pattern = '#<title[^>]*>(.*?)<\s*/\s*title>#is'; preg_match( $pattern, $html, $match_title ); if ( empty( $match_title[1] ) || ! is_string( $match_title[1] ) ) { return ''; } $title = trim( $match_title[1] ); return $this->prepare_metadata_for_output( $title ); } ``` | Uses | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::prepare\_metadata\_for\_output()](prepare_metadata_for_output) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Prepares the metadata by: – stripping all HTML tags and tag entities. | | Used By | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::parse\_url\_details()](parse_url_details) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the contents of the title tag from the HTML response. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. | wordpress WP_REST_URL_Details_Controller::parse_url_details( WP_REST_REQUEST $request ): WP_REST_Response|WP_Error WP\_REST\_URL\_Details\_Controller::parse\_url\_details( WP\_REST\_REQUEST $request ): WP\_REST\_Response|WP\_Error =================================================================================================================== Retrieves the contents of the title tag from the HTML response. `$request` WP\_REST\_REQUEST Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) The parsed details as a response object. [WP\_Error](../wp_error) if there are errors. File: `wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php/) ``` public function parse_url_details( $request ) { $url = untrailingslashit( $request['url'] ); if ( empty( $url ) ) { return new WP_Error( 'rest_invalid_url', __( 'Invalid URL' ), array( 'status' => 404 ) ); } // Transient per URL. $cache_key = $this->build_cache_key_for_url( $url ); // Attempt to retrieve cached response. $cached_response = $this->get_cache( $cache_key ); if ( ! empty( $cached_response ) ) { $remote_url_response = $cached_response; } else { $remote_url_response = $this->get_remote_url( $url ); // Exit if we don't have a valid body or it's empty. if ( is_wp_error( $remote_url_response ) || empty( $remote_url_response ) ) { return $remote_url_response; } // Cache the valid response. $this->set_cache( $cache_key, $remote_url_response ); } $html_head = $this->get_document_head( $remote_url_response ); $meta_elements = $this->get_meta_with_content_elements( $html_head ); $data = $this->add_additional_fields_to_object( array( 'title' => $this->get_title( $html_head ), 'icon' => $this->get_icon( $html_head, $url ), 'description' => $this->get_description( $meta_elements ), 'image' => $this->get_image( $meta_elements, $url ), ), $request ); // Wrap the data in a response object. $response = rest_ensure_response( $data ); /** * Filters the URL data for the response. * * @since 5.9.0 * * @param WP_REST_Response $response The response object. * @param string $url The requested URL. * @param WP_REST_Request $request Request object. * @param string $remote_url_response HTTP response body from the remote URL. */ return apply_filters( 'rest_prepare_url_details', $response, $url, $request, $remote_url_response ); } ``` [apply\_filters( 'rest\_prepare\_url\_details', WP\_REST\_Response $response, string $url, WP\_REST\_Request $request, string $remote\_url\_response )](../../hooks/rest_prepare_url_details) Filters the URL data for the response. | Uses | Description | | --- | --- | | [WP\_REST\_URL\_Details\_Controller::build\_cache\_key\_for\_url()](build_cache_key_for_url) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Utility function to build cache key for a given URL. | | [WP\_REST\_URL\_Details\_Controller::get\_cache()](get_cache) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Utility function to retrieve a value from the cache at a given key. | | [WP\_REST\_URL\_Details\_Controller::set\_cache()](set_cache) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Utility function to cache a given data set at a given cache key. | | [WP\_REST\_URL\_Details\_Controller::get\_document\_head()](get_document_head) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the head element section. | | [WP\_REST\_URL\_Details\_Controller::get\_meta\_with\_content\_elements()](get_meta_with_content_elements) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Gets all the meta tag elements that have a ‘content’ attribute. | | [WP\_REST\_URL\_Details\_Controller::get\_title()](get_title) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Parses the title tag contents from the provided HTML. | | [WP\_REST\_URL\_Details\_Controller::get\_icon()](get_icon) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Parses the site icon from the provided HTML. | | [WP\_REST\_URL\_Details\_Controller::get\_description()](get_description) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Parses the meta description from the provided HTML. | | [WP\_REST\_URL\_Details\_Controller::get\_image()](get_image) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Parses the Open Graph (OG) Image from the provided HTML. | | [WP\_REST\_URL\_Details\_Controller::get\_remote\_url()](get_remote_url) wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Retrieves the document title from a remote URL. | | [untrailingslashit()](../../functions/untrailingslashit) wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. | | [rest\_ensure\_response()](../../functions/rest_ensure_response) wp-includes/rest-api.php | Ensures a REST response is a response object (for consistency). | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |
programming_docs
wordpress WP_Ajax_Upgrader_Skin::feedback( string|array|WP_Error $feedback, mixed $args ) WP\_Ajax\_Upgrader\_Skin::feedback( string|array|WP\_Error $feedback, mixed $args ) =================================================================================== Stores a message about the upgrade. `$feedback` string|array|[WP\_Error](../wp_error) Required Message data. `$args` mixed Optional text replacements. File: `wp-admin/includes/class-wp-ajax-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ajax-upgrader-skin.php/) ``` public function feedback( $feedback, ...$args ) { if ( is_wp_error( $feedback ) ) { foreach ( $feedback->get_error_codes() as $error_code ) { $this->errors->add( $error_code, $feedback->get_error_message( $error_code ), $feedback->get_error_data( $error_code ) ); } } parent::feedback( $feedback, ...$args ); } ``` | Uses | Description | | --- | --- | | [Automatic\_Upgrader\_Skin::feedback()](../automatic_upgrader_skin/feedback) wp-admin/includes/class-automatic-upgrader-skin.php | Stores a message about the upgrade. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$data` to `$feedback` for PHP 8 named parameter support. | | [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Formalized the existing `...$args` parameter by adding it to the function signature. | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Ajax_Upgrader_Skin::get_errors(): WP_Error WP\_Ajax\_Upgrader\_Skin::get\_errors(): WP\_Error ================================================== Retrieves the list of errors. [WP\_Error](../wp_error) Errors during an upgrade. File: `wp-admin/includes/class-wp-ajax-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ajax-upgrader-skin.php/) ``` public function get_errors() { return $this->errors; } ``` | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Ajax_Upgrader_Skin::get_error_messages(): string WP\_Ajax\_Upgrader\_Skin::get\_error\_messages(): string ======================================================== Retrieves a string for error messages. string Error messages during an upgrade. File: `wp-admin/includes/class-wp-ajax-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ajax-upgrader-skin.php/) ``` public function get_error_messages() { $messages = array(); foreach ( $this->errors->get_error_codes() as $error_code ) { $error_data = $this->errors->get_error_data( $error_code ); if ( $error_data && is_string( $error_data ) ) { $messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $error_data ) ); } else { $messages[] = $this->errors->get_error_message( $error_code ); } } return implode( ', ', $messages ); } ``` | Uses | Description | | --- | --- | | [esc\_html()](../../functions/esc_html) wp-includes/formatting.php | Escaping for HTML blocks. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Ajax_Upgrader_Skin::__construct( array $args = array() ) WP\_Ajax\_Upgrader\_Skin::\_\_construct( array $args = array() ) ================================================================ Constructor. Sets up the WordPress Ajax upgrader skin. * [WP\_Upgrader\_Skin::\_\_construct()](../wp_upgrader_skin/__construct) `$args` array Optional The WordPress Ajax upgrader skin arguments to override default options. See [WP\_Upgrader\_Skin::\_\_construct()](../wp_upgrader_skin/__construct). More Arguments from WP\_Upgrader\_Skin::\_\_construct( ... $args ) The WordPress upgrader skin arguments to override default options. Default: `array()` File: `wp-admin/includes/class-wp-ajax-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ajax-upgrader-skin.php/) ``` public function __construct( $args = array() ) { parent::__construct( $args ); $this->errors = new WP_Error(); } ``` | Uses | Description | | --- | --- | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Used By | Description | | --- | --- | | [WP\_REST\_Plugins\_Controller::create\_item()](../wp_rest_plugins_controller/create_item) wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php | Uploads a plugin and optionally activates it. | | [wp\_ajax\_install\_theme()](../../functions/wp_ajax_install_theme) wp-admin/includes/ajax-actions.php | Ajax handler for installing a theme. | | [wp\_ajax\_update\_theme()](../../functions/wp_ajax_update_theme) wp-admin/includes/ajax-actions.php | Ajax handler for updating a theme. | | [wp\_ajax\_install\_plugin()](../../functions/wp_ajax_install_plugin) wp-admin/includes/ajax-actions.php | Ajax handler for installing a plugin. | | [wp\_ajax\_update\_plugin()](../../functions/wp_ajax_update_plugin) wp-admin/includes/ajax-actions.php | Ajax handler for updating a plugin. | | Version | Description | | --- | --- | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Ajax_Upgrader_Skin::error( string|WP_Error $errors, mixed $args ) WP\_Ajax\_Upgrader\_Skin::error( string|WP\_Error $errors, mixed $args ) ======================================================================== Stores an error message about the upgrade. `$errors` string|[WP\_Error](../wp_error) Required Errors. `$args` mixed Optional text replacements. File: `wp-admin/includes/class-wp-ajax-upgrader-skin.php`. [View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-ajax-upgrader-skin.php/) ``` public function error( $errors, ...$args ) { if ( is_string( $errors ) ) { $string = $errors; if ( ! empty( $this->upgrader->strings[ $string ] ) ) { $string = $this->upgrader->strings[ $string ]; } if ( false !== strpos( $string, '%' ) ) { if ( ! empty( $args ) ) { $string = vsprintf( $string, $args ); } } // Count existing errors to generate a unique error code. $errors_count = count( $this->errors->get_error_codes() ); $this->errors->add( 'unknown_upgrade_error_' . ( $errors_count + 1 ), $string ); } elseif ( is_wp_error( $errors ) ) { foreach ( $errors->get_error_codes() as $error_code ) { $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) ); } } parent::error( $errors, ...$args ); } ``` | Uses | Description | | --- | --- | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [5.3.0](https://developer.wordpress.org/reference/since/5.3.0/) | Formalized the existing `...$args` parameter by adding it to the function signature. | | [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Introduced. | wordpress WP_Widget_Pages::form( array $instance ) WP\_Widget\_Pages::form( array $instance ) ========================================== Outputs the settings form for the Pages widget. `$instance` array Required Current settings. File: `wp-includes/widgets/class-wp-widget-pages.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-pages.php/) ``` public function form( $instance ) { // Defaults. $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '', ) ); ?> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label> <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php _e( 'Sort by:' ); ?></label> <select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat"> <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e( 'Page title' ); ?></option> <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e( 'Page order' ); ?></option> <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option> </select> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php _e( 'Exclude:' ); ?></label> <input type="text" value="<?php echo esc_attr( $instance['exclude'] ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'exclude' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>" class="widefat" /> <br /> <small><?php _e( 'Page IDs, separated by commas.' ); ?></small> </p> <?php } ``` | Uses | Description | | --- | --- | | [selected()](../../functions/selected) wp-includes/general-template.php | Outputs the HTML selected attribute. | | [\_e()](../../functions/_e) wp-includes/l10n.php | Displays translated text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Pages::update( array $new_instance, array $old_instance ): array WP\_Widget\_Pages::update( array $new\_instance, array $old\_instance ): array ============================================================================== Handles updating settings for the current Pages widget instance. `$new_instance` array Required New settings for this instance as input by the user via [WP\_Widget::form()](../wp_widget/form). `$old_instance` array Required Old settings for this instance. array Updated settings to save. File: `wp-includes/widgets/class-wp-widget-pages.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-pages.php/) ``` public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = sanitize_text_field( $new_instance['title'] ); if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ), true ) ) { $instance['sortby'] = $new_instance['sortby']; } else { $instance['sortby'] = 'menu_order'; } $instance['exclude'] = sanitize_text_field( $new_instance['exclude'] ); return $instance; } ``` | Uses | Description | | --- | --- | | [sanitize\_text\_field()](../../functions/sanitize_text_field) wp-includes/formatting.php | Sanitizes a string from user input or from the database. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Pages::__construct() WP\_Widget\_Pages::\_\_construct() ================================== Sets up a new Pages widget instance. File: `wp-includes/widgets/class-wp-widget-pages.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-pages.php/) ``` public function __construct() { $widget_ops = array( 'classname' => 'widget_pages', 'description' => __( 'A list of your site&#8217;s Pages.' ), 'customize_selective_refresh' => true, 'show_instance_in_rest' => true, ); parent::__construct( 'pages', __( 'Pages' ), $widget_ops ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget::\_\_construct()](../wp_widget/__construct) wp-includes/class-wp-widget.php | PHP5 constructor. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget_Pages::widget( array $args, array $instance ) WP\_Widget\_Pages::widget( array $args, array $instance ) ========================================================= Outputs the content for the current Pages widget instance. `$args` array Required Display arguments including `'before_title'`, `'after_title'`, `'before_widget'`, and `'after_widget'`. `$instance` array Required Settings for the current Pages widget instance. File: `wp-includes/widgets/class-wp-widget-pages.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/widgets/class-wp-widget-pages.php/) ``` public function widget( $args, $instance ) { $default_title = __( 'Pages' ); $title = ! empty( $instance['title'] ) ? $instance['title'] : $default_title; /** * Filters the widget title. * * @since 2.6.0 * * @param string $title The widget title. Default 'Pages'. * @param array $instance Array of settings for the current widget. * @param mixed $id_base The widget ID. */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; if ( 'menu_order' === $sortby ) { $sortby = 'menu_order, post_title'; } $output = wp_list_pages( /** * Filters the arguments for the Pages widget. * * @since 2.8.0 * @since 4.9.0 Added the `$instance` parameter. * * @see wp_list_pages() * * @param array $args An array of arguments to retrieve the pages list. * @param array $instance Array of settings for the current widget. */ apply_filters( 'widget_pages_args', array( 'title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude, ), $instance ) ); if ( ! empty( $output ) ) { echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml'; /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */ $format = apply_filters( 'navigation_widgets_format', $format ); if ( 'html5' === $format ) { // The title may be filtered: Strip out HTML and make sure the aria-label is never empty. $title = trim( strip_tags( $title ) ); $aria_label = $title ? $title : $default_title; echo '<nav aria-label="' . esc_attr( $aria_label ) . '">'; } ?> <ul> <?php echo $output; ?> </ul> <?php if ( 'html5' === $format ) { echo '</nav>'; } echo $args['after_widget']; } } ``` [apply\_filters( 'navigation\_widgets\_format', string $format )](../../hooks/navigation_widgets_format) Filters the HTML format of widgets with navigation links. [apply\_filters( 'widget\_pages\_args', array $args, array $instance )](../../hooks/widget_pages_args) Filters the arguments for the Pages widget. [apply\_filters( 'widget\_title', string $title, array $instance, mixed $id\_base )](../../hooks/widget_title) Filters the widget title. | Uses | Description | | --- | --- | | [wp\_list\_pages()](../../functions/wp_list_pages) wp-includes/post-template.php | Retrieves or displays a list of pages (or hierarchical post type items) in list (li) format. | | [current\_theme\_supports()](../../functions/current_theme_supports) wp-includes/theme.php | Checks a theme’s support for a given feature. | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [esc\_attr()](../../functions/esc_attr) wp-includes/formatting.php | Escaping for HTML attributes. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::_register() WP\_Widget::\_register() ======================== Register all widget instances of this widget class. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function _register() { $settings = $this->get_settings(); $empty = true; // When $settings is an array-like object, get an intrinsic array for use with array_keys(). if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) { $settings = $settings->getArrayCopy(); } if ( is_array( $settings ) ) { foreach ( array_keys( $settings ) as $number ) { if ( is_numeric( $number ) ) { $this->_set( $number ); $this->_register_one( $number ); $empty = false; } } } if ( $empty ) { // If there are none, we register the widget's existence with a generic template. $this->_set( 1 ); $this->_register_one(); } } ``` | Uses | Description | | --- | --- | | [WP\_Widget::get\_settings()](get_settings) wp-includes/class-wp-widget.php | Retrieves the settings for all instances of the widget class. | | [WP\_Widget::\_register\_one()](_register_one) wp-includes/class-wp-widget.php | Registers an instance of the widget class. | | [WP\_Widget::\_set()](_set) wp-includes/class-wp-widget.php | Sets the internal order number for the widget instance. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::save_settings( array $settings ) WP\_Widget::save\_settings( array $settings ) ============================================= Saves the settings for all instances of the widget class. `$settings` array Required Multi-dimensional array of widget instance settings. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function save_settings( $settings ) { $settings['_multiwidget'] = 1; update_option( $this->option_name, $settings ); } ``` | Uses | Description | | --- | --- | | [update\_option()](../../functions/update_option) wp-includes/option.php | Updates the value of an option that was already added. | | Used By | Description | | --- | --- | | [WP\_Widget::update\_callback()](update_callback) wp-includes/class-wp-widget.php | Handles changed settings (Do NOT override). | | [WP\_Widget::get\_settings()](get_settings) wp-includes/class-wp-widget.php | Retrieves the settings for all instances of the widget class. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::is_preview(): bool WP\_Widget::is\_preview(): bool =============================== Determines whether the current request is inside the Customizer preview. If true — the current request is inside the Customizer preview, then the object cache gets suspended and widgets should check this to decide whether they should store anything persistently to the object cache, to transients, or anywhere else. bool True if within the Customizer preview, false if not. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function is_preview() { global $wp_customize; return ( isset( $wp_customize ) && $wp_customize->is_preview() ); } ``` | Used By | Description | | --- | --- | | [WP\_Widget::display\_callback()](display_callback) wp-includes/class-wp-widget.php | Generates the actual widget content (Do NOT override). | | [WP\_Widget::update\_callback()](update_callback) wp-includes/class-wp-widget.php | Handles changed settings (Do NOT override). | | Version | Description | | --- | --- | | [3.9.0](https://developer.wordpress.org/reference/since/3.9.0/) | Introduced. |
programming_docs
wordpress WP_Widget::form( array $instance ): string WP\_Widget::form( array $instance ): string =========================================== Outputs the settings update form. `$instance` array Required Current settings. string Default return is `'noform'`. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function form( $instance ) { echo '<p class="no-options-widget">' . __( 'There are no options for this widget.' ) . '</p>'; return 'noform'; } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | Used By | Description | | --- | --- | | [WP\_Widget::form\_callback()](form_callback) wp-includes/class-wp-widget.php | Generates the widget control form (Do NOT override). | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::update( array $new_instance, array $old_instance ): array WP\_Widget::update( array $new\_instance, array $old\_instance ): array ======================================================================= Updates a particular instance of a widget. This function should check that `$new_instance` is set correctly. The newly-calculated value of `$instance` should be returned. If false is returned, the instance won’t be saved/updated. `$new_instance` array Required New settings for this instance as input by the user via [WP\_Widget::form()](form). `$old_instance` array Required Old settings for this instance. array Settings to save or bool false to cancel saving. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function update( $new_instance, $old_instance ) { return $new_instance; } ``` | Used By | Description | | --- | --- | | [WP\_Widget::update\_callback()](update_callback) wp-includes/class-wp-widget.php | Handles changed settings (Do NOT override). | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::WP_Widget( string $id_base, string $name, array $widget_options = array(), array $control_options = array() ) WP\_Widget::WP\_Widget( string $id\_base, string $name, array $widget\_options = array(), array $control\_options = array() ) ============================================================================================================================= This method has been deprecated. Use [WP\_Widget::\_\_construct()](../wp_widget/__construct) instead. PHP4 constructor. * [WP\_Widget::\_\_construct()](../wp_widget/__construct) `$id_base` string Optional Base ID for the widget, lowercase and unique. If left empty, a portion of the widget's PHP class name will be used. Has to be unique. `$name` string Optional Name for the widget displayed on the configuration page. `$widget_options` array Optional Widget options. See [wp\_register\_sidebar\_widget()](../../functions/wp_register_sidebar_widget) for information on accepted arguments. Default: `array()` `$control_options` array Optional Widget control options. See [wp\_register\_widget\_control()](../../functions/wp_register_widget_control) for information on accepted arguments. Default: `array()` File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) { _deprecated_constructor( 'WP_Widget', '4.3.0', get_class( $this ) ); WP_Widget::__construct( $id_base, $name, $widget_options, $control_options ); } ``` | Uses | Description | | --- | --- | | [\_deprecated\_constructor()](../../functions/_deprecated_constructor) wp-includes/functions.php | Marks a constructor as deprecated and informs when it has been used. | | [WP\_Widget::\_\_construct()](__construct) wp-includes/class-wp-widget.php | PHP5 constructor. | | Version | Description | | --- | --- | | [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Use \_\_construct() instead. | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::_get_form_callback(): callable WP\_Widget::\_get\_form\_callback(): callable ============================================= Retrieves the form callback. callable Form callback. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function _get_form_callback() { return array( $this, 'form_callback' ); } ``` | Used By | Description | | --- | --- | | [WP\_Widget::\_register\_one()](_register_one) wp-includes/class-wp-widget.php | Registers an instance of the widget class. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::_get_update_callback(): callable WP\_Widget::\_get\_update\_callback(): callable =============================================== Retrieves the widget update callback. callable Update callback. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function _get_update_callback() { return array( $this, 'update_callback' ); } ``` | Used By | Description | | --- | --- | | [WP\_Widget::\_register\_one()](_register_one) wp-includes/class-wp-widget.php | Registers an instance of the widget class. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::_get_display_callback(): callable WP\_Widget::\_get\_display\_callback(): callable ================================================ Retrieves the widget display callback. callable Display callback. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function _get_display_callback() { return array( $this, 'display_callback' ); } ``` | Used By | Description | | --- | --- | | [WP\_Widget::\_register\_one()](_register_one) wp-includes/class-wp-widget.php | Registers an instance of the widget class. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::display_callback( array $args, int|array $widget_args = 1 ) WP\_Widget::display\_callback( array $args, int|array $widget\_args = 1 ) ========================================================================= Generates the actual widget content (Do NOT override). Finds the instance and calls [WP\_Widget::widget()](widget). `$args` array Required Display arguments. See [WP\_Widget::widget()](widget) for information on accepted arguments. More Arguments from WP\_Widget::widget( ... $args ) Display arguments including `'before_title'`, `'after_title'`, `'before_widget'`, and `'after_widget'`. `$widget_args` int|array Optional Internal order number of the widget instance, or array of multi-widget arguments. * `number`intNumber increment used for multiples of the same widget. Default: `1` File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function display_callback( $args, $widget_args = 1 ) { if ( is_numeric( $widget_args ) ) { $widget_args = array( 'number' => $widget_args ); } $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); $this->_set( $widget_args['number'] ); $instances = $this->get_settings(); if ( isset( $instances[ $this->number ] ) ) { $instance = $instances[ $this->number ]; /** * Filters the settings for a particular widget instance. * * Returning false will effectively short-circuit display of the widget. * * @since 2.8.0 * * @param array $instance The current widget instance's settings. * @param WP_Widget $widget The current widget instance. * @param array $args An array of default widget arguments. */ $instance = apply_filters( 'widget_display_callback', $instance, $this, $args ); if ( false === $instance ) { return; } $was_cache_addition_suspended = wp_suspend_cache_addition(); if ( $this->is_preview() && ! $was_cache_addition_suspended ) { wp_suspend_cache_addition( true ); } $this->widget( $args, $instance ); if ( $this->is_preview() ) { wp_suspend_cache_addition( $was_cache_addition_suspended ); } } } ``` [apply\_filters( 'widget\_display\_callback', array $instance, WP\_Widget $widget, array $args )](../../hooks/widget_display_callback) Filters the settings for a particular widget instance. | Uses | Description | | --- | --- | | [wp\_suspend\_cache\_addition()](../../functions/wp_suspend_cache_addition) wp-includes/functions.php | Temporarily suspends cache additions. | | [WP\_Widget::get\_settings()](get_settings) wp-includes/class-wp-widget.php | Retrieves the settings for all instances of the widget class. | | [WP\_Widget::\_set()](_set) wp-includes/class-wp-widget.php | Sets the internal order number for the widget instance. | | [WP\_Widget::is\_preview()](is_preview) wp-includes/class-wp-widget.php | Determines whether the current request is inside the Customizer preview. | | [WP\_Widget::widget()](widget) wp-includes/class-wp-widget.php | Echoes the widget content. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::get_field_name( string $field_name ): string WP\_Widget::get\_field\_name( string $field\_name ): string =========================================================== Constructs name attributes for use in form() fields This function should be used in form() methods to create name attributes for fields to be saved by update() `$field_name` string Required Field name. string Name attribute for `$field_name`. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function get_field_name( $field_name ) { $pos = strpos( $field_name, '[' ); if ( false !== $pos ) { // Replace the first occurrence of '[' with ']['. $field_name = '[' . substr_replace( $field_name, '][', $pos, strlen( '[' ) ); } else { $field_name = '[' . $field_name . ']'; } return 'widget-' . $this->id_base . '[' . $this->number . ']' . $field_name; } ``` | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Array format field names are now accepted. | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::_set( int $number ) WP\_Widget::\_set( int $number ) ================================ Sets the internal order number for the widget instance. `$number` int Required The unique order number of this widget instance compared to other instances of the same class. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function _set( $number ) { $this->number = $number; $this->id = $this->id_base . '-' . $number; } ``` | Used By | Description | | --- | --- | | [WP\_Widget::display\_callback()](display_callback) wp-includes/class-wp-widget.php | Generates the actual widget content (Do NOT override). | | [WP\_Widget::update\_callback()](update_callback) wp-includes/class-wp-widget.php | Handles changed settings (Do NOT override). | | [WP\_Widget::form\_callback()](form_callback) wp-includes/class-wp-widget.php | Generates the widget control form (Do NOT override). | | [WP\_Widget::\_register()](_register) wp-includes/class-wp-widget.php | Register all widget instances of this widget class. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::form_callback( int|array $widget_args = 1 ): string|null WP\_Widget::form\_callback( int|array $widget\_args = 1 ): string|null ====================================================================== Generates the widget control form (Do NOT override). `$widget_args` int|array Optional Internal order number of the widget instance, or array of multi-widget arguments. * `number`intNumber increment used for multiples of the same widget. Default: `1` string|null File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function form_callback( $widget_args = 1 ) { if ( is_numeric( $widget_args ) ) { $widget_args = array( 'number' => $widget_args ); } $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); $all_instances = $this->get_settings(); if ( -1 == $widget_args['number'] ) { // We echo out a form where 'number' can be set later. $this->_set( '__i__' ); $instance = array(); } else { $this->_set( $widget_args['number'] ); $instance = $all_instances[ $widget_args['number'] ]; } /** * Filters the widget instance's settings before displaying the control form. * * Returning false effectively short-circuits display of the control form. * * @since 2.8.0 * * @param array $instance The current widget instance's settings. * @param WP_Widget $widget The current widget instance. */ $instance = apply_filters( 'widget_form_callback', $instance, $this ); $return = null; if ( false !== $instance ) { $return = $this->form( $instance ); /** * Fires at the end of the widget control form. * * Use this hook to add extra fields to the widget form. The hook * is only fired if the value passed to the 'widget_form_callback' * hook is not false. * * Note: If the widget has no form, the text echoed from the default * form method can be hidden using CSS. * * @since 2.8.0 * * @param WP_Widget $widget The widget instance (passed by reference). * @param null $return Return null if new fields are added. * @param array $instance An array of the widget's settings. */ do_action_ref_array( 'in_widget_form', array( &$this, &$return, $instance ) ); } return $return; } ``` [do\_action\_ref\_array( 'in\_widget\_form', WP\_Widget $widget, null $return, array $instance )](../../hooks/in_widget_form) Fires at the end of the widget control form. [apply\_filters( 'widget\_form\_callback', array $instance, WP\_Widget $widget )](../../hooks/widget_form_callback) Filters the widget instance’s settings before displaying the control form. | Uses | Description | | --- | --- | | [do\_action\_ref\_array()](../../functions/do_action_ref_array) wp-includes/plugin.php | Calls the callback functions that have been added to an action hook, specifying arguments in an array. | | [WP\_Widget::get\_settings()](get_settings) wp-includes/class-wp-widget.php | Retrieves the settings for all instances of the widget class. | | [WP\_Widget::\_set()](_set) wp-includes/class-wp-widget.php | Sets the internal order number for the widget instance. | | [WP\_Widget::form()](form) wp-includes/class-wp-widget.php | Outputs the settings update form. | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::_register_one( int $number = -1 ) WP\_Widget::\_register\_one( int $number = -1 ) =============================================== Registers an instance of the widget class. `$number` int Optional The unique order number of this widget instance compared to other instances of the same class. Default: `-1` File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function _register_one( $number = -1 ) { wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); } ``` | Uses | Description | | --- | --- | | [WP\_Widget::\_get\_display\_callback()](_get_display_callback) wp-includes/class-wp-widget.php | Retrieves the widget display callback. | | [WP\_Widget::\_get\_update\_callback()](_get_update_callback) wp-includes/class-wp-widget.php | Retrieves the widget update callback. | | [WP\_Widget::\_get\_form\_callback()](_get_form_callback) wp-includes/class-wp-widget.php | Retrieves the form callback. | | [wp\_register\_sidebar\_widget()](../../functions/wp_register_sidebar_widget) wp-includes/widgets.php | Register an instance of a widget. | | [\_register\_widget\_update\_callback()](../../functions/_register_widget_update_callback) wp-includes/widgets.php | Registers the update callback for a widget. | | [\_register\_widget\_form\_callback()](../../functions/_register_widget_form_callback) wp-includes/widgets.php | Registers the form callback for a widget. | | Used By | Description | | --- | --- | | [WP\_Widget\_Text::\_register\_one()](../wp_widget_text/_register_one) wp-includes/widgets/class-wp-widget-text.php | Add hooks for enqueueing assets when registering all widget instances of this widget class. | | [WP\_Widget\_Custom\_HTML::\_register\_one()](../wp_widget_custom_html/_register_one) wp-includes/widgets/class-wp-widget-custom-html.php | Add hooks for enqueueing assets when registering all widget instances of this widget class. | | [WP\_Widget\_Media::\_register\_one()](../wp_widget_media/_register_one) wp-includes/widgets/class-wp-widget-media.php | Add hooks while registering all widget instances of this widget class. | | [WP\_Widget::\_register()](_register) wp-includes/class-wp-widget.php | Register all widget instances of this widget class. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::get_settings(): array WP\_Widget::get\_settings(): array ================================== Retrieves the settings for all instances of the widget class. array Multi-dimensional array of widget instance settings. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function get_settings() { $settings = get_option( $this->option_name ); if ( false === $settings ) { $settings = array(); if ( isset( $this->alt_option_name ) ) { // Get settings from alternative (legacy) option. $settings = get_option( $this->alt_option_name, array() ); // Delete the alternative (legacy) option as the new option will be created using `$this->option_name`. delete_option( $this->alt_option_name ); } // Save an option so it can be autoloaded next time. $this->save_settings( $settings ); } if ( ! is_array( $settings ) && ! ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) ) { $settings = array(); } if ( ! empty( $settings ) && ! isset( $settings['_multiwidget'] ) ) { // Old format, convert if single widget. $settings = wp_convert_widget_settings( $this->id_base, $this->option_name, $settings ); } unset( $settings['_multiwidget'], $settings['__i__'] ); return $settings; } ``` | Uses | Description | | --- | --- | | [delete\_option()](../../functions/delete_option) wp-includes/option.php | Removes option by name. Prevents removal of protected WordPress options. | | [WP\_Widget::save\_settings()](save_settings) wp-includes/class-wp-widget.php | Saves the settings for all instances of the widget class. | | [wp\_convert\_widget\_settings()](../../functions/wp_convert_widget_settings) wp-includes/widgets.php | Converts the widget settings from single to multi-widget format. | | [get\_option()](../../functions/get_option) wp-includes/option.php | Retrieves an option value based on an option name. | | Used By | Description | | --- | --- | | [WP\_Widget::display\_callback()](display_callback) wp-includes/class-wp-widget.php | Generates the actual widget content (Do NOT override). | | [WP\_Widget::update\_callback()](update_callback) wp-includes/class-wp-widget.php | Handles changed settings (Do NOT override). | | [WP\_Widget::form\_callback()](form_callback) wp-includes/class-wp-widget.php | Generates the widget control form (Do NOT override). | | [WP\_Widget::\_register()](_register) wp-includes/class-wp-widget.php | Register all widget instances of this widget class. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |
programming_docs
wordpress WP_Widget::__construct( string $id_base, string $name, array $widget_options = array(), array $control_options = array() ) WP\_Widget::\_\_construct( string $id\_base, string $name, array $widget\_options = array(), array $control\_options = array() ) ================================================================================================================================ PHP5 constructor. `$id_base` string Optional Base ID for the widget, lowercase and unique. If left empty, a portion of the widget's PHP class name will be used. Has to be unique. `$name` string Optional Name for the widget displayed on the configuration page. `$widget_options` array Optional Widget options. See [wp\_register\_sidebar\_widget()](../../functions/wp_register_sidebar_widget) for information on accepted arguments. Default: `array()` `$control_options` array Optional Widget control options. See [wp\_register\_widget\_control()](../../functions/wp_register_widget_control) for information on accepted arguments. Default: `array()` File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) { if ( ! empty( $id_base ) ) { $id_base = strtolower( $id_base ); } else { $id_base = preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) ); } $this->id_base = $id_base; $this->name = $name; $this->option_name = 'widget_' . $this->id_base; $this->widget_options = wp_parse_args( $widget_options, array( 'classname' => str_replace( '\\', '_', $this->option_name ), 'customize_selective_refresh' => false, ) ); $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) ); } ``` | Uses | Description | | --- | --- | | [wp\_parse\_args()](../../functions/wp_parse_args) wp-includes/functions.php | Merges user defined arguments into defaults array. | | Used By | Description | | --- | --- | | [WP\_Widget\_Block::\_\_construct()](../wp_widget_block/__construct) wp-includes/widgets/class-wp-widget-block.php | Sets up a new Block widget instance. | | [WP\_Widget\_Custom\_HTML::\_\_construct()](../wp_widget_custom_html/__construct) wp-includes/widgets/class-wp-widget-custom-html.php | Sets up a new Custom HTML widget instance. | | [WP\_Widget\_Media::\_\_construct()](../wp_widget_media/__construct) wp-includes/widgets/class-wp-widget-media.php | Constructor. | | [WP\_Nav\_Menu\_Widget::\_\_construct()](../wp_nav_menu_widget/__construct) wp-includes/widgets/class-wp-nav-menu-widget.php | Sets up a new Navigation Menu widget instance. | | [WP\_Widget\_Tag\_Cloud::\_\_construct()](../wp_widget_tag_cloud/__construct) wp-includes/widgets/class-wp-widget-tag-cloud.php | Sets up a new Tag Cloud widget instance. | | [WP\_Widget\_RSS::\_\_construct()](../wp_widget_rss/__construct) wp-includes/widgets/class-wp-widget-rss.php | Sets up a new RSS widget instance. | | [WP\_Widget\_Recent\_Comments::\_\_construct()](../wp_widget_recent_comments/__construct) wp-includes/widgets/class-wp-widget-recent-comments.php | Sets up a new Recent Comments widget instance. | | [WP\_Widget\_Recent\_Posts::\_\_construct()](../wp_widget_recent_posts/__construct) wp-includes/widgets/class-wp-widget-recent-posts.php | Sets up a new Recent Posts widget instance. | | [WP\_Widget\_Categories::\_\_construct()](../wp_widget_categories/__construct) wp-includes/widgets/class-wp-widget-categories.php | Sets up a new Categories widget instance. | | [WP\_Widget\_Text::\_\_construct()](../wp_widget_text/__construct) wp-includes/widgets/class-wp-widget-text.php | Sets up a new Text widget instance. | | [WP\_Widget\_Calendar::\_\_construct()](../wp_widget_calendar/__construct) wp-includes/widgets/class-wp-widget-calendar.php | Sets up a new Calendar widget instance. | | [WP\_Widget\_Meta::\_\_construct()](../wp_widget_meta/__construct) wp-includes/widgets/class-wp-widget-meta.php | Sets up a new Meta widget instance. | | [WP\_Widget\_Archives::\_\_construct()](../wp_widget_archives/__construct) wp-includes/widgets/class-wp-widget-archives.php | Sets up a new Archives widget instance. | | [WP\_Widget\_Links::\_\_construct()](../wp_widget_links/__construct) wp-includes/widgets/class-wp-widget-links.php | Sets up a new Links widget instance. | | [WP\_Widget\_Search::\_\_construct()](../wp_widget_search/__construct) wp-includes/widgets/class-wp-widget-search.php | Sets up a new Search widget instance. | | [WP\_Widget\_Pages::\_\_construct()](../wp_widget_pages/__construct) wp-includes/widgets/class-wp-widget-pages.php | Sets up a new Pages widget instance. | | [WP\_Widget::WP\_Widget()](wp_widget) wp-includes/class-wp-widget.php | PHP4 constructor. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::update_callback( int $deprecated = 1 ) WP\_Widget::update\_callback( int $deprecated = 1 ) =================================================== Handles changed settings (Do NOT override). `$deprecated` int Optional Not used. Default: `1` File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function update_callback( $deprecated = 1 ) { global $wp_registered_widgets; $all_instances = $this->get_settings(); // We need to update the data. if ( $this->updated ) { return; } if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { // Delete the settings for this instance of the widget. if ( isset( $_POST['the-widget-id'] ) ) { $del_id = $_POST['the-widget-id']; } else { return; } if ( isset( $wp_registered_widgets[ $del_id ]['params'][0]['number'] ) ) { $number = $wp_registered_widgets[ $del_id ]['params'][0]['number']; if ( $this->id_base . '-' . $number == $del_id ) { unset( $all_instances[ $number ] ); } } } else { if ( isset( $_POST[ 'widget-' . $this->id_base ] ) && is_array( $_POST[ 'widget-' . $this->id_base ] ) ) { $settings = $_POST[ 'widget-' . $this->id_base ]; } elseif ( isset( $_POST['id_base'] ) && $_POST['id_base'] == $this->id_base ) { $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number']; $settings = array( $num => array() ); } else { return; } foreach ( $settings as $number => $new_instance ) { $new_instance = stripslashes_deep( $new_instance ); $this->_set( $number ); $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); $was_cache_addition_suspended = wp_suspend_cache_addition(); if ( $this->is_preview() && ! $was_cache_addition_suspended ) { wp_suspend_cache_addition( true ); } $instance = $this->update( $new_instance, $old_instance ); if ( $this->is_preview() ) { wp_suspend_cache_addition( $was_cache_addition_suspended ); } /** * Filters a widget's settings before saving. * * Returning false will effectively short-circuit the widget's ability * to update settings. * * @since 2.8.0 * * @param array $instance The current widget instance's settings. * @param array $new_instance Array of new widget settings. * @param array $old_instance Array of old widget settings. * @param WP_Widget $widget The current widget instance. */ $instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this ); if ( false !== $instance ) { $all_instances[ $number ] = $instance; } break; // Run only once. } } $this->save_settings( $all_instances ); $this->updated = true; } ``` [apply\_filters( 'widget\_update\_callback', array $instance, array $new\_instance, array $old\_instance, WP\_Widget $widget )](../../hooks/widget_update_callback) Filters a widget’s settings before saving. | Uses | Description | | --- | --- | | [stripslashes\_deep()](../../functions/stripslashes_deep) wp-includes/formatting.php | Navigates through an array, object, or scalar, and removes slashes from the values. | | [wp\_suspend\_cache\_addition()](../../functions/wp_suspend_cache_addition) wp-includes/functions.php | Temporarily suspends cache additions. | | [WP\_Widget::get\_settings()](get_settings) wp-includes/class-wp-widget.php | Retrieves the settings for all instances of the widget class. | | [WP\_Widget::save\_settings()](save_settings) wp-includes/class-wp-widget.php | Saves the settings for all instances of the widget class. | | [WP\_Widget::\_set()](_set) wp-includes/class-wp-widget.php | Sets the internal order number for the widget instance. | | [WP\_Widget::is\_preview()](is_preview) wp-includes/class-wp-widget.php | Determines whether the current request is inside the Customizer preview. | | [WP\_Widget::update()](update) wp-includes/class-wp-widget.php | Updates a particular instance of a widget. | | [apply\_filters()](../../functions/apply_filters) wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::widget( array $args, array $instance ) WP\_Widget::widget( array $args, array $instance ) ================================================== Echoes the widget content. Subclasses should override this function to generate their widget code. `$args` array Required Display arguments including `'before_title'`, `'after_title'`, `'before_widget'`, and `'after_widget'`. `$instance` array Required The settings for the particular instance of the widget. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function widget( $args, $instance ) { die( 'function WP_Widget::widget() must be overridden in a subclass.' ); } ``` | Used By | Description | | --- | --- | | [WP\_Widget::display\_callback()](../wp_widget/display_callback) wp-includes/class-wp-widget.php | Generates the actual widget content (Do NOT override). | | Version | Description | | --- | --- | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress WP_Widget::get_field_id( string $field_name ): string WP\_Widget::get\_field\_id( string $field\_name ): string ========================================================= Constructs id attributes for use in [WP\_Widget::form()](form) fields. This function should be used in form() methods to create id attributes for fields to be saved by [WP\_Widget::update()](update). `$field_name` string Required Field name. string ID attribute for `$field_name`. File: `wp-includes/class-wp-widget.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-widget.php/) ``` public function get_field_id( $field_name ) { $field_name = str_replace( array( '[]', '[', ']' ), array( '', '-', '' ), $field_name ); $field_name = trim( $field_name, '-' ); return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name; } ``` | Version | Description | | --- | --- | | [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Array format field IDs are now accepted. | | [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. | wordpress IXR_Error::getXml() IXR\_Error::getXml() ==================== File: `wp-includes/IXR/class-IXR-error.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/ixr/class-ixr-error.php/) ``` function getXml() { $xml = <<<EOD <methodResponse> <fault> <value> <struct> <member> <name>faultCode</name> <value><int>{$this->code}</int></value> </member> <member> <name>faultString</name> <value><string>{$this->message}</string></value> </member> </struct> </value> </fault> </methodResponse> EOD; return $xml; } ``` wordpress IXR_Error::__construct( $code, $message ) IXR\_Error::\_\_construct( $code, $message ) ============================================ PHP5 constructor. File: `wp-includes/IXR/class-IXR-error.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/ixr/class-ixr-error.php/) ``` function __construct( $code, $message ) { $this->code = $code; $this->message = htmlspecialchars($message); } ``` | Used By | Description | | --- | --- | | [IXR\_IntrospectionServer::methodSignature()](../ixr_introspectionserver/methodsignature) wp-includes/IXR/class-IXR-introspectionserver.php | | | [IXR\_IntrospectionServer::call()](../ixr_introspectionserver/call) wp-includes/IXR/class-IXR-introspectionserver.php | | | [IXR\_Error::IXR\_Error()](ixr_error) wp-includes/IXR/class-IXR-error.php | PHP4 constructor. | | [IXR\_Server::multiCall()](../ixr_server/multicall) wp-includes/IXR/class-IXR-server.php | | | [IXR\_Server::error()](../ixr_server/error) wp-includes/IXR/class-IXR-server.php | | | [IXR\_Server::call()](../ixr_server/call) wp-includes/IXR/class-IXR-server.php | | | [IXR\_Client::query()](../ixr_client/query) wp-includes/IXR/class-IXR-client.php | | | [wp\_xmlrpc\_server::error()](../wp_xmlrpc_server/error) wp-includes/class-wp-xmlrpc-server.php | Send error response to client. | | [wp\_xmlrpc\_server::\_toggle\_sticky()](../wp_xmlrpc_server/_toggle_sticky) wp-includes/class-wp-xmlrpc-server.php | Encapsulate the logic for sticking a post and determining if the user has permission to do so | | [\_xmlrpc\_wp\_die\_handler()](../../functions/_xmlrpc_wp_die_handler) wp-includes/functions.php | Kills WordPress execution and displays XML response with an error message. | | [WP\_HTTP\_IXR\_Client::query()](../wp_http_ixr_client/query) wp-includes/class-wp-http-ixr-client.php | | | [wp\_xmlrpc\_server::mt\_getPostCategories()](../wp_xmlrpc_server/mt_getpostcategories) wp-includes/class-wp-xmlrpc-server.php | Retrieve post categories. | | [wp\_xmlrpc\_server::mt\_setPostCategories()](../wp_xmlrpc_server/mt_setpostcategories) wp-includes/class-wp-xmlrpc-server.php | Sets categories for a post. | | [wp\_xmlrpc\_server::mt\_getTrackbackPings()](../wp_xmlrpc_server/mt_gettrackbackpings) wp-includes/class-wp-xmlrpc-server.php | Retrieve trackbacks sent to a given post. | | [wp\_xmlrpc\_server::mt\_publishPost()](../wp_xmlrpc_server/mt_publishpost) wp-includes/class-wp-xmlrpc-server.php | Sets a post’s publish status to ‘publish’. | | [wp\_xmlrpc\_server::pingback\_error()](../wp_xmlrpc_server/pingback_error) wp-includes/class-wp-xmlrpc-server.php | Sends a pingback error based on the given error code and message. | | [wp\_xmlrpc\_server::mw\_editPost()](../wp_xmlrpc_server/mw_editpost) wp-includes/class-wp-xmlrpc-server.php | Edit a post. | | [wp\_xmlrpc\_server::mw\_getPost()](../wp_xmlrpc_server/mw_getpost) wp-includes/class-wp-xmlrpc-server.php | Retrieve post. | | [wp\_xmlrpc\_server::mw\_getRecentPosts()](../wp_xmlrpc_server/mw_getrecentposts) wp-includes/class-wp-xmlrpc-server.php | Retrieve list of recent posts. | | [wp\_xmlrpc\_server::mw\_getCategories()](../wp_xmlrpc_server/mw_getcategories) wp-includes/class-wp-xmlrpc-server.php | Retrieve the list of categories on a given blog. | | [wp\_xmlrpc\_server::mw\_newMediaObject()](../wp_xmlrpc_server/mw_newmediaobject) wp-includes/class-wp-xmlrpc-server.php | Uploads a file, following your settings. | | [wp\_xmlrpc\_server::mt\_getRecentPostTitles()](../wp_xmlrpc_server/mt_getrecentposttitles) wp-includes/class-wp-xmlrpc-server.php | Retrieve the post titles of recent posts. | | [wp\_xmlrpc\_server::mt\_getCategoryList()](../wp_xmlrpc_server/mt_getcategorylist) wp-includes/class-wp-xmlrpc-server.php | Retrieve list of all categories on blog. | | [wp\_xmlrpc\_server::blogger\_getUserInfo()](../wp_xmlrpc_server/blogger_getuserinfo) wp-includes/class-wp-xmlrpc-server.php | Retrieve user’s data. | | [wp\_xmlrpc\_server::blogger\_getPost()](../wp_xmlrpc_server/blogger_getpost) wp-includes/class-wp-xmlrpc-server.php | Retrieve post. | | [wp\_xmlrpc\_server::blogger\_getRecentPosts()](../wp_xmlrpc_server/blogger_getrecentposts) wp-includes/class-wp-xmlrpc-server.php | Retrieve list of recent posts. | | [wp\_xmlrpc\_server::blogger\_getTemplate()](../wp_xmlrpc_server/blogger_gettemplate) wp-includes/class-wp-xmlrpc-server.php | Deprecated. | | [wp\_xmlrpc\_server::blogger\_setTemplate()](../wp_xmlrpc_server/blogger_settemplate) wp-includes/class-wp-xmlrpc-server.php | Deprecated. | | [wp\_xmlrpc\_server::blogger\_newPost()](../wp_xmlrpc_server/blogger_newpost) wp-includes/class-wp-xmlrpc-server.php | Creates new post. | | [wp\_xmlrpc\_server::blogger\_editPost()](../wp_xmlrpc_server/blogger_editpost) wp-includes/class-wp-xmlrpc-server.php | Edit a post. | | [wp\_xmlrpc\_server::blogger\_deletePost()](../wp_xmlrpc_server/blogger_deletepost) wp-includes/class-wp-xmlrpc-server.php | Remove a post. | | [wp\_xmlrpc\_server::mw\_newPost()](../wp_xmlrpc_server/mw_newpost) wp-includes/class-wp-xmlrpc-server.php | Create a new post. | | [wp\_xmlrpc\_server::wp\_setOptions()](../wp_xmlrpc_server/wp_setoptions) wp-includes/class-wp-xmlrpc-server.php | Update blog options. | | [wp\_xmlrpc\_server::wp\_getMediaItem()](../wp_xmlrpc_server/wp_getmediaitem) wp-includes/class-wp-xmlrpc-server.php | Retrieve a media item by ID | | [wp\_xmlrpc\_server::wp\_getMediaLibrary()](../wp_xmlrpc_server/wp_getmedialibrary) wp-includes/class-wp-xmlrpc-server.php | Retrieves a collection of media library items (or attachments) | | [wp\_xmlrpc\_server::wp\_getPostFormats()](../wp_xmlrpc_server/wp_getpostformats) wp-includes/class-wp-xmlrpc-server.php | Retrieves a list of post formats used by the site. | | [wp\_xmlrpc\_server::wp\_getPostType()](../wp_xmlrpc_server/wp_getposttype) wp-includes/class-wp-xmlrpc-server.php | Retrieves a post type | | [wp\_xmlrpc\_server::wp\_getRevisions()](../wp_xmlrpc_server/wp_getrevisions) wp-includes/class-wp-xmlrpc-server.php | Retrieve revisions for a specific post. | | [wp\_xmlrpc\_server::wp\_restoreRevision()](../wp_xmlrpc_server/wp_restorerevision) wp-includes/class-wp-xmlrpc-server.php | Restore a post revision | | [wp\_xmlrpc\_server::wp\_getComments()](../wp_xmlrpc_server/wp_getcomments) wp-includes/class-wp-xmlrpc-server.php | Retrieve comments. | | [wp\_xmlrpc\_server::wp\_deleteComment()](../wp_xmlrpc_server/wp_deletecomment) wp-includes/class-wp-xmlrpc-server.php | Delete a comment. | | [wp\_xmlrpc\_server::wp\_editComment()](../wp_xmlrpc_server/wp_editcomment) wp-includes/class-wp-xmlrpc-server.php | Edit comment. | | [wp\_xmlrpc\_server::wp\_newComment()](../wp_xmlrpc_server/wp_newcomment) wp-includes/class-wp-xmlrpc-server.php | Create new comment. | | [wp\_xmlrpc\_server::wp\_getCommentStatusList()](../wp_xmlrpc_server/wp_getcommentstatuslist) wp-includes/class-wp-xmlrpc-server.php | Retrieve all of the comment status. | | [wp\_xmlrpc\_server::wp\_getCommentCount()](../wp_xmlrpc_server/wp_getcommentcount) wp-includes/class-wp-xmlrpc-server.php | Retrieve comment count. | | [wp\_xmlrpc\_server::wp\_getPostStatusList()](../wp_xmlrpc_server/wp_getpoststatuslist) wp-includes/class-wp-xmlrpc-server.php | Retrieve post statuses. | | [wp\_xmlrpc\_server::wp\_getPageStatusList()](../wp_xmlrpc_server/wp_getpagestatuslist) wp-includes/class-wp-xmlrpc-server.php | Retrieve page statuses. | | [wp\_xmlrpc\_server::wp\_getPageTemplates()](../wp_xmlrpc_server/wp_getpagetemplates) wp-includes/class-wp-xmlrpc-server.php | Retrieve page templates. | | [wp\_xmlrpc\_server::wp\_getPages()](../wp_xmlrpc_server/wp_getpages) wp-includes/class-wp-xmlrpc-server.php | Retrieve Pages. | | [wp\_xmlrpc\_server::wp\_deletePage()](../wp_xmlrpc_server/wp_deletepage) wp-includes/class-wp-xmlrpc-server.php | Delete page. | | [wp\_xmlrpc\_server::wp\_editPage()](../wp_xmlrpc_server/wp_editpage) wp-includes/class-wp-xmlrpc-server.php | Edit page. | | [wp\_xmlrpc\_server::wp\_getPageList()](../wp_xmlrpc_server/wp_getpagelist) wp-includes/class-wp-xmlrpc-server.php | Retrieve page list. | | [wp\_xmlrpc\_server::wp\_getAuthors()](../wp_xmlrpc_server/wp_getauthors) wp-includes/class-wp-xmlrpc-server.php | Retrieve authors list. | | [wp\_xmlrpc\_server::wp\_getTags()](../wp_xmlrpc_server/wp_gettags) wp-includes/class-wp-xmlrpc-server.php | Get list of all tags | | [wp\_xmlrpc\_server::wp\_newCategory()](../wp_xmlrpc_server/wp_newcategory) wp-includes/class-wp-xmlrpc-server.php | Create new category. | | [wp\_xmlrpc\_server::wp\_deleteCategory()](../wp_xmlrpc_server/wp_deletecategory) wp-includes/class-wp-xmlrpc-server.php | Remove category. | | [wp\_xmlrpc\_server::wp\_suggestCategories()](../wp_xmlrpc_server/wp_suggestcategories) wp-includes/class-wp-xmlrpc-server.php | Retrieve category list. | | [wp\_xmlrpc\_server::wp\_getComment()](../wp_xmlrpc_server/wp_getcomment) wp-includes/class-wp-xmlrpc-server.php | Retrieve comment. | | [wp\_xmlrpc\_server::wp\_getPosts()](../wp_xmlrpc_server/wp_getposts) wp-includes/class-wp-xmlrpc-server.php | Retrieve posts. | | [wp\_xmlrpc\_server::wp\_newTerm()](../wp_xmlrpc_server/wp_newterm) wp-includes/class-wp-xmlrpc-server.php | Create a new term. | | [wp\_xmlrpc\_server::wp\_editTerm()](../wp_xmlrpc_server/wp_editterm) wp-includes/class-wp-xmlrpc-server.php | Edit a term. | | [wp\_xmlrpc\_server::wp\_deleteTerm()](../wp_xmlrpc_server/wp_deleteterm) wp-includes/class-wp-xmlrpc-server.php | Delete a term. | | [wp\_xmlrpc\_server::wp\_getTerm()](../wp_xmlrpc_server/wp_getterm) wp-includes/class-wp-xmlrpc-server.php | Retrieve a term. | | [wp\_xmlrpc\_server::wp\_getTerms()](../wp_xmlrpc_server/wp_getterms) wp-includes/class-wp-xmlrpc-server.php | Retrieve all terms for a taxonomy. | | [wp\_xmlrpc\_server::wp\_getTaxonomy()](../wp_xmlrpc_server/wp_gettaxonomy) wp-includes/class-wp-xmlrpc-server.php | Retrieve a taxonomy. | | [wp\_xmlrpc\_server::wp\_getUser()](../wp_xmlrpc_server/wp_getuser) wp-includes/class-wp-xmlrpc-server.php | Retrieve a user. | | [wp\_xmlrpc\_server::wp\_getUsers()](../wp_xmlrpc_server/wp_getusers) wp-includes/class-wp-xmlrpc-server.php | Retrieve users. | | [wp\_xmlrpc\_server::wp\_getProfile()](../wp_xmlrpc_server/wp_getprofile) wp-includes/class-wp-xmlrpc-server.php | Retrieve information about the requesting user. | | [wp\_xmlrpc\_server::wp\_editProfile()](../wp_xmlrpc_server/wp_editprofile) wp-includes/class-wp-xmlrpc-server.php | Edit user’s profile. | | [wp\_xmlrpc\_server::wp\_getPage()](../wp_xmlrpc_server/wp_getpage) wp-includes/class-wp-xmlrpc-server.php | Retrieve page. | | [wp\_xmlrpc\_server::\_insert\_post()](../wp_xmlrpc_server/_insert_post) wp-includes/class-wp-xmlrpc-server.php | Helper method for wp\_newPost() and wp\_editPost(), containing shared logic. | | [wp\_xmlrpc\_server::wp\_editPost()](../wp_xmlrpc_server/wp_editpost) wp-includes/class-wp-xmlrpc-server.php | Edit a post for any registered post type. | | [wp\_xmlrpc\_server::wp\_deletePost()](../wp_xmlrpc_server/wp_deletepost) wp-includes/class-wp-xmlrpc-server.php | Delete a post for any registered post type. | | [wp\_xmlrpc\_server::wp\_getPost()](../wp_xmlrpc_server/wp_getpost) wp-includes/class-wp-xmlrpc-server.php | Retrieve a post. | | [wp\_xmlrpc\_server::minimum\_args()](../wp_xmlrpc_server/minimum_args) wp-includes/class-wp-xmlrpc-server.php | Checks if the method received at least the minimum number of arguments. | | [wp\_xmlrpc\_server::login()](../wp_xmlrpc_server/login) wp-includes/class-wp-xmlrpc-server.php | Log user in. | | [xmlrpc\_pingback\_error()](../../functions/xmlrpc_pingback_error) wp-includes/comment.php | Default filter attached to xmlrpc\_pingback\_error. |
programming_docs
wordpress IXR_Error::IXR_Error( $code, $message ) IXR\_Error::IXR\_Error( $code, $message ) ========================================= PHP4 constructor. File: `wp-includes/IXR/class-IXR-error.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/ixr/class-ixr-error.php/) ``` public function IXR_Error( $code, $message ) { self::__construct( $code, $message ); } ``` | Uses | Description | | --- | --- | | [IXR\_Error::\_\_construct()](__construct) wp-includes/IXR/class-IXR-error.php | PHP5 constructor. | wordpress WP_REST_Controller::get_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Controller::get\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error =========================================================================================== Retrieves one item from the collection. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` public function get_item( $request ) { return new WP_Error( 'invalid-method', /* translators: %s: Method name. */ sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::filter_response_by_context( array $data, string $context ): array WP\_REST\_Controller::filter\_response\_by\_context( array $data, string $context ): array ========================================================================================== Filters a response based on the context defined in the schema. `$data` array Required Response data to filter. `$context` string Required Context defined in the schema. array Filtered response. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` public function filter_response_by_context( $data, $context ) { $schema = $this->get_item_schema(); return rest_filter_response_by_context( $data, $schema, $context ); } ``` | Uses | Description | | --- | --- | | [rest\_filter\_response\_by\_context()](../../functions/rest_filter_response_by_context) wp-includes/rest-api.php | Filters the response to remove any fields not available in the given context. | | [WP\_REST\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves the item’s schema, conforming to JSON Schema. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::add_additional_fields_schema( array $schema ): array WP\_REST\_Controller::add\_additional\_fields\_schema( array $schema ): array ============================================================================= Adds the schema from additional fields to a schema array. The type of object is inferred from the passed schema. `$schema` array Required Schema array. array Modified Schema array. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` protected function add_additional_fields_schema( $schema ) { if ( empty( $schema['title'] ) ) { return $schema; } // Can't use $this->get_object_type otherwise we cause an inf loop. $object_type = $schema['title']; $additional_fields = $this->get_additional_fields( $object_type ); foreach ( $additional_fields as $field_name => $field_options ) { if ( ! $field_options['schema'] ) { continue; } $schema['properties'][ $field_name ] = $field_options['schema']; } return $schema; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Controller::get\_additional\_fields()](get_additional_fields) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves all of the registered additional fields for a given object-type. | | Used By | Description | | --- | --- | | [WP\_REST\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves the item’s schema, conforming to JSON Schema. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::prepare_item_for_response( mixed $item, WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Controller::prepare\_item\_for\_response( mixed $item, WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error =========================================================================================================================== Prepares the item for the REST response. `$item` mixed Required WordPress representation of the item. `$request` [WP\_REST\_Request](../wp_rest_request) Required Request object. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` public function prepare_item_for_response( $item, $request ) { return new WP_Error( 'invalid-method', /* translators: %s: Method name. */ sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Controller::get\_items( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ============================================================================================ Retrieves a collection of items. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` public function get_items( $request ) { return new WP_Error( 'invalid-method', /* translators: %s: Method name. */ sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::get_additional_fields( string $object_type = null ): array WP\_REST\_Controller::get\_additional\_fields( string $object\_type = null ): array =================================================================================== Retrieves all of the registered additional fields for a given object-type. `$object_type` string Optional The object type. Default: `null` array Registered additional fields (if any), empty array if none or if the object type could not be inferred. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` protected function get_additional_fields( $object_type = null ) { global $wp_rest_additional_fields; if ( ! $object_type ) { $object_type = $this->get_object_type(); } if ( ! $object_type ) { return array(); } if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) { return array(); } return $wp_rest_additional_fields[ $object_type ]; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Controller::get\_object\_type()](../wp_rest_controller/get_object_type) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves the object type this controller is responsible for managing. | | Used By | Description | | --- | --- | | [WP\_REST\_Controller::get\_fields\_for\_response()](../wp_rest_controller/get_fields_for_response) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Gets an array of fields to be included on the response. | | [WP\_REST\_Controller::add\_additional\_fields\_to\_object()](../wp_rest_controller/add_additional_fields_to_object) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Adds the values from additional fields to a data object. | | [WP\_REST\_Controller::update\_additional\_fields\_for\_object()](../wp_rest_controller/update_additional_fields_for_object) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Updates the values of additional fields added to a data object. | | [WP\_REST\_Controller::add\_additional\_fields\_schema()](../wp_rest_controller/add_additional_fields_schema) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Adds the schema from additional fields to a schema array. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::create_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Controller::create\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ============================================================================================== Creates one item from the collection. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` public function create_item( $request ) { return new WP_Error( 'invalid-method', /* translators: %s: Method name. */ sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::update_additional_fields_for_object( object $object, WP_REST_Request $request ): true|WP_Error WP\_REST\_Controller::update\_additional\_fields\_for\_object( object $object, WP\_REST\_Request $request ): true|WP\_Error =========================================================================================================================== Updates the values of additional fields added to a data object. `$object` object Required Data model like [WP\_Term](../wp_term) or [WP\_Post](../wp_post). `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True on success, [WP\_Error](../wp_error) object if a field cannot be updated. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` protected function update_additional_fields_for_object( $object, $request ) { $additional_fields = $this->get_additional_fields(); foreach ( $additional_fields as $field_name => $field_options ) { if ( ! $field_options['update_callback'] ) { continue; } // Don't run the update callbacks if the data wasn't passed in the request. if ( ! isset( $request[ $field_name ] ) ) { continue; } $result = call_user_func( $field_options['update_callback'], $request[ $field_name ], $object, $field_name, $request, $this->get_object_type() ); if ( is_wp_error( $result ) ) { return $result; } } return true; } ``` | Uses | Description | | --- | --- | | [WP\_REST\_Controller::get\_object\_type()](get_object_type) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves the object type this controller is responsible for managing. | | [WP\_REST\_Controller::get\_additional\_fields()](get_additional_fields) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves all of the registered additional fields for a given object-type. | | [is\_wp\_error()](../../functions/is_wp_error) wp-includes/load.php | Checks whether the given variable is a WordPress Error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::update_item( WP_REST_Request $request ): WP_REST_Response|WP_Error WP\_REST\_Controller::update\_item( WP\_REST\_Request $request ): WP\_REST\_Response|WP\_Error ============================================================================================== Updates one item from the collection. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. [WP\_REST\_Response](../wp_rest_response)|[WP\_Error](../wp_error) Response object on success, or [WP\_Error](../wp_error) object on failure. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` public function update_item( $request ) { return new WP_Error( 'invalid-method', /* translators: %s: Method name. */ sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::add_additional_fields_to_object( array $prepared, WP_REST_Request $request ): array WP\_REST\_Controller::add\_additional\_fields\_to\_object( array $prepared, WP\_REST\_Request $request ): array =============================================================================================================== Adds the values from additional fields to a data object. `$prepared` array Required Prepared response array. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. array Modified data object with additional fields. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` protected function add_additional_fields_to_object( $prepared, $request ) { $additional_fields = $this->get_additional_fields(); $requested_fields = $this->get_fields_for_response( $request ); foreach ( $additional_fields as $field_name => $field_options ) { if ( ! $field_options['get_callback'] ) { continue; } if ( ! rest_is_field_included( $field_name, $requested_fields ) ) { continue; } $prepared[ $field_name ] = call_user_func( $field_options['get_callback'], $prepared, $field_name, $request, $this->get_object_type() ); } return $prepared; } ``` | Uses | Description | | --- | --- | | [rest\_is\_field\_included()](../../functions/rest_is_field_included) wp-includes/rest-api.php | Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body. | | [WP\_REST\_Controller::get\_fields\_for\_response()](get_fields_for_response) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Gets an array of fields to be included on the response. | | [WP\_REST\_Controller::get\_object\_type()](get_object_type) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves the object type this controller is responsible for managing. | | [WP\_REST\_Controller::get\_additional\_fields()](get_additional_fields) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves all of the registered additional fields for a given object-type. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::delete_item_permissions_check( WP_REST_Request $request ): true|WP_Error WP\_REST\_Controller::delete\_item\_permissions\_check( WP\_REST\_Request $request ): true|WP\_Error ==================================================================================================== Checks if a given request has access to delete a specific item. `$request` [WP\_REST\_Request](../wp_rest_request) Required Full details about the request. true|[WP\_Error](../wp_error) True if the request has access to delete the item, [WP\_Error](../wp_error) object otherwise. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` public function delete_item_permissions_check( $request ) { return new WP_Error( 'invalid-method', /* translators: %s: Method name. */ sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); } ``` | Uses | Description | | --- | --- | | [\_\_()](../../functions/__) wp-includes/l10n.php | Retrieves the translation of $text. | | [WP\_Error::\_\_construct()](../wp_error/__construct) wp-includes/class-wp-error.php | Initializes the error. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. | wordpress WP_REST_Controller::get_endpoint_args_for_item_schema( string $method = WP_REST_Server::CREATABLE ): array WP\_REST\_Controller::get\_endpoint\_args\_for\_item\_schema( string $method = WP\_REST\_Server::CREATABLE ): array =================================================================================================================== Retrieves an array of endpoint arguments from the item schema for the controller. `$method` string Optional HTTP method of the request. The arguments for `CREATABLE` requests are checked for required values and may fall-back to a given default, this is not done on `EDITABLE` requests. Default: `WP_REST_Server::CREATABLE` array Endpoint arguments. File: `wp-includes/rest-api/endpoints/class-wp-rest-controller.php`. [View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-controller.php/) ``` public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) { return rest_get_endpoint_args_for_schema( $this->get_item_schema(), $method ); } ``` | Uses | Description | | --- | --- | | [rest\_get\_endpoint\_args\_for\_schema()](../../functions/rest_get_endpoint_args_for_schema) wp-includes/rest-api.php | Retrieves an array of endpoint arguments from the item schema and endpoint method. | | [WP\_REST\_Controller::get\_item\_schema()](get_item_schema) wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Retrieves the item’s schema, conforming to JSON Schema. | | Version | Description | | --- | --- | | [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |
programming_docs