| 1 |
<?php |
| 2 |
|
| 3 |
namespace ElementorOne\Admin\Components; |
| 4 |
|
| 5 |
use ElementorOne\Admin\Helpers\Utils; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Class Fields |
| 13 |
* Handles WordPress settings registration |
| 14 |
*/ |
| 15 |
class Fields { |
| 16 |
|
| 17 |
const SETTING_PREFIX = 'elementor_one_'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Instance |
| 21 |
* @var Fields|null |
| 22 |
*/ |
| 23 |
private static ?Fields $instance = null; |
| 24 |
|
| 25 |
/** |
| 26 |
* Get instance |
| 27 |
* @return Fields|null |
| 28 |
*/ |
| 29 |
public static function instance(): ?Fields { |
| 30 |
if ( ! self::$instance ) { |
| 31 |
self::$instance = new self(); |
| 32 |
} |
| 33 |
return self::$instance; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Register fields |
| 38 |
* @return void |
| 39 |
*/ |
| 40 |
public function register_fields() { |
| 41 |
foreach ( $this->get_settings() as $setting => $args ) { |
| 42 |
register_setting( 'options', self::SETTING_PREFIX . $setting, $args ); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Get settings |
| 48 |
* @return array |
| 49 |
*/ |
| 50 |
public static function get_settings(): array { |
| 51 |
return [ |
| 52 |
'welcome_screen_completed' => [ |
| 53 |
'type' => 'boolean', |
| 54 |
'show_in_rest' => true, |
| 55 |
'description' => 'Elementor One Welcome Screen Completed', |
| 56 |
], |
| 57 |
'dismiss_connect_alert' => [ |
| 58 |
'type' => 'boolean', |
| 59 |
'single' => true, |
| 60 |
'show_in_rest' => true, |
| 61 |
'description' => 'Elementor One Dismiss Connect Alert', |
| 62 |
], |
| 63 |
'editor_update_notification_dismissed' => [ |
| 64 |
'type' => 'boolean', |
| 65 |
'show_in_rest' => true, |
| 66 |
'description' => 'Elementor One Dismiss Editor Update Notification', |
| 67 |
], |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Get plugin settings |
| 73 |
* @return array |
| 74 |
*/ |
| 75 |
public function get_plugin_settings(): array { |
| 76 |
$connect_utils = Utils::get_one_connect()->utils(); |
| 77 |
|
| 78 |
return [ |
| 79 |
'siteName' => get_bloginfo( 'name' ), |
| 80 |
'activeTheme' => wp_get_theme()->get( 'Name' ), |
| 81 |
'isConnected' => $connect_utils->is_connected(), |
| 82 |
'isUrlMismatch' => ! $connect_utils->is_valid_home_url(), |
| 83 |
'isDevelopment' => defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG, |
| 84 |
'siteUrl' => get_site_url(), |
| 85 |
'welcomeScreenCompleted' => (bool) get_option( self::SETTING_PREFIX . 'welcome_screen_completed' ), |
| 86 |
'dismissConnectAlert' => (bool) get_option( self::SETTING_PREFIX . 'dismiss_connect_alert' ), |
| 87 |
'editorUpdateNotificationDismissed' => (bool) get_option( self::SETTING_PREFIX . 'editor_update_notification_dismissed' ), |
| 88 |
'userLocale' => get_user_locale( get_current_user_id() ), |
| 89 |
'isRTL' => is_rtl(), |
| 90 |
]; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Fields constructor |
| 95 |
* @return void |
| 96 |
*/ |
| 97 |
private function __construct() { |
| 98 |
add_action( 'rest_api_init', [ $this, 'register_fields' ] ); |
| 99 |
} |
| 100 |
} |
| 101 |
|