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.

1 time — 0.003047 sec (very slow) | 50000 times — 1.75 sec (fast) | PHP 7.2.5, WP 4.9.8

No Hooks.

Return

null. Nothing (null).

Usage

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

Examples

0

#1 Adjusting the thumbnail size

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.

form_option() code WP 6.5.2

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