Edit File by line
/home/barbar84/www/wp-inclu...
File: theme.php
* Specific post formats can be registered by passing an array of types
[3000] Fix | Delete
* to add_theme_support().
[3001] Fix | Delete
*
[3002] Fix | Delete
* Specific areas of HTML5 support *must* be passed via an array to add_theme_support().
[3003] Fix | Delete
*/
[3004] Fix | Delete
$type = $args[0];
[3005] Fix | Delete
return in_array( $type, $_wp_theme_features[ $feature ][0], true );
[3006] Fix | Delete
[3007] Fix | Delete
case 'custom-logo':
[3008] Fix | Delete
case 'custom-header':
[3009] Fix | Delete
case 'custom-background':
[3010] Fix | Delete
// Specific capabilities can be registered by passing an array to add_theme_support().
[3011] Fix | Delete
return ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) && $_wp_theme_features[ $feature ][0][ $args[0] ] );
[3012] Fix | Delete
}
[3013] Fix | Delete
[3014] Fix | Delete
/**
[3015] Fix | Delete
* Filters whether the current theme supports a specific feature.
[3016] Fix | Delete
*
[3017] Fix | Delete
* The dynamic portion of the hook name, `$feature`, refers to the specific
[3018] Fix | Delete
* theme feature. See add_theme_support() for the list of possible values.
[3019] Fix | Delete
*
[3020] Fix | Delete
* @since 3.4.0
[3021] Fix | Delete
*
[3022] Fix | Delete
* @param bool $supports Whether the current theme supports the given feature. Default true.
[3023] Fix | Delete
* @param array $args Array of arguments for the feature.
[3024] Fix | Delete
* @param string $feature The theme feature.
[3025] Fix | Delete
*/
[3026] Fix | Delete
return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
[3027] Fix | Delete
}
[3028] Fix | Delete
[3029] Fix | Delete
/**
[3030] Fix | Delete
* Checks a theme's support for a given feature before loading the functions which implement it.
[3031] Fix | Delete
*
[3032] Fix | Delete
* @since 2.9.0
[3033] Fix | Delete
*
[3034] Fix | Delete
* @param string $feature The feature being checked. See add_theme_support() for the list
[3035] Fix | Delete
* of possible values.
[3036] Fix | Delete
* @param string $include Path to the file.
[3037] Fix | Delete
* @return bool True if the current theme supports the supplied feature, false otherwise.
[3038] Fix | Delete
*/
[3039] Fix | Delete
function require_if_theme_supports( $feature, $include ) {
[3040] Fix | Delete
if ( current_theme_supports( $feature ) ) {
[3041] Fix | Delete
require $include;
[3042] Fix | Delete
return true;
[3043] Fix | Delete
}
[3044] Fix | Delete
return false;
[3045] Fix | Delete
}
[3046] Fix | Delete
[3047] Fix | Delete
/**
[3048] Fix | Delete
* Registers a theme feature for use in add_theme_support().
[3049] Fix | Delete
*
[3050] Fix | Delete
* This does not indicate that the current theme supports the feature, it only describes
[3051] Fix | Delete
* the feature's supported options.
[3052] Fix | Delete
*
[3053] Fix | Delete
* @since 5.5.0
[3054] Fix | Delete
*
[3055] Fix | Delete
* @see add_theme_support()
[3056] Fix | Delete
*
[3057] Fix | Delete
* @global array $_wp_registered_theme_features
[3058] Fix | Delete
*
[3059] Fix | Delete
* @param string $feature The name uniquely identifying the feature. See add_theme_support()
[3060] Fix | Delete
* for the list of possible values.
[3061] Fix | Delete
* @param array $args {
[3062] Fix | Delete
* Data used to describe the theme.
[3063] Fix | Delete
*
[3064] Fix | Delete
* @type string $type The type of data associated with this feature.
[3065] Fix | Delete
* Valid values are 'string', 'boolean', 'integer',
[3066] Fix | Delete
* 'number', 'array', and 'object'. Defaults to 'boolean'.
[3067] Fix | Delete
* @type boolean $variadic Does this feature utilize the variadic support
[3068] Fix | Delete
* of add_theme_support(), or are all arguments specified
[3069] Fix | Delete
* as the second parameter. Must be used with the "array" type.
[3070] Fix | Delete
* @type string $description A short description of the feature. Included in
[3071] Fix | Delete
* the Themes REST API schema. Intended for developers.
[3072] Fix | Delete
* @type bool|array $show_in_rest {
[3073] Fix | Delete
* Whether this feature should be included in the Themes REST API endpoint.
[3074] Fix | Delete
* Defaults to not being included. When registering an 'array' or 'object' type,
[3075] Fix | Delete
* this argument must be an array with the 'schema' key.
[3076] Fix | Delete
*
[3077] Fix | Delete
* @type array $schema Specifies the JSON Schema definition describing
[3078] Fix | Delete
* the feature. If any objects in the schema do not include
[3079] Fix | Delete
* the 'additionalProperties' keyword, it is set to false.
[3080] Fix | Delete
* @type string $name An alternate name to be used as the property name
[3081] Fix | Delete
* in the REST API.
[3082] Fix | Delete
* @type callable $prepare_callback A function used to format the theme support in the REST API.
[3083] Fix | Delete
* Receives the raw theme support value.
[3084] Fix | Delete
* }
[3085] Fix | Delete
* }
[3086] Fix | Delete
* @return true|WP_Error True if the theme feature was successfully registered, a WP_Error object if not.
[3087] Fix | Delete
*/
[3088] Fix | Delete
function register_theme_feature( $feature, $args = array() ) {
[3089] Fix | Delete
global $_wp_registered_theme_features;
[3090] Fix | Delete
[3091] Fix | Delete
if ( ! is_array( $_wp_registered_theme_features ) ) {
[3092] Fix | Delete
$_wp_registered_theme_features = array();
[3093] Fix | Delete
}
[3094] Fix | Delete
[3095] Fix | Delete
$defaults = array(
[3096] Fix | Delete
'type' => 'boolean',
[3097] Fix | Delete
'variadic' => false,
[3098] Fix | Delete
'description' => '',
[3099] Fix | Delete
'show_in_rest' => false,
[3100] Fix | Delete
);
[3101] Fix | Delete
[3102] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[3103] Fix | Delete
[3104] Fix | Delete
if ( true === $args['show_in_rest'] ) {
[3105] Fix | Delete
$args['show_in_rest'] = array();
[3106] Fix | Delete
}
[3107] Fix | Delete
[3108] Fix | Delete
if ( is_array( $args['show_in_rest'] ) ) {
[3109] Fix | Delete
$args['show_in_rest'] = wp_parse_args(
[3110] Fix | Delete
$args['show_in_rest'],
[3111] Fix | Delete
array(
[3112] Fix | Delete
'schema' => array(),
[3113] Fix | Delete
'name' => $feature,
[3114] Fix | Delete
'prepare_callback' => null,
[3115] Fix | Delete
)
[3116] Fix | Delete
);
[3117] Fix | Delete
}
[3118] Fix | Delete
[3119] Fix | Delete
if ( ! in_array( $args['type'], array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) {
[3120] Fix | Delete
return new WP_Error(
[3121] Fix | Delete
'invalid_type',
[3122] Fix | Delete
__( 'The feature "type" is not valid JSON Schema type.' )
[3123] Fix | Delete
);
[3124] Fix | Delete
}
[3125] Fix | Delete
[3126] Fix | Delete
if ( true === $args['variadic'] && 'array' !== $args['type'] ) {
[3127] Fix | Delete
return new WP_Error(
[3128] Fix | Delete
'variadic_must_be_array',
[3129] Fix | Delete
__( 'When registering a "variadic" theme feature, the "type" must be an "array".' )
[3130] Fix | Delete
);
[3131] Fix | Delete
}
[3132] Fix | Delete
[3133] Fix | Delete
if ( false !== $args['show_in_rest'] && in_array( $args['type'], array( 'array', 'object' ), true ) ) {
[3134] Fix | Delete
if ( ! is_array( $args['show_in_rest'] ) || empty( $args['show_in_rest']['schema'] ) ) {
[3135] Fix | Delete
return new WP_Error(
[3136] Fix | Delete
'missing_schema',
[3137] Fix | Delete
__( 'When registering an "array" or "object" feature to show in the REST API, the feature\'s schema must also be defined.' )
[3138] Fix | Delete
);
[3139] Fix | Delete
}
[3140] Fix | Delete
[3141] Fix | Delete
if ( 'array' === $args['type'] && ! isset( $args['show_in_rest']['schema']['items'] ) ) {
[3142] Fix | Delete
return new WP_Error(
[3143] Fix | Delete
'missing_schema_items',
[3144] Fix | Delete
__( 'When registering an "array" feature, the feature\'s schema must include the "items" keyword.' )
[3145] Fix | Delete
);
[3146] Fix | Delete
}
[3147] Fix | Delete
[3148] Fix | Delete
if ( 'object' === $args['type'] && ! isset( $args['show_in_rest']['schema']['properties'] ) ) {
[3149] Fix | Delete
return new WP_Error(
[3150] Fix | Delete
'missing_schema_properties',
[3151] Fix | Delete
__( 'When registering an "object" feature, the feature\'s schema must include the "properties" keyword.' )
[3152] Fix | Delete
);
[3153] Fix | Delete
}
[3154] Fix | Delete
}
[3155] Fix | Delete
[3156] Fix | Delete
if ( is_array( $args['show_in_rest'] ) ) {
[3157] Fix | Delete
if ( isset( $args['show_in_rest']['prepare_callback'] ) && ! is_callable( $args['show_in_rest']['prepare_callback'] ) ) {
[3158] Fix | Delete
return new WP_Error(
[3159] Fix | Delete
'invalid_rest_prepare_callback',
[3160] Fix | Delete
sprintf(
[3161] Fix | Delete
/* translators: %s: prepare_callback */
[3162] Fix | Delete
__( 'The "%s" must be a callable function.' ),
[3163] Fix | Delete
'prepare_callback'
[3164] Fix | Delete
)
[3165] Fix | Delete
);
[3166] Fix | Delete
}
[3167] Fix | Delete
[3168] Fix | Delete
$args['show_in_rest']['schema'] = wp_parse_args(
[3169] Fix | Delete
$args['show_in_rest']['schema'],
[3170] Fix | Delete
array(
[3171] Fix | Delete
'description' => $args['description'],
[3172] Fix | Delete
'type' => $args['type'],
[3173] Fix | Delete
'default' => false,
[3174] Fix | Delete
)
[3175] Fix | Delete
);
[3176] Fix | Delete
[3177] Fix | Delete
if ( is_bool( $args['show_in_rest']['schema']['default'] )
[3178] Fix | Delete
&& ! in_array( 'boolean', (array) $args['show_in_rest']['schema']['type'], true )
[3179] Fix | Delete
) {
[3180] Fix | Delete
// Automatically include the "boolean" type when the default value is a boolean.
[3181] Fix | Delete
$args['show_in_rest']['schema']['type'] = (array) $args['show_in_rest']['schema']['type'];
[3182] Fix | Delete
array_unshift( $args['show_in_rest']['schema']['type'], 'boolean' );
[3183] Fix | Delete
}
[3184] Fix | Delete
[3185] Fix | Delete
$args['show_in_rest']['schema'] = rest_default_additional_properties_to_false( $args['show_in_rest']['schema'] );
[3186] Fix | Delete
}
[3187] Fix | Delete
[3188] Fix | Delete
$_wp_registered_theme_features[ $feature ] = $args;
[3189] Fix | Delete
[3190] Fix | Delete
return true;
[3191] Fix | Delete
}
[3192] Fix | Delete
[3193] Fix | Delete
/**
[3194] Fix | Delete
* Gets the list of registered theme features.
[3195] Fix | Delete
*
[3196] Fix | Delete
* @since 5.5.0
[3197] Fix | Delete
*
[3198] Fix | Delete
* @global array $_wp_registered_theme_features
[3199] Fix | Delete
*
[3200] Fix | Delete
* @return array[] List of theme features, keyed by their name.
[3201] Fix | Delete
*/
[3202] Fix | Delete
function get_registered_theme_features() {
[3203] Fix | Delete
global $_wp_registered_theme_features;
[3204] Fix | Delete
[3205] Fix | Delete
if ( ! is_array( $_wp_registered_theme_features ) ) {
[3206] Fix | Delete
return array();
[3207] Fix | Delete
}
[3208] Fix | Delete
[3209] Fix | Delete
return $_wp_registered_theme_features;
[3210] Fix | Delete
}
[3211] Fix | Delete
[3212] Fix | Delete
/**
[3213] Fix | Delete
* Gets the registration config for a theme feature.
[3214] Fix | Delete
*
[3215] Fix | Delete
* @since 5.5.0
[3216] Fix | Delete
*
[3217] Fix | Delete
* @global array $_wp_registered_theme_features
[3218] Fix | Delete
*
[3219] Fix | Delete
* @param string $feature The feature name. See add_theme_support() for the list
[3220] Fix | Delete
* of possible values.
[3221] Fix | Delete
* @return array|null The registration args, or null if the feature was not registered.
[3222] Fix | Delete
*/
[3223] Fix | Delete
function get_registered_theme_feature( $feature ) {
[3224] Fix | Delete
global $_wp_registered_theme_features;
[3225] Fix | Delete
[3226] Fix | Delete
if ( ! is_array( $_wp_registered_theme_features ) ) {
[3227] Fix | Delete
return null;
[3228] Fix | Delete
}
[3229] Fix | Delete
[3230] Fix | Delete
return isset( $_wp_registered_theme_features[ $feature ] ) ? $_wp_registered_theme_features[ $feature ] : null;
[3231] Fix | Delete
}
[3232] Fix | Delete
[3233] Fix | Delete
/**
[3234] Fix | Delete
* Checks an attachment being deleted to see if it's a header or background image.
[3235] Fix | Delete
*
[3236] Fix | Delete
* If true it removes the theme modification which would be pointing at the deleted
[3237] Fix | Delete
* attachment.
[3238] Fix | Delete
*
[3239] Fix | Delete
* @access private
[3240] Fix | Delete
* @since 3.0.0
[3241] Fix | Delete
* @since 4.3.0 Also removes `header_image_data`.
[3242] Fix | Delete
* @since 4.5.0 Also removes custom logo theme mods.
[3243] Fix | Delete
*
[3244] Fix | Delete
* @param int $id The attachment ID.
[3245] Fix | Delete
*/
[3246] Fix | Delete
function _delete_attachment_theme_mod( $id ) {
[3247] Fix | Delete
$attachment_image = wp_get_attachment_url( $id );
[3248] Fix | Delete
$header_image = get_header_image();
[3249] Fix | Delete
$background_image = get_background_image();
[3250] Fix | Delete
$custom_logo_id = get_theme_mod( 'custom_logo' );
[3251] Fix | Delete
[3252] Fix | Delete
if ( $custom_logo_id && $custom_logo_id == $id ) {
[3253] Fix | Delete
remove_theme_mod( 'custom_logo' );
[3254] Fix | Delete
remove_theme_mod( 'header_text' );
[3255] Fix | Delete
}
[3256] Fix | Delete
[3257] Fix | Delete
if ( $header_image && $header_image == $attachment_image ) {
[3258] Fix | Delete
remove_theme_mod( 'header_image' );
[3259] Fix | Delete
remove_theme_mod( 'header_image_data' );
[3260] Fix | Delete
}
[3261] Fix | Delete
[3262] Fix | Delete
if ( $background_image && $background_image == $attachment_image ) {
[3263] Fix | Delete
remove_theme_mod( 'background_image' );
[3264] Fix | Delete
}
[3265] Fix | Delete
}
[3266] Fix | Delete
[3267] Fix | Delete
/**
[3268] Fix | Delete
* Checks if a theme has been changed and runs 'after_switch_theme' hook on the next WP load.
[3269] Fix | Delete
*
[3270] Fix | Delete
* See {@see 'after_switch_theme'}.
[3271] Fix | Delete
*
[3272] Fix | Delete
* @since 3.3.0
[3273] Fix | Delete
*/
[3274] Fix | Delete
function check_theme_switched() {
[3275] Fix | Delete
$stylesheet = get_option( 'theme_switched' );
[3276] Fix | Delete
if ( $stylesheet ) {
[3277] Fix | Delete
$old_theme = wp_get_theme( $stylesheet );
[3278] Fix | Delete
[3279] Fix | Delete
// Prevent widget & menu mapping from running since Customizer already called it up front.
[3280] Fix | Delete
if ( get_option( 'theme_switched_via_customizer' ) ) {
[3281] Fix | Delete
remove_action( 'after_switch_theme', '_wp_menus_changed' );
[3282] Fix | Delete
remove_action( 'after_switch_theme', '_wp_sidebars_changed' );
[3283] Fix | Delete
update_option( 'theme_switched_via_customizer', false );
[3284] Fix | Delete
}
[3285] Fix | Delete
[3286] Fix | Delete
if ( $old_theme->exists() ) {
[3287] Fix | Delete
/**
[3288] Fix | Delete
* Fires on the first WP load after a theme switch if the old theme still exists.
[3289] Fix | Delete
*
[3290] Fix | Delete
* This action fires multiple times and the parameters differs
[3291] Fix | Delete
* according to the context, if the old theme exists or not.
[3292] Fix | Delete
* If the old theme is missing, the parameter will be the slug
[3293] Fix | Delete
* of the old theme.
[3294] Fix | Delete
*
[3295] Fix | Delete
* @since 3.3.0
[3296] Fix | Delete
*
[3297] Fix | Delete
* @param string $old_name Old theme name.
[3298] Fix | Delete
* @param WP_Theme $old_theme WP_Theme instance of the old theme.
[3299] Fix | Delete
*/
[3300] Fix | Delete
do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme );
[3301] Fix | Delete
} else {
[3302] Fix | Delete
/** This action is documented in wp-includes/theme.php */
[3303] Fix | Delete
do_action( 'after_switch_theme', $stylesheet, $old_theme );
[3304] Fix | Delete
}
[3305] Fix | Delete
flush_rewrite_rules();
[3306] Fix | Delete
[3307] Fix | Delete
update_option( 'theme_switched', false );
[3308] Fix | Delete
}
[3309] Fix | Delete
}
[3310] Fix | Delete
[3311] Fix | Delete
/**
[3312] Fix | Delete
* Includes and instantiates the WP_Customize_Manager class.
[3313] Fix | Delete
*
[3314] Fix | Delete
* Loads the Customizer at plugins_loaded when accessing the customize.php admin
[3315] Fix | Delete
* page or when any request includes a wp_customize=on param or a customize_changeset
[3316] Fix | Delete
* param (a UUID). This param is a signal for whether to bootstrap the Customizer when
[3317] Fix | Delete
* WordPress is loading, especially in the Customizer preview
[3318] Fix | Delete
* or when making Customizer Ajax requests for widgets or menus.
[3319] Fix | Delete
*
[3320] Fix | Delete
* @since 3.4.0
[3321] Fix | Delete
*
[3322] Fix | Delete
* @global WP_Customize_Manager $wp_customize
[3323] Fix | Delete
*/
[3324] Fix | Delete
function _wp_customize_include() {
[3325] Fix | Delete
[3326] Fix | Delete
$is_customize_admin_page = ( is_admin() && 'customize.php' === basename( $_SERVER['PHP_SELF'] ) );
[3327] Fix | Delete
$should_include = (
[3328] Fix | Delete
$is_customize_admin_page
[3329] Fix | Delete
||
[3330] Fix | Delete
( isset( $_REQUEST['wp_customize'] ) && 'on' === $_REQUEST['wp_customize'] )
[3331] Fix | Delete
||
[3332] Fix | Delete
( ! empty( $_GET['customize_changeset_uuid'] ) || ! empty( $_POST['customize_changeset_uuid'] ) )
[3333] Fix | Delete
);
[3334] Fix | Delete
[3335] Fix | Delete
if ( ! $should_include ) {
[3336] Fix | Delete
return;
[3337] Fix | Delete
}
[3338] Fix | Delete
[3339] Fix | Delete
/*
[3340] Fix | Delete
* Note that wp_unslash() is not being used on the input vars because it is
[3341] Fix | Delete
* called before wp_magic_quotes() gets called. Besides this fact, none of
[3342] Fix | Delete
* the values should contain any characters needing slashes anyway.
[3343] Fix | Delete
*/
[3344] Fix | Delete
$keys = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' );
[3345] Fix | Delete
$input_vars = array_merge(
[3346] Fix | Delete
wp_array_slice_assoc( $_GET, $keys ),
[3347] Fix | Delete
wp_array_slice_assoc( $_POST, $keys )
[3348] Fix | Delete
);
[3349] Fix | Delete
[3350] Fix | Delete
$theme = null;
[3351] Fix | Delete
$autosaved = null;
[3352] Fix | Delete
$messenger_channel = null;
[3353] Fix | Delete
[3354] Fix | Delete
// Value false indicates UUID should be determined after_setup_theme
[3355] Fix | Delete
// to either re-use existing saved changeset or else generate a new UUID if none exists.
[3356] Fix | Delete
$changeset_uuid = false;
[3357] Fix | Delete
[3358] Fix | Delete
// Set initially fo false since defaults to true for back-compat;
[3359] Fix | Delete
// can be overridden via the customize_changeset_branching filter.
[3360] Fix | Delete
$branching = false;
[3361] Fix | Delete
[3362] Fix | Delete
if ( $is_customize_admin_page && isset( $input_vars['changeset_uuid'] ) ) {
[3363] Fix | Delete
$changeset_uuid = sanitize_key( $input_vars['changeset_uuid'] );
[3364] Fix | Delete
} elseif ( ! empty( $input_vars['customize_changeset_uuid'] ) ) {
[3365] Fix | Delete
$changeset_uuid = sanitize_key( $input_vars['customize_changeset_uuid'] );
[3366] Fix | Delete
}
[3367] Fix | Delete
[3368] Fix | Delete
// Note that theme will be sanitized via WP_Theme.
[3369] Fix | Delete
if ( $is_customize_admin_page && isset( $input_vars['theme'] ) ) {
[3370] Fix | Delete
$theme = $input_vars['theme'];
[3371] Fix | Delete
} elseif ( isset( $input_vars['customize_theme'] ) ) {
[3372] Fix | Delete
$theme = $input_vars['customize_theme'];
[3373] Fix | Delete
}
[3374] Fix | Delete
[3375] Fix | Delete
if ( ! empty( $input_vars['customize_autosaved'] ) ) {
[3376] Fix | Delete
$autosaved = true;
[3377] Fix | Delete
}
[3378] Fix | Delete
[3379] Fix | Delete
if ( isset( $input_vars['customize_messenger_channel'] ) ) {
[3380] Fix | Delete
$messenger_channel = sanitize_key( $input_vars['customize_messenger_channel'] );
[3381] Fix | Delete
}
[3382] Fix | Delete
[3383] Fix | Delete
/*
[3384] Fix | Delete
* Note that settings must be previewed even outside the customizer preview
[3385] Fix | Delete
* and also in the customizer pane itself. This is to enable loading an existing
[3386] Fix | Delete
* changeset into the customizer. Previewing the settings only has to be prevented
[3387] Fix | Delete
* here in the case of a customize_save action because this will cause WP to think
[3388] Fix | Delete
* there is nothing changed that needs to be saved.
[3389] Fix | Delete
*/
[3390] Fix | Delete
$is_customize_save_action = (
[3391] Fix | Delete
wp_doing_ajax()
[3392] Fix | Delete
&&
[3393] Fix | Delete
isset( $_REQUEST['action'] )
[3394] Fix | Delete
&&
[3395] Fix | Delete
'customize_save' === wp_unslash( $_REQUEST['action'] )
[3396] Fix | Delete
);
[3397] Fix | Delete
$settings_previewed = ! $is_customize_save_action;
[3398] Fix | Delete
[3399] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
[3400] Fix | Delete
$GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed', 'autosaved', 'branching' ) );
[3401] Fix | Delete
}
[3402] Fix | Delete
[3403] Fix | Delete
/**
[3404] Fix | Delete
* Publishes a snapshot's changes.
[3405] Fix | Delete
*
[3406] Fix | Delete
* @since 4.7.0
[3407] Fix | Delete
* @access private
[3408] Fix | Delete
*
[3409] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[3410] Fix | Delete
* @global WP_Customize_Manager $wp_customize Customizer instance.
[3411] Fix | Delete
*
[3412] Fix | Delete
* @param string $new_status New post status.
[3413] Fix | Delete
* @param string $old_status Old post status.
[3414] Fix | Delete
* @param WP_Post $changeset_post Changeset post object.
[3415] Fix | Delete
*/
[3416] Fix | Delete
function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) {
[3417] Fix | Delete
global $wp_customize, $wpdb;
[3418] Fix | Delete
[3419] Fix | Delete
$is_publishing_changeset = (
[3420] Fix | Delete
'customize_changeset' === $changeset_post->post_type
[3421] Fix | Delete
&&
[3422] Fix | Delete
'publish' === $new_status
[3423] Fix | Delete
&&
[3424] Fix | Delete
'publish' !== $old_status
[3425] Fix | Delete
);
[3426] Fix | Delete
if ( ! $is_publishing_changeset ) {
[3427] Fix | Delete
return;
[3428] Fix | Delete
}
[3429] Fix | Delete
[3430] Fix | Delete
if ( empty( $wp_customize ) ) {
[3431] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
[3432] Fix | Delete
$wp_customize = new WP_Customize_Manager(
[3433] Fix | Delete
array(
[3434] Fix | Delete
'changeset_uuid' => $changeset_post->post_name,
[3435] Fix | Delete
'settings_previewed' => false,
[3436] Fix | Delete
)
[3437] Fix | Delete
);
[3438] Fix | Delete
}
[3439] Fix | Delete
[3440] Fix | Delete
if ( ! did_action( 'customize_register' ) ) {
[3441] Fix | Delete
/*
[3442] Fix | Delete
* When running from CLI or Cron, the customize_register action will need
[3443] Fix | Delete
* to be triggered in order for core, themes, and plugins to register their
[3444] Fix | Delete
* settings. Normally core will add_action( 'customize_register' ) at
[3445] Fix | Delete
* priority 10 to register the core settings, and if any themes/plugins
[3446] Fix | Delete
* also add_action( 'customize_register' ) at the same priority, they
[3447] Fix | Delete
* will have a $wp_customize with those settings registered since they
[3448] Fix | Delete
* call add_action() afterward, normally. However, when manually doing
[3449] Fix | Delete
* the customize_register action after the setup_theme, then the order
[3450] Fix | Delete
* will be reversed for two actions added at priority 10, resulting in
[3451] Fix | Delete
* the core settings no longer being available as expected to themes/plugins.
[3452] Fix | Delete
* So the following manually calls the method that registers the core
[3453] Fix | Delete
* settings up front before doing the action.
[3454] Fix | Delete
*/
[3455] Fix | Delete
remove_action( 'customize_register', array( $wp_customize, 'register_controls' ) );
[3456] Fix | Delete
$wp_customize->register_controls();
[3457] Fix | Delete
[3458] Fix | Delete
/** This filter is documented in /wp-includes/class-wp-customize-manager.php */
[3459] Fix | Delete
do_action( 'customize_register', $wp_customize );
[3460] Fix | Delete
}
[3461] Fix | Delete
$wp_customize->_publish_changeset_values( $changeset_post->ID );
[3462] Fix | Delete
[3463] Fix | Delete
/*
[3464] Fix | Delete
* Trash the changeset post if revisions are not enabled. Unpublished
[3465] Fix | Delete
* changesets by default get garbage collected due to the auto-draft status.
[3466] Fix | Delete
* When a changeset post is published, however, it would no longer get cleaned
[3467] Fix | Delete
* out. This is a problem when the changeset posts are never displayed anywhere,
[3468] Fix | Delete
* since they would just be endlessly piling up. So here we use the revisions
[3469] Fix | Delete
* feature to indicate whether or not a published changeset should get trashed
[3470] Fix | Delete
* and thus garbage collected.
[3471] Fix | Delete
*/
[3472] Fix | Delete
if ( ! wp_revisions_enabled( $changeset_post ) ) {
[3473] Fix | Delete
$wp_customize->trash_changeset_post( $changeset_post->ID );
[3474] Fix | Delete
}
[3475] Fix | Delete
}
[3476] Fix | Delete
[3477] Fix | Delete
/**
[3478] Fix | Delete
* Filters changeset post data upon insert to ensure post_name is intact.
[3479] Fix | Delete
*
[3480] Fix | Delete
* This is needed to prevent the post_name from being dropped when the post is
[3481] Fix | Delete
* transitioned into pending status by a contributor.
[3482] Fix | Delete
*
[3483] Fix | Delete
* @since 4.7.0
[3484] Fix | Delete
*
[3485] Fix | Delete
* @see wp_insert_post()
[3486] Fix | Delete
*
[3487] Fix | Delete
* @param array $post_data An array of slashed post data.
[3488] Fix | Delete
* @param array $supplied_post_data An array of sanitized, but otherwise unmodified post data.
[3489] Fix | Delete
* @return array Filtered data.
[3490] Fix | Delete
*/
[3491] Fix | Delete
function _wp_customize_changeset_filter_insert_post_data( $post_data, $supplied_post_data ) {
[3492] Fix | Delete
if ( isset( $post_data['post_type'] ) && 'customize_changeset' === $post_data['post_type'] ) {
[3493] Fix | Delete
[3494] Fix | Delete
// Prevent post_name from being dropped, such as when contributor saves a changeset post as pending.
[3495] Fix | Delete
if ( empty( $post_data['post_name'] ) && ! empty( $supplied_post_data['post_name'] ) ) {
[3496] Fix | Delete
$post_data['post_name'] = $supplied_post_data['post_name'];
[3497] Fix | Delete
}
[3498] Fix | Delete
}
[3499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function