-
Notifications
You must be signed in to change notification settings - Fork 0
/
all-in-one-wp-preloader.php
177 lines (158 loc) · 6.55 KB
/
all-in-one-wp-preloader.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
<?php
/**
* Plugin Name: All-in-One WP Preloader
* Plugin URI: https://wordpress.org/plugins/all-in-one-wp-preloader
* Description: All-in-One Preloader helps you to create awesome preloader that easy to customize, works on all major browsers and with any wp theme.
* Version: 1.0.0
* Author: Monzur Alam
* Author URI: https://profiles.wordpress.org/monzuralam
* Text Domain: all-in-one-wp-preloader
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// If this file is called directly, abort.
if( ! defined('ABSPATH') ){
exit; // Exit if accessed directly.
}
// Plugin Basename
define( 'AI1WP_PLUGIN_BASENAME', basename( dirname( __FILE__ ) ));
// Plugin Path
define( 'AI1WP_PATH', dirname(__FILE__) );
// Plugin URL
define( 'AI1WP_URL', plugins_url( '' , __FILE__ ));
/**
* Load Textdomain
* Load Plugin Localization files.
*/
if( ! function_exists('ai1wp_i10n') ){
function ai1wp_i10n(){
load_plugin_textdomain( 'all-in-one-wp-preloader', false, AI1WP_PLUGIN_BASENAME . '/languages');
}
add_action('plugins_loaded', 'ai1wp_i10n');
}
/**
* Enqueue Scripts
*/
if( ! function_exists('ai1wp_scripts') ){
function ai1wp_scripts(){
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'ai1wp', AI1WP_URL . '/assets/js/main.js', array('jquery'), time(), true );
}
add_action('wp_enqueue_scripts','ai1wp_scripts');
}
/**
* Enqueue Style
*/
if( ! function_exists('ai1wp_style') ){
function ai1wp_style(){
wp_enqueue_style('ai1wp', AI1WP_URL . '/assets/css/style.css', null, time(), 'all');
}
add_action('wp_enqueue_scripts','ai1wp_style');
}
/*--------------------------------------------------------------
// Carbon fields Inclusion
--------------------------------------------------------------*/
use Carbon_Fields\Container;
use Carbon_Fields\Field;
require_once( AI1WP_PATH . '/admin/carbon-fields/vendor/autoload.php' );
if( ! function_exists('ai1wp_preloader_boot') ){
function ai1wp_preloader_boot(){
\Carbon_Fields\Carbon_Fields::boot();
}
add_action('plugins_loaded','ai1wp_preloader_boot');
}
/*--------------------------------------------------------------
// Settings
--------------------------------------------------------------*/
if( ! function_exists('ai1wp_setting_options') ){
function ai1wp_setting_options(){
Container::make( 'theme_options', __( 'All-in-One WP Preloader', 'all-in-one-wp-preloader' ) ) -> add_fields( array(
Field::make( 'checkbox', 'ai1wp_enable', __('Enable Preloader', 'all-in-one-wp-preloader') ),
Field::make( 'image', 'ai1wp_img', __( 'Preloader Image', 'all-in-one-wp-preloader' ) )
->set_help_text( __( 'If no image select then load default image.' ) )
->set_value_type( 'url' ),
Field::make( 'color', 'ai1wp_bg_color', __( 'Background Color', 'all-in-one-wp-preloader' ) ),
Field::make( 'select', 'ai1wp_layout_style', __( 'Preloader Design', 'all-in-one-wp-preloader' ) )
-> set_options( array(
'1' => __('Loader 1', 'all-in-one-wp-preloader'),
'2' => __('Loader 2', 'all-in-one-wp-preloader'),
'3' => __('Loader 3', 'all-in-one-wp-preloader'),
) ),
) );
}
add_action('carbon_fields_register_fields','ai1wp_setting_options');
}
/*--------------------------------------------------------------
// Preloader Content
--------------------------------------------------------------*/
if( ! function_exists('ai1wp_preloader') ){
function ai1wp_preloader(){
$ai1wp_enable = esc_html(carbon_get_theme_option('ai1wp_enable'));
if( $ai1wp_enable ){
$loderStyle = esc_html(carbon_get_theme_option('ai1wp_layout_style'));
$ai1wp_custom_logo = esc_url( carbon_get_theme_option('ai1wp_img') );
$ai1wp_default_logo = esc_url( AI1WP_URL . '/assets/images/ai1wp.png') ;
$logo = $ai1wp_custom_logo ? $ai1wp_custom_logo : $ai1wp_default_logo;
switch($loderStyle){
case '1':
echo '<div class="preloader ai1wp-style-1">
<figure>
<img src="'. $logo .'" alt="Image">
</figure>
</div>';
// die;
break;
case '2':
echo '<div class="preloader ai1wp-style-2"></div>';
break;
case '3':
echo '<div class="loader-wrap">
<div class="ai1wp-style-3">
<div class="ai1wp-style-3-close">Preloader Close</div>
</div>
<div class="layer layer-one"><span class="overlay"></span></div>
<div class="layer layer-two"><span class="overlay"></span></div>
<div class="layer layer-three"><span class="overlay"></span></div>
</div>';
break;
default:
echo '<div class="preloader ai1wp-style-1">
<figure>
<img src="'. $logo .'" alt="Image">
</figure>
</div>';
break;
}
}
}
add_action('wp_body_open','ai1wp_preloader');
}
/*--------------------------------------------------------------
// Preloader Dynamic Style
--------------------------------------------------------------*/
if( ! function_exists('ai1wp_preloader_dynamic_style') ){
function ai1wp_preloader_dynamic_style(){
$loader_number = esc_html(carbon_get_theme_option('ai1wp_layout_style'));
$ai1wp_bg_color = esc_attr(carbon_get_theme_option('ai1wp_bg_color'));
$ai1wp_logo = esc_url(carbon_get_theme_option('ai1wp_img'));
$ai1wp_default_logo = esc_url( AI1WP_URL . '/assets/images/ai1wp.png' );
$logo = $ai1wp_logo ? $ai1wp_logo : $ai1wp_default_logo;
if( $loader_number != 1 ){
echo '
<style>
.ai1wp-style-'.$loader_number.'{
background-color: '.$ai1wp_bg_color.';
background-image: url('. $logo .');
}
</style>';
}else{
echo '
<style>
.ai1wp-style-'.$loader_number.'{
background-color: '.$ai1wp_bg_color.';
}
</style>';
}
}
add_action('wp_head','ai1wp_preloader_dynamic_style');
}