%PDF- %PDF-
Direktori : /var/www/i4insight.eco-n-tech.co.uk/wp-content/themes/lloyd/ |
Current File : /var/www/i4insight.eco-n-tech.co.uk/wp-content/themes/lloyd/functions.php |
<?php /** * lloyd functions and definitions * * @link https://developer.wordpress.org/themes/basics/theme-functions/ * * @package lloyd */ if ( ! defined( 'LLOYD_VERSION' ) ) { // Replace the version number of the theme on each release. define( 'LLOYD_VERSION', time() ); } if ( ! function_exists( 'lloyd_setup' ) ) : /** * Sets up theme defaults and registers support for various WordPress features. * * Note that this function is hooked into the after_setup_theme hook, which * runs before the init hook. The init hook is too late for some features, such * as indicating support for post thumbnails. */ function lloyd_setup() { /* * Make theme available for translation. * Translations can be filed in the /languages/ directory. * If you're building a theme based on lloyd, use a find and replace * to change 'lloyd' to the name of your theme in all the template files. */ load_theme_textdomain( 'lloyd', get_template_directory() . '/languages' ); // Add default posts and comments RSS feed links to head. add_theme_support( 'automatic-feed-links' ); /* * Let WordPress manage the document title. * By adding theme support, we declare that this theme does not use a * hard-coded <title> tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support( 'title-tag' ); /* * Enable support for Post Thumbnails on posts and pages. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support( 'post-thumbnails' ); // This theme uses wp_nav_menu() in one location. register_nav_menus( array( 'primary' => esc_html__( 'Primary', 'lloyd' ), 'footer' => esc_html__( 'Footer', 'lloyd' ), ) ); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script', ) ); // Set up the WordPress core custom background feature. add_theme_support( 'custom-background', apply_filters( 'lloyd_custom_background_args', array( 'default-color' => 'ffffff', 'default-image' => '', ) ) ); // Add theme support for selective refresh for widgets. add_theme_support( 'customize-selective-refresh-widgets' ); /** * Add support for core custom logo. * * @link https://codex.wordpress.org/Theme_Logo */ add_theme_support( 'custom-logo', array( 'height' => 250, 'width' => 250, 'flex-width' => true, 'flex-height' => true, ) ); /** * Add responsive embeds and block editor styles. */ add_theme_support( 'responsive-embeds' ); add_theme_support( 'editor-styles' ); add_editor_style( 'style-editor.css' ); remove_theme_support( 'block-templates' ); } endif; add_action( 'after_setup_theme', 'lloyd_setup' ); /** * Set the content width in pixels, based on the theme's design and stylesheet. * * Priority 0 to make it available to lower priority callbacks. * * @global int $content_width */ function lloyd_content_width() { $GLOBALS['content_width'] = apply_filters( 'lloyd_content_width', 640 ); } add_action( 'after_setup_theme', 'lloyd_content_width', 0 ); /** * Register widget area. * * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar */ function lloyd_widgets_init() { register_sidebar( array( 'name' => esc_html__( 'Sidebar', 'lloyd' ), 'id' => 'sidebar-1', 'description' => esc_html__( 'Add widgets here.', 'lloyd' ), 'before_widget' => '<section id="%1$s">', 'after_widget' => '</section>', 'before_title' => '<h2>', 'after_title' => '</h2>', ) ); } add_action( 'widgets_init', 'lloyd_widgets_init' ); /** * Enqueue scripts and styles. */ function lloyd_scripts() { wp_enqueue_script('jquery', get_template_directory_uri() . '/js/vendor/jquery.js', array(), LLOYD_VERSION, true); wp_enqueue_script('swiper-js', 'https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.js', array(), LLOYD_VERSION); wp_enqueue_style('swiper-css', 'https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.css', array(), LLOYD_VERSION); wp_enqueue_style('fontawesome-css', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css', array(), LLOYD_VERSION); wp_enqueue_style( 'lloyd-style', get_stylesheet_uri(), array(), LLOYD_VERSION ); wp_enqueue_script( 'lloyd-script', get_template_directory_uri() . '/js/script.min.js', array(), LLOYD_VERSION, true ); wp_enqueue_script('flowbite-js', get_template_directory_uri() . '/js/vendor/flowbite.js', array(), LLOYD_VERSION ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } add_action( 'wp_enqueue_scripts', 'lloyd_scripts' ); add_action( 'wp_enqueue_scripts', 'lloyd_ajax_data', 99 ); function lloyd_ajax_data(){ wp_localize_script( 'lloyd-script', 'lloydajax', array( 'url' => admin_url('admin-ajax.php') ) ); } /** * Add the block editor class to TinyMCE. * * This allows TinyMCE to use Tailwind Typography styles with no other changes. * * @param array $settings TinyMCE settings. * @return array */ function lloyd_tinymce_add_class( $settings ) { $settings['body_class'] = 'block-editor-block-list__layout'; return $settings; } add_filter( 'tiny_mce_before_init', 'lloyd_tinymce_add_class' ); if( function_exists('acf_add_options_page') ) { acf_add_options_page(); } /** * Custom Gutenberg blocks for this theme. */ require get_template_directory() . '/inc/blocks.php'; /** * Custom template tags for this theme. */ require get_template_directory() . '/inc/template-tags.php'; /** * Functions which enhance the theme by hooking into WordPress. */ require get_template_directory() . '/inc/template-functions.php'; function get_custom_styles($fields, $names) { $styles = []; foreach ($fields as $name => $value) { if(in_array($name, $names)) { if($name == 'background') { if(isset($value['type']) && $value['type'] != 'none') { if( isset($value['type']) && $value['type'] == 'color' && isset($value['color']) ) { $color = $value['color']; $styles[] = "background-color: {$color}"; } if( isset($value['type']) && $value['type'] == 'image' && isset($value['image']) ) { $image = $value['image']; $styles[] = "background-image: url('{$image}')"; } } } if($name == 'arrow') { if( isset($value['visibility']) && $value['visibility'] == 'visible' && isset($value['color']) ) { $color = $value['color']; $styles[] = "border-top-color: {$color}"; } } if($name == 'background-color') { $styles[] = "background-color: {$value}"; } if($name == 'color') { $styles[] = "color: {$value}"; } if($name == 'height') { $styles[] = "height: {$value}px"; } } } return !empty($styles) ? ' style="'.join(';',$styles).';"' : ''; } add_action( 'wp_ajax_nopriv_load_posts', 'load_posts_callback' ); add_action( 'wp_ajax_load_posts', 'load_posts_callback' ); function load_posts_callback(){ if($_POST) { $args = array( 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_status' => 'publish' ); $posts = get_posts(); if(isset($_POST['business_areas'])) { $args['post_type'] = 'resource'; if($_POST['business_areas'] !== '') { $args['tax_query'] = [ [ 'taxonomy' => 'business_area', 'field' => 'id', 'terms' => [intval($_POST['business_areas'])], ] ]; } if($_POST['resources_type'] !== '') { $args['meta_query'] = array( array( 'key' => 'resource_type', 'value' => $_POST['resources_type'], 'compare' => '=', ), ); } } else { $args['post_type'] = 'post'; $args['cat'] = intval($_POST['post_category']); } $posts = get_posts($args); get_template_part( 'template-parts/content/content', 'filteritem', array('posts' => $posts) ); } exit(); }