-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.php
155 lines (122 loc) · 4.93 KB
/
settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* @package Gecka Terms Thumbnails
*/
class Gecka_Terms_Thumbnails_Settings {
private static $instance;
private static $settings;
private static $defaults = array(
'term_image_max_w' => 1024,
'term_image_max_h' => 1024,
'term_thumbnail_size_w' => 50,
'term_thumbnail_size_h' => 50,
'term_thumbnail_crop' => 1,
'term_medium_size_w' => 150,
'term_medium_size_h' => 150,
'term_medium_crop' => 0,
'use_wp_media' => false
);
private function __construct() {
foreach ( self::$defaults as $key => $value ) {
self::$settings[ $key ] = get_option( $key, $value );
}
add_action( 'admin_init', array( $this, 'admin_init' ) );
}
/***************************************************************************
* Static functions
**************************************************************************/
public static function instance() {
if ( ! isset( self::$instance ) ) {
$class_name = __CLASS__;
self::$instance = new $class_name;
}
return self::$instance;
}
public function __get( $key ) {
if ( isset( self::$settings[ $key ] ) ) {
return self::$settings[ $key ];
}
return;
}
public function __set( $key, $value ) {
if ( isset( self::$defaults[ $key ] ) ) {
self::$settings[ $key ] = $value;
}
return;
}
public function __save() {
foreach ( self::$settings as $key => $value ) {
if ( isset( self::$defaults[ $key ] ) ) {
update_option( $key, $value );
}
}
}
/***************************************************************************
* Actions and filters hooks
**************************************************************************/
public function admin_init() {
register_setting( 'media', 'term_image_max_w', 'intval' );
register_setting( 'media', 'term_image_max_h', 'intval' );
add_settings_field( 'term_image_max_w', __( 'Term image max size', 'gecka-terms-thumbnails' ), array(
$this,
'field_image_max_size'
), 'media' );
register_setting( 'media', 'term_thumbnail_size_w', 'intval' );
register_setting( 'media', 'term_thumbnail_size_h', 'intval' );
register_setting( 'media', 'term_thumbnail_crop' );
add_settings_field( 'term_thumbnail_size_w', __( 'Term thumbnail max size', 'gecka-terms-thumbnails' ), array(
$this,
'field_thumbnail_max_size'
), 'media' );
register_setting( 'media', 'term_medium_size_w', 'intval' );
register_setting( 'media', 'term_medium_size_h', 'intval' );
register_setting( 'media', 'term_medium_crop' );
add_settings_field( 'term_medium_size_w', __( 'Term medium thumbnail max size', 'gecka-terms-thumbnails' ), array(
$this,
'field_medium_max_size'
), 'media' );
}
public function field_image_max_size() {
?>
<label for="term_image_max_w"><?php _e( 'Max Width' ); ?></label>
<input name="term_image_max_w" type="text" id="term_image_max_w"
value="<?php esc_attr_e( $this->term_image_max_w ); ?>" class="small-text"/>
<label for="term_image_max_h"><?php _e( 'Max Height' ); ?></label>
<input name="term_image_max_h" type="text" id="term_image_max_h"
value="<?php esc_attr_e( $this->term_image_max_h ); ?>" class="small-text"/>
<br>
<span
class="description"><?php _e( 'If one is set, any uploaded original term image will be proportionally resized to this max width.', 'gecka-terms-thumbnails' ); ?></span>
<?php
}
public function field_thumbnail_max_size() {
?>
<label for="term_thumbnail_size_w"><?php _e( 'Max Width' ); ?></label>
<input name="term_thumbnail_size_w" type="text" id="term_thumbnail_size_w"
value="<?php esc_attr_e( $this->term_thumbnail_size_w ); ?>" class="small-text"/>
<label for="term_thumbnail_size_h"><?php _e( 'Max Height' ); ?></label>
<input name="term_thumbnail_size_h" type="text" id="term_thumbnail_size_h"
value="<?php esc_attr_e( $this->term_thumbnail_size_h ); ?>" class="small-text"/>
<br>
<input id="term_thumbnail_crop" type="checkbox" <?php checked( $this->term_thumbnail_crop, 1 ); ?> value="1"
name="term_thumbnail_crop">
<label
for="term_thumbnail_crop"><?php _e( 'Crop thumbnail to exact dimensions (normally thumbnails are proportional)' ) ?></label>
<?php
}
public function field_medium_max_size() {
?>
<label for="term_medium_size_w"><?php _e( 'Max Width' ); ?></label>
<input name="term_medium_size_w" type="text" id="term_medium_size_w"
value="<?php esc_attr_e( $this->term_medium_size_w ); ?>" class="small-text"/>
<label for="term_medium_size_h"><?php _e( 'Max Height' ); ?></label>
<input name="term_medium_size_h" type="text" id="term_medium_size_h"
value="<?php esc_attr_e( $this->term_medium_size_h ); ?>" class="small-text"/>
<br>
<input id="term_medium_crop" type="checkbox" <?php checked( $this->term_medium_crop, 1 ); ?> value="1"
name="term_medium_crop">
<label
for="term_medium_crop"><?php _e( 'Crop thumbnail to exact dimensions (normally thumbnails are proportional)' ) ?></label>
<?php
}
}