wppaste
WordPress

WP_Widget_Links::form( array $instance )

Since
2.8.0
Source
wp-includes/widgets/class-wp-widget-links.php:125
Outputs the settings form for the Links widget.

Compatibility

WordPress
since 2.8.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$instancearray
Current settings.

Performance profile

How much work a call to WP_Widget_Links::form() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_terms().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
235–238

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 261.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • querycontent queryget_terms()called directly
  • hookthird-party callbacksapply_filters()one call below WP_Widget_Links::form()

Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Widget_Links::form() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always235–238wp_parse_args(), get_terms(), ->get_field_id(), _e(), ->get_field_id(), ->get_field_name(), _ex(), ->get_field_id(), _e(), ->get_field_name(), ->get_field_id(), selected(), _e(), selected(), _e(), selected(), _e(), selected(), _ex(), checked(), ->get_field_id(), ->get_field_name(), ->get_field_id(), _e(), checked(), ->get_field_id(), ->get_field_name(), ->get_field_id(), _e(), checked(), ->get_field_id(), ->get_field_name(), ->get_field_id(), _e(), checked(), ->get_field_id(), ->get_field_name(), ->get_field_id(), _e(), ->get_field_id(), _e(), ->get_field_id(), ->get_field_name()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev261235–2384
8.5261235–2384
8.4261235–2384
8.3261235–2384
8.2261235–2384
8.1261235–23841 fewer instruction than PHP 7.4
7.4262235–2394

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 9

  • wp_parse_args()Merges user defined arguments into defaults array.
  • get_terms()Retrieves the terms in a given taxonomy or list of taxonomies.
  • _e()Displays translated text.
  • _ex()Displays translated string with gettext context.
  • selected()Outputs the HTML selected attribute.
  • esc_html()Escaping for HTML blocks.
  • checked()Outputs the HTML checked attribute.
  • WP_Widget_Links::get_field_id()
  • WP_Widget_Links::get_field_name()

Source code

	public function form( $instance ) { 		// Defaults.		$instance  = wp_parse_args(			(array) $instance,			array(				'images'      => true,				'name'        => true,				'description' => false,				'rating'      => false,				'category'    => false,				'orderby'     => 'name',				'limit'       => -1,			)		);		$link_cats = get_terms( array( 'taxonomy' => 'link_category' ) );		$limit     = (int) $instance['limit'];		if ( ! $limit ) {			$limit = -1;		}		?>		<p>			<label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Select Link Category:' ); ?></label>			<select class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>">				<option value=""><?php _ex( 'All Links', 'links widget' ); ?></option>				<?php foreach ( $link_cats as $link_cat ) : ?>					<option value="<?php echo (int) $link_cat->term_id; ?>" <?php selected( $instance['category'], $link_cat->term_id ); ?>>						<?php echo esc_html( $link_cat->name ); ?>					</option>				<?php endforeach; ?>			</select>			<label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Sort by:' ); ?></label>			<select name="<?php echo $this->get_field_name( 'orderby' ); ?>" id="<?php echo $this->get_field_id( 'orderby' ); ?>" class="widefat">				<option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>				<option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>				<option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>				<option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option>			</select>		</p> 		<p>			<input class="checkbox" type="checkbox"<?php checked( $instance['images'], true ); ?> id="<?php echo $this->get_field_id( 'images' ); ?>" name="<?php echo $this->get_field_name( 'images' ); ?>" />			<label for="<?php echo $this->get_field_id( 'images' ); ?>"><?php _e( 'Show Link Image' ); ?></label>			<br /> 			<input class="checkbox" type="checkbox"<?php checked( $instance['name'], true ); ?> id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" />			<label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e( 'Show Link Name' ); ?></label>			<br /> 			<input class="checkbox" type="checkbox"<?php checked( $instance['description'], true ); ?> id="<?php echo $this->get_field_id( 'description' ); ?>" name="<?php echo $this->get_field_name( 'description' ); ?>" />			<label for="<?php echo $this->get_field_id( 'description' ); ?>"><?php _e( 'Show Link Description' ); ?></label>			<br /> 			<input class="checkbox" type="checkbox"<?php checked( $instance['rating'], true ); ?> id="<?php echo $this->get_field_id( 'rating' ); ?>" name="<?php echo $this->get_field_name( 'rating' ); ?>" />			<label for="<?php echo $this->get_field_id( 'rating' ); ?>"><?php _e( 'Show Link Rating' ); ?></label>		</p> 		<p>			<label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e( 'Number of links to show:' ); ?></label>			<input id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo ( -1 !== $limit ) ? (int) $limit : ''; ?>" size="3" />		</p>		<?php	}

Changelog

Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/widgets/class-wp-widget-links.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.