Skip to content

Commit 6b81cac

Browse files
author
Antti Kuosmanen
committed
Update to newer WordPress code standard ruleset
1 parent d4081c2 commit 6b81cac

6 files changed

Lines changed: 36 additions & 18 deletions

File tree

classes/class-cpt-wplf-form.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ function save_cpt( $post_id ) {
401401
// verify nonce
402402
if ( ! isset( $_POST['wplf_form_meta_nonce'] ) ) {
403403
return;
404-
} else if ( ! wp_verify_nonce( $_POST['wplf_form_meta_nonce'], 'wplf_form_meta' ) ) {
404+
} elseif ( ! wp_verify_nonce( $_POST['wplf_form_meta_nonce'], 'wplf_form_meta' ) ) {
405405
return;
406406
}
407407

@@ -502,7 +502,7 @@ function wplf_form( $id, $content = '', $xclass = '' ) {
502502
ob_start();
503503
?>
504504
<form
505-
class="libre-form libre-form-<?php esc_attr_e( $id . ' ' . $xclass ); ?>"
505+
class="libre-form libre-form-<?php echo esc_attr( $id . ' ' . $xclass ); ?>"
506506
<?php
507507
// check if form contains file inputs
508508
if ( strpos( $content, "type='file'" ) >= 0 || strpos( $content, 'type="file"' ) >= 0 ) {
@@ -531,8 +531,8 @@ class="libre-form libre-form-<?php esc_attr_e( $id . ' ' . $xclass ); ?>"
531531
// @codingStandardsIgnoreEnd
532532
?>
533533
<input type="hidden" name="referrer" value="<?php the_permalink(); ?>">
534-
<input type="hidden" name="_referrer_id" value="<?php esc_attr_e( get_the_id() ) ?>">
535-
<input type="hidden" name="_form_id" value="<?php esc_attr_e( $id ); ?>">
534+
<input type="hidden" name="_referrer_id" value="<?php echo esc_attr( get_the_id() ) ?>">
535+
<input type="hidden" name="_form_id" value="<?php echo esc_attr( $id ); ?>">
536536
</form>
537537
<?php
538538
$output = ob_get_clean();

classes/class-cpt-wplf-submission.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function custom_columns_display_cpt( $column, $post_id ) {
8787
if ( 'form' === $column ) {
8888
if ( $form_id = get_post_meta( $post_id, '_form_id', true ) ) {
8989
$form = get_post( $form_id );
90-
echo '<a href="' . esc_url_raw( get_edit_post_link( $form_id, '' ) ). '" target="_blank">';
90+
echo '<a href="' . esc_url_raw( get_edit_post_link( $form_id, '' ) ) . '" target="_blank">';
9191
echo esc_html( $form->post_title );
9292
echo '</a>';
9393
}
@@ -197,14 +197,16 @@ function wplf_submission_bulk_action_admin_notice() {
197197
$count = intval( $_REQUEST['wplf_resent'] );
198198
printf(
199199
'<div id="wplf-submission-bulk-resend-message" class="notice notice-success"><p>' .
200-
esc_html__(
201-
_n( 'Resent email copy of %s submission.',
202-
'Resent email copy of %s submissions.',
203-
$count ),
204-
'wp-libre-form'
205-
) . '</p></div>',
206-
intval( $count )
207-
);
200+
esc_html(
201+
// translators: %s is number of submissions
202+
_n( 'Resent email copy of %s submission.',
203+
'Resent email copy of %s submissions.',
204+
$count,
205+
'wp-libre-form'
206+
)
207+
) .
208+
'</p></div>',
209+
intval( $count ) );
208210
}
209211
}
210212

@@ -242,7 +244,7 @@ function metabox_submission() {
242244
</thead>
243245
<tbody>
244246
<?php foreach ( $fields as $field ) : ?>
245-
<?php if ( '_' !== $field[0] ) : ?>
247+
<?php if ( '_' !== $field[0] ) : ?>
246248
<?php
247249
$value = $postmeta[ $field ][0];
248250

@@ -272,7 +274,7 @@ function metabox_submission() {
272274
<?php if ( strlen( $value ) > 60 || strpos( $value, "\n" ) ) : ?>
273275
<td><textarea style="width:100%" readonly><?php echo esc_textarea( $value ); ?></textarea></td>
274276
<?php else : ?>
275-
<td><input style="width:100%" type="text" value="<?php esc_attr_e( $value ); ?>" readonly></td>
277+
<td><input style="width:100%" type="text" value="<?php echo esc_attr( $value ); ?>" readonly></td>
276278
<?php endif; ?>
277279
</tr>
278280
<?php endif; ?>

inc/wplf-ajax.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ function wplf_ajax_submit_handler() {
5555
foreach ( $_FILES as $key => $file ) {
5656
// Is this enough security wise?
5757
// Currenly only supports 1 file per input
58-
$attach_id = media_handle_upload( $key, 0, array(), array( 'test_form' => false ) );
58+
$attach_id = media_handle_upload( $key, 0, array(), array(
59+
'test_form' => false,
60+
) );
5961
add_post_meta( $post_id, $key, wp_get_attachment_url( $attach_id ) );
6062
add_post_meta( $post_id, $key . '_attachment', $attach_id );
6163
}

inc/wplf-form-actions.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ function wplf_send_email_copy( $return, $submission_id = null ) {
2121
|| isset( $submission_id ) ) {
2222

2323
$to = $form_meta['_wplf_email_copy_to'][0];
24+
// translators: %s is email address of form submitter
2425
$subject = wp_sprintf( __( 'New submission from %s', 'wp-libre-form' ), $referrer );
2526

2627
if ( isset( $submission_id ) ) {
2728
$to = get_post_meta( $submission_id, '_wplf_email_copy_to', true );
29+
// translators: %s is email address of form submitter
2830
$subject = wp_sprintf( __( 'Submission from %s', 'wp-libre-form' ), $referrer );
2931
}
3032

3133
$to = empty( $to ) ? get_option( 'admin_email' ) : $to;
3234
$content = wp_sprintf(
33-
__( 'Form "%s" (ID %d) was submitted with values below: ', 'wp-libre-form' ), $form_title, $form_id );
34-
$content = apply_filters( 'wplf_email_copy_content_start', $content, $form_title, $form_id ). "\n\n";
35+
// translators: %1$s is form title, %2$d is form ID
36+
__( 'Form "%1$s" (ID %2$d) was submitted with values below: ', 'wp-libre-form' ), $form_title, $form_id );
37+
$content = apply_filters( 'wplf_email_copy_content_start', $content, $form_title, $form_id ) . "\n\n";
3538

3639
$fields = $_POST;
3740
if ( isset( $submission_id ) ) {

inc/wplf-form-validation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function wplf_validate_form_exists( $return ) {
1616
|| 'wplf-form' !== get_post_type( $_POST['_form_id'] )
1717
) {
1818
$return->ok = 0;
19+
// translators: %d is form ID
1920
$return->error = sprintf( __( "Form id %d doesn't exist!", 'wp-libre-form' ), intval( $_POST['_form_id'] ) );
2021
}
2122
return $return;

phpcs.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,15 @@
108108

109109
<!-- We don't use nonce verification in this plugin -->
110110
<exclude name="WordPress.CSRF.NonceVerification.NoNonceVerification" />
111+
112+
<!-- We like assignments in if -->
113+
<exclude name="Squiz.PHP.DisallowMultipleAssignments.Found" />
114+
115+
<!-- Our hooks use dashes, not underscores -->
116+
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" />
117+
118+
<!-- This would be nice to enforce, but plugin main file shouldn't be called class-something -->
119+
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
120+
111121
</rule>
112122
</ruleset>

0 commit comments

Comments
 (0)