Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-inclu...
File: class-wp-customize-manager.php
}
[2500] Fix | Delete
$changeset_date_gmt = get_gmt_from_date( $changeset_date );
[2501] Fix | Delete
} else {
[2502] Fix | Delete
$timestamp = strtotime( $changeset_date );
[2503] Fix | Delete
if ( ! $timestamp ) {
[2504] Fix | Delete
wp_send_json_error( 'bad_customize_changeset_date', 400 );
[2505] Fix | Delete
}
[2506] Fix | Delete
$changeset_date_gmt = gmdate( 'Y-m-d H:i:s', $timestamp );
[2507] Fix | Delete
}
[2508] Fix | Delete
}
[2509] Fix | Delete
[2510] Fix | Delete
$lock_user_id = null;
[2511] Fix | Delete
$autosave = ! empty( $_POST['customize_changeset_autosave'] );
[2512] Fix | Delete
if ( ! $is_new_changeset ) {
[2513] Fix | Delete
$lock_user_id = wp_check_post_lock( $this->changeset_post_id() );
[2514] Fix | Delete
}
[2515] Fix | Delete
[2516] Fix | Delete
// Force request to autosave when changeset is locked.
[2517] Fix | Delete
if ( $lock_user_id && ! $autosave ) {
[2518] Fix | Delete
$autosave = true;
[2519] Fix | Delete
$changeset_status = null;
[2520] Fix | Delete
$changeset_date_gmt = null;
[2521] Fix | Delete
}
[2522] Fix | Delete
[2523] Fix | Delete
if ( $autosave && ! defined( 'DOING_AUTOSAVE' ) ) { // Back-compat.
[2524] Fix | Delete
define( 'DOING_AUTOSAVE', true );
[2525] Fix | Delete
}
[2526] Fix | Delete
[2527] Fix | Delete
$autosaved = false;
[2528] Fix | Delete
$r = $this->save_changeset_post(
[2529] Fix | Delete
array(
[2530] Fix | Delete
'status' => $changeset_status,
[2531] Fix | Delete
'title' => $changeset_title,
[2532] Fix | Delete
'date_gmt' => $changeset_date_gmt,
[2533] Fix | Delete
'data' => $input_changeset_data,
[2534] Fix | Delete
'autosave' => $autosave,
[2535] Fix | Delete
)
[2536] Fix | Delete
);
[2537] Fix | Delete
if ( $autosave && ! is_wp_error( $r ) ) {
[2538] Fix | Delete
$autosaved = true;
[2539] Fix | Delete
}
[2540] Fix | Delete
[2541] Fix | Delete
// If the changeset was locked and an autosave request wasn't itself an error, then now explicitly return with a failure.
[2542] Fix | Delete
if ( $lock_user_id && ! is_wp_error( $r ) ) {
[2543] Fix | Delete
$r = new WP_Error(
[2544] Fix | Delete
'changeset_locked',
[2545] Fix | Delete
__( 'Changeset is being edited by other user.' ),
[2546] Fix | Delete
array(
[2547] Fix | Delete
'lock_user' => $this->get_lock_user_data( $lock_user_id ),
[2548] Fix | Delete
)
[2549] Fix | Delete
);
[2550] Fix | Delete
}
[2551] Fix | Delete
[2552] Fix | Delete
if ( is_wp_error( $r ) ) {
[2553] Fix | Delete
$response = array(
[2554] Fix | Delete
'message' => $r->get_error_message(),
[2555] Fix | Delete
'code' => $r->get_error_code(),
[2556] Fix | Delete
);
[2557] Fix | Delete
if ( is_array( $r->get_error_data() ) ) {
[2558] Fix | Delete
$response = array_merge( $response, $r->get_error_data() );
[2559] Fix | Delete
} else {
[2560] Fix | Delete
$response['data'] = $r->get_error_data();
[2561] Fix | Delete
}
[2562] Fix | Delete
} else {
[2563] Fix | Delete
$response = $r;
[2564] Fix | Delete
$changeset_post = get_post( $this->changeset_post_id() );
[2565] Fix | Delete
[2566] Fix | Delete
// Dismiss all other auto-draft changeset posts for this user (they serve like autosave revisions), as there should only be one.
[2567] Fix | Delete
if ( $is_new_changeset ) {
[2568] Fix | Delete
$this->dismiss_user_auto_draft_changesets();
[2569] Fix | Delete
}
[2570] Fix | Delete
[2571] Fix | Delete
// Note that if the changeset status was publish, then it will get set to Trash if revisions are not supported.
[2572] Fix | Delete
$response['changeset_status'] = $changeset_post->post_status;
[2573] Fix | Delete
if ( $is_publish && 'trash' === $response['changeset_status'] ) {
[2574] Fix | Delete
$response['changeset_status'] = 'publish';
[2575] Fix | Delete
}
[2576] Fix | Delete
[2577] Fix | Delete
if ( 'publish' !== $response['changeset_status'] ) {
[2578] Fix | Delete
$this->set_changeset_lock( $changeset_post->ID );
[2579] Fix | Delete
}
[2580] Fix | Delete
[2581] Fix | Delete
if ( 'future' === $response['changeset_status'] ) {
[2582] Fix | Delete
$response['changeset_date'] = $changeset_post->post_date;
[2583] Fix | Delete
}
[2584] Fix | Delete
[2585] Fix | Delete
if ( 'publish' === $response['changeset_status'] || 'trash' === $response['changeset_status'] ) {
[2586] Fix | Delete
$response['next_changeset_uuid'] = wp_generate_uuid4();
[2587] Fix | Delete
}
[2588] Fix | Delete
}
[2589] Fix | Delete
[2590] Fix | Delete
if ( $autosave ) {
[2591] Fix | Delete
$response['autosaved'] = $autosaved;
[2592] Fix | Delete
}
[2593] Fix | Delete
[2594] Fix | Delete
if ( isset( $response['setting_validities'] ) ) {
[2595] Fix | Delete
$response['setting_validities'] = array_map( array( $this, 'prepare_setting_validity_for_js' ), $response['setting_validities'] );
[2596] Fix | Delete
}
[2597] Fix | Delete
[2598] Fix | Delete
/**
[2599] Fix | Delete
* Filters response data for a successful customize_save Ajax request.
[2600] Fix | Delete
*
[2601] Fix | Delete
* This filter does not apply if there was a nonce or authentication failure.
[2602] Fix | Delete
*
[2603] Fix | Delete
* @since 4.2.0
[2604] Fix | Delete
*
[2605] Fix | Delete
* @param array $response Additional information passed back to the 'saved'
[2606] Fix | Delete
* event on `wp.customize`.
[2607] Fix | Delete
* @param WP_Customize_Manager $manager WP_Customize_Manager instance.
[2608] Fix | Delete
*/
[2609] Fix | Delete
$response = apply_filters( 'customize_save_response', $response, $this );
[2610] Fix | Delete
[2611] Fix | Delete
if ( is_wp_error( $r ) ) {
[2612] Fix | Delete
wp_send_json_error( $response );
[2613] Fix | Delete
} else {
[2614] Fix | Delete
wp_send_json_success( $response );
[2615] Fix | Delete
}
[2616] Fix | Delete
}
[2617] Fix | Delete
[2618] Fix | Delete
/**
[2619] Fix | Delete
* Saves the post for the loaded changeset.
[2620] Fix | Delete
*
[2621] Fix | Delete
* @since 4.7.0
[2622] Fix | Delete
*
[2623] Fix | Delete
* @param array $args {
[2624] Fix | Delete
* Args for changeset post.
[2625] Fix | Delete
*
[2626] Fix | Delete
* @type array $data Optional additional changeset data. Values will be merged on top of any existing post values.
[2627] Fix | Delete
* @type string $status Post status. Optional. If supplied, the save will be transactional and a post revision will be allowed.
[2628] Fix | Delete
* @type string $title Post title. Optional.
[2629] Fix | Delete
* @type string $date_gmt Date in GMT. Optional.
[2630] Fix | Delete
* @type int $user_id ID for user who is saving the changeset. Optional, defaults to the current user ID.
[2631] Fix | Delete
* @type bool $starter_content Whether the data is starter content. If false (default), then $starter_content will be cleared for any $data being saved.
[2632] Fix | Delete
* @type bool $autosave Whether this is a request to create an autosave revision.
[2633] Fix | Delete
* }
[2634] Fix | Delete
*
[2635] Fix | Delete
* @return array|WP_Error Returns array on success and WP_Error with array data on error.
[2636] Fix | Delete
*/
[2637] Fix | Delete
public function save_changeset_post( $args = array() ) {
[2638] Fix | Delete
[2639] Fix | Delete
$args = array_merge(
[2640] Fix | Delete
array(
[2641] Fix | Delete
'status' => null,
[2642] Fix | Delete
'title' => null,
[2643] Fix | Delete
'data' => array(),
[2644] Fix | Delete
'date_gmt' => null,
[2645] Fix | Delete
'user_id' => get_current_user_id(),
[2646] Fix | Delete
'starter_content' => false,
[2647] Fix | Delete
'autosave' => false,
[2648] Fix | Delete
),
[2649] Fix | Delete
$args
[2650] Fix | Delete
);
[2651] Fix | Delete
[2652] Fix | Delete
$changeset_post_id = $this->changeset_post_id();
[2653] Fix | Delete
$existing_changeset_data = array();
[2654] Fix | Delete
if ( $changeset_post_id ) {
[2655] Fix | Delete
$existing_status = get_post_status( $changeset_post_id );
[2656] Fix | Delete
if ( 'publish' === $existing_status || 'trash' === $existing_status ) {
[2657] Fix | Delete
return new WP_Error(
[2658] Fix | Delete
'changeset_already_published',
[2659] Fix | Delete
__( 'The previous set of changes has already been published. Please try saving your current set of changes again.' ),
[2660] Fix | Delete
array(
[2661] Fix | Delete
'next_changeset_uuid' => wp_generate_uuid4(),
[2662] Fix | Delete
)
[2663] Fix | Delete
);
[2664] Fix | Delete
}
[2665] Fix | Delete
[2666] Fix | Delete
$existing_changeset_data = $this->get_changeset_post_data( $changeset_post_id );
[2667] Fix | Delete
if ( is_wp_error( $existing_changeset_data ) ) {
[2668] Fix | Delete
return $existing_changeset_data;
[2669] Fix | Delete
}
[2670] Fix | Delete
}
[2671] Fix | Delete
[2672] Fix | Delete
// Fail if attempting to publish but publish hook is missing.
[2673] Fix | Delete
if ( 'publish' === $args['status'] && false === has_action( 'transition_post_status', '_wp_customize_publish_changeset' ) ) {
[2674] Fix | Delete
return new WP_Error( 'missing_publish_callback' );
[2675] Fix | Delete
}
[2676] Fix | Delete
[2677] Fix | Delete
// Validate date.
[2678] Fix | Delete
$now = gmdate( 'Y-m-d H:i:59' );
[2679] Fix | Delete
if ( $args['date_gmt'] ) {
[2680] Fix | Delete
$is_future_dated = ( mysql2date( 'U', $args['date_gmt'], false ) > mysql2date( 'U', $now, false ) );
[2681] Fix | Delete
if ( ! $is_future_dated ) {
[2682] Fix | Delete
return new WP_Error( 'not_future_date', __( 'You must supply a future date to schedule.' ) ); // Only future dates are allowed.
[2683] Fix | Delete
}
[2684] Fix | Delete
[2685] Fix | Delete
if ( ! $this->is_theme_active() && ( 'future' === $args['status'] || $is_future_dated ) ) {
[2686] Fix | Delete
return new WP_Error( 'cannot_schedule_theme_switches' ); // This should be allowed in the future, when theme is a regular setting.
[2687] Fix | Delete
}
[2688] Fix | Delete
$will_remain_auto_draft = ( ! $args['status'] && ( ! $changeset_post_id || 'auto-draft' === get_post_status( $changeset_post_id ) ) );
[2689] Fix | Delete
if ( $will_remain_auto_draft ) {
[2690] Fix | Delete
return new WP_Error( 'cannot_supply_date_for_auto_draft_changeset' );
[2691] Fix | Delete
}
[2692] Fix | Delete
} elseif ( $changeset_post_id && 'future' === $args['status'] ) {
[2693] Fix | Delete
[2694] Fix | Delete
// Fail if the new status is future but the existing post's date is not in the future.
[2695] Fix | Delete
$changeset_post = get_post( $changeset_post_id );
[2696] Fix | Delete
if ( mysql2date( 'U', $changeset_post->post_date_gmt, false ) <= mysql2date( 'U', $now, false ) ) {
[2697] Fix | Delete
return new WP_Error( 'not_future_date', __( 'You must supply a future date to schedule.' ) );
[2698] Fix | Delete
}
[2699] Fix | Delete
}
[2700] Fix | Delete
[2701] Fix | Delete
if ( ! empty( $is_future_dated ) && 'publish' === $args['status'] ) {
[2702] Fix | Delete
$args['status'] = 'future';
[2703] Fix | Delete
}
[2704] Fix | Delete
[2705] Fix | Delete
// Validate autosave param. See _wp_post_revision_fields() for why these fields are disallowed.
[2706] Fix | Delete
if ( $args['autosave'] ) {
[2707] Fix | Delete
if ( $args['date_gmt'] ) {
[2708] Fix | Delete
return new WP_Error( 'illegal_autosave_with_date_gmt' );
[2709] Fix | Delete
} elseif ( $args['status'] ) {
[2710] Fix | Delete
return new WP_Error( 'illegal_autosave_with_status' );
[2711] Fix | Delete
} elseif ( $args['user_id'] && get_current_user_id() !== $args['user_id'] ) {
[2712] Fix | Delete
return new WP_Error( 'illegal_autosave_with_non_current_user' );
[2713] Fix | Delete
}
[2714] Fix | Delete
}
[2715] Fix | Delete
[2716] Fix | Delete
// The request was made via wp.customize.previewer.save().
[2717] Fix | Delete
$update_transactionally = (bool) $args['status'];
[2718] Fix | Delete
$allow_revision = (bool) $args['status'];
[2719] Fix | Delete
[2720] Fix | Delete
// Amend post values with any supplied data.
[2721] Fix | Delete
foreach ( $args['data'] as $setting_id => $setting_params ) {
[2722] Fix | Delete
if ( is_array( $setting_params ) && array_key_exists( 'value', $setting_params ) ) {
[2723] Fix | Delete
$this->set_post_value( $setting_id, $setting_params['value'] ); // Add to post values so that they can be validated and sanitized.
[2724] Fix | Delete
}
[2725] Fix | Delete
}
[2726] Fix | Delete
[2727] Fix | Delete
// Note that in addition to post data, this will include any stashed theme mods.
[2728] Fix | Delete
$post_values = $this->unsanitized_post_values(
[2729] Fix | Delete
array(
[2730] Fix | Delete
'exclude_changeset' => true,
[2731] Fix | Delete
'exclude_post_data' => false,
[2732] Fix | Delete
)
[2733] Fix | Delete
);
[2734] Fix | Delete
$this->add_dynamic_settings( array_keys( $post_values ) ); // Ensure settings get created even if they lack an input value.
[2735] Fix | Delete
[2736] Fix | Delete
/*
[2737] Fix | Delete
* Get list of IDs for settings that have values different from what is currently
[2738] Fix | Delete
* saved in the changeset. By skipping any values that are already the same, the
[2739] Fix | Delete
* subset of changed settings can be passed into validate_setting_values to prevent
[2740] Fix | Delete
* an underprivileged modifying a single setting for which they have the capability
[2741] Fix | Delete
* from being blocked from saving. This also prevents a user from touching of the
[2742] Fix | Delete
* previous saved settings and overriding the associated user_id if they made no change.
[2743] Fix | Delete
*/
[2744] Fix | Delete
$changed_setting_ids = array();
[2745] Fix | Delete
foreach ( $post_values as $setting_id => $setting_value ) {
[2746] Fix | Delete
$setting = $this->get_setting( $setting_id );
[2747] Fix | Delete
[2748] Fix | Delete
if ( $setting && 'theme_mod' === $setting->type ) {
[2749] Fix | Delete
$prefixed_setting_id = $this->get_stylesheet() . '::' . $setting->id;
[2750] Fix | Delete
} else {
[2751] Fix | Delete
$prefixed_setting_id = $setting_id;
[2752] Fix | Delete
}
[2753] Fix | Delete
[2754] Fix | Delete
$is_value_changed = (
[2755] Fix | Delete
! isset( $existing_changeset_data[ $prefixed_setting_id ] )
[2756] Fix | Delete
||
[2757] Fix | Delete
! array_key_exists( 'value', $existing_changeset_data[ $prefixed_setting_id ] )
[2758] Fix | Delete
||
[2759] Fix | Delete
$existing_changeset_data[ $prefixed_setting_id ]['value'] !== $setting_value
[2760] Fix | Delete
);
[2761] Fix | Delete
if ( $is_value_changed ) {
[2762] Fix | Delete
$changed_setting_ids[] = $setting_id;
[2763] Fix | Delete
}
[2764] Fix | Delete
}
[2765] Fix | Delete
[2766] Fix | Delete
/**
[2767] Fix | Delete
* Fires before save validation happens.
[2768] Fix | Delete
*
[2769] Fix | Delete
* Plugins can add just-in-time {@see 'customize_validate_{$this->ID}'} filters
[2770] Fix | Delete
* at this point to catch any settings registered after `customize_register`.
[2771] Fix | Delete
* The dynamic portion of the hook name, `$this->ID` refers to the setting ID.
[2772] Fix | Delete
*
[2773] Fix | Delete
* @since 4.6.0
[2774] Fix | Delete
*
[2775] Fix | Delete
* @param WP_Customize_Manager $manager WP_Customize_Manager instance.
[2776] Fix | Delete
*/
[2777] Fix | Delete
do_action( 'customize_save_validation_before', $this );
[2778] Fix | Delete
[2779] Fix | Delete
// Validate settings.
[2780] Fix | Delete
$validated_values = array_merge(
[2781] Fix | Delete
array_fill_keys( array_keys( $args['data'] ), null ), // Make sure existence/capability checks are done on value-less setting updates.
[2782] Fix | Delete
$post_values
[2783] Fix | Delete
);
[2784] Fix | Delete
$setting_validities = $this->validate_setting_values(
[2785] Fix | Delete
$validated_values,
[2786] Fix | Delete
array(
[2787] Fix | Delete
'validate_capability' => true,
[2788] Fix | Delete
'validate_existence' => true,
[2789] Fix | Delete
)
[2790] Fix | Delete
);
[2791] Fix | Delete
$invalid_setting_count = count( array_filter( $setting_validities, 'is_wp_error' ) );
[2792] Fix | Delete
[2793] Fix | Delete
/*
[2794] Fix | Delete
* Short-circuit if there are invalid settings the update is transactional.
[2795] Fix | Delete
* A changeset update is transactional when a status is supplied in the request.
[2796] Fix | Delete
*/
[2797] Fix | Delete
if ( $update_transactionally && $invalid_setting_count > 0 ) {
[2798] Fix | Delete
$response = array(
[2799] Fix | Delete
'setting_validities' => $setting_validities,
[2800] Fix | Delete
/* translators: %s: Number of invalid settings. */
[2801] Fix | Delete
'message' => sprintf( _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', $invalid_setting_count ), number_format_i18n( $invalid_setting_count ) ),
[2802] Fix | Delete
);
[2803] Fix | Delete
return new WP_Error( 'transaction_fail', '', $response );
[2804] Fix | Delete
}
[2805] Fix | Delete
[2806] Fix | Delete
// Obtain/merge data for changeset.
[2807] Fix | Delete
$original_changeset_data = $this->get_changeset_post_data( $changeset_post_id );
[2808] Fix | Delete
$data = $original_changeset_data;
[2809] Fix | Delete
if ( is_wp_error( $data ) ) {
[2810] Fix | Delete
$data = array();
[2811] Fix | Delete
}
[2812] Fix | Delete
[2813] Fix | Delete
// Ensure that all post values are included in the changeset data.
[2814] Fix | Delete
foreach ( $post_values as $setting_id => $post_value ) {
[2815] Fix | Delete
if ( ! isset( $args['data'][ $setting_id ] ) ) {
[2816] Fix | Delete
$args['data'][ $setting_id ] = array();
[2817] Fix | Delete
}
[2818] Fix | Delete
if ( ! isset( $args['data'][ $setting_id ]['value'] ) ) {
[2819] Fix | Delete
$args['data'][ $setting_id ]['value'] = $post_value;
[2820] Fix | Delete
}
[2821] Fix | Delete
}
[2822] Fix | Delete
[2823] Fix | Delete
foreach ( $args['data'] as $setting_id => $setting_params ) {
[2824] Fix | Delete
$setting = $this->get_setting( $setting_id );
[2825] Fix | Delete
if ( ! $setting || ! $setting->check_capabilities() ) {
[2826] Fix | Delete
continue;
[2827] Fix | Delete
}
[2828] Fix | Delete
[2829] Fix | Delete
// Skip updating changeset for invalid setting values.
[2830] Fix | Delete
if ( isset( $setting_validities[ $setting_id ] ) && is_wp_error( $setting_validities[ $setting_id ] ) ) {
[2831] Fix | Delete
continue;
[2832] Fix | Delete
}
[2833] Fix | Delete
[2834] Fix | Delete
$changeset_setting_id = $setting_id;
[2835] Fix | Delete
if ( 'theme_mod' === $setting->type ) {
[2836] Fix | Delete
$changeset_setting_id = sprintf( '%s::%s', $this->get_stylesheet(), $setting_id );
[2837] Fix | Delete
}
[2838] Fix | Delete
[2839] Fix | Delete
if ( null === $setting_params ) {
[2840] Fix | Delete
// Remove setting from changeset entirely.
[2841] Fix | Delete
unset( $data[ $changeset_setting_id ] );
[2842] Fix | Delete
} else {
[2843] Fix | Delete
[2844] Fix | Delete
if ( ! isset( $data[ $changeset_setting_id ] ) ) {
[2845] Fix | Delete
$data[ $changeset_setting_id ] = array();
[2846] Fix | Delete
}
[2847] Fix | Delete
[2848] Fix | Delete
// Merge any additional setting params that have been supplied with the existing params.
[2849] Fix | Delete
$merged_setting_params = array_merge( $data[ $changeset_setting_id ], $setting_params );
[2850] Fix | Delete
[2851] Fix | Delete
// Skip updating setting params if unchanged (ensuring the user_id is not overwritten).
[2852] Fix | Delete
if ( $data[ $changeset_setting_id ] === $merged_setting_params ) {
[2853] Fix | Delete
continue;
[2854] Fix | Delete
}
[2855] Fix | Delete
[2856] Fix | Delete
$data[ $changeset_setting_id ] = array_merge(
[2857] Fix | Delete
$merged_setting_params,
[2858] Fix | Delete
array(
[2859] Fix | Delete
'type' => $setting->type,
[2860] Fix | Delete
'user_id' => $args['user_id'],
[2861] Fix | Delete
'date_modified_gmt' => current_time( 'mysql', true ),
[2862] Fix | Delete
)
[2863] Fix | Delete
);
[2864] Fix | Delete
[2865] Fix | Delete
// Clear starter_content flag in data if changeset is not explicitly being updated for starter content.
[2866] Fix | Delete
if ( empty( $args['starter_content'] ) ) {
[2867] Fix | Delete
unset( $data[ $changeset_setting_id ]['starter_content'] );
[2868] Fix | Delete
}
[2869] Fix | Delete
}
[2870] Fix | Delete
}
[2871] Fix | Delete
[2872] Fix | Delete
$filter_context = array(
[2873] Fix | Delete
'uuid' => $this->changeset_uuid(),
[2874] Fix | Delete
'title' => $args['title'],
[2875] Fix | Delete
'status' => $args['status'],
[2876] Fix | Delete
'date_gmt' => $args['date_gmt'],
[2877] Fix | Delete
'post_id' => $changeset_post_id,
[2878] Fix | Delete
'previous_data' => is_wp_error( $original_changeset_data ) ? array() : $original_changeset_data,
[2879] Fix | Delete
'manager' => $this,
[2880] Fix | Delete
);
[2881] Fix | Delete
[2882] Fix | Delete
/**
[2883] Fix | Delete
* Filters the settings' data that will be persisted into the changeset.
[2884] Fix | Delete
*
[2885] Fix | Delete
* Plugins may amend additional data (such as additional meta for settings) into the changeset with this filter.
[2886] Fix | Delete
*
[2887] Fix | Delete
* @since 4.7.0
[2888] Fix | Delete
*
[2889] Fix | Delete
* @param array $data Updated changeset data, mapping setting IDs to arrays containing a $value item and optionally other metadata.
[2890] Fix | Delete
* @param array $context {
[2891] Fix | Delete
* Filter context.
[2892] Fix | Delete
*
[2893] Fix | Delete
* @type string $uuid Changeset UUID.
[2894] Fix | Delete
* @type string $title Requested title for the changeset post.
[2895] Fix | Delete
* @type string $status Requested status for the changeset post.
[2896] Fix | Delete
* @type string $date_gmt Requested date for the changeset post in MySQL format and GMT timezone.
[2897] Fix | Delete
* @type int|false $post_id Post ID for the changeset, or false if it doesn't exist yet.
[2898] Fix | Delete
* @type array $previous_data Previous data contained in the changeset.
[2899] Fix | Delete
* @type WP_Customize_Manager $manager Manager instance.
[2900] Fix | Delete
* }
[2901] Fix | Delete
*/
[2902] Fix | Delete
$data = apply_filters( 'customize_changeset_save_data', $data, $filter_context );
[2903] Fix | Delete
[2904] Fix | Delete
// Switch theme if publishing changes now.
[2905] Fix | Delete
if ( 'publish' === $args['status'] && ! $this->is_theme_active() ) {
[2906] Fix | Delete
// Temporarily stop previewing the theme to allow switch_themes() to operate properly.
[2907] Fix | Delete
$this->stop_previewing_theme();
[2908] Fix | Delete
switch_theme( $this->get_stylesheet() );
[2909] Fix | Delete
update_option( 'theme_switched_via_customizer', true );
[2910] Fix | Delete
$this->start_previewing_theme();
[2911] Fix | Delete
}
[2912] Fix | Delete
[2913] Fix | Delete
// Gather the data for wp_insert_post()/wp_update_post().
[2914] Fix | Delete
$post_array = array(
[2915] Fix | Delete
// JSON_UNESCAPED_SLASHES is only to improve readability as slashes needn't be escaped in storage.
[2916] Fix | Delete
'post_content' => wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ),
[2917] Fix | Delete
);
[2918] Fix | Delete
if ( $args['title'] ) {
[2919] Fix | Delete
$post_array['post_title'] = $args['title'];
[2920] Fix | Delete
}
[2921] Fix | Delete
if ( $changeset_post_id ) {
[2922] Fix | Delete
$post_array['ID'] = $changeset_post_id;
[2923] Fix | Delete
} else {
[2924] Fix | Delete
$post_array['post_type'] = 'customize_changeset';
[2925] Fix | Delete
$post_array['post_name'] = $this->changeset_uuid();
[2926] Fix | Delete
$post_array['post_status'] = 'auto-draft';
[2927] Fix | Delete
}
[2928] Fix | Delete
if ( $args['status'] ) {
[2929] Fix | Delete
$post_array['post_status'] = $args['status'];
[2930] Fix | Delete
}
[2931] Fix | Delete
[2932] Fix | Delete
// Reset post date to now if we are publishing, otherwise pass post_date_gmt and translate for post_date.
[2933] Fix | Delete
if ( 'publish' === $args['status'] ) {
[2934] Fix | Delete
$post_array['post_date_gmt'] = '0000-00-00 00:00:00';
[2935] Fix | Delete
$post_array['post_date'] = '0000-00-00 00:00:00';
[2936] Fix | Delete
} elseif ( $args['date_gmt'] ) {
[2937] Fix | Delete
$post_array['post_date_gmt'] = $args['date_gmt'];
[2938] Fix | Delete
$post_array['post_date'] = get_date_from_gmt( $args['date_gmt'] );
[2939] Fix | Delete
} elseif ( $changeset_post_id && 'auto-draft' === get_post_status( $changeset_post_id ) ) {
[2940] Fix | Delete
/*
[2941] Fix | Delete
* Keep bumping the date for the auto-draft whenever it is modified;
[2942] Fix | Delete
* this extends its life, preserving it from garbage-collection via
[2943] Fix | Delete
* wp_delete_auto_drafts().
[2944] Fix | Delete
*/
[2945] Fix | Delete
$post_array['post_date'] = current_time( 'mysql' );
[2946] Fix | Delete
$post_array['post_date_gmt'] = '';
[2947] Fix | Delete
}
[2948] Fix | Delete
[2949] Fix | Delete
$this->store_changeset_revision = $allow_revision;
[2950] Fix | Delete
add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ), 5, 3 );
[2951] Fix | Delete
[2952] Fix | Delete
/*
[2953] Fix | Delete
* Update the changeset post. The publish_customize_changeset action will cause the settings in the
[2954] Fix | Delete
* changeset to be saved via WP_Customize_Setting::save(). Updating a post with publish status will
[2955] Fix | Delete
* trigger WP_Customize_Manager::publish_changeset_values().
[2956] Fix | Delete
*/
[2957] Fix | Delete
add_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5, 3 );
[2958] Fix | Delete
if ( $changeset_post_id ) {
[2959] Fix | Delete
if ( $args['autosave'] && 'auto-draft' !== get_post_status( $changeset_post_id ) ) {
[2960] Fix | Delete
// See _wp_translate_postdata() for why this is required as it will use the edit_post meta capability.
[2961] Fix | Delete
add_filter( 'map_meta_cap', array( $this, 'grant_edit_post_capability_for_changeset' ), 10, 4 );
[2962] Fix | Delete
[2963] Fix | Delete
$post_array['post_ID'] = $post_array['ID'];
[2964] Fix | Delete
$post_array['post_type'] = 'customize_changeset';
[2965] Fix | Delete
[2966] Fix | Delete
$r = wp_create_post_autosave( wp_slash( $post_array ) );
[2967] Fix | Delete
[2968] Fix | Delete
remove_filter( 'map_meta_cap', array( $this, 'grant_edit_post_capability_for_changeset' ), 10 );
[2969] Fix | Delete
} else {
[2970] Fix | Delete
$post_array['edit_date'] = true; // Prevent date clearing.
[2971] Fix | Delete
[2972] Fix | Delete
$r = wp_update_post( wp_slash( $post_array ), true );
[2973] Fix | Delete
[2974] Fix | Delete
// Delete autosave revision for user when the changeset is updated.
[2975] Fix | Delete
if ( ! empty( $args['user_id'] ) ) {
[2976] Fix | Delete
$autosave_draft = wp_get_post_autosave( $changeset_post_id, $args['user_id'] );
[2977] Fix | Delete
if ( $autosave_draft ) {
[2978] Fix | Delete
wp_delete_post( $autosave_draft->ID, true );
[2979] Fix | Delete
}
[2980] Fix | Delete
}
[2981] Fix | Delete
}
[2982] Fix | Delete
} else {
[2983] Fix | Delete
$r = wp_insert_post( wp_slash( $post_array ), true );
[2984] Fix | Delete
if ( ! is_wp_error( $r ) ) {
[2985] Fix | Delete
$this->_changeset_post_id = $r; // Update cached post ID for the loaded changeset.
[2986] Fix | Delete
}
[2987] Fix | Delete
}
[2988] Fix | Delete
remove_filter( 'wp_insert_post_data', array( $this, 'preserve_insert_changeset_post_content' ), 5 );
[2989] Fix | Delete
[2990] Fix | Delete
$this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents.
[2991] Fix | Delete
[2992] Fix | Delete
remove_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ) );
[2993] Fix | Delete
[2994] Fix | Delete
$response = array(
[2995] Fix | Delete
'setting_validities' => $setting_validities,
[2996] Fix | Delete
);
[2997] Fix | Delete
[2998] Fix | Delete
if ( is_wp_error( $r ) ) {
[2999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function