Skip to content
Merged
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
26 changes: 14 additions & 12 deletions classes/controllers/FrmFormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1062,19 +1062,21 @@ public static function get_modal_values() {
* @return void
*/
public static function insert_form_button() {
if ( current_user_can( 'frm_view_forms' ) ) {
// Store the result in memory and re-use it when this function is called multiple times.
// This helps speed up the form builder when there are a lot of HTML fields, where this
// button is inserted once per HTML field.
// In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
if ( ! isset( self::$formidable_tinymce_button ) ) {
FrmAppHelper::load_admin_wide_js();
$menu_name = FrmAppHelper::get_menu_name();
$icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
self::$formidable_tinymce_button = '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' . FrmAppHelper::kses( $icon, 'all' ) . ' ' . esc_html( $menu_name ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
}
echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ( ! current_user_can( 'frm_view_forms' ) ) {
return;
}

// Store the result in memory and re-use it when this function is called multiple times.
// This helps speed up the form builder when there are a lot of HTML fields, where this
// button is inserted once per HTML field.
// In a form with 66 HTML fields, this saves 0.5 seconds on page load time, tested locally.
if ( ! isset( self::$formidable_tinymce_button ) ) {
FrmAppHelper::load_admin_wide_js();
$menu_name = FrmAppHelper::get_menu_name();
$icon = apply_filters( 'frm_media_icon', FrmAppHelper::svg_logo() );
self::$formidable_tinymce_button = '<a href="#TB_inline?width=50&height=50&inlineId=frm_insert_form" class="thickbox button add_media frm_insert_form" title="' . esc_attr__( 'Add forms and content', 'formidable' ) . '">' . FrmAppHelper::kses( $icon, 'all' ) . ' ' . esc_html( $menu_name ) . '</a>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
}
echo self::$formidable_tinymce_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

/**
Expand Down
38 changes: 20 additions & 18 deletions classes/models/FrmInstallerSkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,27 @@ public function footer() {}
* @param string|\WP_Error $errors The WP Error object of errors with the install process.
*/
public function error( $errors ) {
if ( $errors ) {
if ( ! is_string( $errors ) ) {
$error = $errors->get_error_message();
$message = $errors->get_error_data();
$errors = $error . ' ' . $message;
}
echo json_encode(
array(
'error' => $errors,
'message' => $errors,
'success' => false,
)
);
if ( ! $errors ) {
return;
}

if ( ! is_string( $errors ) ) {
$error = $errors->get_error_message();
$message = $errors->get_error_data();
$errors = $error . ' ' . $message;
}
echo json_encode(
array(
'error' => $errors,
'message' => $errors,
'success' => false,
)
);

if ( wp_doing_ajax() ) {
wp_die();
} else {
die();
}
if ( wp_doing_ajax() ) {
wp_die();
} else {
die();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private function hasElseOrElseif( File $phpcsFile, $ifToken ) {
}

/**
* Count the number of statements inside a scope.
* Count the number of statements inside a scope (recursively).
*
* @param File $phpcsFile The file being scanned.
* @param int $scopeToken The token with the scope to count.
Expand All @@ -398,28 +398,13 @@ private function countStatementsInScope( File $phpcsFile, $scopeToken ) {
$scopeOpener = $tokens[ $scopeToken ]['scope_opener'];
$scopeCloser = $tokens[ $scopeToken ]['scope_closer'];

// The target level is the level inside the scope (opener level + 1).
$targetLevel = $tokens[ $scopeOpener ]['level'] + 1;

$count = 0;

for ( $i = $scopeOpener + 1; $i < $scopeCloser; $i++ ) {
// Only count semicolons at the immediate scope level (not nested).
if ( $tokens[ $i ]['code'] === T_SEMICOLON && $tokens[ $i ]['level'] === $targetLevel ) {
// Count all semicolons (statements) at any nesting level.
if ( $tokens[ $i ]['code'] === T_SEMICOLON ) {
++$count;
}

// Also count control structures as statements.
if ( in_array( $tokens[ $i ]['code'], array( T_IF, T_FOREACH, T_FOR, T_WHILE, T_SWITCH, T_TRY ), true ) ) {
if ( $tokens[ $i ]['level'] === $targetLevel ) {
++$count;

// Skip to the end of this control structure.
if ( isset( $tokens[ $i ]['scope_closer'] ) ) {
$i = $tokens[ $i ]['scope_closer'];
}
}
}
}

return $count;
Expand Down