Closed benlk closed 6 years ago
The following things must be ensured:
Here are the solutions that I can think of:
pymsrc
script tag at the start of the_content()the_content
that checks for the presence of the string 'pym', and if it is there, sets a global "maybe" variable to true
definitely
variable to true
. If pymsrc is set, then instead output the pymsrc's tagthe_content
that runs at a very late priority, like 100
, if $maybe and $definitely, prepend the_content
with a script tag that registers the appropriate pymsrc
.new pym.Parent
in the footer<script>var pym_1 = new pym.Parent('pym_1', 'https://f.benlk.com/graphics/heartbeat-abortion-bills/child.html', {})</script>
, instead of outputting it then, add it to the footer with a generated callback function that has the correct variables inserted into its call.This doesn't move the location of the pymsrc
tag starting Pym, but it also does not prevent addressing #33 by enqueuing the pymsrc
tag in the wp_footer
as long as the function outputting that tag is enqueued at a higher priority.
I asked in #wordpress
on freenode IRC, and received feedback to the effect that the best place to put those script tags is in <head>
or at the end of <body>
with wp_footer
.
My worry is that someone using this plugin is going to be using WordPress in a way that powers a non-main-website content presentation, and their content presentation is going to render the_content()
as HTML with scripts and stuff, but without any of the dependency-satisfying code from wp_footer
.
Feedback in #wordpress
on newsnerdery.org Slack from several people also recommends wp_footer
.
Originally reported in #34, the ticket for adding Gutenberg support to the plugin.
With the following post_content:
The following output:
After dumping the filters hooked on
'the_content'
withglobal $wp_filter; var_dump( $wp_filter['the_content'], true );
, I found that the block rendering filterdo_blocks
runs before the shortcode rendererdo_shortcode
.Thus, in a post with one block and one shortcode, the first block gets the id
pym_0
and the first shortcode gets the idpym_1
.Because the current behavior of the function
pym_shortcode()
— which is used for the shortcode and the block output — is to output the Pym.js-loading tag<script src="http://pym-shortcode.test/wp-content/plugins/pym-shortcode/js/pym.v1.min.js"></script>
only during the first call, forpym_0
, the later call topym_shortcode()
earlier in thepost_content
doesn't output the script tag, which means thatpym_1
'snew pym.Parent
call doesn't work, becausepym
is not yet defined.