| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Post Grid Addon for Elementor |
| 4 |
* Description: Addon for the Elementor page builder to display posts in a grid. Useful for generating post grid from your blog posts with multiple options. |
| 5 |
* Plugin URI: https://wphait.com/plugins/post-grid-elementor-addon/ |
| 6 |
* Version: 2.0.24 |
| 7 |
* Author: WP Hait |
| 8 |
* Author URI: https://wphait.com/ |
| 9 |
* Text Domain: post-grid-elementor-addon |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 13 |
|
| 14 |
define( 'PGEA_VERSION', '2.0.24' ); |
| 15 |
define( 'PGEA_SLUG', 'post-grid-elementor-addon' ); |
| 16 |
define( 'PGEA_URL', rtrim( plugin_dir_url( __FILE__ ), '/' ) ); |
| 17 |
define( 'PGEA_URI', rtrim( plugin_dir_path( __FILE__ ), '/' ) ); |
| 18 |
define( 'PGEA_UPGRADE_URL', 'https://checkout.freemius.com/mode/dialog/plugin/6007/plan/9846/' ); |
| 19 |
|
| 20 |
|
| 21 |
if ( ! defined( 'WP_WELCOME_DIR' ) ) { |
| 22 |
define( 'WP_WELCOME_DIR', PGEA_URI . '/vendor/ernilambar/wp-welcome' ); |
| 23 |
} |
| 24 |
|
| 25 |
if ( ! defined( 'WP_WELCOME_URL' ) ) { |
| 26 |
define( 'WP_WELCOME_URL', PGEA_URL . '/vendor/ernilambar/wp-welcome' ); |
| 27 |
} |
| 28 |
|
| 29 |
// Include autoload. |
| 30 |
if ( file_exists( PGEA_URI . '/vendor/autoload.php' ) ) { |
| 31 |
require_once PGEA_URI . '/vendor/autoload.php'; |
| 32 |
require_once PGEA_URI . '/vendor/ernilambar/wp-welcome/init.php'; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Main Post Grid Elementor Addon Class |
| 37 |
* |
| 38 |
* The init class that runs the Post Grid plugin. |
| 39 |
* Intended To make sure that the plugin's minimum requirements are met. |
| 40 |
* |
| 41 |
* You should only modify the constants to match your plugin's needs. |
| 42 |
* |
| 43 |
* Any custom code should go inside Plugin Class in the plugin.php file. |
| 44 |
* @since 1.2.0 |
| 45 |
*/ |
| 46 |
final class Elementor_Post_Grid { |
| 47 |
|
| 48 |
/** |
| 49 |
* Plugin Version |
| 50 |
* |
| 51 |
* @since 1.2.0 |
| 52 |
* @var string The plugin version. |
| 53 |
*/ |
| 54 |
const VERSION = PGEA_VERSION; |
| 55 |
|
| 56 |
/** |
| 57 |
* Minimum Elementor Version |
| 58 |
* |
| 59 |
* @since 1.2.0 |
| 60 |
* @var string Minimum Elementor version required to run the plugin. |
| 61 |
*/ |
| 62 |
const MINIMUM_ELEMENTOR_VERSION = '3.0.0'; |
| 63 |
|
| 64 |
/** |
| 65 |
* Minimum PHP Version |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
* @var string Minimum PHP version required to run the plugin. |
| 69 |
*/ |
| 70 |
const MINIMUM_PHP_VERSION = '5.6.20'; |
| 71 |
|
| 72 |
/** |
| 73 |
* Constructor |
| 74 |
* |
| 75 |
* @since 1.0.0 |
| 76 |
* @access public |
| 77 |
*/ |
| 78 |
public function __construct() { |
| 79 |
|
| 80 |
// Load translation |
| 81 |
add_action( 'init', array( $this, 'i18n' ) ); |
| 82 |
|
| 83 |
// Init Plugin |
| 84 |
add_action( 'plugins_loaded', array( $this, 'init' ) ); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Load Textdomain |
| 89 |
* |
| 90 |
* Load plugin localization files. |
| 91 |
* Fired by `init` action hook. |
| 92 |
* |
| 93 |
* @since 1.2.0 |
| 94 |
* @access public |
| 95 |
*/ |
| 96 |
public function i18n() { |
| 97 |
load_plugin_textdomain( 'post-grid-elementor-addon' ); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Initialize the plugin |
| 102 |
* |
| 103 |
* Validates that Elementor is already loaded. |
| 104 |
* Checks for basic plugin requirements, if one check fail don't continue, |
| 105 |
* if all check have passed include the plugin class. |
| 106 |
* |
| 107 |
* Fired by `plugins_loaded` action hook. |
| 108 |
* |
| 109 |
* @since 1.2.0 |
| 110 |
* @access public |
| 111 |
*/ |
| 112 |
public function init() { |
| 113 |
|
| 114 |
// Check if Elementor installed and activated |
| 115 |
if ( ! did_action( 'elementor/loaded' ) ) { |
| 116 |
add_action( 'admin_notices', array( $this, 'admin_notice_missing_main_plugin' ) ); |
| 117 |
return; |
| 118 |
} |
| 119 |
|
| 120 |
// Check for required Elementor version |
| 121 |
if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) { |
| 122 |
add_action( 'admin_notices', array( $this, 'admin_notice_minimum_elementor_version' ) ); |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
// Check for required PHP version |
| 127 |
if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) { |
| 128 |
add_action( 'admin_notices', array( $this, 'admin_notice_minimum_php_version' ) ); |
| 129 |
return; |
| 130 |
} |
| 131 |
|
| 132 |
add_action( 'admin_init', array( $this, 'setup_custom_notice' ) ); |
| 133 |
|
| 134 |
// Once we get here, We have passed all validation checks so we can safely include our plugin |
| 135 |
require_once( 'plugin.php' ); |
| 136 |
require_once( 'inc/admin.php' ); |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Admin notice |
| 141 |
* |
| 142 |
* Warning when the site doesn't have Elementor installed or activated. |
| 143 |
* |
| 144 |
* @since 1.0.0 |
| 145 |
* @access public |
| 146 |
*/ |
| 147 |
public function admin_notice_missing_main_plugin() { |
| 148 |
if ( isset( $_GET['activate'] ) ) { |
| 149 |
unset( $_GET['activate'] ); |
| 150 |
} |
| 151 |
|
| 152 |
$message = sprintf( |
| 153 |
/* translators: 1: Plugin name 2: Elementor */ |
| 154 |
esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'post-grid-elementor-addon' ), |
| 155 |
'<strong>' . esc_html__( 'Post Grid Addon for Elementor', 'post-grid-elementor-addon' ) . '</strong>', |
| 156 |
'<strong>' . esc_html__( 'Elementor', 'post-grid-elementor-addon' ) . '</strong>' |
| 157 |
); |
| 158 |
|
| 159 |
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message ); |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Admin notice |
| 164 |
* |
| 165 |
* Warning when the site doesn't have a minimum required Elementor version. |
| 166 |
* |
| 167 |
* @since 1.0.0 |
| 168 |
* @access public |
| 169 |
*/ |
| 170 |
public function admin_notice_minimum_elementor_version() { |
| 171 |
if ( isset( $_GET['activate'] ) ) { |
| 172 |
unset( $_GET['activate'] ); |
| 173 |
} |
| 174 |
|
| 175 |
$message = sprintf( |
| 176 |
/* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */ |
| 177 |
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'post-grid-elementor-addon' ), |
| 178 |
'<strong>' . esc_html__( 'Post Grid Addon for Elementor', 'post-grid-elementor-addon' ) . '</strong>', |
| 179 |
'<strong>' . esc_html__( 'Elementor', 'post-grid-elementor-addon' ) . '</strong>', |
| 180 |
self::MINIMUM_ELEMENTOR_VERSION |
| 181 |
); |
| 182 |
|
| 183 |
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message ); |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Admin notice |
| 188 |
* |
| 189 |
* Warning when the site doesn't have a minimum required PHP version. |
| 190 |
* |
| 191 |
* @since 1.0.0 |
| 192 |
* @access public |
| 193 |
*/ |
| 194 |
public function admin_notice_minimum_php_version() { |
| 195 |
if ( isset( $_GET['activate'] ) ) { |
| 196 |
unset( $_GET['activate'] ); |
| 197 |
} |
| 198 |
|
| 199 |
$message = sprintf( |
| 200 |
/* translators: 1: Plugin name 2: PHP 3: Required PHP version */ |
| 201 |
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'post-grid-elementor-addon' ), |
| 202 |
'<strong>' . esc_html__( 'Post Grid Addon for Elementor', 'post-grid-elementor-addon' ) . '</strong>', |
| 203 |
'<strong>' . esc_html__( 'PHP', 'post-grid-elementor-addon' ) . '</strong>', |
| 204 |
self::MINIMUM_PHP_VERSION |
| 205 |
); |
| 206 |
|
| 207 |
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message ); |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* Add admin notice. |
| 212 |
* |
| 213 |
* @since 2.0.8 |
| 214 |
*/ |
| 215 |
public function setup_custom_notice() { |
| 216 |
// Setup notice. |
| 217 |
\Nilambar\AdminNotice\Notice::init( |
| 218 |
array( |
| 219 |
'slug' => PGEA_SLUG, |
| 220 |
'name' => esc_html__( 'Post Grid Addon for Elementor', 'post-grid-elementor-addon' ), |
| 221 |
) |
| 222 |
); |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
// Instantiate Elementor_Post_Grid. |
| 227 |
new Elementor_Post_Grid(); |