1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file contains some 'remember' functions taken from the core Classic Editor Plugin |
4
|
|
|
* Used to align the 'last editor' metadata so that it is set on all Jetpack and WPCOM sites |
5
|
|
|
* |
6
|
|
|
* @package Jetpack |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Jetpack\ClassicEditor; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Remember when the classic editor was used to edit a post. |
13
|
|
|
* |
14
|
|
|
* @param object $post The post being editted. |
15
|
|
|
*/ |
16
|
|
|
function remember_classic_editor( $post ) { |
17
|
|
|
$post_type = get_post_type( $post ); |
18
|
|
|
|
19
|
|
|
if ( $post_type && post_type_supports( $post_type, 'editor' ) ) { |
20
|
|
|
remember_editor( $post->ID, 'classic-editor' ); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Remember when the block editor was used to edit a post. |
26
|
|
|
* |
27
|
|
|
* @param object $editor_settings This is hooked into a filter and this is the settings that are passed in. |
28
|
|
|
* @param object $post The post being editted. |
29
|
|
|
* @return object The unmodified $editor_settings parameter. |
30
|
|
|
*/ |
31
|
|
|
function remember_block_editor( $editor_settings, $post ) { |
32
|
|
|
$post_type = get_post_type( $post ); |
33
|
|
|
|
34
|
|
|
if ( $post_type && classic_editor_can_edit_post_type( $post_type ) ) { |
35
|
|
|
remember_editor( $post->ID, 'block-editor' ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $editor_settings; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Sets the metadata for the specified post and editor. |
43
|
|
|
* |
44
|
|
|
* @param int $post_id The ID of the post to set the metadata for. |
45
|
|
|
* @param string $editor String name of the editor, 'classic-editor' or 'block-editor'. |
46
|
|
|
*/ |
47
|
|
|
function remember_editor( $post_id, $editor ) { |
48
|
|
|
if ( get_post_meta( $post_id, 'classic-editor-remember', true ) !== $editor ) { |
49
|
|
|
update_post_meta( $post_id, 'classic-editor-remember', $editor ); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Checks whether the block editor can be used with the given post type. |
55
|
|
|
* |
56
|
|
|
* @param string $post_type The post type to check. |
57
|
|
|
* @return bool Whether the block editor can be used to edit the supplied post type. |
58
|
|
|
*/ |
59
|
|
|
function classic_editor_can_edit_post_type( $post_type ) { |
60
|
|
|
$can_edit = false; |
61
|
|
|
|
62
|
|
|
if ( function_exists( 'gutenberg_can_edit_post_type' ) ) { |
63
|
|
|
$can_edit = gutenberg_can_edit_post_type( $post_type ); |
64
|
|
|
} elseif ( function_exists( 'use_block_editor_for_post_type' ) ) { |
65
|
|
|
$can_edit = use_block_editor_for_post_type( $post_type ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $can_edit; |
69
|
|
|
} |
70
|
|
|
|