-
Notifications
You must be signed in to change notification settings - Fork 0
/
micemade-themes-tools.php
311 lines (257 loc) · 9.07 KB
/
micemade-themes-tools.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
<?php
/**
* Plugin Name: Micemade themes tools
* Plugin URI: http://micemade.com
* Description: Used for Micemade themes. Extension plugin for theme setup wizard and few bonus functionalities.
* Version: 0.1.9
* Author: Micemade themes
* Author URI: http://micemade.com
* Text Domain: micemade-themes-tools
* Copyright: © 2017 Micemade.
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package WordPress
* @subpackage Micemade Themes Tools
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Micemade Themes Tools
*/
class Micemade_Themes_Tools {
/**
* Instance
*
* @var [type]
*/
private static $instance = null;
/**
* Micemade theme active check
*
* @var boolean
*/
public $micemade_theme_active = false;
/**
* Get instance
*
* @return self::$instance
*/
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Initialize
*
* @return void
*/
public function init() {
add_action( 'init', array( self::$instance, 'load_plugin' ) );
}
/**
* Load plugin
*
* @return void
* fired upon 'init' hook - to check if Micemade theme is active.
* delay plugin method after theme initializes.
*/
public function load_plugin() {
if ( self::$instance->activation_check() ) {
// Translations.
add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
// Social button bellow the main content.
add_filter( 'the_content', array( self::$instance, 'social_buttons' ) );
// User additional data fields.
add_filter( 'user_contactmethods', array( self::$instance, 'add_to_author_profile' ), 10, 1 );
// Custom filters/hooks.
self::$instance->custom_filters_hooks();
// Custom sidebars.
self::$instance->custom_sidebars();
// Github updater.
self::$instance->updater();
$this->micemade_theme_active = true;
} else {
add_action( 'admin_notices', array( self::$instance, 'admin_notice' ) );
$this->micemade_theme_active = false;
}
}
/**
* Activation check
*
* @return bool $micemade_theme_active - if current theme is made by Micemade.
*/
public function activation_check() {
$current_is_micemade_theme = false;
// Array of supported Micemade Themes -to deprecate.
$micemade_themes = array( 'natura', 'beautify', 'ayame', 'lillabelle', 'inspace' );
if ( is_child_theme() ) {
$parent_theme = wp_get_theme();
$active_theme = $parent_theme->get( 'Template' );
} else {
$active_theme = get_option( 'template' );
}
$active_theme_supported = in_array( $active_theme, $micemade_themes );
// end deprecate.
$current_theme_supported = current_theme_supports( 'micemade-themes-tools' );
// Deprecate $active_theme_supported and leave only $current_theme_supported.
if ( $current_theme_supported || $active_theme_supported ) {
$current_is_micemade_theme = true;
}
return $current_is_micemade_theme;
}
/**
* Admin notice
*
* @return void
* notice if this plugin is active without Micemade theme.
*/
public function admin_notice() {
$class = 'error updated settings-error notice is-dismissible';
$message = __( '"Micemade Themes Tools" is active without active Micemade theme. Please, either activate Micemade theme, or deactivate "Micemade Themes Tools" plugin.', 'micemade-themes-tools' );
echo '<div class="' . esc_attr( $class ) . '"><p>' . esc_html( $message ) . '</p></div>';
}
/**
* Load textdomain
*
* @return boolean
* load plugin translations.
*/
public function load_textdomain() {
$lang_dir = apply_filters( 'micemade_themes_tools_lang_dir', trailingslashit( plugin_dir_path( __FILE__ ) . 'languages' ) );
// Traditional WordPress plugin locale filter.
$locale = apply_filters( 'plugin_locale', get_locale(), 'micemade-themes-tools' );
$mofile = sprintf( '%1$s-%2$s.mo', 'micemade-themes-tools', $locale );
// Setup paths to current locale file.
$mofile_local = $lang_dir . $mofile;
if ( file_exists( $mofile_local ) ) {
// Look in the /wp-content/plugins/micemade-themes-tools/languages/ folder.
load_textdomain( 'micemade-themes-tools', $mofile_local );
} else {
// Load the default language files.
load_plugin_textdomain( 'micemade-themes-tools', false, $lang_dir );
}
return false;
}
/**
* Social buttons
*
* @param html $content - output html with social icons.
* @return html $content
*/
public function social_buttons( $content ) {
global $post;
$permalink = get_permalink( $post->ID );
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
$title = get_the_title();
$title = str_replace( ' ', ' ', $title );
$share_txt = esc_html__( 'Share this on ', 'micemade-themes-tools' );
/*
// If current page is:
// in the WP loop and
// not feed and
// not homepage and
// not archive
// not Elementor Template ( commonly for Maintenance mode )
// show social media links
*/
if ( in_the_loop() && ! is_feed() && ! is_home() && ! is_page() && ! is_archive() && 'elementor_library' !== $post->post_type ) {
$content = $content . '<div class="share-post"><p>' . esc_html__( 'Share this', 'micemade-themes-tools' ) . '</p><div class="social">
<a class="icon-twitter tip-top share-link" href="http://twitter.com/share?text=' . esc_attr( $title ) . '&url=' . esc_url( $permalink ) . '"
onclick="window.open(this.href, \'twitter-share\', \'width=550,height=235\');return false;" title="' . esc_attr( $share_txt ) . 'Twitter">
<i class="fa fa-twitter" aria-hidden="true"></i>
</a>
<a class="icon-fb tip-top share-link" href="https://www.facebook.com/sharer/sharer.php?u=' . esc_url( $permalink ) . '"
onclick="window.open(this.href, \'facebook-share\',\'width=580,height=296\');return false;" title="' . esc_attr( $share_txt ) . 'Facebook">
<i class="fa fa-facebook" aria-hidden="true"></i>
</a>
<a class="icon-gplus tip-top share-link" href="https://plus.google.com/share?url=' . esc_url( $permalink ) . '"
onclick="window.open(this.href, \'google-plus-share\', \'width=490,height=530\');return false;" title="' . esc_attr( $share_txt ) . 'Google Plus">
<i class="fa fa-google-plus" aria-hidden="true"></i>
</a>
<a class="icon-pinterest tip-top share-link" href="https://pinterest.com/pin/create/button/?url=' . esc_url( $permalink ) . '&media=' . esc_url( $thumb[0] ) . '&description=' . esc_attr( $title ) . '" onclick="window.open(this.href, \'pinterest-share\', \'width=490,height=530\');return false;" title="' . esc_attr( $share_txt ) . 'Pinterest">
<i class="fa fa-pinterest" aria-hidden="true"></i>
</a>
</div></div>';
}
return $content;
}
/**
* Add to author profile
*
* @param array $contactmethods - additional input fields for author profile.
* @return $contactmethods
*/
public function add_to_author_profile( $contactmethods = array() ) {
// Show additional contact fields only on Micemade themes.
$current_theme_supported = current_theme_supports( 'micemade-themes-tools' );
if ( $current_theme_supported ) {
$contactmethods['rss_url'] = 'RSS URL';
$contactmethods['google_profile'] = esc_html__( 'Google Profile URL', 'micemade-themes-tools' );
$contactmethods['twitter_profile'] = esc_html__( 'Twitter Profile URL', 'micemade-themes-tools' );
$contactmethods['facebook_profile'] = esc_html__( 'Facebook Profile URL', 'micemade-themes-tools' );
$contactmethods['linkedin_profile'] = esc_html__( 'Linkedin Profile URL', 'micemade-themes-tools' );
$contactmethods['skype'] = esc_html__( 'Skype', 'micemade-themes-tools' );
}
return $contactmethods;
}
/**
* Custom filters / hooks
*
* @return void
*/
public function custom_filters_hooks() {
require_once plugin_dir_path( __FILE__ ) . 'includes/custom-filters-hooks.php';
}
/**
* Custom sidebars
*
* @return void
*/
public function custom_sidebars() {
require_once plugin_dir_path( __FILE__ ) . 'includes/custom-sidebars.php';
}
/**
* GitHub Updater
*
* @return void
*
* include Github based plugin updater class
*/
private function updater() {
if ( is_admin() ) {
require_once plugin_dir_path( __FILE__ ) . 'github_updater.php';
new Micemade_GitHub_Plugin_Updater( __FILE__, 'Micemade', 'micemade-themes-tools' );
}
}
}
// Initialize the plugin.
Micemade_Themes_Tools::get_instance()->init();
/**
* Import WC attributes helper
*
* @param string $attribute_name - name of the attribute.
* @return void
*
* import product attributes helper :
* register atts taxonomies to import attribute terms
* used by Micemade Theme Setup Wizard
*/
function micemade_import_wc_attibutes_helper( $attribute_name ) {
register_taxonomy(
'pa_' . $attribute_name,
apply_filters( 'woocommerce_taxonomy_objects_' . $attribute_name, array( 'product' ) ),
apply_filters(
'woocommerce_taxonomy_args_' . $attribute_name, array(
'hierarchical' => true,
'show_ui' => false,
'query_var' => true,
'rewrite' => false,
)
)
);
register_taxonomy_for_object_type( 'pa_' . $attribute_name, 'product' );
}