function pmai_pmxi_custom_field_to_delete($field_to_delete, $pid, $post_type, $options, $cur_meta_key) { if ($field_to_delete === false) { return $field_to_delete; } return pmai_is_acf_update_allowed($cur_meta_key, $options); }
function pmai_pmxi_custom_field_to_update( $field_to_update, $post_type, $options, $m_key ){ if ( $field_to_update === false ) return $field_to_update; return pmai_is_acf_update_allowed($m_key, $options); }
public function import_field($pid, $i, $key, $field, $fieldContainerName = "") { $this->parsing_data['logger'] and call_user_func($this->parsing_data['logger'], sprintf(__('- Importing field `%s`', 'pmxi_plugin'), $fieldContainerName . $field['name'])); // If update is not allowed if (!empty($this->articleData['ID']) and !pmai_is_acf_update_allowed($fieldContainerName . $field['name'], $this->parsing_data['import']->options)) { $this->parsing_data['logger'] and call_user_func($this->parsing_data['logger'], sprintf(__('- Field `%s` is skipped attempted to import options', 'pmxi_plugin'), $fieldContainerName . $field['name'])); return false; } $this->update_post_meta($pid, "_" . $fieldContainerName . $field['name'], $key); switch ($field['type']) { case 'text': case 'textarea': case 'number': case 'email': case 'password': case 'wysiwyg': case 'color_picker': case 'message': case 'date_picker': case 'limiter': case 'wp_wysiwyg': case 'date_time_picker': case 'oembed': case 'url': $this->update_post_meta($pid, $fieldContainerName . $field['name'], $field['values'][$i]); //$this->parsing_data['logger'] and call_user_func($this->parsing_data['logger'], sprintf(__('- Field `%s` updated with value `%s`', 'pmxi_plugin'), $fieldContainerName . $field['name'], $field['values'][$i])); break; case 'google_map': $this->update_post_meta($pid, $fieldContainerName . $field['name'], array('address' => $field['values']['address'][$i], 'lat' => $field['values']['lat'][$i], 'lng' => $field['values']['lng'][$i])); break; case 'paypal_item': $this->update_post_meta($pid, $fieldContainerName . $field['name'], array('item_name' => $field['values']['item_name'][$i], 'item_description' => $field['values']['item_description'][$i], 'price' => $field['values']['price'][$i])); break; case 'location-field': $this->update_post_meta($pid, $fieldContainerName . $field['name'], $field['values']['address'][$i] . "|" . $field['values']['lat'][$i] . "," . $field['values']['lng'][$i]); break; case 'gallery': //$imgs = explode(",", $field['values'][$i]); $gallery_ids = array(); if (!empty($field['values'][$i])) { foreach ($field['values'][$i] as $url) { if ("" != $url and $attid = $this->import_image($url, $pid, $this->parsing_data['logger'])) { $gallery_ids[] = $attid; } } } $this->update_post_meta($pid, $fieldContainerName . $field['name'], $gallery_ids); break; case 'user': if (strpos($field['values'][$i], ",")) { $users = array_map('trim', explode(",", $field['values'][$i])); if (!empty($users)) { foreach ($users as $key => $author) { $user = get_user_by('login', $author) or $user = get_user_by('slug', $author) or $user = get_user_by('email', $author) or ctype_digit($author) and $user = get_user_by('id', $author); $users[$key] = !empty($user) ? $user->ID : ""; } } $this->update_post_meta($pid, $fieldContainerName . $field['name'], $users); } else { $author = $field['values'][$i]; $user = get_user_by('login', $author) or $user = get_user_by('slug', $author) or $user = get_user_by('email', $author) or ctype_digit($author) and $user = get_user_by('id', $author); $this->update_post_meta($pid, $fieldContainerName . $field['name'], !empty($user) ? $user->ID : ""); } break; case 'image': if ("" != $field['values'][$i] and $attid = $this->import_image($field['values'][$i], $pid, $this->parsing_data['logger'])) { $this->update_post_meta($pid, $fieldContainerName . $field['name'], $attid); } break; case 'file': if ("" != $field['values'][$i] and $attid = $this->import_file($field['values'][$i], $pid, $this->parsing_data['logger'], $this->parsing_data['import']->options['is_fast_mode'])) { $this->update_post_meta($pid, $fieldContainerName . $field['name'], $attid); } break; case 'checkbox': case 'select': case 'radio': case 'true_false': if ($field['is_multiple']) { $this->update_post_meta($pid, $fieldContainerName . $field['name'], (!empty($field['values'][$i]) and is_array($field['values'][$i])) ? $field['values'][$i] : array()); } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], $field['values'][$i]); } break; case 'taxonomy': if ($field['is_multiple'] !== true and $field['is_multiple'] == 'nesting') { if (!empty($field['values'])) { foreach ($field['values'] as $tx_name => $txes) { $assign_taxes = array(); // create term if not exists if (!empty($txes[$i])) { foreach ($txes[$i] as $key => $single_tax) { if (is_array($single_tax)) { $parent_id = !empty($single_tax['parent']) ? pmxi_recursion_taxes($single_tax['parent'], $tx_name, $txes[$i], $key) : ''; $term = $parent_id ? is_exists_term($tx_name, $single_tax['name'], (int) $parent_id) : is_exists_term($tx_name, $single_tax['name']); if (empty($term) and !is_wp_error($term)) { $term_attr = array('parent' => !empty($parent_id) ? $parent_id : 0); $term = wp_insert_term($single_tax['name'], $tx_name, $term_attr); } if (is_wp_error($term)) { } elseif (!empty($term)) { $cat_id = $term['term_id']; if ($cat_id and $single_tax['assign']) { if (!in_array($cat_id, $assign_taxes)) { $assign_taxes[] = $cat_id; } } } } } } if (!empty($assign_taxes)) { $this->update_post_meta($pid, $fieldContainerName . $field['name'], $assign_taxes); } } } } elseif ($field['is_multiple']) { $mult_values = array(); foreach ($field['values'] as $number => $values) { $mult_values[] = trim($values[$i]); } $this->update_post_meta($pid, $fieldContainerName . $field['name'], $mult_values); } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], $field['values'][$i]); } break; case 'page_link': if ("" != $field['values'][$i]) { $post_ids = array(); $entries = explode(",", $field['values'][$i]); if (!empty($entries) and is_array($entries)) { foreach ($entries as $ev) { $args = array('name' => $ev, 'post_type' => 'any', 'post_status' => 'any', 'numberposts' => 1); //$the_query = new WP_Query( $args ); $my_posts = get_posts($args); if ($my_posts) { $post_ids[] = get_permalink($my_posts[0]->ID); } elseif (ctype_digit($ev)) { $my_post = get_post($ev); if ($my_post) { $post_ids[] = get_permalink($my_post->ID); } } //wp_reset_postdata(); } } if (!empty($post_ids)) { if ($field['multiple']) { $this->update_post_meta($pid, $fieldContainerName . $field['name'], $post_ids); } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], array_shift($post_ids)); } } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], ''); } } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], ''); } break; case 'post_object': if ("" != $field['values'][$i]) { $post_ids = array(); $entries = explode(",", $field['values'][$i]); if (!empty($entries) and is_array($entries)) { foreach ($entries as $ev) { $args = array('name' => $ev, 'post_type' => 'any', 'post_status' => 'any', 'numberposts' => 1); $my_posts = get_posts($args); if ($my_posts) { $post_ids[] = $my_posts[0]->ID; } elseif (ctype_digit($ev)) { $post_ids[] = $ev; } } } if (!empty($post_ids)) { if ($field['multiple']) { $this->update_post_meta($pid, $fieldContainerName . $field['name'], $post_ids); } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], array_shift($post_ids)); } } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], ''); } } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], ''); } break; case 'relationship': if ("" != $field['values'][$i]) { $post_ids = array(); $entries = explode(",", $field['values'][$i]); if (!empty($entries) and is_array($entries)) { foreach ($entries as $ev) { if (ctype_digit($ev)) { $post_ids[] = $ev; } else { $args = array('name' => $ev, 'post_type' => 'any', 'post_status' => 'any', 'numberposts' => 1); $my_posts = get_posts($args); if ($my_posts) { $post_ids[] = $my_posts[0]->ID; } wp_reset_postdata(); } } } if (!empty($post_ids)) { $this->update_post_meta($pid, $fieldContainerName . $field['name'], $post_ids); } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], ''); } } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], ''); } break; case 'gravity_forms_field': case 'acf_cf7': if ($field['is_multiple']) { $this->update_post_meta($pid, $fieldContainerName . $field['name'], explode(",", $field['values'][$i])); } else { $this->update_post_meta($pid, $fieldContainerName . $field['name'], $field['values'][$i]); } break; case 'repeater': if (!empty($field['values'])) { if ($field['is_variable'] == 'xml') { // is variable repeater mode enabled for ($k = 0; $k < $field['values'][$i]['countRows']; $k++) { foreach ($field['values'][$i]['vals'] as $sub_field_key => $sub_field) { $this->import_field($pid, $k, $sub_field_key, $sub_field, $fieldContainerName . $field['name'] . "_" . $k . "_"); } } $this->update_post_meta($pid, $fieldContainerName . $field['name'], $field['values'][$i]['countRows']); } else { // is fixed repeater mode enabled $countRows = 0; foreach ($field['values'] as $row_number => $row) { if (!empty($row)) { $countRows++; $is_row_import_allowed = true; if ($field['is_ignore_empties'] and $field['is_variable'] === false or $field['is_variable']) { $is_row_import_allowed = false; foreach ($row as $sub_field_key_check => $sub_field_check) { if (!empty($sub_field_check['xpath']) and !empty($sub_field_check['values'][$i]) and !in_array($sub_field_check['type'], array('repeater'))) { $is_row_import_allowed = true; break; } } } if ($is_row_import_allowed) { if ($field['is_variable'] !== false and $field['is_variable'] != '') { $countCSVrows = 0; foreach ($row as $sub_field_key => $sub_field) { $entries = explode($field['is_variable'], $sub_field['values'][$i]); if (count($entries) > $countCSVrows) { $countCSVrows = count($entries); } } for ($k = 0; $k < $countCSVrows; $k++) { foreach ($row as $sub_field_key => $sub_field) { $entries = explode($field['is_variable'], $sub_field['values'][$i]); $sub_field['values'][$i] = empty($entries[$k]) ? '' : $entries[$k]; $this->import_field($pid, $i, $sub_field_key, $sub_field, $fieldContainerName . $field['name'] . "_" . $k . "_"); } } $countRows = $countCSVrows; } else { foreach ($row as $sub_field_key => $sub_field) { $this->import_field($pid, $i, $sub_field_key, $sub_field, $fieldContainerName . $field['name'] . "_" . $row_number . "_"); } } } else { $countRows--; } } } $this->update_post_meta($pid, $fieldContainerName . $field['name'], $countRows); } } break; case 'flexible_content': if (!empty($field['values'])) { $layouts = array(); foreach ($field['values'] as $layout_number => $layout) { if (!empty($layout['fields'])) { $layouts[] = $layout['acf_fc_layout']; foreach ($layout['fields'] as $sub_field_key => $sub_field) { $this->import_field($pid, $i, $sub_field_key, $sub_field, $fieldContainerName . $field['name'] . "_" . $layout_number . "_"); } } } $this->update_post_meta($pid, $fieldContainerName . $field['name'], $layouts); } break; default: # code... break; } $v = get_post_meta($pid, $fieldContainerName . $field['name'], true); $this->parsing_data['logger'] and call_user_func($this->parsing_data['logger'], sprintf(__('- Field `%s` updated with value `%s`', 'pmxi_plugin'), $fieldContainerName . $field['name'], maybe_serialize($v))); }