-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into i18n-updates
- Loading branch information
Showing
170 changed files
with
2,610 additions
and
1,323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Contributors Guide | ||
|
||
Welcome to the Gutenberg Project Contributors Guide. | ||
|
||
The following guidelines are in place to create consistency across the project and the numerous contributors. See also the [Contributing Documentation](https://github.com/WordPress/gutenberg/blob/master/CONTRIBUTING.md) for technical details around setup, and submitting your contributions. | ||
|
||
* [Coding Guidelines](../../docs/contributors/coding-guidelines.md) outline additional patterns and conventions used in the Gutenberg project. | ||
* [Copy Guidelines](../../docs/contributors/copy-guide.md) | ||
* [Design Principles & Vision](../../docs/contributors/design.md) | ||
|
||
Please see the table of contents on the left side of the Gutenberg Handbook for the full list of contributor resources. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.82 KB
docs/designers-developers/assets/js-tutorial-error-blocks-undefined.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...igners-developers/developers/tutorials/javascript/extending-the-block-editor.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Extending the Block Editor | ||
|
||
Let's look at using the [Block Style Variation example](../../../../../docs/designers-developers/developers/filters/block-filters.md#block-style-variations) to extend the editor. This example allows you to add your own custom CSS class name to any core block type. | ||
|
||
Replace the existing `console.log()` code in your `myguten.js` file with: | ||
|
||
```js | ||
wp.blocks.registerBlockStyle( 'core/quote', { | ||
name: 'fancy-quote', | ||
label: 'Fancy Quote' | ||
} ); | ||
``` | ||
|
||
**Important:** Notice that you are using a function from `wp.blocks` package. This means you must specify it as a dependency when you enqueue the script. Update the `myguten-plugin.php` file to: | ||
|
||
```php | ||
<?php | ||
/* | ||
Plugin Name: Fancy Quote | ||
*/ | ||
|
||
function myguten_enqueue() { | ||
wp_enqueue_script( 'myguten-script', | ||
plugins_url( 'myguten.js', __FILE__ ), | ||
array( 'wp-blocks') | ||
); | ||
} | ||
add_action( 'enqueue_block_editor_assets', 'myguten_enqueue' ); | ||
``` | ||
|
||
The last argument in the `wp_enqueue_script()` function is an array of dependencies. WordPress makes packages available under the `wp` namespace. In the example, you use `wp.blocks` to access the items that the blocks package exports (in this case the `registerBlockStyle()` function). | ||
|
||
See [Packages](../../../../../docs/designers-developers/developers/packages.md) for list of available packages and what objects they export. | ||
|
||
After you have updated both JavaScript and PHP files, go to the Block Editor and create a new post. | ||
|
||
Add a quote block, and in the right sidebar under Styles, you will see your new Fancy Quote style listed. Click the Fancy Quote to select and apply that style to your quote block. | ||
|
||
|
||
![Fancy Quote Style in Inspector](https://raw.githubusercontent.com/WordPress/gutenberg/master/docs/designers-developers/assets/fancy-quote-in-inspector.png) | ||
|
||
|
||
You will not see a visible change, even if you Preview or Publish the post. However, if you look at the source, you will see the `is-style-fancy-quote` class name is now attached to your quote block. | ||
|
||
Let's add some style. Go ahead and create a `style.css` file with: | ||
|
||
```css | ||
.is-style-fancy-quote { | ||
color: tomato; | ||
} | ||
|
||
``` | ||
|
||
You enqueue the CSS file by adding the following to your `myguten-plugin.php`: | ||
|
||
```php | ||
function myguten_stylesheet() { | ||
wp_enqueue_style( 'myguten-style', plugins_url( 'style.css', __FILE__ ) ); | ||
} | ||
add_action( 'enqueue_block_assets', 'myguten_stylesheet' ); | ||
``` | ||
|
||
Now when you view in the editor and published, you will see your Fancy Quote style, a delicious tomato color text. | ||
|
||
![Fancy Quote with Style](https://raw.githubusercontent.com/WordPress/gutenberg/master/docs/designers-developers/assets/fancy-quote-with-style.png) | ||
|
49 changes: 49 additions & 0 deletions
49
docs/designers-developers/developers/tutorials/javascript/loading-javascript.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Loading JavaScript | ||
|
||
With the plugin in place, you can add the code that loads the JavaScript. This methodology follows the standard WordPress procedure of enqueuing scripts, see [enqueuing section of the Plugin Handbook](https://developer.wordpress.org/plugins/javascript/enqueuing/). | ||
|
||
Add the following code to your `myguten-plugin.php` file: | ||
|
||
```php | ||
function myguten_enqueue() { | ||
wp_enqueue_script( | ||
'myguten-script', | ||
plugins_url( 'myguten.js', __FILE__ ) | ||
); | ||
} | ||
add_action( 'enqueue_block_editor_assets', 'myguten_enqueue' ); | ||
``` | ||
|
||
The `enqueue_block_editor_assets` hook is used, which is called when the block editor loads, and will enqueue the JavaScript file `myguten.js`. | ||
|
||
Create a file called `myguten.js` and add: | ||
|
||
```js | ||
console.log( "I'm loaded!" ); | ||
``` | ||
|
||
Next, create a new post in the block editor. | ||
|
||
We'll check the JavaScript console in your browser's Developer Tools, to see if the message is displayed. If you're not sure what developer tools are, Mozilla's ["What are browser developer tools?"](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools) documentation provides more information, including more background on the [JavaScript console](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools#The_JavaScript_console). | ||
|
||
If your code is registered and enqueued correctly, you should see a message in your console: | ||
|
||
![Console Log Message Success](https://raw.githubusercontent.com/WordPress/gutenberg/master/docs/designers-developers/assets/js-tutorial-console-log-success.png) | ||
|
||
**Note for Theme Developers:** The above method of enqueing is used for plugins. If you are extending the Block Editor for your theme there is a minor difference, you will use the `get_template_directory_uri()` function instead of `plugins_url()`. So for a theme, the enqueue example is: | ||
|
||
```php | ||
function myguten_enqueue() { | ||
wp_enqueue_script( | ||
'myguten-script', | ||
get_template_directory_uri() . '/myguten.js' | ||
); | ||
} | ||
add_action( 'enqueue_block_editor_assets', 'myguten_enqueue' ); | ||
``` | ||
|
||
### Recap | ||
|
||
At this point, you have a plugin in the directory `wp-content/plugins/myguten-plugin` with two files: the PHP server-side code in `myguten-plugin.php`, and the JavaScript which runs in the browser in `myguten.js`. | ||
|
||
This puts all the initial pieces in place for you to start extending the Block Editor. |
16 changes: 16 additions & 0 deletions
16
docs/designers-developers/developers/tutorials/javascript/plugins-background.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Plugins Background | ||
|
||
The primary means of extending WordPress is the plugin. WordPress' [Plugin Basics](https://developer.wordpress.org/plugins/the-basics/) documentation provides for more details on building a plugin. The quickest way to start is to create a new directory in `wp-content/plugins/` to hold your plugin code, for this example you can call it `myguten-plugin`. | ||
|
||
Inside of this new directory, create a file called `myguten-plugin.php` which is the server-side code that runs when your plugin is active. For now place the following in that file: | ||
|
||
```php | ||
<?php | ||
/* | ||
Plugin Name: Fancy Quote | ||
*/ | ||
``` | ||
|
||
To summarize, you should have a directory `wp-content/plugins/myguten-plugin/` which has the single file `myguten-plugin.php`. Once that is in place, go to your plugins list in `wp-admin` and you should see your plugin listed. | ||
|
||
Click **Activate** and your plugin will load with WordPress. |
Oops, something went wrong.