PluginProbe
Filterable Portfolio / trunk
Filterable Portfolio vtrunk
trunk 1.5.1 1.6.0 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
filterable-portfolio / filterable-portfolio.php

filterable-portfolio.php in Filterable Portfolio trunk, at filterable-portfolio.php

286 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Filterable Portfolio
4 * Plugin URI: https://github.com/sayful1/filterable-portfolio
5 * Description: A WordPress plugin to display portfolio images with filtering.
6 * Version: 1.6.6
7 * Author: Majeed Raza
8 * Author URI: https://github.com/sayful1/
9 * License: GPLv3
10 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt
11 * Text Domain: filterable-portfolio
12 * Domain Path: /languages
13 * Requires at least: 6.0
14 * Tested up to: 7.0
15 * Requires PHP: 7.0
16 */
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 die; // If this file is called directly, abort.
20 }
21
22 if ( ! class_exists( 'Filterable_Portfolio' ) ) {
23 /**
24 * Main Filterable_Portfolio Class.
25 *
26 * @class Filterable_Portfolio
27 */
28 final class Filterable_Portfolio {
29
30 /**
31 * Plugin unique slug
32 *
33 * @var string
34 */
35 private $plugin_name = 'filterable-portfolio';
36
37 /**
38 * Holds various class instances
39 *
40 * @var array
41 */
42 private $container = [];
43
44 /**
45 * Current version number
46 *
47 * @var string
48 */
49 private $version = '1.6.6';
50
51 /**
52 * Instance of this class
53 *
54 * @var self
55 */
56 protected static $instance;
57
58 /**
59 * Ensures only one instance of this class is loaded or can be loaded.
60 *
61 * @return Filterable_Portfolio
62 * @since 1.2.3
63 */
64 public static function instance() {
65 if ( is_null( self::$instance ) ) {
66 self::$instance = new self();
67
68 // Define plugin constants
69 self::$instance->define_constants();
70
71 // Includes plugin files
72 self::$instance->include_files();
73
74 // initialize plugin classes
75 self::$instance->init_classes();
76
77 add_action( 'init', [ self::$instance, 'load_textdomain' ] );
78 add_action( 'init', [ self::$instance, 'add_image_size' ] );
79 add_filter( 'admin_footer_text', [ self::$instance, 'admin_footer_text' ] );
80 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ self::$instance, 'action_links' ] );
81
82 register_activation_hook( __FILE__, [ self::$instance, 'activation' ] );
83 register_deactivation_hook( __FILE__, [ self::$instance, 'deactivation' ] );
84
85 do_action( 'filterable_portfolio_init' );
86 }
87
88 return self::$instance;
89 }
90
91 /**
92 * Magic getter to bypass referencing plugin.
93 *
94 * @param string $property
95 *
96 * @return mixed
97 */
98 public function __get( $property ) {
99 if ( array_key_exists( $property, $this->container ) ) {
100 return $this->container[ $property ];
101 }
102
103 return $this->{$property};
104 }
105
106 /**
107 * Define plugin constants
108 */
109 public function define_constants() {
110 define( 'FILTERABLE_PORTFOLIO_VERSION', $this->version );
111 define( 'FILTERABLE_PORTFOLIO_FILE', __FILE__ );
112 define( 'FILTERABLE_PORTFOLIO_PATH', dirname( FILTERABLE_PORTFOLIO_FILE ) );
113 define( 'FILTERABLE_PORTFOLIO_INCLUDES', FILTERABLE_PORTFOLIO_PATH . '/includes' );
114 define( 'FILTERABLE_PORTFOLIO_TEMPLATES', FILTERABLE_PORTFOLIO_PATH . '/templates' );
115 define( 'FILTERABLE_PORTFOLIO_URL', plugins_url( '', FILTERABLE_PORTFOLIO_FILE ) );
116 define( 'FILTERABLE_PORTFOLIO_ASSETS', FILTERABLE_PORTFOLIO_URL . '/assets' );
117 }
118
119 /**
120 * Define constant if not already set.
121 *
122 * @param string $name
123 * @param string|bool $value
124 */
125 private function define( $name, $value ) {
126 if ( ! defined( $name ) ) {
127 define( $name, $value );
128 }
129 }
130
131 /**
132 * Load the plugin text domain for translation.
133 *
134 * @return void
135 */
136 public function load_textdomain() {
137 load_plugin_textdomain( $this->plugin_name, false, basename( FILTERABLE_PORTFOLIO_PATH ) . '/languages' );
138 }
139
140 /**
141 * To be run when the plugin is activated
142 * @return void
143 */
144 public function activation() {
145 do_action( 'filterable_portfolio_activation' );
146 flush_rewrite_rules();
147 }
148
149 /**
150 * To be run when the plugin is deactivated
151 * @return void
152 */
153 public function deactivation() {
154 do_action( 'filterable_portfolio_deactivation' );
155 flush_rewrite_rules();
156 }
157
158 /**
159 * Add custom image size for portfolio
160 */
161 public function add_image_size() {
162 add_image_size( 'filterable-portfolio', 370, 370, true );
163 }
164
165 /**
166 * Includes files
167 */
168 private function include_files() {
169 spl_autoload_register( function ( $class ) {
170
171 // If class already exists, not need to include it
172 if ( class_exists( $class ) || false === strpos( $class, 'Filterable_Portfolio_' ) ) {
173 return;
174 }
175
176 // Include our classes
177 $file_name = 'class-' . strtolower( str_replace( '_', '-', $class ) ) . '.php';
178
179 $class_path = FILTERABLE_PORTFOLIO_INCLUDES . '/' . $file_name;
180 if ( file_exists( $class_path ) ) {
181 require_once $class_path;
182 }
183 } );
184 }
185
186 /**
187 * Include admin and front facing files
188 * @return void
189 */
190 private function init_classes() {
191 $this->container['admin'] = Filterable_Portfolio_Admin::init();
192 $this->container['scripts'] = Filterable_Portfolio_Scripts::init();
193 $this->container['block'] = Filterable_Portfolio_Gutenberg_Block::init();
194
195 if ( $this->is_request( 'admin' ) ) {
196 $this->container['setting'] = Filterable_Portfolio_Setting::init();
197 $this->container['metabox'] = Filterable_Portfolio_Metabox::init();
198 }
199
200 if ( $this->is_request( 'frontend' ) ) {
201 $this->container['portfolio'] = Filterable_Portfolio_Single_Post::init();
202 $this->container['shortcode'] = Filterable_Portfolio_Shortcode::init();
203 $this->container['shapla'] = Filterable_Portfolio_Shapla_Theme::init();
204 $this->container['rest'] = Filterable_Portfolio_REST_Controller::init();
205 }
206
207 add_action( 'widgets_init', array( 'Filterable_Portfolio_Widget', 'register' ) );
208
209 // WP-CLI Commands
210 if ( class_exists( WP_CLI::class ) && class_exists( WP_CLI_Command::class ) ) {
211 WP_CLI::add_command( 'filterable-portfolio', Filterable_Portfolio_CLI_Command::class );
212 }
213 }
214
215 /**
216 * Add custom footer text on plugins page.
217 *
218 * @param string $text
219 *
220 * @return string
221 */
222 public function admin_footer_text( $text ) {
223 global $post_type, $hook_suffix;
224
225 /* translators: 1: strong html tag start, 2: strong html tag end */
226 $footer_text = sprintf( __( 'If you like %1$s Filterable Portfolio %2$s please leave us a %3$s rating. A huge thanks in advance!',
227 'filterable-portfolio' ), '<strong>', '</strong>',
228 '<a href="https://wordpress.org/support/view/plugin-reviews/filterable-portfolio?filter=5#postform" target="_blank" data-rated="Thanks :)">&starf;&starf;&starf;&starf;&starf;</a>' );
229
230 if ( $post_type == 'portfolio' || $hook_suffix == 'portfolio_page_fp-settings' ) {
231 return $footer_text;
232 }
233
234 return $text;
235 }
236
237 /**
238 * Add custom links on plugins page.
239 *
240 * @param mixed $links
241 *
242 * @return array
243 */
244 public function action_links( $links ) {
245 $plugin_links = array(
246 '<a href="' . admin_url( 'edit.php?post_type=portfolio&page=fp-settings' ) . '">' . __( 'Settings',
247 'filterable-portfolio' ) . '</a>'
248 );
249
250 return array_merge( $plugin_links, $links );
251 }
252
253
254 /**
255 * What type of request is this?
256 *
257 * @param string $type admin, ajax, cron or frontend.
258 *
259 * @return bool
260 */
261 private function is_request( $type ) {
262 switch ( $type ) {
263 case 'admin':
264 return is_admin();
265 case 'ajax':
266 return defined( 'DOING_AJAX' );
267 case 'cron':
268 return defined( 'DOING_CRON' );
269 case 'frontend':
270 return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
271 }
272
273 return false;
274 }
275 }
276 }
277
278 /**
279 * Begins execution of the plugin.
280 *
281 * Since everything within the plugin is registered via hooks,
282 * then kicking off the plugin from this point in the file does
283 * not affect the page life cycle.
284 */
285 Filterable_Portfolio::instance();
286