Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use strict comparison #1537

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static function ( $result, $option, $value ) {
'wpcf7_contact_forms_per_page',
);

if ( in_array( $option, $wpcf7_screens ) ) {
if ( in_array( $option, $wpcf7_screens, true ) ) {
$result = $value;
}

Expand Down Expand Up @@ -275,7 +275,7 @@ function wpcf7_load_contact_form_admin() {

if ( ! $contact_form ) {
$query['message'] = 'failed';
} elseif ( -1 == $id ) {
} elseif ( -1 === (int) $id ) {
$query['message'] = 'created';
} else {
$query['message'] = 'saved';
Expand Down Expand Up @@ -405,7 +405,7 @@ function wpcf7_admin_management_page() {
return;
}

if ( 'validate' == wpcf7_current_action()
if ( 'validate' === wpcf7_current_action()
and wpcf7_validate_configuration()
and current_user_can( 'wpcf7_edit_contact_forms' ) ) {
wpcf7_admin_bulk_validate_page();
Expand Down Expand Up @@ -552,7 +552,7 @@ function wpcf7_admin_integration_page() {
add_action( 'wpcf7_admin_notices', 'wpcf7_admin_updated_message', 10, 3 );

function wpcf7_admin_updated_message( $page, $action, $object ) {
if ( ! in_array( $page, array( 'wpcf7', 'wpcf7-new' ) ) ) {
if ( ! in_array( $page, array( 'wpcf7', 'wpcf7-new' ), true ) ) {
return;
}

Expand Down Expand Up @@ -607,7 +607,7 @@ function wpcf7_admin_updated_message( $page, $action, $object ) {
add_filter( 'plugin_action_links', 'wpcf7_plugin_action_links', 10, 2 );

function wpcf7_plugin_action_links( $links, $file ) {
if ( $file != WPCF7_PLUGIN_BASENAME ) {
if ( WPCF7_PLUGIN_BASENAME !== $file ) {
return $links;
}

Expand Down
10 changes: 5 additions & 5 deletions admin/includes/class-contact-forms-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public function prepare_items() {
}

if ( ! empty( $_REQUEST['orderby'] ) ) {
if ( 'title' == $_REQUEST['orderby'] ) {
if ( 'title' === $_REQUEST['orderby'] ) {
$args['orderby'] = 'title';
} elseif ( 'author' == $_REQUEST['orderby'] ) {
} elseif ( 'author' === $_REQUEST['orderby'] ) {
$args['orderby'] = 'author';
} elseif ( 'date' == $_REQUEST['orderby'] ) {
} elseif ( 'date' === $_REQUEST['orderby'] ) {
$args['orderby'] = 'date';
}
}

if ( ! empty( $_REQUEST['order'] ) ) {
if ( 'asc' == strtolower( $_REQUEST['order'] ) ) {
if ( 'asc' === strtolower( $_REQUEST['order'] ) ) {
$args['order'] = 'ASC';
} elseif ( 'desc' == strtolower( $_REQUEST['order'] ) ) {
} elseif ( 'desc' === strtolower( $_REQUEST['order'] ) ) {
$args['order'] = 'DESC';
}
}
Expand Down
6 changes: 3 additions & 3 deletions admin/includes/config-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ function wpcf7_admin_warnings_bulk_cv( $page, $action, $object ) {
add_action( 'wpcf7_admin_load', 'wpcf7_load_bulk_validate_page', 10, 2 );

function wpcf7_load_bulk_validate_page( $page, $action ) {
if ( 'wpcf7' != $page
or 'validate' != $action
if ( 'wpcf7' !== $page
or 'validate' !== $action
or ! wpcf7_validate_configuration()
or 'POST' != $_SERVER['REQUEST_METHOD'] ) {
or 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion admin/includes/welcome-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function wpcf7_welcome_panel_screen_settings( $screen_settings, $screen ) {
);

$checkbox_id = 'wpcf7-welcome-panel-show';
$checked = ! in_array( wpcf7_version( 'only_major=1' ), $vers );
$checked = ! in_array( wpcf7_version( 'only_major=1' ), $vers, true );

$checkbox = sprintf(
'<input %s />',
Expand Down
4 changes: 2 additions & 2 deletions includes/config-validator/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public function validate_mail_additional_headers( $template, $content ) {

if (
in_array(
strtolower( $header_name ), array( 'reply-to', 'cc', 'bcc' )
strtolower( $header_name ), array( 'reply-to', 'cc', 'bcc' ), true
) and
'' !== $header_value and
$this->detect_invalid_mailbox_syntax( $section, $header_value )
Expand All @@ -283,7 +283,7 @@ public function validate_mail_additional_headers( $template, $content ) {
}

if (
in_array( strtolower( $header_name ), array( 'cc', 'bcc' ) ) and
in_array( strtolower( $header_name ), array( 'cc', 'bcc' ), true ) and
$this->detect_unsafe_email_without_protection( $section, $header_value )
) {
$unsafe_email_fields[] = $header_name;
Expand Down
4 changes: 2 additions & 2 deletions includes/contact-form-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function wpcf7_save_contact_form( $data = '', $context = 'save' ) {

$data['id'] = (int) $data['id'];

if ( -1 == $data['id'] ) {
if ( -1 === $data['id'] ) {
$contact_form = WPCF7_ContactForm::get_template();
} else {
$contact_form = wpcf7_contact_form( $data['id'] );
Expand Down Expand Up @@ -347,7 +347,7 @@ function wpcf7_save_contact_form( $data = '', $context = 'save' ) {

do_action( 'wpcf7_save_contact_form', $contact_form, $data, $context );

if ( 'save' == $context ) {
if ( 'save' === $context ) {
$contact_form->save();
}

Expand Down
8 changes: 4 additions & 4 deletions includes/contact-form-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
class WPCF7_ContactFormTemplate {

public static function get_default( $prop = 'form' ) {
if ( 'form' == $prop ) {
if ( 'form' === $prop ) {
$template = self::form();
} elseif ( 'mail' == $prop ) {
} elseif ( 'mail' === $prop ) {
$template = self::mail();
} elseif ( 'mail_2' == $prop ) {
} elseif ( 'mail_2' === $prop ) {
$template = self::mail_2();
} elseif ( 'messages' == $prop ) {
} elseif ( 'messages' === $prop ) {
$template = self::messages();
} else {
$template = null;
Expand Down
10 changes: 5 additions & 5 deletions includes/contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public function form_html( $options = '' ) {

$this->shortcode_atts = $options;

if ( 'raw_form' == $options['output'] ) {
if ( 'raw_form' === $options['output'] ) {
return sprintf(
'<pre class="wpcf7-raw-form"><code>%s</code></pre>',
esc_html( $this->prop( 'form' ) )
Expand Down Expand Up @@ -584,7 +584,7 @@ public function form_html( $options = '' ) {
wpcf7_format_atts( array(
'class' => 'wpcf7 no-js',
'id' => $this->unit_tag(),
( get_option( 'html_type' ) == 'text/html' ) ? 'lang' : 'xml:lang'
( get_option( 'html_type' ) === 'text/html' ) ? 'lang' : 'xml:lang'
=> $lang_tag,
'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr',
'data-wpcf7-id' => $this->id(),
Expand Down Expand Up @@ -982,11 +982,11 @@ public function collect_mail_tags( $options = '' ) {
if ( empty( $type ) ) {
continue;
} elseif ( ! empty( $options['include'] ) ) {
if ( ! in_array( $type, $options['include'] ) ) {
if ( ! in_array( $type, $options['include'], true ) ) {
continue;
}
} elseif ( ! empty( $options['exclude'] ) ) {
if ( in_array( $type, $options['exclude'] ) ) {
if ( in_array( $type, $options['exclude'], true ) ) {
continue;
}
}
Expand Down Expand Up @@ -1155,7 +1155,7 @@ public function additional_setting( $name, $max = 1 ) {

foreach ( $settings as $setting ) {
if ( preg_match( $pattern, $setting, $matches ) ) {
if ( $matches[1] != $name ) {
if ( $matches[1] !== $name ) {
continue;
}

Expand Down
6 changes: 2 additions & 4 deletions includes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static function ( $type ) {
if ( false === strpos( $type, '/' ) ) {
return sprintf( '.%s', trim( $type, '.' ) );
} elseif ( preg_match( '%^([a-z]+)/[*]$%i', $type, $matches ) ) {
if ( in_array( $matches[1], array( 'audio', 'video', 'image' ) ) ) {
if ( in_array( $matches[1], array( 'audio', 'video', 'image' ), true ) ) {
return $type;
} else {
return '';
Expand Down Expand Up @@ -360,9 +360,7 @@ function wpcf7_cleanup_upload_files( $seconds = 60, $max = 100 ) {

if ( $handle = opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( '.' == $file
or '..' == $file
or '.htaccess' == $file ) {
if ( '.' === $file or '..' === $file or '.htaccess' === $file ) {
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions includes/form-tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function get_option( $option_name, $pattern = '', $single = false ) {
$pattern = $preset_patterns[$pattern];
}

if ( '' == $pattern ) {
if ( '' === $pattern ) {
$pattern = '.+';
}

Expand Down Expand Up @@ -350,9 +350,9 @@ public function get_default_option( $default_value = '', $args = '' ) {
foreach ( $options as $opt ) {
$opt = sanitize_key( $opt );

if ( 'user_' == substr( $opt, 0, 5 ) and is_user_logged_in() ) {
if ( 'user_' === substr( $opt, 0, 5 ) and is_user_logged_in() ) {
$primary_props = array( 'user_login', 'user_email', 'user_url' );
$opt = in_array( $opt, $primary_props ) ? $opt : substr( $opt, 5 );
$opt = in_array( $opt, $primary_props, true ) ? $opt : substr( $opt, 5 );

$user = wp_get_current_user();
$user_prop = $user->get( $opt );
Expand Down
6 changes: 2 additions & 4 deletions includes/form-tags-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ public function normalize( $content ) {
*/
private function normalize_callback( $matches ) {
// allow [[foo]] syntax for escaping a tag
if ( $matches[1] == '['
and $matches[6] == ']' ) {
if ( '[' === $matches[1] and ']' === $matches[6] ) {
return $matches[0];
}

Expand Down Expand Up @@ -466,8 +465,7 @@ private function replace_callback( $matches ) {
*/
private function scan_callback( $matches, $replace = false ) {
// allow [[foo]] syntax for escaping a tag
if ( $matches[1] == '['
and $matches[6] == ']' ) {
if ( '[' === $matches[1] and ']' === $matches[6] ) {
return substr( $matches[0], 1, -1 );
}

Expand Down
11 changes: 6 additions & 5 deletions includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function wpcf7_normalize_newline( $text, $to = "\n" ) {

$nls = array( "\r\n", "\r", "\n" );

if ( ! in_array( $to, $nls ) ) {
if ( ! in_array( $to, $nls, true ) ) {
return $text;
}

Expand Down Expand Up @@ -215,7 +215,8 @@ function wpcf7_canonicalize( $text, $options = '' ) {

$is_utf8 = in_array(
$charset,
array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' )
array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ),
true
);

if ( $is_utf8 ) {
Expand All @@ -235,13 +236,13 @@ function wpcf7_canonicalize( $text, $options = '' ) {
$text = preg_replace( '/[\r\n\t ]+/', ' ', $text );
}

if ( 'lower' == $options['strto'] ) {
if ( 'lower' === $options['strto'] ) {
if ( function_exists( 'mb_strtolower' ) ) {
$text = mb_strtolower( $text, $charset );
} else {
$text = strtolower( $text );
}
} elseif ( 'upper' == $options['strto'] ) {
} elseif ( 'upper' === $options['strto'] ) {
if ( function_exists( 'mb_strtoupper' ) ) {
$text = mb_strtoupper( $text, $charset );
} else {
Expand Down Expand Up @@ -550,7 +551,7 @@ function wpcf7_format_atts( $atts ) {
'selected',
);

if ( in_array( $name, $boolean_attributes ) and '' === $value ) {
if ( in_array( $name, $boolean_attributes, true ) and '' === $value ) {
$value = false;
}

Expand Down
18 changes: 8 additions & 10 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function wpcf7_plugin_path( $path = '' ) {
function wpcf7_plugin_url( $path = '' ) {
$url = plugins_url( $path, WPCF7_PLUGIN );

if ( is_ssl()
and 'http:' == substr( $url, 0, 5 ) ) {
if ( is_ssl() and 'http:' === substr( $url, 0, 5 ) ) {
$url = 'https:' . substr( $url, 5 );
}

Expand Down Expand Up @@ -67,9 +66,9 @@ function wpcf7_upload_dir( $type = false ) {
'url' => $uploads['baseurl'],
) );

if ( 'dir' == $type ) {
if ( 'dir' === $type ) {
return $uploads['dir'];
} if ( 'url' == $type ) {
} if ( 'url' === $type ) {
return $uploads['url'];
}

Expand Down Expand Up @@ -359,7 +358,7 @@ function wpcf7_enctype_value( $enctype ) {
'text/plain',
);

if ( in_array( $enctype, $valid_enctypes ) ) {
if ( in_array( $enctype, $valid_enctypes, true ) ) {
return $enctype;
}

Expand Down Expand Up @@ -406,8 +405,7 @@ function wpcf7_rmdir_p( $dir ) {

if ( $handle = opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file == "."
or $file == ".." ) {
if ( '.' === $file or '..' === $file ) {
continue;
}

Expand Down Expand Up @@ -505,7 +503,7 @@ function wpcf7_count_code_units( $text ) {
*/
function wpcf7_is_localhost() {
$sitename = wp_parse_url( network_home_url(), PHP_URL_HOST );
return in_array( strtolower( $sitename ), array( 'localhost', '127.0.0.1' ) );
return in_array( strtolower( $sitename ), array( 'localhost', '127.0.0.1' ), true );
}


Expand Down Expand Up @@ -688,9 +686,9 @@ function wpcf7_anonymize_ip_addr( $ip_addr ) {
return $ip_addr;
}

if ( 4 == strlen( $packed ) ) { // IPv4
if ( 4 === strlen( $packed ) ) { // IPv4
$mask = '255.255.255.0';
} elseif ( 16 == strlen( $packed ) ) { // IPv6
} elseif ( 16 === strlen( $packed ) ) { // IPv6
$mask = 'ffff:ffff:ffff:0000:0000:0000:0000:0000';
} else {
return $ip_addr;
Expand Down
Loading