forked from bootscore/bs-swiper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
151 lines (115 loc) · 4.1 KB
/
main.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
<?php
/*Plugin Name: bS Swiper
Plugin URI: https://bootscore.me/plugins/bs-swiper/
Description: Plugin to show posts, pages, custom post types or WooCommerce products in a swiper.js carousel for bootScore theme. <a href="https://bootscore.me/documentation/bs-swiper/">Documentation</a> | <a href="https://bootscore.me/shop/products/free/bs5-swiper/">Changelog</a>
Version: 5.1.0.2
Author: bootScore
Author URI: https://bootscore.me
License: MIT License
*/
// Update checker
require 'update/update-checker.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://bootscore.me/wp-content/plugins/bs-swiper-main/update/plugin.json',
__FILE__, //Full path to the main plugin file or functions.php.
'bs-swiper-main'
);
// Register Styles and Scripts
function swiper_scripts() {
wp_enqueue_script( 'swiper-min-js', plugins_url( '/js/swiper-bundle.min.js' , __FILE__ ), array(), false, true );
wp_enqueue_script( 'swiper-init-js', plugins_url( '/js/swiper-init.js' , __FILE__ ), array(), false, true );
wp_register_style( 'swiper-min-css', plugins_url('css/swiper-bundle.min.css', __FILE__) );
wp_enqueue_style( 'swiper-min-css' );
wp_register_style( 'swiper-style-css', plugins_url('css/swiper-style.css', __FILE__) );
wp_enqueue_style( 'swiper-style-css' );
}
add_action('wp_enqueue_scripts','swiper_scripts');
/**
* Locate template.
*
* Locate the called template.
* Search Order:
* 1. /themes/theme/bs-swiper-main/$template_name
* 2. /themes/theme/$template_name
* 3. /plugins/bs-swiper-main/templates/$template_name.
*
* @since 1.0.0
*
* @param string $template_name Template to load.
* @param string $string $template_path Path to templates.
* @param string $default_path Default path to template files.
* @return string Path to the template file.
*/
function bs_swiper_locate_template( $template_name, $template_path = '', $default_path = '' ) {
// Set variable to search in bs-swiper-main folder of theme.
if ( ! $template_path ) :
$template_path = 'bs-swiper-main/';
endif;
// Set default plugin templates path.
if ( ! $default_path ) :
$default_path = plugin_dir_path( __FILE__ ) . 'templates/'; // Path to the template folder
endif;
// Search template file in theme folder.
$template = locate_template( array(
$template_path . $template_name,
$template_name
) );
// Get plugins template file.
if ( ! $template ) :
$template = $default_path . $template_name;
endif;
return apply_filters( 'bs_swiper_locate_template', $template, $template_name, $template_path, $default_path );
}
/**
* Get template.
*
* Search for the template and include the file.
*
* @since 1.0.0
*
* @see bs_swiper_locate_template()
*
* @param string $template_name Template to load.
* @param array $args Args passed for the template file.
* @param string $string $template_path Path to templates.
* @param string $default_path Default path to template files.
*/
function bs_swiper_get_template( $template_name, $args = array(), $tempate_path = '', $default_path = '' ) {
if ( is_array( $args ) && isset( $args ) ) :
extract( $args );
endif;
$template_file = bs_swiper_locate_template( $template_name, $tempate_path, $default_path );
if ( ! file_exists( $template_file ) ) :
_doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $template_file ), '1.0.0' );
return;
endif;
include $template_file;
}
/**
* Templates.
*
* This func tion will output the templates
* file from the /templates.
*
* @since 1.0.0
*/
// Cards
function bs_swiper_card() {
return bs_swiper_get_template( 'sc-swiper-card.php' );
}
add_action('wp_head', 'bs_swiper_card');
// Products
function bs_swiper_card_product() {
return bs_swiper_get_template( 'sc-swiper-card-product.php' );
}
add_action('wp_head', 'bs_swiper_card_product');
// Heroes
function bs_swiper_hero() {
return bs_swiper_get_template( 'sc-swiper-hero.php' );
}
add_action('wp_head', 'bs_swiper_hero');
// Heroes Fade
function bs_swiper_hero_fade() {
return bs_swiper_get_template( 'sc-swiper-hero-fade.php' );
}
add_action('wp_head', 'bs_swiper_hero_fade');