PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / trunk
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz vtrunk
2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / compatibility / multilingual / multilingual-manager.php
sureforms / inc / compatibility / multilingual Last commit date
providers 3 weeks ago multilingual-manager.php 2 months ago string-backfill.php 3 weeks ago string-collector.php 3 weeks ago string-translator.php 3 weeks ago
multilingual-manager.php
96 lines
1 <?php
2 /**
3 * Multilingual Manager.
4 *
5 * Resolves the active multilingual provider (WPML for v1). Returns Null_Provider when
6 * no supported multilingual plugin is active, so call sites can stay free of conditionals.
7 *
8 * @package sureforms.
9 * @since 2.11.0
10 */
11
12 namespace SRFM\Inc\Compatibility\Multilingual;
13
14 use SRFM\Inc\Compatibility\Multilingual\Providers\Null_Provider;
15 use SRFM\Inc\Compatibility\Multilingual\Providers\Provider;
16 use SRFM\Inc\Compatibility\Multilingual\Providers\WPML_Provider;
17 use SRFM\Inc\Traits\Get_Instance;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit; // Exit if accessed directly.
21 }
22
23 /**
24 * Multilingual_Manager.
25 *
26 * Resolves the active multilingual provider (WPML for v1). Returns Null_Provider when
27 * no supported multilingual plugin is active.
28 *
29 * @since 2.11.0
30 */
31 class Multilingual_Manager {
32 use Get_Instance;
33
34 /**
35 * Resolved provider instance.
36 *
37 * @since 2.11.0
38 * @var Provider
39 */
40 private $provider;
41
42 /**
43 * Constructor. Resolves and caches the active multilingual provider.
44 *
45 * @since 2.11.0
46 */
47 public function __construct() {
48 $this->provider = $this->resolve_provider();
49 }
50
51 /**
52 * Get the resolved multilingual provider.
53 *
54 * @since 2.11.0
55 * @return Provider Active provider instance, or Null_Provider when none is available.
56 */
57 public function provider(): Provider {
58 return $this->provider;
59 }
60
61 /**
62 * Resolve which provider to use based on the active multilingual plugin.
63 *
64 * Resolution order:
65 * 1. WPML_Provider when WPML 4.5+ is active.
66 * 2. Null_Provider otherwise.
67 * 3. The `srfm_multilingual_provider` filter may override the default with any
68 * {@see Provider} implementation; non-conforming values are ignored.
69 *
70 * @since 2.11.0
71 * @return Provider Resolved provider instance.
72 */
73 protected function resolve_provider(): Provider {
74 $wpml = new WPML_Provider();
75
76 $provider = $wpml->is_active() ? $wpml : new Null_Provider();
77
78 /**
79 * Filter the resolved multilingual provider.
80 *
81 * Third parties can return their own {@see Provider} implementation to
82 * replace SureForms' default resolution. Non-conforming return values are ignored.
83 *
84 * @since 2.11.0
85 * @param Provider $provider The resolved provider instance.
86 */
87 $filtered = apply_filters( 'srfm_multilingual_provider', $provider );
88
89 if ( $filtered instanceof Provider ) {
90 return $filtered;
91 }
92
93 return $provider;
94 }
95 }
96