id, Menu::screen_ids(), true ); } // End is_plugin_screen() /** * Verify an AJAX request's nonce and capability, ending the request on failure. * * @param string $nonce_action * @param string $capability * @return void */ public static function verify_ajax( string $nonce_action, string $capability = 'manage_options' ) : void { check_ajax_referer( $nonce_action, 'nonce' ); if ( ! current_user_can( $capability ) ) { wp_send_json_error( __( 'You do not have permission to do that.', 'deadbolt' ), 403 ); } } // End verify_ajax() /** * Get the visitor's query string arguments to carry between the restricted page and the No Access Page. * WordPress query vars, such as page_id, are left out so they never change which page loads. * * @return array Sanitized key => value pairs. */ public static function carry_query_args() : array { global $wp; $query = wp_unslash( $_GET ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- read-only carryover of the visitor's query string; each key and value is sanitized below. $skip = array_merge( [ 'no_access', 'cb' ], isset( $wp->public_query_vars ) ? (array) $wp->public_query_vars : [] ); $carry = []; foreach ( (array) $query as $key => $value ) { $key = sanitize_key( $key ); if ( '' !== $key && is_scalar( $value ) && ! in_array( $key, $skip, true ) ) { $carry[ $key ] = sanitize_text_field( (string) $value ); } } return (array) apply_filters( 'deadbolt_carry_query_args', $carry ); } // End carry_query_args() /** * Get all public post types that can be restricted. * * @return array Associative array of slug => WP_Post_Type. */ public static function public_post_types() : array { $types = get_post_types( [ 'public' => true ], 'objects' ); unset( $types[ 'attachment' ] ); return $types; } // End public_post_types() /** * Get every role on the site with translated labels. * * @return array Associative array of slug => label. */ public static function all_roles() : array { static $roles = null; if ( null !== $roles ) { return $roles; } $roles = []; foreach ( wp_roles()->role_names as $slug => $name ) { $roles[ $slug ] = translate_user_role( $name ); } return $roles; } // End all_roles() /** * Get display names for a list of user IDs. * * @param array $user_ids * @return array Associative array of ID => display name. */ public static function user_labels( array $user_ids ) : array { $user_ids = array_filter( array_map( 'absint', $user_ids ) ); if ( empty( $user_ids ) ) { return []; } $users = get_users( [ 'include' => $user_ids, 'fields' => [ 'ID', 'display_name' ], 'orderby' => 'include', ] ); $labels = []; foreach ( $users as $user ) { $labels[ (int) $user->ID ] = $user->display_name; } return $labels; } // End user_labels() /** * Render a tooltip icon with hover text, matching Admin Help Docs' pattern. * * @param string $text * @return void */ public static function tooltip( string $text ) : void { if ( '' === $text ) { return; } ?> label. * @param string $placeholder * @return void */ public static function render_picker( string $source, string $name, array $selected, string $placeholder ) : void { ?>