Skip to content

Commit

Permalink
Merge pull request #1437 from rocklobster-in/dev/5.9
Browse files Browse the repository at this point in the history
Rename $args
  • Loading branch information
takayukister authored Jun 16, 2024
2 parents 36c3bae + 25a1e1a commit 582cc06
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 90 deletions.
6 changes: 3 additions & 3 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function wpcf7_admin_enqueue_scripts( $hook_suffix ) {
array( 'in_footer' => true )
);

$args = array(
$l10n = array(
'apiSettings' => array(
'root' => sanitize_url( rest_url( 'contact-form-7/v1' ) ),
'namespace' => 'contact-form-7/v1',
Expand Down Expand Up @@ -164,11 +164,11 @@ function wpcf7_admin_enqueue_scripts( $hook_suffix ) {
and wpcf7_validate_configuration() ) {
$config_validator = new WPCF7_ConfigValidator( $post );
$config_validator->restore();
$args['configValidator']['errors'] =
$l10n['configValidator']['errors'] =
$config_validator->collect_error_messages();
}

wp_localize_script( 'wpcf7-admin', 'wpcf7', $args );
wp_localize_script( 'wpcf7-admin', 'wpcf7', $l10n );

add_thickbox();

Expand Down
28 changes: 14 additions & 14 deletions admin/includes/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ function wpcf7_editor_panel_mail( $post ) {
) );
}

function wpcf7_editor_box_mail( $post, $args = '' ) {
$args = wp_parse_args( $args, array(
function wpcf7_editor_box_mail( $post, $options = '' ) {
$options = wp_parse_args( $options, array(
'id' => 'wpcf7-mail',
'name' => 'mail',
'title' => __( 'Mail', 'contact-form-7' ),
'use' => null,
) );

$id = esc_attr( $args['id'] );
$id = esc_attr( $options['id'] );

$mail = wp_parse_args( $post->prop( $args['name'] ), array(
$mail = wp_parse_args( $post->prop( $options['name'] ), array(
'active' => false,
'recipient' => '',
'sender' => '',
Expand All @@ -115,12 +115,12 @@ function wpcf7_editor_box_mail( $post, $args = '' ) {

?>
<div class="contact-form-editor-box-mail" id="<?php echo $id; ?>">
<h2><?php echo esc_html( $args['title'] ); ?></h2>
<h2><?php echo esc_html( $options['title'] ); ?></h2>

<?php
if ( ! empty( $args['use'] ) ) :
if ( ! empty( $options['use'] ) ) :
?>
<label for="<?php echo $id; ?>-active"><input type="checkbox" id="<?php echo $id; ?>-active" name="<?php echo $id; ?>[active]" data-config-field="" class="toggle-form-table" value="1"<?php echo ( $mail['active'] ) ? ' checked="checked"' : ''; ?> /> <?php echo esc_html( $args['use'] ); ?></label>
<label for="<?php echo $id; ?>-active"><input type="checkbox" id="<?php echo $id; ?>-active" name="<?php echo $id; ?>[active]" data-config-field="" class="toggle-form-table" value="1"<?php echo ( $mail['active'] ) ? ' checked="checked"' : ''; ?> /> <?php echo esc_html( $options['use'] ); ?></label>
<p class="description"><?php echo esc_html( __( "Mail (2) is an additional mail template often used as an autoresponder.", 'contact-form-7' ) ); ?></p>
<?php
endif;
Expand All @@ -140,7 +140,7 @@ function wpcf7_editor_box_mail( $post, $args = '' ) {
echo esc_html( __( "In the following fields, you can use these mail-tags:",
'contact-form-7' ) );
echo '<br />';
$post->suggest_mail_tags( $args['name'] );
$post->suggest_mail_tags( $options['name'] );
?>
</legend>
<table class="form-table">
Expand All @@ -150,7 +150,7 @@ function wpcf7_editor_box_mail( $post, $args = '' ) {
<label for="<?php echo $id; ?>-recipient"><?php echo esc_html( __( 'To', 'contact-form-7' ) ); ?></label>
</th>
<td>
<input type="text" id="<?php echo $id; ?>-recipient" name="<?php echo $id; ?>[recipient]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['recipient'] ); ?>" data-config-field="<?php echo sprintf( '%s.recipient', esc_attr( $args['name'] ) ); ?>" />
<input type="text" id="<?php echo $id; ?>-recipient" name="<?php echo $id; ?>[recipient]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['recipient'] ); ?>" data-config-field="<?php echo sprintf( '%s.recipient', esc_attr( $options['name'] ) ); ?>" />
</td>
</tr>

Expand All @@ -159,7 +159,7 @@ function wpcf7_editor_box_mail( $post, $args = '' ) {
<label for="<?php echo $id; ?>-sender"><?php echo esc_html( __( 'From', 'contact-form-7' ) ); ?></label>
</th>
<td>
<input type="text" id="<?php echo $id; ?>-sender" name="<?php echo $id; ?>[sender]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['sender'] ); ?>" data-config-field="<?php echo sprintf( '%s.sender', esc_attr( $args['name'] ) ); ?>" />
<input type="text" id="<?php echo $id; ?>-sender" name="<?php echo $id; ?>[sender]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['sender'] ); ?>" data-config-field="<?php echo sprintf( '%s.sender', esc_attr( $options['name'] ) ); ?>" />
</td>
</tr>

Expand All @@ -168,7 +168,7 @@ function wpcf7_editor_box_mail( $post, $args = '' ) {
<label for="<?php echo $id; ?>-subject"><?php echo esc_html( __( 'Subject', 'contact-form-7' ) ); ?></label>
</th>
<td>
<input type="text" id="<?php echo $id; ?>-subject" name="<?php echo $id; ?>[subject]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['subject'] ); ?>" data-config-field="<?php echo sprintf( '%s.subject', esc_attr( $args['name'] ) ); ?>" />
<input type="text" id="<?php echo $id; ?>-subject" name="<?php echo $id; ?>[subject]" class="large-text code" size="70" value="<?php echo esc_attr( $mail['subject'] ); ?>" data-config-field="<?php echo sprintf( '%s.subject', esc_attr( $options['name'] ) ); ?>" />
</td>
</tr>

Expand All @@ -177,7 +177,7 @@ function wpcf7_editor_box_mail( $post, $args = '' ) {
<label for="<?php echo $id; ?>-additional-headers"><?php echo esc_html( __( 'Additional headers', 'contact-form-7' ) ); ?></label>
</th>
<td>
<textarea id="<?php echo $id; ?>-additional-headers" name="<?php echo $id; ?>[additional_headers]" cols="100" rows="4" class="large-text code" data-config-field="<?php echo sprintf( '%s.additional_headers', esc_attr( $args['name'] ) ); ?>"><?php echo esc_textarea( $mail['additional_headers'] ); ?></textarea>
<textarea id="<?php echo $id; ?>-additional-headers" name="<?php echo $id; ?>[additional_headers]" cols="100" rows="4" class="large-text code" data-config-field="<?php echo sprintf( '%s.additional_headers', esc_attr( $options['name'] ) ); ?>"><?php echo esc_textarea( $mail['additional_headers'] ); ?></textarea>
</td>
</tr>

Expand All @@ -186,7 +186,7 @@ function wpcf7_editor_box_mail( $post, $args = '' ) {
<label for="<?php echo $id; ?>-body"><?php echo esc_html( __( 'Message body', 'contact-form-7' ) ); ?></label>
</th>
<td>
<textarea id="<?php echo $id; ?>-body" name="<?php echo $id; ?>[body]" cols="100" rows="18" class="large-text code" data-config-field="<?php echo sprintf( '%s.body', esc_attr( $args['name'] ) ); ?>"><?php echo esc_textarea( $mail['body'] ); ?></textarea>
<textarea id="<?php echo $id; ?>-body" name="<?php echo $id; ?>[body]" cols="100" rows="18" class="large-text code" data-config-field="<?php echo sprintf( '%s.body', esc_attr( $options['name'] ) ); ?>"><?php echo esc_textarea( $mail['body'] ); ?></textarea>

<p><label for="<?php echo $id; ?>-exclude-blank"><input type="checkbox" id="<?php echo $id; ?>-exclude-blank" name="<?php echo $id; ?>[exclude_blank]" value="1"<?php echo ( ! empty( $mail['exclude_blank'] ) ) ? ' checked="checked"' : ''; ?> /> <?php echo esc_html( __( 'Exclude lines with blank mail-tags from output', 'contact-form-7' ) ); ?></label></p>

Expand All @@ -199,7 +199,7 @@ function wpcf7_editor_box_mail( $post, $args = '' ) {
<label for="<?php echo $id; ?>-attachments"><?php echo esc_html( __( 'File attachments', 'contact-form-7' ) ); ?></label>
</th>
<td>
<textarea id="<?php echo $id; ?>-attachments" name="<?php echo $id; ?>[attachments]" cols="100" rows="4" class="large-text code" data-config-field="<?php echo sprintf( '%s.attachments', esc_attr( $args['name'] ) ); ?>"><?php echo esc_textarea( $mail['attachments'] ); ?></textarea>
<textarea id="<?php echo $id; ?>-attachments" name="<?php echo $id; ?>[attachments]" cols="100" rows="4" class="large-text code" data-config-field="<?php echo sprintf( '%s.attachments', esc_attr( $options['name'] ) ); ?>"><?php echo esc_textarea( $mail['attachments'] ); ?></textarea>
</td>
</tr>
</tbody>
Expand Down
14 changes: 7 additions & 7 deletions includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* Validates uploaded files and moves them to the temporary directory.
*
* @param array $file An item of `$_FILES`.
* @param string|array $args Optional. Arguments to control behavior.
* @param string|array $options Optional. Options to control behavior.
* @return array|WP_Error Array of file paths, or WP_Error if validation fails.
*/
function wpcf7_unship_uploaded_file( $file, $args = '' ) {
$args = wp_parse_args( $args, array(
function wpcf7_unship_uploaded_file( $file, $options = '' ) {
$options = wp_parse_args( $options, array(
'required' => false,
'filetypes' => '',
'limit' => MB_IN_BYTES,
Expand All @@ -33,13 +33,13 @@ function wpcf7_unship_uploaded_file( $file, $args = '' ) {
}
}

if ( isset( $args['schema'] ) and isset( $args['name'] ) ) {
if ( isset( $options['schema'] ) and isset( $options['name'] ) ) {
$context = array(
'file' => true,
'field' => $args['name'],
'field' => $options['name'],
);

foreach ( $args['schema']->validate( $context ) as $result ) {
foreach ( $options['schema']->validate( $context ) as $result ) {
if ( is_wp_error( $result ) ) {
return $result;
}
Expand All @@ -64,7 +64,7 @@ function wpcf7_unship_uploaded_file( $file, $args = '' ) {
$filename = wpcf7_antiscript_file_name( $filename );

$filename = apply_filters( 'wpcf7_upload_file_name',
$filename, $name, $args
$filename, $name, $options
);

$filename = wp_unique_filename( $uploads_dir, $filename );
Expand Down
20 changes: 10 additions & 10 deletions includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,19 @@ function wpcf7_strip_newline( $text ) {
* Canonicalizes text.
*
* @param string $text Input text.
* @param string|array|object $args Options.
* @param string|array|object $options Options.
* @return string Canonicalized text.
*/
function wpcf7_canonicalize( $text, $args = '' ) {
function wpcf7_canonicalize( $text, $options = '' ) {
// for back-compat
if ( is_string( $args ) and '' !== $args
and false === strpos( $args, '=' ) ) {
$args = array(
'strto' => $args,
if ( is_string( $options ) and '' !== $options
and false === strpos( $options, '=' ) ) {
$options = array(
'strto' => $options,
);
}

$args = wp_parse_args( $args, array(
$options = wp_parse_args( $options, array(
'strto' => 'lower',
'strip_separators' => false,
) );
Expand All @@ -229,19 +229,19 @@ function wpcf7_canonicalize( $text, $args = '' ) {
$text = mb_convert_kana( $text, 'asKV', $charset );
}

if ( $args['strip_separators'] ) {
if ( $options['strip_separators'] ) {
$text = preg_replace( '/[\r\n\t ]+/', '', $text );
} else {
$text = preg_replace( '/[\r\n\t ]+/', ' ', $text );
}

if ( 'lower' == $args['strto'] ) {
if ( 'lower' == $options['strto'] ) {
if ( function_exists( 'mb_strtolower' ) ) {
$text = mb_strtolower( $text, $charset );
} else {
$text = strtolower( $text );
}
} elseif ( 'upper' == $args['strto'] ) {
} elseif ( 'upper' == $options['strto'] ) {
if ( function_exists( 'mb_strtoupper' ) ) {
$text = mb_strtoupper( $text, $charset );
} else {
Expand Down
42 changes: 20 additions & 22 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ static function ( $i ) {
* Creates a comma-separated list from a multi-dimensional array.
*
* @param mixed $input Array or item of array.
* @param string|array $args Optional. Output options.
* @param string|array $options Optional. Output options.
* @return string Comma-separated list.
*/
function wpcf7_flat_join( $input, $args = '' ) {
$args = wp_parse_args( $args, array(
function wpcf7_flat_join( $input, $options = '' ) {
$options = wp_parse_args( $options, array(
'separator' => ', ',
) );

Expand All @@ -164,7 +164,7 @@ function wpcf7_flat_join( $input, $args = '' ) {
}
}

return implode( $args['separator'], $output );
return implode( $options['separator'], $output );
}


Expand Down Expand Up @@ -242,16 +242,16 @@ function wpcf7_load_css() {
*
* @param string $url Link URL.
* @param string $anchor_text Anchor label text.
* @param string|array $args Optional. Link options.
* @param string|array $atts Optional. HTML attributes.
* @return string Formatted anchor element.
*/
function wpcf7_link( $url, $anchor_text, $args = '' ) {
$args = wp_parse_args( $args, array(
function wpcf7_link( $url, $anchor_text, $atts = '' ) {
$atts = wp_parse_args( $atts, array(
'id' => null,
'class' => null,
) );

$atts = array_merge( $args, array(
$atts = array_merge( $atts, array(
'href' => esc_url( $url ),
) );

Expand Down Expand Up @@ -294,22 +294,20 @@ function wpcf7_register_post_types() {
/**
* Returns the version string of this plugin.
*
* @param string|array $args Optional. Output options.
* @param string|array $options Optional. Output options.
* @return string Version string.
*/
function wpcf7_version( $args = '' ) {
$defaults = array(
function wpcf7_version( $options = '' ) {
$options = wp_parse_args( $options, array(
'limit' => -1,
'only_major' => false,
);

$args = wp_parse_args( $args, $defaults );
) );

if ( $args['only_major'] ) {
$args['limit'] = 2;
if ( $options['only_major'] ) {
$options['limit'] = 2;
}

$args['limit'] = (int) $args['limit'];
$options['limit'] = (int) $options['limit'];

$ver = WPCF7_VERSION;
$ver = strtr( $ver, '_-+', '...' );
Expand All @@ -318,8 +316,8 @@ function wpcf7_version( $args = '' ) {
$ver = trim( $ver, '.' );
$ver = explode( '.', $ver );

if ( -1 < $args['limit'] ) {
$ver = array_slice( $ver, 0, $args['limit'] );
if ( -1 < $options['limit'] ) {
$ver = array_slice( $ver, 0, $options['limit'] );
}

$ver = implode( '.', $ver );
Expand Down Expand Up @@ -433,15 +431,15 @@ function wpcf7_rmdir_p( $dir ) {
*
* @link https://developer.wordpress.org/reference/functions/_http_build_query/
*
* @param array $args URL query parameters.
* @param array $data URL query parameters.
* @param string $key Optional. If specified, used to prefix key name.
* @return string Query string.
*/
function wpcf7_build_query( $args, $key = '' ) {
function wpcf7_build_query( $data, $key = '' ) {
$sep = '&';
$ret = array();

foreach ( (array) $args as $k => $v ) {
foreach ( (array) $data as $k => $v ) {
$k = urlencode( $k );

if ( ! empty( $key ) ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/html-formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class WPCF7_HTMLFormatter {
/**
* Constructor.
*/
public function __construct( $args = '' ) {
$this->options = wp_parse_args( $args, array(
public function __construct( $options = '' ) {
$this->options = wp_parse_args( $options, array(
'auto_br' => true,
'auto_indent' => true,
) );
Expand Down
Loading

0 comments on commit 582cc06

Please sign in to comment.