author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* The custom background script. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* The custom background class. |
|
11 |
* |
|
12 |
* @since 3.0.0 |
|
13 |
*/ |
|
14 |
class Custom_Background { |
|
15 |
||
16 |
/** |
|
17 |
* Callback for administration header. |
|
18 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* @var callable |
0 | 20 |
* @since 3.0.0 |
21 |
*/ |
|
5 | 22 |
public $admin_header_callback; |
0 | 23 |
|
24 |
/** |
|
25 |
* Callback for header div. |
|
26 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
* @var callable |
0 | 28 |
* @since 3.0.0 |
29 |
*/ |
|
5 | 30 |
public $admin_image_div_callback; |
0 | 31 |
|
32 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* Used to trigger a success message when settings updated and set to true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* @since 3.0.0 |
5 | 36 |
* @var bool |
0 | 37 |
*/ |
5 | 38 |
private $updated; |
0 | 39 |
|
40 |
/** |
|
41 |
* Constructor - Register administration header callback. |
|
42 |
* |
|
43 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
* @param callable $admin_header_callback |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
* @param callable $admin_image_div_callback Optional custom image div output callback. |
0 | 46 |
*/ |
5 | 47 |
public function __construct($admin_header_callback = '', $admin_image_div_callback = '') { |
0 | 48 |
$this->admin_header_callback = $admin_header_callback; |
49 |
$this->admin_image_div_callback = $admin_image_div_callback; |
|
50 |
||
51 |
add_action( 'admin_menu', array( $this, 'init' ) ); |
|
5 | 52 |
|
53 |
add_action( 'wp_ajax_custom-background-add', array( $this, 'ajax_background_add' ) ); |
|
54 |
||
55 |
// Unused since 3.5.0. |
|
0 | 56 |
add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) ); |
57 |
} |
|
58 |
||
59 |
/** |
|
60 |
* Set up the hooks for the Custom Background admin page. |
|
61 |
* |
|
62 |
* @since 3.0.0 |
|
63 |
*/ |
|
5 | 64 |
public function init() { |
65 |
$page = add_theme_page( __( 'Background' ), __( 'Background' ), 'edit_theme_options', 'custom-background', array( $this, 'admin_page' ) ); |
|
66 |
if ( ! $page ) { |
|
0 | 67 |
return; |
5 | 68 |
} |
0 | 69 |
|
5 | 70 |
add_action( "load-$page", array( $this, 'admin_load' ) ); |
71 |
add_action( "load-$page", array( $this, 'take_action' ), 49 ); |
|
72 |
add_action( "load-$page", array( $this, 'handle_upload' ), 49 ); |
|
0 | 73 |
|
5 | 74 |
if ( $this->admin_header_callback ) { |
75 |
add_action( "admin_head-$page", $this->admin_header_callback, 51 ); |
|
76 |
} |
|
0 | 77 |
} |
78 |
||
79 |
/** |
|
80 |
* Set up the enqueue for the CSS & JavaScript files. |
|
81 |
* |
|
82 |
* @since 3.0.0 |
|
83 |
*/ |
|
5 | 84 |
public function admin_load() { |
0 | 85 |
get_current_screen()->add_help_tab( array( |
86 |
'id' => 'overview', |
|
87 |
'title' => __('Overview'), |
|
88 |
'content' => |
|
89 |
'<p>' . __( 'You can customize the look of your site without touching any of your theme’s code by using a custom background. Your background can be an image or a color.' ) . '</p>' . |
|
90 |
'<p>' . __( 'To use a background image, simply upload it or choose an image that has already been uploaded to your Media Library by clicking the “Choose Image” button. You can display a single instance of your image, or tile it to fill the screen. You can have your background fixed in place, so your site content moves on top of it, or you can have it scroll with your site.' ) . '</p>' . |
|
91 |
'<p>' . __( 'You can also choose a background color by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '</p>' . |
|
92 |
'<p>' . __( 'Don’t forget to click on the Save Changes button when you are finished.' ) . '</p>' |
|
93 |
) ); |
|
94 |
||
95 |
get_current_screen()->set_help_sidebar( |
|
96 |
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
'<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Background_Screen">Documentation on Custom Background</a>' ) . '</p>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
'<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>' |
0 | 99 |
); |
100 |
||
101 |
wp_enqueue_media(); |
|
102 |
wp_enqueue_script('custom-background'); |
|
103 |
wp_enqueue_style('wp-color-picker'); |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Execute custom background modification. |
|
108 |
* |
|
109 |
* @since 3.0.0 |
|
110 |
*/ |
|
5 | 111 |
public function take_action() { |
0 | 112 |
if ( empty($_POST) ) |
113 |
return; |
|
114 |
||
115 |
if ( isset($_POST['reset-background']) ) { |
|
116 |
check_admin_referer('custom-background-reset', '_wpnonce-custom-background-reset'); |
|
117 |
remove_theme_mod('background_image'); |
|
118 |
remove_theme_mod('background_image_thumb'); |
|
119 |
$this->updated = true; |
|
120 |
return; |
|
121 |
} |
|
122 |
||
123 |
if ( isset($_POST['remove-background']) ) { |
|
124 |
// @TODO: Uploaded files are not removed here. |
|
125 |
check_admin_referer('custom-background-remove', '_wpnonce-custom-background-remove'); |
|
126 |
set_theme_mod('background_image', ''); |
|
127 |
set_theme_mod('background_image_thumb', ''); |
|
128 |
$this->updated = true; |
|
129 |
wp_safe_redirect( $_POST['_wp_http_referer'] ); |
|
130 |
return; |
|
131 |
} |
|
132 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
if ( isset( $_POST['background-preset'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
check_admin_referer( 'custom-background' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
$preset = $_POST['background-preset']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
$preset = 'default'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
set_theme_mod( 'background_preset', $preset ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
if ( isset( $_POST['background-position'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
check_admin_referer( 'custom-background' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
$position = explode( ' ', $_POST['background-position'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
if ( in_array( $position[0], array( 'left', 'center', 'right' ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
$position_x = $position[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
$position_x = 'left'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
if ( in_array( $position[1], array( 'top', 'center', 'bottom' ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
$position_y = $position[1]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
$position_y = 'top'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
set_theme_mod( 'background_position_x', $position_x ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
set_theme_mod( 'background_position_y', $position_y ); |
0 | 164 |
} |
165 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
if ( isset( $_POST['background-size'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
check_admin_referer( 'custom-background' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
if ( in_array( $_POST['background-size'], array( 'auto', 'contain', 'cover' ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
$size = $_POST['background-size']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
$size = 'auto'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
set_theme_mod( 'background_size', $size ); |
0 | 176 |
} |
177 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
if ( isset( $_POST['background-repeat'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
check_admin_referer( 'custom-background' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
$repeat = $_POST['background-repeat']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
if ( 'no-repeat' !== $repeat ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
$repeat = 'repeat'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
set_theme_mod( 'background_repeat', $repeat ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
if ( isset( $_POST['background-attachment'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
check_admin_referer( 'custom-background' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
$attachment = $_POST['background-attachment']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
if ( 'fixed' !== $attachment ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
$attachment = 'scroll'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
set_theme_mod( 'background_attachment', $attachment ); |
0 | 200 |
} |
201 |
||
202 |
if ( isset($_POST['background-color']) ) { |
|
203 |
check_admin_referer('custom-background'); |
|
204 |
$color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['background-color']); |
|
205 |
if ( strlen($color) == 6 || strlen($color) == 3 ) |
|
206 |
set_theme_mod('background_color', $color); |
|
207 |
else |
|
208 |
set_theme_mod('background_color', ''); |
|
209 |
} |
|
210 |
||
211 |
$this->updated = true; |
|
212 |
} |
|
213 |
||
214 |
/** |
|
215 |
* Display the custom background page. |
|
216 |
* |
|
217 |
* @since 3.0.0 |
|
218 |
*/ |
|
5 | 219 |
public function admin_page() { |
0 | 220 |
?> |
221 |
<div class="wrap" id="custom-background"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
<h1><?php _e( 'Custom Background' ); ?></h1> |
5 | 223 |
|
224 |
<?php if ( current_user_can( 'customize' ) ) { ?> |
|
225 |
<div class="notice notice-info hide-if-no-customize"> |
|
226 |
<p> |
|
227 |
<?php |
|
228 |
printf( |
|
229 |
__( 'You can now manage and live-preview Custom Backgrounds in the <a href="%1$s">Customizer</a>.' ), |
|
230 |
admin_url( 'customize.php?autofocus[control]=background_image' ) |
|
231 |
); |
|
232 |
?> |
|
233 |
</p> |
|
234 |
</div> |
|
235 |
<?php } ?> |
|
236 |
||
237 |
<?php if ( ! empty( $this->updated ) ) { ?> |
|
0 | 238 |
<div id="message" class="updated"> |
239 |
<p><?php printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p> |
|
240 |
</div> |
|
5 | 241 |
<?php } ?> |
0 | 242 |
|
5 | 243 |
<h3><?php _e( 'Background Image' ); ?></h3> |
244 |
||
0 | 245 |
<table class="form-table"> |
246 |
<tbody> |
|
5 | 247 |
<tr> |
248 |
<th scope="row"><?php _e( 'Preview' ); ?></th> |
|
0 | 249 |
<td> |
5 | 250 |
<?php |
251 |
if ( $this->admin_image_div_callback ) { |
|
252 |
call_user_func( $this->admin_image_div_callback ); |
|
253 |
} else { |
|
254 |
$background_styles = ''; |
|
255 |
if ( $bgcolor = get_background_color() ) |
|
256 |
$background_styles .= 'background-color: #' . $bgcolor . ';'; |
|
0 | 257 |
|
5 | 258 |
$background_image_thumb = get_background_image(); |
259 |
if ( $background_image_thumb ) { |
|
260 |
$background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
$background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
$background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
$background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
$background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
$background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); |
5 | 266 |
|
267 |
// Background-image URL must be single quote, see below. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
$background_styles .= " background-image: url('$background_image_thumb');" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
. " background-size: $background_size;" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
. " background-position: $background_position_x $background_position_y;" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
. " background-repeat: $background_repeat;" |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
. " background-attachment: $background_attachment;"; |
5 | 273 |
} |
274 |
?> |
|
275 |
<div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?> |
|
276 |
<?php if ( $background_image_thumb ) { ?> |
|
277 |
<img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /><br /> |
|
278 |
<img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /> |
|
279 |
<?php } ?> |
|
280 |
</div> |
|
281 |
<?php } ?> |
|
0 | 282 |
</td> |
283 |
</tr> |
|
5 | 284 |
|
0 | 285 |
<?php if ( get_background_image() ) : ?> |
5 | 286 |
<tr> |
0 | 287 |
<th scope="row"><?php _e('Remove Image'); ?></th> |
288 |
<td> |
|
5 | 289 |
<form method="post"> |
0 | 290 |
<?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
<?php submit_button( __( 'Remove Background Image' ), '', 'remove-background', false ); ?><br/> |
0 | 292 |
<?php _e('This will remove the background image. You will not be able to restore any customizations.') ?> |
293 |
</form> |
|
294 |
</td> |
|
295 |
</tr> |
|
296 |
<?php endif; ?> |
|
297 |
||
298 |
<?php $default_image = get_theme_support( 'custom-background', 'default-image' ); ?> |
|
299 |
<?php if ( $default_image && get_background_image() != $default_image ) : ?> |
|
5 | 300 |
<tr> |
0 | 301 |
<th scope="row"><?php _e('Restore Original Image'); ?></th> |
302 |
<td> |
|
5 | 303 |
<form method="post"> |
0 | 304 |
<?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
<?php submit_button( __( 'Restore Original Image' ), '', 'reset-background', false ); ?><br/> |
0 | 306 |
<?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?> |
307 |
</form> |
|
308 |
</td> |
|
309 |
</tr> |
|
5 | 310 |
<?php endif; ?> |
0 | 311 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
<?php if ( current_user_can( 'upload_files' ) ): ?> |
5 | 313 |
<tr> |
0 | 314 |
<th scope="row"><?php _e('Select Image'); ?></th> |
5 | 315 |
<td><form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post"> |
0 | 316 |
<p> |
317 |
<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> |
|
318 |
<input type="file" id="upload" name="import" /> |
|
319 |
<input type="hidden" name="action" value="save" /> |
|
320 |
<?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
<?php submit_button( __( 'Upload' ), '', 'submit', false ); ?> |
0 | 322 |
</p> |
323 |
<p> |
|
324 |
<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br /> |
|
5 | 325 |
<button id="choose-from-library-link" class="button" |
0 | 326 |
data-choose="<?php esc_attr_e( 'Choose a Background Image' ); ?>" |
5 | 327 |
data-update="<?php esc_attr_e( 'Set as background' ); ?>"><?php _e( 'Choose Image' ); ?></button> |
0 | 328 |
</p> |
329 |
</form> |
|
330 |
</td> |
|
331 |
</tr> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
332 |
<?php endif; ?> |
0 | 333 |
</tbody> |
334 |
</table> |
|
335 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
<h3><?php _e( 'Display Options' ); ?></h3> |
5 | 337 |
<form method="post"> |
0 | 338 |
<table class="form-table"> |
339 |
<tbody> |
|
340 |
<?php if ( get_background_image() ) : ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
<input name="background-preset" type="hidden" value="custom"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
343 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
$background_position = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
'%s %s', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
$background_position_options = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
'left top' => array( 'label' => __( 'Top Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
'center top' => array( 'label' => __( 'Top' ), 'icon' => 'dashicons dashicons-arrow-up-alt' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
'right top' => array( 'label' => __( 'Top Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
'left center' => array( 'label' => __( 'Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
'center center' => array( 'label' => __( 'Center' ), 'icon' => 'background-position-center-icon' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
'right center' => array( 'label' => __( 'Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
'left bottom' => array( 'label' => __( 'Bottom Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
'center bottom' => array( 'label' => __( 'Bottom' ), 'icon' => 'dashicons dashicons-arrow-down-alt' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
'right bottom' => array( 'label' => __( 'Bottom Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
?> |
5 | 368 |
<tr> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
<th scope="row"><?php _e( 'Image Position' ); ?></th> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
<div class="background-position-control"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
<?php foreach ( $background_position_options as $group ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
<div class="button-group"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
<?php foreach ( $group as $value => $input ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
<label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
<input class="screen-reader-text" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>"<?php checked( $value, $background_position ); ?>> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
<span class="button display-options position"><span class="<?php echo esc_attr( $input['icon'] ); ?>" aria-hidden="true"></span></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
<span class="screen-reader-text"><?php echo $input['label']; ?></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
</label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
<?php endforeach; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
<?php endforeach; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
</div> |
0 | 384 |
</fieldset></td> |
385 |
</tr> |
|
386 |
||
5 | 387 |
<tr> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
<th scope="row"><label for="background-size"><?php _e( 'Image Size' ); ?></label></th> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Size' ); ?></span></legend> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
<select id="background-size" name="background-size"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
<option value="auto"<?php selected( 'auto', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _ex( 'Original', 'Original Size' ); ?></option> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
<option value="contain"<?php selected( 'contain', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _e( 'Fit to Screen' ); ?></option> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
<option value="cover"<?php selected( 'cover', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _e( 'Fill Screen' ); ?></option> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
</select> |
0 | 395 |
</fieldset></td> |
396 |
</tr> |
|
397 |
||
5 | 398 |
<tr> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
<th scope="row"><?php _ex( 'Repeat', 'Background Repeat' ); ?></th> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
<td><fieldset><legend class="screen-reader-text"><span><?php _ex( 'Repeat', 'Background Repeat' ); ?></span></legend> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
<input name="background-repeat" type="hidden" value="no-repeat"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
<label><input type="checkbox" name="background-repeat" value="repeat"<?php checked( 'repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?>> <?php _e( 'Repeat Background Image' ); ?></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
</fieldset></td> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
</tr> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
<tr> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
<th scope="row"><?php _ex( 'Scroll', 'Background Scroll' ); ?></th> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
<td><fieldset><legend class="screen-reader-text"><span><?php _ex( 'Scroll', 'Background Scroll' ); ?></span></legend> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
<input name="background-attachment" type="hidden" value="fixed"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
<label><input name="background-attachment" type="checkbox" value="scroll" <?php checked( 'scroll', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?>> <?php _e( 'Scroll with Page' ); ?></label> |
0 | 411 |
</fieldset></td> |
412 |
</tr> |
|
413 |
<?php endif; // get_background_image() ?> |
|
5 | 414 |
<tr> |
0 | 415 |
<th scope="row"><?php _e( 'Background Color' ); ?></th> |
416 |
<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> |
|
417 |
<?php |
|
418 |
$default_color = ''; |
|
419 |
if ( current_theme_supports( 'custom-background', 'default-color' ) ) |
|
420 |
$default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"'; |
|
421 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
<input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr( get_background_color() ); ?>"<?php echo $default_color ?>> |
0 | 423 |
</fieldset></td> |
424 |
</tr> |
|
425 |
</tbody> |
|
426 |
</table> |
|
427 |
||
428 |
<?php wp_nonce_field('custom-background'); ?> |
|
429 |
<?php submit_button( null, 'primary', 'save-background-options' ); ?> |
|
430 |
</form> |
|
431 |
||
432 |
</div> |
|
433 |
<?php |
|
434 |
} |
|
435 |
||
436 |
/** |
|
437 |
* Handle an Image upload for the background image. |
|
438 |
* |
|
439 |
* @since 3.0.0 |
|
440 |
*/ |
|
5 | 441 |
public function handle_upload() { |
0 | 442 |
if ( empty($_FILES) ) |
443 |
return; |
|
444 |
||
445 |
check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload'); |
|
446 |
$overrides = array('test_form' => false); |
|
447 |
||
448 |
$uploaded_file = $_FILES['import']; |
|
5 | 449 |
$wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] ); |
0 | 450 |
if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) |
451 |
wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) ); |
|
452 |
||
453 |
$file = wp_handle_upload($uploaded_file, $overrides); |
|
454 |
||
455 |
if ( isset($file['error']) ) |
|
456 |
wp_die( $file['error'] ); |
|
457 |
||
458 |
$url = $file['url']; |
|
459 |
$type = $file['type']; |
|
460 |
$file = $file['file']; |
|
461 |
$filename = basename($file); |
|
462 |
||
463 |
// Construct the object array |
|
464 |
$object = array( |
|
465 |
'post_title' => $filename, |
|
466 |
'post_content' => $url, |
|
467 |
'post_mime_type' => $type, |
|
468 |
'guid' => $url, |
|
469 |
'context' => 'custom-background' |
|
470 |
); |
|
471 |
||
472 |
// Save the data |
|
473 |
$id = wp_insert_attachment($object, $file); |
|
474 |
||
475 |
// Add the meta-data |
|
476 |
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
|
477 |
update_post_meta( $id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); |
|
478 |
||
479 |
set_theme_mod('background_image', esc_url_raw($url)); |
|
480 |
||
481 |
$thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' ); |
|
482 |
set_theme_mod('background_image_thumb', esc_url_raw( $thumbnail[0] ) ); |
|
483 |
||
484 |
/** This action is documented in wp-admin/custom-header.php */ |
|
485 |
do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication |
|
486 |
$this->updated = true; |
|
487 |
} |
|
488 |
||
489 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
* Ajax handler for adding custom background context to an attachment. |
5 | 491 |
* |
492 |
* Triggered when the user adds a new background image from the |
|
493 |
* Media Manager. |
|
494 |
* |
|
495 |
* @since 4.1.0 |
|
496 |
*/ |
|
497 |
public function ajax_background_add() { |
|
498 |
check_ajax_referer( 'background-add', 'nonce' ); |
|
499 |
||
500 |
if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
501 |
wp_send_json_error(); |
|
502 |
} |
|
503 |
||
504 |
$attachment_id = absint( $_POST['attachment_id'] ); |
|
505 |
if ( $attachment_id < 1 ) { |
|
506 |
wp_send_json_error(); |
|
507 |
} |
|
508 |
||
509 |
update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_stylesheet() ); |
|
510 |
||
511 |
wp_send_json_success(); |
|
512 |
} |
|
513 |
||
514 |
/** |
|
0 | 515 |
* |
516 |
* @since 3.4.0 |
|
5 | 517 |
* @deprecated 3.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
* @param array $form_fields |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
* @return array $form_fields |
0 | 521 |
*/ |
5 | 522 |
public function attachment_fields_to_edit( $form_fields ) { |
0 | 523 |
return $form_fields; |
524 |
} |
|
525 |
||
526 |
/** |
|
527 |
* |
|
528 |
* @since 3.4.0 |
|
5 | 529 |
* @deprecated 3.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
530 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
531 |
* @param array $tabs |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
532 |
* @return array $tabs |
0 | 533 |
*/ |
5 | 534 |
public function filter_upload_tabs( $tabs ) { |
0 | 535 |
return $tabs; |
536 |
} |
|
537 |
||
5 | 538 |
/** |
539 |
* |
|
540 |
* @since 3.4.0 |
|
541 |
* @deprecated 3.5.0 |
|
542 |
*/ |
|
0 | 543 |
public function wp_set_background_image() { |
544 |
if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit; |
|
545 |
$attachment_id = absint($_POST['attachment_id']); |
|
546 |
/** This filter is documented in wp-admin/includes/media.php */ |
|
547 |
$sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) )); |
|
548 |
$size = 'thumbnail'; |
|
549 |
if ( in_array( $_POST['size'], $sizes ) ) |
|
550 |
$size = esc_attr( $_POST['size'] ); |
|
551 |
||
552 |
update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); |
|
553 |
$url = wp_get_attachment_image_src( $attachment_id, $size ); |
|
554 |
$thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); |
|
555 |
set_theme_mod( 'background_image', esc_url_raw( $url[0] ) ); |
|
556 |
set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) ); |
|
557 |
exit; |
|
558 |
} |
|
559 |
} |