PluginProbe
WP Ultimate Post Grid / 1.7
WP Ultimate Post Grid v1.7
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.7, at wp-ultimate-post-grid.php

224 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.7
7 Author: Bootstrapped Ventures
8 Author URI: http://bootstrapped.ventures
9 License: GPLv3
10 */
11 define( 'WPUPG_VERSION', '1.7' );
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( 'meta_box_post' );
134 $this->helper( 'notices' );
135 $this->helper( 'pagination' );
136 $this->helper( 'plugin_action_link' );
137 $this->helper( 'post_save' );
138 $this->helper( 'post_type' );
139 $this->helper( 'support_tab' );
140 $this->helper( 'vafpress_menu' );
141 $this->helper( 'vafpress_shortcode' );
142 $this->helper( 'shortcodes/filter_shortcode' );
143 $this->helper( 'shortcodes/grid_shortcode' );
144
145 // Include required helpers but don't instantiate
146 $this->include_helper( 'addons/addon' );
147 $this->include_helper( 'addons/premium_addon' );
148 $this->include_helper( 'models/grid' );
149
150 // Load core addons
151 $this->helper( 'addon_loader' )->load_addons( $this->coreDir . '/addons' );
152
153 // Load default assets
154 $this->helper( 'assets' );
155 }
156
157 /**
158 * Access a helper. Will instantiate if helper hasn't been loaded before.
159 */
160 public function helper( $helper )
161 {
162 // Lazy instantiate helper
163 if( !isset( $this->helpers[$helper] ) ) {
164 $this->include_helper( $helper );
165
166 // Get class name from filename
167 $class_name = 'WPUPG';
168
169 $dirs = explode( '/', $helper );
170 $file = end( $dirs );
171 $name_parts = explode( '_', $file );
172 foreach( $name_parts as $name_part ) {
173 $class_name .= '_' . ucfirst( $name_part );
174 }
175
176 // Instantiate class if exists
177 if( class_exists( $class_name ) ) {
178 $this->helpers[$helper] = new $class_name();
179 }
180 }
181
182 // Return helper instance
183 return $this->helpers[$helper];
184 }
185
186 /**
187 * Include a helper. Looks through all helper directories that have been added.
188 */
189 public function include_helper( $helper )
190 {
191 foreach( $this->helper_dirs as $dir )
192 {
193 $file = $dir . '/'.$helper.'.php';
194
195 if( file_exists( $file ) ) {
196 require_once( $file );
197 }
198 }
199 }
200
201 /**
202 * Add a directory to look for helpers.
203 */
204 public function add_helper_directory( $dir )
205 {
206 if( is_dir( $dir ) ) {
207 $this->helper_dirs[] = $dir;
208 }
209 }
210
211 /*
212 * Quick access functions
213 */
214
215 public function template( $template )
216 {
217 return $this->addon( 'custom-templates' )->get_template( $template );
218 }
219 }
220
221 // Premium version is responsible for instantiating if available
222 if( !class_exists( 'WPUltimatePostGridPremium' ) ) {
223 WPUltimatePostGrid::get();
224 }