WordPress at a glance

form_option() WP 1.5.0

Displays the sanitized option value. Used when displaying the wp option value for the value attribute of the <input> tag.

The option value is escaped using the esc_attr() function.

Works based on: get_option()
✈ 1 time = 0.003047s = very slow | 50000 times = 1.75s = fast | PHP 7.2.5, WP 4.9.8

No Hooks.

Return

Null. Nothing.

Usage

form_option( $option );
$option(string) (required)
Option name.

Examples

#1 Adjusting thumbnail sizes

There are many examples of form_option() usage in the options-media.php file. This file is responsible for the output of the Media settings page in the admin panel. The below code is from this file.

<tr>
	<th scope="row">
		<?php _e( 'Thumbnail size' ) ?>
	</th>
	<td>
		<fieldset>
			<legend class="screen-reader-text">
				<span>
					<?php _e( 'Thumbnail size' ); ?>
				</span>
			</legend>

			<label for="thumbnail_size_w">
				<?php _e( 'Width' ); ?>
			</label>
			<input name="thumbnail_size_w"
				   type="number"
				   step="1"
				   min="0"
				   id="thumbnail_size_w"
				   value="<?php form_option( 'thumbnail_size_w' ); ?>"
				   class="small-text"/>
			<br/>

			<label for="thumbnail_size_h">
				<?php _e( 'Height' ); ?>
			</label>
			<input name="thumbnail_size_h"
				   type="number"
				   step="1"
				   min="0"
				   id="thumbnail_size_h"
				   value="<?php form_option( 'thumbnail_size_h' ); ?>"
				   class="small-text"/>
		</fieldset>

		<input name="thumbnail_crop"
			   type="checkbox"
			   id="thumbnail_crop"
			   value="1" <?php checked( '1', get_option( 'thumbnail_crop' ) ); ?>/>
		<label for="thumbnail_crop">
			<?php _e( 'Crop thumbnail to exact dimensions (normally thumbnails are proportional)' ); ?>
		</label>
	</td>
</tr>

Changelog

Since 1.5.0 Introduced.

Code of form option: wp-includes/option.php WP 5.2.2

<?php
function form_option( $option ) {
	echo esc_attr( get_option( $option ) );
}

Related Functions

From tag: form functions

No comments
    Hello, !     Log In . Register