normalize image options
This commit is contained in:
parent
9b3b25f7fa
commit
3afd1646ad
@ -104,6 +104,31 @@ class ComicPress {
|
||||
return $current_max;
|
||||
}
|
||||
|
||||
function normalize_image_size_options() {
|
||||
$protected_options = apply_filters('comicpress_protected_image_size_options', array('thumbnail', 'medium', 'large'));
|
||||
foreach (get_alloptions() as $option => $value) {
|
||||
if (strpos($option, '_size_w') !== false) {
|
||||
$size = str_replace('_size_w', '', $option);
|
||||
if (!in_array($size, $protected_options)) {
|
||||
foreach (array('_size_w', '_size_h', '_crop') as $suffix) {
|
||||
delete_option("${size}${suffix}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->comicpress_options['image_types'])) {
|
||||
foreach ($this->comicpress_options['image_types'] as $type => $info) {
|
||||
if (isset($info['dimensions'])) {
|
||||
list($width, $height) = explode('x', $info['dimensions']);
|
||||
update_option("${type}_size_w", intval($width));
|
||||
update_option("${type}_size_h", intval($height));
|
||||
update_option("${type}_crop", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
/**
|
||||
|
@ -232,6 +232,58 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$this->assertEquals($expected_result, $this->cp->editor_max_image_size($input, $type));
|
||||
}
|
||||
|
||||
function providerTestNormalizeImageSizeOptions() {
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'comic_size_w' => 500,
|
||||
'comic_size_h' => 500,
|
||||
'comic_crop' => 0,
|
||||
'thumbnail_size_w' => 500,
|
||||
'thumbnail_size_h' => 500,
|
||||
'thumbnail_crop' => 1,
|
||||
),
|
||||
array(),
|
||||
array(
|
||||
'comic_size_w' => false,
|
||||
'comic_size_h' => false,
|
||||
'comic_crop' => false,
|
||||
'thumbnail_size_w' => 500,
|
||||
'thumbnail_size_h' => 500,
|
||||
'thumbnail_crop' => 1,
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(),
|
||||
array('comic' => array(
|
||||
'dimensions' => '500x500'
|
||||
)),
|
||||
array(
|
||||
'comic_size_w' => 500,
|
||||
'comic_size_h' => 500,
|
||||
'comic_crop' => 0
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestNormalizeImageSizeOptions
|
||||
*/
|
||||
function testNormalizeImageSizeOptions($options, $image_types, $expected_options) {
|
||||
foreach ($options as $option => $value) {
|
||||
update_option($option, $value);
|
||||
}
|
||||
|
||||
$this->cp->comicpress_options['image_types'] = $image_types;
|
||||
|
||||
$this->cp->normalize_image_size_options();
|
||||
|
||||
foreach ($expected_options as $option => $value) {
|
||||
$this->assertTrue($value === get_option($option));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user