public static get_available_crop ( ) : array | ||
return | array |
public static function get_available_crop()
{
global $wp_version;
// Return the only possible
if (version_compare($wp_version, '3.9', '<')) {
return array();
}
$x = array('left' => __('Left', 'simple-image-sizes'), 'center' => __('Center', 'simple-image-sizes'), 'right' => __('Right', 'simple-image-sizes'));
$y = array('top' => __('top', 'simple-image-sizes'), 'center' => __('center', 'simple-image-sizes'), 'bottom' => __('bottom', 'simple-image-sizes'));
/**
* Base crops
*/
$crops = array(0 => __('No', 'simple-image-sizes'), 1 => __('Yes', 'simple-image-sizes'));
foreach ($x as $x_pos => $x_pos_label) {
foreach ($y as $y_pos => $y_pos_label) {
$crops[$x_pos . '_' . $y_pos] = $x_pos_label . ' ' . $y_pos_label;
}
}
return $crops;
}
/** * Add a size by Ajax * * @access public * @return void * @author Nicolas Juen */ public static function a_add_size() { // Get the nonce $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : ''; // Get old options $sizes = (array) get_option(SIS_OPTION, array()); $croppings = SIS_Admin_Main::get_available_crop(); $croppings[true] = ''; $croppings[false] = ''; // Check entries $name = isset($_POST['name']) ? sanitize_title($_POST['name']) : ''; $height = !isset($_POST['height']) ? 0 : absint($_POST['height']); $width = !isset($_POST['width']) ? 0 : absint($_POST['width']); $crop = isset($_POST['crop']) && isset($croppings[$_POST['crop']]) ? $_POST['crop'] : false; $show = isset($_POST['show']) && $_POST['show'] == 'false' ? false : true; $cn = isset($_POST['customName']) && !empty($_POST['customName']) ? sanitize_text_field($_POST['customName']) : $name; // Check the nonce if (!wp_verify_nonce($nonce, 'add_size')) { die(0); } // If no name given do not save if (empty($name)) { die(0); } // Make values $values = array('custom' => 1, 'w' => $width, 'h' => $height, 'c' => $crop, 's' => $show, 'n' => $cn); // If the size have not changed return 2 if (isset($sizes[$name]) && $sizes[$name] === $values) { die(2); } // Put the new values $sizes[$name] = $values; // display update result echo (int) update_option('custom_image_sizes', $sizes); die; }