Rebuild Thumbnails. * * The screen is built from the components WordPress already ships - postboxes, * list tables, form tables, notices - so it looks and behaves like the rest of * the admin rather than like a plugin with opinions of its own. * * @package ajax-thumbnail-rebuild */ if ( ! defined( 'ABSPATH' ) ) { exit; } class ATR_Admin_Page { const SLUG = 'ajax-thumbnail-rebuild'; /** Hook suffix of the page, for admin_enqueue_scripts. */ private string $hook_suffix = ''; public function register(): void { $this->hook_suffix = (string) add_management_page( __( 'Rebuild Thumbnails', 'ajax-thumbnail-rebuild' ), __( 'Rebuild Thumbnails', 'ajax-thumbnail-rebuild' ), ATR_Plugin::capability(), self::SLUG, array( $this, 'render' ) ); } public function hook_suffix(): string { return $this->hook_suffix; } public static function url( string $tab = '' ): string { $args = array( 'page' => self::SLUG ); if ( '' !== $tab ) { $args['tab'] = $tab; } return add_query_arg( $args, admin_url( 'tools.php' ) ); } /** * Every tab on the screen: what it is called and what it shows. * * @return array */ private function tabs(): array { $tabs = array( 'rebuild' => __( 'Rebuild', 'ajax-thumbnail-rebuild' ), 'sizes' => __( 'Registered sizes', 'ajax-thumbnail-rebuild' ), 'cleanup' => __( 'Cleanup', 'ajax-thumbnail-rebuild' ), 'largest' => __( 'Largest images', 'ajax-thumbnail-rebuild' ), ); /* The settings are a tab each. All of them on one page was a wall of fields nobody could find anything in. */ foreach ( ATR_Settings::pages() as $page => $settings ) { $tabs[ $page ] = $settings['label']; } return $tabs; } private function current_tab(): string { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only navigation. $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'rebuild'; return array_key_exists( $tab, $this->tabs() ) ? $tab : 'rebuild'; } public function render(): void { if ( ! current_user_can( ATR_Plugin::capability() ) ) { wp_die( esc_html__( 'You are not allowed to rebuild thumbnails.', 'ajax-thumbnail-rebuild' ) ); } $tab = $this->current_tab(); $sizes = ATR_Image_Sizes::all(); ?>

render_sizes_tab( $sizes ); ?> render_cleanup_tab(); ?> render_largest_tab(); ?> render_settings_tab( $tab ); ?> render_rebuild_tab( $sizes ); ?>
$sizes */ private function render_rebuild_tab( array $sizes ): void { ?>

' . esc_html( number_format_i18n( count( $selected ) ) ) . '' ); ?>

' . esc_html( number_format_i18n( $total ) ) . '' ); ?>

' . esc_html( number_format_i18n( $total ) ) . '' ); ?>

' . esc_html( number_format_i18n( $total ) ) . '' ); ?>

' . esc_html( (string) wp_parse_url( home_url(), PHP_URL_HOST ) ) . '' ); ?>

render_settings_sections( ATR_Settings::page_slug( $page ) ); ?>

$sizes */ private function render_sizes_tab( array $sizes ): void { ?>
0 ? number_format_i18n( $size['width'] ) : __( 'any', 'ajax-thumbnail-rebuild' ) ); ?> 0 ? number_format_i18n( $size['height'] ) : __( 'any', 'ajax-thumbnail-rebuild' ) ); ?>