-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from wp-media/branch-1.4.5
Rename Admin Page + Add Imagify Banner
- Loading branch information
Showing
8 changed files
with
251 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' ); | ||
|
||
/** | ||
* Manage the dismissed boxes | ||
* | ||
* @since 2.4 Add a delete_transient on function name (box name) | ||
* @since 1.3.0 $args can replace $_GET when called internaly | ||
* @since 1.1.10 | ||
* | ||
* @param array $args An array of query args. | ||
*/ | ||
function rocket_lazyload_dismiss_boxes( $args ) { | ||
$args = empty( $args ) ? $_GET : $args; | ||
|
||
if ( isset( $args['box'], $args['_wpnonce'] ) ) { | ||
|
||
if ( ! wp_verify_nonce( $args['_wpnonce'], $args['action'] . '_' . $args['box'] ) ) { | ||
if ( defined( 'DOING_AJAX' ) ) { | ||
wp_send_json( array( 'error' => 1 ) ); | ||
} else { | ||
wp_nonce_ays( '' ); | ||
} | ||
} | ||
|
||
if ( '__rocket_lazyload_imagify_notice' === $args['box'] ) { | ||
update_option( 'rocket_lazyload_dismiss_imagify_notice', 0 ); | ||
} | ||
|
||
global $current_user; | ||
$actual = get_user_meta( $current_user->ID, 'rocket_lazyload_boxes', true ); | ||
$actual = array_merge( (array) $actual, array( $args['box'] ) ); | ||
$actual = array_filter( $actual ); | ||
$actual = array_unique( $actual ); | ||
update_user_meta( $current_user->ID, 'rocket_lazyload_boxes', $actual ); | ||
delete_transient( $args['box'] ); | ||
|
||
if ( 'admin-post.php' === $GLOBALS['pagenow'] ) { | ||
if ( defined( 'DOING_AJAX' ) ) { | ||
wp_send_json( array( 'error' => 0 ) ); | ||
} else { | ||
wp_safe_redirect( wp_get_referer() ); | ||
die(); | ||
} | ||
} | ||
} | ||
} | ||
add_action( 'wp_ajax_rocket_lazyload_ignore', 'rocket_lazyload_dismiss_boxes' ); | ||
add_action( 'admin_post_rocket_lazyload_ignore', 'rocket_lazyload_dismiss_boxes' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' ); | ||
|
||
/** | ||
* Add a message about Imagify on the Rocket LazyLoad options page. | ||
* | ||
* @author Geoffrey Crofte | ||
* @return void | ||
* @since 1.4.5 | ||
*/ | ||
function rocket_lazyload_imagify_notice() { | ||
$current_screen = get_current_screen(); | ||
|
||
// Add the notice only on the "WP Rocket" settings, "Media Library" & "Upload New Media" screens. | ||
if ( 'admin_notices' === current_filter() && ( isset( $current_screen ) && 'settings_page_rocket-lazyload' !== $current_screen->base ) ) { | ||
return; | ||
} | ||
|
||
$boxes = get_user_meta( $GLOBALS['current_user']->ID, 'rocket_lazyload_boxes', true ); | ||
|
||
if ( defined( 'IMAGIFY_VERSION' ) || in_array( __FUNCTION__, (array) $boxes, true ) || 1 === get_option( 'rocket_lazyload_dismiss_imagify_notice' ) || ! current_user_can( 'manage_options' ) ) { | ||
return; | ||
} | ||
|
||
$action_url = wp_nonce_url( add_query_arg( | ||
array( | ||
'action' => 'install-plugin', | ||
'plugin' => 'imagify', | ||
), | ||
admin_url( 'update.php' ) | ||
), 'install-plugin_imagify' ); | ||
|
||
$classes = ' install-now'; | ||
$cta_txt = esc_html__( 'Install Imagify for Free', 'rocket-lazyload' ); | ||
|
||
$dismiss_url = wp_nonce_url( | ||
admin_url( 'admin-post.php?action=rocket_lazyload_ignore&box=' . __FUNCTION__ ), | ||
'rocket_lazyload_ignore_' . __FUNCTION__ | ||
); | ||
?> | ||
|
||
<div id="plugin-filter" class="updated plugin-card plugin-card-imagify rktll-imagify-notice"> | ||
<a href="<?php echo $dismiss_url; ?>" class="rktll-cross"><span class="dashicons dashicons-no"></span></a> | ||
|
||
<p class="rktll-imagify-logo"> | ||
<img src="<?php echo ROCKET_LL_ASSETS_URL ?>img/logo-imagify.png" srcset="<?php echo ROCKET_LL_ASSETS_URL ?>img/logo-imagify.svg 2x" alt="Imagify" width="150" height="18"> | ||
</p> | ||
<p class="rktll-imagify-msg"> | ||
<?php _e( 'Speed up your website and boost your SEO by reducing image file sizes without losing quality with Imagify.', 'rocket-lazyload' ); ?> | ||
</p> | ||
<p class="rktll-imagify-cta"> | ||
<a data-slug="imagify" href="<?php echo $action_url; ?>" class="button button-primary<?php echo $classes; ?>"><?php echo $cta_txt; ?></a> | ||
</p> | ||
</div> | ||
|
||
<?php | ||
} | ||
add_action( 'admin_notices', 'rocket_lazyload_imagify_notice' ); | ||
|
||
/** | ||
* Add Script to remove Notice thanks to JS. | ||
* @since 1.4.5 | ||
* @author Geoffrey Crofte | ||
* @return void | ||
*/ | ||
function rocket_lazyload_notice_script() { | ||
echo <<<HTML | ||
<script> | ||
jQuery( document ).ready( function( $ ){ | ||
$( '.rktll-cross' ).on( 'click', function( e ) { | ||
e.preventDefault(); | ||
var url = $( this ).attr( 'href' ).replace( 'admin-post', 'admin-ajax' ); | ||
$.get( url ).done( $( this ).parent().hide( 'slow' ) ); | ||
}); | ||
} ); | ||
</script> | ||
HTML; | ||
} | ||
add_action( 'admin_footer', 'rocket_lazyload_notice_script' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.