Skip to content

Commit

Permalink
Use PHP 7 new features.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 19, 2023
1 parent c5726d5 commit c7a936c
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 37 deletions.
5 changes: 3 additions & 2 deletions src/php/Avada/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function init_hooks() {
* @param array $params Parameters.
*
* @return void
* @noinspection PhpUnusedParameterInspection
*/
public function form_after_open( $args, $params ) {
$this->form_id = isset( $params['id'] ) ? (int) $params['id'] : 0;
Expand Down Expand Up @@ -91,8 +92,8 @@ public function verify( $demo_mode ) {
[];

$form_data = wp_parse_args( str_replace( '&', '&', $form_data ) );
$hcaptcha_response = isset( $form_data['h-captcha-response'] ) ? $form_data['h-captcha-response'] : '';
$hcaptcha_widget_id = isset( $form_data['hcaptcha-widget-id'] ) ? $form_data['hcaptcha-widget-id'] : '';
$hcaptcha_response = $form_data['h-captcha-response'] ?? '';
$hcaptcha_widget_id = $form_data['hcaptcha-widget-id'] ?? '';
$_POST['hcaptcha-widget-id'] = $hcaptcha_widget_id;
// phpcs:disable WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Missing

Expand Down
2 changes: 1 addition & 1 deletion src/php/BackInStockNotifier/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function after_submit_button( $product_id, $variation_id ) {
*/
public function verify( $post_data, $rest_api ) {

$hcaptcha_response = isset( $post_data['h-captcha-response'] ) ? $post_data['h-captcha-response'] : '';
$hcaptcha_response = $post_data['h-captcha-response'] ?? '';

$result = hcaptcha_request_verify( $hcaptcha_response );

Expand Down
10 changes: 5 additions & 5 deletions src/php/CF7/CF7.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function cf7_hcaptcha_shortcode( $attr = [] ) {
'size' => $hcaptcha_size, // The hCaptcha widget size.
'id' => [
'source' => HCaptcha::get_class_source( __CLASS__ ),
'form_id' => isset( $attr['form_id'] ) ? $attr['form_id'] : 0,
'form_id' => $attr['form_id'] ?? 0,
], // hCaptcha widget id.
/**
* Example of id:
Expand All @@ -125,7 +125,7 @@ public function cf7_hcaptcha_shortcode( $attr = [] ) {
if ( $args['id'] ) {
$id = (array) $args['id'];
$id['source'] = isset( $id['source'] ) ? (array) $id['source'] : [];
$id['form_id'] = isset( $id['form_id'] ) ? $id['form_id'] : 0;
$id['form_id'] = $id['form_id'] ?? 0;

/**
* Filters the protection status of a form.
Expand Down Expand Up @@ -191,7 +191,7 @@ public function verify_hcaptcha( $result, $tag ) {
}

$data = $submission->get_posted_data();
$response = isset( $data['h-captcha-response'] ) ? $data['h-captcha-response'] : '';
$response = $data['h-captcha-response'] ?? '';
$captcha_result = hcaptcha_request_verify( $response );

if ( null !== $captcha_result ) {
Expand Down Expand Up @@ -245,7 +245,7 @@ public function enqueue_scripts() {
}

/**
* Add form_id to cf7_hcaptcha shortcode if it does not exists.
* Add form_id to cf7_hcaptcha shortcode if it does not exist.
* Replace to proper form_id if needed.
*
* @param string $output CF7 form output.
Expand Down Expand Up @@ -273,7 +273,7 @@ private function add_form_id_to_cf7_hcap_shortcode( $output, $form_id ) {
array_walk(
$atts,
static function ( &$value, $key ) {
$value = "{$key}=\"{$value}\"";
$value = "$key=\"$value\"";
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/php/Divi/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function verify( $return, $tag, $attr, $m ) {
if ( $current_form_fields ) {
$fields_data_json = htmlspecialchars_decode( str_replace( '\\', '', $current_form_fields ) );
$fields_data_array = json_decode( $fields_data_json, true );
$fields_data_array = null === $fields_data_array ? [] : $fields_data_array;
$fields_data_array = $fields_data_array ?? [];
$fields_data_array = array_filter(
$fields_data_array,
static function ( $item ) {
Expand Down
2 changes: 1 addition & 1 deletion src/php/ElementorPro/HCaptchaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function render_field( $item, $item_index, $widget ) {
$this->add_render_attributes( $item, $item_index, $widget );

$data = $widget->get_raw_data();
$form_id = isset( $data['settings']['form_id'] ) ? $data['settings']['form_id'] : 0;
$form_id = $data['settings']['form_id'] ?? 0;

$args = [
'id' => [
Expand Down
4 changes: 2 additions & 2 deletions src/php/FluentForm/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function verify( $errors, $data, $form, $fields ) {
return $errors;
}

$hcaptcha_response = isset( $data['h-captcha-response'] ) ? $data['h-captcha-response'] : '';
$_POST['hcaptcha-widget-id'] = isset( $data['hcaptcha-widget-id'] ) ? $data['hcaptcha-widget-id'] : '';
$hcaptcha_response = $data['h-captcha-response'] ?? '';
$_POST['hcaptcha-widget-id'] = $data['hcaptcha-widget-id'] ?? '';
$error_message = hcaptcha_request_verify( $hcaptcha_response );

if ( null !== $error_message ) {
Expand Down
1 change: 1 addition & 0 deletions src/php/FormidableForms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function add_captcha( $html, $field, $atts ) {
* @param array $post wp_unslash( $_POST ) content.
*
* @return bool
* @noinspection PhpUnusedParameterInspection
*/
public function prevent_native_validation( $is_field_hidden, $field, $post ) {
if ( 'captcha' !== $field->type ) {
Expand Down
2 changes: 1 addition & 1 deletion src/php/GravityForms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function add_captcha( $button_input, $form ) {
'auto' => true,
'id' => [
'source' => HCaptcha::get_class_source( __CLASS__ ),
'form_id' => isset( $form['id'] ) ? $form['id'] : 0,
'form_id' => $form['id'] ?? 0,
],
];

Expand Down
4 changes: 2 additions & 2 deletions src/php/Helpers/HCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public static function form_display( $args = [] ) {

if ( $args['id'] ) {
$id = (array) $args['id'];
$id['source'] = isset( $id['source'] ) ? (array) $id['source'] : [];
$id['form_id'] = isset( $id['form_id'] ) ? $id['form_id'] : 0;
$id['source'] = (array) ( $id['source'] ?? [] );
$id['form_id'] = $id['form_id'] ?? 0;

/**
* Filters the protection status of a form.
Expand Down
2 changes: 1 addition & 1 deletion src/php/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function init_hooks() {
*/
public function get( $class ) {

return isset( $this->loaded_classes[ $class ] ) ? $this->loaded_classes[ $class ] : null;
return $this->loaded_classes[ $class ] ?? null;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/php/Migrations/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ private function migrate_200() {

list( $new_option_key, $new_option_value ) = $new_option_name;

$new_options[ $new_option_key ] = isset( $new_options[ $new_option_key ] ) ?
$new_options[ $new_option_key ] :
[];
$new_options[ $new_option_key ] = $new_options[ $new_option_key ] ?? [];

if ( 'on' === $old_option ) {
$new_options[ $new_option_key ][] = $new_option_value;
Expand Down
2 changes: 1 addition & 1 deletion src/php/NF/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct() {
* @return null|string
*/
public function validate( $field, $data ) {
$value = isset( $field['value'] ) ? $field['value'] : '';
$value = $field['value'] ?? '';

return hcaptcha_request_verify( $value );
}
Expand Down
3 changes: 1 addition & 2 deletions src/php/PaidMembershipsPro/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
namespace HCaptcha\PaidMembershipsPro;

use HCaptcha\Helpers\HCaptcha;
use WP_Error;
use WP_User;

/**
* Class Checkout.
Expand Down Expand Up @@ -61,6 +59,7 @@ public function add_captcha() {
* Verify login form.
*
* @return void
* @noinspection PhpUndefinedFunctionInspection
*/
public function verify() {
global $pmpro_msg, $pmpro_msgt;
Expand Down
6 changes: 3 additions & 3 deletions src/php/Settings/Abstracts/SettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@ protected function get_names_from_referer() {
$args = $this->wp_parse_str( $query );

return [
'page' => isset( $args['page'] ) ? $args['page'] : null,
'tab' => isset( $args['tab'] ) ? $args['tab'] : null,
'page' => $args['page'] ?? null,
'tab' => $args['tab'] ?? null,
];
}

Expand Down Expand Up @@ -1033,7 +1033,7 @@ public function field_callback( array $arguments ) {
'table' => 'print_table_field',
];

$type = isset( $arguments['type'] ) ? $arguments['type'] : '';
$type = $arguments['type'] ?? '';

if ( ! array_key_exists( $type, $types ) ) {
return;
Expand Down
10 changes: 5 additions & 5 deletions src/php/Settings/Integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ public function sort_fields( $fields ) {
uasort(
$fields,
static function ( $a, $b ) {
$a_disabled = isset( $a['disabled'] ) ? $a['disabled'] : false;
$b_disabled = isset( $b['disabled'] ) ? $b['disabled'] : false;
$a_disabled = $a['disabled'] ?? false;
$b_disabled = $b['disabled'] ?? false;

$a_label = isset( $a['label'] ) ? strtolower( $a['label'] ) : '';
$b_label = isset( $b['label'] ) ? strtolower( $b['label'] ) : '';
$a_label = strtolower( $a['label'] ?? '' );
$b_label = strtolower( $b['label'] ?? '' );

if ( $a_disabled === $b_disabled ) {
return strcmp( $a_label, $b_label );
return $a_label <=> $b_label;
}

if ( ! $a_disabled && $b_disabled ) {
Expand Down
1 change: 1 addition & 0 deletions src/php/Subscriber/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function add_captcha( $content ) {
* @param bool $check_result Check result.
*
* @return bool|string
* @noinspection NullCoalescingOperatorCanBeUsedInspection
*/
public function verify( $check_result ) {
$error_message = hcaptcha_get_verify_message( self::NAME, self::ACTION );
Expand Down
3 changes: 0 additions & 3 deletions src/php/WPDiscuz/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

namespace HCaptcha\WPDiscuz;

use HCaptcha\Helpers\HCaptcha;
use WP_User;

/**
* Class Base.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/php/WPDiscuz/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ public function init_hooks() {
* @param WP_User|false $current_user Current user.
*
* @return string
* @noinspection PhpUnusedParameterInspection
*/
public function add_hcaptcha( $output, $comments_count, $current_user ) {
global $post;

$args = [
'id' => [
'source' => HCaptcha::get_class_source( static::class ),
'form_id' => $post ? $post->ID : 0,
'form_id' => $post->ID ?? 0,
],
];

Expand Down
3 changes: 1 addition & 2 deletions src/php/WPDiscuz/Subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace HCaptcha\WPDiscuz;

use HCaptcha\Helpers\HCaptcha;
use WP_User;

/**
* Class Subscribe.
Expand Down Expand Up @@ -39,7 +38,7 @@ public function add_hcaptcha() {
$args = [
'id' => [
'source' => HCaptcha::get_class_source( static::class ),
'form_id' => $post ? $post->ID : 0,
'form_id' => $post->ID ?? 0,
],
];

Expand Down
2 changes: 1 addition & 1 deletion src/php/includes/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function hcaptcha_request_verify( $hcaptcha_response ) {
$error_codes = [];

if ( ! isset( $body['success'] ) || true !== (bool) $body['success'] ) {
$error_codes = isset( $body['error-codes'] ) ? $body['error-codes'] : [ 'fail' ];
$error_codes = $body['error-codes'] ?? [ 'fail' ];
$result = isset( $body['error-codes'] ) ? hcap_get_error_message( $body['error-codes'] ) : $fail_message;
}

Expand Down

0 comments on commit c7a936c

Please sign in to comment.