Merged in feature/from-pantheon (pull request #16)

code from pantheon

* code from pantheon
This commit is contained in:
Tony Volpe
2024-01-10 17:03:02 +00:00
parent 054b4fffc9
commit 4eb982d7a8
16492 changed files with 3475854 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
defined( 'ABSPATH' ) || die( 'Cheatin uh?' );
add_action( 'admin_bar_menu', '_imagify_admin_bar', IMAGIFY_INT_MAX );
/**
* Add Imagify menu in the admin bar.
*
* @since 1.0
*
* @param object $wp_admin_bar WP_Admin_Bar instance, passed by reference.
*/
function _imagify_admin_bar( $wp_admin_bar ) {
if ( ! imagify_get_context( 'wp' )->current_user_can( 'manage' ) ) {
return;
}
if ( ! get_imagify_option( 'admin_bar_menu' ) ) {
return;
}
// Parent.
$wp_admin_bar->add_menu( array(
'id' => 'imagify',
'title' => 'Imagify',
'href' => get_imagify_admin_url(),
) );
// Settings.
$wp_admin_bar->add_menu(array(
'parent' => 'imagify',
'id' => 'imagify-settings',
'title' => __( 'Settings' ),
'href' => get_imagify_admin_url(),
) );
// Bulk Optimization.
if ( ! is_network_admin() ) {
$wp_admin_bar->add_menu(array(
'parent' => 'imagify',
'id' => 'imagify-bulk-optimization',
'title' => __( 'Bulk Optimization', 'imagify' ),
'href' => get_imagify_admin_url( 'bulk-optimization' ),
) );
}
// Documentation.
$wp_admin_bar->add_menu(array(
'parent' => 'imagify',
'id' => 'imagify-documentation',
'title' => __( 'Documentation', 'imagify' ),
'href' => imagify_get_external_url( 'documentation' ),
'meta' => array(
'target' => '_blank',
),
) );
// Rate it.
$wp_admin_bar->add_menu(array(
'parent' => 'imagify',
'id' => 'imagify-rate-it',
/* translators: %s is WordPress.org. */
'title' => sprintf( __( 'Rate Imagify on %s', 'imagify' ), 'WordPress.org' ),
'href' => imagify_get_external_url( 'rate' ),
'meta' => array(
'target' => '_blank',
),
) );
// Quota & Profile informations.
if ( defined( 'IMAGIFY_HIDDEN_ACCOUNT' ) && IMAGIFY_HIDDEN_ACCOUNT || ! get_imagify_option( 'api_key' ) ) {
return;
}
$wp_admin_bar->add_menu( array(
'parent' => 'imagify',
'id' => 'imagify-profile',
'title' => wp_nonce_field( 'imagify-get-admin-bar-profile', 'imagifygetadminbarprofilenonce', false, false ) . '<div id="wp-admin-bar-imagify-profile-loading" class="hide-if-no-js">' . __( 'Loading...', 'imagify' ) . '</div><div id="wp-admin-bar-imagify-profile-content" class="hide-if-no-js"></div>',
) );
}

View File

@@ -0,0 +1,69 @@
<?php
defined( 'ABSPATH' ) || die( 'Cheatin uh?' );
add_action( 'delete_attachment', 'imagify_trigger_delete_attachment_hook' );
/**
* Trigger a common Imagify hook when an attachment is deleted.
*
* @since 1.9
* @author Grégory Viguier
*
* @param int $post_id Attachment ID.
*/
function imagify_trigger_delete_attachment_hook( $post_id ) {
$process = imagify_get_optimization_process( $post_id, 'wp' );
if ( ! $process->is_valid() ) {
return;
}
imagify_trigger_delete_media_hook( $process );
}
add_action( 'imagify_delete_media', 'imagify_cleanup_after_media_deletion' );
/**
* Delete the backup file and the WebP files when an attachement is deleted.
*
* @since 1.9
* @author Grégory Viguier
*
* @param ProcessInterface $process An optimization process.
*/
function imagify_cleanup_after_media_deletion( $process ) {
if ( 'wp' !== $process->get_media()->get_context() ) {
return;
}
/**
* The optimization data will be automatically deleted by WP (post metas).
* Delete the WebP versions and the backup file.
*/
$process->delete_webp_files();
$process->delete_backup();
}
add_filter( 'ext2type', 'imagify_add_webp_type' );
/**
* Add the WebP extension to wp_get_ext_types().
*
* @since 1.9
* @author Grégory Viguier
*
* @param array $ext2type Multi-dimensional array with extensions for a default set of file types.
* @return array
*/
function imagify_add_webp_type( $ext2type ) {
if ( ! in_array( 'webp', $ext2type['image'], true ) ) {
$ext2type['image'][] = 'webp';
}
return $ext2type;
}
/**
* Set WPs "big images threshold" to Imagifys resizing value.
*
* @since 1.9.8
* @since WP 5.3
* @author Grégory Viguier
*/
add_filter( 'big_image_size_threshold', [ imagify_get_context( 'wp' ), 'get_resizing_threshold' ], IMAGIFY_INT_MAX );

View File

@@ -0,0 +1,33 @@
<?php
defined( 'ABSPATH' ) || die( 'Cheatin uh?' );
add_action( 'update_option_' . Imagify_Options::get_instance()->get_option_name(), 'imagify_maybe_delete_partner_on_option_update', 10, 2 );
/**
* After the first API key has been successfully added, make sure the partner ID is deleted.
*
* @since 1.6.14
* @author Grégory Viguier
*
* @param mixed $old_value The old option value.
* @param mixed $new_value The new option value.
*/
function imagify_maybe_delete_partner_on_option_update( $old_value, $new_value ) {
if ( empty( $old_value['api_key'] ) && ! empty( $new_value['api_key'] ) ) {
imagify_delete_partner();
}
}
add_action( 'update_site_option_' . Imagify_Options::get_instance()->get_option_name(), 'imagify_maybe_delete_partner_on_network_option_update', 10, 3 );
/**
* After the first API key has been successfully added to the network option, make sure the partner ID is deleted.
*
* @since 1.6.14
* @author Grégory Viguier
*
* @param string $option Name of the network option.
* @param mixed $new_value The new network option value.
* @param mixed $old_value The old network option value.
*/
function imagify_maybe_delete_partner_on_network_option_update( $option, $new_value, $old_value ) {
imagify_maybe_delete_partner_on_option_update( $old_value, $new_value );
}