: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( ! empty( $error ) ) {
$this->set_errors( $error );
function sanitize( $data ) {
foreach ( $data as $key => $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $k => $v ) {
$data[ $key ][ $k ] = esc_sql( $v );
$data[ $key ] = esc_sql( $value );
function check_extension( $file ) {
$extension = substr( $file, strrpos( $file, '.' ) + 1 );
if ( ! in_array( strtolower( $extension ), [ 'png', 'gif', 'jpg', 'svg' ], true ) ) {
$this->set_errors( __( 'File extension not allowed.', 'sitepress' ) );
function set_errors( $str = false ) {
$this->error .= $str . '<br />';
function get_messages() {
function set_messages( $str = false ) {
$this->message .= $str . '<br />';
function upload_flag( $id ) {
if ( isset( $_FILES['icl_edit_languages']['tmp_name'][ $id ]['flag_file'] ) ) {
$uploaded_file = filter_var(
$_FILES['icl_edit_languages']['tmp_name'][ $id ]['flag_file'],
FILTER_SANITIZE_FULL_SPECIAL_CHARS
$original_file = filter_var(
$_FILES['icl_edit_languages']['name'][ $id ]['flag_file'],
FILTER_SANITIZE_FULL_SPECIAL_CHARS
$target_path = $this->upload_dir . '/' . $original_file;
$wpml_wp_api = new WPML_WP_API();
'upload_mimes', function () {
return self::ACCEPTED_MIME_TYPES;
$mime = $wpml_wp_api->get_file_mime_type(
$_FILES['icl_edit_languages']['tmp_name'][ $id ]['flag_file'],
$_FILES['icl_edit_languages']['name'][ $id ]['flag_file']
$allowed_mime_types = array_values( self::ACCEPTED_MIME_TYPES );
$validated = in_array( $mime, $allowed_mime_types, true );
if ( $validated && move_uploaded_file( $uploaded_file, $target_path ) ) {
if ( function_exists( 'wp_get_image_editor' ) && 'image/svg+xml' !== $mime ) {
$image = wp_get_image_editor( $target_path );
if ( ! is_wp_error( $image ) ) {
$image->resize( 18, 12, true );
$image->save( $target_path );
$result = $original_file;
$error_message = __( 'There was an error uploading the file, please try again!', 'sitepress' );
if ( ! empty( $_FILES['icl_edit_languages']['error'][ $id ]['flag_file'] ) ) {
switch ( $_FILES['icl_edit_languages']['error'][ $id ]['flag_file'] ) {
case UPLOAD_ERR_INI_SIZE;
$error_message = __( 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'sitepress' );
case UPLOAD_ERR_FORM_SIZE;
$error_message = sprintf( __( 'The uploaded file exceeds %s bytes.', 'sitepress' ), $this->max_file_size );
$error_message = __( 'The uploaded file was only partially uploaded.', 'sitepress' );
$error_message = __( 'No file was uploaded.', 'sitepress' );
case UPLOAD_ERR_NO_TMP_DIR;
$error_message = __( 'Missing a temporary folder.', 'sitepress' );
case UPLOAD_ERR_CANT_WRITE;
$error_message = __( 'Failed to write file to disk.', 'sitepress' );
case UPLOAD_ERR_EXTENSION;
$error_message = __( 'A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help.', 'sitepress' );
$this->set_errors( $error_message );
global $sitepress, $sitepress_settings;
if ( ! isset( $sitepress_settings['edit_languages_flag_migration'] ) ) {
foreach ( glob( get_stylesheet_directory() . '/flags/*' ) as $filename ) {
rename( $filename, $this->upload_dir . '/' . basename( $filename ) );
$sitepress->save_settings( [ 'edit_languages_flag_migration' => 1 ] );
private function update_language_packs( SitePress $sitepress ) {
if ( $this->update_language_packs_if_needed ) {
$wpml_localization = new WPML_Download_Localization( $sitepress->get_active_languages(), $sitepress->get_default_language() );
$wpml_localization->download_language_packs();
$wpml_languages_notices = new WPML_Languages_Notices( wpml_get_admin_notices() );
$wpml_languages_notices->missing_languages( $wpml_localization->get_not_founds() );
private function get_add_language_from_post_data( $id ) {
$value = isset( $_POST['icl_edit_languages'][ $id ]['translations']['add'] ) ? stripslashes_deep( $_POST['icl_edit_languages'][ $id ]['translations']['add'] ) : '';
$value = filter_var( $value, FILTER_SANITIZE_STRING );
private function get_translations_data( $lang, $translation ) {
if ( $lang['id'] == 'add' ) {
$value = isset( $_POST['icl_edit_languages']['add']['translations'][ $translation['code'] ] ) ? $_POST['icl_edit_languages']['add']['translations'][ $translation['code'] ] : '';
$value = filter_var( $value, FILTER_SANITIZE_STRING );
$value = isset( $lang['translation'][ $translation['id'] ] ) ? $lang['translation'][ $translation['id'] ] : '';
$value = stripslashes_deep( $value );