Skip to content

Commit c7a9f0d

Browse files
committed
basic coding standards
1 parent be119d1 commit c7a9f0d

12 files changed

+75
-52
lines changed

admin/CF7_AntiSpam_Admin_Charts.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
* @author Codekraft Studio <info@codekraft.it>
1616
*/
1717

18-
/**
19-
* It creates a class called CF7_AntiSpam_Admin.
20-
*/
2118
class CF7_AntiSpam_Admin_Charts {
2219
/**
2320
* It queries the database for all the emails received in the last week, then it creates two lists:
@@ -67,15 +64,15 @@ private function cf7a_process_mail_collection( $query ) {
6764
$is_ham = 'flamingo-spam' !== $post->post_status;
6865
$today = esc_html( get_the_date( 'Y-m-d' ) );
6966

70-
// Initialize the date array if not exists
67+
/* Initialize the date array if not exists */
7168
if ( ! isset( $mail_collection['by_date'][ $today ] ) ) {
7269
$mail_collection['by_date'][ $today ] = array();
7370
}
7471

75-
// Count by type
72+
/* Count by type */
7673
++$mail_collection['by_type'][ $is_ham ? 'ham' : 'spam' ];
7774

78-
// Store by date
75+
/* Store by date */
7976
$mail_collection['by_date'][ $today ][] = array(
8077
'status' => $is_ham ? 'ham' : 'spam',
8178
);
@@ -129,7 +126,7 @@ private function cf7a_prepare_chart_data( $mail_collection ) {
129126
$mail_collection['by_date'] = array_reverse( $mail_collection['by_date'] );
130127
$count = array();
131128

132-
// Process data by date
129+
/* Process data by date */
133130
foreach ( $mail_collection['by_date'] as $date => $items ) {
134131
if ( ! isset( $count[ $date ] ) ) {
135132
$count[ $date ] = array(
@@ -138,13 +135,13 @@ private function cf7a_prepare_chart_data( $mail_collection ) {
138135
);
139136
}
140137

141-
// Count items by status for each date
138+
/* Count items by status for each date */
142139
foreach ( $items as $item ) {
143140
++$count[ $date ][ $item['status'] ];
144141
}
145142
}
146143

147-
// Extract ham and spam arrays for chart
144+
/* Extract ham and spam arrays for chart */
148145
$ham = array();
149146
$spam = array();
150147

@@ -209,7 +206,9 @@ private function cf7a_render_footer() {
209206
?>
210207
<p class="community-events-footer">
211208
<a href="<?php echo esc_url_raw( admin_url( 'admin.php?page=flamingo' ) ); ?>">
212-
<?php esc_html_e( 'Flamingo Inbound Messages', 'flamingo' ); ?>
209+
<?php
210+
/* phpcs:ignore WordPress.WP.I18n.TextDomainMismatch */
211+
esc_html_e( 'Flamingo Inbound Messages', 'flamingo' ); ?>
213212
<span aria-hidden="true" class="dashicons dashicons-external"></span>
214213
</a>
215214
|
@@ -246,13 +245,13 @@ public function cf7a_flamingo_widget() {
246245
return;
247246
}
248247

249-
// Process the mail collection
248+
/* Process the mail collection */
250249
$mail_collection = $this->cf7a_process_mail_collection( $query );
251250

252-
// Prepare chart data
251+
/* Prepare chart data */
253252
$chart_data = $this->cf7a_prepare_chart_data( $mail_collection );
254253

255-
// Render the widget
254+
/* Render the widget */
256255
?>
257256
<div id="antispam-widget">
258257
<canvas id="line-chart" width="400" height="200"></canvas>
@@ -282,13 +281,13 @@ public function cf7a_dash_charts() {
282281
return;
283282
}
284283

285-
// Process the mail collection
284+
/* Process the mail collection */
286285
$mail_collection = $this->cf7a_process_mail_collection( $query );
287286

288-
// Prepare chart data
287+
/* Prepare chart data */
289288
$chart_data = $this->cf7a_prepare_chart_data( $mail_collection );
290289

291-
// Render the widget
290+
/* Render the widget */
292291
?>
293292
<div id="antispam-charts">
294293
<div class="antispam-charts-container">

admin/CF7_AntiSpam_Admin_Customizations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ public function cf7a_geoip_key_callback() {
13441344
'<input type="text" id="geoip_dbkey" name="cf7a_options[geoip_dbkey]" %s %s/>',
13451345
empty( $this->options['geoip_dbkey'] ) ? '' : 'value="' . esc_attr( $this->options['geoip_dbkey'] ) . '"',
13461346
// phpcs:ignore WordPress.Security.EscapeOutput
1347-
empty( CF7ANTISPAM_GEOIP_KEY ) ? '' : 'disabled placeholder="' . esc_attr__( 'KEY provided' ) . '"'
1347+
empty( CF7ANTISPAM_GEOIP_KEY ) ? '' : 'disabled placeholder="' . esc_attr__( 'KEY provided', 'cf7-antispam' ) . '"'
13481348
);
13491349
}
13501350

admin/CF7_AntiSpam_Admin_Display.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,11 @@ function ( $count ) {
381381
<?php if ( count( $reason_counts ) > 5 ) : ?>
382382
<div class="cf7a-reason-item cf7a-reason-summary">
383383
<span class="cf7a-reason-name">
384-
<em><?php printf( esc_html__( 'Total unique reasons: %d', 'cf7-antispam' ), count( $reason_counts ) ); ?></em>
384+
<em><?php printf(
385+
/* translators: %d is the number of unique reasons */
386+
esc_html__( 'Total unique reasons: %d', 'cf7-antispam' ),
387+
count( $reason_counts ) );
388+
?></em>
385389
</span>
386390
<span class="cf7a-reason-count">
387391
<em><?php echo esc_html( array_sum( $reason_counts ) ); ?></em>
@@ -642,9 +646,9 @@ public static function cf7a_get_blacklisted_table() {
642646
cf7a_format_status( $row->status - $max_attempts ),
643647
esc_html( $row->ip ),
644648
esc_url( $unban_url ),
645-
esc_html__( '[unban ip]' ),
649+
esc_html__( '[unban ip]', 'cf7-antispam' ),
646650
esc_url( $ban_url ),
647-
esc_html__( '[ban forever]' ),
651+
esc_html__( '[ban forever]', 'cf7-antispam' ),
648652
cf7a_compress_array( $meta['reason'], true )
649653
);
650654
}
@@ -666,7 +670,11 @@ public static function cf7a_get_blacklisted_table() {
666670
),
667671
)
668672
),
669-
sprintf( esc_html__( 'Showing %d blacklisted IPs', 'cf7-antispam' ), intval( $count ) )
673+
sprintf(
674+
/* translators: %d is the number of blacklisted IPs */
675+
esc_html__( 'Showing %d blacklisted IPs', 'cf7-antispam' ),
676+
intval( $count )
677+
)
670678
);
671679
} else {
672680
echo '<p>' . esc_html__( 'No blacklisted IPs found.', 'cf7-antispam' ) . '</p>';
@@ -753,7 +761,7 @@ public function cf7a_get_debug_info() {
753761
private function cf7a_get_debug_info_rest_api() {
754762
printf(
755763
'<h3 class="title"><span class="dashicons dashicons-rest-api"></span> Rest API</h3><p><b>Rest API</b><div id="rest-api-status" class="waiting">%s</div></p>',
756-
esc_html__( 'Waiting for Rest API Status...' )
764+
esc_html__( 'Waiting for Rest API Status...', 'cf7-antispam' )
757765
);
758766
}
759767

@@ -800,17 +808,17 @@ private function cf7a_get_debug_info_dnsbl() {
800808
sprintf(
801809
'<tr><td>%s</td><td>%s</td><td>%f sec</td></tr>',
802810
$dnsbl,
803-
$is_spam ? esc_html__( 'spam' ) : esc_html__( 'ham' ),
811+
$is_spam ? esc_html__( 'spam', 'cf7-antispam' ) : esc_html__( 'ham', 'cf7-antispam' ),
804812
$time_taken
805813
);
806814
}
807815

808816
if ( ! empty( $performance_test ) ) {
809817
printf(
810818
'<h3 class="title"><span class="dashicons dashicons-privacy"></span> %s</h3><p>%s</p><p>%s: %s</p><table class="dnsbl_table">%s</table>',
811-
esc_html__( 'DNSBL performance test:' ),
812-
esc_html__( 'Results below 0.01 are fine, OK/Spam indicates the status of your ip on DNSBL servers' ),
813-
esc_html__( 'Your IP address' ),
819+
esc_html__( 'DNSBL performance test:', 'cf7-antispam' ),
820+
esc_html__( 'Results below 0.01 are fine, OK/Spam indicates the status of your ip on DNSBL servers', 'cf7-antispam' ),
821+
esc_html__( 'Your IP address', 'cf7-antispam' ),
814822
filter_var( $remote_ip, FILTER_VALIDATE_IP ),
815823
wp_kses(
816824
implode( '', $performance_test ),

cf7-antispam.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Author: Codekraft
66
* Text Domain: cf7-antispam
77
* Domain Path: /languages
8-
* Version: 0.6.4
8+
* Version: 0.7.0
99
*
1010
* @package cf7-antispam
1111
*/
@@ -18,7 +18,7 @@
1818
/* CONSTANTS */
1919
define( 'CF7ANTISPAM_NAME', 'cf7-antispam' );
2020

21-
define( 'CF7ANTISPAM_VERSION', '0.6.4' );
21+
define( 'CF7ANTISPAM_VERSION', '0.7.0' );
2222

2323
define( 'CF7ANTISPAM_PLUGIN', __FILE__ );
2424

@@ -67,6 +67,7 @@
6767
/**
6868
* The code that runs during plugin activation.
6969
*/
70+
/* phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound */
7071
function activate_cf7_antispam( $network_wide ) {
7172
\CF7_AntiSpam\Engine\CF7_AntiSpam_Activator::on_activate( $network_wide );
7273
}
@@ -79,6 +80,7 @@ function activate_cf7_antispam( $network_wide ) {
7980
*
8081
* @param int $blog_id - The ID of the new blog.
8182
*/
83+
/* phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound */
8284
function on_create_blog( $blog_id ) {
8385
if ( is_plugin_active_for_network( 'cf7-antispam/cf7-antispam.php' ) ) {
8486
switch_to_blog( $blog_id );
@@ -95,6 +97,7 @@ function on_create_blog( $blog_id ) {
9597
*
9698
* @param array $tables - Array of tables.
9799
*/
100+
/* phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound */
98101
function on_delete_blog( $tables ) {
99102
global $wpdb;
100103
$tables[] = $wpdb->prefix . 'cf7a_wordlist';
@@ -106,6 +109,7 @@ function on_delete_blog( $tables ) {
106109
/**
107110
* The code that runs during plugin deactivation.
108111
*/
112+
/* phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound */
109113
function deactivate_cf7_antispam() {
110114
\CF7_AntiSpam\Engine\CF7_AntiSpam_Deactivator::deactivate();
111115
}
@@ -114,6 +118,7 @@ function deactivate_cf7_antispam() {
114118
/**
115119
* The code that runs during plugin un-installation.
116120
*/
121+
/* phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound */
117122
function uninstall_cf7_antispam() {
118123
\CF7_AntiSpam\Engine\CF7_AntiSpam_Uninstaller::uninstall();
119124
}
@@ -124,6 +129,7 @@ function uninstall_cf7_antispam() {
124129
* Call the integration action to mount our plugin as a component
125130
* into the intefration page
126131
*/
132+
/* phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound */
127133
function cf7_antispam_register_service() {
128134
$integration = WPCF7_Integration::get_instance();
129135
$integration->add_service(
@@ -136,8 +142,9 @@ function cf7_antispam_register_service() {
136142
/**
137143
* Executes CF7-AntiSpam
138144
*/
145+
/* phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound */
139146
function run_cf7a() {
140147
$cf7a = new \CF7_AntiSpam\Core\CF7_AntiSpam();
141148
$cf7a->run();
142149
}
143-
add_action( 'init', 'run_cf7a', 11, 0 );
150+
add_action( 'init', 'run_cf7a', 11 );

core/CF7_AntiSpam.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,11 @@ public function spam_mail_report( $mail_body, $last_report_timestamp ) {
388388
)
389389
);
390390

391-
$mail_body .= __( \sprintf( '<p>%s overall spam attempts, %s since last report</p>', $all, $last ), 'cf7-antispam' );
391+
$mail_body .= '<p>' . sprintf(
392+
/* translators: %1$s overall spam attempts, %2$s since last report */
393+
__('%1$s overall spam attempts, %2$s since last report', 'cf7-antispam' ),
394+
$all, $last
395+
) . '</p>';
392396

393397
return $mail_body;
394398
}

core/CF7_AntiSpam_Filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ public function cf7a_spam_filter( $spam ) {
943943
if ( ! empty( $mail_tag_text ) ) {
944944

945945
/* get the collection of the generated (fake) input name used as honeypots name value */
946-
$input_names = get_honeypot_input_names( $options['honeypot_input_names'] );
946+
$input_names = cf7a_get_honeypot_input_names( $options['honeypot_input_names'] );
947947

948948
$mail_tag_count = count( $input_names );
949949

core/CF7_AntiSpam_Flamingo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public function cf7a_flamingo_remove_honeypot( $result ) {
423423

424424
if ( isset( $options['check_honeypot'] ) && intval( $options['check_honeypot'] ) === 1 ) {
425425
$submission = WPCF7_Submission::get_instance();
426-
$honeypot_default_names = get_honeypot_input_names( $options['honeypot_input_names'] );
426+
$honeypot_default_names = cf7a_get_honeypot_input_names( $options['honeypot_input_names'] );
427427

428428
if ( ! $submission ) {
429429
return true;

core/CF7_AntiSpam_Frontend.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function cf7a_remove_cf7_error_message( $error_codes, $contact_form ) {
154154
public function cf7a_honeypot_add( $form_elements ) {
155155
/* A list of default names for the honeypot fields. */
156156
$options = get_option( 'cf7a_options', array() );
157-
$input_names = ! empty( $options['honeypot_input_names'] ) ? get_honeypot_input_names( $options['honeypot_input_names'] ) : array();
157+
$input_names = ! empty( $options['honeypot_input_names'] ) ? cf7a_get_honeypot_input_names( $options['honeypot_input_names'] ) : array();
158158
$input_class = ! empty( $this->options['cf7a_customizations_class'] ) ? sanitize_html_class( $this->options['cf7a_customizations_class'] ) : 'cf7a';
159159
/**
160160
* Controls the maximum number of honeypots.
@@ -579,7 +579,13 @@ public function cf7a_check_resend( $cf7, &$abort, $submission ) {
579579
} elseif ( get_transient( "mail_sent_$hash" ) ) {
580580
// Set the status
581581
$submission->set_status( 'mail_sent_multiple' );
582-
$submission->set_response( esc_html__( "Slow down, please wait $expire seconds before resending.", 'cf7-antispam' ) );
582+
$submission->set_response(
583+
sprintf(
584+
/* translators: % is the number of seconds to wait */
585+
esc_html__( 'Slow down, please wait %s seconds before resending.', 'cf7-antispam' ),
586+
$expire
587+
)
588+
);
583589
} else {
584590
delete_transient( "mail_sent_$hash" );
585591
set_transient( "mail_sent_$hash", true, $expire );

core/CF7_AntiSpam_Rest_Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function cf7a_get_permissions_check( $request ) {
9191
if ( ! current_user_can( 'manage_options' ) ) {
9292
return new WP_Error(
9393
'rest_forbidden',
94-
esc_html__( 'You cannot view the plugin status.' ),
94+
esc_html__( 'You cannot view the plugin status.', 'cf7-antispam' ),
9595
array( 'status' => 401 )
9696
);
9797
}

core/CF7_Antispam_Service.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ public function __construct() {
6666
* @return string "CF7-Antispam" with the translation "Contact Form 7 Antispam".
6767
*/
6868
public function get_title() {
69-
return __( 'Antispam', 'Contact Form 7 Antispam' );
69+
return __( 'Antispam', 'cf7-antispam' );
7070
}
7171

7272
/**
7373
* The function checks if a certain option called "enabled" is set to true.
7474
*
75-
* @return bool value of the 'enabled' key in the array.
75+
* @return bool value of the 'enabled' key in the array.
7676
*/
7777
public function is_active() {
7878
return isset( $this->options['cf7a_enable'] ) ? $this->options['cf7a_enable'] : false;
@@ -229,13 +229,9 @@ public function display( $action = '' ) {
229229
)
230230
);
231231

232-
printf(
233-
'<p><strong>%s</strong></p>',
234-
// phpcs:ignore
235-
wpcf7_link(
236-
esc_html__( 'https://wordpress.org/plugins/cf7-antispam/', 'contact-form-7' ),
237-
esc_html__( 'CF7-Antispam (v' . CF7ANTISPAM_VERSION . ')', 'contact-form-7' )
238-
)
232+
printf( '<p><strong>%s</strong></p>',
233+
wpcf7_link( esc_html__( 'https://wordpress.org/plugins/cf7-antispam/', 'contact-form-7' ), sprintf( 'CF7-Antispam (v%s)', 'contact-form-7' ), CF7ANTISPAM_VERSION )
234+
239235
);
240236

241237
if ( $this->is_active() ) {

0 commit comments

Comments
 (0)