Last active
September 16, 2015 22:42
-
-
Save westonruter/180251bb5359202995e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Heavy_Widget extends WP_Widget { | |
public $input_count = 500; | |
function __construct() { | |
parent::__construct( 'heavy', 'Heavy' ); | |
} | |
function form( $instance ) { | |
?> | |
<div class="heavy-widget"> | |
<p> | |
<?php $id = 'title'; ?> | |
<label for="<?php echo $this->get_field_id( $id ) ?>"><?php echo $id; ?></label> | |
<input | |
type="text" | |
id="<?php echo $this->get_field_id( $id ) ?>" | |
name="<?php echo $this->get_field_name( $id ) ?>" | |
value="<?php if ( isset( $instance[ $id ] ) ) { echo esc_attr( $instance[ $id ] ); } ?>" | |
> | |
</p> | |
<details> | |
<summary>Other fields</summary> | |
<?php | |
for ( $i = 0; $i < $this->input_count; $i += 1 ) { | |
$id = "field$i"; | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_id( $id ) ?>"><?php echo $id; ?></label> | |
<input | |
type="text" | |
id="<?php echo $this->get_field_id( $id ) ?>" | |
name="<?php echo $this->get_field_name( $id ) ?>" | |
value="<?php if ( isset( $instance[ $id ] ) ) { echo esc_attr( $instance[ $id ] ); } ?>" | |
> | |
</p> | |
<?php | |
} | |
?> | |
</details> | |
</div> | |
<?php | |
} | |
function widget( $args, $instance ) { | |
echo $args['before_widget']; | |
echo $this->id; | |
print_r( $instance ); | |
echo $args['after_widget']; | |
} | |
function update( $new_instance, $old_instance ) { | |
$title = isset( $new_instance['title'] ) ? $new_instance['title'] : ''; | |
$keys = array_slice( array_keys( $new_instance ), 0, 27 ); | |
$new_instance = array_merge( compact( 'title' ), wp_array_slice_assoc( $new_instance, $keys ) ); | |
return $new_instance; | |
} | |
} | |
add_action( 'widgets_init', function() { | |
register_widget( 'Heavy_Widget' ); | |
} ); | |
add_action( 'shutdown', function () { | |
global $pagenow; | |
if ( 'customize.php' !== $pagenow ) { | |
return; | |
} | |
?> | |
<!-- | |
memory_get_peak_usage(): <?php echo number_format_i18n( memory_get_peak_usage() ); ?> | |
memory_get_usage(): <?php echo number_format_i18n( memory_get_usage() ); ?> | |
--> | |
<?php | |
}, 1000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment