| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * Plugin Name: Background Image Cropper
|
|---|
| 4 | * Plugin URI: https://core.trac.wordpress.org/ticket/32403
|
|---|
| 5 | * Description: Adds cropping to backgroud images in the Customizer, like header images have.
|
|---|
| 6 | * Version: 0.9
|
|---|
| 7 | * Author: Nick Halsey
|
|---|
| 8 | * Author URI: http://nick.halsey.co/
|
|---|
| 9 | * Tags: custom background, background image, cropping, customizer
|
|---|
| 10 | * License: GPL
|
|---|
| 11 |
|
|---|
| 12 | =====================================================================================
|
|---|
| 13 | Copyright (C) 2015 Nick Halsey
|
|---|
| 14 |
|
|---|
| 15 | This program is free software; you can redistribute it and/or
|
|---|
| 16 | modify it under the terms of the GNU General Public License
|
|---|
| 17 | as published by the Free Software Foundation; either version 2
|
|---|
| 18 | of the License, or (at your option) any later version.
|
|---|
| 19 |
|
|---|
| 20 | This program is distributed in the hope that it will be useful,
|
|---|
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 23 | GNU General Public License for more details.
|
|---|
| 24 |
|
|---|
| 25 | You should have received a copy of the GNU General Public License
|
|---|
| 26 | along with WordPress; if not, write to the Free Software
|
|---|
| 27 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|---|
| 28 | =====================================================================================
|
|---|
| 29 | */
|
|---|
| 30 |
|
|---|
| 31 | add_action( 'customize_register', 'background_image_cropper_register', 11 ); // after core
|
|---|
| 32 | /**
|
|---|
| 33 | * Replace the core background image control with one that supports cropping.
|
|---|
| 34 | *
|
|---|
| 35 | * @todo ensure that the background-image context is properly set for any cropped background images.
|
|---|
| 36 | *
|
|---|
| 37 | * @param WP_Customize_Manager $wp_customize Customizer manager object.
|
|---|
| 38 | * @since 4.2.0
|
|---|
| 39 | */
|
|---|
| 40 | function background_image_cropper_register( $wp_customize ) {
|
|---|
| 41 | $wp_customize->remove_control( 'background_image' );
|
|---|
| 42 | $wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'background_image', array(
|
|---|
| 43 | 'section' => 'background_image',
|
|---|
| 44 | 'priority' => 0,
|
|---|
| 45 | 'flex_width' => true,
|
|---|
| 46 | 'flex_height' => true,
|
|---|
| 47 | 'width' => 1920,
|
|---|
| 48 | 'height' => 1080,
|
|---|
| 49 | ) ) );
|
|---|
| 50 | }
|
|---|