-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathocean-stick-anything.php
507 lines (427 loc) · 13.2 KB
/
ocean-stick-anything.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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<?php
/**
* Plugin Name: Ocean Stick Anything
* Plugin URI: https://oceanwp.org/extension/ocean-stick-anything/
* Description: A simple plugin to stick anything you want on your site.
* Version: 2.0.7
* Author: OceanWP
* Author URI: https://oceanwp.org/
* Requires at least: 5.6
* Tested up to: 6.3.1
*
* Text Domain: ocean-stick-anything
* Domain Path: /languages
*
* @package Ocean_Stick_Anything
* @category Core
* @author OceanWP
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Returns the main instance of Ocean_Stick_Anything to prevent the need to use globals.
*
* @since 1.0.0
* @return object Ocean_Stick_Anything
*/
function Ocean_Stick_Anything() {
return Ocean_Stick_Anything::instance();
} // End Ocean_Stick_Anything()
Ocean_Stick_Anything();
/**
* Main Ocean_Stick_Anything Class
*
* @class Ocean_Stick_Anything
* @version 1.0.0
* @since 1.0.0
* @package Ocean_Stick_Anything
*/
final class Ocean_Stick_Anything {
/**
* Ocean_Stick_Anything The single instance of Ocean_Stick_Anything.
*
* @var object
* @access private
* @since 1.0.0
*/
private static $_instance = null;
/**
* The token.
*
* @var string
* @access public
* @since 1.0.0
*/
public $token;
/**
* The version number.
*
* @var string
* @access public
* @since 1.0.0
*/
public $version;
/**
* The plugin url.
*
* @var string
* @access public
*/
public $plugin_url;
/**
* The plugin path.
*
* @var string
* @access public
*/
public $plugin_path;
// Admin - Start
/**
* The admin object.
*
* @var object
* @access public
* @since 1.0.0
*/
public $admin;
/**
* Constructor function.
*
* @access public
* @since 1.0.0
* @return void
*/
public function __construct( $widget_areas = array() ) {
$this->token = 'ocean-stick-anything';
$this->plugin_url = plugin_dir_url( __FILE__ );
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->version = '2.0.7';
register_activation_hook( __FILE__, array( $this, 'install' ) );
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
add_action( 'init', array( $this, 'setup' ) );
}
/**
* Main Ocean_Stick_Anything Instance
*
* Ensures only one instance of Ocean_Stick_Anything is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see Ocean_Stick_Anything()
* @return Main Ocean_Stick_Anything instance
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
} // End instance()
/**
* Load the localisation file.
*
* @access public
* @since 1.0.0
* @return void
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'ocean-stick-anything', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' );
}
/**
* Installation.
* Runs on activation. Logs the version number and assigns a notice message to a WordPress option.
*
* @access public
* @since 1.0.0
* @return void
*/
public function install() {
$this->_log_version_number();
}
/**
* Log the plugin version number.
*
* @access private
* @since 1.0.0
* @return void
*/
private function _log_version_number() {
// Log the version number.
update_option( $this->token . '-version', $this->version );
}
/**
* Setup all the things.
* Only executes if OceanWP or a child theme using OceanWP as a parent is active and the extension specific filter returns true.
*
* @return void
*/
public function setup() {
$theme = wp_get_theme();
if ( 'OceanWP' == $theme->name || 'oceanwp' == $theme->template ) {
if ( ! is_admin() ) {
add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ), 999 );
}
add_filter( 'ocean_localize_array', array( $this, 'localize_array' ) );
add_action( 'admin_menu', array( $this, 'add_page' ), 60 );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
}
}
/**
* Enqueue scripts.
*
* @since 1.0.0
*/
public function scripts() {
wp_enqueue_script( 'sticky-kit', plugins_url( '/assets/js/vendors/sticky-kit.min.js', __FILE__ ), array( 'jquery' ), $this->version, true );
wp_enqueue_script( 'osa-script', plugins_url( '/assets/js/stick-anythings.min.js', __FILE__ ), array( 'oceanwp-main', 'sticky-kit' ), $this->version, true );
}
/**
* Localize array
*
* @since 1.0.0
*/
public function localize_array( $array ) {
$array['stickElements'] = get_option( 'osa_stick_elements' );
// If offset
$isOffset = get_option( 'osa_stick_offset' );
if ( ! empty( $isOffset ) ) {
$array['isOffset'] = $isOffset;
}
// If un-stick
$unstick = get_option( 'osa_unstick' );
if ( ! empty( $unstick ) ) {
$array['unStick'] = $unstick;
}
return $array;
}
/**
* Add sub menu page
*
* @since 1.0.0
*/
public function add_page() {
add_submenu_page(
'oceanwp',
esc_html__( 'Stick Elements', 'ocean-stick-anything' ),
esc_html__( 'Stick Elements', 'ocean-stick-anything' ),
'manage_options',
'oceanwp-panel-stick',
array( $this, 'create_admin_page' )
);
}
/**
* Get settings.
*
* @since 1.0.0
*/
public static function get_settings() {
$settings = array(
'stick_elements' => get_option( 'osa_stick_elements' ),
'stick_offset' => get_option( 'osa_stick_offset' ),
'unstick' => get_option( 'osa_unstick' ),
);
return apply_filters( 'osa_stick_settings', $settings );
}
/**
* Settings page output
*
* @since 1.0.0
*/
public function create_admin_page() {
// Get settings
$settings = self::get_settings(); ?>
<div class="wrap oceanwp-theme-panel clr">
<h1><?php esc_attr_e( 'Stick Anything', 'ocean-stick-anything' ); ?></h1>
<p class="description"><?php esc_html_e( 'On this page, you can stick any element of your site just by adding the elements in the input.', 'ocean-stick-anything' ); ?></p>
<div class="oceanwp-settings clr">
<?php
if ( ! class_exists( 'Ocean_Sticky_Header' )
&& true != apply_filters( 'oceanwp_theme_panel_sidebar_enabled', false ) ) {
?>
<div class="oceanwp-sidebar right clr">
<?php self::admin_page_sidebar(); ?>
</div>
<?php } ?>
<div class="left clr">
<form method="post" action="options.php">
<?php settings_fields( 'osa_settings' ); ?>
<div class="oceanwp-panels clr">
<h2><?php esc_html_e( 'Stick', 'ocean-stick-anything' ); ?></h2>
<p class="description">
<?php
echo sprintf(
esc_html__( 'You need to add your CSS selector in the Elements field, %1$sfollow this article%2$s to know how to get a CSS selector.', 'ocean-extra' ),
'<a href="https://docs.oceanwp.org/article/529-how-to-get-a-css-selector" target="_blank">',
'</a>'
);
?>
</p>
<table class="form-table">
<tbody>
<tr id="osa_stick_elements_tr">
<th scope="row">
<label for="osa_stick_elements"><?php esc_html_e( 'Elements', 'ocean-stick-anything' ); ?></label>
</th>
<td>
<input name="osa_settings[stick_elements]" type="text" id="osa_stick_elements" value="<?php echo esc_attr( $settings['stick_elements'] ); ?>" class="regular-text">
<p class="description">
<?php esc_html_e( 'Add the element(s) you want to stick separated by a comma. If you want to stick the sidebar, add ".widget-area".', 'ocean-stick-anything' ); ?>
</p>
</td>
</tr>
<tr id="osa_stick_offset_tr">
<th scope="row">
<label for="osa_stick_offset"><?php esc_html_e( 'Offset (px)', 'ocean-stick-anything' ); ?></label>
</th>
<td>
<input name="osa_settings[stick_offset]" type="number" id="osa_stick_offset" value="<?php echo esc_attr( $settings['stick_offset'] ); ?>" class="regular-text">
<p class="description">
<?php esc_html_e( 'Add a space in pixels between the top of the page and the sticky element .', 'ocean-stick-anything' ); ?>
</p>
</td>
</tr>
</tbody>
</table>
<hr>
<h2><?php esc_html_e( 'Responsive', 'ocean-stick-anything' ); ?></h2>
<p class="description">
<?php esc_html_e( 'Here you can choose to un-stick the element(s) when your screen is smaller.', 'ocean-stick-anything' ); ?>
</p>
<table class="form-table">
<tbody>
<tr id="osa_unstick_tr">
<th scope="row">
<label for="osa_unstick"><?php esc_html_e( 'Un-stick From (px)', 'ocean-stick-anything' ); ?></label>
</th>
<td>
<input name="osa_settings[unstick]" type="number" id="osa_unstick" value="<?php echo esc_attr( $settings['unstick'] ); ?>" class="regular-text">
</td>
</tr>
</tbody>
</table>
<?php submit_button(); ?>
</div>
</form>
</div>
</div><!-- .oceanwp-settings -->
</div>
<?php
}
/**
* Settings page sidebar
*
* @since 1.4.0
*/
public static function admin_page_sidebar() {
// Link
$link = 'https://oceanwp.org/extension/ocean-sticky-header/?utm_source=dash&utm_medium=stick-panel&utm_campaign=sticky';
?>
<div class="oceanwp-bloc oceanwp-sticky">
<h3><?php esc_html_e( 'Ocean Sticky Header', 'ocean-extra' ); ?></h3>
<div class="content-wrap">
<p class="content"><?php esc_html_e( 'This plugin is a must-have for any type of website, it allow you to fix your header automatically or manually if you create a custom header style with many control settings.', 'ocean-extra' ); ?></p>
<a href="<?php echo esc_url( $link ); ?>" class="button owp-button" target="_blank"><?php esc_html_e( 'Read More', 'ocean-extra' ); ?></a>
</div>
<i class="dashicons dashicons-admin-post"></i>
</div>
<?php
}
/**
* Register a setting and its sanitization callback.
*
* @since 1.0.0
*/
public static function register_settings() {
register_setting( 'osa_settings', 'osa_settings', array( 'Ocean_Stick_Anything', 'sanitize_settings' ) );
}
/**
* Main Sanitization callback
*
* @since 1.0.0
*/
public static function sanitize_settings() {
// Get settings
$settings = self::get_settings();
foreach ( $settings as $key => $setting ) {
if ( isset( $_POST['osa_settings'][ $key ] ) ) {
update_option( 'osa_' . $key, sanitize_text_field( wp_unslash( $_POST['osa_settings'][ $key ] ) ) );
}
}
}
/**
* Load scripts
*
* @since 1.0.0
*/
public static function admin_scripts( $hook ) {
// Only load scripts when needed.
if ( ! class_exists( 'Ocean_Extra' ) ) {
return;
}
if ( class_exists( 'Ocean_Extra' ) && OE_ADMIN_PANEL_HOOK_PREFIX . '-stick' != $hook ) {
return;
}
// CSS.
wp_enqueue_style( 'oceanwp-stick-anything', plugins_url( '/assets/css/main.min.css', __FILE__ ) );
}
} // End Class.
// --------------------------------------------------------------------------------
// region Freemius
// --------------------------------------------------------------------------------
if ( ! function_exists( 'ocean_stick_anything_fs' ) ) {
// Create a helper function for easy SDK access.
function ocean_stick_anything_fs() {
global $ocean_stick_anything_fs;
if ( ! isset( $ocean_stick_anything_fs ) ) {
$ocean_stick_anything_fs = OceanWP_EDD_Addon_Migration::instance( 'ocean_stick_anything_fs' )->init_sdk(
array(
'id' => '3815',
'slug' => 'ocean-stick-anything',
'public_key' => 'pk_f9a790f52e74ee60eb2812ba763dd',
'is_premium' => false,
'is_premium_only' => false,
'has_paid_plans' => false,
)
);
}
return $ocean_stick_anything_fs;
}
function ocean_stick_anything_fs_addon_init() {
if ( class_exists( 'Ocean_Extra' ) ) {
OceanWP_EDD_Addon_Migration::instance( 'ocean_stick_anything_fs' )->init();
}
}
if ( 0 == did_action( 'owp_fs_loaded' ) ) {
// Init add-on only after parent theme was loaded.
add_action( 'owp_fs_loaded', 'ocean_stick_anything_fs_addon_init', 15 );
} else {
if ( class_exists( 'Ocean_Extra' ) ) {
/**
* This makes sure that if the theme was already loaded
* before the plugin, it will run Freemius right away.
*
* This is crucial for the plugin's activation hook.
*/
ocean_stick_anything_fs_addon_init();
}
}
}
// endregion