forked from devinsays/customizer-background-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customizer-background-control.php
executable file
·65 lines (53 loc) · 1.96 KB
/
customizer-background-control.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Plugin Name: Customizer Background Control
* Plugin URI: https://github.com/devinsays
* Author: Devin Price
* Author URI: http://wptheming.com
* Description: Registers a new custom customizer control for backgrounds
* Version: 1.0.0
* License: GNU General Public License v2.0 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
/**
* Register control scripts/styles.
*
* @since 1.0.0
* @access public
* @return void
*/
function customize_background_controls_register_scripts() {
// Since this can be used as a drop-in library
// We'll load the JS relative to this PHP file
$file = dirname( __FILE__ );
// Get the URL and path to wp-content
$content_url = untrailingslashit( dirname( dirname( get_stylesheet_directory_uri() ) ) );
$content_dir = untrailingslashit( WP_CONTENT_DIR );
// Fix path on Windows servers
$file = wp_normalize_path( $file );
$content_dir = wp_normalize_path( $content_dir );
$uri = str_replace( $content_dir, $content_url, $file );
wp_register_script(
'customizer-background-image-controls',
esc_url( $uri . '/js/customize-controls.js' ),
array( 'customize-controls' )
);
}
add_action( 'customize_controls_enqueue_scripts', 'customize_background_controls_register_scripts' );
/**
* Register customizer panels, sections, settings, and controls.
*
* @since 1.0.0
* @access public
* @param object $wp_customize
* @return void
*/
function customize_background_control_customize_register( $wp_customize ) {
// Load customizer background control class.
require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'customize/class-customize-background-image-control.php' );
// Register background control JS template.
$wp_customize->register_control_type( 'Customize_Custom_Background_Control' );
}
add_action( 'customize_register', 'customize_background_control_customize_register' );
// For testing purposes
require_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'example.php' );