-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.php
218 lines (178 loc) · 5.66 KB
/
plugin.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
<?php
namespace WhiteZimmer;
use Elementor\Controls_Manager;
use ElementorPro\Modules\Forms\Module;
use WhiteZimmer\Integrations\Zimmer_Review;
use WhiteZimmer\Tags\Tag_Coupon;
/**
* Class Plugin
*
* Main Plugin class
* @since 1.0
*/
class Plugin {
/**
* Instance
*
* @since 1.0
* @access private
* @static
*
* @var Plugin 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
* @access public
*
* @return Plugin An instance of the class.
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* widget_scripts
*
* Load required plugin core files.
*
* @since 1.0
* @access public
*/
public function widget_assets() {
wp_register_script( 'jquery-mosaic', plugins_url( '/assets/js/lib/jquery-mosaic/jquery.mosaic.js', __FILE__ ), [ 'jquery' ], '0.15.3', true );
wp_register_style( 'jquery-mosaic', plugins_url( '/assets/js/lib/jquery-mosaic/jquery.mosaic.css', __FILE__ ), [], '0.15.3' );
if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
wp_enqueue_style( 'jquery-mosaic' );
}
wp_register_script( 'posts-gallery', plugins_url( '/assets/js/frontend/posts-gallery.js', __FILE__ ), [ 'jquery-mosaic' ], \Elementor_White_Zimmer::VERSION, true );
}
/**
* Include Widgets files
*
* Load widgets files
*
* @since 1.0
* @access private
*/
private function include_widgets_files() {
require_once __DIR__ . '/widgets/hello-world.php';
require_once __DIR__ . '/widgets/posts-gallery.php';
}
/**
* Register Widgets
*
* Register new Elementor widgets.
*
* @since 1.0
* @access public
*
* @param \Elementor\Widgets_Manager $widgets_manager
*
* @throws \Exception
*/
public function register_widgets( $widgets_manager ) {
// Its is now safe to include Widgets files
$this->include_widgets_files();
// Register Widgets
$widgets_manager->register_widget_type( new Widgets\Alt_Heading() );
$widgets_manager->register_widget_type( new Widgets\Posts_Gallery() );
}
public function register_taxonomies() {
require_once( __DIR__ . '/taxonomies.php' );
foreach ( $taxonomies as $taxonomy_name => $taxonomy_args ) {
register_taxonomy( $taxonomy_name, array( 'zimmer' ), $taxonomy_args );
}
}
public function register_post_types() {
require_once( __DIR__ . '/post_types.php' );
foreach ( $post_types as $post_type_name => $post_type_args ) {
register_post_type( $post_type_name, $post_type_args );
}
}
public function change_rating_widget( $control_stack ) {
// Update the control
$control_stack->update_control( 'rating', [
'type' => Controls_Manager::TEXT,
'dynamic' => [
'active' => true,
],
]
, [
'recursive' => true, // To update an array by merging
]
);
}
public function register_tags( $tag_manager ) {
require __DIR__ . '/tags/tag-coupon.php';
$tag_manager->register_tag( new Tag_Coupon() );
}
public function register_form_integrations() {
require __DIR__ . '/integrations/zimmer-review.php';
/** @var Module $forms */
$forms = \ElementorPro\Plugin::instance()->modules_manager->get_modules( 'forms' );
$forms->add_form_action( 'zimmer_review', new Zimmer_Review() );
}
/**
* Plugin class constructor
*
* Register plugin action hooks and filters
*
* @since 1.0
* @access public
*/
public function __construct() {
add_action( 'elementor_pro/init', [ $this, 'register_form_integrations' ] );
// Register widget scripts
add_action( 'elementor/frontend/after_register_scripts', [ $this, 'widget_assets' ] );
// Register widgets
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_widgets' ] );
add_action( 'init', [ $this, 'register_post_types' ], 0 );
add_action( 'init', [ $this, 'register_taxonomies' ], 0 );
add_action( 'elementor/dynamic_tags/register_tags', [ $this, 'register_tags' ] );
add_action( 'elementor/element/star-rating/section_rating/before_section_end', [ $this, 'change_rating_widget' ], 10, 2 );
//add_filter( 'elementor/widget/render_content',
/**
* @param string $widget_content
* @param \Elementor\Widget_Base $widget
*//*
function ( $widget_content, $widget ) {
if ( 'heading' !== $widget->get_name() ) {
return $widget_content;
}
$settings = $widget->get_settings_for_display();
$widget->add_render_attribute( 'heading', 'class', 'cool-heading' );
$widget_content = '<' . $settings['html_tag'] . $widget->get_render_attribute_string( 'heading' ) . '>';
$widget_content .= $settings['title'];
$widget_content .= '</' . $settings['html_tag'] . '>';
return $widget_content;
}, 10, 2 );
*/
add_filter( 'elementor/frontend/widget/should_render', function( $should_render, $widget ) {
// check if current widget is our desired widget, in this example we use login widget
if ( 'login' !== $widget->get_name() ) {
return $should_render;
}
// If we got here then its our widget so check if te user is logged in and if he is
// then we want to stop the render so we return false
return ! is_user_logged_in();
}, 10, 2 );
// render for logged in users only
add_filter( 'elementor/frontend/widget/should_render', function( $should_render, $widget ) {
// check if current widget is our desired widget, in this example we use form widget
if ( 'form' !== $widget->get_name() ) {
return $should_render;
}
// If we got here then its our widget so check if te user is logged in
return is_user_logged_in();
}, 10, 2 );
}
}
// Instantiate Plugin Class
Plugin::instance();