-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpp-set-media-as-gallery-cover.php
157 lines (130 loc) · 2.99 KB
/
mpp-set-media-as-gallery-cover.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
149
150
151
152
153
154
155
156
157
<?php
/**
* Plugin Name: MediaPress Set Media as Gallery Cover
* Description: Let user set a photo as gallery cover. It is a utility plugin.
* Plugin URI: https://buddydev.com/plugins/mpp-set-media-as-gallery-cover/
* Author: BuddyDev
* Author URI: https://buddydev.com/
* Version: 1.0.0
*
* Text Domain: mpp-featured-content
* Domain Path: /languages
*/
// Exit if file access directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class MPP_Set_Media_As_Gallery_Cover
*/
class MPP_Set_Media_As_Gallery_Cover {
/**
* Class instance
*
* @var MPP_Set_Media_As_Gallery_Cover
*/
private static $instance = null;
/**
* Plugin directory path
*
* @var string
*/
private $path;
/**
* Plugin directory url
*
* @var string
*/
private $url;
/**
* The constructor.
*/
private function __construct() {
$this->path = plugin_dir_path( __FILE__ );
$this->url = plugin_dir_url( __FILE__ );
$this->setup();
}
/**
* Get class instance
*
* @return MPP_Set_Media_As_Gallery_Cover
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Setup callbacks to mediapress hooks
*/
public function setup() {
add_action( 'mpp_loaded', array( $this, 'load' ) );
add_action( 'mpp_enqueue_scripts', array( $this, 'load_assets' ) );
add_action( 'mpp_init', array( $this, 'load_text_domain' ) );
}
/**
* Load plugins other files
*/
public function load() {
if ( ! function_exists( 'buddypress' ) ) {
return;
}
$files = array(
'core/mppsmagc-functions.php',
'core/mppsmagc-templates.php',
'core/class-mppsmagc-ajax-handler.php',
'core/class-mppsmagc-view-helper.php',
);
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
$files[] = 'admin/class-mppsmagc-admin-helper.php';
}
foreach ( $files as $file ) {
require_once $this->path . $file;
}
}
/**
* Loads plugin assets
*/
public function load_assets() {
if ( ! function_exists( 'buddypress' ) ) {
return;
}
wp_register_script( 'mpp-set-media-as-gallery-cover', $this->url . 'assets/js/mpp-set-media-as-gallery-cover.js', array( 'jquery' ) );
wp_localize_script( 'mpp-set-media-as-gallery-cover', 'MPPSMAGCover', array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
) );
wp_enqueue_script( 'mpp-set-media-as-gallery-cover' );
}
/**
* Load plugin language file
*/
public function load_text_domain() {
load_plugin_textdomain( 'mpp-set-media-as-gallery-cover', false, basename( dirname( __FILE__ ) ) . '/languages/' );
}
/**
* Return plugin directory path
*
* @return string
*/
public function get_path() {
return $this->path;
}
/**
* Return plugin directory url
*
* @return string
*/
public function get_url() {
return $this->url;
}
}
/**
* Class instance
*
* @return MPP_Set_Media_As_Gallery_Cover
*/
function mpp_set_media_as_gallery_cover() {
return MPP_Set_Media_As_Gallery_Cover::get_instance();
}
mpp_set_media_as_gallery_cover();