Skip to content

Commit

Permalink
fixed flagallery integration
Browse files Browse the repository at this point in the history
  • Loading branch information
nosilver4u committed Sep 10, 2019
1 parent aedc9c0 commit cc720f6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* fixed: JS WebP incorrectly parses GIF/SVG images in Force WebP mode
* fixed: JS WebP does not support lazy load + infinite scroll
* fixed: Lazy Load auto-scaling breaks if background image is enclosed in encoded quotes
* fixed: GRAND FlaGallery integration broken by hook suffix change

= 4.9.2 =
* fixed: generating lazy load PNG placeholders with large heights causes 500 errors
Expand Down
42 changes: 37 additions & 5 deletions classes/class-ewww-flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,38 @@ function ewww_flag_bulk() {
echo '</div></div>';
}

/**
* Checks the hook suffix to see if this is the individual gallery management page.
*
* @param string $hook The hook suffix of the page.
* @returns boolean True for the gallery page, false anywhere else.
*/
function is_gallery_page( $hook ) {
if ( 'flagallery_page_flag-manage-gallery' === $hook ) {
return true;
}
if ( false !== strpos( $hook, 'page_flag-manage-gallery' ) ) {
return true;
}
return false;
}

/**
* Checks the hook suffix to see if this is the bulk optimize page.
*
* @param string $hook The hook suffix of the page.
* @returns boolean True for the bulk page, false anywhere else.
*/
function is_bulk_page( $hook ) {
if ( 'flagallery_page_flag-bulk-optimize' === $hook ) {
return true;
}
if ( false !== strpos( $hook, 'page_flag-bulk-optimize' ) ) {
return true;
}
return false;
}

/**
* Prepares the bulk operation and includes the necessary javascript files.
*
Expand All @@ -181,15 +213,15 @@ function ewww_flag_bulk() {
function ewww_flag_bulk_script( $hook ) {
ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
// Make sure we are being hooked from a valid location.
if ( 'flagallery_page_flag-bulk-optimize' !== $hook && 'flagallery_page_flag-manage-gallery' !== $hook ) {
if ( ! $this->is_bulk_page( $hook ) && ! $this->is_gallery_page( $hook ) ) {
return;
}
// If there is no requested bulk action, do nothing.
if ( 'flagallery_page_flag-manage-gallery' === $hook && ( empty( $_REQUEST['bulkaction'] ) || 0 === strpos( $_REQUEST['bulkaction'], 'bulk_optimize' ) ) ) {
if ( $this->is_gallery_page( $hook ) && ( empty( $_REQUEST['bulkaction'] ) || 0 === strpos( $_REQUEST['bulkaction'], 'bulk_optimize' ) ) ) {
return;
}
// If there is no media to optimize, do nothing.
if ( 'flagallery_page_flag-manage-gallery' === $hook && ( empty( $_REQUEST['doaction'] ) || ! is_array( $_REQUEST['doaction'] ) ) ) {
if ( $this->is_gallery_page( $hook ) && ( empty( $_REQUEST['doaction'] ) || ! is_array( $_REQUEST['doaction'] ) ) ) {
return;
}
$ids = null;
Expand Down Expand Up @@ -234,7 +266,7 @@ function ewww_flag_bulk_script( $hook ) {
} elseif ( ! empty( $resume ) ) {
// If there is an operation to resume, get those IDs from the db.
$ids = get_option( 'ewww_image_optimizer_bulk_flag_attachments' );
} elseif ( 'flagallery_page_flag-bulk-optimize' === $hook ) {
} elseif ( $this->is_bulk_page( $hook ) ) {
// Otherwise, if we are on the main bulk optimize page, just get all the IDs available.
global $wpdb;
$ids = $wpdb->get_col( "SELECT pid FROM $wpdb->flagpictures ORDER BY sortorder ASC" );
Expand Down Expand Up @@ -636,7 +668,7 @@ function ewww_flag_bulk_cleanup() {
*/
function ewww_flag_manual_actions_script( $hook ) {
ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
if ( 'flagallery_page_flag-manage-gallery' !== $hook ) {
if ( ! $this->is_gallery_page( $hook ) ) {
return;
}
if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ https://developers.google.com/web/tools/lighthouse/audits/optimize-images
* fixed: JS WebP incorrectly parses GIF/SVG images in Force WebP mode
* fixed: JS WebP does not support lazy load + infinite scroll
* fixed: Lazy Load auto-scaling breaks if background image is enclosed in encoded quotes
* fixed: GRAND FlaGallery integration broken by hook suffix change

= 4.9.2 =
* fixed: generating lazy load PNG placeholders with large heights causes 500 errors
Expand Down

0 comments on commit cc720f6

Please sign in to comment.