-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
129 lines (111 loc) · 3.38 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
<?php
/**
* Plugin Name: Swiper Shortcode Pro
* Plugin URI: https://github.com/benignware-labs/wp-swiper-shortcode
* Description: Swiper Integration for Wordpress
* Author: Rafael Nowrotek
* Author URI: http://benignware.com/
* Version: 0.1.0-beta.29
*
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Functions
*/
require_once plugin_dir_path( __FILE__ ) . 'lib/helpers.php';
require_once plugin_dir_path( __FILE__ ) . 'lib/functions.php';
require_once plugin_dir_path( __FILE__ ) . 'features/sidebar.php';
/**
* Block Initializer.
*/
require_once plugin_dir_path( __FILE__ ) . 'src/init.php';
add_filter('swiper_options', function($options = array(), $params = array()) {
$options = array_merge(
array_filter($options, function ($key) {
return in_array($key, array(
'speed',
'space_between',
'slides_per_view',
'slides_per_column',
'centered_slides',
'parallax',
'autoplay',
'loop',
'free_mode',
'watch_slides_progress',
'watch_slides_visibility',
'theme',
'breakpoints'
));
}, ARRAY_FILTER_USE_KEY),
array(
'navigation' => isset($options['navigation']) && $options['navigation'] ? array_merge(
array(
'nextEl' => '.swiper-button-next',
'prevEl' => '.swiper-button-prev'
),
is_array($options['navigation']) ? $options['navigation'] : array()
) : null,
'pagination' => isset($options['pagination']) && $options['pagination'] ? array_merge(
array(
'el' => '.swiper-pagination',
'clickable' => false
),
is_array($options['pagination']) ? $options['pagination'] : array(),
is_string($options['pagination']) ? array(
'type' => $options['pagination']
) : array()
) : null,
'scrollbar' => isset($options['scrollbar']) && $options['scrollbar'] ? array_merge(
array(
'el' => '.swiper-scrollbar'
),
is_array($options['scrollbar']) ? $options['scrollbar'] : array()
) : null,
'thumbs' => isset($options['thumbs']) && (is_array($options['thumbs']) || $options['thumbs']) ? array_merge(
array(
'slides_per_view' => 3,
'space_between' => 0,
'free_mode' => true,
'watch_slides_visibility' => true,
'watch_slides_progress' => true
),
is_array($options['thumbs']) ? $options['thumbs'] : array()
) : null
)
);
$options = array_filter($options, function($value) {
return $value !== null && !empty($value) && $value !== 'false';
});
$options = array_filter($options);
return $options;
}, 10, 2);
// Swiper Shortcodes
add_shortcode('swiper', 'swiper_shortcode');
add_shortcode('swiper_slide', 'swiper_slide_shortcode');
add_shortcode('swiper_gallery', 'swiper_gallery_shortcode');
register_swiper_theme('white', array(
'classes' => array(
'swiper-button-next' => 'swiper-button-white',
'swiper-button-prev' => 'swiper-button-white',
'swiper-pagination' => 'swiper-pagination-white',
'swiper-scrollbar' => 'swiper-scrollbar-white'
)
));
register_swiper_theme('black', array(
'classes' => array(
'swiper-button-next' => 'swiper-button-black',
'swiper-button-prev' => 'swiper-button-black',
'swiper-pagination' => 'swiper-pagination-black',
'swiper-scrollbar' => 'swiper-scrollbar-black'
)
));
add_filter( 'post_gallery', function($output = '', $atts = null) {
$params = array_merge(array(
'fit' => 'cover'
), $atts);
return swiper_gallery_shortcode($params, $output);
}, 11, 2 );