-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.php
160 lines (122 loc) · 3.8 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
151
152
153
154
155
156
157
158
159
160
<?php
/*Plugin Name: bs Grid
Plugin URI: https://bootscore.me/documentation/bs-grid/
Description: Displays posts from category, child pages from parent id or custom post types by parent taxonomy id in post or page via shortcode.
Version: 5.7.1
Tested up to: 6.6
Requires at least: 5.0
Requires PHP: 7.4
Author: Bootscore
Author URI: https://bootscore.me
License: MIT License
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
/**
* Update checker
*/
require 'update/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
'https://github.com/bootscore/bs-grid/',
__FILE__,
'bs-grid'
);
//Set the branch that contains the stable release.
$myUpdateChecker->setBranch('main');
/**
* Register Scripts
*/
function bs_grid_scripts(){
wp_enqueue_script('bs-grid-js', plugins_url('/assets/js/bs-grid.min.js', __FILE__), array(), false, true);
}
add_action('wp_enqueue_scripts', 'bs_grid_scripts');
/**
* Locate template.
*
* Locate the called template.
* Search Order:
* 1. /themes/theme/bs-grid/$template_name
* 2. /themes/theme/bs-grid-main/$template_name
* 3. /themes/theme/$template_name
* 4. /plugins/bs-grid-main/templates/$template_name.
*
* @since 5.6.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_grid_locate_template($template_name, $template_path = '', $default_path = '') {
// Set default plugin templates path.
if (!$default_path) :
$default_path = plugin_dir_path(__FILE__) . 'templates/'; // Path to the template folder
endif;
// Check if 'bs-grid/' exists in the theme.
$bs_grid_path = get_theme_file_path('bs-grid/' . $template_name);
if (file_exists($bs_grid_path)) {
return $bs_grid_path;
}
// Check if 'bs-grid-main/' exists in the theme.
// Fallback for existing 'bs-grid-main/' folders in child theme
$bs_grid_main_path = get_theme_file_path('bs-grid-main/' . $template_name);
if (file_exists($bs_grid_main_path)) {
return $bs_grid_main_path;
}
// If neither 'bs-grid/' nor 'bs-grid-main/' exists, return the default path.
return $default_path . $template_name;
}
/**
* Get template.
*
* Search for the template and include the file.
*
* @since 1.0.0
*
* @see bs_grid_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_grid_get_template($template_name, $args = array(), $tempate_path = '', $default_path = '') {
if (is_array($args) && isset($args)) :
extract($args);
endif;
$template_file = bs_grid_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
*/
function bs_grid() {
return bs_grid_get_template('sc-grid.php');
}
add_action('wp_head', 'bs_grid');
function bs_grid_list() {
return bs_grid_get_template('sc-list.php');
}
add_action('wp_head', 'bs_grid_list');
function bs_grid_hero() {
return bs_grid_get_template('sc-hero.php');
}
add_action('wp_head', 'bs_grid_hero');
function bs_grid_accordion() {
return bs_grid_get_template('sc-accordion.php');
}
add_action('wp_head', 'bs_grid_accordion');
function bs_grid_tabs() {
return bs_grid_get_template('sc-tabs.php');
}
add_action('wp_head', 'bs_grid_tabs');