VariableProductTitle
4 years ago
.gitkeep
4 years ago
WpaeInvalidPhpException.php
4 years ago
WpaeInvalidStringException.php
4 years ago
WpaeMethodNotFoundException.php
4 years ago
WpaePhpInterpreterErrorHandler.php
4 years ago
WpaeString.php
4 years ago
WpaeTooMuchRecursionException.php
4 years ago
WpaeXmlProcessor.php
4 years ago
XmlCsvExport.php
4 years ago
XmlExportACF.php
4 years ago
XmlExportComment.php
4 years ago
XmlExportCpt.php
4 years ago
XmlExportEngine.php
4 years ago
XmlExportFiltering.php
4 years ago
XmlExportMediaGallery.php
4 years ago
XmlExportTaxonomy.php
4 years ago
XmlExportUser.php
4 years ago
XmlExportWooCommerce.php
4 years ago
XmlExportWooCommerceCoupon.php
4 years ago
XmlExportWooCommerceOrder.php
4 years ago
XmlGoogleMerchants.php
4 years ago
XmlSpec.php
4 years ago
XmlExportUser.php
747 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! class_exists('XmlExportUser') ){ |
| 4 | |
| 5 | final class XmlExportUser |
| 6 | { |
| 7 | private $init_fields = array( |
| 8 | array( |
| 9 | 'label' => 'id', |
| 10 | 'name' => 'ID', |
| 11 | 'type' => 'id' |
| 12 | ), |
| 13 | array( |
| 14 | 'label' => 'user_email', |
| 15 | 'name' => 'User Email', |
| 16 | 'type' => 'user_email' |
| 17 | ), |
| 18 | array( |
| 19 | 'label' => 'user_login', |
| 20 | 'name' => 'User Login', |
| 21 | 'type' => 'user_login' |
| 22 | ) |
| 23 | ); |
| 24 | |
| 25 | private $default_fields = array( |
| 26 | array( |
| 27 | 'label' => 'id', |
| 28 | 'name' => 'ID', |
| 29 | 'type' => 'id' |
| 30 | ), |
| 31 | array( |
| 32 | 'label' => 'user_login', |
| 33 | 'name' => 'User Login', |
| 34 | 'type' => 'user_login' |
| 35 | ), |
| 36 | array( |
| 37 | 'label' => 'user_email', |
| 38 | 'name' => 'User Email', |
| 39 | 'type' => 'user_email' |
| 40 | ), |
| 41 | array( |
| 42 | 'label' => 'first_name', |
| 43 | 'name' => 'First Name', |
| 44 | 'type' => 'first_name' |
| 45 | ), |
| 46 | array( |
| 47 | 'label' => 'last_name', |
| 48 | 'name' => 'Last Name', |
| 49 | 'type' => 'last_name' |
| 50 | ), |
| 51 | array( |
| 52 | 'label' => 'user_registered', |
| 53 | 'name' => 'User Registered', |
| 54 | 'type' => 'user_registered' |
| 55 | ), |
| 56 | array( |
| 57 | 'label' => 'user_nicename', |
| 58 | 'name' => 'User Nicename', |
| 59 | 'type' => 'user_nicename' |
| 60 | ), |
| 61 | array( |
| 62 | 'label' => 'user_url', |
| 63 | 'name' => 'User URL', |
| 64 | 'type' => 'user_url' |
| 65 | ), |
| 66 | array( |
| 67 | 'label' => 'display_name', |
| 68 | 'name' => 'Display Name', |
| 69 | 'type' => 'display_name' |
| 70 | ), |
| 71 | array( |
| 72 | 'label' => 'nickname', |
| 73 | 'name' => 'Nickname', |
| 74 | 'type' => 'nickname' |
| 75 | ), |
| 76 | array( |
| 77 | 'label' => 'description', |
| 78 | 'name' => 'Description', |
| 79 | 'type' => 'description' |
| 80 | ) |
| 81 | ); |
| 82 | |
| 83 | private $advanced_fields = array( |
| 84 | array( |
| 85 | 'label' => 'wp_capabilities', |
| 86 | 'name' => 'User Role', |
| 87 | 'type' => 'wp_capabilities' |
| 88 | ), |
| 89 | array( |
| 90 | 'label' => 'user_pass', |
| 91 | 'name' => 'User Pass', |
| 92 | 'type' => 'user_pass' |
| 93 | ), |
| 94 | array( |
| 95 | 'label' => 'user_activation_key', |
| 96 | 'name' => 'User Activation Key', |
| 97 | 'type' => 'user_activation_key' |
| 98 | ), |
| 99 | array( |
| 100 | 'label' => 'user_status', |
| 101 | 'name' => 'User Status', |
| 102 | 'type' => 'user_status' |
| 103 | ) |
| 104 | ); |
| 105 | |
| 106 | private $user_core_fields = array(); |
| 107 | |
| 108 | public static $is_active = true; |
| 109 | |
| 110 | public static $is_export_shop_customer = false; |
| 111 | |
| 112 | public function __construct() |
| 113 | { |
| 114 | |
| 115 | $this->user_core_fields = array('rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'wp_user_level', 'show_welcome_panel', 'dismissed_wp_pointers', 'session_tokens', 'wp_user-settings', 'wp_user-settings-time', 'wp_dashboard_quick_press_last_post_id', 'metaboxhidden_dashboard', 'closedpostboxes_dashboard', 'wp_nav_menu_recently_edited', 'meta-box-order_dashboard', 'closedpostboxes_product', 'metaboxhidden_product', 'manageedit-shop_ordercolumnshidden', 'aim', 'yim', 'jabber', 'wp_media_library_mode'); |
| 116 | |
| 117 | if ( ( XmlExportEngine::$exportOptions['export_type'] == 'specific' and ! in_array('users', XmlExportEngine::$post_types) and ! in_array('shop_customer', XmlExportEngine::$post_types) ) |
| 118 | or ( XmlExportEngine::$exportOptions['export_type'] == 'advanced' and XmlExportEngine::$exportOptions['wp_query_selector'] != 'wp_user_query' ) ){ |
| 119 | self::$is_active = false; |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | self::$is_active = true; |
| 124 | |
| 125 | if (in_array('shop_customer', XmlExportEngine::$post_types)) self::$is_export_shop_customer = true; |
| 126 | |
| 127 | add_filter("wp_all_export_available_data", array( &$this, "filter_available_data"), 10, 1); |
| 128 | add_filter("wp_all_export_available_sections", array( &$this, "filter_available_sections" ), 10, 1); |
| 129 | add_filter("wp_all_export_init_fields", array( &$this, "filter_init_fields"), 10, 1); |
| 130 | add_filter("wp_all_export_default_fields", array( &$this, "filter_default_fields"), 10, 1); |
| 131 | add_filter("wp_all_export_other_fields", array( &$this, "filter_other_fields"), 10, 1); |
| 132 | |
| 133 | } |
| 134 | |
| 135 | // [FILTERS] |
| 136 | |
| 137 | /** |
| 138 | * |
| 139 | * Filter Init Fields |
| 140 | * |
| 141 | */ |
| 142 | public function filter_init_fields($init_fields){ |
| 143 | return $this->init_fields; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * |
| 148 | * Filter Default Fields |
| 149 | * |
| 150 | */ |
| 151 | public function filter_default_fields($default_fields){ |
| 152 | return $this->default_fields; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * |
| 157 | * Filter Other Fields |
| 158 | * |
| 159 | */ |
| 160 | public function filter_other_fields($other_fields){ |
| 161 | |
| 162 | $other_fields = array(); |
| 163 | |
| 164 | foreach ( $this->advanced_fields as $key => $field ) { |
| 165 | $other_fields[] = $field; |
| 166 | } |
| 167 | |
| 168 | foreach ( $this->user_core_fields as $field ) { |
| 169 | $other_fields[] = $this->fix_titles(array( |
| 170 | 'label' => $field, |
| 171 | 'name' => $field, |
| 172 | 'type' => 'cf' |
| 173 | )); |
| 174 | } |
| 175 | |
| 176 | return $other_fields; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * |
| 181 | * Filter Available Data |
| 182 | * |
| 183 | */ |
| 184 | public function filter_available_data($available_data){ |
| 185 | |
| 186 | if (self::$is_export_shop_customer) |
| 187 | { |
| 188 | $available_data['address_fields'] = $this->available_customer_data(); |
| 189 | } |
| 190 | elseif (self::$is_woo_custom_founded) |
| 191 | { |
| 192 | $available_data['customer_fields'] = $this->available_customer_data(); |
| 193 | } |
| 194 | |
| 195 | return $available_data; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * |
| 200 | * Filter Sections in Available Data |
| 201 | * |
| 202 | */ |
| 203 | public function filter_available_sections($available_sections){ |
| 204 | |
| 205 | unset($available_sections['cats']); |
| 206 | unset($available_sections['media']); |
| 207 | |
| 208 | if (self::$is_export_shop_customer) |
| 209 | { |
| 210 | $customer_data = array( |
| 211 | 'address' => array( |
| 212 | 'title' => __("Address", "wp_all_export_plugin"), |
| 213 | 'content' => 'address_fields' |
| 214 | ) |
| 215 | ); |
| 216 | |
| 217 | return array_merge(array_slice($available_sections, 0, 1), $customer_data, array_slice($available_sections, 1)); |
| 218 | } |
| 219 | elseif (self::$is_woo_custom_founded) |
| 220 | { |
| 221 | $customer_data = array( |
| 222 | 'customer' => array( |
| 223 | 'title' => __("Address", "wp_all_export_plugin"), |
| 224 | 'content' => 'customer_fields' |
| 225 | ) |
| 226 | ); |
| 227 | $available_sections = array_merge(array_slice($available_sections, 0, 1), $customer_data, array_slice($available_sections, 1)); |
| 228 | } |
| 229 | |
| 230 | self::$is_export_shop_customer or $available_sections['other']['title'] = __("Other", "wp_all_export_plugin"); |
| 231 | |
| 232 | return $available_sections; |
| 233 | } |
| 234 | |
| 235 | // [\FILTERS] |
| 236 | |
| 237 | public static $meta_keys; |
| 238 | public static $is_woo_custom_founded = false; |
| 239 | public function init( & $existing_meta_keys = array() ) |
| 240 | { |
| 241 | if ( ! self::$is_active ) return; |
| 242 | |
| 243 | global $wpdb; |
| 244 | //$table_prefix = $wpdb->prefix; |
| 245 | self::$meta_keys = $wpdb->get_results("SELECT DISTINCT ".$wpdb->usermeta .".meta_key FROM $wpdb->usermeta, $wpdb->users WHERE ".$wpdb->usermeta.".user_id = ".$wpdb->users.".ID LIMIT 500"); |
| 246 | |
| 247 | $user_ids = array(); |
| 248 | if ( ! empty(XmlExportEngine::$exportQuery->results)) { |
| 249 | foreach ( XmlExportEngine::$exportQuery->results as $user ) : |
| 250 | $user_ids[] = $user->ID; |
| 251 | endforeach; |
| 252 | } |
| 253 | |
| 254 | if ( ! empty(self::$meta_keys)){ |
| 255 | |
| 256 | $address_fields = $this->available_customer_data(); |
| 257 | |
| 258 | $customer_users = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value != %s ", '_customer_user', '0')); |
| 259 | |
| 260 | // detect if at least one filtered user is a WooCommerce customer |
| 261 | if ( ! empty($customer_users) ) { |
| 262 | foreach ($customer_users as $customer_user) { |
| 263 | if ( in_array($customer_user->meta_value, $user_ids) ) |
| 264 | { |
| 265 | self::$is_woo_custom_founded = true; |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | $exclude_keys = array('_first_variation_attributes', '_is_first_variation_created'); |
| 272 | foreach (self::$meta_keys as $meta_key) { |
| 273 | if ( ! in_array($meta_key->meta_key, $exclude_keys)) |
| 274 | { |
| 275 | $to_add = true; |
| 276 | foreach ($this->default_fields as $default_value) { |
| 277 | if ( $meta_key->meta_key == $default_value['name'] || $meta_key->meta_key == $default_value['type'] ){ |
| 278 | $to_add = false; |
| 279 | break; |
| 280 | } |
| 281 | } |
| 282 | if ( $to_add ){ |
| 283 | foreach ($this->advanced_fields as $advanced_value) { |
| 284 | if ( $meta_key->meta_key == $advanced_value['name'] || $meta_key->meta_key == $advanced_value['type']){ |
| 285 | $to_add = false; |
| 286 | break; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | if ( $to_add ){ |
| 291 | foreach ($this->user_core_fields as $core_field) { |
| 292 | if ( $meta_key->meta_key == $core_field ){ |
| 293 | $to_add = false; |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | if ( $to_add && ( self::$is_export_shop_customer || self::$is_woo_custom_founded ) ) |
| 299 | { |
| 300 | foreach ($address_fields as $address_value) { |
| 301 | if ( $meta_key->meta_key == $address_value['label']){ |
| 302 | $to_add = false; |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | if ( $to_add ) |
| 308 | { |
| 309 | $existing_meta_keys[] = $meta_key->meta_key; |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | public function available_customer_data() |
| 317 | { |
| 318 | |
| 319 | $main_fields = array( |
| 320 | array( |
| 321 | 'name' => __('Customer User ID', 'wp_all_export_plugin'), |
| 322 | 'label' => '_customer_user', |
| 323 | 'type' => 'cf' |
| 324 | ) |
| 325 | ); |
| 326 | |
| 327 | $data = array_merge($main_fields, $this->available_billing_information_data(), $this->available_shipping_information_data()); |
| 328 | |
| 329 | return apply_filters('wp_all_export_available_user_data_filter', $data); |
| 330 | |
| 331 | } |
| 332 | |
| 333 | public function available_billing_information_data() |
| 334 | { |
| 335 | |
| 336 | $keys = array( |
| 337 | 'billing_first_name', 'billing_last_name', 'billing_company', |
| 338 | 'billing_address_1', 'billing_address_2', 'billing_city', |
| 339 | 'billing_postcode', 'billing_country', 'billing_state', |
| 340 | 'billing_email', 'billing_phone' |
| 341 | ); |
| 342 | |
| 343 | $data = $this->generate_friendly_titles($keys, 'billing'); |
| 344 | |
| 345 | return apply_filters('wp_all_export_available_billing_information_data_filter', $data); |
| 346 | |
| 347 | } |
| 348 | |
| 349 | public function available_shipping_information_data() |
| 350 | { |
| 351 | |
| 352 | $keys = array( |
| 353 | 'shipping_first_name', 'shipping_last_name', 'shipping_company', |
| 354 | 'shipping_address_1', 'shipping_address_2', 'shipping_city', |
| 355 | 'shipping_postcode', 'shipping_country', 'shipping_state' |
| 356 | ); |
| 357 | |
| 358 | $data = $this->generate_friendly_titles($keys, 'shipping'); |
| 359 | |
| 360 | return apply_filters('wp_all_export_available_shipping_information_data_filter', $data); |
| 361 | |
| 362 | } |
| 363 | |
| 364 | public function generate_friendly_titles($keys, $keyword = ''){ |
| 365 | $data = array(); |
| 366 | foreach ($keys as $key) { |
| 367 | |
| 368 | $key1 = $this->fix_titles(str_replace('_', ' ', $key)); |
| 369 | $key2 = ''; |
| 370 | |
| 371 | if(strpos($key1, $keyword)!== false) |
| 372 | { |
| 373 | $key1 = str_replace($keyword, '', $key1); |
| 374 | $key2 = ' ('.__($keyword, 'wp_all_export_plugin').')'; |
| 375 | } |
| 376 | |
| 377 | $data[] = array( |
| 378 | 'name' => __(trim($key1), 'woocommerce').$key2, |
| 379 | 'label' => $key, |
| 380 | 'type' => 'cf' |
| 381 | ); |
| 382 | |
| 383 | } |
| 384 | return $data; |
| 385 | } |
| 386 | /** |
| 387 | * |
| 388 | * Helper method to fix fields title |
| 389 | * |
| 390 | */ |
| 391 | protected function fix_titles($field) |
| 392 | { |
| 393 | if (is_array($field)) |
| 394 | { |
| 395 | $field['name'] = $this->fix_title($field['name']); |
| 396 | } |
| 397 | else |
| 398 | { |
| 399 | $field = $this->fix_title($field); |
| 400 | } |
| 401 | return $field; |
| 402 | } |
| 403 | /** |
| 404 | * |
| 405 | * Helper method to fix single title |
| 406 | * |
| 407 | */ |
| 408 | protected function fix_title($title) |
| 409 | { |
| 410 | $uc_title = ucwords(trim(str_replace("-", " ", str_replace("_", " ", $title)))); |
| 411 | |
| 412 | return stripos($uc_title, "width") === false ? str_ireplace(array('id', 'url', 'sku', 'wp', 'ssl'), array('ID', 'URL', 'SKU', 'WP', 'SSL'), $uc_title) : $uc_title; |
| 413 | } |
| 414 | |
| 415 | public static function prepare_data( $user, $xmlWriter = false, &$acfs, $implode_delimiter, $preview ) |
| 416 | { |
| 417 | $article = array(); |
| 418 | |
| 419 | // associate exported user with import |
| 420 | if ( wp_all_export_is_compatible() and XmlExportEngine::$exportOptions['is_generate_import'] and XmlExportEngine::$exportOptions['import_id']) |
| 421 | { |
| 422 | $postRecord = new PMXI_Post_Record(); |
| 423 | $postRecord->clear(); |
| 424 | $postRecord->getBy(array( |
| 425 | 'post_id' => $user->ID, |
| 426 | 'import_id' => XmlExportEngine::$exportOptions['import_id'], |
| 427 | )); |
| 428 | |
| 429 | if ($postRecord->isEmpty()){ |
| 430 | $postRecord->set(array( |
| 431 | 'post_id' => $user->ID, |
| 432 | 'import_id' => XmlExportEngine::$exportOptions['import_id'], |
| 433 | 'unique_key' => $user->ID |
| 434 | ))->save(); |
| 435 | } |
| 436 | unset($postRecord); |
| 437 | } |
| 438 | |
| 439 | $is_xml_export = false; |
| 440 | |
| 441 | if ( ! empty($xmlWriter) and XmlExportEngine::$exportOptions['export_to'] == 'xml' and ! in_array(XmlExportEngine::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ){ |
| 442 | $is_xml_export = true; |
| 443 | } |
| 444 | |
| 445 | foreach (XmlExportEngine::$exportOptions['ids'] as $ID => $value) |
| 446 | { |
| 447 | $fieldName = apply_filters('wp_all_export_field_name', wp_all_export_parse_field_name(XmlExportEngine::$exportOptions['cc_name'][$ID]), XmlExportEngine::$exportID); |
| 448 | $fieldValue = XmlExportEngine::$exportOptions['cc_value'][$ID]; |
| 449 | $fieldLabel = XmlExportEngine::$exportOptions['cc_label'][$ID]; |
| 450 | $fieldSql = XmlExportEngine::$exportOptions['cc_sql'][$ID]; |
| 451 | $fieldPhp = XmlExportEngine::$exportOptions['cc_php'][$ID]; |
| 452 | $fieldCode = XmlExportEngine::$exportOptions['cc_code'][$ID]; |
| 453 | $fieldType = XmlExportEngine::$exportOptions['cc_type'][$ID]; |
| 454 | $fieldOptions = XmlExportEngine::$exportOptions['cc_options'][$ID]; |
| 455 | $fieldSettings = empty(XmlExportEngine::$exportOptions['cc_settings'][$ID]) ? $fieldOptions : XmlExportEngine::$exportOptions['cc_settings'][$ID]; |
| 456 | |
| 457 | if ( empty($fieldName) or empty($fieldType) or ! is_numeric($ID) ) continue; |
| 458 | |
| 459 | $element_name = ( ! empty($fieldName) ) ? $fieldName : 'untitled_' . $ID; |
| 460 | $element_name_ns = ''; |
| 461 | |
| 462 | if ( $is_xml_export ) |
| 463 | { |
| 464 | $element_name = ( ! empty($fieldName) ) ? preg_replace('/[^a-z0-9_:-]/i', '', $fieldName) : 'untitled_' . $ID; |
| 465 | |
| 466 | if (strpos($element_name, ":") !== false) |
| 467 | { |
| 468 | $element_name_parts = explode(":", $element_name); |
| 469 | $element_name_ns = (empty($element_name_parts[0])) ? '' : $element_name_parts[0]; |
| 470 | $element_name = (empty($element_name_parts[1])) ? 'untitled_' . $ID : preg_replace('/[^a-z0-9_-]/i', '', $element_name_parts[1]); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | $fieldSnipped = ( ! empty($fieldPhp ) and ! empty($fieldCode)) ? $fieldCode : false; |
| 475 | |
| 476 | switch ($fieldType) |
| 477 | { |
| 478 | case 'id': |
| 479 | // For ID columns make first element in lowercase for Excel export |
| 480 | if ($element_name == 'ID' && !$ID && isset(XmlExportEngine::$exportOptions['export_to']) && XmlExportEngine::$exportOptions['export_to'] == 'csv' && isset(XmlExportEngine::$exportOptions['export_to_sheet']) && XmlExportEngine::$exportOptions['export_to_sheet'] != 'csv'){ |
| 481 | $element_name = 'id'; |
| 482 | } |
| 483 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_id', pmxe_filter($user->ID, $fieldSnipped), $user->ID) ); |
| 484 | break; |
| 485 | case 'user_login': |
| 486 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_login', pmxe_filter($user->user_login, $fieldSnipped), $user->ID) ); |
| 487 | break; |
| 488 | case 'user_pass': |
| 489 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_pass', pmxe_filter($user->user_pass, $fieldSnipped), $user->ID) ); |
| 490 | break; |
| 491 | case 'user_email': |
| 492 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_email', pmxe_filter($user->user_email, $fieldSnipped), $user->ID) ); |
| 493 | break; |
| 494 | case 'user_nicename': |
| 495 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_nicename', pmxe_filter($user->user_nicename, $fieldSnipped), $user->ID) ); |
| 496 | break; |
| 497 | case 'user_url': |
| 498 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_url', pmxe_filter($user->user_url, $fieldSnipped), $user->ID) ); |
| 499 | break; |
| 500 | case 'user_activation_key': |
| 501 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_activation_key', pmxe_filter($user->user_activation_key, $fieldSnipped), $user->ID) ); |
| 502 | break; |
| 503 | case 'user_status': |
| 504 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_status', pmxe_filter($user->user_status, $fieldSnipped), $user->ID) ); |
| 505 | break; |
| 506 | case 'display_name': |
| 507 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_display_name', pmxe_filter($user->display_name, $fieldSnipped), $user->ID) ); |
| 508 | break; |
| 509 | case 'nickname': |
| 510 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_nickname', pmxe_filter($user->nickname, $fieldSnipped), $user->ID) ); |
| 511 | break; |
| 512 | case 'first_name': |
| 513 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_first_name', pmxe_filter($user->first_name, $fieldSnipped), $user->ID) ); |
| 514 | break; |
| 515 | case 'last_name': |
| 516 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_last_name', pmxe_filter($user->last_name, $fieldSnipped), $user->ID) ); |
| 517 | break; |
| 518 | case 'wp_capabilities': |
| 519 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_wp_capabilities', pmxe_filter(implode($implode_delimiter, $user->roles), $fieldSnipped), $user->ID) ); |
| 520 | break; |
| 521 | case 'description': |
| 522 | $val = apply_filters('pmxe_user_description', pmxe_filter($user->description, $fieldSnipped), $user->ID); |
| 523 | wp_all_export_write_article( $article, $element_name, ($preview) ? trim(preg_replace('~[\r\n]+~', ' ', htmlspecialchars($val))) : $val ); |
| 524 | break; |
| 525 | case 'user_registered': |
| 526 | |
| 527 | $post_date = prepare_date_field_value($fieldSettings, strtotime($user->user_registered)); |
| 528 | |
| 529 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_user_registered', pmxe_filter($post_date, $fieldSnipped), $user->ID) ); |
| 530 | |
| 531 | break; |
| 532 | case 'cf': |
| 533 | |
| 534 | if ( ! empty($fieldValue) ) |
| 535 | { |
| 536 | $val = ""; |
| 537 | |
| 538 | $cur_meta_values = get_user_meta($user->ID, $fieldValue); |
| 539 | |
| 540 | if ( ! empty($cur_meta_values) and is_array($cur_meta_values) ) |
| 541 | { |
| 542 | foreach ($cur_meta_values as $key => $cur_meta_value) |
| 543 | { |
| 544 | if (empty($val)) |
| 545 | { |
| 546 | $val = apply_filters('pmxe_custom_field', pmxe_filter(maybe_serialize($cur_meta_value), $fieldSnipped), $fieldValue, $user->ID); |
| 547 | } |
| 548 | else |
| 549 | { |
| 550 | $val = apply_filters('pmxe_custom_field', pmxe_filter($val . $implode_delimiter . maybe_serialize($cur_meta_value), $fieldSnipped), $fieldValue, $user->ID); |
| 551 | } |
| 552 | } |
| 553 | wp_all_export_write_article( $article, $element_name, $val ); |
| 554 | } |
| 555 | |
| 556 | if ( empty($cur_meta_values) ) |
| 557 | { |
| 558 | if ( empty($article[$element_name]) ) |
| 559 | { |
| 560 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_custom_field', pmxe_filter('', $fieldSnipped), $fieldValue, $user->ID) ); |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | break; |
| 565 | case 'acf': |
| 566 | |
| 567 | if ( ! empty($fieldLabel) and class_exists( 'acf' ) ) |
| 568 | { |
| 569 | global $acf; |
| 570 | |
| 571 | $field_options = unserialize($fieldOptions); |
| 572 | |
| 573 | if ( ! $is_xml_export ) |
| 574 | { |
| 575 | switch ($field_options['type']) { |
| 576 | case 'textarea': |
| 577 | case 'oembed': |
| 578 | case 'wysiwyg': |
| 579 | case 'wp_wysiwyg': |
| 580 | case 'date_time_picker': |
| 581 | case 'date_picker': |
| 582 | |
| 583 | $field_value = get_field($fieldLabel, 'user_' . $user->ID, false); |
| 584 | |
| 585 | break; |
| 586 | |
| 587 | default: |
| 588 | |
| 589 | $field_value = get_field($fieldLabel, 'user_' . $user->ID); |
| 590 | |
| 591 | break; |
| 592 | } |
| 593 | } |
| 594 | else |
| 595 | { |
| 596 | $field_value = get_field($fieldLabel, 'user_' . $user->ID); |
| 597 | } |
| 598 | |
| 599 | XmlExportACF::export_acf_field( |
| 600 | $field_value, |
| 601 | XmlExportEngine::$exportOptions, |
| 602 | $ID, |
| 603 | 'user_' . $user->ID, |
| 604 | $article, |
| 605 | $xmlWriter, |
| 606 | $acfs, |
| 607 | $element_name, |
| 608 | $element_name_ns, |
| 609 | $fieldSnipped, |
| 610 | $field_options['group_id'], |
| 611 | $preview |
| 612 | ); |
| 613 | |
| 614 | } |
| 615 | |
| 616 | break; |
| 617 | case 'sql': |
| 618 | |
| 619 | if ( ! empty($fieldSql) ) |
| 620 | { |
| 621 | global $wpdb; |
| 622 | $val = $wpdb->get_var( $wpdb->prepare( stripcslashes(str_replace("%%ID%%", "%d", $fieldSql)), $user->ID )); |
| 623 | if ( ! empty($fieldPhp) and !empty($fieldCode) ) |
| 624 | { |
| 625 | // if shortcode defined |
| 626 | if (strpos($fieldCode, '[') === 0) |
| 627 | { |
| 628 | $val = do_shortcode(str_replace("%%VALUE%%", $val, $fieldCode)); |
| 629 | } |
| 630 | else |
| 631 | { |
| 632 | $val = eval('return ' . stripcslashes(str_replace("%%VALUE%%", $val, $fieldCode)) . ';'); |
| 633 | } |
| 634 | } |
| 635 | wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_sql_field', $val, $element_name, $user->ID) ); |
| 636 | } |
| 637 | break; |
| 638 | default: |
| 639 | # code... |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | if ( $is_xml_export and isset($article[$element_name]) ) |
| 644 | { |
| 645 | $element_name_in_file = XmlCsvExport::_get_valid_header_name( $element_name ); |
| 646 | |
| 647 | $xmlWriter = apply_filters('wp_all_export_add_before_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $user->ID); |
| 648 | |
| 649 | $xmlWriter->beginElement($element_name_ns, $element_name_in_file, null); |
| 650 | $xmlWriter->writeData($article[$element_name], $element_name_in_file); |
| 651 | $xmlWriter->closeElement(); |
| 652 | |
| 653 | $xmlWriter = apply_filters('wp_all_export_add_after_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $user->ID); |
| 654 | } |
| 655 | } |
| 656 | return $article; |
| 657 | } |
| 658 | |
| 659 | public static function prepare_import_template( $exportOptions, &$templateOptions, $element_name, $ID) |
| 660 | { |
| 661 | |
| 662 | $options = $exportOptions; |
| 663 | |
| 664 | $element_type = $options['cc_type'][$ID]; |
| 665 | |
| 666 | $is_xml_template = $options['export_to'] == 'xml'; |
| 667 | |
| 668 | $implode_delimiter = XmlExportEngine::$implode; |
| 669 | |
| 670 | switch ($element_type) |
| 671 | { |
| 672 | // Export Users |
| 673 | case 'user_login': |
| 674 | $templateOptions['pmui']['login'] = '{'. $element_name .'[1]}'; |
| 675 | $templateOptions['is_update_login'] = 1; |
| 676 | break; |
| 677 | case 'user_pass': |
| 678 | $templateOptions['pmui']['pass'] = '{'. $element_name .'[1]}'; |
| 679 | $templateOptions['is_update_password'] = 1; |
| 680 | break; |
| 681 | case 'user_nicename': |
| 682 | $templateOptions['pmui']['nicename'] = '{'. $element_name .'[1]}'; |
| 683 | $templateOptions['is_update_nicename'] = 1; |
| 684 | break; |
| 685 | case 'user_email': |
| 686 | $templateOptions['pmui']['email'] = '{'. $element_name .'[1]}'; |
| 687 | $templateOptions['is_update_email'] = 1; |
| 688 | break; |
| 689 | case 'user_registered': |
| 690 | $templateOptions['pmui']['registered'] = '{'. $element_name .'[1]}'; |
| 691 | $templateOptions['is_update_registered'] = 1; |
| 692 | break; |
| 693 | case 'display_name': |
| 694 | $templateOptions['pmui']['display_name'] = '{'. $element_name .'[1]}'; |
| 695 | $templateOptions['is_update_display_name'] = 1; |
| 696 | break; |
| 697 | case 'user_url': |
| 698 | $templateOptions['pmui']['url'] = '{'. $element_name .'[1]}'; |
| 699 | $templateOptions['is_update_url'] = 1; |
| 700 | break; |
| 701 | |
| 702 | case 'first_name': |
| 703 | $templateOptions['pmui']['first_name'] = '{'. $element_name .'[1]}'; |
| 704 | $templateOptions['is_update_first_name'] = 1; |
| 705 | break; |
| 706 | case 'last_name': |
| 707 | $templateOptions['pmui']['last_name'] = '{'. $element_name .'[1]}'; |
| 708 | $templateOptions['is_update_last_name'] = 1; |
| 709 | break; |
| 710 | case 'wp_capabilities': |
| 711 | $templateOptions['pmui']['role'] = '{'. $element_name .'[1]}'; |
| 712 | $templateOptions['is_update_role'] = 1; |
| 713 | break; |
| 714 | case 'nickname': |
| 715 | $templateOptions['pmui']['nickname'] = '{'. $element_name .'[1]}'; |
| 716 | $templateOptions['is_update_nickname'] = 1; |
| 717 | break; |
| 718 | case 'description': |
| 719 | $templateOptions['pmui']['description'] = '{'. $element_name .'[1]}'; |
| 720 | $templateOptions['is_update_description'] = 1; |
| 721 | break; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * __get function. |
| 727 | * |
| 728 | * @access public |
| 729 | * @param mixed $key |
| 730 | * @return mixed |
| 731 | */ |
| 732 | public function __get( $key ) { |
| 733 | return $this->get( $key ); |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * Get a session variable |
| 738 | * |
| 739 | * @param string $key |
| 740 | * @param mixed $default used if the session variable isn't set |
| 741 | * @return mixed value of session variable |
| 742 | */ |
| 743 | public function get( $key, $default = null ) { |
| 744 | return isset( $this->{$key} ) ? $this->{$key} : $default; |
| 745 | } |
| 746 | } |
| 747 | } |