1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Imgix_Options_page { |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* The instance of the class. |
7
|
|
|
* |
8
|
|
|
* @var Imgix_Options_page |
9
|
|
|
*/ |
10
|
|
|
protected static $instance; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Plugin options |
14
|
|
|
* |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
protected $options = []; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
public function __construct() { |
21
|
|
|
$this->options = get_option( 'imgix_settings', [] ); |
22
|
|
|
add_action( 'admin_init', [ $this, 'imgix_register_settings' ] ); |
23
|
|
|
add_action( 'admin_menu', [ $this, 'imgix_add_options_link' ] ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Plugin loader instance. |
28
|
|
|
* |
29
|
|
|
* @return Imgix_Options_page |
30
|
|
|
*/ |
31
|
|
|
public static function instance() { |
32
|
|
|
if ( ! isset( self::$instance ) ) { |
33
|
|
|
self::$instance = new self; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return self::$instance; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Renders options page |
41
|
|
|
*/ |
42
|
|
|
public function imgix_options_page() { |
43
|
|
|
?> |
44
|
|
|
<div class="wrap"> |
45
|
|
|
|
46
|
|
|
<h1> |
47
|
|
|
<img src="<?php echo plugins_url( 'assets/images/imgix-logo.png', __DIR__ ); ?>" alt="imgix Logo"> |
48
|
|
|
</h1> |
49
|
|
|
|
50
|
|
|
<p><strong>Need help getting started?</strong> It's easy! Check out our |
51
|
|
|
<a href="https://github.com/imgix-wordpress/imgix-wordpress#getting-started" target="_blank">instructions.</a> |
52
|
|
|
</p> |
53
|
|
|
|
54
|
|
|
<form method="post" action="<?php echo admin_url( 'options.php' ); ?>"> |
55
|
|
|
<?php settings_fields( 'imgix_settings_group' ); ?> |
56
|
|
|
<table class="form-table"> |
57
|
|
|
<tbody> |
58
|
|
|
<tr> |
59
|
|
|
<th> |
60
|
|
|
<label class="description" for="imgix_settings[cdn_link]"><?php esc_html_e( 'imgix Source', 'imgix' ); ?> |
61
|
|
|
</th> |
62
|
|
|
<td> |
63
|
|
|
<input id="imgix_settings[cdn_link]" type="url" name="imgix_settings[cdn_link]" placeholder="https://yourcompany.imgix.net" value="<?php echo $this->get_option( 'cdn_link' ); ?>" class="regular-text code"/> |
64
|
|
|
</td> |
65
|
|
|
</tr> |
66
|
|
|
<tr> |
67
|
|
|
<th> |
68
|
|
|
<label class="description" for="imgix_settings[external_cdn_link]"><?php esc_html_e( 'CDN URL', 'imgix' ); ?> |
69
|
|
|
</th> |
70
|
|
|
<td> |
71
|
|
|
<input id="imgix_settings[external_cdn_link]" type="url" name="imgix_settings[external_cdn_link]" placeholder="http://s3-eu-west-2.amazonaws.com/your-bucket" value="<?php echo $this->get_option( 'external_cdn_link' ); ?>" class="regular-text code"/> |
72
|
|
|
</td> |
73
|
|
|
</tr> |
74
|
|
|
<tr> |
75
|
|
|
<th> |
76
|
|
|
<label class="description" for="imgix_settings[auto_format]"><?php esc_html_e( 'Auto Format Images', 'imgix' ); ?></label> |
77
|
|
|
</th> |
78
|
|
|
<td> |
79
|
|
|
<input id="imgix_settings[auto_format]" type="checkbox" name="imgix_settings[auto_format]" value="1" <?php checked( $this->get_option( 'auto_format' ) ) ?> /> |
80
|
|
|
</td> |
81
|
|
|
</tr> |
82
|
|
|
<tr> |
83
|
|
|
<th> |
84
|
|
|
<label class="description" for="imgix_settings[auto_enhance]"><?php esc_html_e( 'Auto Enhance Images', 'imgix' ); ?></label> |
85
|
|
|
</th> |
86
|
|
|
<td> |
87
|
|
|
<input id="imgix_settings[auto_enhance]" type="checkbox" name="imgix_settings[auto_enhance]" value="1" <?php checked( $this->get_option( 'auto_enhance' ) ) ?> /> |
88
|
|
|
</td> |
89
|
|
|
</tr> |
90
|
|
|
<tr> |
91
|
|
|
<th> |
92
|
|
|
<label class="description" for="imgix_settings[auto_compress]"><?php esc_html_e( 'Auto Compress Images', 'imgix' ); ?></label> |
93
|
|
|
</th> |
94
|
|
|
<td> |
95
|
|
|
<input id="imgix_settings[auto_compress]" type="checkbox" name="imgix_settings[auto_compress]" value="1" <?php checked( $this->get_option( 'auto_compress' ) ) ?> /> |
96
|
|
|
</td> |
97
|
|
|
</tr> |
98
|
|
|
<tr> |
99
|
|
|
<th> |
100
|
|
|
<label class="description" for="imgix_settings[add_dpi2_srcset]"><?php esc_html_e( 'Automatically add retina images using srcset', 'imgix' ); ?></label> |
101
|
|
|
</th> |
102
|
|
|
<td> |
103
|
|
|
<input id="imgix_settings[add_dpi2_srcset]" type="checkbox" name="imgix_settings[add_dpi2_srcset]" value="1" <?php checked( $this->get_option( 'add_dpi2_srcset' ) ) ?> /> |
104
|
|
|
</td> |
105
|
|
|
</tr> |
106
|
|
|
</tbody> |
107
|
|
|
</table> |
108
|
|
|
|
109
|
|
|
<p class="submit"> |
110
|
|
|
<input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Options', 'imgix' ); ?>"/> |
111
|
|
|
</p> |
112
|
|
|
</form> |
113
|
|
|
|
114
|
|
|
<p class="description"> |
115
|
|
|
This plugin is powered by |
116
|
|
|
<a href="http://www.imgix.com" target="_blank">imgix</a>. You can find and contribute to the code on |
117
|
|
|
<a href="https://github.com/imgix-wordpress/images-via-imgix" target="_blank">GitHub</a>. |
118
|
|
|
</p> |
119
|
|
|
</div> |
120
|
|
|
<?php |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Adds link to options page in Admin > Settings menu. |
125
|
|
|
*/ |
126
|
|
|
public function imgix_add_options_link() { |
127
|
|
|
add_options_page( 'imgix', 'imgix', 'manage_options', 'imgix-options', [ $this, 'imgix_options_page' ] ); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Creates our settings in the options table. |
132
|
|
|
*/ |
133
|
|
|
public function imgix_register_settings() { |
134
|
|
|
register_setting( 'imgix_settings_group', 'imgix_settings' ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get option and handle if option is not set |
139
|
|
|
* |
140
|
|
|
* @param string $key |
141
|
|
|
* |
142
|
|
|
* @return mixed |
143
|
|
|
*/ |
144
|
|
|
protected function get_option( $key ) { |
145
|
|
|
return isset( $this->options[ $key ] ) ? $this->options[ $key ] : ''; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
Imgix_Options_page::instance(); |
150
|
|
|
|