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

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