PluginProbe
Polylang / 3.8.6
Polylang v3.8.6
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / src / Options / Business / Hide_Default.php

Hide_Default.php in Polylang 3.8.6, at src/Options/Business/Hide_Default.php

99 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 namespace WP_Syntex\Polylang\Options\Business;
7
8 use WP_Error;
9 use WP_Syntex\Polylang\Options\Primitive\Abstract_Boolean;
10 use WP_Syntex\Polylang\Options\Options;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Class defining the "Display/Hide URL language information for default language" boolean option.
16 * /!\ Sanitization depends on `force_lang`: this option must be set AFTER `force_lang`.
17 *
18 * @since 3.7
19 */
20 class Hide_Default extends Abstract_Boolean {
21 /**
22 * Returns option key.
23 *
24 * @since 3.7
25 *
26 * @return string
27 *
28 * @phpstan-return 'hide_default'
29 */
30 public static function key(): string {
31 return 'hide_default';
32 }
33
34 /**
35 * Adds information to the site health info array.
36 *
37 * @since 3.8
38 *
39 * @param Options $options An instance of the Options class providing additional configuration.
40 *
41 * @return array The updated site health information.
42 */
43 public function get_site_health_info( Options $options ): array { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
44 if ( $this->get() ) {
45 $value = '1: ' . __( 'Hide URL language information for default language', 'polylang' );
46 } else {
47 $value = '0: ' . __( 'Display URL language information for default language', 'polylang' );
48 }
49
50 return $this->format_single_value_for_site_health_info( $value );
51 }
52 /**
53 * Returns the default value.
54 *
55 * @since 3.7
56 *
57 * @return bool
58 */
59 protected function get_default() {
60 return true;
61 }
62
63 /**
64 * Sanitizes option's value.
65 * Can populate the `$errors` property with blocking and non-blocking errors: in case of non-blocking errors,
66 * the value is sanitized and can be stored.
67 *
68 * @since 3.7
69 *
70 * @param bool $value Value to sanitize.
71 * @param Options $options All options.
72 * @return bool|WP_Error The sanitized value. An instance of `WP_Error` in case of blocking error.
73 */
74 protected function sanitize( $value, Options $options ) {
75 if ( 3 === $options->get( 'force_lang' ) ) {
76 return false;
77 }
78
79 /** @var bool|WP_Error */
80 return parent::sanitize( $value, $options );
81 }
82
83 /**
84 * Returns the description used in the JSON schema.
85 *
86 * @since 3.7
87 *
88 * @return string
89 */
90 protected function get_description(): string {
91 return sprintf(
92 /* translators: %1$s and %2$s are "true/false" values. */
93 __( 'Remove the language code in URL for the default language: %1$s to hide, %2$s to display.', 'polylang' ),
94 '`true`',
95 '`false`'
96 );
97 }
98 }
99