Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/inc/classes/archive-title-renderer.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace Blocksy;
4 +
5 + class ArchiveTitleRenderer {
6 + private $has_label = false;
7 +
8 + public function __construct($args = []) {
9 + $args = wp_parse_args($args, [
10 + 'has_label' => false
11 + ]);
12 +
13 + $this->has_label = $args['has_label'];
14 + }
15 +
16 + public function render_title($title, $original_title, $prefix) {
17 + if (! $this->has_label) {
18 + return $original_title;
19 + }
20 +
21 + return blocksy_html_tag(
22 + 'span',
23 + [
24 + 'class' => 'ct-title-label'
25 + ],
26 + rtrim(trim($prefix), ':')
27 + ) . ' ' . $original_title;
28 + }
29 +
30 + public function get_the_archive_title() {
31 + $this->start_rendering();
32 +
33 + $title = get_the_archive_title();
34 +
35 + $this->finish_rendering();
36 +
37 + return $title;
38 + }
39 +
40 + private function start_rendering() {
41 + add_filter(
42 + 'get_the_archive_title',
43 + [$this, 'render_title'],
44 +
45 + // Start rendering early, so that someone that alters the title
46 + // later will get our changes.
47 + 1,
48 + 3
49 + );
50 + }
51 +
52 + private function finish_rendering() {
53 + remove_filter(
54 + 'get_the_archive_title',
55 + [$this, 'render_title'],
56 +
57 + // Start rendering early, so that someone that alters the title
58 + // later will get our changes.
59 + 1,
60 + 3
61 + );
62 + }
63 + }
64 +