Created
July 17, 2017 17:06
-
-
Save erickolivares/7c2a7eb0b269fd71dfe34afd650484e9 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
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