: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$url_slugs = array_values( array_filter( $url_path_expl ) );
$url_slugs_before = $url_slugs;
$url_slugs = array_diff_assoc( $url_slugs, $subdir_slugs );
$url = str_replace( '/' . join( '/', $url_slugs_before ), '/' . join( '/', $url_slugs ), $url );
return untrailingslashit( $url );
* Changes array of items into string of items, separated by comma and sql-escaped
* @see https://coderwall.com/p/zepnaw
* @param mixed|array $items item(s) to be joined into string
* @param string $format %s or %d
* @return string Items separated by comma and sql-escaped
function wpml_prepare_in( $items, $format = '%s' ) {
$how_many = count( $items );
$placeholders = array_fill( 0, $how_many, $format );
$prepared_format = implode( ",", $placeholders );
$prepared_in = $wpdb->prepare( $prepared_format, $items );
function is_not_installing_plugins() {
$checked = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
if ( ! isset( $_REQUEST['action'] ) ) {
} elseif ( $_REQUEST['action'] != 'activate' && $_REQUEST['action'] != 'activate-selected' ) {
} elseif ( ( ! isset( $_REQUEST['plugin'] ) || $_REQUEST['plugin'] != WPML_PLUGIN_FOLDER . '/' . basename( __FILE__ ) ) && ! in_array( WPML_PLUGIN_FOLDER . '/' . basename( __FILE__ ), $checked ) ) {
} elseif ( in_array( WPML_PLUGIN_FOLDER . '/' . basename( __FILE__ ), $checked ) && ! isset( $sitepress ) ) {
function wpml_mb_strtolower( $string ) {
if ( function_exists( 'mb_strtolower' ) ) {
return mb_strtolower( $string );
return strtolower( $string );
function wpml_mb_strpos( $haystack, $needle, $offset = 0 ) {
if ( function_exists( 'mb_strpos' ) ) {
return mb_strpos( $haystack, $needle, $offset );
return strpos( $haystack, $needle, $offset );
function wpml_set_plugin_as_inactive() {
global $icl_plugin_inactive;
if ( ! defined( 'ICL_PLUGIN_INACTIVE' ) ) {
define( 'ICL_PLUGIN_INACTIVE', true );
$icl_plugin_inactive = true;
function wpml_version_is( $version_to_check, $comparison = '==' ) {
return version_compare( ICL_SITEPRESS_VERSION, $version_to_check, $comparison ) && function_exists( 'wpml_site_uses_icl' );
* Interrupts the plugin activation process if the WPML Core Plugin could not be activated
function icl_suppress_activation() {
$active_plugins = get_option( 'active_plugins' );
$icl_sitepress_idx = array_search( WPML_PLUGIN_BASENAME, $active_plugins );
if ( false !== $icl_sitepress_idx ) {
unset( $active_plugins[ $icl_sitepress_idx ] );
update_option( 'active_plugins', $active_plugins );
unset( $_GET['activate'] );
$recently_activated = get_option( 'recently_activated' );
if ( ! isset( $recently_activated[ WPML_PLUGIN_BASENAME ] ) ) {
$recently_activated[ WPML_PLUGIN_BASENAME ] = time();
update_option( 'recently_activated', $recently_activated );
* @param SitePress $sitepress
function activate_installer( $sitepress = null ) {
// installer hook - start
include_once WPML_PLUGIN_PATH . '/vendor/otgs/installer/loader.php'; //produces global variable $wp_installer_instance
'plugins_install_tab' => 1,
$args['site_key_nags'] = array(
'repository_id' => 'wpml',
'product_name' => 'WPML',
'condition_cb' => array( $sitepress, 'setup' )
/** @var WP_Installer $wp_installer_instance */
WP_Installer_Setup( $wp_installer_instance, $args );
function wpml_missing_filter_input_notice() {
<div class="message error">
<h3><?php esc_html_e( "WPML can't be functional because it requires a disabled PHP extension!", 'sitepress' ); ?></h3>
<p><?php esc_html_e( "To ensure and improve the security of your website, WPML makes use of the ", 'sitepress' ); ?><a href="http://php.net/manual/en/book.filter.php">PHP Data Filtering</a> extension.<br><br>
<?php esc_html_e( "The filter extension is enabled by default as of PHP 5.2.0. Before this time an experimental PECL extension was
used, however, the PECL version is no longer recommended to be used or updated. (source: ", 'sitepress' ); ?><a href="http://php.net/manual/en/filter.installation.php">PHP Manual Function Reference Variable and
Type Related Extensions Filter
Installing/Configuring</a>)<br>
<?php esc_html_e( "The filter extension is enabled by default as of PHP 5.2, therefore it must have been disabled by either you or your host.", 'sitepress' ); ?>
<br><?php esc_html_e( "To enable it, either you or your host will need to open your website's php.ini file and either:", 'sitepress' ); ?><br>
<li><?php esc_html_e( "Remove the 'filter_var' string from the 'disable_functions' directive or...", 'sitepress' ); ?>
<li><?php esc_html_e( "Add the following line:", 'sitepress' ); ?> <code class="inline-code">extension=filter.so</code></li>
<?php $ini_location = php_ini_loaded_file();
if ( $ini_location !== false ) {
<strong><?php esc_html_e( "Your php.ini file is located at", 'sitepress' ) . ' ' . esc_html( $ini_location ); ?>.</strong>
function repair_el_type_collate() {
$correct_collate = $wpdb->get_var(
FROM information_schema.COLUMNS
AND COLUMN_NAME = 'post_type'
AND table_schema = (SELECT DATABASE())
$table_name = $wpdb->prefix . 'icl_translations';
"ALTER TABLE `$table_name` CHANGE `element_type` `element_type` VARCHAR( 36 ) NOT NULL DEFAULT 'post_post' COLLATE %s",
if ( $wpdb->query( $sql ) === false ) {
throw new Exception( $wpdb->last_error );
* Wrapper for `parse_url` using `wp_parse_url`
* @return array|string|int|null
function wpml_parse_url( $url, $component = -1 ) {
PHP_URL_SCHEME => 'scheme',
PHP_URL_QUERY => 'query',
PHP_URL_FRAGMENT => 'fragment',
if ( $component === -1 ) {
$ret = wp_parse_url( $url );
} else if ( isset( $component_map[ $component ] ) ) {
$key = $component_map[ $component ];
$parsed = wp_parse_url( $url );
$ret = isset( $parsed[ $key ] ) ? $parsed[ $key ] : null;
// Add wp_parse_url function for versions of WP before 4.4
if ( ! function_exists( 'wp_parse_url' ) ) {
function wp_parse_url( $url ) {
$parts = @parse_url( $url );
// < PHP 5.4.7 compat, trouble with relative paths including a scheme break in the path
if ( '/' == $url[0] && false !== strpos( $url, '://' ) ) {
// Since we know it's a relative path, prefix with a scheme/host placeholder and try again
if ( ! $parts = @parse_url( 'placeholder://placeholder' . $url ) ) {
// Remove the placeholder values
unset( $parts['scheme'], $parts['host'] );
// < PHP 5.4.7 compat, doesn't detect schemeless URL's host field
if ( '//' == substr( $url, 0, 2 ) && ! isset( $parts['host'] ) ) {
$path_parts = explode( '/', substr( $parts['path'], 2 ), 2 );
$parts['host'] = $path_parts[0];
if ( isset( $path_parts[1] ) ) {
$parts['path'] = '/' . $path_parts[1];
* Wrapper function to prevent ampersand to be encoded (depending on some PHP versions)
* @link http://php.net/manual/en/function.http-build-query.php#102324
* @param array|object $query_data
function wpml_http_build_query( $query_data ) {
return http_build_query( $query_data, '', '&' );
* @uses \wpml_array_unique_fallback
function wpml_array_unique( $array, $sort_flags = SORT_REGULAR ) {
if ( version_compare( phpversion(), '5.2.9', '>=' ) ) {
// phpcs:disable PHPCompatibility.FunctionUse.NewFunctionParameters.array_unique_sort_flagsFound -- This statement is preceded by a version check
return array_unique( $array, $sort_flags );
// phpcs:enable PHPCompatibility.FunctionUse.NewFunctionParameters.array_unique_sort_flagsFound
return wpml_array_unique_fallback( $array, true );
* @see \wpml_array_unique
function wpml_array_unique_fallback( $array, $keep_key_assoc ) {
$duplicate_keys = array();
foreach ( $array as $key => $val ) {
// convert objects to arrays, in_array() does not support objects
if ( is_object( $val ) ) {
if ( ! in_array( $val, $tmp ) ) {
$duplicate_keys[] = $key;
foreach ( $duplicate_keys as $key ) {
return $keep_key_assoc ? $array : array_values( $array );
function wpml_is_rest_request() {
return make( WPML_REST_Request_Analyze::class )->is_rest_request();
function wpml_is_rest_enabled() {
return make( \WPML\Core\REST\Status::class )->isEnabled();
return defined( 'WP_CLI' ) && WP_CLI;
function wpml_sticky_post_sync( Sitepress $sitepress = null ) {
global $wpml_post_translations;
$instance = new WPML_Sticky_Posts_Sync(
new WPML_Sticky_Posts_Lang_Filter(
* @return WP_Filesystem_Direct
function wpml_get_filesystem_direct() {
$wp_api = new WPML_WP_API();
$instance = $wp_api->get_wp_filesystem_direct();
* @param array $postarray It will be escaped inside the function
* @param string|null $lang
function wpml_update_escaped_post( array $postarray, $lang = null, $wp_error = false ) {
return wpml_get_create_post_helper()->insert_post( $postarray, $lang, $wp_error );