forked from tomaszsita/wp-manual-image-crop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manual-image-crop.php
81 lines (64 loc) · 2.67 KB
/
manual-image-crop.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
Plugin Name: Manual Image Crop
Plugin URI: https://github.com/mcaskill/wp-manual-image-crop
Description: Plugin allows you to manually crop all the image sizes registered in your WordPress theme (in particular featured image). Simply click on the "Crop" link next to any image in your media library and select the area of the image you want to crop.
Version: 1.13
Author: Tomasz Sita
Author URI: https://github.com/mcaskill
License: GPL2
Text Domain: microp
Domain Path: /languages/
*/
define('mic_VERSION', '1.13');
include_once(dirname(__FILE__) . '/lib/ManualImageCropSettingsPage.php');
include_once(dirname(__FILE__) . '/lib/plugin-conflicts.php'); // Show important plugin conflicts in an error message
//mic - stands for Manual Image Crop
add_action('plugins_loaded', 'mic_init_plugin');
add_option('mic_make2x', 'true'); //Add option so we can persist make2x choice across sessions
/**
* inits the plugin
*/
function mic_init_plugin() {
// we are gonna use our plugin in the admin area only, so ends here if it's a frontend
if (!is_admin()) return;
include_once(dirname(__FILE__) . '/lib/ManualImageCrop.php');
load_plugin_textdomain('microp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
$ManualImageCrop = ManualImageCrop::getInstance();
add_action( 'admin_enqueue_scripts', array($ManualImageCrop, 'enqueueAssets') );
$ManualImageCrop->addEditorLinks();
//attach admin actions
add_action('wp_ajax_mic_editor_window', 'mic_ajax_editor_window');
add_action('wp_ajax_mic_crop_image', 'mic_ajax_crop_image');
// Support regenerate thumbnails to regenerate them at the specified size
if ( class_exists('RegenerateThumbnails') ) {
include_once( dirname(__FILE__) . '/extensions/regenerate-thumbnails.php' );
}
}
/**
* ajax call rendering the image cropping area
*/
function mic_ajax_editor_window() {
include_once(dirname(__FILE__) . '/lib/ManualImageCropEditorWindow.php');
$ManualImageCropEditorWindow = ManualImageCropEditorWindow::getInstance();
$ManualImageCropEditorWindow->renderWindow();
exit;
}
/**
* ajax call that does the cropping job and overrides the previous image version
*/
function mic_ajax_crop_image() {
$ManualImageCrop = ManualImageCrop::getInstance();
$ManualImageCrop->cropImage();
exit;
}
/**
* add settings link on plugin page
*/
function mic_settings_link($links) {
$settings_link = '<a href="'. admin_url( 'options-general.php?page=Mic-setting-admin' ) .'">' . __('Settings') . '</a>';
array_unshift($links, $settings_link);
return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'mic_settings_link' );