PluginProbe
Squeeze – Image Optimization & Compression, WEBP Conversion / 1.5
Squeeze – Image Optimization & Compression, WEBP Conversion v1.5
1.7.15 1.7.14 1.7.13 1.7.12 1.7.11 1.7.10 trunk 1.0 1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5 1.5.1 1.5.2 1.6 All 42 releases
squeeze / squeeze.php

squeeze.php in Squeeze – Image Optimization & Compression, WEBP Conversion 1.5, at squeeze.php

145 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.5
9 *
10 * Text Domain: squeeze
11 * Domain Path: /languages
12 *
13 * License: GPLv3
14 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
15 *
16 */
17 // Exit if accessed directly.
18 if ( !defined( 'ABSPATH' ) ) {
19 exit;
20 }
21 define( 'SQUEEZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
22 define( 'SQUEEZE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
23 define( 'SQUEEZE_PLUGIN_VERSION', '1.5' );
24 define( 'SQUEEZE_ALLOWED_IMAGE_MIME_TYPES', array(
25 'image/jpeg',
26 'image/jpg',
27 'image/png',
28 'image/webp',
29 'image/avif'
30 ) );
31 define( 'SQUEEZE_ALLOWED_IMAGE_FORMATS', 'jpg,jpeg,png,webp,avif' );
32 define( 'SQUEEZE_MEDIA_PER_PAGE', apply_filters( 'squeeze_media_per_page', 50 ) );
33
34 add_action( 'plugins_loaded', 'squeeze_load_textdomain' );
35 /**
36 * Load plugin textdomain
37 */
38 function squeeze_load_textdomain() {
39 load_plugin_textdomain( 'squeeze', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
40 }
41
42 include_once SQUEEZE_PLUGIN_DIR . 'src/settings.php';
43 include_once SQUEEZE_PLUGIN_DIR . 'src/handlers.php';
44 add_action( 'admin_print_footer_scripts', 'squeeze_block_assets' );
45 /**
46 * Enqueue assets
47 */
48 function squeeze_block_assets() {
49 global $pagenow;
50 $options = get_option( 'squeeze_options' );
51 $default_options = squeeze_get_default_value( null, true );
52 // get all default values
53 $js_options = array();
54 foreach ( $default_options as $key => $value ) {
55 if ( isset( $options[$key] ) ) {
56 if ( is_numeric( $options[$key] ) ) {
57 $js_options[$key] = intval( $options[$key] );
58 } elseif ( $options[$key] === "on" ) {
59 $js_options[$key] = true;
60 } elseif ( $key === "compress_thumbs" ) {
61 $js_options[$key] = $options[$key];
62 }
63 } else {
64 $js_options[$key] = $value;
65 }
66 }
67 if ( !wp_script_is( 'media-editor', 'enqueued' ) ) {
68 wp_enqueue_media();
69 }
70 // Enqueue script for backend.
71 wp_enqueue_script(
72 'squeeze-script',
73 plugins_url( '/assets/js/script.bundle.js', __FILE__ ),
74 array('jquery', 'wp-mediaelement'),
75 SQUEEZE_PLUGIN_VERSION,
76 true
77 );
78 // WP Localized globals. Use dynamic PHP stuff in JavaScript via `squeeze` object.
79 wp_localize_script(
80 'squeeze-script',
81 'squeezeOptions',
82 // Array containing dynamic data for a JS Global.
83 [
84 'pluginUrl' => SQUEEZE_PLUGIN_URL,
85 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
86 'nonce' => wp_create_nonce( 'squeeze-nonce' ),
87 'options' => wp_json_encode( $js_options ),
88 ]
89 );
90 if ( $pagenow === 'upload.php' && isset( $_GET['page'] ) && $_GET['page'] === 'squeeze-bulk' ) {
91 wp_localize_script( 'squeeze-script', 'squeezeBulk', [
92 'allImages' => implode( ",", squeeze_get_total_images() ),
93 'unCompressedImages' => implode( ",", squeeze_get_uncompressed_images() ),
94 ] );
95 }
96 // Check if we are on the options page for the plugin
97 if ( $pagenow === 'upload.php' || $pagenow === 'options-general.php' && isset( $_GET['page'] ) && $_GET['page'] === 'squeeze' ) {
98 wp_enqueue_script(
99 'squeeze-settings-script',
100 plugins_url( '/assets/js/admin.js', __FILE__ ),
101 array('jquery'),
102 SQUEEZE_PLUGIN_VERSION,
103 true
104 );
105 }
106 wp_set_script_translations( 'squeeze-script', 'squeeze', plugin_dir_path( __DIR__ ) . 'languages' );
107 // Enqueue styles for backend.
108 wp_enqueue_style(
109 'squeeze-style',
110 plugins_url( '/assets/css/admin.css', __FILE__ ),
111 array(),
112 SQUEEZE_PLUGIN_VERSION
113 );
114 }
115
116 add_filter(
117 'plugin_action_links',
118 'squeeze_plugin_action_links',
119 10,
120 2
121 );
122 /**
123 * Add settings link on plugin page
124 *
125 * @param array $links
126 * @return array
127 */
128 function squeeze_plugin_action_links( $actions, $plugin_file ) {
129 static $plugin;
130 if ( !isset( $plugin ) ) {
131 $plugin = plugin_basename( __FILE__ );
132 }
133 if ( $plugin === $plugin_file ) {
134 $settings_link = array(
135 'settings' => '<a href="' . admin_url( 'options-general.php?page=squeeze' ) . '">' . __( 'Settings', 'squeeze' ) . '</a>',
136 );
137 $bulk_link = array(
138 'bulk' => '<a href="' . admin_url( 'upload.php?page=squeeze-bulk' ) . '">' . __( 'Bulk Squeeze', 'squeeze' ) . '</a>',
139 );
140 $actions = array_merge( $bulk_link, $actions );
141 $actions = array_merge( $settings_link, $actions );
142 }
143 return $actions;
144 }
145