forked from interconnectit/my-eyes-are-up-here
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-eyes-are-up-here.php
148 lines (128 loc) · 2.86 KB
/
my-eyes-are-up-here.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* Plugin Name: My Eyes Are Up Here
* Plugin URI: https://github.com/interconnectit/my-eyes-are-up-here
* Description: Detects faces during thumbnail cropping and moves the crop position accordingly.
* Version: 99.99.99
* Author: interconnect/it
* Author URI: http://interconnectit.com
*
* Text Domain: my-eyes-are-up-here
* Domain Path: /languages/
*
* @package my-eyes-are-up-here
* @author interconnect/it
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class MyEyesAreUpHere
*/
final class MyEyesAreUpHere {
const REQUEST_ADMIN = 'admin';
const REQUEST_AJAX = 'ajax';
const REQUEST_WP_CLI = 'wp-cli';
/**
* Instance
*
* @var MyEyesAreUpHere
*/
private static $_instance;
/**
* Get instance
*
* @return MyEyesAreUpHere
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self;
}
return self::$_instance;
}
/**
* Constructor
*/
public function __construct() {
$this->includes();
$this->init_hooks();
}
/**
* Determine request type
*
* @param string $type Request type.
*
* @return bool
*/
public function is_request( $type ) {
switch ( $type ) {
case self::REQUEST_ADMIN:
return is_admin();
case self::REQUEST_AJAX:
return defined( 'DOING_AJAX' );
case self::REQUEST_WP_CLI:
return ( defined( 'WP_CLI' ) && WP_CLI );
}
}
/**
* Get plugin path
*
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
/**
* Get plugin URL
*
* @return string
*/
public function plugin_url() {
return untrailingslashit( plugins_url( '/', __FILE__ ) );
}
/**
* Get ajax URL
*
* @return string
*/
public function ajax_url() {
return admin_url( 'admin-ajax.php', 'relative' );
}
/**
* Load localisation
*/
public function localisation() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'my-eyes-are-up-here' );
load_textdomain( 'my-eyes-are-up-here', WP_LANG_DIR . '/my-eyes-are-up-here/my-eyes-are-up-here-' . $locale . '.mo' );
load_plugin_textdomain( 'my-eyes-are-up-here', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
}
/**
* Includes
*/
protected function includes() {
require_once 'includes/class-meauh-ajax.php';
require_once 'includes/class-meauh-attachment.php';
if ( $this->is_request( self::REQUEST_ADMIN ) ) {
require_once 'includes/class-meauh-admin.php';
}
if ( $this->is_request( self::REQUEST_WP_CLI ) ) {
require_once 'includes/class-meauh-attachment.php';
}
}
/**
* Init hooks
*/
protected function init_hooks() {
add_action( 'init', array( $this, 'localisation' ), 0 );
}
}
/**
* Get instance
*
* @return MyEyesAreUpHere
*/
function meauh() {
return MyEyesAreUpHere::instance();
}
// Global for backwards compatibility.
$GLOBALS['meauh'] = meauh();