Plugin Directory

Changeset 2221536


Ignore:
Timestamp:
01/03/2020 10:04:04 AM (6 years ago)
Author:
Magenta Cuda
Message:

version 1.2.2

Location:
shortcode-tester/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • shortcode-tester/trunk/js/mf2tk_macros_admin.js

    r2197070 r2221536  
    1414    });
    1515    // "Shortcode Tester" evaluate button
    16     divShortcode.find("button#mf2tk-shortcode-tester-evaluate,button#mf2tk-shortcode-tester-evaluate-and-prettify,button#mf2tk-shortcode-tester-show-rendered")
    17             .click(function(){
     16    divShortcode.find("button#mf2tk-shortcode-tester-evaluate,button#mf2tk-shortcode-tester-evaluate-and-prettify,"
     17            +"button#mf2tk-shortcode-tester-show-rendered,button#mf2tk-shortcode-tester-alt-show-rendered").click(function(){
    1818        var permalink=jQuery("#sample-permalink a");
    1919        if(!permalink.length){
     
    4242        var punc=url.indexOf("?")===-1?"?":"&";
    4343        var source=jQuery("div#mf2tk-shortcode-tester div#mf2tk-shortcode-tester-area-source textarea").val();
    44         if(this.id==="mf2tk-shortcode-tester-show-rendered"){
     44        if(this.id==="mf2tk-shortcode-tester-show-rendered"||this.id==="mf2tk-shortcode-tester-alt-show-rendered"){
    4545            var width=640;
    4646            var height=480;
     
    4949            var features="left="+left+",top="+top+",width="+width+",height="+height+",location=0,resizable,scrollbars,menubar=0";
    5050            url+=punc+"mc-sct=tpcti_html_eval_post_content&post_content="+encodeURI(source);
     51            if(this.id==="mf2tk-shortcode-tester-alt-show-rendered"){
     52                url+="&theme_scripts=nullify";
     53            }
    5154            window.open(url,"mc-sct-rendered",features);
    5255            return;
  • shortcode-tester/trunk/readme.txt

    r2197070 r2221536  
    55Requires at least: 3.6
    66Tested up to: 5.3
    7 Stable tag: 1.2.1
     7Stable tag: 1.2.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2525In addition to the HTML elements emitted by the PHP code for the shortcode, the shortcode may have JavaScript code to dynamically emit additional HTML elements. The shortcode tester hides non shortcode HTML elements by setting the CSS display property to none and changing the element id. These changes may affect the execution of the shortcode's JavaScript code.
    2626
     27= "Show Rendered" vs "Alt Show Rendered" =
     28
     29"Show Rendered" allows all JavaScript code to execute. Unfortunately, the shortcode tester hides non shortcode HTML elements and this may cause some JavaScript code to abort which prevents the execution of the shortcode's JavaScript code. "Alt Show Rendered" suppresses the execution of the theme's JavaScript code and this may allow the shortcode's JavaScript code to execute.
     30
     31= Does "Show Rendered" require that the shortcode have support for Gutenberg blocks? =
     32
     33No. "Show Rendered" does not use Gutenberg blocks. It uses the WordPress server to render the shortcode as it would when the page is requested from the browser and tries to skip rendering everything but the shortcode. In particular, it will work with old plugins that do not have support for Gutenberg blocks.
     34
    2735== Screenshots ==
    28361. The Shortcode Tester
    2937
    3038== Changelog ==
     39
     40= 1.2.2 =
     41* added "Alt Show Rendered" button which prevent the theme's scripts from running
    3142
    3243= 1.2.1 =
     
    5970== Upgrade Notice ==
    6071
     72= 1.2.2 =
     73* added "Alt Show Rendered" button which prevent the theme's scripts from running
     74
    6175= 1.2.1 =
    6276* fix problem with non permalink URL's
  • shortcode-tester/trunk/shortcode-tester-loader.php

    r2197070 r2221536  
    55Plugin URI:  https://github.com/magenta-cuda/shortcode-tester
    66Description: a simple shortcode tester
    7 Version:     1.2.1
     7Version:     1.2.2
    88Author:      Magenta Cuda
    99Author URI:  https://github.com/magenta-cuda
  • shortcode-tester/trunk/shortcode-tester.php

    r2197070 r2221536  
    137137        <button id="mf2tk-shortcode-tester-show-both" class="mf2tk-shortcode-tester-button">Show Both</button>
    138138        <button id="mf2tk-shortcode-tester-show-rendered" class="mf2tk-shortcode-tester-button">Show Rendered</button>
     139        <button id="mf2tk-shortcode-tester-alt-show-rendered" class="mf2tk-shortcode-tester-button" title="Please try this if 'Show Rendered' does not work.">
     140            Alt Show Rendered
     141        </button>
    139142    </div>
    140143    <div class="sct_ix-shortcode_tester_input_output">
     
    265268                $offset = $gt_offset;
    266269            }
    267             if ( $marked === FALSE && ! in_array( $name, [ 'script' ] ) ) {
    268                 # Add element to list of elements to hide.
    269                 # error_log( 'hide_html_elements():Element to hide = "' . substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset ) . '"' );
    270                 $elements[ ] = (object) [ 'name' => $name, 'left' => $left_offset, 'right' => $gt_offset ];
     270            if ( $marked === FALSE ) {
     271                $op = FALSE;
     272                if ( $name === 'script' ) {
     273                    # error_log( 'hide_html_elements():<script> = "' . substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset ) . '"' );
     274                    if ( array_key_exists( 'theme_scripts', $_REQUEST ) && $_REQUEST['theme_scripts'] === 'nullify' ) {
     275                        $tag = substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset );
     276                        if ( preg_match( '#src=("|\')([^\1]+?)\1#', $tag, $matches ) === 1 ) {
     277                            # error_log( 'hide_html_elements():src = "' . $matches[2] );
     278                            if ( strpos( $matches[2], '/wp-content/themes/' ) !== FALSE ) {
     279                                # error_log( 'hide_html_elements():theme <script> = "' . substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset ) . '"' );
     280                                $op = 'nullify-script';
     281                            }
     282                        }
     283                    }
     284                } else {
     285                    $op = 'hide';
     286                }
     287                if ( $op !== FALSE ) {
     288                    # Add element to list of elements to hide or nullify.
     289                    # error_log( 'hide_html_elements():Element to hide = "' . substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset ) . '"' );
     290                    $elements[ ] = (object) [ 'op' => $op, 'name' => $name, 'left' => $left_offset, 'right' => $gt_offset ];
     291                }
    271292            }
    272293            $start = $offset + 1;
     
    281302            # error_log( 'hide_html_elements():$name=' . $element->name );
    282303            # error_log( 'hide_html_elements():tag=' . substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ) );
    283             if ( ( $style_offset = strpos( substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ), 'style=' ) ) === FALSE ) {
    284                 $buffer = substr_replace( $buffer, ' style="display:none;"', $element->right, 0 );
    285             } else {
    286                 # Element already has an inline style attribute.
    287                 // TODO:
    288                 $buffer = substr_replace( $buffer, ' style="display:none;"', $element->right, 0 );
    289             }
    290             # JavaScript can make visible elements that we have hidden. Changing an element's id may defeat this.
    291             if ( ( $id_offset = strpos( substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ), 'id=' ) ) !== FALSE ) {
    292                 $buffer = substr_replace( $buffer, 'xxx-', $element->left + $id_offset + 4, 0 );
     304            if ( $element->op === 'hide' ) {
     305                if ( ( $style_offset = strpos( substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ), 'style=' ) ) === FALSE ) {
     306                    $buffer = substr_replace( $buffer, ' style="display:none;"', $element->right, 0 );
     307                } else {
     308                    # Element already has an inline style attribute.
     309                    // TODO:
     310                    $buffer = substr_replace( $buffer, ' style="display:none;"', $element->right, 0 );
     311                }
     312                # JavaScript can make visible elements that we have hidden. Changing an element's id may defeat this.
     313                if ( ( $id_offset = strpos( substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ), 'id=' ) ) !== FALSE ) {
     314                    $buffer = substr_replace( $buffer, 'xxx-', $element->left + $id_offset + 4, 0 );
     315                }
     316            } else if ( $element->op === 'nullify-script' ) {
     317                # Prevent script from loading.
     318                $buffer = substr_replace( $buffer, '<script>/* Nullified by shortcode-tester. */', $element->left, ( $element->right + 1 ) - $element->left );
    293319            }
    294320        }
Note: See TracChangeset for help on using the changeset viewer.