| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
use Elementor\Core\Common\Modules\EventTracker\DB as Events_DB_Manager; |
| 5 |
use Elementor\Core\Experiments\Experiments_Reporter; |
| 6 |
use Elementor\Modules\System_Info\Module as System_Info_Module; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Elementor tracker. |
| 14 |
* |
| 15 |
* Elementor tracker handler class is responsible for sending non-sensitive plugin |
| 16 |
* data to Elementor servers for users that actively allowed data tracking. |
| 17 |
* |
| 18 |
* @since 1.0.0 |
| 19 |
*/ |
| 20 |
class Tracker { |
| 21 |
|
| 22 |
/** |
| 23 |
* API URL. |
| 24 |
* |
| 25 |
* Holds the URL of the Tracker API. |
| 26 |
* |
| 27 |
* @since 1.0.0 |
| 28 |
* @access private |
| 29 |
* |
| 30 |
* @var string API URL. |
| 31 |
*/ |
| 32 |
private static $_api_url = 'https://my.elementor.com/api/v1/tracker/'; |
| 33 |
|
| 34 |
private static $notice_shown = false; |
| 35 |
|
| 36 |
/** |
| 37 |
* Init. |
| 38 |
* |
| 39 |
* Initialize Elementor tracker. |
| 40 |
* |
| 41 |
* @since 1.0.0 |
| 42 |
* @access public |
| 43 |
* @static |
| 44 |
*/ |
| 45 |
public static function init() { |
| 46 |
add_action( 'elementor/tracker/send_event', [ __CLASS__, 'send_tracking_data' ] ); |
| 47 |
add_action( 'admin_init', [ __CLASS__, 'handle_tracker_actions' ] ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Check for settings opt-in. |
| 52 |
* |
| 53 |
* Checks whether the site admin has opted-in for data tracking, or not. |
| 54 |
* |
| 55 |
* @since 1.0.0 |
| 56 |
* @access public |
| 57 |
* @static |
| 58 |
* |
| 59 |
* @param string $new_value Allowed tracking value. |
| 60 |
* |
| 61 |
* @return string Return `yes` if tracking allowed, `no` otherwise. |
| 62 |
*/ |
| 63 |
public static function check_for_settings_optin( $new_value ) { |
| 64 |
$old_value = get_option( 'elementor_allow_tracking', 'no' ); |
| 65 |
if ( $old_value !== $new_value && 'yes' === $new_value ) { |
| 66 |
Plugin::$instance->custom_tasks->add_tasks_requested_to_run( [ |
| 67 |
'opt_in_recalculate_usage', |
| 68 |
'opt_in_send_tracking_data', |
| 69 |
] ); |
| 70 |
} |
| 71 |
|
| 72 |
if ( empty( $new_value ) ) { |
| 73 |
$new_value = 'no'; |
| 74 |
} |
| 75 |
|
| 76 |
return $new_value; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Send tracking data. |
| 81 |
* |
| 82 |
* Decide whether to send tracking data, or not. |
| 83 |
* |
| 84 |
* @since 1.0.0 |
| 85 |
* @access public |
| 86 |
* @static |
| 87 |
* |
| 88 |
* @param bool $override |
| 89 |
*/ |
| 90 |
public static function send_tracking_data( $override = false ) { |
| 91 |
// Don't trigger this on AJAX Requests. |
| 92 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
if ( ! self::is_allow_track() ) { |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
$last_send = self::get_last_send_time(); |
| 101 |
|
| 102 |
/** |
| 103 |
* Tracker override send. |
| 104 |
* |
| 105 |
* Filters whether to override sending tracking data or not. |
| 106 |
* |
| 107 |
* @since 1.0.0 |
| 108 |
* |
| 109 |
* @param bool $override Whether to override default setting or not. |
| 110 |
*/ |
| 111 |
$override = apply_filters( 'elementor/tracker/send_override', $override ); |
| 112 |
|
| 113 |
if ( ! $override ) { |
| 114 |
$last_send_interval = strtotime( '-1 week' ); |
| 115 |
|
| 116 |
/** |
| 117 |
* Tracker last send interval. |
| 118 |
* |
| 119 |
* Filters the interval of between two tracking requests. |
| 120 |
* |
| 121 |
* @since 1.0.0 |
| 122 |
* |
| 123 |
* @param int $last_send_interval A date/time string. Default is `strtotime( '-1 week' )`. |
| 124 |
*/ |
| 125 |
$last_send_interval = apply_filters( 'elementor/tracker/last_send_interval', $last_send_interval ); |
| 126 |
|
| 127 |
// Send a maximum of once per week by default. |
| 128 |
if ( $last_send && $last_send > $last_send_interval ) { |
| 129 |
return; |
| 130 |
} |
| 131 |
} else { |
| 132 |
// Make sure there is at least a 1 hour delay between override sends, we dont want duplicate calls due to double clicking links. |
| 133 |
if ( $last_send && $last_send > strtotime( '-1 hours' ) ) { |
| 134 |
return; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
// Update time first before sending to ensure it is set. |
| 139 |
update_option( 'elementor_tracker_last_send', time() ); |
| 140 |
|
| 141 |
$params = self::get_tracking_data( empty( $last_send ) ); |
| 142 |
|
| 143 |
// Tracking data is used for System Info reports, and events should not be included in System Info reports, |
| 144 |
// so it is added here |
| 145 |
$params['analytics_events'] = self::get_events(); |
| 146 |
|
| 147 |
add_filter( 'https_ssl_verify', '__return_false' ); |
| 148 |
|
| 149 |
wp_safe_remote_post( |
| 150 |
self::$_api_url, |
| 151 |
[ |
| 152 |
'timeout' => 25, |
| 153 |
'blocking' => false, |
| 154 |
// 'sslverify' => false, |
| 155 |
'body' => [ |
| 156 |
'data' => wp_json_encode( $params ), |
| 157 |
], |
| 158 |
] |
| 159 |
); |
| 160 |
|
| 161 |
// After sending the event tracking data, we reset the events table. |
| 162 |
Events_DB_Manager::reset_table(); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Is allow track. |
| 167 |
* |
| 168 |
* Checks whether the site admin has opted-in for data tracking, or not. |
| 169 |
* |
| 170 |
* @since 1.0.0 |
| 171 |
* @access public |
| 172 |
* @static |
| 173 |
*/ |
| 174 |
public static function is_allow_track() { |
| 175 |
return 'yes' === get_option( 'elementor_allow_tracking', 'no' ); |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Handle tracker actions. |
| 180 |
* |
| 181 |
* Check if the user opted-in or opted-out and update the database. |
| 182 |
* |
| 183 |
* Fired by `admin_init` action. |
| 184 |
* |
| 185 |
* @since 1.0.0 |
| 186 |
* @access public |
| 187 |
* @static |
| 188 |
*/ |
| 189 |
public static function handle_tracker_actions() { |
| 190 |
if ( ! isset( $_GET['elementor_tracker'] ) ) { |
| 191 |
return; |
| 192 |
} |
| 193 |
|
| 194 |
if ( 'opt_into' === $_GET['elementor_tracker'] ) { |
| 195 |
check_admin_referer( 'opt_into' ); |
| 196 |
|
| 197 |
self::set_opt_in( true ); |
| 198 |
} |
| 199 |
|
| 200 |
if ( 'opt_out' === $_GET['elementor_tracker'] ) { |
| 201 |
check_admin_referer( 'opt_out' ); |
| 202 |
|
| 203 |
self::set_opt_in( false ); |
| 204 |
} |
| 205 |
|
| 206 |
wp_redirect( remove_query_arg( 'elementor_tracker' ) ); |
| 207 |
exit; |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* @since 2.2.0 |
| 212 |
* @access public |
| 213 |
* @static |
| 214 |
*/ |
| 215 |
public static function is_notice_shown() { |
| 216 |
return self::$notice_shown; |
| 217 |
} |
| 218 |
|
| 219 |
public static function set_opt_in( $value ) { |
| 220 |
if ( $value ) { |
| 221 |
update_option( 'elementor_allow_tracking', 'yes' ); |
| 222 |
self::send_tracking_data( true ); |
| 223 |
} else { |
| 224 |
update_option( 'elementor_allow_tracking', 'no' ); |
| 225 |
update_option( 'elementor_tracker_notice', '1' ); |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Get system reports data. |
| 231 |
* |
| 232 |
* Retrieve the data from system reports. |
| 233 |
* |
| 234 |
* @since 2.0.0 |
| 235 |
* @access private |
| 236 |
* @static |
| 237 |
* |
| 238 |
* @return array The data from system reports. |
| 239 |
*/ |
| 240 |
private static function get_system_reports_data() { |
| 241 |
$reports = Plugin::$instance->system_info->load_reports( System_Info_Module::get_allowed_reports() ); |
| 242 |
|
| 243 |
// The log report should not be sent with the usage data - it is not used and causes bloat. |
| 244 |
if ( isset( $reports['log'] ) ) { |
| 245 |
unset( $reports['log'] ); |
| 246 |
} |
| 247 |
|
| 248 |
$system_reports = []; |
| 249 |
foreach ( $reports as $report_key => $report_details ) { |
| 250 |
$system_reports[ $report_key ] = []; |
| 251 |
foreach ( $report_details['report']->get_report() as $sub_report_key => $sub_report_details ) { |
| 252 |
$system_reports[ $report_key ][ $sub_report_key ] = $sub_report_details['value']; |
| 253 |
} |
| 254 |
} |
| 255 |
return $system_reports; |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* Get last send time. |
| 260 |
* |
| 261 |
* Retrieve the last time tracking data was sent. |
| 262 |
* |
| 263 |
* @since 2.0.0 |
| 264 |
* @access private |
| 265 |
* @static |
| 266 |
* |
| 267 |
* @return int|false The last time tracking data was sent, or false if |
| 268 |
* tracking data never sent. |
| 269 |
*/ |
| 270 |
private static function get_last_send_time() { |
| 271 |
$last_send_time = get_option( 'elementor_tracker_last_send', false ); |
| 272 |
|
| 273 |
/** |
| 274 |
* Tracker last send time. |
| 275 |
* |
| 276 |
* Filters the last time tracking data was sent. |
| 277 |
* |
| 278 |
* @since 1.0.0 |
| 279 |
* |
| 280 |
* @param int|false $last_send_time The last time tracking data was sent, |
| 281 |
* or false if tracking data never sent. |
| 282 |
*/ |
| 283 |
$last_send_time = apply_filters( 'elementor/tracker/last_send_time', $last_send_time ); |
| 284 |
|
| 285 |
return $last_send_time; |
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* Get non elementor post usages. |
| 290 |
* |
| 291 |
* Retrieve the number of posts that not using elementor. |
| 292 |
|
| 293 |
* @return array The number of posts using not used by Elementor grouped by post types |
| 294 |
* and post status. |
| 295 |
*/ |
| 296 |
public static function get_non_elementor_posts_usage() { |
| 297 |
global $wpdb; |
| 298 |
|
| 299 |
$usage = []; |
| 300 |
|
| 301 |
$results = $wpdb->get_results( |
| 302 |
"SELECT `post_type`, `post_status`, COUNT(`ID`) `hits` |
| 303 |
FROM {$wpdb->posts} `p` |
| 304 |
LEFT JOIN {$wpdb->postmeta} `pm` ON(`p`.`ID` = `pm`.`post_id` AND `meta_key` = '_elementor_edit_mode' ) |
| 305 |
WHERE `post_type` != 'elementor_library' AND `meta_value` IS NULL |
| 306 |
GROUP BY `post_type`, `post_status`;" |
| 307 |
); |
| 308 |
|
| 309 |
if ( $results ) { |
| 310 |
foreach ( $results as $result ) { |
| 311 |
$usage[ $result->post_type ][ $result->post_status ] = $result->hits; |
| 312 |
} |
| 313 |
} |
| 314 |
|
| 315 |
return $usage; |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Get posts usage. |
| 320 |
* |
| 321 |
* Retrieve the number of posts using Elementor. |
| 322 |
* |
| 323 |
* @since 2.0.0 |
| 324 |
* @access public |
| 325 |
* @static |
| 326 |
* |
| 327 |
* @return array The number of posts using Elementor grouped by post types |
| 328 |
* and post status. |
| 329 |
*/ |
| 330 |
public static function get_posts_usage() { |
| 331 |
global $wpdb; |
| 332 |
|
| 333 |
$usage = []; |
| 334 |
|
| 335 |
$results = $wpdb->get_results( |
| 336 |
"SELECT `post_type`, `post_status`, COUNT(`ID`) `hits` |
| 337 |
FROM {$wpdb->posts} `p` |
| 338 |
LEFT JOIN {$wpdb->postmeta} `pm` ON(`p`.`ID` = `pm`.`post_id`) |
| 339 |
WHERE `post_type` != 'elementor_library' |
| 340 |
AND `meta_key` = '_elementor_edit_mode' AND `meta_value` = 'builder' |
| 341 |
GROUP BY `post_type`, `post_status`;" |
| 342 |
); |
| 343 |
|
| 344 |
if ( $results ) { |
| 345 |
foreach ( $results as $result ) { |
| 346 |
$usage[ $result->post_type ][ $result->post_status ] = (int) $result->hits; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
return $usage; |
| 351 |
} |
| 352 |
|
| 353 |
/** |
| 354 |
* Get library usage. |
| 355 |
* |
| 356 |
* Retrieve the number of Elementor library items saved. |
| 357 |
* |
| 358 |
* @since 2.0.0 |
| 359 |
* @access public |
| 360 |
* @static |
| 361 |
* |
| 362 |
* @return array The number of Elementor library items grouped by post types |
| 363 |
* and meta value. |
| 364 |
*/ |
| 365 |
public static function get_library_usage() { |
| 366 |
global $wpdb; |
| 367 |
|
| 368 |
$usage = []; |
| 369 |
|
| 370 |
$results = $wpdb->get_results( |
| 371 |
"SELECT `meta_value`, COUNT(`ID`) `hits` |
| 372 |
FROM {$wpdb->posts} `p` |
| 373 |
LEFT JOIN {$wpdb->postmeta} `pm` ON(`p`.`ID` = `pm`.`post_id`) |
| 374 |
WHERE `post_type` = 'elementor_library' |
| 375 |
AND `meta_key` = '_elementor_template_type' |
| 376 |
GROUP BY `post_type`, `meta_value`;" |
| 377 |
); |
| 378 |
|
| 379 |
if ( $results ) { |
| 380 |
foreach ( $results as $result ) { |
| 381 |
$usage[ $result->meta_value ] = $result->hits; |
| 382 |
} |
| 383 |
} |
| 384 |
|
| 385 |
return $usage; |
| 386 |
|
| 387 |
} |
| 388 |
|
| 389 |
/** |
| 390 |
* Get usage of general settings. |
| 391 |
* 'Elementor->Settings->General'. |
| 392 |
* |
| 393 |
* @return array |
| 394 |
*/ |
| 395 |
public static function get_settings_general_usage() { |
| 396 |
return self::get_tracking_data_from_settings( 'general' ); |
| 397 |
} |
| 398 |
|
| 399 |
/** |
| 400 |
* Get usage of advanced settings. |
| 401 |
* 'Elementor->Settings->Advanced'. |
| 402 |
* |
| 403 |
* @return array |
| 404 |
*/ |
| 405 |
public static function get_settings_advanced_usage() { |
| 406 |
return self::get_tracking_data_from_settings( 'advanced' ); |
| 407 |
} |
| 408 |
|
| 409 |
/** |
| 410 |
* Get usage of experiments settings. |
| 411 |
* |
| 412 |
* 'Elementor->Settings->Experiments'. |
| 413 |
* |
| 414 |
* @return array |
| 415 |
*/ |
| 416 |
public static function get_settings_experiments_usage() { |
| 417 |
$system_info = Plugin::$instance->system_info; |
| 418 |
|
| 419 |
/** |
| 420 |
* @var $experiments_report Experiments_Reporter |
| 421 |
*/ |
| 422 |
$experiments_report = $system_info->create_reporter( [ |
| 423 |
'class_name' => Experiments_Reporter::class, |
| 424 |
] ); |
| 425 |
|
| 426 |
return $experiments_report->get_experiments()['value']; |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* Get usage of general tools. |
| 431 |
* 'Elementor->Tools->General'. |
| 432 |
* |
| 433 |
* @return array |
| 434 |
*/ |
| 435 |
public static function get_tools_general_usage() { |
| 436 |
return self::get_tracking_data_from_tools( 'general' ); |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* Get usage of 'version control' tools. |
| 441 |
* 'Elementor->Tools->Version Control'. |
| 442 |
* |
| 443 |
* @return array |
| 444 |
*/ |
| 445 |
public static function get_tools_version_control_usage() { |
| 446 |
return self::get_tracking_data_from_tools( 'versions' ); |
| 447 |
} |
| 448 |
|
| 449 |
/** |
| 450 |
* Get usage of 'maintenance' tools. |
| 451 |
* 'Elementor->Tools->Maintenance'. |
| 452 |
* |
| 453 |
* @return array |
| 454 |
*/ |
| 455 |
public static function get_tools_maintenance_usage() { |
| 456 |
return self::get_tracking_data_from_tools( 'maintenance_mode' ); |
| 457 |
} |
| 458 |
|
| 459 |
/** |
| 460 |
* Get library usage extend. |
| 461 |
* |
| 462 |
* Retrieve the number of Elementor library items saved. |
| 463 |
* |
| 464 |
* @return array The number of Elementor library items grouped by post types, post status |
| 465 |
* and meta value. |
| 466 |
*/ |
| 467 |
public static function get_library_usage_extend() { |
| 468 |
global $wpdb; |
| 469 |
|
| 470 |
$usage = []; |
| 471 |
|
| 472 |
$results = $wpdb->get_results( |
| 473 |
"SELECT `meta_value`, COUNT(`ID`) `hits`, `post_status` |
| 474 |
FROM {$wpdb->posts} `p` |
| 475 |
LEFT JOIN {$wpdb->postmeta} `pm` ON(`p`.`ID` = `pm`.`post_id`) |
| 476 |
WHERE `post_type` = 'elementor_library' |
| 477 |
AND `meta_key` = '_elementor_template_type' |
| 478 |
GROUP BY `post_type`, `meta_value`, `post_status`;" |
| 479 |
); |
| 480 |
|
| 481 |
if ( $results ) { |
| 482 |
foreach ( $results as $result ) { |
| 483 |
if ( empty( $usage[ $result->meta_value ] ) ) { |
| 484 |
$usage[ $result->meta_value ] = []; |
| 485 |
} |
| 486 |
|
| 487 |
if ( empty( $usage[ $result->meta_value ][ $result->post_status ] ) ) { |
| 488 |
$usage[ $result->meta_value ][ $result->post_status ] = 0; |
| 489 |
} |
| 490 |
|
| 491 |
$usage[ $result->meta_value ][ $result->post_status ] += $result->hits; |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
return $usage; |
| 496 |
} |
| 497 |
|
| 498 |
public static function get_events() { |
| 499 |
global $wpdb; |
| 500 |
$table_name = $wpdb->prefix . Events_DB_Manager::TABLE_NAME; |
| 501 |
|
| 502 |
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 503 |
$results = $wpdb->get_results( "SELECT event_data FROM {$table_name}" ); |
| 504 |
|
| 505 |
$events_data = []; |
| 506 |
|
| 507 |
foreach ( $results as $event ) { |
| 508 |
// Results are stored in the database as a JSON string. Since all tracking data is encoded right before |
| 509 |
// being sent, it is now decoded. |
| 510 |
$events_data[] = json_decode( $event->event_data, true ); |
| 511 |
} |
| 512 |
|
| 513 |
return $events_data; |
| 514 |
} |
| 515 |
|
| 516 |
/** |
| 517 |
* Get the tracking data |
| 518 |
* |
| 519 |
* Retrieve tracking data and apply filter |
| 520 |
* |
| 521 |
* @access public |
| 522 |
* @static |
| 523 |
* |
| 524 |
* @param bool $is_first_time |
| 525 |
* |
| 526 |
* @return array |
| 527 |
*/ |
| 528 |
public static function get_tracking_data( $is_first_time = false ) { |
| 529 |
$params = [ |
| 530 |
'system' => self::get_system_reports_data(), |
| 531 |
'site_lang' => get_bloginfo( 'language' ), |
| 532 |
'email' => get_option( 'admin_email' ), |
| 533 |
'usages' => [ |
| 534 |
'posts' => self::get_posts_usage(), |
| 535 |
'non-elementor-posts' => self::get_non_elementor_posts_usage(), |
| 536 |
'library' => self::get_library_usage(), |
| 537 |
'settings' => [ |
| 538 |
'general' => self::get_settings_general_usage(), |
| 539 |
'advanced' => self::get_settings_advanced_usage(), |
| 540 |
'experiments' => self::get_settings_experiments_usage(), |
| 541 |
], |
| 542 |
'tools' => [ |
| 543 |
'general' => self::get_tools_general_usage(), |
| 544 |
'version' => self::get_tools_version_control_usage(), |
| 545 |
'maintenance' => self::get_tools_maintenance_usage(), |
| 546 |
], |
| 547 |
'library-details' => self::get_library_usage_extend(), |
| 548 |
], |
| 549 |
'is_first_time' => $is_first_time, |
| 550 |
'install_time' => Plugin::instance()->get_install_time(), |
| 551 |
]; |
| 552 |
|
| 553 |
/** |
| 554 |
* Tracker send tracking data params. |
| 555 |
* |
| 556 |
* Filters the data parameters when sending tracking request. |
| 557 |
* |
| 558 |
* @param array $params Variable to encode as JSON. |
| 559 |
* |
| 560 |
* @since 1.0.0 |
| 561 |
* |
| 562 |
*/ |
| 563 |
$params = apply_filters( 'elementor/tracker/send_tracking_data_params', $params ); |
| 564 |
|
| 565 |
return $params; |
| 566 |
} |
| 567 |
|
| 568 |
/** |
| 569 |
* @param string $tab_name |
| 570 |
* @return array |
| 571 |
*/ |
| 572 |
private static function get_tracking_data_from_settings( $tab_name ) { |
| 573 |
return self::get_tracking_data_from_settings_page( |
| 574 |
Plugin::$instance->settings->get_tabs(), |
| 575 |
$tab_name |
| 576 |
); |
| 577 |
} |
| 578 |
|
| 579 |
/** |
| 580 |
* @param string $tab_name |
| 581 |
* @return array |
| 582 |
*/ |
| 583 |
private static function get_tracking_data_from_tools( $tab_name ) { |
| 584 |
return self::get_tracking_data_from_settings_page( |
| 585 |
Plugin::$instance->tools->get_tabs(), |
| 586 |
$tab_name |
| 587 |
); |
| 588 |
} |
| 589 |
|
| 590 |
private static function get_tracking_data_from_settings_page( $tabs, $tab_name ) { |
| 591 |
$result = []; |
| 592 |
|
| 593 |
if ( empty( $tabs[ $tab_name ] ) ) { |
| 594 |
return $result; |
| 595 |
} |
| 596 |
|
| 597 |
$tab = $tabs[ $tab_name ]; |
| 598 |
|
| 599 |
foreach ( $tab['sections'] as $section_name => $section ) { |
| 600 |
foreach ( $section['fields'] as $field_name => $field ) { |
| 601 |
// Skips fields with '_' prefix. |
| 602 |
if ( '_' === $field_name[0] ) { |
| 603 |
continue; |
| 604 |
} |
| 605 |
|
| 606 |
$default_value = null; |
| 607 |
$args = $field['field_args']; |
| 608 |
switch ( $args['type'] ) { |
| 609 |
case 'checkbox': |
| 610 |
$default_value = $args['value']; |
| 611 |
break; |
| 612 |
|
| 613 |
case 'select': |
| 614 |
case 'checkbox_list_cpt': |
| 615 |
$default_value = $args['std']; |
| 616 |
break; |
| 617 |
|
| 618 |
case 'checkbox_list_roles': |
| 619 |
$default_value = null; |
| 620 |
break; |
| 621 |
|
| 622 |
// 'raw_html' is used as action and not as data. |
| 623 |
case 'raw_html': |
| 624 |
continue 2; // Skip fields loop. |
| 625 |
|
| 626 |
default: |
| 627 |
trigger_error( 'Invalid type: \'' . $args['type'] . '\'' ); // phpcs:ignore |
| 628 |
} |
| 629 |
|
| 630 |
$result[ $field_name ] = get_option( 'elementor_' . $field_name, $default_value ); |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
return $result; |
| 635 |
} |
| 636 |
} |
| 637 |
|