✨feature: Get styles from theme folder
📄 docs: Add comment for template loader
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
<?php
|
||||
if (!defined('ABSPATH')) { exit; } // Prevent direct access
|
||||
|
||||
/** Retrieves the path to a template file.
|
||||
*
|
||||
* Checks if a template file exists in the theme's "resource-filter" directory
|
||||
* first, and returns its path if found. If not found in the theme directory,
|
||||
* it checks the plugin's templates directory. If the template is found in
|
||||
* neither location, it returns false.
|
||||
*
|
||||
* @param string $template_name The name of the template file to retrieve.
|
||||
* @return string|false The path to the template file if found, or false if not.
|
||||
*/
|
||||
|
||||
function rfGetTemplate($template_name) {
|
||||
$theme_template = get_stylesheet_directory() . "/resource-filter/$template_name";
|
||||
$plugin_template = plugin_dir_path(__FILE__) . "../templates/$template_name";
|
||||
|
||||
@@ -35,9 +35,22 @@ class ResourceFilterPlugin {
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function enqueueScripts() {
|
||||
// Check if a custom stylesheet exists in the theme directory
|
||||
$theme_stylesheet = get_stylesheet_directory() . '/resource-filter/style.css';
|
||||
$theme_stylesheet_url = get_stylesheet_directory_uri() . '/resource-filter/style.css';
|
||||
|
||||
if (file_exists($theme_stylesheet)) {
|
||||
// Enqueue the stylesheet from the theme
|
||||
error_log('Using theme stylesheet');
|
||||
wp_enqueue_style('content-filter-style', $theme_stylesheet_url, [], filemtime($theme_stylesheet));
|
||||
} else {
|
||||
// Fall back to the plugin's stylesheet
|
||||
error_log('Using plugin stylesheet');
|
||||
wp_enqueue_style('content-filter-style', plugins_url('assets/style.css', __FILE__), [], filemtime(plugin_dir_path(__FILE__) . 'assets/style.css'));
|
||||
}
|
||||
|
||||
// Load script only if the shortcode is present on the page
|
||||
if (!is_admin() && has_shortcode(get_post_field('post_content', get_the_ID()), 'resource_filter')) {
|
||||
wp_enqueue_style('resource-filter-style', plugins_url('assets/style.css', __FILE__));
|
||||
wp_enqueue_script('resource-filter-script', plugins_url('assets/script.js', __FILE__), ['jquery'], null, true);
|
||||
|
||||
wp_localize_script('resource-filter-script', 'resourceFilterAjax', [
|
||||
|
||||
Reference in New Issue
Block a user