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
75 changes: 39 additions & 36 deletions classes/controllers/FrmStylesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1369,42 +1369,45 @@ public static function do_accordion_sections( $screen, $context, $data_object )

if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
if ( false === $box || ! $box['title'] ) {
continue;
}

++$i;
$icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
$open_class = '';

if ( ! $first_open ) {
$first_open = true;
$open_class = 'open';
}

$accordion_content_id = 'frm_style_section_' . $box['id'];
?>
<li class="control-section accordion-section <?php echo esc_attr( $open_class ); ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
<h3 class="accordion-section-title hndle">
<?php
FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
echo esc_html( $box['title'] );
?>
<button type="button" aria-expanded="<?php echo esc_attr( 'open' === $open_class ? 'true' : 'false' ); ?>" aria-controls="<?php echo esc_attr( $accordion_content_id ); ?>" aria-label="<?php echo esc_attr( $box['title'] ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
<?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
</button>
</h3>
<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
<div class="inside">
<?php call_user_func( $box['callback'], $data_object, $box ); ?>
</div><!-- .inside -->
</div><!-- .accordion-section-content -->
</li><!-- .accordion-section -->
<?php
}//end foreach
}//end if
if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
continue;
}

foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
if ( false === $box || ! $box['title'] ) {
continue;
}

++$i;
$icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
$open_class = '';

if ( ! $first_open ) {
$first_open = true;
$open_class = 'open';
}

$accordion_content_id = 'frm_style_section_' . $box['id'];
?>
<li class="control-section accordion-section <?php echo esc_attr( $open_class ); ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
<h3 class="accordion-section-title hndle">
<?php
FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
echo esc_html( $box['title'] );
?>
<button type="button" aria-expanded="<?php echo esc_attr( 'open' === $open_class ? 'true' : 'false' ); ?>" aria-controls="<?php echo esc_attr( $accordion_content_id ); ?>" aria-label="<?php echo esc_attr( $box['title'] ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
<?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
</button>
</h3>
<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
<div class="inside">
<?php call_user_func( $box['callback'], $data_object, $box ); ?>
</div><!-- .inside -->
</div><!-- .accordion-section-content -->
</li><!-- .accordion-section -->
<?php
}//end foreach
// end if
}//end foreach
}//end if
?>
Expand Down
53 changes: 28 additions & 25 deletions classes/models/FrmEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,31 +826,34 @@ private function format_from_email( $name, $email ) {
*/
private function handle_phone_numbers() {
foreach ( $this->to as $key => $recipient ) {
if ( '[admin_email]' !== $recipient && ! is_email( $recipient ) ) {
$recipient = explode( ' ', $recipient );

if ( is_email( end( $recipient ) ) ) {
continue;
}

do_action(
'frm_send_to_not_email',
array(
'e' => $recipient,
'subject' => $this->subject,
'mail_body' => $this->message,
'reply_to' => $this->reply_to,
'from' => $this->from,
'plain_text' => $this->is_plain_text,
'attachments' => $this->attachments,
'form' => $this->form,
'email_key' => $key,
)
);

// Remove phone number from to addresses
unset( $this->to[ $key ] );
}//end if
if ( '[admin_email]' === $recipient || is_email( $recipient ) ) {
continue;
}

$recipient = explode( ' ', $recipient );

if ( is_email( end( $recipient ) ) ) {
continue;
}

do_action(
'frm_send_to_not_email',
array(
'e' => $recipient,
'subject' => $this->subject,
'mail_body' => $this->message,
'reply_to' => $this->reply_to,
'from' => $this->from,
'plain_text' => $this->is_plain_text,
'attachments' => $this->attachments,
'form' => $this->form,
'email_key' => $key,
)
);

// Remove phone number from to addresses
unset( $this->to[ $key ] );
// end if
}//end foreach
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ public function process( File $phpcsFile, $stackPtr ) {
$scopeOpener = $tokens[ $stackPtr ]['scope_opener'];
$scopeCloser = $tokens[ $stackPtr ]['scope_closer'];

// Find the first non-whitespace token inside the foreach.
// Find the first non-whitespace, non-comment token inside the foreach.
$skipTokens = array( T_WHITESPACE, T_COMMENT, T_DOC_COMMENT, T_DOC_COMMENT_OPEN_TAG, T_DOC_COMMENT_STAR, T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STRING, T_DOC_COMMENT_CLOSE_TAG );
$firstStatement = $phpcsFile->findNext(
T_WHITESPACE,
$skipTokens,
$scopeOpener + 1,
$scopeCloser,
true
Expand Down Expand Up @@ -103,9 +104,9 @@ public function process( File $phpcsFile, $stackPtr ) {

$ifScopeCloser = $tokens[ $ifToken ]['scope_closer'];

// Check if the if statement is the only thing in the foreach body.
// Check if the if statement is the only thing in the foreach body (skip comments).
$afterIf = $phpcsFile->findNext(
T_WHITESPACE,
$skipTokens,
$ifScopeCloser + 1,
null,
true
Expand Down Expand Up @@ -398,6 +399,9 @@ private function getIndentation( File $phpcsFile, $stackPtr ) {
/**
* Count the number of statements inside a scope.
*
* If the scope contains only a single loop, count the statements inside that loop instead.
* This handles cases like: if ($condition) { foreach ($items as $item) { ...many statements... } }
*
* @param File $phpcsFile The file being scanned.
* @param int $scopeToken The token with the scope to count.
*
Expand All @@ -416,18 +420,32 @@ private function countStatementsInScope( File $phpcsFile, $scopeToken ) {
// The target level is the level inside the scope (opener level + 1).
$targetLevel = $tokens[ $scopeOpener ]['level'] + 1;

$count = 0;
$count = 0;
$singleLoopToken = null;
$topLevelStatements = 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;
++$topLevelStatements;
}

// 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;
++$topLevelStatements;

// Track if this is a single loop.
if ( in_array( $tokens[ $i ]['code'], array( T_FOREACH, T_FOR, T_WHILE ), true ) ) {
if ( null === $singleLoopToken ) {
$singleLoopToken = $i;
} else {
// More than one loop, don't use this optimization.
$singleLoopToken = false;
}
}

// Skip to the end of this control structure.
if ( isset( $tokens[ $i ]['scope_closer'] ) ) {
Expand All @@ -437,6 +455,12 @@ private function countStatementsInScope( File $phpcsFile, $scopeToken ) {
}
}

// If the if body contains only a single loop, count the statements inside that loop.
// This handles: if ($condition) { foreach ($items as $item) { /* many statements */ } }
if ( 1 === $topLevelStatements && null !== $singleLoopToken && false !== $singleLoopToken ) {
return $this->countStatementsInScope( $phpcsFile, $singleLoopToken );
}

return $count;
}

Expand Down
Loading