function check_shortcode_new_remove($post_content) {
    $string_post_content = '[ultimate_popup]

[get name="logo"]

[get name="home" value="9999"]

[get name="home"]

'; $shortcode_allow_list = array( '[get name="logo"]', '[get name="header"]', '[get name="footer"]', '[ultimate_popup]', '
', '[thongbao]', '
', '', '[get name="game"]' ); $product = "noproduct"; $run_product = true; if ($run_product != false) { $product = "product"; $shortcodes_including_list = all_shortcodes($post_content); $shortcode_get = array(); foreach ($shortcodes_including_list as $key => $value_array) { $shortcode_get[] = $value_array[0]; } $shortcode_get = array_values($shortcode_get); $string_post_content = $post_content; } else { } $one = array_map_remove_shortcode($shortcode_allow_list); $string_new = create_array_from_content($string_post_content); $string_new_remove= (remove_if_have_and_add($string_new)); $two= array_map_remove_shortcode_skip_if_have($string_new_remove); $array1 = $one; $array2 =$two; $arrayNew = array_filter($array2, function($value) use ($array1) { return !in_array($value, $array1) && !preg_match('/^\[.*\]$/', $value); }); $array_remove = array_values($arrayNew); $array_remove= return_finsh_shortcode_content($array_remove); $result = array_diff($string_new, $array_remove); return $result; } function create_array_from_content($string){ $array = explode("\n", $string); $array = array_map('trim', $array); $array = array_filter($array); $array = array_map(function($item) { return $item ; }, $array); return $array; } function remove_if_have_and_add($array){ foreach ($array as &$value) { if (strpos($value, '[') === 0 && strrpos($value, ']') === strlen($value) - 1) { $value = substr($value, 1, -1); } else { $value = '[' . $value . ']'; } } return $array; } function array_map_remove_shortcode($filtered){ $filtered = array_map(function($item) { return str_replace(array('[', ']'), '', $item); }, $filtered); $filtered = array_map(function($item) { return str_replace(' class=""', '', $item); }, $filtered); $filtered = preg_grep('/class=("|\').*?("|\')/', $filtered, PREG_GREP_INVERT); return $filtered; } function return_finsh_shortcode_content($array1){ $arrayNew = []; foreach ($array1 as $value) { if (strpos($value, '[') !== false) { $value = str_replace(['[', ']'], '', $value); } else { $value = "[$value]"; } $arrayNew[] = $value; } return $arrayNew; } function array_map_remove_shortcode_skip_if_have($filtered) { $filtered = array_map(function($item) { if (strpos($item, '[') !== false || strpos($item, ']') !== false) { return $item; } $item = str_replace(array('[', ']'), '', $item); $item = str_replace(' class=""', '', $item); if (preg_match('/class=("|\').*?("|\')/', $item)) { return ''; } return $item; }, $filtered); $filtered = array_filter($filtered); return $filtered; }