WordPress.org

Make WordPress Core

Ticket #29211: background-image-cropper.php

File background-image-cropper.php, 2.0 KB (added by celloexpressions, 5 years ago)

Test plugin/example implementation - background image cropping (with flex width and height).

Line 
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=====================================================================================
13Copyright (C) 2015 Nick Halsey
14
15This program is free software; you can redistribute it and/or
16modify it under the terms of the GNU General Public License
17as published by the Free Software Foundation; either version 2
18of the License, or (at your option) any later version.
19
20This program is distributed in the hope that it will be useful,
21but WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23GNU General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with WordPress; if not, write to the Free Software
27Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
28=====================================================================================
29*/
30
31add_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 */
40function 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}