| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Squeeze |
| 5 |
* Description: Compress unlimited images directly into your browser. |
| 6 |
* Author URI: https://bogdan.kyiv.ua |
| 7 |
* Author: Bogdan Bendziukov |
| 8 |
* Version: 1.4.7 |
| 9 |
* |
| 10 |
* Text Domain: squeeze |
| 11 |
* Domain Path: /languages |
| 12 |
* |
| 13 |
* License: GNU GPL v3 |
| 14 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.html |
| 15 |
* |
| 16 |
* Network: false |
| 17 |
* |
| 18 |
*/ |
| 19 |
// Exit if accessed directly. |
| 20 |
if ( !defined( 'ABSPATH' ) ) { |
| 21 |
exit; |
| 22 |
} |
| 23 |
define( 'SQUEEZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 24 |
define( 'SQUEEZE_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 25 |
define( 'SQUEEZE_PLUGIN_VERSION', '1.4.7' ); |
| 26 |
define( 'SQUEEZE_ALLOWED_IMAGE_MIME_TYPES', array( |
| 27 |
'image/jpeg', |
| 28 |
'image/jpg', |
| 29 |
'image/png', |
| 30 |
'image/webp', |
| 31 |
'image/avif' |
| 32 |
) ); |
| 33 |
define( 'SQUEEZE_ALLOWED_IMAGE_FORMATS', 'jpg,jpeg,png,webp,avif' ); |
| 34 |
|
| 35 |
add_action( 'plugins_loaded', 'squeeze_load_textdomain' ); |
| 36 |
/** |
| 37 |
* Load plugin textdomain |
| 38 |
*/ |
| 39 |
function squeeze_load_textdomain() { |
| 40 |
load_plugin_textdomain( 'squeeze', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 41 |
} |
| 42 |
|
| 43 |
include_once SQUEEZE_PLUGIN_DIR . 'src/settings.php'; |
| 44 |
include_once SQUEEZE_PLUGIN_DIR . 'src/handlers.php'; |
| 45 |
add_action( 'admin_print_footer_scripts', 'squeeze_block_assets' ); |
| 46 |
/** |
| 47 |
* Enqueue assets |
| 48 |
*/ |
| 49 |
function squeeze_block_assets() { |
| 50 |
global $pagenow; |
| 51 |
$options = get_option( 'squeeze_options' ); |
| 52 |
$default_options = squeeze_get_default_value( null, true ); |
| 53 |
// get all default values |
| 54 |
$js_options = array(); |
| 55 |
foreach ( $default_options as $key => $value ) { |
| 56 |
if ( isset( $options[$key] ) ) { |
| 57 |
if ( is_numeric( $options[$key] ) ) { |
| 58 |
$js_options[$key] = intval( $options[$key] ); |
| 59 |
} elseif ( $options[$key] === "on" ) { |
| 60 |
$js_options[$key] = true; |
| 61 |
} elseif ( $key === "compress_thumbs" ) { |
| 62 |
$js_options[$key] = $options[$key]; |
| 63 |
} |
| 64 |
} else { |
| 65 |
$js_options[$key] = $value; |
| 66 |
} |
| 67 |
} |
| 68 |
if ( !wp_script_is( 'media-editor', 'enqueued' ) ) { |
| 69 |
wp_enqueue_media(); |
| 70 |
} |
| 71 |
// Enqueue script for backend. |
| 72 |
wp_enqueue_script( |
| 73 |
'squeeze-script', |
| 74 |
plugins_url( '/assets/js/script.bundle.js', __FILE__ ), |
| 75 |
array('jquery', 'wp-mediaelement'), |
| 76 |
SQUEEZE_PLUGIN_VERSION, |
| 77 |
true |
| 78 |
); |
| 79 |
// WP Localized globals. Use dynamic PHP stuff in JavaScript via `squeeze` object. |
| 80 |
wp_localize_script( |
| 81 |
'squeeze-script', |
| 82 |
'squeezeOptions', |
| 83 |
// Array containing dynamic data for a JS Global. |
| 84 |
[ |
| 85 |
'pluginUrl' => SQUEEZE_PLUGIN_URL, |
| 86 |
'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
| 87 |
'nonce' => wp_create_nonce( 'squeeze-nonce' ), |
| 88 |
'options' => wp_json_encode( $js_options ), |
| 89 |
] |
| 90 |
); |
| 91 |
// Check if we are on the options page for the plugin |
| 92 |
if ( $pagenow === 'upload.php' && isset( $_GET['page'] ) && $_GET['page'] === 'squeeze' ) { |
| 93 |
wp_enqueue_script( |
| 94 |
'squeeze-settings-script', |
| 95 |
plugins_url( '/assets/js/admin.js', __FILE__ ), |
| 96 |
array('jquery'), |
| 97 |
SQUEEZE_PLUGIN_VERSION, |
| 98 |
true |
| 99 |
); |
| 100 |
} |
| 101 |
wp_set_script_translations( 'squeeze-script', 'squeeze', plugin_dir_path( __DIR__ ) . 'languages' ); |
| 102 |
// Enqueue styles for backend. |
| 103 |
wp_enqueue_style( |
| 104 |
'squeeze-style', |
| 105 |
plugins_url( '/assets/css/admin.css', __FILE__ ), |
| 106 |
array(), |
| 107 |
SQUEEZE_PLUGIN_VERSION |
| 108 |
); |
| 109 |
} |
| 110 |
|