PluginProbe
Polylang / 3.2
Polylang v3.2
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 / include / rest-request.php

rest-request.php in Polylang 3.2, at include/rest-request.php

94 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 /**
7 * Main Polylang class for REST API requrests, accessible from @see PLL().
8 *
9 * @since 2.6
10 */
11 class PLL_REST_Request extends PLL_Base {
12 /**
13 * @var PLL_Language|false|null A `PLL_Language` when defined, `false` otherwise. `null` until the language
14 * definition process runs.
15 */
16 public $curlang;
17
18 /**
19 * @var PLL_Filters|null
20 */
21 public $filters;
22
23 /**
24 * @var PLL_Filters_Links|null
25 */
26 public $filters_links;
27
28 /**
29 * @var PLL_Admin_Links|null
30 */
31 public $links;
32
33 /**
34 * @var PLL_Nav_Menu|null
35 */
36 public $nav_menu;
37
38 /**
39 * @var PLL_Static_Pages|null
40 */
41 public $static_pages;
42
43 /**
44 * @var PLL_Filters_Widgets_Options|null
45 */
46 public $filters_widgets_options;
47
48 /**
49 * Setup filters.
50 *
51 * @since 2.6
52 *
53 * @return void
54 */
55 public function init() {
56 parent::init();
57
58 if ( ! $this->model->get_languages_list() ) {
59 return;
60 }
61
62 if ( ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
63 if ( is_string( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
64 $this->curlang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
65 }
66
67 if ( empty( $this->curlang ) && ! empty( $this->options['default_lang'] ) && is_string( $this->options['default_lang'] ) ) {
68 // A lang has been requested but it is invalid, let's fall back to the default one.
69 $this->curlang = $this->model->get_language( sanitize_key( $this->options['default_lang'] ) );
70 }
71 }
72
73 if ( ! empty( $this->curlang ) ) {
74 /** This action is documented in frontend/choose-lang.php */
75 do_action( 'pll_language_defined', $this->curlang->slug, $this->curlang );
76 } else {
77 /** This action is documented in include/class-polylang.php */
78 do_action( 'pll_no_language_defined' ); // To load overridden textdomains.
79 }
80
81 $this->filters_links = new PLL_Filters_Links( $this );
82 $this->filters = new PLL_Filters( $this );
83 $this->filters_widgets_options = new PLL_Filters_Widgets_Options( $this );
84
85 // Static front page and page for posts.
86 if ( 'page' === get_option( 'show_on_front' ) ) {
87 $this->static_pages = new PLL_Static_Pages( $this );
88 }
89
90 $this->links = new PLL_Admin_Links( $this );
91 $this->nav_menu = new PLL_Nav_Menu( $this ); // For auto added pages to menu.
92 }
93 }
94