PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / 6.2.1
پارسی دیت – Parsi Date v6.2.1
6.2.1 6.2 6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / inc / App / Core / FixTitle.php
wp-parsidate / inc / App / Core Last commit date
Core.php 3 weeks ago Debug.php 3 weeks ago FixDates.php 3 weeks ago FixPermalink.php 3 weeks ago FixTitle.php 3 weeks ago ShamsiDate.php 3 weeks ago
FixTitle.php
71 lines
1 <?php
2 /**
3 * Fix title settings
4 *
5 * Fix page title
6 */
7
8 namespace WPParsidate\App\Core;
9
10 use WPParsidate\Core\Names;
11 use WPParsidate\Helper\Number;
12 use WPParsidate\Settings\Settings;
13
14 class FixTitle {
15 public function __construct() {
16 add_filter( 'wp_title', [ $this, 'fixWpTitle' ], PHP_INT_MAX, 3 );
17 add_filter( 'pre_get_document_title', [ $this, 'fixWpTitle' ], PHP_INT_MAX ); // WP 4.4+
18 }
19
20 /**
21 * Fixes titles for archives
22 *
23 * @param string|null $title Archive title.
24 * @param string $sep Separator.
25 * @param string $seplocation Separator location.
26 *
27 * @return string
28 */
29 public function fixWpTitle( ?string $title, $sep = '-', $seplocation = 'right' ): string {
30 global $wp_query;
31
32 // pre_get_document_title may return null.
33 $title ??= '';
34
35 /**
36 * Filters the separator for the document title.
37 *
38 * @since WP 4.4.0
39 *
40 * @param string $sep Document title separator. Default '-'.
41 */
42 $sep = apply_filters( 'document_title_separator', $sep );
43
44 $query = $wp_query->query ?? [];
45
46 if ( ! is_archive() || ! Settings::get( 'persian_date', false ) ) {
47 return $title;
48 }
49
50 if ( $seplocation === 'right' ) {
51 $query = array_reverse( $query );
52 }
53
54 if ( isset( $query['monthnum'] ) ) {
55 $monthsName = Names::getMonths();
56
57 if ( isset( $monthsName[ (int) $query['monthnum'] ] ) ) {
58 $query['monthnum'] = $monthsName[ (int) $query['monthnum'] ];
59 }
60
61 $title = implode( ' ', $query ) . " $sep " . get_bloginfo( 'name' );
62 }
63
64 if ( Settings::get( 'conv_page_title', false ) ) {
65 $title = Number::fixNumber( $title );
66 }
67
68 return (string) $title;
69 }
70 }
71