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
/home/sportsfe.../httpdocs/wp-conte.../plugins/themify-.../themify
File: themify-import-functions.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* importing/erasing contents of the theme
[3] Fix | Delete
*
[4] Fix | Delete
* @package Themify
[5] Fix | Delete
*/
[6] Fix | Delete
defined('ABSPATH') || exit;
[7] Fix | Delete
[8] Fix | Delete
class Themify_Import_Helper {
[9] Fix | Delete
[10] Fix | Delete
const DEMO_KEY = 'tf_demo';
[11] Fix | Delete
[12] Fix | Delete
public static function init() {
[13] Fix | Delete
add_action('wp_ajax_themify_import_terms', array(__CLASS__, 'import_ajax_terms'));
[14] Fix | Delete
add_action('wp_ajax_themify_import_posts', array(__CLASS__, 'import_ajax_posts'));
[15] Fix | Delete
add_action('wp_ajax_themify_import_theme_data', array(__CLASS__, 'import_ajax_theme_data'));
[16] Fix | Delete
add_action('wp_ajax_themify_upload_image', array(__CLASS__, 'import_ajax_image'));
[17] Fix | Delete
add_action('wp_ajax_themify_import_gallery', array(__CLASS__, 'import_ajax_post_gallery'));
[18] Fix | Delete
add_action('wp_ajax_themify_erase_content', array(__CLASS__, 'erase_demo'));
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
public static function import_ajax_posts() {
[22] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[23] Fix | Delete
if (current_user_can('import')) {
[24] Fix | Delete
if (isset($_POST['data'])) {
[25] Fix | Delete
$posts = stripslashes_deep($_POST['data']);
[26] Fix | Delete
} elseif (isset($_FILES['data'])) {
[27] Fix | Delete
$posts = file_get_contents($_FILES['data']['tmp_name']);
[28] Fix | Delete
}
[29] Fix | Delete
if (!empty($posts)) {
[30] Fix | Delete
self::set_time_limit();
[31] Fix | Delete
self::raise_memory_limit();
[32] Fix | Delete
$posts = json_decode($posts, true);
[33] Fix | Delete
$skinId = !empty($_POST['id']) ? $_POST['id'] : 'default';
[34] Fix | Delete
$ids = array();
[35] Fix | Delete
foreach ($posts as $post) {
[36] Fix | Delete
$id = self::import_post($post, $skinId);
[37] Fix | Delete
if (is_numeric($id) && $post['post_type'] !== 'tbp_template') {
[38] Fix | Delete
self::set_import_id($post['ID'], $id, 'post', $skinId);
[39] Fix | Delete
}
[40] Fix | Delete
$ids[$post['ID']] = $id;
[41] Fix | Delete
}
[42] Fix | Delete
if (!empty($ids)) {
[43] Fix | Delete
wp_send_json_success($ids);
[44] Fix | Delete
}
[45] Fix | Delete
}
[46] Fix | Delete
}
[47] Fix | Delete
wp_send_json_error();
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
public static function import_ajax_terms() {
[51] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[52] Fix | Delete
if (current_user_can('import')) {
[53] Fix | Delete
if (isset($_POST['data'])) {
[54] Fix | Delete
$terms = stripslashes_deep($_POST['data']);
[55] Fix | Delete
} elseif (isset($_FILES['data'])) {
[56] Fix | Delete
$terms = file_get_contents($_FILES['data']['tmp_name']);
[57] Fix | Delete
}
[58] Fix | Delete
if (!empty($terms)) {
[59] Fix | Delete
self::set_time_limit();
[60] Fix | Delete
self::raise_memory_limit();
[61] Fix | Delete
$terms = json_decode($terms, true);
[62] Fix | Delete
$skinId = !empty($_POST['id']) ? $_POST['id'] : 'default';
[63] Fix | Delete
$ids = array();
[64] Fix | Delete
foreach ($terms as $term) {
[65] Fix | Delete
$id = self::import_term($term);
[66] Fix | Delete
if (is_numeric($id)) {
[67] Fix | Delete
self::set_import_id($term['term_id'], $id, 'taxonomy', $skinId);
[68] Fix | Delete
}
[69] Fix | Delete
$ids[$term['term_id']] = $id;
[70] Fix | Delete
}
[71] Fix | Delete
if (!empty($ids)) {
[72] Fix | Delete
wp_send_json_success($ids);
[73] Fix | Delete
}
[74] Fix | Delete
}
[75] Fix | Delete
}
[76] Fix | Delete
wp_send_json_error();
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
public static function import_ajax_theme_data() {
[80] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[81] Fix | Delete
if (current_user_can('manage_options')) {
[82] Fix | Delete
if (isset($_POST['data'])) {
[83] Fix | Delete
$settings = stripslashes_deep($_POST['data']);
[84] Fix | Delete
} elseif (isset($_FILES['data'])) {
[85] Fix | Delete
$settings = file_get_contents($_FILES['data']['tmp_name']);
[86] Fix | Delete
}
[87] Fix | Delete
if (!empty($settings)) {
[88] Fix | Delete
self::set_time_limit();
[89] Fix | Delete
self::raise_memory_limit();
[90] Fix | Delete
$settings = json_decode($settings, true);
[91] Fix | Delete
$skinId = !empty($_POST['id']) ? $_POST['id'] : 'default';
[92] Fix | Delete
$id = self::import_settings($settings, $skinId);
[93] Fix | Delete
if ($id !== false) {
[94] Fix | Delete
wp_send_json_success($id);
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
}
[98] Fix | Delete
wp_send_json_error();
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
public static function import_ajax_image() {
[102] Fix | Delete
if (!empty($_POST['postData']) && current_user_can('import')) {
[103] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[104] Fix | Delete
$postData = json_decode(stripslashes_deep($_POST['postData']), true);
[105] Fix | Delete
$response = array();
[106] Fix | Delete
if (!empty($postData)) {
[107] Fix | Delete
self::set_time_limit();
[108] Fix | Delete
self::raise_memory_limit('image');
[109] Fix | Delete
$skinId = !empty($_POST['save_id']) ? $_POST['save_id'] : '';
[110] Fix | Delete
$webp = empty($_POST['stop_webp']) ? true : false;
[111] Fix | Delete
foreach ($postData as $key => $arrPost) {
[112] Fix | Delete
if (!empty($arrPost['thumb'])) {
[113] Fix | Delete
$blob = !empty($_FILES[$key]) && $_FILES[$key] != '1' ? $_FILES[$key] : null;
[114] Fix | Delete
$res = self::import_media($arrPost, $blob, $webp);
[115] Fix | Delete
if ($skinId !== '' && is_array($res) && isset($res['id'])) {
[116] Fix | Delete
self::set_import_id(null, $res['id'], 'attachment', $skinId);
[117] Fix | Delete
}
[118] Fix | Delete
$response[$arrPost['thumb']] = $res;
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
[124] Fix | Delete
wp_send_json_success($response);
[125] Fix | Delete
}
[126] Fix | Delete
wp_send_json_error();
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
public static function import_ajax_post_gallery() {
[130] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[131] Fix | Delete
if (current_user_can('import')) {
[132] Fix | Delete
if (isset($_POST['data'])) {
[133] Fix | Delete
$data = stripslashes_deep($_POST['data']);
[134] Fix | Delete
} elseif (isset($_FILES['data'])) {
[135] Fix | Delete
$data = file_get_contents($_FILES['data']['tmp_name']);
[136] Fix | Delete
}
[137] Fix | Delete
if (!empty($data)) {
[138] Fix | Delete
$data = json_decode($data, true);
[139] Fix | Delete
if (!empty($data)) {
[140] Fix | Delete
self::set_time_limit();
[141] Fix | Delete
self::raise_memory_limit();
[142] Fix | Delete
foreach ($data as $post_id => $gallery) {
[143] Fix | Delete
self::import_post_gallery($post_id, $gallery);
[144] Fix | Delete
}
[145] Fix | Delete
wp_send_json_success();
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
wp_send_json_error();
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
protected static function set_time_limit(int $limit = 0) {
[153] Fix | Delete
ignore_user_abort(true);
[154] Fix | Delete
if (function_exists('set_time_limit') && false === strpos(ini_get('disable_functions'), 'set_time_limit') && !ini_get('safe_mode')) { // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved
[155] Fix | Delete
@set_time_limit($limit); // @codingStandardsIgnoreLine
[156] Fix | Delete
}
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
protected static function raise_memory_limit(string $context = 'admin',string $size = '512MB') {
[160] Fix | Delete
if (!defined('WP_MAX_MEMORY_LIMIT')) {
[161] Fix | Delete
define('WP_MAX_MEMORY_LIMIT', $size);
[162] Fix | Delete
}
[163] Fix | Delete
return wp_raise_memory_limit($context);
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
public static function import_product_attribute($name, $slug) {
[167] Fix | Delete
if (function_exists('wc_create_attribute') && !empty($name) && !empty($slug) && current_user_can('import')) {
[168] Fix | Delete
wc_create_attribute(array(
[169] Fix | Delete
'name' => $name,
[170] Fix | Delete
'slug' => $slug,
[171] Fix | Delete
));
[172] Fix | Delete
$slug = wc_attribute_taxonomy_name($slug);
[173] Fix | Delete
register_taxonomy($slug, array('product'), array(
[174] Fix | Delete
'labels' => array(
[175] Fix | Delete
'name' => sprintf(_x('Product %s', 'Product Attribute', 'woocommerce'), $name),
[176] Fix | Delete
'singular_name' => $name,
[177] Fix | Delete
)
[178] Fix | Delete
));
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
protected static function get_term_id_by_slug($slug, $tax, $importId = 0) {
[183] Fix | Delete
$term = get_term_by('slug', $slug, $tax);
[184] Fix | Delete
if ($importId > 0 && (!$term || is_wp_error($term))) {
[185] Fix | Delete
$term = get_term((int) $importId, $tax);
[186] Fix | Delete
}
[187] Fix | Delete
if (!empty($term) && !is_wp_error($term) && $term->taxonomy === $tax) {
[188] Fix | Delete
return (int) $term->term_id;
[189] Fix | Delete
}
[190] Fix | Delete
return false;
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
/**
[194] Fix | Delete
* Removes all content marked as demo
[195] Fix | Delete
*
[196] Fix | Delete
* @return void
[197] Fix | Delete
*/
[198] Fix | Delete
public static function erase_demo() {
[199] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[200] Fix | Delete
if (!current_user_can('delete_pages')) {
[201] Fix | Delete
wp_send_json_error(__('You are not allowed to delete pages on this site', 'themify'));
[202] Fix | Delete
}
[203] Fix | Delete
if (isset($_POST['data'])) {
[204] Fix | Delete
$data = json_decode(stripslashes_deep($_POST['data']), true);
[205] Fix | Delete
} elseif (isset($_FILES['data'])) {
[206] Fix | Delete
$data = file_get_contents($_FILES['data']['tmp_name']);
[207] Fix | Delete
} else {
[208] Fix | Delete
$data = array();
[209] Fix | Delete
}
[210] Fix | Delete
self::set_time_limit();
[211] Fix | Delete
self::raise_memory_limit();
[212] Fix | Delete
$keepModified = !empty($data['keep_modify']) && $data['keep_modify'] !== '0';
[213] Fix | Delete
$isWc = themify_is_woocommerce_active();
[214] Fix | Delete
$wc_pages = array();
[215] Fix | Delete
if ($isWc === true) {
[216] Fix | Delete
foreach (array('myaccount', 'shop', 'cart', 'checkout', 'view_order', 'terms') as $wc_page) {
[217] Fix | Delete
$page_id = wc_get_page_id($wc_page);
[218] Fix | Delete
if ($page_id > 0) {
[219] Fix | Delete
$wc_pages[$page_id] = $wc_page;
[220] Fix | Delete
}
[221] Fix | Delete
}
[222] Fix | Delete
}
[223] Fix | Delete
$terms = get_terms([
[224] Fix | Delete
'number' => 0,
[225] Fix | Delete
'meta_key' => '_' . static::DEMO_KEY,
[226] Fix | Delete
'meta_value' => 1,
[227] Fix | Delete
'no_found_rows' => true,
[228] Fix | Delete
]
[229] Fix | Delete
);
[230] Fix | Delete
if (!empty($terms)) {
[231] Fix | Delete
foreach ($terms as $term) {
[232] Fix | Delete
wp_delete_term($term->term_id, $term->taxonomy);
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
$posts = get_posts([
[237] Fix | Delete
'post_type' => get_post_types(),
[238] Fix | Delete
'post_status' => 'any',
[239] Fix | Delete
'meta_key' => '_' . static::DEMO_KEY,
[240] Fix | Delete
'meta_value' => 1,
[241] Fix | Delete
'no_found_rows' => true,
[242] Fix | Delete
'posts_per_page' => -1,
[243] Fix | Delete
]);
[244] Fix | Delete
foreach ($posts as $post) {
[245] Fix | Delete
$delete = $keepModified === true ? !(strtotime($post->post_modified) > strtotime($post->post_date)) : true;
[246] Fix | Delete
if ($delete === true) {
[247] Fix | Delete
if ($post->post_type === 'attachment') {
[248] Fix | Delete
self::erase_image($post, $keepModified);
[249] Fix | Delete
} elseif ($isWc === true && $post->post_type === 'product') {
[250] Fix | Delete
self::erase_product($post->ID, $keepModified);
[251] Fix | Delete
} else {
[252] Fix | Delete
wp_delete_post($post->ID, true);
[253] Fix | Delete
if (isset($wc_pages[$post->ID])) {
[254] Fix | Delete
delete_option('woocommerce_' . $post->post_name . '_page_id');
[255] Fix | Delete
}
[256] Fix | Delete
}
[257] Fix | Delete
}
[258] Fix | Delete
}
[259] Fix | Delete
$items = Themify_Storage::get(static::DEMO_KEY);
[260] Fix | Delete
$isBreak = false;
[261] Fix | Delete
if (!empty($items)) {
[262] Fix | Delete
$items = json_decode($items, true);
[263] Fix | Delete
$memory = (int) (wp_convert_hr_to_bytes(WP_MEMORY_LIMIT) * MB_IN_BYTES);
[264] Fix | Delete
$limit = $memory > 128 ? 100 : ($memory < 64 ? 60 : 80);
[265] Fix | Delete
$count = 0;
[266] Fix | Delete
foreach ($items as $skin => $el) {
[267] Fix | Delete
if (!empty($el['taxonomy'])) {
[268] Fix | Delete
foreach ($el['taxonomy'] as $oldId => $newId) {
[269] Fix | Delete
$term = get_term($newId);
[270] Fix | Delete
$delete = true;
[271] Fix | Delete
if (!empty($term) && !is_wp_error($term)) {
[272] Fix | Delete
$success = current_user_can('delete_term', $newId) ? wp_delete_term($newId, $term->taxonomy) : false;
[273] Fix | Delete
if ($success === true) {
[274] Fix | Delete
++$count;
[275] Fix | Delete
} elseif ($success === false) {
[276] Fix | Delete
$delete = false;
[277] Fix | Delete
} elseif (is_wp_error($success) && $success === 0) {
[278] Fix | Delete
unset($items[$skin]['taxonomy'][$oldId]);
[279] Fix | Delete
}
[280] Fix | Delete
}
[281] Fix | Delete
if ($delete === true) {
[282] Fix | Delete
unset($items[$skin]['taxonomy'][$oldId]);
[283] Fix | Delete
if ($count >= $limit) {
[284] Fix | Delete
$isBreak = true;
[285] Fix | Delete
break;
[286] Fix | Delete
}
[287] Fix | Delete
}
[288] Fix | Delete
}
[289] Fix | Delete
}
[290] Fix | Delete
if (!empty($el['post']) && $count < $limit) {
[291] Fix | Delete
foreach ($el['post'] as $oldId => $newId) {
[292] Fix | Delete
$post = get_post($newId);
[293] Fix | Delete
$delete = true;
[294] Fix | Delete
if (!empty($post)) {
[295] Fix | Delete
$delete = $keepModified === true ? !(strtotime($post->post_modified) > strtotime($post->post_date)) : true;
[296] Fix | Delete
if ($delete === true) {
[297] Fix | Delete
$post_type = $post->post_type;
[298] Fix | Delete
if (($post_type !== 'page' && current_user_can('delete_post', $newId)) || ($post_type === 'page' && current_user_can('delete_page', $newId))) {
[299] Fix | Delete
if ($post_type === 'attachment') {
[300] Fix | Delete
$el['attachment'][] = $newId;
[301] Fix | Delete
} else {
[302] Fix | Delete
if ($isWc === true && $post_type === 'product') {
[303] Fix | Delete
$deletedItems = self::erase_product($post->ID, $keepModified);
[304] Fix | Delete
$delete = false;
[305] Fix | Delete
foreach ($deletedItems['posts'] as $product_id => $is_deleted) {
[306] Fix | Delete
if ($is_deleted === true) {
[307] Fix | Delete
++$count;
[308] Fix | Delete
$product_id = (int) $product_id;
[309] Fix | Delete
unset($items[$skin]['post'][$product_id]);
[310] Fix | Delete
}
[311] Fix | Delete
}
[312] Fix | Delete
if (!empty($deletedItems['attachment'])) {
[313] Fix | Delete
foreach ($deletedItems['attachment'] as $image_id => $is_deleted) {
[314] Fix | Delete
if ($is_deleted === true) {
[315] Fix | Delete
++$count;
[316] Fix | Delete
if (isset($items[$skin]['attachment'])) {
[317] Fix | Delete
$image_id = (int) $image_id;
[318] Fix | Delete
unset($items[$skin]['attachment'][$image_id], $el['attachment'][$image_id]);
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
}
[322] Fix | Delete
}
[323] Fix | Delete
} else {
[324] Fix | Delete
$success = wp_delete_post($post->ID, true);
[325] Fix | Delete
$delete = !empty($success);
[326] Fix | Delete
if ($delete === true) {
[327] Fix | Delete
++$count;
[328] Fix | Delete
}
[329] Fix | Delete
}
[330] Fix | Delete
}
[331] Fix | Delete
} else {
[332] Fix | Delete
$delete = false;
[333] Fix | Delete
}
[334] Fix | Delete
}
[335] Fix | Delete
}
[336] Fix | Delete
if ($delete === true) {
[337] Fix | Delete
unset($items[$skin]['post'][$oldId]);
[338] Fix | Delete
if (!empty($post) && isset($wc_pages[$post->ID])) {
[339] Fix | Delete
delete_option('woocommerce_' . str_replace('-', '', $post->post_name) . '_page_id');
[340] Fix | Delete
}
[341] Fix | Delete
}
[342] Fix | Delete
if ($count >= $limit) {
[343] Fix | Delete
$isBreak = true;
[344] Fix | Delete
break;
[345] Fix | Delete
}
[346] Fix | Delete
}
[347] Fix | Delete
}
[348] Fix | Delete
if (!empty($el['attachment']) && $count < $limit) {
[349] Fix | Delete
foreach ($el['attachment'] as $oldId => $newId) {
[350] Fix | Delete
$post = get_post($newId);
[351] Fix | Delete
$delete = true;
[352] Fix | Delete
if (!empty($post) && $post->post_type === 'attachment') {
[353] Fix | Delete
$delete = $keepModified === true ? !(strtotime($post->post_modified) > strtotime($post->post_date)) : true;
[354] Fix | Delete
if ($delete === true) {
[355] Fix | Delete
$delete = current_user_can('delete_post', $newId) ? self::erase_image($post, $keepModified) : false;
[356] Fix | Delete
if ($delete === true) {
[357] Fix | Delete
++$count;
[358] Fix | Delete
}
[359] Fix | Delete
}
[360] Fix | Delete
}
[361] Fix | Delete
if ($delete === true) {
[362] Fix | Delete
unset($items[$skin]['attachment'][$oldId]);
[363] Fix | Delete
if ($count >= $limit) {
[364] Fix | Delete
$isBreak = true;
[365] Fix | Delete
break;
[366] Fix | Delete
}
[367] Fix | Delete
}
[368] Fix | Delete
}
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
if (empty($items[$skin]['taxonomy'])) {
[372] Fix | Delete
unset($items[$skin]['taxonomy']);
[373] Fix | Delete
}
[374] Fix | Delete
if (empty($items[$skin]['post'])) {
[375] Fix | Delete
unset($items[$skin]['post']);
[376] Fix | Delete
}
[377] Fix | Delete
if (empty($items[$skin]['attachment'])) {
[378] Fix | Delete
unset($items[$skin]['attachment']);
[379] Fix | Delete
}
[380] Fix | Delete
if (empty($items[$skin])) {
[381] Fix | Delete
unset($items[$skin]);
[382] Fix | Delete
}
[383] Fix | Delete
if ($isBreak === true) {
[384] Fix | Delete
break;
[385] Fix | Delete
}
[386] Fix | Delete
}
[387] Fix | Delete
if (!empty($items)) {
[388] Fix | Delete
Themify_Storage::set(static::DEMO_KEY, $items);
[389] Fix | Delete
} else {
[390] Fix | Delete
Themify_Storage::delete(static::DEMO_KEY);
[391] Fix | Delete
}
[392] Fix | Delete
}
[393] Fix | Delete
if ($isBreak === true) {
[394] Fix | Delete
$response = 'repeat';
[395] Fix | Delete
} else {
[396] Fix | Delete
$response = self::has_demo_content() ? 'hasdemo' : 0;
[397] Fix | Delete
}
[398] Fix | Delete
wp_send_json_success($response);
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
public static function erase_product($id, $keepModified = false) {
[402] Fix | Delete
$product = themify_is_woocommerce_active() ? wc_get_product($id) : null;
[403] Fix | Delete
$res = array('posts' => array());
[404] Fix | Delete
if (!empty($product)) {
[405] Fix | Delete
$isVariable = $product->is_type('variable');
[406] Fix | Delete
$isGroup = $product->is_type('grouped');
[407] Fix | Delete
if ($isVariable || $isGroup) {
[408] Fix | Delete
foreach ($product->get_children() as $child_id) {
[409] Fix | Delete
$child = wc_get_product($child_id);
[410] Fix | Delete
$delete = true;
[411] Fix | Delete
if (!empty($child)) {
[412] Fix | Delete
if ($isVariable) {
[413] Fix | Delete
$delete = $child->delete(true);
[414] Fix | Delete
} else {
[415] Fix | Delete
$child->set_parent_id(0);
[416] Fix | Delete
$delete = $child->save();
[417] Fix | Delete
$delete = $delete > 0 ? true : false;
[418] Fix | Delete
}
[419] Fix | Delete
}
[420] Fix | Delete
$res['posts'][$child_id] = $delete;
[421] Fix | Delete
}
[422] Fix | Delete
}
[423] Fix | Delete
$image_galleries_id = $product->get_gallery_image_ids();
[424] Fix | Delete
[425] Fix | Delete
if (!empty($image_galleries_id)) {
[426] Fix | Delete
$res['attachment'] = array();
[427] Fix | Delete
foreach ($image_galleries_id as $image_id) {
[428] Fix | Delete
$post = get_post($image_id);
[429] Fix | Delete
$delete = true;
[430] Fix | Delete
if (!empty($post) && $post->post_type === 'attachment') {
[431] Fix | Delete
$delete = $keepModified === true ? !(strtotime($post->post_modified) > strtotime($post->post_date)) : true;
[432] Fix | Delete
if ($delete === true) {
[433] Fix | Delete
$delete = self::erase_image($image_id, $keepModified);
[434] Fix | Delete
}
[435] Fix | Delete
}
[436] Fix | Delete
$res['attachment'][$image_id] = $delete;
[437] Fix | Delete
}
[438] Fix | Delete
}
[439] Fix | Delete
$res['posts'][$id] = $product->delete(true);
[440] Fix | Delete
// Delete parent product transients.
[441] Fix | Delete
if ($parent_id = wp_get_post_parent_id($id)) {
[442] Fix | Delete
wc_delete_product_transients($parent_id);
[443] Fix | Delete
}
[444] Fix | Delete
} else {
[445] Fix | Delete
$res['posts'][$id] = wp_delete_post($id, true);
[446] Fix | Delete
}
[447] Fix | Delete
return $res;
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
public static function erase_image($post, $force = false) {
[451] Fix | Delete
$post = get_post($post);
[452] Fix | Delete
if (!empty($post) && $post->post_type === 'attachment') {
[453] Fix | Delete
$delete = $force === true || $post->post_parent === 0 || get_post_status($post->post_parent) === false;
[454] Fix | Delete
if ($delete === true) {
[455] Fix | Delete
if ($force === true) {
[456] Fix | Delete
global $wpdb;
[457] Fix | Delete
$file_name = wp_basename(wp_get_attachment_url($post->ID));
[458] Fix | Delete
$path = pathinfo($file_name);
[459] Fix | Delete
$file_name = esc_sql($path['basename']);
[460] Fix | Delete
$size_name = esc_sql($path['filename']) . '-';
[461] Fix | Delete
$sql = "'%$file_name%' OR '%$size_name%'";
[462] Fix | Delete
unset($path, $file_name, $size_name);
[463] Fix | Delete
$exist = $wpdb->query("SELECT 1 FROM $wpdb->postmeta WHERE `meta_value` LIKE $sql LIMIT 1");
[464] Fix | Delete
if (!empty($exist)) {
[465] Fix | Delete
return false;
[466] Fix | Delete
}
[467] Fix | Delete
$exist = $wpdb->query("SELECT 1 FROM $wpdb->posts WHERE `post_content` LIKE $sql LIMIT 1");
[468] Fix | Delete
if (!empty($exist)) {
[469] Fix | Delete
return false;
[470] Fix | Delete
}
[471] Fix | Delete
$exist = $wpdb->query("SELECT 1 FROM $wpdb->termmeta WHERE `meta_value` LIKE $sql LIMIT 1");
[472] Fix | Delete
if (!empty($exist)) {
[473] Fix | Delete
return false;
[474] Fix | Delete
}
[475] Fix | Delete
}
[476] Fix | Delete
return wp_delete_attachment($post->ID, true);
[477] Fix | Delete
}
[478] Fix | Delete
}
[479] Fix | Delete
return true;
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
/**
[483] Fix | Delete
* Returns true only if there are any demo contents installed on this site
[484] Fix | Delete
*
[485] Fix | Delete
* @return bool
[486] Fix | Delete
*/
[487] Fix | Delete
public static function has_demo_content() {
[488] Fix | Delete
$content = Themify_Storage::get(static::DEMO_KEY);
[489] Fix | Delete
if (!empty($content)) {
[490] Fix | Delete
return true;
[491] Fix | Delete
}
[492] Fix | Delete
$terms = get_terms([
[493] Fix | Delete
'number' => 1,
[494] Fix | Delete
'meta_key' => '_' . static::DEMO_KEY,
[495] Fix | Delete
'meta_value' => 1,
[496] Fix | Delete
'no_found_rows' => true,]
[497] Fix | Delete
);
[498] Fix | Delete
if (!empty($terms)) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function