editor = $editor; } public function register(): void { add_action('admin_menu', [$this, 'menu'], 21); add_action('admin_post_' . self::ACTION_DELETE, [$this, 'handle_delete']); } public static function url(array $args = []): string { return add_query_arg(array_merge(['page' => self::SLUG], $args), admin_url('admin.php')); } public function menu(): void { add_submenu_page('zadex', __('Components', 'zadex'), __('Components', 'zadex'), 'edit_posts', self::SLUG, [$this, 'render']); } public function delete_url(int $id): string { return wp_nonce_url(add_query_arg(['action' => self::ACTION_DELETE, 'id' => $id], admin_url('admin-post.php')), self::ACTION_DELETE . '_' . $id); } public static function kind_label(string $kind): string { return $kind === 'widget' ? __('Global widget', 'zadex') : __('Component', 'zadex'); } public function render(): void { if (!current_user_can('edit_posts')) { return; } $posts = ComponentPost::all(); ?>

ID; $usage = Usage::count($id); $edit = $this->editor->edit_url($id); $warning = $usage > 0 /* translators: %d: number of pages */ ? sprintf(_n('This component is used on %d page. Its instances will disappear from it. Delete it permanently?', 'This component is used on %d pages. Its instances will disappear from them. Delete it permanently?', $usage, 'zadex'), $usage) : __('Delete this component permanently?', 'zadex'); ?>
post_title !== '' ? $post->post_title : __('(no title)', 'zadex')); ?> post_modified ?? $post->post_modified_gmt)); ?>
delete($id); Notices::add(self::SLUG, __('Component deleted.', 'zadex')); wp_safe_redirect($url); exit; } /** Capability + nonce check, delete; returns the redirect URL. */ public function delete(int $id): string { if ($id <= 0 || !ComponentPost::exists($id) || !current_user_can('delete_post', $id)) { wp_die(esc_html__('Not allowed.', 'zadex'), 403); } check_admin_referer(self::ACTION_DELETE . '_' . $id); wp_delete_post($id, true); ComponentPost::reset_cache($id); return self::url(); } }