PluginProbe
WP Ultimate Post Grid / 1.6
WP Ultimate Post Grid v1.6
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / wp-ultimate-post-grid.php

wp-ultimate-post-grid.php in WP Ultimate Post Grid 1.6, at wp-ultimate-post-grid.php

222 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP Ultimate Post Grid
4 Plugin URI: http://bootstrapped.ventures/wp-ultimate-post-grid/
5 Description: Easily create filterable grids for any of your posts, pages or custom post types
6 Version: 1.6
7 Author: Bootstrapped Ventures
8 Author URI: http://bootstrapped.ventures
9 License: GPLv3
10 */
11 define( 'WPUPG_VERSION', '1.6' );
12 define( 'WPUPG_POST_TYPE', 'wpupg_grid' );
13
14 class WPUltimatePostGrid {
15
16 private static $instance;
17 private static $instantiated_by_premium;
18 private static $addons = array();
19
20 /**
21 * Return instance of self
22 */
23 public static function get( $instantiated_by_premium = false )
24 {
25 // Instantiate self only once
26 if( is_null( self::$instance ) ) {
27 self::$instantiated_by_premium = $instantiated_by_premium;
28 self::$instance = new self;
29 self::$instance->init();
30 }
31
32 return self::$instance;
33 }
34
35 /**
36 * Returns true if we are using the Premium version
37 */
38 public static function is_premium_active()
39 {
40 return self::$instantiated_by_premium;
41 }
42
43 /**
44 * Add loaded addon to array of loaded addons
45 */
46 public static function loaded_addon( $addon, $instance )
47 {
48 if( !array_key_exists( $addon, self::$addons ) ) {
49 self::$addons[$addon] = $instance;
50 }
51 }
52
53 /**
54 * Returns true if the specified addon has been loaded
55 */
56 public static function is_addon_active( $addon )
57 {
58 return array_key_exists( $addon, self::$addons );
59 }
60
61 public static function addon( $addon )
62 {
63 if( isset( self::$addons[$addon] ) ) {
64 return self::$addons[$addon];
65 }
66
67 return false;
68 }
69
70 /**
71 * Access a VafPress option with optional default value
72 */
73 public static function option( $name, $default = null )
74 {
75 $option = vp_option( 'wpupg_option.' . $name );
76
77 return is_null( $option ) ? $default : $option;
78 }
79
80
81 public $pluginName = 'wp-ultimate-post-grid';
82 public $coreDir;
83 public $corePath;
84 public $coreUrl;
85 public $pluginFile;
86
87 protected $helper_dirs = array();
88 protected $helpers = array();
89
90 /**
91 * Initialize
92 */
93 public function init()
94 {
95 // Load external libraries
96 if( !class_exists( 'VP_AutoLoader' ) ) {
97 require_once( 'vendor/vafpress/bootstrap.php' );
98 }
99
100 // Update plugin version
101 update_option( $this->pluginName . '_version', WPUPG_VERSION );
102
103 // Set core directory, URL and main plugin file
104 $this->corePath = str_replace( '/wp-ultimate-post-grid.php', '', plugin_basename( __FILE__ ) );
105 $this->coreDir = apply_filters( 'wpupg_core_dir', WP_PLUGIN_DIR . '/' . $this->corePath );
106 $this->coreUrl = apply_filters( 'wpupg_core_url', plugins_url() . '/' . $this->corePath );
107 $this->pluginFile = apply_filters( 'wpupg_plugin_file', __FILE__ );
108
109 // Load textdomain
110 if( !self::is_premium_active() ) {
111 $domain = 'wp-ultimate-post-grid';
112 $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
113
114 load_textdomain( $domain, WP_LANG_DIR.'/'.$domain.'/'.$domain.'-'.$locale.'.mo' );
115 load_plugin_textdomain( $domain, false, $this->corePath . '/lang/' );
116 }
117
118 // Add core helper directory
119 $this->add_helper_directory( $this->coreDir . '/helpers' );
120
121 // Migrate first if needed
122 $this->helper( 'migration' );
123
124 // Load required helpers
125 $this->helper( 'activate' );
126 $this->helper( 'ajax' );
127 $this->helper( 'content' );
128 $this->helper( 'css' );
129 $this->helper( 'faq' );
130 $this->helper( 'grid_cache' );
131 $this->helper( 'grid_save' );
132 $this->helper( 'meta_box' );
133 $this->helper( 'notices' );
134 $this->helper( 'pagination' );
135 $this->helper( 'plugin_action_link' );
136 $this->helper( 'post_type' );
137 $this->helper( 'support_tab' );
138 $this->helper( 'vafpress_menu' );
139 $this->helper( 'vafpress_shortcode' );
140 $this->helper( 'shortcodes/filter_shortcode' );
141 $this->helper( 'shortcodes/grid_shortcode' );
142
143 // Include required helpers but don't instantiate
144 $this->include_helper( 'addons/addon' );
145 $this->include_helper( 'addons/premium_addon' );
146 $this->include_helper( 'models/grid' );
147
148 // Load core addons
149 $this->helper( 'addon_loader' )->load_addons( $this->coreDir . '/addons' );
150
151 // Load default assets
152 $this->helper( 'assets' );
153 }
154
155 /**
156 * Access a helper. Will instantiate if helper hasn't been loaded before.
157 */
158 public function helper( $helper )
159 {
160 // Lazy instantiate helper
161 if( !isset( $this->helpers[$helper] ) ) {
162 $this->include_helper( $helper );
163
164 // Get class name from filename
165 $class_name = 'WPUPG';
166
167 $dirs = explode( '/', $helper );
168 $file = end( $dirs );
169 $name_parts = explode( '_', $file );
170 foreach( $name_parts as $name_part ) {
171 $class_name .= '_' . ucfirst( $name_part );
172 }
173
174 // Instantiate class if exists
175 if( class_exists( $class_name ) ) {
176 $this->helpers[$helper] = new $class_name();
177 }
178 }
179
180 // Return helper instance
181 return $this->helpers[$helper];
182 }
183
184 /**
185 * Include a helper. Looks through all helper directories that have been added.
186 */
187 public function include_helper( $helper )
188 {
189 foreach( $this->helper_dirs as $dir )
190 {
191 $file = $dir . '/'.$helper.'.php';
192
193 if( file_exists( $file ) ) {
194 require_once( $file );
195 }
196 }
197 }
198
199 /**
200 * Add a directory to look for helpers.
201 */
202 public function add_helper_directory( $dir )
203 {
204 if( is_dir( $dir ) ) {
205 $this->helper_dirs[] = $dir;
206 }
207 }
208
209 /*
210 * Quick access functions
211 */
212
213 public function template( $template )
214 {
215 return $this->addon( 'custom-templates' )->get_template( $template );
216 }
217 }
218
219 // Premium version is responsible for instantiating if available
220 if( !class_exists( 'WPUltimatePostGridPremium' ) ) {
221 WPUltimatePostGrid::get();
222 }