-
Notifications
You must be signed in to change notification settings - Fork 0
/
u-loader.php
230 lines (162 loc) · 6.13 KB
/
u-loader.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
<?php
/**
* @package ULoader
*/
/*
Plugin Name: U Loader
Description: A Simple easy-to-use preloader for Wordpress. Just get a cool animation with your logo while loading your site. This plugin is made with HTML, CSS and JS.
Version: 1.0.0
Requires at least: 5.2
Requires PHP: 7.2
Author: Utpal Barman
Author URI: https://utpal-barman.github.io/
License: GPL v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: u-loader
*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// restrict direct access here
defined( 'ABSPATH' ) or die('Can\t Access on this on');
// load css : funtion
function u_loader_wp_enqueue_scripts(){
wp_enqueue_style( 'u-loader-style', plugins_url ( 'css/style.css', __FILE__ ) );
}
// load css : action
add_action('wp_enqueue_scripts', 'u_loader_wp_enqueue_scripts');
// ---------------------------------------------------------
// add html to head : function
function u_loader_add_head_div() {
$options = get_option( 'u_loader_image_url' );
if ( !isset($options['url']) ) {
$options['url'] = plugins_url('u-loader/assets/u-loader-default.gif');
}
?>
<div class="u-loader u-grayscale" style="background: url( <?php print $options['url']; ?> ) center no-repeat #fff;"></div>
<?php
}
// add to head : action
add_action('wp_head', 'u_loader_add_head_div');
// ---------------------------------------------------------
// add to footer : funtion
function u_loader_script() {
?>
<script>
(function ($) {
$(window).load(function () {
$(".u-loader").animate({ zoom: '150%' }).removeClass("u-grayscale").fadeOut("slow");
});
})(jQuery);
</script>
<?php
}
// add to footer : funtion
add_action('wp_footer', 'u_loader_script');
// ---------------------------------------------------------
//
// plugin action Links
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'u_loader_plugin_action_links', 10, 5 );
function u_loader_plugin_action_links( $actions, $plugin_file ){
static $plugin;
if ( !isset($plugin) ){
$plugin = plugin_basename(__FILE__);
}
if ($plugin == $plugin_file) {
if ( is_ssl() ) {
$settings_link = '<a href="'.admin_url('admin.php?page=u-loader-settings', 'https' ).'">Settings</a>';
}else{
$settings_link = '<a href="'.admin_url('admin.php?page=u-loader-settings', 'http' ).'">Settings</a>';
}
$settings = array($settings_link);
$actions = array_merge($settings, $actions);
}
return $actions;
}
// ---------------------------------------------------------
// Add to admin menu
add_action('admin_menu','u_loader_menu_options');
function u_loader_menu_options (){
add_menu_page('U Loader', 'U Loader', 'manage_options', 'u-loader-settings', 'u_loader_settings_view', 'dashicons-image-rotate', 99);
}
function u_loader_settings_view(){
?>
<div class="wrap">
<h1 style="font-weight: 700"> U Loader Settings </h1>
<br/>
<script>
function getDefaultURL() {
jQuery(".toplevel_page_u-loader-settings .form-table input").val("<?php print plugins_url('u-loader/assets/u-loader-default.gif'); ?>");
jQuery("#u-loader-preview").attr("src", jQuery(".u-loader-input").val());
}
</script>
<button class="button-secondary" onclick="getDefaultURL()"> Restore Default </button>
<br/>
<br/>
<hr/>
<h2>Preview</h2>
<?php
$options = get_option( 'u_loader_image_url' );
if ( !isset($options['url']) ) {
$options['url'] = plugins_url('u-loader/assets/u-loader-default.gif');
}
?>
<img src="<?php print $options['url']; ?>" id="u-loader-preview" style="height: 200px; width: 300px; object-fit: contain;"/>
<form action="options.php" method="post">
<?php
// security field
settings_fields( 'u_loader_settings_group' );
// output settings section here
do_settings_sections('u_loader_settings_group');
// save settings button
submit_button( 'Save Settings' );
?>
</form>
</div>
<?php
}
// ---------------------------------------------------------
add_action( 'admin_init', 'u_loader_admin_init' );
function u_loader_admin_init() {
register_setting( 'u_loader_settings_group', 'u_loader_image_url' );
add_settings_section(
'u_loader_section_id',
'Insert Your Logo',
'u_loader_section_callback',
'u_loader_settings_group'
);
add_settings_field(
'url',
'Paste a valid icon URL',
'u_loader_cb',
'u_loader_settings_group',
'u_loader_section_id'
);
}
// ---------------------------------------------------------
function u_loader_section_callback(){
}
function u_loader_cb(){
$options = get_option( 'u_loader_image_url' );
if ( !isset($options['url']) ) {
$options['url'] = plugins_url('u-loader/assets/u-loader-default.gif');
}
?>
<input class="u-loader-input" type='text' name='u_loader_image_url[url]' value='<?php echo $options['url']; ?>'>
<script>
jQuery(".u-loader-input").on("input", function () {
jQuery("#u-loader-preview").attr("src", jQuery(".u-loader-input").val());
});
</script>
<?php
}