diff --git a/classes/controllers/FrmStylesController.php b/classes/controllers/FrmStylesController.php index 003815daef..6bab715b99 100644 --- a/classes/controllers/FrmStylesController.php +++ b/classes/controllers/FrmStylesController.php @@ -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']; - ?> -
  • -

    - - -

    -
    -
    - -
    -
    -
  • - +
  • +

    + + +

    +
    +
    + +
    +
    +
  • + diff --git a/classes/models/FrmEmail.php b/classes/models/FrmEmail.php index 854869e0a8..6f9c713a50 100644 --- a/classes/models/FrmEmail.php +++ b/classes/models/FrmEmail.php @@ -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 } diff --git a/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/FlipForeachIfToContinueSniff.php b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/FlipForeachIfToContinueSniff.php index 27599c5b4f..a8024c8f55 100644 --- a/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/FlipForeachIfToContinueSniff.php +++ b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/FlipForeachIfToContinueSniff.php @@ -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 @@ -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 @@ -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. * @@ -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'] ) ) { @@ -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; }