admin-templates
1 year ago
base
1 year ago
container
1 year ago
controls
1 year ago
editor-templates
1 year ago
elements
1 year ago
interfaces
1 year ago
libraries
1 year ago
managers
1 year ago
settings
1 year ago
template-library
1 year ago
widgets
1 year ago
api.php
1 year ago
autoloader.php
1 year ago
beta-testers.php
3 years ago
compatibility.php
1 year ago
conditions.php
3 years ago
db.php
2 years ago
editor-assets-api.php
1 year ago
embed.php
1 year ago
fonts.php
1 year ago
frontend.php
1 year ago
heartbeat.php
3 years ago
maintenance-mode.php
2 years ago
maintenance.php
3 years ago
plugin.php
1 year ago
preview.php
1 year ago
rollback.php
3 years ago
shapes.php
1 year ago
stylesheet.php
1 year ago
tracker.php
1 year ago
user.php
2 years ago
utils.php
1 year ago
tracker.php
652 lines
| 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 performance settings. |
| 411 | * 'Elementor->Settings->Performance'. |
| 412 | * |
| 413 | * @return array |
| 414 | */ |
| 415 | public static function get_settings_performance_usage() { |
| 416 | return self::get_tracking_data_from_settings( 'performance' ); |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Get usage of experiments settings. |
| 421 | * |
| 422 | * 'Elementor->Settings->Experiments'. |
| 423 | * |
| 424 | * @return array |
| 425 | */ |
| 426 | public static function get_settings_experiments_usage() { |
| 427 | $system_info = Plugin::$instance->system_info; |
| 428 | |
| 429 | /** |
| 430 | * @var $experiments_report Experiments_Reporter |
| 431 | */ |
| 432 | $experiments_report = $system_info->create_reporter( [ |
| 433 | 'class_name' => Experiments_Reporter::class, |
| 434 | ] ); |
| 435 | |
| 436 | return $experiments_report->get_experiments()['value']; |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Get usage of general tools. |
| 441 | * 'Elementor->Tools->General'. |
| 442 | * |
| 443 | * @return array |
| 444 | */ |
| 445 | public static function get_tools_general_usage() { |
| 446 | return self::get_tracking_data_from_tools( 'general' ); |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Get usage of 'version control' tools. |
| 451 | * 'Elementor->Tools->Version Control'. |
| 452 | * |
| 453 | * @return array |
| 454 | */ |
| 455 | public static function get_tools_version_control_usage() { |
| 456 | return self::get_tracking_data_from_tools( 'versions' ); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Get usage of 'maintenance' tools. |
| 461 | * 'Elementor->Tools->Maintenance'. |
| 462 | * |
| 463 | * @return array |
| 464 | */ |
| 465 | public static function get_tools_maintenance_usage() { |
| 466 | return self::get_tracking_data_from_tools( 'maintenance_mode' ); |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Get library usage extend. |
| 471 | * |
| 472 | * Retrieve the number of Elementor library items saved. |
| 473 | * |
| 474 | * @return array The number of Elementor library items grouped by post types, post status |
| 475 | * and meta value. |
| 476 | */ |
| 477 | public static function get_library_usage_extend() { |
| 478 | global $wpdb; |
| 479 | |
| 480 | $usage = []; |
| 481 | |
| 482 | $results = $wpdb->get_results( |
| 483 | "SELECT `meta_value`, COUNT(`ID`) `hits`, `post_status` |
| 484 | FROM {$wpdb->posts} `p` |
| 485 | LEFT JOIN {$wpdb->postmeta} `pm` ON(`p`.`ID` = `pm`.`post_id`) |
| 486 | WHERE `post_type` = 'elementor_library' |
| 487 | AND `meta_key` = '_elementor_template_type' |
| 488 | GROUP BY `post_type`, `meta_value`, `post_status`;" |
| 489 | ); |
| 490 | |
| 491 | if ( $results ) { |
| 492 | foreach ( $results as $result ) { |
| 493 | if ( empty( $usage[ $result->meta_value ] ) ) { |
| 494 | $usage[ $result->meta_value ] = []; |
| 495 | } |
| 496 | |
| 497 | if ( empty( $usage[ $result->meta_value ][ $result->post_status ] ) ) { |
| 498 | $usage[ $result->meta_value ][ $result->post_status ] = 0; |
| 499 | } |
| 500 | |
| 501 | $usage[ $result->meta_value ][ $result->post_status ] += $result->hits; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | return $usage; |
| 506 | } |
| 507 | |
| 508 | public static function get_events() { |
| 509 | global $wpdb; |
| 510 | $table_name = $wpdb->prefix . Events_DB_Manager::TABLE_NAME; |
| 511 | |
| 512 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 513 | $results = $wpdb->get_results( "SELECT event_data FROM {$table_name}" ); |
| 514 | |
| 515 | $events_data = []; |
| 516 | |
| 517 | foreach ( $results as $event ) { |
| 518 | // Results are stored in the database as a JSON string. Since all tracking data is encoded right before |
| 519 | // being sent, it is now decoded. |
| 520 | $events_data[] = json_decode( $event->event_data, true ); |
| 521 | } |
| 522 | |
| 523 | return $events_data; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Get the tracking data |
| 528 | * |
| 529 | * Retrieve tracking data and apply filter |
| 530 | * |
| 531 | * @access public |
| 532 | * @static |
| 533 | * |
| 534 | * @param bool $is_first_time |
| 535 | * |
| 536 | * @return array |
| 537 | */ |
| 538 | public static function get_tracking_data( $is_first_time = false ) { |
| 539 | $params = [ |
| 540 | 'system' => self::get_system_reports_data(), |
| 541 | 'site_lang' => get_bloginfo( 'language' ), |
| 542 | 'email' => get_option( 'admin_email' ), |
| 543 | 'usages' => [ |
| 544 | 'posts' => self::get_posts_usage(), |
| 545 | 'non-elementor-posts' => self::get_non_elementor_posts_usage(), |
| 546 | 'library' => self::get_library_usage(), |
| 547 | 'settings' => [ |
| 548 | 'general' => self::get_settings_general_usage(), |
| 549 | 'advanced' => self::get_settings_advanced_usage(), |
| 550 | 'experiments' => self::get_settings_experiments_usage(), |
| 551 | ], |
| 552 | 'tools' => [ |
| 553 | 'general' => self::get_tools_general_usage(), |
| 554 | 'version' => self::get_tools_version_control_usage(), |
| 555 | 'maintenance' => self::get_tools_maintenance_usage(), |
| 556 | ], |
| 557 | 'library-details' => self::get_library_usage_extend(), |
| 558 | ], |
| 559 | 'is_first_time' => $is_first_time, |
| 560 | 'install_time' => Plugin::instance()->get_install_time(), |
| 561 | ]; |
| 562 | |
| 563 | $site_key = Api::get_site_key(); |
| 564 | if ( ! empty( $site_key ) ) { |
| 565 | $params['site_key'] = $site_key; |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * Tracker send tracking data params. |
| 570 | * |
| 571 | * Filters the data parameters when sending tracking request. |
| 572 | * |
| 573 | * @param array $params Variable to encode as JSON. |
| 574 | * |
| 575 | * @since 1.0.0 |
| 576 | * |
| 577 | */ |
| 578 | $params = apply_filters( 'elementor/tracker/send_tracking_data_params', $params ); |
| 579 | |
| 580 | return $params; |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * @param string $tab_name |
| 585 | * @return array |
| 586 | */ |
| 587 | private static function get_tracking_data_from_settings( $tab_name ) { |
| 588 | return self::get_tracking_data_from_settings_page( |
| 589 | Plugin::$instance->settings->get_tabs(), |
| 590 | $tab_name |
| 591 | ); |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * @param string $tab_name |
| 596 | * @return array |
| 597 | */ |
| 598 | private static function get_tracking_data_from_tools( $tab_name ) { |
| 599 | return self::get_tracking_data_from_settings_page( |
| 600 | Plugin::$instance->tools->get_tabs(), |
| 601 | $tab_name |
| 602 | ); |
| 603 | } |
| 604 | |
| 605 | private static function get_tracking_data_from_settings_page( $tabs, $tab_name ) { |
| 606 | $result = []; |
| 607 | |
| 608 | if ( empty( $tabs[ $tab_name ] ) ) { |
| 609 | return $result; |
| 610 | } |
| 611 | |
| 612 | $tab = $tabs[ $tab_name ]; |
| 613 | |
| 614 | foreach ( $tab['sections'] as $section_name => $section ) { |
| 615 | foreach ( $section['fields'] as $field_name => $field ) { |
| 616 | // Skips fields with '_' prefix. |
| 617 | if ( '_' === $field_name[0] ) { |
| 618 | continue; |
| 619 | } |
| 620 | |
| 621 | $default_value = null; |
| 622 | $args = $field['field_args']; |
| 623 | switch ( $args['type'] ) { |
| 624 | case 'checkbox': |
| 625 | $default_value = $args['value']; |
| 626 | break; |
| 627 | |
| 628 | case 'select': |
| 629 | case 'checkbox_list_cpt': |
| 630 | $default_value = $args['std']; |
| 631 | break; |
| 632 | |
| 633 | case 'checkbox_list_roles': |
| 634 | $default_value = null; |
| 635 | break; |
| 636 | |
| 637 | // 'raw_html' is used as action and not as data. |
| 638 | case 'raw_html': |
| 639 | continue 2; // Skip fields loop. |
| 640 | |
| 641 | default: |
| 642 | trigger_error( 'Invalid type: \'' . $args['type'] . '\'' ); // phpcs:ignore |
| 643 | } |
| 644 | |
| 645 | $result[ $field_name ] = get_option( 'elementor_' . $field_name, $default_value ); |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | return $result; |
| 650 | } |
| 651 | } |
| 652 |