Skip to content

Instantly share code, notes, and snippets.

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 erickolivares/3b19f7d46b3490acc4cef345e76fd217 to your computer and use it in GitHub Desktop.
Save erickolivares/3b19f7d46b3490acc4cef345e76fd217 to your computer and use it in GitHub Desktop.
function crop_settings_api_init() {
// Add the section to media settings
add_settings_section(
'crop_settings_section',
'Crop images',
'crop_settings_callback_function',
'media'
);
// Add the fields to the new section
add_settings_field(
'medium_crop',
'Medium size crop',
'crop_medium_callback_function',
'media',
'crop_settings_section'
);
add_settings_field(
'large_crop',
'Large size crop',
'crop_large_callback_function',
'media',
'crop_settings_section'
);
register_setting( 'media', 'medium_crop' );
register_setting( 'media', 'large_crop' );
} // crop_settings_api_init()
add_action( 'admin_init', 'crop_settings_api_init', 1 );
// Settings section callback function
function crop_settings_callback_function() {
echo '<p>Choose whether to crop the medium and large size images</p>';
}
// Callback function for our medium crop setting
function crop_medium_callback_function() {
echo '<input name="medium_crop" type="checkbox" id="medium_crop" value="1"';
$mediumcrop = get_option( "medium_crop");
if ( $mediumcrop == 1 ) {
echo ' checked';
}
echo '/>';
echo '<label for="medium_crop">Crop medium to exact dimensions</label>';
}
// Callback function for our large crop setting
function crop_large_callback_function() {
echo '<input name="large_crop" type="checkbox" id="large_crop" value="1"';
$largecrop = get_option( "large_crop");
if ( $largecrop == 1 ) {
echo ' checked';
}
echo '/>';
echo '<label for="large_crop">Crop large to exact dimensions</label>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment