PluginProbe
Squeeze – Image Optimization & Compression, WEBP Conversion / 1.1
Squeeze – Image Optimization & Compression, WEBP Conversion v1.1
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.1, at squeeze.php

93 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Squeeze
4 * Description: Compress images by squoosh.app
5 * Author URI: https://bogdan.kyiv.ua
6 * Author: Bogdan Bendziukov
7 * Version: 1.1
8 *
9 * Text Domain: squeeze
10 * Domain Path: /languages
11 *
12 * License: GNU GPL v3
13 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
14 *
15 * Network: false
16 *
17 */
18
19 // Exit if accessed directly.
20 if (!defined('ABSPATH')) {
21 exit;
22 }
23
24 define('SQUEEZE_PLUGIN_DIR', plugin_dir_path(__FILE__));
25 define('SQUEEZE_PLUGIN_URL', plugin_dir_url(__FILE__));
26
27 add_action('plugins_loaded', 'squeeze_load_textdomain');
28 /**
29 * Load plugin textdomain
30 */
31 function squeeze_load_textdomain() {
32 load_plugin_textdomain('squeeze', false, dirname(plugin_basename(__FILE__)) . '/languages/');
33 }
34
35 include_once(SQUEEZE_PLUGIN_DIR . 'src/settings.php');
36 include_once(SQUEEZE_PLUGIN_DIR . 'src/handlers.php');
37
38
39 add_action('admin_print_footer_scripts', 'squeeze_block_assets');
40 /**
41 * Enqueue assets
42 */
43 function squeeze_block_assets() {
44 global $pagenow;
45
46 $options = get_option( 'squeeze_options' );
47 $default_options = squeeze_get_default_value( null, true); // get all default values
48 $js_options = array();
49
50 foreach ($default_options as $key => $value) {
51 if (isset($options[$key])) {
52 if (is_numeric($options[$key])) {
53 $js_options[$key] = intval($options[$key]);
54 } elseif ($options[$key] === "on") {
55 $js_options[$key] = true;
56 }
57 } else {
58 $js_options[$key] = $value;
59 }
60 }
61
62 // Enqueue script for backend.
63
64 wp_enqueue_script(
65 'squeeze-script',
66 // Handle.
67 plugins_url('/assets/js/script.bundle.js', __FILE__),
68 array('jquery', 'wp-mediaelement'),
69 // Dependencies, defined above.
70 null,
71 true // Enqueue the script in the footer.
72 );
73
74
75 // WP Localized globals. Use dynamic PHP stuff in JavaScript via `squeeze` object.
76 wp_localize_script(
77 'squeeze-script',
78 'squeeze',
79 // Array containing dynamic data for a JS Global.
80 [
81 'pluginUrl' => SQUEEZE_PLUGIN_URL,
82 'ajaxUrl' => admin_url('admin-ajax.php'),
83 'nonce' => wp_create_nonce('squeeze-nonce'),
84 'options' => json_encode($js_options),
85 ]
86 );
87
88 wp_set_script_translations('squeeze-script', 'squeeze', plugin_dir_path(__DIR__) . 'languages');
89
90 }
91
92
93