$value ) {
if ( isset( $options[$key] ) ) {
if ( is_numeric( $options[$key] ) ) {
$js_options[$key] = intval( $options[$key] );
} elseif ( $options[$key] === "on" ) {
$js_options[$key] = true;
} elseif ( $key === "compress_thumbs" ) {
$js_options[$key] = $options[$key];
}
} else {
$js_options[$key] = $value;
}
}
if ( !wp_script_is( 'media-editor', 'enqueued' ) ) {
wp_enqueue_media();
}
// Enqueue script for backend.
wp_enqueue_script(
'squeeze-script',
plugins_url( '/assets/js/script.bundle.js', __FILE__ ),
array('jquery', 'wp-mediaelement'),
SQUEEZE_PLUGIN_VERSION,
true
);
// WP Localized globals. Use dynamic PHP stuff in JavaScript via `squeeze` object.
wp_localize_script(
'squeeze-script',
'squeezeOptions',
// Array containing dynamic data for a JS Global.
[
'pluginUrl' => SQUEEZE_PLUGIN_URL,
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'squeeze-nonce' ),
'options' => wp_json_encode( $js_options ),
]
);
if ( $pagenow === 'upload.php' && isset( $_GET['page'] ) && $_GET['page'] === 'squeeze-bulk' ) {
wp_localize_script( 'squeeze-script', 'squeezeBulk', [
'allImages' => implode( ",", squeeze_get_total_images() ),
'unCompressedImages' => implode( ",", squeeze_get_uncompressed_images() ),
] );
}
// Check if we are on the options page for the plugin
if ( $pagenow === 'upload.php' || $pagenow === 'options-general.php' && isset( $_GET['page'] ) && $_GET['page'] === 'squeeze' ) {
wp_enqueue_script(
'squeeze-settings-script',
plugins_url( '/assets/js/admin.js', __FILE__ ),
array('jquery'),
SQUEEZE_PLUGIN_VERSION,
true
);
}
wp_set_script_translations( 'squeeze-script', 'squeeze', plugin_dir_path( __DIR__ ) . 'languages' );
// Enqueue styles for backend.
wp_enqueue_style(
'squeeze-style',
plugins_url( '/assets/css/admin.css', __FILE__ ),
array(),
SQUEEZE_PLUGIN_VERSION
);
}
add_filter(
'plugin_action_links',
'squeeze_plugin_action_links',
10,
2
);
/**
* Add settings link on plugin page
*
* @param array $links
* @return array
*/
function squeeze_plugin_action_links( $actions, $plugin_file ) {
static $plugin;
if ( !isset( $plugin ) ) {
$plugin = plugin_basename( __FILE__ );
}
if ( $plugin === $plugin_file ) {
$settings_link = array(
'settings' => '' . __( 'Settings', 'squeeze' ) . '',
);
$bulk_link = array(
'bulk' => '' . __( 'Bulk Squeeze', 'squeeze' ) . '',
);
$actions = array_merge( $bulk_link, $actions );
$actions = array_merge( $settings_link, $actions );
}
return $actions;
}