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

236 lines 6.7 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.8.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.8.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( 'privacy' );
143 $this->helper( 'support_tab' );
144 $this->helper( 'vafpress_menu' );
145 $this->helper( 'vafpress_shortcode' );
146 $this->helper( 'shortcodes/filter_shortcode' );
147 $this->helper( 'shortcodes/grid_shortcode' );
148
149 // Include required helpers but don't instantiate
150 $this->include_helper( 'addons/addon' );
151 $this->include_helper( 'addons/premium_addon' );
152 $this->include_helper( 'models/grid' );
153 $this->include_helper( 'grid_manager' );
154
155 // Load core addons
156 $this->helper( 'addon_loader' )->load_addons( $this->coreDir . '/addons' );
157
158 // Load default assets
159 $this->helper( 'assets' );
160 }
161
162 /**
163 * Access a helper. Will instantiate if helper hasn't been loaded before.
164 */
165 public function helper( $helper )
166 {
167 // Lazy instantiate helper
168 if( !isset( $this->helpers[$helper] ) ) {
169 $this->include_helper( $helper );
170
171 // Get class name from filename
172 $class_name = 'WPUPG';
173
174 $dirs = explode( '/', $helper );
175 $file = end( $dirs );
176 $name_parts = explode( '_', $file );
177 foreach( $name_parts as $name_part ) {
178 $class_name .= '_' . ucfirst( $name_part );
179 }
180
181 // Instantiate class if exists
182 if( class_exists( $class_name ) ) {
183 $this->helpers[$helper] = new $class_name();
184 }
185 }
186
187 // Return helper instance
188 return $this->helpers[$helper];
189 }
190
191 /**
192 * Include a helper. Looks through all helper directories that have been added.
193 */
194 public function include_helper( $helper )
195 {
196 foreach( $this->helper_dirs as $dir )
197 {
198 $file = $dir . '/'.$helper.'.php';
199
200 if( file_exists( $file ) ) {
201 require_once( $file );
202 }
203 }
204 }
205
206 /**
207 * Add a directory to look for helpers.
208 */
209 public function add_helper_directory( $dir )
210 {
211 if( is_dir( $dir ) ) {
212 $this->helper_dirs[] = $dir;
213 }
214 }
215
216 /*
217 * Quick access functions
218 */
219
220 public function template( $template )
221 {
222 return $this->addon( 'custom-templates' )->get_template( $template );
223 }
224 }
225
226 // Backward compatibility for older versions of WordPress
227 if( !function_exists( 'get_term_meta' ) ) {
228 function get_term_meta ( $term_id = 0, $key = '', $single = false ) {
229 return '';
230 }
231 }
232
233 // Premium version is responsible for instantiating if available
234 if( !class_exists( 'WPUltimatePostGridPremium' ) ) {
235 WPUltimatePostGrid::get();
236 }