-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclass-editor.php
More file actions
73 lines (63 loc) · 2.05 KB
/
class-editor.php
File metadata and controls
73 lines (63 loc) · 2.05 KB
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
<?php
/**
* Tweaks for the editor.
*
* @package Progress_Planner
*/
namespace Progress_Planner\Admin;
/**
* Editor class.
*/
class Editor {
/**
* Constructor.
*/
public function __construct() {
\add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_editor_script' ] );
}
/**
* Enqueue the editor script.
*
* @return void
*/
public function enqueue_editor_script() {
// Bail early when we're on the site-editor.php page.
$request = \filter_input( INPUT_SERVER, 'REQUEST_URI' );
if ( ! $request && isset( $_SERVER['REQUEST_URI'] ) ) {
$request = \sanitize_text_field( \wp_unslash( $_SERVER['REQUEST_URI'] ) );
}
if ( $request && \str_contains( $request, 'site-editor.php' ) ) {
return;
}
// Only load on Page edit screen and if the user can edit others posts.
if ( 'page' !== \get_post_type() || ! \current_user_can( 'edit_others_posts' ) ) {
return;
}
$page_types = \progress_planner()->get_page_types()->get_page_types();
// Check if the page-type is set in the URL (user is coming from the Settings page).
if ( isset( $_GET['prpl_page_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$prpl_pt = \sanitize_text_field( \wp_unslash( $_GET['prpl_page_type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
foreach ( $page_types as $page_type ) {
if ( $page_type['slug'] === $prpl_pt ) {
$prpl_preselected_page_type = $page_type['id'];
break;
}
}
} else {
// Get the default page-type.
$prpl_preselected_page_type = \progress_planner()->get_page_types()->get_default_page_type( (string) \get_post_type(), (int) \get_the_ID() );
}
\progress_planner()->get_admin__enqueue()->enqueue_script(
'editor',
[
'name' => 'progressPlannerEditor',
'data' => [
'lessons' => \progress_planner()->get_lessons()->get_items(),
'pageTypes' => $page_types,
'defaultPageType' => $prpl_preselected_page_type,
],
]
);
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/editor' );
}
}