PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / trunk
پارسی دیت – Parsi Date vtrunk
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 / Tools / Other.php
wp-parsidate / inc / App / Tools Last commit date
HookDeactivator.php 1 month ago Other.php 1 month ago Tools.php 1 month ago
Other.php
83 lines
1 <?php
2
3 namespace WPParsidate\App\Tools;
4
5 use WPParsidate\Helper\Debug;
6 use WPParsidate\Settings\Settings;
7
8 class Other {
9 private const sectionID = 'other';
10
11 public function __construct() {
12 add_filter( 'wp_parsidate_tools_settings_sections', [ $this, 'addSectionSettings' ] );
13
14 if ( Settings::get( 'date_in_admin_bar', false ) ) {
15 add_action( 'admin_bar_menu', [ $this, 'addDateToAdminBar' ], PHP_INT_MAX );
16 add_action( 'admin_head', [ $this, 'adminBarDateStyle' ] );
17 }
18 }
19
20 /**
21 * Add Jalali date to WordPress admin bar
22 *
23 * @param $adminBar
24 *
25 * @return void
26 */
27 public function addDateToAdminBar( $adminBar ): void {
28 $format = Debug::plugin() ? 'l Y/m/d H:i:s' : 'l Y/m/d';
29 //$currentDate = parsidate( $format, current_time( 'timestamp' ) );
30 $currentDate = wp_date( $format, time() );
31
32 $args = array(
33 'id' => 'wpp_current_date',
34 'title' => esc_html__( 'Today:&nbsp;', 'wp-parsidate' ) . $currentDate,
35 'meta' => array( 'class' => 'wpp-admin-bar-date' ),
36 );
37
38 $adminBar->add_node( $args );
39 }
40
41 public function adminBarDateStyle(): void {
42 global $_wp_admin_css_colors;
43 $color = get_user_option( 'admin_color' );
44 $bgColor = $_wp_admin_css_colors[ $color ]->colors[2] ?? '#2271b1';
45
46 echo '<style>
47 .wpp-admin-bar-date {
48 color: #fff !important;
49 background-color: ' . esc_html( $bgColor ) . ' !important;
50 unicode-bidi: embed !important;
51 }
52 </style>';
53 }
54
55 public function addSectionSettings( array $sections ): array {
56 $settings = [
57 'start_grid_admin_bar' => array(
58 'title' => esc_html__( 'Admin Bar', 'wp-parsidate' ),
59 'type' => 'startGrid',
60 ),
61 'date_in_admin_bar' => array(
62 'id' => 'date_in_admin_bar',
63 'title' => esc_html__( 'Display date in the admin bar', 'wp-parsidate' ),
64 'type' => 'toggle',
65 'default' => false,
66 'desc' => esc_html__( "Display today's Jalali date in the WordPress admin bar.", 'wp-parsidate' ),
67 'sanitize' => 'bool'
68 ),
69 'end_grid_admin_bar' => array(
70 'type' => 'endGrid',
71 ),
72 ];
73
74 $sections[ self::sectionID ] = array(
75 'title' => esc_html__( 'Other tools', 'wp-parsidate' ),
76 'desc' => esc_html__( 'Other tools', 'wp-parsidate' ),
77 'settings' => $settings
78 );
79
80 return $sections;
81 }
82 }
83