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

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