Skip to content
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

476: Fix javascript registration #500

Merged
merged 13 commits into from Sep 7, 2016

Conversation

toolstack
Copy link
Contributor

Alternate solution to #476 which uses standard WP style and script registration and enqueuing functions.

wp_register_script( 'gp-editor', $url . '/editor.js', array( 'gp-common', 'jquery-ui-tooltip' ), '20160329' );
wp_register_script( 'gp-glossary', $url . '/glossary.js', array( 'gp-common', 'gp-editor' ), '20160329' );
wp_register_script( 'gp-translations-page', $url . '/translations-page.js', array( 'gp-common', 'gp-editor' ), '20150430' );
wp_register_script( 'gp-mass-create-sets-page', $url . '/mass-create-sets-page.js', array( 'gp-common', 'gp-editor' ), '20150430' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gp-editor has already gp-common as a dependency, so we don't have to repeat it for the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tossed back and forth a few times on how best to approach that, in the end I decided it was better to be verbose in the dependencies instead of nesting them. Makes it clear what each script has for a dependency, however I'm fine with doing it the other way as well.

That's why in the template files I included all dependencies even though just including one would sometimes be all that was technically required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the end I decided it was better to be verbose in the dependencies instead of nesting them.

Well, if you want to go this route you have to define 'jquery' too. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I'm not I'll update it to nest them.

* Register the GlotPress styles
*
* @param WP_Styles $styles
* Register the GlotPress styles and load the base style sheet.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs are third-person singular elements, so third-person singular verbs should be used. (https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/#language)

@ocean90
Copy link
Member

ocean90 commented Sep 4, 2016

What do you think about merging gp_styles_default() and gp_register_scripts() into gp_register_assets()?

@toolstack
Copy link
Contributor Author

I did consider merging them but I think keeping them separate is probably better, though I don't have a really good reason for that.

@ocean90
Copy link
Member

ocean90 commented Sep 4, 2016

Note that gp_register_scripts() was previously gp_scripts_default(), so you already changed one.

* @param string|array $handles A single script handle to enqueue or an array of enqueue handles to enqueue.
*/
function gp_enqueue_script( $handles ) {
gp_enqueue_scripts( $handles );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't provide two functions which do the same. gp_enqueue_script() should continue to only support one handle.

function gp_enqueue_script( $handle ) {
    gp_enqueue_scripts( array( $handle ) );
}

Same for gp_enqueue_style().

@toolstack toolstack force-pushed the 476-fix-javascript-registration-alternate branch from 6fb9a93 to 3edffd5 Compare September 7, 2016 13:15
@@ -60,7 +60,7 @@ function gp_enqueue_styles( $handles ) {
* @param string $handle A single style handle to enqueue.
*/
function gp_enqueue_style( $handle ) {
if ( ! in_array( $handle, GP::$styles ) ) {
if ( false === in_array( $handle, GP::$styles ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for this change? Did you mean to change it to! in_array( $handle, GP::$styles, true )?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coding standards check requires the comparison to be strict, hence the false === instead of !.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that was for the third argument of in_array(). in_array() returns only boolean values so there is no need for the strict check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just noticed that, I've updated the PR but left in the false ===.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ocean90 ocean90 merged commit e06e768 into develop Sep 7, 2016
@ocean90 ocean90 deleted the 476-fix-javascript-registration-alternate branch September 7, 2016 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants