Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/themify-.../themify
File: themify-import-functions.php
return true;
[500] Fix | Delete
}
[501] Fix | Delete
[502] Fix | Delete
$posts = get_posts([
[503] Fix | Delete
'post_type' => get_post_types(),
[504] Fix | Delete
'post_status' => 'any',
[505] Fix | Delete
'meta_key' => '_' . static::DEMO_KEY,
[506] Fix | Delete
'meta_value' => 1,
[507] Fix | Delete
'no_found_rows' => true,
[508] Fix | Delete
'posts_per_page' => 1,
[509] Fix | Delete
]);
[510] Fix | Delete
if (!empty($posts)) {
[511] Fix | Delete
return true;
[512] Fix | Delete
}
[513] Fix | Delete
return false;
[514] Fix | Delete
}
[515] Fix | Delete
[516] Fix | Delete
protected static function set_import_id($oldId, $newId, $type, $skinId = 'default') {
[517] Fix | Delete
$newId = (int) $newId;
[518] Fix | Delete
if ($newId > 0) {
[519] Fix | Delete
$items = Themify_Storage::get(static::DEMO_KEY);
[520] Fix | Delete
$items = empty($items) ? array() : json_decode($items, true);
[521] Fix | Delete
if (empty($items[$skinId])) {
[522] Fix | Delete
$items[$skinId] = array();
[523] Fix | Delete
}
[524] Fix | Delete
if (empty($items[$skinId][$type])) {
[525] Fix | Delete
$items[$skinId][$type] = array();
[526] Fix | Delete
}
[527] Fix | Delete
if (!$oldId) {
[528] Fix | Delete
$items[$skinId][$type][] = $newId;
[529] Fix | Delete
} else {
[530] Fix | Delete
$items[$skinId][$type][$oldId] = $newId;
[531] Fix | Delete
}
[532] Fix | Delete
return Themify_Storage::set(static::DEMO_KEY, $items);
[533] Fix | Delete
}
[534] Fix | Delete
return false;
[535] Fix | Delete
}
[536] Fix | Delete
[537] Fix | Delete
protected static function get_import_id($old_id, $skinId = 'default', $import_type = null) {
[538] Fix | Delete
global $wpdb;
[539] Fix | Delete
$type = 'post';
[540] Fix | Delete
$key = 'post_id';
[541] Fix | Delete
$table = $wpdb->postmeta;
[542] Fix | Delete
if ($import_type === 'taxonomy') {
[543] Fix | Delete
$type = 'taxonomy';
[544] Fix | Delete
$key = 'term_id';
[545] Fix | Delete
$table = $wpdb->termmeta;
[546] Fix | Delete
}
[547] Fix | Delete
$items = Themify_Storage::get(static::DEMO_KEY);
[548] Fix | Delete
$items = empty($items) ? array() : json_decode($items, true);
[549] Fix | Delete
if (isset($items[$skinId])) {
[550] Fix | Delete
$items = $items[$skinId];
[551] Fix | Delete
}
[552] Fix | Delete
if (!empty($items) && !empty($items[$type][$old_id])) {
[553] Fix | Delete
return $items[$type][$old_id];
[554] Fix | Delete
}
[555] Fix | Delete
[556] Fix | Delete
//backward
[557] Fix | Delete
$result = $wpdb->get_row($wpdb->prepare(
[558] Fix | Delete
"SELECT {$key} FROM {$table} WHERE meta_key = '_" . static::DEMO_KEY . "_id' AND meta_value = %d LIMIT 1",
[559] Fix | Delete
$old_id
[560] Fix | Delete
), ARRAY_A);
[561] Fix | Delete
[562] Fix | Delete
if (isset($result[$key])) {
[563] Fix | Delete
if (self::set_import_id($old_id, $result[$key], $type, $skinId)) {
[564] Fix | Delete
if ($type === 'taxonomy') {
[565] Fix | Delete
delete_term_meta($result[$key], '_' . static::DEMO_KEY . '_id');
[566] Fix | Delete
} else {
[567] Fix | Delete
delete_post_meta($result[$key], '_' . static::DEMO_KEY . '_id');
[568] Fix | Delete
}
[569] Fix | Delete
}
[570] Fix | Delete
return $result[$key];
[571] Fix | Delete
}
[572] Fix | Delete
[573] Fix | Delete
return false;
[574] Fix | Delete
}
[575] Fix | Delete
[576] Fix | Delete
public static function import_term(array $term, $skinId = 'default', $update = false) {
[577] Fix | Delete
if (!empty($term)) {
[578] Fix | Delete
if (taxonomy_exists($term['taxonomy'])) {
[579] Fix | Delete
if ($term['taxonomy'] === 'nav_menu') {
[580] Fix | Delete
return self::import_menu($term, $update);
[581] Fix | Delete
}
[582] Fix | Delete
$term_id = term_exists($term['slug'], $term['taxonomy']);
[583] Fix | Delete
if (empty($term['parent']) || empty($term['parent_slug'])) {
[584] Fix | Delete
$parent = 0;
[585] Fix | Delete
} else {
[586] Fix | Delete
$parentTerm = self::get_term_id_by_slug($term['parent_slug'], $term['taxonomy'], self::get_import_id($term['parent'], $skinId, 'taxonomy'));
[587] Fix | Delete
$parent = $parentTerm !== false ? $parentTerm : 0;
[588] Fix | Delete
unset($parentTerm);
[589] Fix | Delete
}
[590] Fix | Delete
if (empty($term_id)) {
[591] Fix | Delete
[592] Fix | Delete
$term_id = wp_insert_term($term['name'], $term['taxonomy'], array(
[593] Fix | Delete
'parent' => $parent,
[594] Fix | Delete
'slug' => $term['slug'],
[595] Fix | Delete
'description' => isset($term['description']) ? $term['description'] : ''
[596] Fix | Delete
));
[597] Fix | Delete
} elseif ($update === true) {
[598] Fix | Delete
$term_id = wp_update_term($term_id, $term['taxonomy'], array(
[599] Fix | Delete
'name' => $term['name'],
[600] Fix | Delete
'slug' => $term['slug'],
[601] Fix | Delete
'parent' => $parent,
[602] Fix | Delete
'description' => isset($term['description']) ? $term['description'] : ''
[603] Fix | Delete
));
[604] Fix | Delete
}
[605] Fix | Delete
if ($term_id && !is_wp_error($term_id)) {
[606] Fix | Delete
if (is_array($term_id)) {
[607] Fix | Delete
$term_id = $term_id['term_id'];
[608] Fix | Delete
}
[609] Fix | Delete
return self::get_import_id($term_id, $skinId, 'taxonomy') ? true : (int) $term_id;
[610] Fix | Delete
} else {
[611] Fix | Delete
return false;
[612] Fix | Delete
}
[613] Fix | Delete
} else {
[614] Fix | Delete
return array('msg' => sprintf(__("Taxonomy %s dosen't exist", 'themify'), $term['taxonomy']), 'skip' => $term['taxonomy']);
[615] Fix | Delete
}
[616] Fix | Delete
}
[617] Fix | Delete
return false;
[618] Fix | Delete
}
[619] Fix | Delete
[620] Fix | Delete
public static function import_post(array $post, $skinId = 'default', $update = false) {
[621] Fix | Delete
if (!empty($post)) {
[622] Fix | Delete
[623] Fix | Delete
if (post_type_exists($post['post_type'])) {
[624] Fix | Delete
$post['post_author'] = get_current_user_id();
[625] Fix | Delete
$post['post_status'] = 'publish';
[626] Fix | Delete
if (!isset($post['post_parent'])) {
[627] Fix | Delete
$post['post_parent'] = 0;
[628] Fix | Delete
}
[629] Fix | Delete
if (!isset($post['menu_order'])) {
[630] Fix | Delete
$post['menu_order'] = 0;
[631] Fix | Delete
}
[632] Fix | Delete
if (!isset($post['post_content'])) {
[633] Fix | Delete
$post['post_content'] = '';
[634] Fix | Delete
}
[635] Fix | Delete
if (!isset($post['post_excerpt'])) {
[636] Fix | Delete
$post['post_excerpt'] = '';
[637] Fix | Delete
}
[638] Fix | Delete
if (isset($post['post_date'])) {
[639] Fix | Delete
$post['post_modified'] = $post['post_date'];
[640] Fix | Delete
}
[641] Fix | Delete
if ($post['post_type'] === 'nav_menu_item') {
[642] Fix | Delete
return self::import_menu_item($post, $skinId, $update);
[643] Fix | Delete
}
[644] Fix | Delete
$old_id = $post['ID'];
[645] Fix | Delete
$isWcPage = false;
[646] Fix | Delete
unset($post['ID']);
[647] Fix | Delete
/* Menu items don't have reliable post_title, skip the post_exists check */
[648] Fix | Delete
/* With tbp_template, different Themes can have duplicate templates so skip post_exists */
[649] Fix | Delete
if ($post['post_type'] !== 'tbp_template') {
[650] Fix | Delete
$isWcPage = !empty($post['is_wc_page']) && themify_is_woocommerce_active();
[651] Fix | Delete
$post_id = isset($post['post_date'], $post['post_title']) ? post_exists($post['post_title'], '', $post['post_date'], $post['post_type']) : 0;
[652] Fix | Delete
if ($isWcPage === true && !$post_id && isset($post['post_name'])) {
[653] Fix | Delete
$post_id = wc_get_page_id(str_replace('-', '', $post['post_name'])); //wc doesn't check if a post exist
[654] Fix | Delete
}
[655] Fix | Delete
if (!$post_id) {
[656] Fix | Delete
$post_id = self::get_import_id($old_id, $skinId);
[657] Fix | Delete
}
[658] Fix | Delete
if (!$post_id || $post_id <= 0 || get_post_type($post_id) !== $post['post_type']) {
[659] Fix | Delete
$post_id = 0;
[660] Fix | Delete
}
[661] Fix | Delete
if ($post_id > 0) {
[662] Fix | Delete
if ($update === true) {
[663] Fix | Delete
$post['ID'] = $post_id;
[664] Fix | Delete
} else {
[665] Fix | Delete
return $post_id;
[666] Fix | Delete
}
[667] Fix | Delete
}
[668] Fix | Delete
[669] Fix | Delete
if ($post['post_parent'] > 0) {
[670] Fix | Delete
$parent_id = self::get_import_id($post['post_parent'], $skinId);
[671] Fix | Delete
$post['post_parent'] = empty( $parent_id ) ? 0 : $parent_id;
[672] Fix | Delete
}
[673] Fix | Delete
[674] Fix | Delete
/**
[675] Fix | Delete
* for hierarchical taxonomies, IDs must be used so wp_set_post_terms can function properly
[676] Fix | Delete
* convert term slugs to IDs for hierarchical taxonomies
[677] Fix | Delete
*/
[678] Fix | Delete
if (!empty($post['tax_input'])) {
[679] Fix | Delete
foreach ($post['tax_input'] as $tax => $terms) {
[680] Fix | Delete
if (!taxonomy_exists($tax)) {
[681] Fix | Delete
unset($post['tax_input'][$tax]);
[682] Fix | Delete
} elseif (is_taxonomy_hierarchical($tax)) {
[683] Fix | Delete
$post['tax_input'][$tax] = array();
[684] Fix | Delete
$terms = explode(', ', $terms);
[685] Fix | Delete
foreach ($terms as $t) {
[686] Fix | Delete
$tid = self::get_term_id_by_slug($t, $tax);
[687] Fix | Delete
if ($tid !== false) {
[688] Fix | Delete
$post['tax_input'][$tax][] = $tid;
[689] Fix | Delete
}
[690] Fix | Delete
}
[691] Fix | Delete
if (empty($post['tax_input'][$tax])) {
[692] Fix | Delete
unset($post['tax_input'][$tax]);
[693] Fix | Delete
}
[694] Fix | Delete
}
[695] Fix | Delete
}
[696] Fix | Delete
}
[697] Fix | Delete
}
[698] Fix | Delete
$builderKey = ThemifyBuilder_Data_Manager::META_KEY;
[699] Fix | Delete
if (!empty($post['meta_input'][$builderKey])) {
[700] Fix | Delete
$builder = $post['meta_input'][$builderKey];
[701] Fix | Delete
}
[702] Fix | Delete
$isHome = !empty($post['is_home']);
[703] Fix | Delete
$productGallery = !empty($post['_product_image_gallery']) ? $post['_product_image_gallery'] : null;
[704] Fix | Delete
unset($post['meta_input'][$builderKey], $post['is_home'], $post['is_wc_page'], $post['_product_image_gallery']);
[705] Fix | Delete
$post_id = wp_insert_post($post, true);
[706] Fix | Delete
[707] Fix | Delete
if (!$post_id || is_wp_error($post_id)) {
[708] Fix | Delete
return false;
[709] Fix | Delete
}
[710] Fix | Delete
$post_id = (int) $post_id;
[711] Fix | Delete
if (!empty($builder)) {
[712] Fix | Delete
$res = ThemifyBuilder_Data_Manager::update_builder_meta($post_id, $builder, false);
[713] Fix | Delete
if (!empty($res['mid'])) {
[714] Fix | Delete
Themify_Global_Styles::save_used_global_styles($res['builder_data'], $post_id);
[715] Fix | Delete
}
[716] Fix | Delete
unset($builder, $res);
[717] Fix | Delete
}
[718] Fix | Delete
if (isset($post['post_date'])) {
[719] Fix | Delete
global $wpdb;
[720] Fix | Delete
$wpdb->update($wpdb->posts, array('post_modified' => $post['post_date'], 'post_modified_gmt' => get_gmt_from_date($post['post_date'])), array('id' => $post_id));
[721] Fix | Delete
}
[722] Fix | Delete
// Home page
[723] Fix | Delete
if ($isHome === true) {
[724] Fix | Delete
update_option('show_on_front', 'page');
[725] Fix | Delete
update_option('page_on_front', $post_id);
[726] Fix | Delete
}
[727] Fix | Delete
if ($isWcPage === true) {
[728] Fix | Delete
$post_name = str_replace('-', '', $post['post_name']);
[729] Fix | Delete
$wc_page = wc_get_page_id($post_name);
[730] Fix | Delete
if ($wc_page <= 0 || get_post_type($wc_page) !== $post['post_type']) {
[731] Fix | Delete
update_option('woocommerce_' . $post_name . '_page_id', $post_id, true);
[732] Fix | Delete
}
[733] Fix | Delete
}
[734] Fix | Delete
if ($productGallery !== null) {
[735] Fix | Delete
self::import_post_gallery($post_id, $productGallery);
[736] Fix | Delete
}
[737] Fix | Delete
return $post_id;
[738] Fix | Delete
} else {
[739] Fix | Delete
return array('msg' => sprintf(__("Post Type %s dosen't exist", 'themify'), $post['post_type']), 'skip' => $post['post_type']);
[740] Fix | Delete
}
[741] Fix | Delete
}
[742] Fix | Delete
}
[743] Fix | Delete
[744] Fix | Delete
public static function import_menu_item(array $post, $skinId = 'default', $update = false) {
[745] Fix | Delete
if ($post['post_type'] === 'nav_menu_item' && isset($post['tax_input']['nav_menu'])) {
[746] Fix | Delete
$oldId = (!empty($post['post_title']) && !empty($post['post_date'])) ? post_exists($post['post_title'], '', $post['post_date'], $post['post_type']) : false;
[747] Fix | Delete
if (!$oldId) {
[748] Fix | Delete
$oldId = self::get_import_id($post['ID'], $skinId);
[749] Fix | Delete
}
[750] Fix | Delete
if (!$oldId || get_post_type($oldId) !== $post['post_type']) {
[751] Fix | Delete
$oldId = 0;
[752] Fix | Delete
} elseif ($update === false) {
[753] Fix | Delete
return true;
[754] Fix | Delete
}
[755] Fix | Delete
$m = wp_get_nav_menu_object($post['tax_input']['nav_menu']);
[756] Fix | Delete
if (empty($m) || is_wp_error($m)) {
[757] Fix | Delete
return array('msg' => sprintf(__("Menu %s dosen't exist", 'themify'), $post['tax_input']['nav_menu']));
[758] Fix | Delete
}
[759] Fix | Delete
$menuId = $m->term_id;
[760] Fix | Delete
if (empty($post['meta_input']) || empty($post['meta_input']['_menu_item_type']) || empty($post['meta_input']['_menu_item_object'])) {
[761] Fix | Delete
return false;
[762] Fix | Delete
}
[763] Fix | Delete
$meta = $post['meta_input'];
[764] Fix | Delete
$menuType = $meta['_menu_item_type'];
[765] Fix | Delete
$args = array(
[766] Fix | Delete
'menu-item-title' => isset($post['post_title']) ? $post['post_title'] : '',
[767] Fix | Delete
'menu-item-position' => isset($post['menu_order']) ? $post['menu_order'] : 0,
[768] Fix | Delete
'menu-item-classes' => isset($meta['_menu_item_classes']) ? (is_array($meta['_menu_item_classes']) ? implode(' ', $meta['_menu_item_classes']) : $meta['_menu_item_classes']) : '',
[769] Fix | Delete
'menu-item-xfn' => isset($meta['_menu_item_xfn']) ? (is_array($meta['_menu_item_xfn']) ? implode(' ', $meta['_menu_item_xfn']) : $meta['_menu_item_xfn']) : '',
[770] Fix | Delete
'menu-item-type' => $menuType,
[771] Fix | Delete
'menu-item-object' => $meta['_menu_item_object'],
[772] Fix | Delete
'menu-item-target' => isset($meta['_menu_item_target']) ? $meta['_menu_item_target'] : '',
[773] Fix | Delete
'menu-item-description' => isset($post['post_content']) ? $post['post_content'] : '',
[774] Fix | Delete
'menu-item-post-date' => isset($post['post_date']) ? $post['post_date'] : '',
[775] Fix | Delete
'menu-item-post-date-gmt' => isset($post['post_date_gmt']) ? $post['post_date_gmt'] : '',
[776] Fix | Delete
'menu-item-status' => isset($post['post_status']) ? $post['post_status'] : 'publish',
[777] Fix | Delete
'menu-item-object-id' => 0
[778] Fix | Delete
);
[779] Fix | Delete
unset($m);
[780] Fix | Delete
if ($args['menu-item-post-date-gmt'] === '') {
[781] Fix | Delete
$args['menu-item-post-date-gmt'] = $args['menu-item-post-date'];
[782] Fix | Delete
}
[783] Fix | Delete
if ($menuType !== 'custom') {
[784] Fix | Delete
$objectType = $meta['_menu_item_object'];
[785] Fix | Delete
if (($menuType === 'post_type_archive' || $menuType === 'post_type') && !post_type_exists($objectType)) {
[786] Fix | Delete
return array('msg' => sprintf(__("Post Type %s dosen't exist", 'themify'), $objectType));
[787] Fix | Delete
} elseif ($menuType === 'taxonomy' && !taxonomy_exists($objectType)) {
[788] Fix | Delete
return array('msg' => sprintf(__("Taxonomy %s dosen't exist", 'themify'), $objectType));
[789] Fix | Delete
}
[790] Fix | Delete
if ($menuType !== 'post_type_archive') {
[791] Fix | Delete
$menu_item_id = $meta['_menu_item_object_id'];
[792] Fix | Delete
$newId = null;
[793] Fix | Delete
if (!is_numeric($menu_item_id) && function_exists('wc_get_page_id')) {
[794] Fix | Delete
$newId = wc_get_page_id($menu_item_id); //wc doesn't check if a post exist
[795] Fix | Delete
if ($newId <= 0 || get_post_type($newId) !== $objectType) {
[796] Fix | Delete
$newId = null;
[797] Fix | Delete
}
[798] Fix | Delete
} else {
[799] Fix | Delete
if (is_numeric($menu_item_id)) {
[800] Fix | Delete
$menu_item_id = (int) $menu_item_id;
[801] Fix | Delete
$newId = self::get_import_id($menu_item_id, $skinId, $menuType);
[802] Fix | Delete
}
[803] Fix | Delete
if ($menuType === 'post_type') {
[804] Fix | Delete
if (isset($meta['slug']) && (!$newId || get_post_type($newId) !== $objectType)) {
[805] Fix | Delete
$newId = null;
[806] Fix | Delete
if ($objectType === 'page') {
[807] Fix | Delete
$newId = get_page_by_path($meta['slug']);
[808] Fix | Delete
} else {
[809] Fix | Delete
$tmp = array(
[810] Fix | Delete
'name' => $meta['slug'],
[811] Fix | Delete
'post_type' => $objectType,
[812] Fix | Delete
'post_status' => 'any',
[813] Fix | Delete
'no_found_rows' => true,
[814] Fix | Delete
'posts_per_page' => 1
[815] Fix | Delete
);
[816] Fix | Delete
$newId = get_posts($tmp);
[817] Fix | Delete
if (!empty($newId)) {
[818] Fix | Delete
$newId = $newId[0];
[819] Fix | Delete
}
[820] Fix | Delete
unset($tmp);
[821] Fix | Delete
}
[822] Fix | Delete
}
[823] Fix | Delete
$newId = !empty($newId) ? (is_numeric($newId) ? $newId : $newId->ID) : null;
[824] Fix | Delete
} elseif ($menuType === 'taxonomy' && isset($meta['slug']) && (!$newId || !term_exists($newId, $objectType))) {
[825] Fix | Delete
$newId = self::get_term_id_by_slug($meta['slug'], $objectType, $newId);
[826] Fix | Delete
}
[827] Fix | Delete
}
[828] Fix | Delete
if (empty($newId)) {
[829] Fix | Delete
return false;
[830] Fix | Delete
}
[831] Fix | Delete
$args['menu-item-object-id'] = $newId;
[832] Fix | Delete
}
[833] Fix | Delete
} else {
[834] Fix | Delete
$args['menu-item-url'] = isset($meta['_menu_item_url']) ? $meta['_menu_item_url'] : '';
[835] Fix | Delete
}
[836] Fix | Delete
$parent = isset($meta['_menu_item_menu_item_parent']) ? (int) $meta['_menu_item_menu_item_parent'] : 0;
[837] Fix | Delete
if ($parent > 0) {
[838] Fix | Delete
$parent = self::get_import_id($parent, $skinId);
[839] Fix | Delete
if (!$parent || get_post_type($parent) !== $post['post_type']) {
[840] Fix | Delete
$parent = 0;
[841] Fix | Delete
}
[842] Fix | Delete
}
[843] Fix | Delete
unset($post);
[844] Fix | Delete
$args['menu-item-parent-id'] = $parent;
[845] Fix | Delete
$post_id = wp_update_nav_menu_item($menuId, $oldId, $args);
[846] Fix | Delete
if (!$post_id || is_wp_error($post_id)) {
[847] Fix | Delete
return false;
[848] Fix | Delete
}
[849] Fix | Delete
unset($args,
[850] Fix | Delete
$parent,
[851] Fix | Delete
$meta['slug'],
[852] Fix | Delete
$meta['is_home'],
[853] Fix | Delete
$meta['_menu_item_object'],
[854] Fix | Delete
$meta['_menu_item_object_id'],
[855] Fix | Delete
$meta['_menu_item_url'],
[856] Fix | Delete
$meta['_menu_item_menu_item_parent'],
[857] Fix | Delete
$meta['_menu_item_xfn'],
[858] Fix | Delete
$meta['_menu_item_classes'],
[859] Fix | Delete
$meta['_menu_item_target'],
[860] Fix | Delete
$meta['_menu_item_type']);
[861] Fix | Delete
if (!empty($meta)) {
[862] Fix | Delete
foreach ($meta as $k => $v) {
[863] Fix | Delete
if ($v !== '' && $v !== null) {
[864] Fix | Delete
update_post_meta($post_id, $k, sanitize_key($v));
[865] Fix | Delete
}
[866] Fix | Delete
}
[867] Fix | Delete
}
[868] Fix | Delete
return $post_id;
[869] Fix | Delete
}
[870] Fix | Delete
return false;
[871] Fix | Delete
}
[872] Fix | Delete
[873] Fix | Delete
public static function import_menu(array $menu, $update = false) {
[874] Fix | Delete
$m = wp_get_nav_menu_object($menu['slug']);
[875] Fix | Delete
if (empty($m) || is_wp_error($m)) {
[876] Fix | Delete
$m = wp_get_nav_menu_object(sanitize_title($menu['name']));
[877] Fix | Delete
}
[878] Fix | Delete
$m = empty($m) || is_wp_error($m) ? 0 : $m->term_id;
[879] Fix | Delete
if ($m === 0 || $update === true) {
[880] Fix | Delete
$m = wp_update_nav_menu_object($m, array(
[881] Fix | Delete
'menu-name' => $menu['name'],
[882] Fix | Delete
'parent' => isset($menu['parent']) ? $menu['parent'] : 0,
[883] Fix | Delete
'description' => isset($menu['description']) ? $menu['description'] : ''
[884] Fix | Delete
));
[885] Fix | Delete
}
[886] Fix | Delete
return $m && !is_wp_error($m) ? $m : false;
[887] Fix | Delete
}
[888] Fix | Delete
[889] Fix | Delete
public static function import_settings(array $settings, $skinId = 'default', $update = false) {
[890] Fix | Delete
if (!empty($settings)) {
[891] Fix | Delete
if (!empty($settings['theme_mods'])) {
[892] Fix | Delete
$theme = get_option('stylesheet');
[893] Fix | Delete
update_option('theme_mods_' . $theme, $settings['theme_mods']);
[894] Fix | Delete
unset($theme);
[895] Fix | Delete
}
[896] Fix | Delete
if (!empty($settings['menu'])) {
[897] Fix | Delete
foreach ($settings['menu'] as $menu) {
[898] Fix | Delete
$m = self::import_menu($menu, $update);
[899] Fix | Delete
if ($m !== false) {
[900] Fix | Delete
self::set_import_id($menu['term_id'], $m, 'taxonomy', $skinId);
[901] Fix | Delete
}
[902] Fix | Delete
}
[903] Fix | Delete
}
[904] Fix | Delete
if (!empty($settings['menu_locations'])) {
[905] Fix | Delete
$locations = $settings['menu_locations'];
[906] Fix | Delete
$themeLocations = get_theme_mod('nav_menu_locations');
[907] Fix | Delete
if(empty($themeLocations)){
[908] Fix | Delete
$themeLocations=[];
[909] Fix | Delete
}
[910] Fix | Delete
foreach ($locations as $location => $menu) {
[911] Fix | Delete
$m = self::import_menu($menu, $update);
[912] Fix | Delete
if ($m !== false) {
[913] Fix | Delete
$themeLocations[$location] = $m;
[914] Fix | Delete
self::set_import_id($menu['term_id'], $m, 'taxonomy', $skinId);
[915] Fix | Delete
}
[916] Fix | Delete
}
[917] Fix | Delete
set_theme_mod('nav_menu_locations', $themeLocations);
[918] Fix | Delete
unset($themeLocations, $locations);
[919] Fix | Delete
}
[920] Fix | Delete
if (!empty($settings['product_filter']) && method_exists('WPF', 'get_instance') && method_exists('WPF_Options', 'get_option')) {
[921] Fix | Delete
$instance = WPF::get_instance();
[922] Fix | Delete
if (method_exists($instance, 'get_plugin_name') && method_exists($instance, 'get_version')) {
[923] Fix | Delete
$instance = WPF_Options::get_option($instance->get_plugin_name(), $instance->get_version());
[924] Fix | Delete
if (method_exists($instance, 'get') && method_exists($instance, 'set')) {
[925] Fix | Delete
$instance->set(array_merge($settings['product_filter'], $instance->get()));
[926] Fix | Delete
}
[927] Fix | Delete
}
[928] Fix | Delete
}
[929] Fix | Delete
if (!empty($settings['product_attribute'])) {
[930] Fix | Delete
foreach ($settings['product_attribute'] as $slug => $label) {
[931] Fix | Delete
self::import_product_attribute($label, $slug);
[932] Fix | Delete
}
[933] Fix | Delete
}
[934] Fix | Delete
if (!empty($settings['homepage'])) {
[935] Fix | Delete
$homepage = get_page_by_path($settings['homepage']);
[936] Fix | Delete
if (!empty($homepage) && !is_wp_error($homepage)) {
[937] Fix | Delete
update_option('show_on_front', 'page');
[938] Fix | Delete
update_option('page_on_front', $homepage->ID);
[939] Fix | Delete
}
[940] Fix | Delete
unset($homepage);
[941] Fix | Delete
}
[942] Fix | Delete
if (!empty($settings['widgets'])) {
[943] Fix | Delete
$importWidgets = $settings['widgets'];
[944] Fix | Delete
$sidebars_widgets = array();
[945] Fix | Delete
$index = 1001;
[946] Fix | Delete
foreach ($importWidgets as $wid => $widgets) {
[947] Fix | Delete
$sidebars_widgets[$wid] = array();
[948] Fix | Delete
foreach ($widgets as $widget) {
[949] Fix | Delete
if (is_array($widget['options']) && isset($widget['options']['nav_menu'])) {
[950] Fix | Delete
$menuId = self::get_term_id_by_slug($widget['options']['nav_menu'], 'nav_menu');
[951] Fix | Delete
if ($menuId !== false) {
[952] Fix | Delete
$widget['options']['nav_menu'] = $menuId;
[953] Fix | Delete
} else {
[954] Fix | Delete
continue;
[955] Fix | Delete
}
[956] Fix | Delete
}
[957] Fix | Delete
++$index;
[958] Fix | Delete
$id = 'widget_' . $widget['id'];
[959] Fix | Delete
$themeWidget = get_option($id);
[960] Fix | Delete
if (empty($themeWidget)) {
[961] Fix | Delete
$themeWidget = array();
[962] Fix | Delete
}
[963] Fix | Delete
$themeWidget[$index] = $widget['options'];
[964] Fix | Delete
update_option($id, $themeWidget);
[965] Fix | Delete
$sidebars_widgets[$wid][] = $widget['id'] . '-' . $index;
[966] Fix | Delete
}
[967] Fix | Delete
}
[968] Fix | Delete
update_option('sidebars_widgets', $sidebars_widgets);
[969] Fix | Delete
unset($sidebars_widgets, $importWidgets);
[970] Fix | Delete
}
[971] Fix | Delete
if (!empty($settings['themify_settings'])) {
[972] Fix | Delete
$skinSettings = array_merge(themify_get_data(), $settings['themify_settings']);
[973] Fix | Delete
themify_set_data($skinSettings);
[974] Fix | Delete
}
[975] Fix | Delete
return true;
[976] Fix | Delete
}
[977] Fix | Delete
return false;
[978] Fix | Delete
}
[979] Fix | Delete
[980] Fix | Delete
public static function import_post_gallery($post_id, $gallery) {
[981] Fix | Delete
if (!empty($gallery)) {
[982] Fix | Delete
if (is_array($gallery)) {
[983] Fix | Delete
$gallery = implode(',', $gallery);
[984] Fix | Delete
}
[985] Fix | Delete
return update_post_meta($post_id, '_product_image_gallery', $gallery);
[986] Fix | Delete
}
[987] Fix | Delete
return false;
[988] Fix | Delete
}
[989] Fix | Delete
[990] Fix | Delete
public static function compare_files($f1, $f2, $size = 4096) {
[991] Fix | Delete
$fh1 = fopen($f1, 'rb');
[992] Fix | Delete
$fh2 = fopen($f2, 'rb');
[993] Fix | Delete
if ($fh1 !== false && $fh2 !== false) {
[994] Fix | Delete
try {
[995] Fix | Delete
while (!feof($fh1) && !feof($fh2)) {
[996] Fix | Delete
yield fread($fh1, $size) => fread($fh2, $size);
[997] Fix | Delete
}
[998] Fix | Delete
} finally {
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function