Skip to content
Open
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-user-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
$caps_with_roles = array();

foreach ( $available_roles as $role => $role_data ) {
$role_caps = array_keys( array_filter( $role_data['capabilities'] ) );
$role_caps = (isset($role_data['capabilities'])) ? array_keys( array_filter( $role_data['capabilities'] ) ) : array();

Check failure on line 485 in src/wp-includes/class-wp-user-query.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 space before close parenthesis; 0 found

Check failure on line 485 in src/wp-includes/class-wp-user-query.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 spaces before closing parenthesis; 0 found

Check failure on line 485 in src/wp-includes/class-wp-user-query.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 485 in src/wp-includes/class-wp-user-query.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Expected 1 space after open parenthesis; 0 found

foreach ( $capabilities as $cap ) {
if ( in_array( $cap, $role_caps, true ) ) {
Expand Down
42 changes: 42 additions & 0 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8702,3 +8702,45 @@ function wp_create_initial_post_meta() {
);
}
}

/**
* Retrieves page IDs, permalinks, or titles based on a template file name.
*
* Queries pages using a specified template file and returns an array of
* IDs, permalinks, or titles based on the provided field parameter.
*
* @param string $template The template file name to search for.
* @param string $field The field to return: 'ID' for page IDs, 'permalink' for page permalinks, or 'title' for page titles.
* @return array|null An array of IDs, permalinks, or titles of matching pages, or null if no pages are found.
*/

function get_page_by_template( $template, $field = 'ID' ) {
$query = new WP_Query(
array(
'post_type' => 'page',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => $template,
'compare' => '==',
),
),
'fields' => 'ids',
)
);

if ( $query->have_posts() ) {
$template_page_ids = $query->posts;
wp_reset_postdata();
if ( 'ID' === $field ) {
return $template_page_ids;
} elseif ( 'title' === $field ) {
return array_combine( $template_page_ids, array_map( 'get_the_title', $template_page_ids ) );
} elseif ( 'permalink' === $field ) {
return array_combine( $template_page_ids, array_map( 'get_permalink', $template_page_ids ) );
}
}

wp_reset_postdata();
return null;
}
Loading