-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-grid-sorter.php
executable file
·142 lines (124 loc) · 3.39 KB
/
wp-grid-sorter.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
<?php
/**
* @package Grid Sorter
* @version 1.0.0
*/
/*
Plugin Name: Grid Sorter
Description: Sort your grid
Author: Vu Tran
Version: 1.0.0
Author URI: http://vu-tran.com/
*/
class WPGridSorter
{
/**
* The plugins root path
*
* @access protected
* @var string
*/
protected $path = '';
/**
* Initializes the plugin
*
* @access public
* @param string $path
* @return void
*/
public function __construct($path)
{
$this->path = $path;
// Load included files
$this->loadInc();
// Load modules
$this->loadModules();
// Load static assets
$this->loadAssets();
// Load modules
$this->ajax = new WPGridSorter_Ajax($this);
$this->mappings = new WPGridSorter_Mappings($this);
$this->pages = new WPGridSorter_Pages($this, WP_GRID_SORTER_PATH . '/pages/');
// Register admin pages
add_action('admin_menu', array(&$this, 'registerPages'));
}
/**
* Load included files
*
* @access private
* @return void
*/
private function loadInc()
{
require_once('inc/functions.php');
require_once('inc/hooks.php');
}
/**
* Load plugin modules
*
* @access private
* @return void
*/
private function loadModules()
{
require_once('modules/ajax.php');
require_once('modules/mappings.php');
require_once('modules/pages.php');
}
/**
* Enqueues stylesheets and javascripts
*
* @access private
* @return void
*/
private function loadAssets()
{
// Register third-party packages
if (is_admin()) {
wp_register_script('imagesLoaded', plugins_url('assets/scripts/imagesLoaded.js', __FILE__), array('jquery'));
wp_register_script('draggabilly', plugins_url('assets/scripts/draggabilly.pkgd.min.js', __FILE__), array('jquery'));
wp_register_script('packery', plugins_url('assets/scripts/packery.pkgd.min.js', __FILE__), array('jquery'));
// Register the stylesheets/scripts
wp_register_style('wp-grid-sorter-main', plugins_url('assets/stylesheets/wp-grid-sorter.css', __FILE__));
wp_register_script('wp-grid-sorter-main', plugins_url('assets/scripts/wp-grid-sorter.js', __FILE__), array('jquery', 'jquery-ui-sortable', 'jquery-form', 'imagesLoaded', 'draggabilly', 'packery'));
// Enqueue the stylesheets/scripts
wp_enqueue_style('wp-grid-sorter-main');
wp_enqueue_script('wp-grid-sorter-main');
}
}
/**
* Register custom admin menu pages
*
* @access public
* @return void
*/
public function registerPages()
{
add_menu_page('Grid Sorter', 'Grid Sorter', 'edit_posts', 'wp-grid-sorter/pages/general', array(&$this->pages, 'general'));
}
/**
* Retrieve the root plugin path
*
* @access public
* @return string
*/
public function getPath()
{
return $this->path;
}
}
add_action('init', 'wp_grid_sorter_init');
/**
* Initializes the plugin
*
* @access public
* @return void
*/
function wp_grid_sorter_init()
{
// Load constants
define('WP_GRID_SORTER_PATH', plugin_dir_path(__FILE__));
global $wp_grid_sorter;
// Instantiate the plugin
$wp_grid_sorter = new WPGridSorter(WP_GRID_SORTER_PATH);
}