public
Created

  • Download Gist
plugin.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
<?php
/**
* Plugin Name: My Plugin
* Plugin Description: http://core.trac.wordpress.org/ticket/10702
*/
 
class My_Plugin_Test_10702 {
public $cycles = 1000;
 
function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
 
function start() {
$this->start_time = microtime( true );
}
 
function stop() {
return ( microtime( true ) - $this->start_time );
}
 
function init() {
add_shortcode( 'foo', array( $this, 'shortcode_callback' ) );
add_shortcode( 'bar', array( $this, 'shortcode_callback' ) );
add_shortcode( 'baz', array( $this, 'shortcode_callback' ) );
 
// No shortcodes
$content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
 
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "no shortcodes: %f" . PHP_EOL, $this->stop() );
 
// Some shortcodes
$content = "Lorem [foo] ipsum dolor [bar] sit amet, consectetur adipisicing elit, [baz] sed do eiusmod tempor incididunt [foo] ut labore et dolore magna aliqua. [bar] Ut enim ad minim veniam, quis nostrud [baz] exercitation ullamco laboris nisi ut [foo arg='one'] aliquip ex ea commodo consequat. [bar arg='two'] Duis aute irure dolor in reprehenderit in voluptate velit [baz arg='three'] esse cillum dolore eu fugiat nulla pariatur. [foo arg='one'] Excepteur [/foo] sint [bar arg='two'] occaecat [/bar] cupidatat non proident, [baz arg='three'] sunt [/baz] in culpa qui officia deserunt mollit anim id est laborum.";
 
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "some shortcodes %f" . PHP_EOL, $this->stop() );
 
$content = str_repeat( $content, 10 );
 
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "10x shortcodes %f" . PHP_EOL, $this->stop() );
 
// Nested (old-style) shortcodes
$content = "Lorem [foo] ipsum dolor [bar] sit [/bar] amet [/foo], consectetur adipisicing elit, [baz] sed do [foo] eiusmod [bar] tempor [/bar] incididunt [/foo] ut labore [/baz] et dolore magna aliqua. [bar] Ut enim ad [foo] minim [/foo] veniam [/bar], quis nostrud [baz] exercitation [foo] ullamco [bar] laboris [/bar] nisi [/foo] ut [/baz] [foo arg='one'] aliquip [bar arg='two'] ex [/bar] ea commodo [/foo] consequat. [bar arg='two'] Duis aute irure dolor in reprehenderit in voluptate velit [baz arg='three'] esse cillum dolore [/baz] eu fugiat [/bar] nulla pariatur. [foo arg='one'] Excepteur [/foo] sint [bar arg='two'] occaecat [/bar] cupidatat non [foo arg='one'] proi [bar arg='two'] dent, [baz arg='three'] sunt [/baz] in [/bar] culpa qui [/foo] officia deserunt mollit anim id est laborum.";
 
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "nested shortcodes %f" . PHP_EOL, $this->stop() );
 
$content = str_repeat( $content, 10 );
 
$this->start();
for ( $i = 0; $i <= $this->cycles; $i++ )
do_shortcode( $content );
printf( "10x nested shortcodes %f" . PHP_EOL, $this->stop() );
 
die();
}
 
function shortcode_callback( $args, $content = '', $tag ) {
$arg = @$args['arg'];
return '<' . $tag . ' arg="' . esc_attr( $arg ) . '">' . do_shortcode( $content ) . '</' . $tag . ' arg="' . esc_attr( $arg ) . '">';
}
}
new My_Plugin_Test_10702;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.