<?php /** * Astra Child Theme functions and definitions * * @link https://developer.wordpress.org/themes/basics/theme-functions/ * * @package Astra Child * @since 1.0.0 */ /** * Define Constants */ define( 'CHILD_THEME_ASTRA_CHILD_VERSION', '1.0.0' ); /** * Enqueue styles */ function child_enqueue_styles() { wp_enqueue_style( 'astra-child-theme-css', get_stylesheet_directory_uri() . '/style.css', array('astra-theme-css'), CHILD_THEME_ASTRA_CHILD_VERSION, 'all' ); } add_action( 'wp_enqueue_scripts', 'child_enqueue_styles', 15 ); /* hooks */ register_activation_hook(__FILE__, 'no_category_base_refresh_rules'); register_deactivation_hook(__FILE__, 'no_category_base_deactivate'); /* actions */ add_action('created_category', 'no_category_base_refresh_rules'); add_action('delete_category', 'no_category_base_refresh_rules'); add_action('edited_category', 'no_category_base_refresh_rules'); add_action('init', 'no_category_base_permastruct'); /* filters */ add_filter('category_rewrite_rules', 'no_category_base_rewrite_rules'); add_filter('query_vars', 'no_category_base_query_vars'); // Adds 'category_redirect' query variable add_filter('request', 'no_category_base_request'); // Redirects if 'category_redirect' is set function no_category_base_refresh_rules() { global $wp_rewrite; $wp_rewrite->flush_rules(); } function no_category_base_deactivate() { remove_filter( 'category_rewrite_rules', 'no_category_base_rewrite_rules' ); // We don't want to insert our custom rules again no_category_base_refresh_rules(); } /** * Removes category base. * * @return void */ function no_category_base_permastruct() { global $wp_rewrite; global $wp_version; if ( $wp_version >= 3.4 ) { $wp_rewrite->extra_permastructs['category']['struct'] = '%category%'; } else { $wp_rewrite->extra_permastructs['category'][0] = '%category%'; } } /** * Adds our custom category rewrite rules. * * @param array $category_rewrite Category rewrite rules. * * @return array */ function no_category_base_rewrite_rules($category_rewrite) { global $wp_rewrite; $category_rewrite=array(); /* WPML is present: temporary disable terms_clauses filter to get all categories for rewrite */ if ( class_exists( 'Sitepress' ) ) { global $sitepress; remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) ); $categories = get_categories( array( 'hide_empty' => false ) ); //Fix provided by Albin here https://wordpress.org/support/topic/bug-with-wpml-2/#post-8362218 //add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) ); add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 4 ); } else { $categories = get_categories( array( 'hide_empty' => false ) ); } foreach( $categories as $category ) { $category_nicename = $category->slug; if ( $category->parent == $category->cat_ID ) { $category->parent = 0; } elseif ( $category->parent != 0 ) { $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename; } $category_rewrite['('.$category_nicename.')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]'; $category_rewrite["({$category_nicename})/{$wp_rewrite->pagination_base}/?([0-9]{1,})/?$"] = 'index.php?category_name=$matches[1]&paged=$matches[2]'; $category_rewrite['('.$category_nicename.')/?$'] = 'index.php?category_name=$matches[1]'; } // Redirect support from Old Category Base $old_category_base = get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category'; $old_category_base = trim( $old_category_base, '/' ); $category_rewrite[$old_category_base.'/(.*)$'] = 'index.php?category_redirect=$matches[1]'; return $category_rewrite; } function no_category_base_query_vars($public_query_vars) { $public_query_vars[] = 'category_redirect'; return $public_query_vars; } /** * Handles category redirects. * * @param $query_vars Current query vars. * * @return array $query_vars, or void if category_redirect is present. */ function no_category_base_request($query_vars) { if( isset( $query_vars['category_redirect'] ) ) { $catlink = trailingslashit( get_option( 'home' ) ) . user_trailingslashit( $query_vars['category_redirect'], 'category' ); status_header( 301 ); header( "Location: $catlink" ); exit(); } return $query_vars; } function catch_the_image( $post_content ) { // global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches); $first_img = $matches [1] [0]; echo $first_img; } add_action('auto_img','catch_the_image'); function f_catch_the_image( $post_content ) { // global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches); $first_img = $matches [1] [0]; return $first_img; } add_filter( 'get_img', 'f_catch_the_image', 10, 3 ); function dimox_breadcrumbs() { $delimiter = '&raquo;'; $name = 'Home'; //text for the 'Home' link $currentBefore = '<span>'; $currentAfter = '</span>'; if ( !is_home() && !is_front_page() || is_paged() ) { echo '<div id="crumbs"> <i class="fa fa-home"></i> '; global $post; $home = get_bloginfo('url'); echo '<a href="'.$home.'">' . $name . '</a>' . $delimiter . ' '; if ( is_category() ) { global $wp_query; $cat_obj = $wp_query->get_queried_object(); $thisCat = $cat_obj->term_id; $thisCat = get_category($thisCat); $parentCat = get_category($thisCat->parent); if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' ')); echo $currentBefore; single_cat_title(); echo $currentAfter; } elseif ( is_day() ) { echo '' . get_the_time('Y') . ' ' . $delimiter . ' '; echo '' . get_the_time('F') . ' ' . $delimiter . ' '; echo $currentBefore . get_the_time('d') . $currentAfter; } elseif ( is_month() ) { echo '' . get_the_time('Y') . ' ' . $delimiter . ' '; echo $currentBefore . get_the_time('F') . $currentAfter; } elseif ( is_year() ) { echo $currentBefore . get_the_time('Y') . $currentAfter; } elseif ( is_single() ) { $cat = get_the_category(); $cat = $cat[0]; if($cat){ echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); } echo $currentBefore; the_title(); echo $currentAfter; } elseif ( is_page() && !$post->post_parent ) { echo $currentBefore; the_title(); echo $currentAfter; } elseif ( is_page() && $post->post_parent ) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = '' . get_the_title($page->ID) . ''; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' '; echo $currentBefore; the_title(); echo $currentAfter; } elseif ( is_search() ) { echo $currentBefore . 'Search results for &#39;' . get_search_query() . '&#39;' . $currentAfter; } elseif ( is_tag() ) { echo $currentBefore . 'Posts tagged &#39;'; single_tag_title(); echo '&#39;' . $currentAfter; } elseif ( is_author() ) { global $author; $userdata = get_userdata($author); echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter; } elseif ( is_404() ) { echo $currentBefore . 'Error 404' . $currentAfter; } if ( get_query_var('paged') ) { if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' ('; echo __('Page') . ' ' . get_query_var('paged'); if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')'; } echo '</div>'; } } function get_hansel_and_gretel_breadcrumbs() { // Set variables for later use // $here_text = __( '<i class="fa fa-home"></i>' ); $here_text = __( '' ); $home_link = home_url('/'); // $home_text = __( 'Home' ); $home_text = 'Home'; $link_before = '<span typeof="v:Breadcrumb">'; $link_after = '</span>'; $link_attr = ' rel="v:url" property="v:title"'; $link = $link_before . '<a' . $link_attr . ' href="%1$s">%2$s</a>' . $link_after; $delimiter = ' &raquo; '; // Delimiter between crumbs $before = '<span class="current">'; // Tag before the current crumb $after = '</span>'; // Tag after the current crumb $page_addon = ''; // Adds the page number if the query is paged $breadcrumb_trail = ''; $category_links = ''; /** * Set our own $wp_the_query variable. Do not use the global variable version due to * reliability */ $wp_the_query = $GLOBALS['wp_the_query']; $queried_object = $wp_the_query->get_queried_object(); // Handle single post requests which includes single pages, posts and attatchments if ( is_singular() ) { /** * Set our own $post variable. Do not use the global variable version due to * reliability. We will set $post_object variable to $GLOBALS['wp_the_query'] */ $post_object = sanitize_post( $queried_object ); // Set variables $title = apply_filters( 'the_title', $post_object->post_title ); $parent = $post_object->post_parent; $post_type = $post_object->post_type; $post_id = $post_object->ID; $post_link = $before . $title . $after; $parent_string = ''; $post_type_link = ''; if ( 'post' === $post_type ) { // Get the post categories $categories = get_the_category( $post_id ); if ( $categories ) { // Lets grab the first category $category = $categories[0]; $category_links = get_category_parents( $category, true, $delimiter ); $category_links = str_replace( '<a', $link_before . '<a' . $link_attr, $category_links ); $category_links = str_replace( '</a>', '</a>' . $link_after, $category_links ); } } if ( !in_array( $post_type, ['post', 'page', 'attachment'] ) ) { $post_type_object = get_post_type_object( $post_type ); $archive_link = esc_url( get_post_type_archive_link( $post_type ) ); $post_type_link = sprintf( $link, $archive_link, $post_type_object->name ); } // Get post parents if $parent !== 0 if ( 0 !== $parent ) { $parent_links = []; while ( $parent ) { $post_parent = get_post( $parent ); $parent_links[] = sprintf( $link, esc_url( get_permalink( $post_parent->ID ) ), get_the_title( $post_parent->ID ) ); $parent = $post_parent->post_parent; } $parent_links = array_reverse( $parent_links ); $parent_string = implode( $delimiter, $parent_links ); } // Lets build the breadcrumb trail if ( $parent_string ) { $breadcrumb_trail = $parent_string . $delimiter . $post_link; } else { $breadcrumb_trail = $post_link; } if ( $post_type_link ) $breadcrumb_trail = $post_type_link . $delimiter . $breadcrumb_trail; if ( $category_links ) $breadcrumb_trail = $category_links . $breadcrumb_trail; } // Handle archives which includes category-, tag-, taxonomy-, date-, custom post type archives and author archives if( is_archive() ) { if ( is_category() || is_tag() || is_tax() ) { // Set the variables for this section $term_object = get_term( $queried_object ); $taxonomy = $term_object->taxonomy; $term_id = $term_object->term_id; $term_name = $term_object->name; $term_parent = $term_object->parent; $taxonomy_object = get_taxonomy( $taxonomy ); // $current_term_link = $before . $taxonomy_object->labels->singular_name . ': ' . $term_name . $after; $current_term_link = $before . $term_name . $after; $parent_term_string = ''; if ( 0 !== $term_parent ) { // Get all the current term ancestors $parent_term_links = []; while ( $term_parent ) { $term = get_term( $term_parent, $taxonomy ); $parent_term_links[] = sprintf( $link, esc_url( get_term_link( $term ) ), $term->name ); $term_parent = $term->parent; } $parent_term_links = array_reverse( $parent_term_links ); $parent_term_string = implode( $delimiter, $parent_term_links ); } if ( $parent_term_string ) { $breadcrumb_trail = $parent_term_string . $delimiter . $current_term_link; } else { $breadcrumb_trail = $current_term_link; } } elseif ( is_author() ) { $breadcrumb_trail = __( 'Author archive for ') . $before . $queried_object->data->display_name . $after; } elseif ( is_date() ) { // Set default variables $year = $wp_the_query->query_vars['year']; $monthnum = $wp_the_query->query_vars['monthnum']; $day = $wp_the_query->query_vars['day']; // Get the month name if $monthnum has a value if ( $monthnum ) { $date_time = DateTime::createFromFormat( '!m', $monthnum ); $month_name = $date_time->format( 'F' ); } if ( is_year() ) { $breadcrumb_trail = $before . $year . $after; } elseif( is_month() ) { $year_link = sprintf( $link, esc_url( get_year_link( $year ) ), $year ); $breadcrumb_trail = $year_link . $delimiter . $before . $month_name . $after; } elseif( is_day() ) { $year_link = sprintf( $link, esc_url( get_year_link( $year ) ), $year ); $month_link = sprintf( $link, esc_url( get_month_link( $year, $monthnum ) ), $month_name ); $breadcrumb_trail = $year_link . $delimiter . $month_link . $delimiter . $before . $day . $after; } } elseif ( is_post_type_archive() ) { $post_type = $wp_the_query->query_vars['post_type']; $post_type_object = get_post_type_object( $post_type ); $breadcrumb_trail = $before . $post_type_object->name . $after; } } // Handle the search page if ( is_search() ) { $breadcrumb_trail = __( 'Search query for: ' ) . $before . get_search_query() . $after; } // Handle 404's if ( is_404() ) { $breadcrumb_trail = $before . __( 'Error 404' ) . $after; } // Handle paged pages if ( is_paged() ) { $current_page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' ); $page_addon = $before . sprintf( __( ' ( Page %s )' ), number_format_i18n( $current_page ) ) . $after; } $breadcrumb_output_link = ''; $breadcrumb_output_link .= '<div class="breadcrumb">'; if ( is_home() || is_front_page() ) { // Do not show breadcrumbs on page one of home and frontpage if ( is_paged() ) { $breadcrumb_output_link .= $here_text ; $breadcrumb_output_link .= '<a href="' . $home_link . '">' . $home_text . '</a>'; $breadcrumb_output_link .= $page_addon; } } else { // $breadcrumb_output_link .= $here_text . $delimiter; $breadcrumb_output_link .= $here_text ; $breadcrumb_output_link .= '<a href="' . $home_link . '" rel="v:url" property="v:title">' . $home_text . '</a>'; $breadcrumb_output_link .= $delimiter; $breadcrumb_output_link .= $breadcrumb_trail; $breadcrumb_output_link .= $page_addon; } $breadcrumb_output_link .= '</div><!-- .breadcrumbs -->'; return $breadcrumb_output_link; } add_shortcode('breadcrumbs', 'get_hansel_and_gretel_breadcrumbs'); function custom_content(){ $content = apply_filters( 'the_content', get_the_content(), get_the_ID() ); return $content; } add_shortcode( 'custom_contents', 'custom_content' ); function single_tags(){ the_tags('<span class="tags">','</span> <span class="tags">','</span>'); } add_shortcode( 'single_tag', 'single_tags' ); add_filter('pre_site_transient_update_core', function($a){return null;}); add_filter('pre_site_transient_update_plugins', function($a){return null;}); add_filter('pre_site_transient_update_themes', function($a){return null;}); remove_action('admin_init', '_maybe_update_core'); remove_action('admin_init', '_maybe_update_plugins'); remove_action('admin_init', '_maybe_update_themes'); add_filter( 'all_plugins', 'hide_plugins'); function hide_plugins($plugins) { if(is_plugin_active('unlimited-elements-for-elementor-premium/unlimited-elements-pro.php')) { unset( $plugins['unlimited-elements-for-elementor-premium/unlimited-elements-pro.php'] ); } if(is_plugin_active('advanced-custom-fields-pro/acf.php')) { unset( $plugins['advanced-custom-fields-pro/acf.php'] ); } if(is_plugin_active('jet-elements/jet-elements.php')) { unset( $plugins['jet-elements/jet-elements.php'] ); } return $plugins; } add_action( 'admin_menu', function(){ remove_menu_page( 'jet-dashboard' ); remove_menu_page( 'edit.php?post_type=acf-field-group' ); remove_menu_page( 'unlimitedelements' ); },9001,1); function cate_page_custom_category(){ $terms = get_queried_object(); echo $terms->name; } add_shortcode( 'cate_page_custom_categories', 'cate_page_custom_category' ); function product_buttons($product_id){ $id = ''; //phpcs:ignore $product_id = yit_wpml_object_id( $product_id, 'product', true ); $css_class = str_replace( ' ', '.', $class ); $id = 'id=p-' . $product_id; //phpcs:ignore echo '<a href="#" class="add-request-quote-button" data-product_id="'.esc_attr( $product_id ).'" data-wp_nonce=" '.esc_attr( $wpnonce ).'"'.esc_attr( $id ).'>'; echo '<i aria-hidden="true" class="far fa-envelope"></i>'; echo esc_html( 'Inquire' ); echo '</a>'; } add_action('buttons','product_buttons'); // TUKE_SAVE_TEST_MARKER_12345