PluginProbe
EleSpare – News, Magazine and Blog Addons for Elementor / 2.0.0
EleSpare – News, Magazine and Blog Addons for Elementor v2.0.0
trunk 1.0.0 2.0.0 3.1.1
elespare / elespare.php

elespare.php in EleSpare – News, Magazine and Blog Addons for Elementor 2.0.0, at elespare.php

302 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elespare - News, Magazine and Blog Addons for Elementor (Free Widgets, Templates and Header/Footer Builder)
4 *
5 * @package Elespare
6 *
7 * Plugin Name: Elespare
8 * Description: News, Magazine and Blog Addons for Elementor (Free Widgets, Templates and Header/Footer Builder)
9 * Plugin URI: https://elespare.com/
10 * Version: 2.0.3
11 * Elementor tested up to: 3.15.3
12 * Elementor Pro tested up to: 3.15.3
13 * Author: Elespare
14 * Author URI: https://elespare.com/
15 * Text Domain: elespare
16 */
17
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 // Exit if accessed directly.
21 exit;
22 }
23 define( 'ELESPARE_VERSION', '2.0.3' );
24 define( 'ELESPARE', __FILE__ );
25 define( 'ELESPARE_DIR_PATH', plugin_dir_path( ELESPARE ) );
26 define( 'ELESPARE_DIR_URL', plugin_dir_url( ELESPARE ) );
27 defined( 'ELESPARE_SHOW_PRO_NOTICES' ) || define( 'ELESPARE_SHOW_PRO_NOTICES', true );
28
29 /**
30 * Main Elespare Class
31 *
32 * The init class that runs the Elementor Elespare plugin.
33 * Intended To make sure that the plugin's minimum requirements are met.
34 * You should only modify the constants to match your plugin's needs.
35 *
36 * Any custom code should go inside Plugin Class in the class-widgets.php file.
37 */
38 final class Elespare {
39
40 /**
41 * Plugin Version
42 *
43 * @since 1.0.0
44 * @var string The plugin version.
45 */
46 const VERSION = '2.0.3';
47
48 /**
49 * Minimum Elementor Version
50 *
51 * @since 1.0.0
52 * @var string Minimum Elementor version required to run the plugin.
53 */
54 const MINIMUM_ELEMENTOR_VERSION = '2.8.0';
55
56 /**
57 * Minimum PHP Version
58 *
59 * @since 1.0.0
60 * @var string Minimum PHP version required to run the plugin.
61 */
62 const MINIMUM_PHP_VERSION = '5.4';
63
64 /**
65 * Constructor
66 *
67 * @since 1.0.0
68 * @access public
69 */
70 public function __construct() {
71 // Load the translation.
72 add_action( 'init', array( $this, 'i18n' ) );
73
74 // Initialize the plugin.
75 add_action( 'plugins_loaded', array( $this, 'init' ) );
76
77 // Register widget style
78 add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'ElespareWidgetStyle' ] );
79
80 add_action( 'elementor/elements/categories_registered', [ $this, 'register_widget_category' ] );
81
82 add_action( 'activated_plugin', [ $this, 'elespare_activation_redirect' ] );
83 }
84
85 public function ElespareWidgetStyle()
86 {
87 wp_register_style( 'elespare-posts-grid', plugins_url( 'dist/elespare.style.build.min.css', ELESPARE ), array(), self::VERSION );
88 wp_enqueue_style( 'elespare-posts-grid' );
89 }
90
91 /**
92 * Load Textdomain
93 *
94 * Load plugin localization files.
95 * Fired by `init` action hook.
96 *
97 * @since 1.0.0
98 * @access public
99 */
100 public function i18n() {
101 load_plugin_textdomain( 'elespare' );
102 }
103
104 /**
105 * Initialize the plugin
106 *
107 * Validates that Elementor is already loaded.
108 * Checks for basic plugin requirements, if one check fail don't continue,
109 * if all check have passed include the plugin class.
110 *
111 * Fired by `plugins_loaded` action hook.
112 *
113 * @since 1.0.0
114 * @access public
115 */
116 public function init() {
117
118 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_enqueue' ] );
119
120 include_once ELESPARE_DIR_PATH .'inc/admin/class-admin-dashboard.php';
121
122 // Check if Elementor installed and activated.
123 if ( ! did_action( 'elementor/loaded' ) ) {
124 add_action( 'admin_notices', array( $this, 'admin_notice_missing_main_plugin' ) );
125 return;
126 }
127
128 // Check for required Elementor version.
129 if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
130 add_action( 'admin_notices', array( $this, 'admin_notice_minimum_elementor_version' ) );
131 return;
132 }
133
134 // Check for required PHP version.
135 if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
136 add_action( 'admin_notices', array( $this, 'admin_notice_minimum_php_version' ) );
137 return;
138 }
139
140 // Once we get here, We have passed all validation checks so we can safely include our widgets.
141 require_once 'class-elespare.php';
142 include_once ELESPARE_DIR_PATH.'header-footer/init.php';
143 require(ELESPARE_DIR_PATH.'inc/functions.php');
144 require(ELESPARE_DIR_PATH.'inc/init.php');
145
146
147
148 }
149
150 /**
151 * Admin notice
152 *
153 * Warning when the site doesn't have Elementor installed or activated.
154 *
155 * @since 1.0.0
156 * @access public
157 */
158 public function admin_notice_missing_main_plugin() {
159 $view_demos = __( 'View Demos', 'elespare' );
160 $docs_support = __( 'Documentations', 'elespare' );
161 $contact_support = __( 'Need Help?', 'elespare' );
162 if ( file_exists( WP_PLUGIN_DIR . '/elementor/elementor.php' ) ) {
163 $notice_title = __( 'Activate Elementor', 'elespare' );
164 $notice_url = wp_nonce_url( 'plugins.php?action=activate&plugin=elementor/elementor.php&plugin_status=all&paged=1', 'activate-plugin_elementor/elementor.php' );
165 }else{
166 $notice_title = __( 'Install Elementor', 'elespare' );
167 $notice_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=elementor' ), 'install-plugin_elementor' );
168 }
169
170 $messages = sprintf(
171 /* translators: 1: Plugin name 2: Elementor */
172 esc_html__( '%3$s %1$s requires %2$s to be installed and activated to get the outstanding News,Magazine and Blog elements (widgets) and Header/Footer builder.%4$s %3$s %5$s %6$s %7$s %8$s %4$s', 'elespare' ),
173 '<strong>' . esc_html__( 'Elespare', 'elespare' ) . '</strong>',
174 '<strong>' . esc_html__( 'Elementor', 'elespare' ) . '</strong>',
175 '<p>',
176 '</p>',
177 '<a class="button-primary" href="' . esc_url( $notice_url ) . '">' . $notice_title . '</a>',
178 '<a class="button-secondary" target="_blank" href="' . esc_url( 'http://afthemes.com/plugins/elespare/' ) . '">' . $view_demos . '</a>',
179 '<a class="button-secondary" target="_blank" href="' . esc_url( 'https://afthemes.com/plugins/elespare/elespare-docs/' ) . '">' . $docs_support . '</a>',
180 '<a class="button-secondary" target="_blank" href="' . esc_url( 'http://afthemes.com/supports/' ) . '">' . $contact_support . '</a>'
181
182 );
183
184
185 printf( '<div class="notice notice-warning is-dismissible">%1$s</div>', $messages );
186 }
187
188 /**
189 * Admin notice
190 *
191 * Warning when the site doesn't have a minimum required Elementor version.
192 *
193 * @since 1.0.0
194 * @access public
195 */
196 public function admin_notice_minimum_elementor_version() {
197 // deactivate_plugins( plugin_basename( ELESPARE ) );
198
199 $ele_version = sprintf(
200 '<div class="notice notice-warning is-dismissible"><p><strong>"%1$s"</strong> requires <strong>"%2$s"</strong> version %3$s or greater.</p></div>',
201 'Elespare',
202 'Elementor',
203 self::MINIMUM_ELEMENTOR_VERSION
204 );
205
206 echo wp_kses($ele_version, array(
207 'div' => array(
208 'class' => array(),
209 'p' => array(),
210 'strong' => array(),
211 ),
212 ));
213 }
214
215 /**
216 * Admin notice
217 *
218 * Warning when the site doesn't have a minimum required PHP version.
219 *
220 * @since 1.0.0
221 * @access public
222 */
223 public function admin_notice_minimum_php_version() {
224 // deactivate_plugins( plugin_basename( ELESPARE ) );
225
226 $ele_php_version = sprintf(
227
228 '<div class="notice notice-warning is-dismissible"><p><strong>"%1$s"</strong> requires <strong>"%2$s"</strong> version %3$s or greater.</p></div>',
229 'Elespare',
230 'PHP',
231 self::MINIMUM_PHP_VERSION
232 );
233
234 echo wp_kses($ele_php_version, array(
235 'div' => array(
236 'class' => array(),
237 'p' => array(),
238 'strong' => array(),
239 ),
240 ));
241 }
242
243
244 public function register_widget_category( $elements_manager ) {
245
246 $elements_manager->add_category(
247 'elespare',
248 [
249 'title' => esc_html__( 'Elespare', 'elespare' ),
250 'icon' => 'fa fa-plug',
251 ]
252 );
253
254 }
255
256 function editor_enqueue(){
257 wp_enqueue_style(
258 'elespare-icons',
259 ELESPARE_DIR_URL . 'assets/font/elespare-icons.css',
260 null,
261 ELESPARE_VERSION
262 );
263
264
265
266 global $wp_query;
267 $id = $wp_query->post->ID;
268 wp_enqueue_script( 'elespare-elementor-modal', ELESPARE_DIR_URL . 'assets/js/elementor-modal.js', [ 'jquery' ], ELESPARE_VERSION );
269
270 wp_enqueue_script(
271 'elespare-library-react',
272 ELESPARE_DIR_URL . 'dist/main_js.build.min.js',
273 [
274 'wp-editor',
275 'elespare-elementor-modal'],
276 ELESPARE_VERSION,
277 true
278 );
279
280 wp_localize_script( 'elespare-library-react', 'AFTLibrary', array(
281 'ajaxurl' => admin_url( 'admin-ajax.php' ),
282 'baseUrl' => ELESPARE_DIR_URL,
283 'externalUrl'=>'https://templatespare.com/wp-content/uploads/elespare/free/',
284 'apiUrl' => site_url().'/index.php?rest_route=/',
285 'currentPage'=>$id,
286 'key' => '',
287 'host' => $_SERVER['HTTP_HOST'],
288
289
290
291 ) );
292 }
293
294 function elespare_activation_redirect($plugin){
295 if( $plugin == plugin_basename( ELESPARE ) ) {
296 exit( wp_redirect( add_query_arg(['page' => 'elespare_dashboard'], admin_url('admin.php') )));
297 }
298 }
299 }
300
301 // Instantiate Elespare.
302 new Elespare();