Skip to content

Commit 9a7f2d1

Browse files
committed
Merge master
2 parents b491da7 + c94f880 commit 9a7f2d1

File tree

241 files changed

+4863
-6751
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+4863
-6751
lines changed

.eslintrc.json

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"plugin:sonarjs/recommended",
2020
"plugin:cypress/recommended",
2121
"plugin:no-jquery/deprecated",
22-
"plugin:compat/recommended"
22+
"plugin:compat/recommended",
23+
"plugin:unicorn/all"
2324
],
2425
"env": {
2526
"browser": true,
@@ -34,7 +35,7 @@
3435
"window": true,
3536
"document": true
3637
},
37-
"plugins": ["react", "jsx-a11y", "sonarjs", "cypress", "no-jquery", "compat", "jsdoc"],
38+
"plugins": ["react", "jsx-a11y", "sonarjs", "cypress", "no-jquery", "compat", "jsdoc", "unicorn"],
3839
"settings": {
3940
"import/resolver": {
4041
"webpack": {
@@ -149,7 +150,56 @@
149150
"no-jquery/no-when": "error",
150151
"react/jsx-no-target-blank": "off",
151152
"comma-dangle": "off",
152-
"arrow-parens": ["error", "as-needed"]
153+
"arrow-parens": ["error", "as-needed"],
154+
"unicorn/filename-case": "off",
155+
"unicorn/prefer-query-selector": "off",
156+
"unicorn/no-null": "off",
157+
"unicorn/prefer-module": "off",
158+
"unicorn/explicit-length-check": "off",
159+
"unicorn/better-regex": "off",
160+
"unicorn/no-keyword-prefix": "off",
161+
"unicorn/no-array-for-each": "off",
162+
"unicorn/prevent-abbreviations": "off",
163+
"unicorn/no-this-assignment": "off",
164+
"unicorn/no-document-cookie": "off",
165+
"unicorn/prefer-number-properties": "off",
166+
"unicorn/prefer-spread": "off",
167+
"unicorn/consistent-function-scoping": "off",
168+
"unicorn/prefer-export-from": "off",
169+
"unicorn/no-array-callback-reference": "off",
170+
"unicorn/prefer-ternary": "off",
171+
"unicorn/no-for-loop": "off",
172+
"unicorn/no-array-reduce": "off",
173+
"unicorn/prefer-at": "off",
174+
"unicorn/consistent-destructuring": "off",
175+
"unicorn/prefer-string-slice": "off",
176+
"unicorn/catch-error-name": "off",
177+
"unicorn/no-static-only-class": "off",
178+
"unicorn/prefer-optional-catch-binding": "off",
179+
"unicorn/no-lonely-if": "off",
180+
"unicorn/prefer-set-has": "off",
181+
"unicorn/prefer-switch": "off",
182+
"unicorn/no-useless-switch-case": "off",
183+
"unicorn/prefer-prototype-methods": "off",
184+
// Fix this soon
185+
"unicorn/prefer-dom-node-dataset": "off",
186+
// Look more into this one.
187+
"unicorn/numeric-separators-style": "off",
188+
// Look into this
189+
"unicorn/no-unsafe-regex": "off",
190+
// Consider this one.
191+
"unicorn/prefer-regexp-test": "off",
192+
"unicorn/prefer-logical-operator-over-ternary": "off",
193+
// Maybe fix
194+
"unicorn/prefer-dom-node-text-content": "off",
195+
"unicorn/empty-brace-spaces": "off",
196+
// Probably fix
197+
"unicorn/no-array-push-push": "off",
198+
"unicorn/prefer-array-find": "off",
199+
"unicorn/prefer-add-event-listener": "off",
200+
"unicorn/text-encoding-identifier-case": "off",
201+
"unicorn/prefer-string-replace-all": "off",
202+
"unicorn/no-useless-promise-resolve-reject": "off"
153203
},
154204
"overrides": [
155205
{
@@ -165,7 +215,14 @@
165215
"no-jquery/no-prop": "error",
166216
"no-jquery/no-filter": "error",
167217
"no-jquery/no-data": "error",
168-
"no-jquery/no-parents": "error"
218+
"no-jquery/no-parents": "error",
219+
"no-jquery/no-val": "error",
220+
"no-jquery/no-serialize": "error",
221+
"no-jquery/no-class": "error",
222+
"no-jquery/no-closest": "error",
223+
"no-jquery/no-ajax": "error",
224+
"no-jquery/no-fade": "error",
225+
"no-jquery/no-is": "error"
169226
}
170227
}
171228
]

.php-cs-fixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'no_whitespace_in_blank_line' => true,
2626
'ternary_to_null_coalescing' => true,
2727
'no_null_property_initialization' => true,
28+
'return_assignment' => true,
2829
'blank_line_before_statement' => array(
2930
'statements' => array(
3031
'try',

bin/zip-plugin.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ zip -r $zipname $destination \
5151
-x "*/.wordpress-org/*" \
5252
-x "*/.wp-env.json" \
5353
-x "*/.prettierrc" \
54+
-x "*/.scannerwork" \
5455
-x "*/.jscsrc" \
5556
-x "*/.jshintrc" \
5657
-x "*/.jshintignore" \

classes/controllers/FrmAddonsController.php

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,8 @@ protected static function set_categories( &$addon ) {
267267
public static function license_settings() {
268268
$plugins = apply_filters( 'frm_installed_addons', array() );
269269

270-
if ( empty( $plugins ) ) {
270+
if ( ! $plugins ) {
271271
esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
272-
273272
return;
274273
}
275274

@@ -285,7 +284,7 @@ protected static function get_api_addons() {
285284
$api = new FrmFormApi();
286285
$addons = $api->get_api_info();
287286

288-
if ( empty( $addons ) ) {
287+
if ( ! $addons ) {
289288
$addons = self::fallback_plugin_list();
290289
} else {
291290
foreach ( $addons as $k => $addon ) {
@@ -307,7 +306,6 @@ protected static function get_api_addons() {
307306
*/
308307
public static function get_addons_count() {
309308
$addons = self::get_api_addons();
310-
311309
return count( $addons );
312310
}
313311

@@ -407,6 +405,7 @@ protected static function fallback_plugin_list() {
407405
$info['slug'] = $k;
408406
$list[ $k ] = array_merge( $defaults, $info );
409407
}
408+
410409
return $list;
411410
}
412411

@@ -447,14 +446,15 @@ public static function get_pro_license() {
447446

448447
$license = $creds['license'];
449448

450-
if ( empty( $license ) ) {
449+
if ( ! $license ) {
451450
return '';
452451
}
453452

454-
if ( strpos( $license, '-' ) ) {
453+
if ( str_contains( $license, '-' ) ) {
455454
// this is a fix for licenses saved in the past
456455
$license = strtoupper( $license );
457456
}
457+
458458
return $license;
459459
}
460460

@@ -496,7 +496,7 @@ public static function is_license_expired() {
496496

497497
$expires = $version_info['error']['expires'] ?? 0;
498498

499-
if ( empty( $expires ) || $expires > time() ) {
499+
if ( ! $expires || $expires > time() ) {
500500
return false;
501501
}
502502

@@ -519,7 +519,7 @@ public static function is_license_expired() {
519519
public static function get_primary_license_info() {
520520
$installed_addons = apply_filters( 'frm_installed_addons', array() );
521521

522-
if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
522+
if ( ! $installed_addons || ! isset( $installed_addons['formidable_pro'] ) ) {
523523
return false;
524524
}
525525

@@ -549,7 +549,7 @@ public static function check_update( $transient ) {
549549

550550
$installed_addons = apply_filters( 'frm_installed_addons', array() );
551551

552-
if ( empty( $installed_addons ) ) {
552+
if ( ! $installed_addons ) {
553553
return $transient;
554554
}
555555

@@ -566,7 +566,7 @@ public static function check_update( $transient ) {
566566

567567
$folder = $plugin->plugin;
568568

569-
if ( empty( $folder ) ) {
569+
if ( ! $folder ) {
570570
continue;
571571
}
572572

@@ -641,13 +641,12 @@ protected static function fill_update_addon_info( $installed_addons ) {
641641

642642
$new_license = $addon->license;
643643

644-
if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) {
644+
if ( ! $new_license || in_array( $new_license, $checked_licenses, true ) ) {
645645
continue;
646646
}
647647

648648
$checked_licenses[] = $new_license;
649-
650-
$api = new FrmFormApi( $new_license );
649+
$api = new FrmFormApi( $new_license );
651650

652651
if ( empty( $version_info ) ) {
653652
$version_info = $api->get_api_info();
@@ -656,13 +655,13 @@ protected static function fill_update_addon_info( $installed_addons ) {
656655

657656
$plugin = $api->get_addon_for_license( $addon, $version_info );
658657

659-
if ( empty( $plugin ) ) {
658+
if ( ! $plugin ) {
660659
continue;
661660
}
662661

663662
$download_id = $plugin['id'] ?? 0;
664663

665-
if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) {
664+
if ( $download_id && ! isset( $version_info[ $download_id ]['package'] ) ) {
666665
// if this addon is using its own license, get the update url
667666
$addon_info = $api->get_api_info();
668667

@@ -710,7 +709,7 @@ public static function install_link( $plugin ) {
710709
);
711710
}
712711

713-
if ( ! empty( $link ) ) {
712+
if ( $link ) {
714713
$link['status'] = $addon['status']['type'];
715714
}
716715
} elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) {
@@ -741,6 +740,7 @@ public static function get_addon( $plugin ) {
741740
return $addon;
742741
}
743742
}
743+
744744
return false;
745745
}
746746

@@ -756,6 +756,7 @@ protected static function get_license_type() {
756756
if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) {
757757
$license_type = $addons['error']['type'];
758758
}
759+
759760
return $license_type;
760761
}
761762

@@ -771,7 +772,7 @@ public static function get_addon_for_license( $addons, $license ) {
771772
$download_id = $license->download_id;
772773
$plugin = array();
773774

774-
if ( empty( $download_id ) && ! empty( $addons ) ) {
775+
if ( ! $download_id && ! empty( $addons ) ) {
775776
foreach ( $addons as $addon ) {
776777
if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) {
777778
return $addon;
@@ -790,6 +791,9 @@ public static function get_addon_for_license( $addons, $license ) {
790791
* @return void
791792
*/
792793
protected static function prepare_addons( &$addons ) {
794+
// Reset categories to prevent count accumulation across multiple calls.
795+
self::$categories = array();
796+
793797
$activate_url = '';
794798

795799
if ( current_user_can( 'activate_plugins' ) ) {
@@ -803,10 +807,8 @@ protected static function prepare_addons( &$addons ) {
803807
$slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
804808
$file_name = $addon['plugin'];
805809
} else {
806-
$slug = $id;
807-
810+
$slug = $id;
808811
$base_file = $addon['file'] ?? 'formidable-' . $slug;
809-
810812
$file_name = $base_file . '/' . $base_file . '.php';
811813

812814
if ( ! isset( $addon['plugin'] ) ) {
@@ -826,7 +828,7 @@ protected static function prepare_addons( &$addons ) {
826828

827829
$addon['activate_url'] = '';
828830

829-
if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) {
831+
if ( $addon['installed'] && $activate_url && ! self::is_plugin_active( $file_name, $slug ) ) {
830832
$addon['activate_url'] = add_query_arg(
831833
array(
832834
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
@@ -984,11 +986,7 @@ protected static function uninstall_plugin( $plugin ) {
984986
self::deactivate_plugin( $plugin, true );
985987
$result = delete_plugins( array( $plugin ) );
986988

987-
if ( is_wp_error( $result ) ) {
988-
return $result;
989-
}
990-
991-
return true;
989+
return is_wp_error( $result ) ? $result : true;
992990
}
993991

994992
/**
@@ -1112,6 +1110,7 @@ protected static function install_addon() {
11121110
'success' => false,
11131111
);
11141112
}
1113+
11151114
return $plugin;
11161115
}
11171116

@@ -1229,6 +1228,7 @@ protected static function handle_addon_action( $installed, $action ) {
12291228
if ( wp_doing_ajax() ) {
12301229
wp_send_json_error( array( 'error' => $result->get_error_message() ) );
12311230
}
1231+
12321232
return array(
12331233
'message' => $result->get_error_message(),
12341234
'success' => false,
@@ -1244,8 +1244,7 @@ protected static function handle_addon_action( $installed, $action ) {
12441244
*/
12451245
private static function get_addon_activation_response() {
12461246
$activating_page = self::get_activating_page();
1247-
1248-
$message = $activating_page ? __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ) : __( 'Your plugin has been activated.', 'formidable' );
1247+
$message = $activating_page ? __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ) : __( 'Your plugin has been activated.', 'formidable' );
12491248

12501249
return array(
12511250
'message' => $message,
@@ -1266,11 +1265,7 @@ private static function get_activating_page() {
12661265
return 'settings';
12671266
}
12681267

1269-
if ( str_contains( $referer, 'frm_action=edit' ) ) {
1270-
return 'form_builder';
1271-
}
1272-
1273-
return '';
1268+
return str_contains( $referer, 'frm_action=edit' ) ? 'form_builder' : '';
12741269
}
12751270

12761271
/**
@@ -1297,7 +1292,7 @@ protected static function install_addon_permissions() {
12971292
public static function connect_link() {
12981293
$auth = get_option( 'frm_connect_token' );
12991294

1300-
if ( empty( $auth ) ) {
1295+
if ( ! $auth ) {
13011296
$auth = hash( 'sha512', wp_rand() );
13021297
update_option( 'frm_connect_token', $auth, 'no' );
13031298
}
@@ -1331,15 +1326,15 @@ public static function can_install_addon_api() {
13311326

13321327
// The download link is not required if already installed.
13331328
$is_installed = FrmAppHelper::pro_is_included();
1334-
$file_missing = ! $is_installed && empty( $post_url );
1329+
$file_missing = ! $is_installed && ! $post_url;
13351330

13361331
if ( ! $post_auth || $file_missing ) {
13371332
return false;
13381333
}
13391334

13401335
// Verify auth.
13411336
$auth = get_option( 'frm_connect_token' );
1342-
return ! empty( $auth ) && hash_equals( $auth, $post_auth );
1337+
return $auth && hash_equals( $auth, $post_auth );
13431338
}
13441339

13451340
/**
@@ -1550,7 +1545,6 @@ private static function allowed_external_urls() {
15501545

15511546
if ( ! is_array( $allowed_url_list ) ) {
15521547
_doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' );
1553-
15541548
return array();
15551549
}
15561550

0 commit comments

Comments
 (0)