summaryrefslogtreecommitdiff
blob: 940ef0ba311fb9fc1462c3e271be9db2b14fc2f3 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php

/**
 * Module Name: Custom CSS
 * Module Description: Tweak your site’s CSS without modifying your theme.
 * Sort Order: 2
 * First Introduced: 1.7
 * Requires Connection: No
 * Auto Activate: Yes
 * Module Tags: Appearance
 * Feature: Appearance
 * Additional Search Queries: css, customize, custom, style, editor, less, sass, preprocessor, font, mobile, appearance, theme, stylesheet
 */

function jetpack_load_custom_css() {
	// If WordPress has the core version of Custom CSS, load our new version.
	// @see https://core.trac.wordpress.org/changeset/38829
	if ( function_exists( 'wp_get_custom_css' ) ) {
		if ( ! function_exists( 'wp_update_custom_css_post' ) ) {
			wp_die( 'Please run a SVN up to get the latest version of trunk, or update to at least 4.7 RC1' );
		}
		if ( ! Jetpack_Options::get_option( 'custom_css_4.7_migration' ) ) {
			include_once dirname( __FILE__ ) . '/custom-css/migrate-to-core.php';
		}

		// TODO: DELETE THIS
		else {
			if ( defined( 'WP_CLI' ) && WP_CLI ) {
				function jetpack_custom_css_undo_data_migration_cli() {
					Jetpack_Options::delete_option( 'custom_css_4.7_migration' );
					WP_CLI::success( __( 'Option deleted, re-migrate via `wp jetpack custom-css migrate`.', 'jetpack' ) );
				}
				WP_CLI::add_command( 'jetpack custom-css undo-migrate', 'jetpack_custom_css_undo_data_migration_cli' );
			}
		}
		// TODO: END DELETE THIS

		include_once dirname( __FILE__ ) . '/custom-css/custom-css/preprocessors.php';
		include_once dirname( __FILE__ ) . '/custom-css/custom-css-4.7.php';
		return;
	}

	include_once dirname( __FILE__ ) . "/custom-css/custom-css.php";
	add_action( 'init', array( 'Jetpack_Custom_CSS', 'init' ) );
}

add_action( 'jetpack_modules_loaded', 'custom_css_loaded' );

function custom_css_loaded() {
	Jetpack::enable_module_configurable( __FILE__ );
	Jetpack::module_configuration_load( __FILE__, 'custom_css_configuration_load' );
	add_filter( 'jetpack_module_configuration_url_custom-css', 'jetpack_custom_css_configuration_url' );
}

/**
 * Overrides default configuration url
 *
 * @uses admin_url
 * @return string module settings URL
 */
function jetpack_custom_css_configuration_url() {
	// Redirect to Core's CSS editor in the customizer if the feature is available.
	if ( function_exists( 'wp_get_custom_css' ) ) {
		$configuration_link = Jetpack_Custom_CSS_Enhancements::customizer_link(
			array(
				'return_url' => wp_get_referer(),
			)
		);
	} else {
		$configuration_link = admin_url( 'themes.php?page=editcss#settingsdiv' );
	}

	return $configuration_link;
}

function custom_css_configuration_load() {
	// Redirect to Core's CSS editor in the customizer if the feature is available.
	if ( function_exists( 'wp_get_custom_css' ) ) {
		$configuration_link = Jetpack_Custom_CSS_Enhancements::customizer_link(
			array(
				'return_url' => wp_get_referer(),
			)
		);
	} else {
		$configuration_link = admin_url( 'themes.php?page=editcss#settingsdiv' );
	}

	wp_safe_redirect( $configuration_link );
	exit;
}

jetpack_load_custom_css();