1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class to provide a way to override the default attachment crop position. Handy if you want to override the default of center,center |
4
|
|
|
* Date: 19/02/2018 |
5
|
|
|
* |
6
|
|
|
* @since 1.4.18 |
7
|
|
|
*/ |
8
|
|
|
if ( ! class_exists( 'FooGallery_Default_Crop_Position' ) ) { |
9
|
|
|
|
10
|
|
|
class FooGallery_Default_Crop_Position { |
|
|
|
|
11
|
|
|
|
12
|
|
|
function __construct() { |
|
|
|
|
13
|
|
|
add_filter( 'foogallery_admin_settings_override', array( $this, 'add_default_crop_position_setting' ) ); |
14
|
|
|
add_action( 'foogallery_admin_settings_custom_type_render_setting', array( $this, 'render_crop_position_setting' ) ); |
15
|
|
|
add_filter( 'wpthumb_default_crop_position', array( $this, 'override_default_crop_position' ) ); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Adds the crop position setting to the settings array |
20
|
|
|
* |
21
|
|
|
* @param $settings |
22
|
|
|
* |
23
|
|
|
* @return mixed |
24
|
|
|
*/ |
25
|
|
|
function add_default_crop_position_setting( $settings ) { |
|
|
|
|
26
|
|
|
$just_settings = $settings['settings']; |
27
|
|
|
$position = 0; |
28
|
|
|
//find the position of the 'thumb_jpeg_quality' setting |
29
|
|
|
foreach( $just_settings as $setting ) { |
30
|
|
|
$position++; |
31
|
|
|
if ( 'thumb_jpeg_quality' === $setting['id'] ) { |
32
|
|
|
break; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$new_settings[] = array( |
|
|
|
|
37
|
|
|
'id' => 'default_crop_position', |
38
|
|
|
'title' => __( 'Default Crop Position', 'foogallery' ), |
39
|
|
|
'desc' => __( 'The default crop position when resizing thumbnails.', 'foogallery' ), |
40
|
|
|
'type' => 'crop', |
41
|
|
|
'default' => 'center,center', |
42
|
|
|
'tab' => 'thumb' |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
array_splice( $just_settings, $position, 0, $new_settings ); |
46
|
|
|
|
47
|
|
|
$settings['settings'] = $just_settings; |
48
|
|
|
|
49
|
|
|
return $settings; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Render the custom crop position to the settings page |
54
|
|
|
* |
55
|
|
|
* @param array $args |
56
|
|
|
*/ |
57
|
|
|
function render_crop_position_setting( $args ) { |
|
|
|
|
58
|
|
|
if ( 'crop' === $args['type'] ) { |
59
|
|
|
$current_position = foogallery_get_setting( 'default_crop_position', 'center,center'); ?> |
|
|
|
|
60
|
|
|
<style>.foogallery_crop_pos input { margin: 5px !important; width: auto; }</style> |
61
|
|
|
<div class="foogallery_crop_pos"> |
62
|
|
|
<input type="radio" name="foogallery[default_crop_position]" value="left,top" title="Left, Top" <?php checked( 'left,top', $current_position ) ?>/> |
63
|
|
|
<input type="radio" name="foogallery[default_crop_position]" value="center,top" title="Center, Top" <?php checked( 'center,top', $current_position ) ?>/> |
64
|
|
|
<input type="radio" name="foogallery[default_crop_position]" value="right,top" title="Right, Top" <?php checked( 'right,top', $current_position ) ?>/><br/> |
65
|
|
|
<input type="radio" name="foogallery[default_crop_position]" value="left,center" title="Left, Center" <?php checked( 'left,center', $current_position ) ?>/> |
66
|
|
|
<input type="radio" name="foogallery[default_crop_position]" value="center,center" title="Center, Center" <?php checked( 'center,center', $current_position ) ?>/> |
67
|
|
|
<input type="radio" name="foogallery[default_crop_position]" value="right,center" title="Right, Center" <?php checked( 'right,center', $current_position ) ?>/><br/> |
68
|
|
|
<input type="radio" name="foogallery[default_crop_position]" value="left,bottom" title="Left, Bottom" <?php checked( 'left,bottom', $current_position ) ?>/> |
69
|
|
|
<input type="radio" name="foogallery[default_crop_position]" value="center,bottom" title="Center, Bottom" <?php checked( 'center,bottom', $current_position ) ?>/> |
70
|
|
|
<input type="radio" name="foogallery[default_crop_position]" value="right,bottom" title="Right, Bottom" <?php checked( 'right,bottom', $current_position ) ?>/> |
71
|
|
|
</div> |
72
|
|
|
<?php } |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
function override_default_crop_position( $default ) { |
|
|
|
|
76
|
|
|
$crop_position = foogallery_get_setting( 'default_crop_position', 'center,center'); |
|
|
|
|
77
|
|
|
return $crop_position; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.