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 / Plugin / Plugin.php
wp-parsidate / inc / Plugin Last commit date
Install.php 3 weeks ago Plugin.php 3 weeks ago
Plugin.php
118 lines
1 <?php
2 /**
3 * Plugin hooks
4 *
5 * Load local text domain, Add starter notice, Change some links
6 */
7
8 namespace WPParsidate\Plugin;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use WPParsidate\Helper\Param;
13 use WPParsidate\Settings\Settings;
14
15 class Plugin {
16 public function __construct() {
17 add_filter( 'plugin_action_links_' . plugin_basename( WP_PARSI_ROOT ), [ $this, 'pluginActionLink' ] );
18 add_filter( 'login_headerurl', [ $this, 'changeLoginLink' ], 10, 2 );
19 add_action( 'admin_notices', [ $this, 'activationAdminNotice' ] );
20 add_action( 'admin_init', [ $this, 'dismissActivationNotice' ] );
21 add_action( 'init', [ $this, 'loadTextDomain' ], - 1 );
22 add_filter( 'http_request_args', [ $this, 'limitWpParsiTimeout' ], 10, 2 );
23 }
24
25 /**
26 * Limits the timeout for requests to wp-parsi.com to prevent dashboard lag.
27 *
28 * @param array $args Request arguments.
29 * @param string $url Request URL.
30 *
31 * @return array Modified request arguments.
32 */
33 public function limitWpParsiTimeout( array $args, string $url ): array {
34 if ( str_contains( $url, 'wp-parsi.com' ) ) {
35 $args['timeout'] = 3;
36 }
37
38 return $args;
39 }
40
41 /**
42 * Load plugin translations from the local languages directory.
43 *
44 * Always loads the local .mo file so that newly added/translated strings
45 * are available immediately, even before they're published on translate.wordpress.org.
46 * Uses determine_locale() instead of hardcoding 'fa_IR' for multi-locale flexibility.
47 */
48 public function loadTextDomain(): void {
49 if ( __( 'WordPress', 'wp-parsidate' ) !== 'وردپرس' || Settings::get( 'local_text_domain', false )) {
50 load_textdomain(
51 'wp-parsidate',
52 WP_PARSI_DIR . 'languages/wp-parsidate-' . determine_locale() . '.mo'
53 );
54 }
55 }
56
57 /**
58 * Notice for the activation.
59 * Added dismiss feature.
60 *
61 * @return void
62 * @author Ehsaan
63 */
64 public function activationAdminNotice(): void {
65 $dismissed = Settings::get( 'activation_admin_notice_dismissed', false );
66
67 if ( ! $dismissed && ( ! isset( $_GET['page'] ) || WP_PARSI_KEY_SLUG !== Param::get( 'page' ) ) &&
68 ! Settings::get( 'persian_date', false ) ) {
69 $dismiss_url = wp_nonce_url( add_query_arg( 'wpp-action', 'dismiss-active-notice' ), 'wpp_dismiss_notice' );
70
71 /* translators: 1: ParsiDate settings link, 2: Dismiss notice link */
72 $message = __( '<div class="updated wpp-message"><p>ParsiDate activated, you may need to configure it to work properly. <a href="%1$s">Go to configuration page</a> &ndash; <a href="%2$s">Dismiss</a></p></div>',
73 'wp-parsidate' );
74 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
75 echo sprintf( $message,
76 esc_url_raw( menu_page_url( WP_PARSI_KEY_SLUG, false ) ),
77 esc_url_raw( $dismiss_url ),
78 );
79 }
80 }
81
82 /**
83 * Dismiss the notice action
84 *
85 * @return void
86 * @author Ehsaan
87 */
88 public function dismissActivationNotice(): void {
89 if ( isset( $_GET['wpp-action'] ) && Param::get( 'wpp-action' ) === 'dismiss-active-notice' ) {
90 check_admin_referer( 'wpp_dismiss_notice' );
91 Settings::save( 'activation_admin_notice_dismissed', true );
92 }
93 }
94
95 /**
96 * Change login header url in wp-login.php & Widget primary link
97 *
98 * @return string
99 */
100 public function changeLoginLink(): string {
101 return 'https://wp-parsi.com';
102 }
103
104 /**
105 * Add setting link to admin plugins
106 *
107 * @param array $links
108 *
109 * @return array
110 */
111 public static function pluginActionLink( $links ): array {
112 $links[] = '<a href="' . menu_page_url( WP_PARSI_KEY_SLUG, false ) . '">' .
113 esc_html__( 'Settings', 'wp-parsidate' ) . '</a>';
114
115 return $links;
116 }
117 }
118