-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Gutenberg support to the plugin #34
Conversation
…align' attribute, and thereby with Gutenberg https://codex.wordpress.org/CSS
With the following post_content:
The following output:
Why does the first one have a later ID? Does the block renderer run before the shortcode renderer? How can it be assured that the script source is output before any and all tags? |
Long long debug outputwp> global $wp_filter; var_dump( $wp_filter['the_content'], true );
object(WP_Hook)#1139 (5) {
["callbacks"]=>
array(5) {
[8]=>
array(3) {
["00000000430b60a000000000382d9011run_shortcode"]=>
array(2) {
["function"]=>
array(2) {
[0]=>
object(WP_Embed)#1440 (7) {
["handlers"]=>
array(2) {
[10]=>
array(1) {
["youtube_embed_url"]=>
array(2) {
["regex"]=>
string(51) "#https?://(www.)?youtube\.com/(?:v|embed)/([^/]+)#i"
["callback"]=>
string(24) "wp_embed_handler_youtube"
}
}
[9999]=>
array(2) {
["audio"]=>
array(2) {
["regex"]=>
string(41) "#^https?://.+?\.(mp3|ogg|flac|m4a|wav)$#i"
["callback"]=>
string(22) "wp_embed_handler_audio"
}
["video"]=>
array(2) {
["regex"]=>
string(41) "#^https?://.+?\.(mp4|m4v|webm|ogv|flv)$#i"
["callback"]=>
string(22) "wp_embed_handler_video"
}
}
}
["post_ID"]=>
NULL
["usecache"]=>
bool(true)
["linkifunknown"]=>
bool(true)
["last_attr"]=>
array(0) {
}
["last_url"]=>
string(0) ""
["return_false_on_fail"]=>
bool(false)
}
[1]=>
string(13) "run_shortcode"
}
["accepted_args"]=>
int(1)
}
["00000000430b60a000000000382d9011autoembed"]=>
array(2) {
["function"]=>
array(2) {
[0]=>
object(WP_Embed)#1440 (7) {
["handlers"]=>
array(2) {
[10]=>
array(1) {
["youtube_embed_url"]=>
array(2) {
["regex"]=>
string(51) "#https?://(www.)?youtube\.com/(?:v|embed)/([^/]+)#i"
["callback"]=>
string(24) "wp_embed_handler_youtube"
}
}
[9999]=>
array(2) {
["audio"]=>
array(2) {
["regex"]=>
string(41) "#^https?://.+?\.(mp3|ogg|flac|m4a|wav)$#i"
["callback"]=>
string(22) "wp_embed_handler_audio"
}
["video"]=>
array(2) {
["regex"]=>
string(41) "#^https?://.+?\.(mp4|m4v|webm|ogv|flv)$#i"
["callback"]=>
string(22) "wp_embed_handler_video"
}
}
}
["post_ID"]=>
NULL
["usecache"]=>
bool(true)
["linkifunknown"]=>
bool(true)
["last_attr"]=>
array(0) {
}
["last_url"]=>
string(0) ""
["return_false_on_fail"]=>
bool(false)
}
[1]=>
string(9) "autoembed"
}
["accepted_args"]=>
int(1)
}
["gutenberg_wpautop"]=>
array(2) {
["function"]=>
string(17) "gutenberg_wpautop"
["accepted_args"]=>
int(1)
}
}
[9]=>
array(1) {
["do_blocks"]=>
array(2) {
["function"]=>
string(9) "do_blocks"
["accepted_args"]=>
int(1)
}
}
[10]=>
array(4) {
["wptexturize"]=>
array(2) {
["function"]=>
string(11) "wptexturize"
["accepted_args"]=>
int(1)
}
["shortcode_unautop"]=>
array(2) {
["function"]=>
string(17) "shortcode_unautop"
["accepted_args"]=>
int(1)
}
["prepend_attachment"]=>
array(2) {
["function"]=>
string(18) "prepend_attachment"
["accepted_args"]=>
int(1)
}
["wp_make_content_images_responsive"]=>
array(2) {
["function"]=>
string(33) "wp_make_content_images_responsive"
["accepted_args"]=>
int(1)
}
}
[11]=>
array(2) {
["capital_P_dangit"]=>
array(2) {
["function"]=>
string(16) "capital_P_dangit"
["accepted_args"]=>
int(1)
}
["do_shortcode"]=>
array(2) {
["function"]=>
string(12) "do_shortcode"
["accepted_args"]=>
int(1)
}
}
[20]=>
array(1) {
["convert_smilies"]=>
array(2) {
["function"]=>
string(15) "convert_smilies"
["accepted_args"]=>
int(1)
}
}
}
["iterations":"WP_Hook":private]=>
array(0) {
}
["current_priority":"WP_Hook":private]=>
array(0) {
}
["nesting_level":"WP_Hook":private]=>
int(0)
["doing_action":"WP_Hook":private]=>
bool(false)
} |
Hrm, how might this work:
Alternately:
|
…footer action. This addresses the problem described at #34 (comment) WordPress renders blocks before rendering shortcodes. If a post contains a Pym shortcode followed by a Pym block, the shortcode, which appears first, will have the id pym_1 and the block, which is processed first, will have the id pym_0. Because the script tag that loads `pym.js`, `<script src="http://example.org/wp-content/plugins/pym-shortcode/js/pym.v1.min.js"></script>` is output on the first *processed* Pym thing, it's not output on the page until after pym_1's `new pym.Parent` was called. Because the `pym.js` library isn't loaded on the page until pym_0, at pym_1 `new pym.Parent` will fail. This commit solves the problem by: - not messing with block or shortcode rendering order - not moving the `<script src="http://example.org/wp-content/plugins/pym-shortcode/js/pym.v1.min.js"></script>` - moving the `new pym.Parent` calls to after the entire post_content has been processed, by outputting them in the `wp_footer` action A problem I foresee with this approach is that the output of the_content() no longer contains all elements necessary to display the post.
Gonna open a separate issue for this problem, because that makes it easier to discuss separately from "should we implement blocks". |
- Fixes #33, moving `pymsrc` script tags to `wp_footer` - Fixes #35, moving `new pym.Parent` tags to `wp_footer` - If a post has differing pymsrc values, output a warning to the page console.log (if console.log exists, that is; gotta support IE 9 since Pym.js does) - If a post has differing pymsrc values, output a warning to the server log if WP_DEBUG - Adds a singleton class Pymsrc_Output to manage all of that.
…lygraphics 'cos it's cool
On the subject of the browser console errors, hard to tell.
It's disconcerting to deactivate the plugin and see nothing where a block used to be, just an empty "Classic" editor. |
…tent if the plugin ever gets deactivated
|
Internationalization is blocked by insufficient Gutenberg docs; see #40. |
Okay, state of this PR: Changes
New issues createdto be addressed before the next release
deferred
|
Spelling/punctuation updates.
Update to readme
Changes to docs:
|
Changes
To do list
pymsrc
script tags to the footernew pym.Parent
script tags to the footerparent_id
instead ofid
in order to avoid conflicts with ReactGutenbergWordPress alignment classesalignfull
andalignwide
classes, for testing purposes: https://wordpress.org/themes/atomic-blocks/Add support for converting a Pym iframe into a generic embed iframe via atransform
: https://wordpress.org/gutenberg/handbook/block-api/#transforms-optional