backward.php
2 months ago
functions.php
2 months ago
get_file_curl.php
2 months ago
get_taxonomies_by_object_type.php
2 months ago
is_exists_term.php
2 months ago
pmxi_findDuplicates.php
2 months ago
pmxi_recursion_taxes.php
1 month ago
reverse_taxonomies_html.php
2 months ago
str_getcsv.php
2 months ago
wp_all_import_addon_notifications.php
2 months ago
wp_all_import_base64_decode_image.php
2 months ago
wp_all_import_clear_directory.php
2 months ago
wp_all_import_ctx_mapping.php
2 months ago
wp_all_import_custom_type.php
2 months ago
wp_all_import_filter_html_kses.php
2 months ago
wp_all_import_get_feed_type.php
2 months ago
wp_all_import_get_gz.php
2 months ago
wp_all_import_get_image_from_gallery.php
2 months ago
wp_all_import_get_import_id.php
2 months ago
wp_all_import_get_import_post_type.php
2 months ago
wp_all_import_get_page_by_title.php
2 months ago
wp_all_import_get_parent_post.php
2 months ago
wp_all_import_get_parent_terms.php
2 months ago
wp_all_import_get_reader_engine.php
2 months ago
wp_all_import_get_url.php
2 months ago
wp_all_import_is_base64_encoded.php
2 months ago
wp_all_import_is_json.php
2 months ago
wp_all_import_is_title_required.php
2 months ago
wp_all_import_is_update_cf.php
2 months ago
wp_all_import_json_to_xml.php
2 months ago
wp_all_import_rand_char.php
2 months ago
wp_all_import_remove_source.php
2 months ago
wp_all_import_rmdir.php
2 months ago
wp_all_import_sanitize_filename.php
2 months ago
wp_all_import_sanitize_svg.php
2 months ago
wp_all_import_sanitize_url.php
2 months ago
wp_all_import_secure_file.php
2 months ago
wp_all_import_strip_tags_content.php
2 months ago
wp_all_import_template_notifications.php
2 months ago
wp_all_import_url_title.php
2 months ago
wp_all_import_xml2array.php
2 months ago
wp_delete_attachments.php
2 months ago
wp_redirect_or_javascript.php
2 months ago
wpai_util_map.php
2 months ago
functions.php
596 lines
| 1 | <?php |
| 2 | // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals |
| 3 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 | if( !function_exists('wpai_wp_enqueue_code_editor')){ |
| 5 | function wpai_wp_enqueue_code_editor( $args ) { |
| 6 | |
| 7 | // We need syntax highlighting to work in the plugin regardless of user setting. |
| 8 | // Function matches https://developer.wordpress.org/reference/functions/wp_enqueue_code_editor/ otherwise. |
| 9 | /*if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) { |
| 10 | return false; |
| 11 | }*/ |
| 12 | |
| 13 | $settings = wp_get_code_editor_settings( $args ); |
| 14 | |
| 15 | if ( empty( $settings ) || empty( $settings['codemirror'] ) ) { |
| 16 | return false; |
| 17 | } |
| 18 | |
| 19 | wp_enqueue_script( 'code-editor' ); |
| 20 | wp_enqueue_style( 'code-editor' ); |
| 21 | |
| 22 | if ( isset( $settings['codemirror']['mode'] ) ) { |
| 23 | $mode = $settings['codemirror']['mode']; |
| 24 | if ( is_string( $mode ) ) { |
| 25 | $mode = array( |
| 26 | 'name' => $mode, |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | if ( ! empty( $settings['codemirror']['lint'] ) ) { |
| 31 | switch ( $mode['name'] ) { |
| 32 | case 'css': |
| 33 | case 'text/css': |
| 34 | case 'text/x-scss': |
| 35 | case 'text/x-less': |
| 36 | wp_enqueue_script( 'csslint' ); |
| 37 | break; |
| 38 | case 'htmlmixed': |
| 39 | case 'text/html': |
| 40 | case 'php': |
| 41 | case 'application/x-httpd-php': |
| 42 | case 'text/x-php': |
| 43 | wp_enqueue_script( 'htmlhint' ); |
| 44 | wp_enqueue_script( 'csslint' ); |
| 45 | wp_enqueue_script( 'jshint' ); |
| 46 | if ( ! current_user_can( 'unfiltered_html' ) ) { |
| 47 | wp_enqueue_script( 'htmlhint-kses' ); |
| 48 | } |
| 49 | break; |
| 50 | case 'javascript': |
| 51 | case 'application/ecmascript': |
| 52 | case 'application/json': |
| 53 | case 'application/javascript': |
| 54 | case 'application/ld+json': |
| 55 | case 'text/typescript': |
| 56 | case 'application/typescript': |
| 57 | wp_enqueue_script( 'jshint' ); |
| 58 | wp_enqueue_script( 'jsonlint' ); |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) ); |
| 65 | |
| 66 | /** |
| 67 | * Fires when scripts and styles are enqueued for the code editor. |
| 68 | * |
| 69 | * @since 4.9.0 |
| 70 | * |
| 71 | * @param array $settings Settings for the enqueued code editor. |
| 72 | */ |
| 73 | do_action( 'wp_enqueue_code_editor', $settings ); |
| 74 | |
| 75 | return $settings; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if ( ! function_exists('pmxi_if') ) { |
| 80 | function pmxi_if( $left_condition, $operand, $right_condition, $then, $else = '' ) { |
| 81 | $str = trim(implode(' ', array($left_condition, html_entity_decode($operand), $right_condition))); |
| 82 | // phpcs:ignore Generic.PHP.ForbiddenFunctions.Found |
| 83 | return (eval ("return ($str);")) ? $then : $else; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if ( ! function_exists('is_empty') ) { |
| 88 | function is_empty( $var ) { |
| 89 | return empty($var); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if ( ! function_exists('pmxi_human_filesize') ) { |
| 94 | function pmxi_human_filesize($bytes, $decimals = 2) { |
| 95 | $sz = 'BKMGTP'; |
| 96 | $factor = (int) floor((strlen($bytes) - 1) / 3); |
| 97 | return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . (isset($sz[$factor]) ? $sz[$factor] : ''); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if ( ! function_exists('pmxi_get_remote_image_ext') ) { |
| 102 | function pmxi_get_remote_image_ext( $filePath ) { |
| 103 | $response = wp_remote_get($filePath); |
| 104 | $headers = wp_remote_retrieve_headers( $response ); |
| 105 | $content_type = (!empty($headers['content-type'])) ? explode('/', $headers['content-type']) : false; |
| 106 | if (!empty($content_type[1])){ |
| 107 | if (preg_match('%jpeg%i', $content_type[1])) return 'jpeg'; |
| 108 | if (preg_match('%jpg%i', $content_type[1])) return 'jpg'; |
| 109 | if (preg_match('%png%i', $content_type[1])) return 'png'; |
| 110 | if (preg_match('%gif%i', $content_type[1])) return 'gif'; |
| 111 | if (preg_match('%svg%i', $content_type[1])) return 'svg'; |
| 112 | if (preg_match('%webp%i', $content_type[1])) return 'webp'; |
| 113 | if (preg_match('%pdf%i', $content_type[1])) return 'pdf'; |
| 114 | return ($content_type[1] == "unknown") ? "" : $content_type[1]; |
| 115 | } |
| 116 | return ''; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if ( ! function_exists('pmxi_getExtension') ) { |
| 121 | function pmxi_getExtension( $str ){ |
| 122 | $i = strrpos($str,"."); |
| 123 | if (!$i) return ""; |
| 124 | $l = strlen($str) - $i; |
| 125 | $ext = substr($str,$i+1,$l); |
| 126 | return (strlen($ext) <= 4) ? $ext : ""; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if ( ! function_exists('pmxi_getExtensionFromStr' ) ) { |
| 131 | function pmxi_getExtensionFromStr( $str ) { |
| 132 | $filetype = wp_check_filetype($str); |
| 133 | if (empty($filetype['ext'])){ |
| 134 | $filetype = wp_check_filetype(strtok($str, "?")); |
| 135 | } |
| 136 | return ($filetype['ext'] == "unknown") ? "" : $filetype['ext']; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if ( ! function_exists('pmxi_convert_encoding')) { |
| 141 | function pmxi_convert_encoding ( $source, $target_encoding = 'ASCII' ) { |
| 142 | if ( function_exists('mb_detect_encoding') ) { |
| 143 | // detect the character encoding of the incoming file |
| 144 | $encoding = mb_detect_encoding( $source, "auto" ); |
| 145 | // escape all of the question marks so we can remove artifacts from |
| 146 | // the unicode conversion process |
| 147 | $target = str_replace( "?", "[question_mark]", $source ); |
| 148 | // convert the string to the target encoding |
| 149 | $target = mb_convert_encoding( $target, $target_encoding, $encoding); |
| 150 | // remove any question marks that have been introduced because of illegal characters |
| 151 | $target = str_replace( "?", "", $target ); |
| 152 | // replace the token string "[question_mark]" with the symbol "?" |
| 153 | $target = str_replace( "[question_mark]", "?", $target ); |
| 154 | return html_entity_decode($target, ENT_COMPAT, 'UTF-8'); |
| 155 | } |
| 156 | return $source; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | if ( ! function_exists('wp_all_import_get_remote_file_name') ) { |
| 161 | function wp_all_import_get_remote_file_name( $filePath ) { |
| 162 | $bn = wp_all_import_basename($filePath); |
| 163 | $type = (preg_match('%\W(csv|txt|dat|psv)$%i', $bn)) ? 'csv' : false; |
| 164 | if (!$type) $type = (preg_match('%\W(xml)$%i', $bn)) ? 'xml' : false; |
| 165 | if (!$type) $type = (preg_match('%\W(zip)$%i', $bn)) || (preg_match('%\W(get_bundle)$%i', $bn) && strpos($bn, 'export_id') !== false && strpos($bn, 'security_token') !== false) ? 'zip' : false; |
| 166 | if (!$type) $type = (preg_match('%\W(gz)$%i', $bn)) ? 'gz' : false; |
| 167 | |
| 168 | if(!$type){ |
| 169 | $filePath = strtok($filePath, "?"); |
| 170 | $bn = wp_all_import_basename($filePath); |
| 171 | $type = (preg_match('%\W(csv|txt|dat|psv)$%i', $bn)) ? 'csv' : false; |
| 172 | if (!$type) $type = (preg_match('%\W(xml)$%i', $bn)) ? 'xml' : false; |
| 173 | if (!$type) $type = (preg_match('%\W(zip)$%i', $bn)) ? 'zip' : false; |
| 174 | if (!$type) $type = (preg_match('%\W(gz)$%i', $bn)) ? 'gz' : false; |
| 175 | } |
| 176 | return ($type) ? $type : false; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | if ( ! function_exists('wp_all_import_translate_uri') ) { |
| 181 | function wp_all_import_translate_uri($uri) { |
| 182 | $parts = explode('/', $uri); |
| 183 | for ($i = 1; $i < count($parts); $i++) { |
| 184 | $parts[$i] = rawurlencode($parts[$i]); |
| 185 | } |
| 186 | return implode('/', $parts); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | if ( ! function_exists('wp_all_import_cdata_filter') ) { |
| 191 | function wp_all_import_cdata_filter($matches) { |
| 192 | PMXI_Import_Record::$cdata[] = $matches[0]; |
| 193 | return '{{CPLACE_'. count(PMXI_Import_Record::$cdata) .'}}'; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if ( ! function_exists('wp_all_import_amp_filter') ) { |
| 198 | function wp_all_import_amp_filter($matches) { |
| 199 | if (empty($matches[1]) && !empty($matches[0])) { |
| 200 | return "&"; |
| 201 | } |
| 202 | return in_array($matches[1], array("amp;", "lt;", "gt;")) ? "&" . $matches[1] : "&" . $matches[1]; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | if ( ! function_exists('wp_all_import_isValidMd5') ) { |
| 207 | function wp_all_import_isValidMd5($md5 ='') { |
| 208 | return preg_match('/^[a-f0-9]{32}$/', $md5); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | if ( ! function_exists('wp_all_import_get_relative_path') ) { |
| 213 | function wp_all_import_get_relative_path($path){ |
| 214 | $uploads = wp_upload_dir(); |
| 215 | return str_replace($uploads['basedir'], '', $path); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | if ( ! function_exists('wp_all_import_get_absolute_path') ) { |
| 220 | function wp_all_import_get_absolute_path($path) { |
| 221 | $uploads = wp_upload_dir(); |
| 222 | return ( strpos($path, $uploads['basedir']) === false and ! preg_match('%^https?://%i', $path)) ? $uploads['basedir'] . $path : $path; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | if ( ! function_exists('wp_all_import_clear_xss') ) { |
| 227 | function wp_all_import_clear_xss( $str ) { |
| 228 | return stripslashes(esc_sql(htmlspecialchars(wp_strip_all_tags($str)))); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | if ( ! function_exists('wp_all_import_get_taxonomies') ) { |
| 233 | function wp_all_import_get_taxonomies() { |
| 234 | // get all taxonomies |
| 235 | $taxonomies = get_taxonomies(FALSE, 'objects'); |
| 236 | $ignore = array('nav_menu', 'link_category'); |
| 237 | $r = array(); |
| 238 | // populate $r |
| 239 | foreach ($taxonomies as $taxonomy) { |
| 240 | if (in_array($taxonomy->name, $ignore)) { |
| 241 | continue; |
| 242 | } |
| 243 | if ( ! empty($taxonomy->labels->name) && strpos($taxonomy->labels->name, "_") === false){ |
| 244 | $r[$taxonomy->name] = $taxonomy->labels->name; |
| 245 | } |
| 246 | else{ |
| 247 | $r[$taxonomy->name] = empty($taxonomy->labels->singular_name) ? $taxonomy->name : $taxonomy->labels->singular_name; |
| 248 | } |
| 249 | } |
| 250 | asort($r, SORT_FLAG_CASE | SORT_STRING); |
| 251 | // return |
| 252 | return $r; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | if ( ! function_exists('wp_all_import_is_password_protected_feed') ) { |
| 257 | function wp_all_import_is_password_protected_feed($url){ |
| 258 | $url_data = wp_parse_url($url); |
| 259 | return (!empty($url_data['user']) and !empty($url_data['pass'])) ? true : false; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | if ( ! function_exists('wp_all_import_cmp_custom_types') ) { |
| 264 | function wp_all_import_cmp_custom_types($a, $b) { |
| 265 | return strcmp($a->labels->name, $b->labels->name); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | if ( ! function_exists('wp_all_import_basename') ) { |
| 270 | function wp_all_import_basename($file) { |
| 271 | $a = explode('/', $file); |
| 272 | return end($a); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if ( ! function_exists('wp_all_import_update_post_count') ) { |
| 277 | function wp_all_import_update_post_count() { |
| 278 | global $wpdb; |
| 279 | update_option( 'post_count', (int) $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type = 'post'" ), false ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | if ( ! function_exists('wp_all_import_supported_image_types') ) { |
| 284 | function wp_all_import_supported_image_types() { |
| 285 | $supported_image_types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP); |
| 286 | if (defined('IMAGETYPE_WEBP')) { |
| 287 | $supported_image_types[] = IMAGETYPE_WEBP; |
| 288 | } |
| 289 | return $supported_image_types; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | if ( ! function_exists('wp_all_import_generate_functions_hash') ) { |
| 294 | function wp_all_import_generate_functions_hash() { |
| 295 | $uploads = wp_upload_dir(); |
| 296 | $functions_hash = false; |
| 297 | $functions_file = $uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php'; |
| 298 | if (@file_exists($functions_file)) { |
| 299 | $functions_hash = hash_file('md5', $functions_file); |
| 300 | // Check functions file from current theme. |
| 301 | $theme_functions_file = get_template_directory() . '/functions.php'; |
| 302 | if (@file_exists($theme_functions_file)) { |
| 303 | $functions_hash .= hash_file('md5', $theme_functions_file); |
| 304 | } |
| 305 | } |
| 306 | return $functions_hash; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | if (!function_exists('wp_all_import_is_update_custom_field')) { |
| 311 | function wp_all_import_is_update_custom_field($meta_key, $options) { |
| 312 | if ($options['update_all_data'] == 'yes') { |
| 313 | return TRUE; |
| 314 | } |
| 315 | if (!$options['is_update_custom_fields']) { |
| 316 | return FALSE; |
| 317 | } |
| 318 | if ($options['update_custom_fields_logic'] == "full_update") { |
| 319 | return TRUE; |
| 320 | } |
| 321 | if ($options['update_custom_fields_logic'] == "only" |
| 322 | && !empty($options['custom_fields_list']) |
| 323 | && is_array($options['custom_fields_list']) |
| 324 | && in_array($meta_key, $options['custom_fields_list']) |
| 325 | ) { |
| 326 | return TRUE; |
| 327 | } |
| 328 | if ($options['update_custom_fields_logic'] == "all_except" |
| 329 | && (empty($options['custom_fields_list']) || !in_array($meta_key, $options['custom_fields_list'])) |
| 330 | ) { |
| 331 | return TRUE; |
| 332 | } |
| 333 | |
| 334 | return FALSE; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | if (!function_exists('wp_all_import_delete_missing_notice')) { |
| 339 | function wp_all_import_delete_missing_notice( $options ) { |
| 340 | |
| 341 | $options += PMXI_Plugin::get_default_import_options(); |
| 342 | |
| 343 | $notice = false; |
| 344 | if (!empty($options['is_delete_missing'])) { |
| 345 | |
| 346 | switch ($options['custom_type']){ |
| 347 | case 'taxonomies': |
| 348 | $custom_type = get_taxonomy($options['taxonomy_type']); |
| 349 | if (empty($custom_type)){ |
| 350 | $custom_type = new stdClass(); |
| 351 | $custom_type->labels = new stdClass(); |
| 352 | $custom_type->labels->name = __('Taxonomy Terms', 'wp-all-import'); |
| 353 | $custom_type->labels->singular_name = __('Taxonomy Term', 'wp-all-import'); |
| 354 | } |
| 355 | break; |
| 356 | case 'comments': |
| 357 | $custom_type = new stdClass(); |
| 358 | $custom_type->labels = new stdClass(); |
| 359 | $custom_type->labels->name = __('Comments', 'wp-all-import'); |
| 360 | $custom_type->labels->singular_name = __('Comment', 'wp-all-import'); |
| 361 | break; |
| 362 | case 'woo_reviews': |
| 363 | $custom_type = new stdClass(); |
| 364 | $custom_type->labels = new stdClass(); |
| 365 | $custom_type->labels->name = __('Reviews', 'wp-all-import'); |
| 366 | $custom_type->labels->singular_name = __('Review', 'wp-all-import'); |
| 367 | break; |
| 368 | default: |
| 369 | $custom_type = get_post_type_object( $options['custom_type'] ); |
| 370 | break; |
| 371 | } |
| 372 | |
| 373 | if ($options['delete_missing_logic'] == 'all' && $options['delete_missing_action'] == 'keep' && !empty($options['is_change_post_status_of_removed'])) { |
| 374 | if( !empty($options['is_send_removed_to_trash']) ) { |
| 375 | /* translators: see placeholders in the string below */ |
| 376 | $notice = sprintf( __( '<span class="important-warning">Warning</span>: Any %s not in your import file will be sent to the trash, even those not created by this import.', 'wp-all-import' ), $custom_type->labels->name); |
| 377 | }else{ |
| 378 | /* translators: see placeholders in the string below */ |
| 379 | $notice = sprintf( __( '<span class="important-warning">Warning</span>: Any %1$s not in your import file will be marked as %2$s, even those not created by this import.', 'wp-all-import' ), $custom_type->labels->name, $options['status_of_removed'] ); |
| 380 | } |
| 381 | } |
| 382 | if ($options['delete_missing_logic'] == 'import' && $options['delete_missing_action'] == 'keep' && !empty($options['is_send_removed_to_trash'])) { |
| 383 | /* translators: see placeholders in the string below */ |
| 384 | $notice = sprintf(__('<span class="important-warning">Warning</span>: %s created by this import and no longer present in the import file will be sent to the trash.', 'wp-all-import'), $custom_type->labels->name); |
| 385 | } |
| 386 | if ($options['delete_missing_logic'] == 'import' && $options['delete_missing_action'] == 'keep' && !empty($options['is_change_post_status_of_removed'])) { |
| 387 | if( !empty($options['is_send_removed_to_trash']) ) { |
| 388 | /* translators: see placeholders in the string below */ |
| 389 | $notice = sprintf( __( '<span class="important-warning">Warning</span>: %s created by this import and no longer present in the import file will be sent to the trash.', 'wp-all-import' ), $custom_type->labels->name); |
| 390 | }else{ |
| 391 | /* translators: see placeholders in the string below */ |
| 392 | $notice = sprintf( __( '<span class="important-warning">Warning</span>: %1$s created by this import and no longer present in the import file will be marked as %2$s.', 'wp-all-import' ), $custom_type->labels->name, $options['status_of_removed'] ); |
| 393 | } |
| 394 | } |
| 395 | if ($options['delete_missing_logic'] == 'import' && $options['delete_missing_action'] == 'remove') { |
| 396 | /* translators: see placeholders in the string below */ |
| 397 | $notice = sprintf(__('<span class="important-warning">Warning</span>: %s created by this import and no longer present in the import file will be <b>permanently deleted</b>.', 'wp-all-import'), $custom_type->labels->name); |
| 398 | } |
| 399 | if ($options['delete_missing_logic'] == 'all' && $options['delete_missing_action'] == 'keep' && !empty($options['is_send_removed_to_trash'])) { |
| 400 | /* translators: see placeholders in the string below */ |
| 401 | $notice = sprintf(__('<span class="important-warning">Warning</span>: Any %1$s not in your import file will be sent to the trash when this import runs. This includes %2$s that weren\'t created by this import.', 'wp-all-import'), $custom_type->labels->name, $custom_type->labels->name); |
| 402 | } |
| 403 | if ($options['delete_missing_logic'] == 'all' && $options['delete_missing_action'] == 'remove') { |
| 404 | /* translators: see placeholders in the string below */ |
| 405 | $notice = sprintf(__('<span class="important-warning">Warning</span>: Any %s not in your import file will be <b>permanently deleted</b>, even those not created by this import.', 'wp-all-import'), $custom_type->labels->name); |
| 406 | } |
| 407 | } |
| 408 | return $notice; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | if (!function_exists('wp_all_import_custom_type_labels')) { |
| 413 | function wp_all_import_custom_type_labels($post_type, $taxonomy_type = false) { |
| 414 | switch ($post_type){ |
| 415 | case 'taxonomies': |
| 416 | if (!empty($taxonomy_type)) { |
| 417 | $tx = get_taxonomy($taxonomy_type); |
| 418 | } |
| 419 | $custom_type = new stdClass(); |
| 420 | $custom_type->name = $post_type; |
| 421 | $custom_type->label = empty($tx->labels->name) ? __('Taxonomy Terms', 'wp-all-import') : $tx->labels->name; |
| 422 | $custom_type->labels = new stdClass(); |
| 423 | $custom_type->labels->name = empty($tx->labels->name) ? __('Taxonomy Terms', 'wp-all-import') : $tx->labels->name; |
| 424 | $custom_type->labels->singular_name = empty($tx->labels->singular_name) ? __('Taxonomy Term', 'wp-all-import') : $tx->labels->singular_name; |
| 425 | break; |
| 426 | case 'comments': |
| 427 | $custom_type = new stdClass(); |
| 428 | $custom_type->name = $post_type; |
| 429 | $custom_type->label = __('Comments', 'wp-all-import'); |
| 430 | $custom_type->labels = new stdClass(); |
| 431 | $custom_type->labels->name = __('Comments', 'wp-all-import'); |
| 432 | $custom_type->labels->singular_name = __('Comment', 'wp-all-import'); |
| 433 | break; |
| 434 | case 'woo_reviews': |
| 435 | $custom_type = new stdClass(); |
| 436 | $custom_type->name = $post_type; |
| 437 | $custom_type->label = __('WooCommerce Reviews', 'wp-all-import'); |
| 438 | $custom_type->labels = new stdClass(); |
| 439 | $custom_type->labels->name = __('WooCommerce Reviews', 'wp-all-import'); |
| 440 | $custom_type->labels->singular_name = __('Review', 'wp-all-import'); |
| 441 | break; |
| 442 | case 'import_users': |
| 443 | $custom_type = new stdClass(); |
| 444 | $custom_type->name = $post_type; |
| 445 | $custom_type->label = __('Users', 'wp-all-import'); |
| 446 | $custom_type->labels = new stdClass(); |
| 447 | $custom_type->labels->name = __('Users', 'wp-all-import'); |
| 448 | $custom_type->labels->singular_name = __('User', 'wp-all-import'); |
| 449 | break; |
| 450 | case 'gf_entries': |
| 451 | $custom_type = new stdClass(); |
| 452 | $custom_type->name = $post_type; |
| 453 | $custom_type->label = __('Gravity Forms Entry', 'wp-all-import'); |
| 454 | $custom_type->labels = new stdClass(); |
| 455 | $custom_type->labels->name = __('Gravity Forms Entry', 'wp-all-import'); |
| 456 | $custom_type->labels->singular_name = __('Gravity Forms Entry', 'wp-all-import'); |
| 457 | break; |
| 458 | case 'shop_customer': |
| 459 | $custom_type = new stdClass(); |
| 460 | $custom_type->name = $post_type; |
| 461 | $custom_type->label = __('WooCommerce Customers', 'wp-all-import'); |
| 462 | $custom_type->labels = new stdClass(); |
| 463 | $custom_type->labels->name = __('WooCommerce Customers', 'wp-all-import'); |
| 464 | $custom_type->labels->singular_name = __('WooCommerce Customer', 'wp-all-import'); |
| 465 | break; |
| 466 | default: |
| 467 | $custom_type = get_post_type_object( $post_type ); |
| 468 | break; |
| 469 | } |
| 470 | return $custom_type; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | if (!function_exists('wp_all_import_get_product_id_by_sku')) { |
| 475 | function wp_all_import_get_product_id_by_sku( $sku ) { |
| 476 | global $wpdb; |
| 477 | |
| 478 | // phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery |
| 479 | // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 480 | $id = $wpdb->get_var( |
| 481 | $wpdb->prepare( |
| 482 | " |
| 483 | SELECT posts.ID |
| 484 | FROM {$wpdb->posts} as posts |
| 485 | INNER JOIN {$wpdb->wc_product_meta_lookup} AS lookup ON posts.ID = lookup.product_id |
| 486 | WHERE |
| 487 | posts.post_type IN ( 'product', 'product_variation' ) |
| 488 | AND lookup.sku = %s |
| 489 | LIMIT 1 |
| 490 | ", |
| 491 | $sku |
| 492 | ) |
| 493 | ); |
| 494 | |
| 495 | return (int) apply_filters( 'wp_all_import_get_product_id_by_sku', $id, $sku ); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | if (!function_exists('wp_all_import_supported_image_extensions')) { |
| 500 | function wp_all_import_supported_image_extensions() { |
| 501 | $types = ['svg']; // |
| 502 | $mime_types = get_allowed_mime_types(); |
| 503 | if ( ! empty($mime_types) ) { |
| 504 | foreach ($mime_types as $ext => $mime_type) { |
| 505 | if (strpos($mime_type, 'image/') !== FALSE) { |
| 506 | $types[] = $ext; |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | return implode("|", apply_filters('pmxi_supported_image_extensions', $types)); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | if (!function_exists('pmxi_truncate_term_slug')) { |
| 515 | function pmxi_truncate_term_slug($string, $limit = 200) { |
| 516 | // Function to check if the string is URL-encoded. |
| 517 | $is_url_encoded = (urldecode($string) !== $string); |
| 518 | |
| 519 | // Function to truncate URL-encoded strings. |
| 520 | if ($is_url_encoded) { |
| 521 | $decoded = rawurldecode($string); |
| 522 | $encoded_string = ''; |
| 523 | $encoded_length = 0; |
| 524 | |
| 525 | for ($i = 0; $i < mb_strlen($decoded); $i++) { |
| 526 | $char = mb_substr($decoded, $i, 1); |
| 527 | $encoded_char = rawurlencode($char); |
| 528 | $char_length = strlen($encoded_char); |
| 529 | |
| 530 | if ($encoded_length + $char_length > $limit) { |
| 531 | break; |
| 532 | } |
| 533 | |
| 534 | $encoded_string .= $encoded_char; |
| 535 | $encoded_length += $char_length; |
| 536 | } |
| 537 | |
| 538 | return $encoded_string; |
| 539 | } else { |
| 540 | // Function to truncate regular strings. |
| 541 | if (mb_strlen($string) > $limit) { |
| 542 | return mb_substr($string, 0, $limit); |
| 543 | } |
| 544 | return $string; |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if(!function_exists('pmxi_maybe_unserialize')) |
| 550 | { |
| 551 | function pmxi_maybe_unserialize($value) |
| 552 | { |
| 553 | if(is_serialized($value)){ |
| 554 | $value = @unserialize(trim($value), ['allowed_classes' => false]); |
| 555 | } |
| 556 | |
| 557 | return $value; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | if (!function_exists('wp_all_import_get_allowed_zip_extensions')) { |
| 562 | /** |
| 563 | * Get allowed file extensions for zip extraction (whitelist approach) |
| 564 | * @return array |
| 565 | */ |
| 566 | function wp_all_import_get_allowed_zip_extensions() { |
| 567 | // Data file extensions |
| 568 | $data_extensions = array( |
| 569 | 'xml', 'csv', 'txt', 'json', 'sql', 'dat', 'psv', 'tsv', 'xls', 'xlsx' |
| 570 | ); |
| 571 | |
| 572 | // Get image extensions from WordPress and plugin |
| 573 | $image_extensions = array(); |
| 574 | if (function_exists('wp_all_import_supported_image_extensions')) { |
| 575 | $supported_image_extensions = wp_all_import_supported_image_extensions(); |
| 576 | if ($supported_image_extensions) { |
| 577 | $image_extensions = explode('|', $supported_image_extensions); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | // Additional common image extensions not covered by the function |
| 582 | $additional_image_extensions = array( |
| 583 | 'jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'avif', 'ico', 'tiff', 'tif' |
| 584 | ); |
| 585 | |
| 586 | // Merge all allowed extensions |
| 587 | $allowed_extensions = array_merge($data_extensions, $image_extensions, $additional_image_extensions); |
| 588 | |
| 589 | // Remove duplicates and empty values |
| 590 | $allowed_extensions = array_filter(array_unique($allowed_extensions)); |
| 591 | |
| 592 | // Apply filter to allow customization |
| 593 | return apply_filters('wp_all_import_allowed_zip_extensions', $allowed_extensions); |
| 594 | } |
| 595 | } |
| 596 |