Skip to content

Commit

Permalink
Fix deprecated preg_split with PHP8.1 (#1085)
Browse files Browse the repository at this point in the history
Passing null to parameter #3 ($limit) of type int is deprecated.
  • Loading branch information
herrvigg committed Jan 30, 2022
1 parent 9a2635f commit 6db0f3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions admin/qtx_admin_options_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ function qtranxf_update_option( $nm, $default_value = null ) {
if ( function_exists( $default_value ) ) {
$default_value = call_user_func( $default_value );
} elseif ( is_array( $q_config[ $nm ] ) ) {
$default_value = preg_split( '/[\s,]+/', $default_value, null, PREG_SPLIT_NO_EMPTY );
$default_value = preg_split( '/[\s,]+/', $default_value, -1, PREG_SPLIT_NO_EMPTY );
}
}
if ( $default_value === $q_config[ $nm ] ) {
Expand Down Expand Up @@ -597,11 +597,11 @@ function qtranxf_update_setting( $var, $type = QTX_STRING, $def = null ) {
$val = $_POST[ $var ];
if ( ! is_array( $_POST[ $var ] ) ) {
$val = sanitize_text_field( $val );
$val = preg_split( '/[\s,]+/', $val, null, PREG_SPLIT_NO_EMPTY );
$val = preg_split( '/[\s,]+/', $val, -1, PREG_SPLIT_NO_EMPTY );
}
if ( empty( $val ) && ! is_null( $def ) ) {
if ( is_string( $def ) ) {
$val = preg_split( '/[\s,]+/', $def, null, PREG_SPLIT_NO_EMPTY );
$val = preg_split( '/[\s,]+/', $def, -1, PREG_SPLIT_NO_EMPTY );
} else if ( is_array( $def ) ) {
$val = $def;
}
Expand Down Expand Up @@ -714,7 +714,7 @@ function qtranxf_update_setting_ignore_file_types( $name ) {
if ( ! isset( $_POST[ $name ] ) ) {
return false;
}
$posted = preg_split( '/[\s,]+/', strtolower( sanitize_text_field( $_POST[ $name ] ) ), null, PREG_SPLIT_NO_EMPTY );
$posted = preg_split( '/[\s,]+/', strtolower( sanitize_text_field( $_POST[ $name ] ) ), -1, PREG_SPLIT_NO_EMPTY );
$ignored = explode( ',', QTX_IGNORE_FILE_TYPES );
if ( is_array( $posted ) ) {
foreach ( $posted as $posted_value ) {
Expand Down Expand Up @@ -837,7 +837,7 @@ function qtranxf_update_settings() {
if ( isset( $_POST['json_config_files'] ) ) {
// verify that files are loadable
$json_config_files_post = sanitize_text_field( stripslashes( $_POST['json_config_files'] ) );
$json_files = preg_split( '/[\s,]+/', $json_config_files_post, null, PREG_SPLIT_NO_EMPTY );
$json_files = preg_split( '/[\s,]+/', $json_config_files_post, -1, PREG_SPLIT_NO_EMPTY );
if ( empty( $json_files ) ) {
$_POST['config_files'] = array();
unset( $_POST['json_config_files'] );
Expand Down
8 changes: 4 additions & 4 deletions qtranslate_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ function qtranxf_load_option_array( $name, $default_value = null ) {
if ( function_exists( $default_value ) ) {
$vals = call_user_func( $default_value );
} else {
$vals = preg_split( '/[\s,]+/', $default_value, null, PREG_SPLIT_NO_EMPTY );
$vals = preg_split( '/[\s,]+/', $default_value, -1, PREG_SPLIT_NO_EMPTY );
}
} else if ( is_array( $default_value ) ) {
$vals = $default_value;
Expand Down Expand Up @@ -829,7 +829,7 @@ function qtranxf_load_config() {
$ignore_file_types = get_option( 'qtranslate_ignore_file_types' );
$val = explode( ',', QTX_IGNORE_FILE_TYPES );
if ( ! empty( $ignore_file_types ) ) {
$vals = preg_split( '/[\s,]+/', strtolower( $ignore_file_types ), null, PREG_SPLIT_NO_EMPTY );
$vals = preg_split( '/[\s,]+/', strtolower( $ignore_file_types ), -1, PREG_SPLIT_NO_EMPTY );
foreach ( $vals as $v ) {
if ( empty( $v ) ) {
continue;
Expand Down Expand Up @@ -1174,7 +1174,7 @@ function qtranxf_get_language_blocks( $text ) {
$lang_code = QTX_LANG_CODE_FORMAT;
$split_regex = "#(<!--:$lang_code-->|<!--:-->|\[:$lang_code\]|\[:\]|\{:$lang_code\}|\{:\})#ism";

return preg_split( $split_regex, $text, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
return preg_split( $split_regex, $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
}

function qtranxf_split( $text ) {
Expand Down Expand Up @@ -1397,7 +1397,7 @@ function qtranxf_join_byseparator( $texts, $regex_sep ) {

$lines = array();
foreach ( $texts as $lang => $lang_text ) {
$lines[ $lang ] = preg_split( $regex_sep, $lang_text, null, PREG_SPLIT_DELIM_CAPTURE );
$lines[ $lang ] = preg_split( $regex_sep, $lang_text, -1, PREG_SPLIT_DELIM_CAPTURE );
}

$text = '';
Expand Down

0 comments on commit 6db0f3a

Please sign in to comment.