| | 104 | |
| | 105 | function settings() { |
| | 106 | if ( $this->admin_image_div_callback ) { |
| | 107 | call_user_func($this->admin_image_div_callback); |
| | 108 | } else { |
| | 109 | add_settings_section( 'background-image', __('Background Image'), '__return_false', 'custom-background-image' ); |
| | 110 | add_settings_field( 'preview', __('Preview'), array(&$this, 'preview_field'), 'custom-background-image', 'background-image' ); |
| | 111 | |
| | 112 | if ( get_background_image() ) |
| | 113 | add_settings_field( 'remove-background', __('Remove Image'), array(&$this, 'remove_background_field'), 'custom-background-image', 'background-image' ); |
| | 114 | |
| | 115 | if ( defined( 'BACKGROUND_IMAGE' ) ) |
| | 116 | add_settings_field( 'reset-background', __('Restore Original Image'), array(&$this, 'reset_background_field'), 'custom-background-image', 'background-image' ); |
| | 117 | |
| | 118 | add_settings_field( 'custom-background-upload', __('Upload Image'), array(&$this, 'background_upload_field'), 'custom-background-image', 'background-image' ); |
| | 119 | } |
| | 120 | |
| | 121 | add_settings_section( 'display-options', __('Display Options'), '__return_false', $this->page ); |
| | 122 | if ( get_background_image() ) { |
| | 123 | add_settings_field( 'background-position', __('Position'), array(&$this, 'background_position_field'), $this->page, 'display-options' ); |
| | 124 | add_settings_field( 'background-repeat', __('Repeat'), array(&$this, 'background_repeat_field'), $this->page, 'display-options' ); |
| | 125 | add_settings_field( 'background-attachment', __('Attachment'), array(&$this, 'background_attachment_field'), $this->page, 'display-options' ); |
| | 126 | } |
| | 127 | add_settings_field( 'background-color', __('Background Color'), array(&$this, 'background_color_field'), $this->page, 'display-options' ); |
| | 128 | } |
| | 129 | |
| | 130 | function preview_field() { |
| | 131 | $background_styles = ''; |
| | 132 | if ( $bgcolor = get_background_color() ) |
| | 133 | $background_styles .= 'background-color: #' . $bgcolor . ';'; |
| | 134 | |
| | 135 | if ( get_background_image() ) { |
| | 136 | // background-image URL must be single quote, see below |
| | 137 | $background_styles .= ' background-image: url(\'' . get_theme_mod('background_image_thumb', '') . '\');' |
| | 138 | . ' background-repeat: ' . get_theme_mod('background_repeat', 'repeat') . ';' |
| | 139 | . ' background-position: top ' . get_theme_mod('background_position_x', 'left'); |
| | 140 | } |
| | 141 | ?> |
| | 142 | <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?> |
| | 143 | <?php if ( get_background_image() ) { ?> |
| | 144 | <img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" alt="" /><br /> |
| | 145 | <img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" alt="" /> |
| | 146 | <?php } ?> |
| | 147 | </div> |
| | 148 | <?php |
| | 149 | } |
| | 150 | |
| | 151 | function remove_background_field() { |
| | 152 | echo '<form method="post" action="">'; |
| | 153 | wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); |
| | 154 | submit_button( __( 'Remove Background Image' ), 'button', 'remove-background', false ); |
| | 155 | echo '<br/>'; |
| | 156 | _e('This will remove the background image. You will not be able to restore any customizations.'); |
| | 157 | echo '</form>'; |
| | 158 | } |
| | 159 | |
| | 160 | function restore_background_field() { |
| | 161 | echo '<form method="post" action="">'; |
| | 162 | wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); |
| | 163 | submit_button( __( 'Restore Original Image' ), 'button', 'reset-background', false ); |
| | 164 | echo '<br/>'; |
| | 165 | _e('This will restore the original background image. You will not be able to restore any customizations.'); |
| | 166 | echo '</form>'; |
| | 167 | } |
| | 168 | |
| | 169 | function background_upload_field() { |
| | 170 | ?> |
| | 171 | <form enctype="multipart/form-data" id="upload-form" method="post" action=""> |
| | 172 | <label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /> |
| | 173 | <input type="file" id="upload" name="import" /> |
| | 174 | <input type="hidden" name="action" value="save" /> |
| | 175 | <?php |
| | 176 | wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload'); |
| | 177 | submit_button( __( 'Upload' ), 'button', 'submit', false ); |
| | 178 | ?> |
| | 179 | </form> |
| | 180 | <?php |
| | 181 | } |
| | 182 | |
| | 183 | function background_position_field() { |
| | 184 | ?> |
| | 185 | <fieldset> |
| | 186 | <legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend> |
| | 187 | <label> |
| | 188 | <input name="background-position-x" type="radio" value="left"<?php checked('left', get_theme_mod('background_position_x', 'left')); ?> /> |
| | 189 | <?php _e('Left') ?> |
| | 190 | </label> |
| | 191 | <label> |
| | 192 | <input name="background-position-x" type="radio" value="center"<?php checked('center', get_theme_mod('background_position_x', 'left')); ?> /> |
| | 193 | <?php _e('Center') ?> |
| | 194 | </label> |
| | 195 | <label> |
| | 196 | <input name="background-position-x" type="radio" value="right"<?php checked('right', get_theme_mod('background_position_x', 'left')); ?> /> |
| | 197 | <?php _e('Right') ?> |
| | 198 | </label> |
| | 199 | </fieldset> |
| | 200 | <?php |
| | 201 | } |
| | 202 | |
| | 203 | function background_repeat_field() { |
| | 204 | ?> |
| | 205 | <fieldset> |
| | 206 | <legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend> |
| | 207 | <label> |
| | 208 | <input type="radio" name="background-repeat" value="no-repeat"<?php checked('no-repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> |
| | 209 | <?php _e('No Repeat'); ?> |
| | 210 | </label> |
| | 211 | <label> |
| | 212 | <input type="radio" name="background-repeat" value="repeat"<?php checked('repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> |
| | 213 | <?php _e('Tile'); ?> |
| | 214 | </label> |
| | 215 | <label> |
| | 216 | <input type="radio" name="background-repeat" value="repeat-x"<?php checked('repeat-x', get_theme_mod('background_repeat', 'repeat')); ?> /> |
| | 217 | <?php _e('Tile Horizontally'); ?> |
| | 218 | </label> |
| | 219 | <label> |
| | 220 | <input type="radio" name="background-repeat" value="repeat-y"<?php checked('repeat-y', get_theme_mod('background_repeat', 'repeat')); ?> /> |
| | 221 | <?php _e('Tile Vertically'); ?> |
| | 222 | </label> |
| | 223 | </fieldset> |
| | 224 | <?php |
| | 225 | } |
| | 226 | |
| | 227 | function background_attachment_field() { |
| | 228 | ?> |
| | 229 | <fieldset> |
| | 230 | <legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend> |
| | 231 | <label> |
| | 232 | <input name="background-attachment" type="radio" value="scroll" <?php checked('scroll', get_theme_mod('background_attachment', 'scroll')); ?> /> |
| | 233 | <?php _e('Scroll') ?> |
| | 234 | </label> |
| | 235 | <label> |
| | 236 | <input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment', 'scroll')); ?> /> |
| | 237 | <?php _e('Fixed') ?> |
| | 238 | </label> |
| | 239 | </fieldset> |
| | 240 | <?php |
| | 241 | } |
| | 242 | |
| | 243 | function background_color_field() { |
| | 244 | ?> |
| | 245 | <fieldset> |
| | 246 | <legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> |
| | 247 | <?php $show_clear = get_background_color() ? '' : ' style="display:none"'; ?> |
| | 248 | <input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr(get_background_color()) ?>" /> |
| | 249 | <a class="hide-if-no-js" href="#" id="pickcolor"><?php _e('Select a Color'); ?></a> <span<?php echo $show_clear; ?> class="hide-if-no-js" id="clearcolor"> (<a href="#"><?php _e( 'Clear' ); ?></a>)</span> |
| | 250 | <div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> |
| | 251 | </fieldset> |
| | 252 | <?php |
| | 253 | } |
| | 254 | |
| | 255 | function updated() { |
| | 256 | if ( ! get_settings_errors('custom-background') ) |
| | 257 | add_settings_error( 'custom-background', 'background-updated',sprintf(__( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' )), 'updated' ); |
| | 258 | } |
| | 259 | |
| | 260 | function admin_notices() { |
| | 261 | settings_errors( 'custom-background' ); |
| | 262 | } |
| 183 | | <?php } |
| 184 | | |
| 185 | | if ( $this->admin_image_div_callback ) { |
| 186 | | call_user_func($this->admin_image_div_callback); |
| 187 | | } else { |
| 188 | | ?> |
| 189 | | <h3><?php _e('Background Image'); ?></h3> |
| 190 | | <table class="form-table"> |
| 191 | | <tbody> |
| 192 | | <tr valign="top"> |
| 193 | | <th scope="row"><?php _e('Preview'); ?></th> |
| 194 | | <td> |
| 195 | | <?php |
| 196 | | $background_styles = ''; |
| 197 | | if ( $bgcolor = get_background_color() ) |
| 198 | | $background_styles .= 'background-color: #' . $bgcolor . ';'; |
| 199 | | |
| 200 | | if ( get_background_image() ) { |
| 201 | | // background-image URL must be single quote, see below |
| 202 | | $background_styles .= ' background-image: url(\'' . get_theme_mod('background_image_thumb', '') . '\');' |
| 203 | | . ' background-repeat: ' . get_theme_mod('background_repeat', 'repeat') . ';' |
| 204 | | . ' background-position: top ' . get_theme_mod('background_position_x', 'left'); |
| 205 | | } |
| 206 | | ?> |
| 207 | | <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?> |
| 208 | | <?php if ( get_background_image() ) { ?> |
| 209 | | <img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" alt="" /><br /> |
| 210 | | <img class="custom-background-image" src="<?php echo get_theme_mod('background_image_thumb', ''); ?>" style="visibility:hidden;" alt="" /> |
| 211 | | <?php } ?> |
| 212 | | </div> |
| 213 | | <?php } ?> |
| 214 | | </td> |
| 215 | | </tr> |
| 216 | | <?php if ( get_background_image() ) : ?> |
| 217 | | <tr valign="top"> |
| 218 | | <th scope="row"><?php _e('Remove Image'); ?></th> |
| 219 | | <td> |
| 220 | | <form method="post" action=""> |
| 221 | | <?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?> |
| 222 | | <?php submit_button( __( 'Remove Background Image' ), 'button', 'remove-background', false ); ?><br/> |
| 223 | | <?php _e('This will remove the background image. You will not be able to restore any customizations.') ?> |
| 224 | | </form> |
| 225 | | </td> |
| 226 | | </tr> |
| 227 | | <?php endif; ?> |
| 228 | | |
| 229 | | <?php if ( defined( 'BACKGROUND_IMAGE' ) ) : // Show only if a default background image exists ?> |
| 230 | | <tr valign="top"> |
| 231 | | <th scope="row"><?php _e('Restore Original Image'); ?></th> |
| 232 | | <td> |
| 233 | | <form method="post" action=""> |
| 234 | | <?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?> |
| 235 | | <?php submit_button( __( 'Restore Original Image' ), 'button', 'reset-background', false ); ?><br/> |
| 236 | | <?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?> |
| 237 | | </form> |
| 238 | | </td> |
| 239 | | </tr> |
| 240 | | |
| 241 | | <?php endif; ?> |
| 242 | | <tr valign="top"> |
| 243 | | <th scope="row"><?php _e('Upload Image'); ?></th> |
| 244 | | <td><form enctype="multipart/form-data" id="upload-form" method="post" action=""> |
| 245 | | <label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" /> |
| 246 | | <input type="hidden" name="action" value="save" /> |
| 247 | | <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?> |
| 248 | | <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> |
| 249 | | </form> |
| 250 | | </td> |
| 251 | | </tr> |
| 252 | | </tbody> |
| 253 | | </table> |
| 254 | | |
| 255 | | <h3><?php _e('Display Options') ?></h3> |
| 256 | | <form method="post" action=""> |
| 257 | | <table class="form-table"> |
| 258 | | <tbody> |
| 259 | | <?php if ( get_background_image() ) : ?> |
| 260 | | <tr valign="top"> |
| 261 | | <th scope="row"><?php _e( 'Position' ); ?></th> |
| 262 | | <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend> |
| 263 | | <label> |
| 264 | | <input name="background-position-x" type="radio" value="left"<?php checked('left', get_theme_mod('background_position_x', 'left')); ?> /> |
| 265 | | <?php _e('Left') ?> |
| 266 | | </label> |
| 267 | | <label> |
| 268 | | <input name="background-position-x" type="radio" value="center"<?php checked('center', get_theme_mod('background_position_x', 'left')); ?> /> |
| 269 | | <?php _e('Center') ?> |
| 270 | | </label> |
| 271 | | <label> |
| 272 | | <input name="background-position-x" type="radio" value="right"<?php checked('right', get_theme_mod('background_position_x', 'left')); ?> /> |
| 273 | | <?php _e('Right') ?> |
| 274 | | </label> |
| 275 | | </fieldset></td> |
| 276 | | </tr> |
| 277 | | |
| 278 | | <tr valign="top"> |
| 279 | | <th scope="row"><?php _e( 'Repeat' ); ?></th> |
| 280 | | <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend> |
| 281 | | <label><input type="radio" name="background-repeat" value="no-repeat"<?php checked('no-repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('No Repeat'); ?></label> |
| 282 | | <label><input type="radio" name="background-repeat" value="repeat"<?php checked('repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile'); ?></label> |
| 283 | | <label><input type="radio" name="background-repeat" value="repeat-x"<?php checked('repeat-x', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile Horizontally'); ?></label> |
| 284 | | <label><input type="radio" name="background-repeat" value="repeat-y"<?php checked('repeat-y', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile Vertically'); ?></label> |
| 285 | | </fieldset></td> |
| 286 | | </tr> |
| 287 | | |
| 288 | | <tr valign="top"> |
| 289 | | <th scope="row"><?php _e( 'Attachment' ); ?></th> |
| 290 | | <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend> |
| 291 | | <label> |
| 292 | | <input name="background-attachment" type="radio" value="scroll" <?php checked('scroll', get_theme_mod('background_attachment', 'scroll')); ?> /> |
| 293 | | <?php _e('Scroll') ?> |
| 294 | | </label> |
| 295 | | <label> |
| 296 | | <input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment', 'scroll')); ?> /> |
| 297 | | <?php _e('Fixed') ?> |
| 298 | | </label> |
| 299 | | </fieldset></td> |
| 300 | | </tr> |
| 301 | | <?php endif; // get_background_image() ?> |
| 302 | | <tr valign="top"> |
| 303 | | <th scope="row"><?php _e( 'Background Color' ); ?></th> |
| 304 | | <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> |
| 305 | | <?php $show_clear = get_background_color() ? '' : ' style="display:none"'; ?> |
| 306 | | <input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr(get_background_color()) ?>" /> |
| 307 | | <a class="hide-if-no-js" href="#" id="pickcolor"><?php _e('Select a Color'); ?></a> <span<?php echo $show_clear; ?> class="hide-if-no-js" id="clearcolor"> (<a href="#"><?php _e( 'Clear' ); ?></a>)</span> |
| 308 | | <div id="colorPickerDiv" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> |
| 309 | | </fieldset></td> |
| 310 | | </tr> |
| 311 | | </tbody> |
| 312 | | </table> |
| 313 | | |
| 314 | | <?php wp_nonce_field('custom-background'); ?> |
| 315 | | <?php submit_button( null, 'primary', 'save-background-options' ); ?> |
| 316 | | </form> |
| 317 | | |
| 318 | | </div> |