Make WordPress Core

Changeset 33299


Ignore:
Timestamp:
07/16/2015 09:08:05 PM (9 years ago)
Author:
iseulde
Message:

Editor: word count: exclude shortcodes

Props desaiuditd, adamsilverstein, azaozz and iseulde.
Fixes #27386. See #30966.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/word-count.js

    r33292 r33299  
    11( function() {
    22    function WordCounter( settings ) {
    3         var key;
     3        var key,
     4            shortcodes;
    45
    56        if ( settings ) {
     
    910                }
    1011            }
     12        }
     13
     14        shortcodes = this.settings.l10n.shortcodes;
     15
     16        if ( shortcodes && shortcodes.length ) {
     17            this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'gi' );
    1118        }
    1219    }
     
    6673
    6774            text = text.replace( this.settings.HTMLRegExp, '\n' );
     75
     76            if ( this.settings.shortcodesRegExp ) {
     77                text = text.replace( this.settings.shortcodesRegExp, '\n' );
     78            }
     79
    6880            text = text.replace( this.settings.spaceRegExp, ' ' );
    6981
  • trunk/src/wp-includes/script-loader.php

    r33291 r33299  
    401401           enter 'characters', or 'all' to include spaces. Otherwise, enter 'words'.
    402402           Do not translate into your own language. */
    403         'type' => _x( 'words', 'word count: words, characters or all?' )
     403        'type' => _x( 'words', 'word count: words, characters or all?' ),
     404        'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array()
    404405    ) );
    405406
  • trunk/tests/qunit/wp-admin/js/word-count.js

    r33292 r33299  
    4545                characters: 14,
    4646                all: 14
     47            },
     48            {
     49                message: 'Shortcodes.',
     50                string: 'one [shortcode attribute="value"]two[/shortcode]three',
     51                words: 3,
     52                characters: 11,
     53                all: 12
    4754            }
    4855        ], function( test ) {
     
    5259        } );
    5360    } );
    54 } )( window.QUnit, new window.wp.utils.WordCounter() );
     61} )( window.QUnit, new window.wp.utils.WordCounter( {
     62    l10n: {
     63        shortcodes: [ 'shortcode' ]
     64    }
     65} ) );
Note: See TracChangeset for help on using the changeset viewer.