diff --git a/classes/helpers/FrmHtmlHelper.php b/classes/helpers/FrmHtmlHelper.php index f9f2e30189..f47d42fcff 100644 --- a/classes/helpers/FrmHtmlHelper.php +++ b/classes/helpers/FrmHtmlHelper.php @@ -119,7 +119,7 @@ public static function echo_unit_input( $args = array() ) { /> /> - $unit ) ); diff --git a/classes/views/dashboard/templates/notification-banner.php b/classes/views/dashboard/templates/notification-banner.php index 952732159d..3ba6b60fe5 100644 --- a/classes/views/dashboard/templates/notification-banner.php +++ b/classes/views/dashboard/templates/notification-banner.php @@ -10,11 +10,11 @@
-

🎉

-

+

🎉

+

- +
diff --git a/classes/views/form-templates/template.php b/classes/views/form-templates/template.php index 4479b853cf..18c52047dd 100644 --- a/classes/views/form-templates/template.php +++ b/classes/views/form-templates/template.php @@ -88,7 +88,7 @@ esc_html( date_i18n( get_option( 'date_format' ), strtotime( $template['created_at'] ) ) ) ); } else { - echo esc_html__( 'No description', 'formidable' ); + esc_html_e( 'No description', 'formidable' ); } ?>

diff --git a/classes/views/shared/errors.php b/classes/views/shared/errors.php index 9e5d7c89d3..979b12df21 100644 --- a/classes/views/shared/errors.php +++ b/classes/views/shared/errors.php @@ -48,7 +48,7 @@ if ( ! empty( $warnings ) && is_array( $warnings ) ) { ?>
- - + - + - + - + - + - + + value="" id="" /> - @@ -181,8 +181,8 @@
- - + + - diff --git a/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/PreferEscHtmlESniff.php b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/PreferEscHtmlESniff.php index 8ccae19009..f20499840b 100644 --- a/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/PreferEscHtmlESniff.php +++ b/phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/PreferEscHtmlESniff.php @@ -18,6 +18,8 @@ * - echo esc_attr( __( ... ) ) -> esc_attr_e( ... ) * - echo esc_html( _x( ... ) ) -> esc_html_x( ... ) * - echo esc_attr( _x( ... ) ) -> esc_attr_x( ... ) + * - echo esc_html__( ... ) -> esc_html_e( ... ) + * - echo esc_attr__( ... ) -> esc_attr_e( ... ) */ class PreferEscHtmlESniff implements Sniff { @@ -37,6 +39,16 @@ class PreferEscHtmlESniff implements Sniff { ), ); + /** + * Mapping of already combined functions that should drop echo entirely. + * + * @var array + */ + private $directReplacements = array( + 'esc_html__' => 'esc_html_e', + 'esc_attr__' => 'esc_attr_e', + ); + /** * Returns an array of tokens this test wants to listen for. * @@ -71,6 +83,11 @@ public function process( File $phpcsFile, $stackPtr ) { $escapeFunc = $tokens[ $nextToken ]['content']; + if ( isset( $this->directReplacements[ $escapeFunc ] ) ) { + $this->processDirectCombinedFunction( $phpcsFile, $stackPtr, $nextToken, $escapeFunc ); + return; + } + if ( ! isset( $this->replacements[ $escapeFunc ] ) ) { return; } @@ -144,17 +161,76 @@ public function process( File $phpcsFile, $stackPtr ) { ); if ( true === $fix ) { - $phpcsFile->fixer->beginChangeset(); + $this->replaceEchoWithCombinedFunction( $phpcsFile, $stackPtr, $semicolon, $replacementFunc, $translateArgs ); + } + } + + /** + * Handle echo statements that already use combined translation helpers. + * + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr Pointer to the echo token. + * @param int $functionPointer Pointer to the combined function token. + * @param string $functionName The function currently in use (e.g. esc_html__). + * + * @return void + */ + private function processDirectCombinedFunction( File $phpcsFile, $stackPtr, $functionPointer, $functionName ) { + $tokens = $phpcsFile->getTokens(); + + $openParen = $phpcsFile->findNext( T_WHITESPACE, $functionPointer + 1, null, true ); + + if ( false === $openParen || $tokens[ $openParen ]['code'] !== T_OPEN_PARENTHESIS ) { + return; + } + + if ( ! isset( $tokens[ $openParen ]['parenthesis_closer'] ) ) { + return; + } + + $closeParen = $tokens[ $openParen ]['parenthesis_closer']; + + $semicolon = $phpcsFile->findNext( T_WHITESPACE, $closeParen + 1, null, true ); + + if ( false === $semicolon || $tokens[ $semicolon ]['code'] !== T_SEMICOLON ) { + return; + } + + $args = $phpcsFile->getTokensAsString( $openParen + 1, $closeParen - $openParen - 1 ); + $replacementFunc = $this->directReplacements[ $functionName ]; + + $fix = $phpcsFile->addFixableError( + 'Use %s() instead of echo %s().', + $stackPtr, + 'PreferCombinedFunctionDirect', + array( $replacementFunc, $functionName ) + ); - // Remove everything from echo to the semicolon. - for ( $i = $stackPtr; $i <= $semicolon; $i++ ) { - $phpcsFile->fixer->replaceToken( $i, '' ); - } + if ( true === $fix ) { + $this->replaceEchoWithCombinedFunction( $phpcsFile, $stackPtr, $semicolon, $replacementFunc, $args ); + } + } - // Add the new combined function call. - $phpcsFile->fixer->addContent( $stackPtr, $replacementFunc . '( ' . trim( $translateArgs ) . ' );' ); + /** + * Replace an echo statement with the combined helper. + * + * @param File $phpcsFile The file being scanned. + * @param int $stackPtr Pointer to the echo token. + * @param int $semicolonPtr Pointer to the semicolon. + * @param string $replacement Function name to use. + * @param string $argumentString Function arguments as a string. + * + * @return void + */ + private function replaceEchoWithCombinedFunction( File $phpcsFile, $stackPtr, $semicolonPtr, $replacement, $argumentString ) { + $phpcsFile->fixer->beginChangeset(); - $phpcsFile->fixer->endChangeset(); + for ( $i = $stackPtr; $i <= $semicolonPtr; $i++ ) { + $phpcsFile->fixer->replaceToken( $i, '' ); } + + $phpcsFile->fixer->addContent( $stackPtr, $replacement . '( ' . trim( $argumentString ) . ' );' ); + + $phpcsFile->fixer->endChangeset(); } } diff --git a/stripe/views/payments/show.php b/stripe/views/payments/show.php index e2a1e69e5b..0dc525ae9b 100755 --- a/stripe/views/payments/show.php +++ b/stripe/views/payments/show.php @@ -170,7 +170,7 @@