Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active October 7, 2015 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/b4640cbf4d71bc84933f to your computer and use it in GitHub Desktop.
Save westonruter/b4640cbf4d71bc84933f to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z "$CURL_COOKIES" ]; then
echo "Define a CURL_COOKIES environment variable containing the auth cookies for curl"
echo "For example, invoke via:"
echo "CURL_COOKIES='wordpress_test_cookie=WP+Cookie+check; wordpress_logged_in_abc123=...' $0"
exit 1
fi
if [ -z "$CURL_NONCE" ]; then
echo "Define a CURL_NONCE environment variable containing the nonce for the Customizer prevew"
echo "For example, invoke via:"
echo "CURL_NONCE='abc123' $0"
exit 1
fi
make_dirty=false
ensure_option_added=false
while [[ $# > 0 ]]; do
key="$1"
case $key in
--make_dirty|--make-dirty|--dirty)
make_dirty=true
;;
--ensure_option_added|--ensure-option-added|--add_option|add-option)
ensure_option_added=true
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
echo "add_option:$ensure_option_added, dirty:$make_dirty" 1>&2
TIMEFORMAT=%R
for i in $( seq 0 20 ); do
setting_count=$( expr $i \* 50 );
url="http://src.wordpress-develop.dev/?setting_count=$setting_count"
if [[ true == $make_dirty ]]; then
url="$url&make_dirty=true"
fi
if [[ true == $ensure_option_added ]]; then
url="$url&ensure_option_added=true"
fi
echo -n -e "$setting_count\t"
time curl "$url" -s \
-H 'Pragma: no-cache' \
-H 'Origin: http://src.wordpress-develop.dev' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Accept-Language: en-US,en;q=0.8' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
-H 'Accept: */*' -H 'Cache-Control: no-cache' \
-H 'X-Requested-With: XMLHttpRequest' \
-H "Cookie: $CURL_COOKIES" \
-H 'Connection: keep-alive' \
-H 'Referer: http://src.wordpress-develop.dev/wp-admin/customize.php?url=http%3A%2F%2Fsrc.wordpress-develop.dev%2F' \
--data 'wp_customize=on&theme=twentyfifteen&customized=%7B%7D&nonce='$CURL_NONCE'&customize_messenger_channel=preview-0' \
-o /dev/null --compressed 2>&1 | awk '{print $1}'
done
<?php
/**
* Plugin Name: Tests for Trac 32103
* Author: Weston Ruter, XWP
*/
define( 'TRAC_32103_SETTING_ID_BASE', 'trac_32103' );
define( 'TRAC_32103_MAX_SETTINGS', 1000 );
$default_root_values = array();
for ( $i = 1; $i <= TRAC_32103_MAX_SETTINGS; $i += 1 ) {
$default_root_values[ "setting_$i" ] = array( 'l1' => array( 'l2' => array( 'l3' => $i ) ) );
}
add_action( 'customize_register', function( \WP_Customize_Manager $manager ) use ( $default_root_values ) {
$preview_url = $manager->get_preview_url();
if ( isset( $_REQUEST['ensure_option_added'] ) && 'true' === $_REQUEST['ensure_option_added'] ) {
add_option( TRAC_32103_SETTING_ID_BASE, $default_root_values, '', 'no' );
$preview_url = add_query_arg( 'ensure_option_added', 'true', $preview_url );
}
$setting_count = 0;
if ( isset( $_REQUEST['setting_count'] ) ) {
$setting_count = min( absint( $_REQUEST['setting_count'] ), TRAC_32103_MAX_SETTINGS );
$preview_url = add_query_arg( 'setting_count', $setting_count, $preview_url );
}
$make_dirty = false;
if ( isset( $_REQUEST['make_dirty'] ) && 'true' === $_REQUEST['make_dirty'] ) {
$make_dirty = true;
$preview_url = add_query_arg( 'make_dirty', 'true', $preview_url );
}
$manager->set_preview_url( $preview_url );
if ( 0 === $setting_count ) {
return;
}
$manager->add_section( 'trac-32103', array(
'title' => 'Trac 32103',
) );
$added_count = 0;
foreach ( $default_root_values as $key => $value ) {
if ( $added_count >= $setting_count ) {
break;
}
$setting_id = TRAC_32103_SETTING_ID_BASE . "[$key][l1][l2][l3]";
$manager->add_setting( $setting_id, array(
'type' => 'option',
'sanitize_callback' => 'absint',
'default' => $value['l1']['l2']['l3'],
) );
$setting = $manager->get_setting( $setting_id );
$manager->add_control( $setting_id, array(
'label' => $setting_id,
'type' => 'number',
'settings' => $setting_id,
'section' => 'trac-32103',
) );
$added_count += 1;
if ( $make_dirty ) {
$setting->dirty = true;
$manager->set_post_value( $setting_id, rand() );
}
}
} );
add_action( 'shutdown', function() {
delete_option( TRAC_32103_SETTING_ID_BASE );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment