-
Notifications
You must be signed in to change notification settings - Fork 0
/
indiano-travel.php
442 lines (347 loc) · 10.7 KB
/
indiano-travel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?php
/**
* Plugin Name: Indiano Travel
* Description: We building Elementor Extention for our official project. This extention based on indiano travel blog.
* Plugin URI: https://inovate.digital/
* Version: 1.0.0
* Author: Inovate Degital
* Author URI: https://www.inovate.digital/
* Text Domain: inovate-elementor
* Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
*
* The main class that initiates and runs the plugin.
*
* @since 1.0.0
*/
final class Inovate_Elementor_Extension {
/**
* Plugin Version
*
* @since 1.0.0
*
* @var string The plugin version.
*/
const VERSION = '1.0.0';
/**
* Minimum Elementor Version
*
* @since 1.0.0
*
* @var string Minimum Elementor version required to run the plugin.
*/
const MINIMUM_ELEMENTOR_VERSION = '2.0.0';
/**
* Minimum PHP Version
*
* @since 1.0.0
*
* @var string Minimum PHP version required to run the plugin.
*/
const MINIMUM_PHP_VERSION = '7.0';
/**
* Instance
*
* @since 1.0.0
*
* @access private
* @static
*
* @var Inovate_Elementor_Extension The single instance of the class.
*/
private static $_instance = null;
/**
* Instance
*
* Ensures only one instance of the class is loaded or can be loaded.
*
* @since 1.0.0
*
* @access public
* @static
*
* @return Inovate_Elementor_Extension An instance of the class.
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Constructor
*
* @since 1.0.0
*
* @access public
*/
public function __construct() {
add_action( 'init', [ $this, 'i18n' ] );
add_action( 'plugins_loaded', [ $this, 'init' ] );
}
/**
* Load Textdomain
*
* Load plugin localization files.
*
* Fired by `init` action hook.
*
* @since 1.0.0
*
* @access public
*/
public function i18n() {
load_plugin_textdomain( 'inovate-elementor', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
/**
* Initialize the plugin
*
* Load the plugin only after Elementor (and other plugins) are loaded.
* Checks for basic plugin requirements, if one check fail don't continue,
* if all check have passed load the files required to run the plugin.
*
* Fired by `plugins_loaded` action hook.
*
* @since 1.0.0
*
* @access public
*/
public function init() {
// Check if Elementor installed and activated
if ( ! did_action( 'elementor/loaded' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_missing_main_plugin' ] );
return;
}
// Check for required Elementor version
if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] );
return;
}
// Check for required PHP version
if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
return;
}
// Register Widget Styles
add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'widget_styles' ] );
add_action('elementor/frontend/after_enqueue_scripts', [ $this, 'widget_scripts' ] );
// Add Plugin actions
add_action( 'elementor/widgets/widgets_registered', [ $this, 'init_widgets' ] );
add_action( 'elementor/controls/controls_registered', [ $this, 'init_controls' ] );
// Category Init
add_action( 'elementor/init', [ $this, 'elementor_common_category' ] );
}
/**
* Admin notice
*
* Warning when the site doesn't have Elementor installed or activated.
*
* @since 1.0.0
*
* @access public
*/
public function admin_notice_missing_main_plugin() {
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
$message = sprintf(
/* translators: 1: Plugin name 2: Elementor */
esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'inovate-elementor' ),
'<strong>' . esc_html__( 'Inovate Elementor', 'inovate-elementor' ) . '</strong>',
'<strong>' . esc_html__( 'Elementor', 'inovate-elementor' ) . '</strong>'
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
}
/**
* Admin notice
*
* Warning when the site doesn't have a minimum required Elementor version.
*
* @since 1.0.0
*
* @access public
*/
public function admin_notice_minimum_elementor_version() {
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
$message = sprintf(
/* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'inovate-elementor' ),
'<strong>' . esc_html__( 'Inovate Elementor', 'inovate-elementor' ) . '</strong>',
'<strong>' . esc_html__( 'Elementor', 'inovate-elementor' ) . '</strong>',
self::MINIMUM_ELEMENTOR_VERSION
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
}
/**
* Admin notice
*
* Warning when the site doesn't have a minimum required PHP version.
*
* @since 1.0.0
*
* @access public
*/
public function admin_notice_minimum_php_version() {
if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
$message = sprintf(
/* translators: 1: Plugin name 2: PHP 3: Required PHP version */
esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'inovate-elementor' ),
'<strong>' . esc_html__( 'Inovate Elementor', 'inovate-elementor' ) . '</strong>',
'<strong>' . esc_html__( 'PHP', 'inovate-elementor' ) . '</strong>',
self::MINIMUM_PHP_VERSION
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
}
/**
* Init Widgets
*
* Include widgets files and register them
*
* @since 1.0.0
*
* @access public
*/
public function init_widgets() {
require_once( __DIR__ . '/widgets/it-city-hero.php' );
require_once( __DIR__ . '/widgets/it-place-hero.php' );
require_once( __DIR__ . '/widgets/it-accordion.php' );
require_once( __DIR__ . '/widgets/indiano-author.php' );
require_once( __DIR__ . '/widgets/it-posts.php' );
require_once( __DIR__ . '/widgets/it-posts2.php' );
require_once( __DIR__ . '/widgets/it-city.php' );
require_once( __DIR__ . '/widgets/it-place.php' );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new City_Hero_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Place_Hero_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new IT_Accordion_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Indiano_Author() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new IT_Posts_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new IT_Posts_Widget_Two() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new IT_City_Widget() );
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new IT_Place_Widget() );
}
/**
* Init Controls
*
* Include controls files and register them
*
* @since 1.0.0
*
* @access public
*/
public function init_controls() {
/*
* Todo: this block needs to be commented out when the custom control is ready
*
*
// Include Control files
require_once( __DIR__ . '/controls/test-control.php' );
// Register control
\Elementor\Plugin::$instance->controls_manager->register_control( 'control-type-', new \Test_Control() );
*/
}
// Custom CSS
public function widget_styles() {
wp_register_style( 'inovate-main', plugins_url( 'assets/css/inovate-main.css', __FILE__ ), array(), time( ) );
wp_enqueue_style( 'inovate-main' );
}
// Custom JS
public function widget_scripts() {
wp_register_script( 'inovate-main', plugins_url( 'assets/js/inovate-main.js', __FILE__ ), array( ), time( ) );
wp_enqueue_script( 'inovate-main' );
}
// Custom Category
public function elementor_common_category () {
\Elementor\Plugin::$instance->elements_manager->add_category(
'inovate-category',
[
'title' => __( 'Indiano Travel', 'inovate-elementor' ),
'icon' => 'fa fa-plug', //default icon
]
);
}
}
Inovate_Elementor_Extension::instance();
// Change wordpress default logo
function wpb_login_logo() { ?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url(https://indiano.travel/wp-content/uploads/2022/01/indiano-travel.png);
background-repeat: no-repeat;
padding-bottom: 10px;
}
</style>
<?php }
add_action( 'login_enqueue_scripts', 'wpb_login_logo' );
/*
Load More using Ajax For city
*/
add_action( 'wp_footer', 'my_action_javascript' );
function my_action_javascript() { ?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
var page = 4;
var page_count = '<?php echo ceil(wp_count_posts('city')->publish/4); ?>';
jQuery('#load_more').on('click',function(){
var data = {
'action': 'my_action',
'page': page
};
jQuery.post(ajaxurl, data, function(response) {
jQuery('.it-post-card').append(response);
if(page_count == page){
jQuery('#load_more').hide();
}
page = page + 1;
});
});
});
</script> <?php
}
add_action( 'wp_ajax_my_action', 'my_action' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action' );
function my_action() {
global $wpdb; // this is how you get access to the database
$args = array(
'post_type' => 'city',
//'posts_per_page' => $it_city_count,
'post_status' => 'publish',
'post__not_in' => array(get_the_ID()),
'tag' => $it_city_tag,
'tax_query' => $tax_query,
'paged' => $_POST['page']
);
$city_query = new WP_Query( $args );
if( $city_query->have_posts() ) :
while( $city_query->have_posts() ) : $city_query->the_post(); ?>
<div class="it-card-item">
<div class="it-card-img">
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail();}
else { echo '<img src="https://source.unsplash.com/300x200" />';}
?>
</a>
</div>
<div class="it-card-content">
<a href="<?php the_permalink(); ?>">
<h3><?php the_title(); ?></h3>
</a>
<span class="it-city state-tag">
<?php
$state_names = get_the_terms($post->ID, 'state_name');
if ($state_names) {
foreach ($state_names as $state_name) {
echo $state_name->name;
}
}
?>
</span>
</div>
</div> <!-- single item -->
<?php endwhile;
else : _e( 'Sorry, no city matched your criteria.', 'inovate-elementor' );
endif;
wp_die();
}