forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
98 lines (88 loc) · 2.76 KB
/
index.php
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
93
94
95
96
97
98
<?php
/**
* Plugin Name: Gutenberg
* Plugin URI: https://wordpress.github.io/gutenberg/
* Description: Prototyping since 1440. Development plugin for the editor focus in core.
* Version: 0.1.0
*
* @package gutenberg
*/
/**
* Gutenberg's Menu.
*
* Adds a new wp-admin menu page for the Gutenberg editor.
*
* @since 0.1.0
*/
function gutenberg_menu() {
add_menu_page(
'Gutenberg',
'Gutenberg',
'manage_options',
'gutenberg',
'the_gutenberg_project'
);
}
add_action( 'admin_menu', 'gutenberg_menu' );
/**
* Registers common scripts to be used as dependencies of the editor and plugins.
*
* @since 0.1.0
*/
function gutenberg_register_scripts() {
$suffix = SCRIPT_DEBUG ? '' : '.min';
// Vendor
wp_register_script( 'react', 'https://unpkg.com/react@15/dist/react' . $suffix . '.js' );
wp_register_script( 'react-dom', 'https://unpkg.com/react-dom@15/dist/react-dom' . $suffix . '.js', array( 'react' ) );
// Editor
wp_register_script( 'tinymce-nightly', 'https://fiddle.azurewebsites.net/tinymce/nightly/tinymce.min.js' );
wp_register_script( 'wp-element', plugins_url( 'element/build/index.js', __FILE__ ), array( 'react', 'react-dom' ) );
wp_register_script( 'wp-blocks', plugins_url( 'blocks/build/index.js', __FILE__ ), array( 'wp-element', 'tinymce-nightly' ) );
}
add_action( 'init', 'gutenberg_register_scripts' );
/**
* Scripts & Styles.
*
* Enqueues the needed scripts and styles when visiting the top-level page of
* the Gutenberg editor.
*
* @param string $hook Screen name.
* @since 0.1.0
*/
function gutenberg_scripts_and_styles( $hook ) {
if ( 'toplevel_page_gutenberg' === $hook ) {
// Scripts
wp_register_script( 'gutenberg-content', plugins_url( 'post-content.js', __FILE__ ) );
wp_enqueue_script( 'wp-editor', plugins_url( 'editor/build/index.js', __FILE__ ), array( 'wp-blocks', 'wp-element', 'gutenberg-content' ), false, true );
wp_add_inline_script( 'wp-editor', 'wp.editor.createEditorInstance( \'editor\', { content: window.content } );' );
// Styles
wp_enqueue_style( 'wp-editor', plugins_url( 'editor/build/style.css', __FILE__ ) );
}
}
add_action( 'admin_enqueue_scripts', 'gutenberg_scripts_and_styles' );
/**
* Project.
*
* The main entry point for the Gutenberg editor. Renders the editor on the
* wp-admin page for the plugin.
*
* @since 0.1.0
*/
function the_gutenberg_project() {
?>
<div class="gutenberg">
<section id="editor" class="gutenberg__editor"></section>
</div>
<?php
}
/**
* Registers a block.
*
* @param string $name Block name including namespace.
* @param array $args Optional. Array of settings for the block. Default
* empty array.
* @return bool True on success, false on error.
*/
function register_block( $name, $args = array() ) {
// Not implemented yet.
}