| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| <?php | ||
| /** | ||
| * Helper functions used by module. | ||
| * | ||
| * @package performance-lab | ||
| * @since 1.0.0 | ||
| */ | ||
|
|
||
| /** | ||
| * Gets total of enqueued scripts. | ||
| * | ||
| * @since 1.0.0 | ||
| * | ||
| * @return int|false Number of total scripts or false if transient hasn't been set. | ||
| */ | ||
| function perflab_aea_get_total_enqueued_scripts() { | ||
| $enqueued_scripts = false; | ||
| $list_enqueued_scripts = get_transient( 'aea_enqueued_front_page_scripts' ); | ||
| if ( $list_enqueued_scripts ) { | ||
| $enqueued_scripts = count( $list_enqueued_scripts ); | ||
| } | ||
| return $enqueued_scripts; | ||
| } | ||
|
|
||
| /** | ||
| * Gets total size in bytes of Enqueued Scripts. | ||
| * | ||
| * @since 1.0.0 | ||
| * | ||
| * @return int|false Byte Total size or false if transient hasn't been set. | ||
| */ | ||
| function perflab_aea_get_total_size_bytes_enqueued_scripts() { | ||
| $total_size = false; | ||
| $list_enqueued_scripts = get_transient( 'aea_enqueued_front_page_scripts' ); | ||
| if ( $list_enqueued_scripts ) { | ||
| $total_size = 0; | ||
| foreach ( $list_enqueued_scripts as $enqueued_script ) { | ||
| $total_size += $enqueued_script['size']; | ||
| } | ||
| } | ||
| return $total_size; | ||
| } | ||
|
|
||
| /** | ||
| * Gets total of enqueued styles. | ||
| * | ||
| * @since 1.0.0 | ||
| * | ||
| * @return int|false Number of total styles or false if transient hasn't been set. | ||
| */ | ||
| function perflab_aea_get_total_enqueued_styles() { | ||
| $enqueued_styles = false; | ||
| $list_enqueued_styles = get_transient( 'aea_enqueued_front_page_styles' ); | ||
| if ( $list_enqueued_styles ) { | ||
| $enqueued_styles = count( $list_enqueued_styles ); | ||
| } | ||
| return $enqueued_styles; | ||
| } | ||
|
|
||
| /** | ||
| * Gets total size in bytes of Enqueued Styles. | ||
| * | ||
| * @since 1.0.0 | ||
| * | ||
| * @return int|false Byte Total size or false if transient hasn't been set. | ||
| */ | ||
| function perflab_aea_get_total_size_bytes_enqueued_styles() { | ||
| $total_size = false; | ||
| $list_enqueued_styles = get_transient( 'aea_enqueued_front_page_styles' ); | ||
| if ( $list_enqueued_styles ) { | ||
| $total_size = 0; | ||
| foreach ( $list_enqueued_styles as $enqueued_style ) { | ||
| $total_size += $enqueued_style['size']; | ||
| } | ||
| } | ||
| return $total_size; | ||
| } | ||
|
|
||
| /** | ||
| * Convert full URL paths to absolute paths. | ||
| * | ||
| * @since 1.0.0 | ||
| * | ||
| * @param string $resource_url URl resource link. | ||
| * @return string Returns absolute path to the resource. | ||
| */ | ||
| function perflab_aea_get_path_from_resource_url( $resource_url ) { | ||
| return ABSPATH . wp_make_link_relative( $resource_url ); | ||
| } | ||
|
|
||
| /** | ||
| * If file exists, returns its size. | ||
| * | ||
| * @since 1.0.0 | ||
| * | ||
| * @param string $file_src Path to the file. | ||
| * @return int Returns size if file exists, 0 if it doesn't. | ||
| */ | ||
| function perflab_aea_get_resource_file_size( $file_src ) { | ||
| return file_exists( $file_src ) ? filesize( $file_src ) : 0; | ||
| } | ||
|
|
||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis is okay for a start, but it's a bit oversimplified:
For most sites what you have here will work, but we should make sure to also accomodate those other sites.
I suggest we expand this as follows to at least cover for these two cases a bit better:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality@felixarntz can you give me an example of the first case? I cannot see it clearly.
Regarding WordPress may be in a subdirectory of the domain.
Do you mean something like this?
https://example.com/blog/wp-content/themes/test-theme/style.css ?
If that's the case, doesn't ABSPATH . wp_make_link_relative( $resource_url ) covers it too?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality@manuelRod Some popular environments like https://github.com/roots/bedrock have their wp-content directory outside of the (rest of the) WordPress directory, so that URLs would be e.g. https://example.com/content/themes/... and https://example.com/wp/wp-includes/.... Both conditions I'm suggesting here cover that use-case, the first is for assets that come from the wp-content directory in a custom location, the second one for when the WordPress directory is in a subdirectory.
I don't think it does, since wp_make_link_relative simply removes the protocol and domain. Looking at my example above, that means you get /wp/wp-includes/..., and when you append that to ABSPATH, the wp directory would basically be in there twice. That's why for these cases we have to use the site_url() function, which is the "URL equivalent" of ABSPATH (the same way that WP_CONTENT_URL is the "URL equivalent" to WP_CONTENT_DIR).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.