PluginProbe
Age Gate / 3.7.3
Age Gate v3.7.3
3.7.3 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 All 113 releases
age-gate / src / Presentation / Title.php

Title.php in Age Gate 3.7.3, at src/Presentation/Title.php

85 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AgeGate\Presentation;
4
5 use AgeGate\Common\Content;
6 use AgeGate\Common\Settings;
7
8 class Title
9 {
10 private $settings;
11
12 private $content;
13
14 public function __construct(Content $content, Settings $settings)
15 {
16 $this->settings = $settings;
17 $this->content = $content;
18
19 if ($settings->method !== 'js' && $settings->switchTitle) {
20 add_filter('wpseo_title', [$this, 'returnPageTitle'], 1000, 1);
21 add_filter('rank_math/frontend/title', [$this, 'returnPageTitle'], 1000, 1);
22 add_filter('document_title_parts', [$this, 'changePageTitle'], 1000, 1);
23 add_filter('wp_title', [$this, 'changeDefaultTitle'], 10, 3);
24 }
25
26 }
27
28 public function getTitle()
29 {
30 return $this->settings->customTitle . ' - ' . get_bloginfo('name');
31 }
32
33 /**
34 * Change the page title for themes with theme_support
35 * for title-tag
36 *
37 * @return array
38 */
39 public function changePageTitle($title = [])
40 {
41 if ($this->content->isRestricted()) {
42 return [
43 'title' => $this->settings->customTitle,
44 'site' => get_bloginfo('name'),
45 ];
46 }
47
48 return $title;
49 }
50
51 /**
52 * Change the title for themes that
53 * do not support title tag
54 *
55 * @param string $title
56 * @param string $sep
57 * @param string $location
58 * @return string
59 */
60 public function changeDefaultTitle($title, $sep, $location)
61 {
62
63 if ($this->content->isRestricted()) {
64 return $this->getTitle();
65 }
66
67 return $title;
68 }
69
70 /**
71 * Change the parts sent to Yoast or Think Math
72 *
73 * @return void
74 */
75 public function returnPageTitle($title)
76 {
77 if ($this->content->isRestricted()) {
78 return $this->getTitle();
79 }
80
81 return $title;
82 }
83
84 }
85