File: /mnt/data/dev/dev-mentoring-wp/wp-content/themes/mentoring/functions.php
<?php
/**
* mentoring functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package mentoring
*/
if ( ! defined('ABSPATH') ) {
exit;
}
// Theme utility functions
require_once get_template_directory(). '/inc/mentoring-demo-content.php';
require get_template_directory() . '/inc/scripts.php'; //Theme styles and scripts
require get_template_directory() . '/inc/functions-utilities.php';
// Theme Setup
require get_template_directory() . '/inc/functions-setup.php';
// Theme Scripts/Styles
require get_template_directory() . '/inc/functions-scripts.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';
// Social Media Functions
require get_template_directory() . '/inc/functions-social.php';
// Dynamic Css
require get_template_directory() . '/inc/color-customizer.php';
// Subheader Functions
require get_template_directory() . '/inc/functions-subheader.php';
// Sidebar Functions
require get_template_directory() . '/inc/functions-sidebars.php';
// WooCommerce Functions
require get_template_directory() . '/inc/functions-woocommerce.php';
// Responsible for edd options
require get_template_directory() . '/inc/functions-edd.php';
// Load theme options.
require get_template_directory() . '/inc/redux-options/redux-config.php';
// TGM plugin activation.
require get_template_directory() . '/inc/tgm-plugin-activation/required-plugin.php';
// Responsible for post functions
require get_template_directory() . '/inc/classes/class-mentoring-blog-functions.php';
// Responsible for portfolio functions
require get_template_directory() . '/inc/classes/class-mentoring-portfolio-functions.php';
// Responsible for service functions
require get_template_directory() . '/inc/classes/class-mentoring-service-functions.php';
// Responsible for mentor functions
require get_template_directory() . '/inc/classes/class-mentoring-mentor-functions.php';
// Responsible for lazy load functions
require get_template_directory() . '/inc/classes/class-mentoring-lazy-load-functions.php';
require get_template_directory() . '/widgets/recent-posts-widgets.php';
// Responsible for bfi thumb functions
require get_template_directory() . '/inc/classes/BFI_Thumb.php';
// Subheader Functions
require get_template_directory() . '/inc/functions-popup.php';
/*========================
CUSTOM WALKERS
========================*/
// Comment walker.
require get_template_directory() . '/classes/class-mentoring-walker-comment.php';
// Category Widget walker.
require get_template_directory() . '/classes/class-mentoring-walker-category.php';
//function license_activation() {
// require_once get_template_directory() . '/inc/license-activation.php';
//}
//add_action('after_setup_theme', 'license_activation');
if ( ! function_exists( 'mentoring_string_limit_words' ) ) {
function mentoring_string_limit_words($string, $word_limit) {
$words = explode(' ', $string, ($word_limit + 1));
if (count($words) > $word_limit) {
array_pop($words);
//add a ... at last article when more than limit word count
return implode(' ', $words) ;
} else {
//otherwise
return implode(' ', $words);
}
}
}
function mentoring_custom_header_widget() {
register_sidebar( array(
'name' => 'Custom Header Widget',
'id' => 'custom-header-widget',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="chw-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => 'Footer Style1 Column1',
'id' => 'footerarea-one',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widgettitle">',
'after_title' => '</h6>',
) );
register_sidebar( array(
'name' => 'Footer Style1 Column2',
'id' => 'footerarea-two',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widgettitle">',
'after_title' => '</h6>',
) );
register_sidebar( array(
'name' => 'Footer Style1 Column3',
'id' => 'footerarea-three',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widgettitle">',
'after_title' => '</h6>',
) );
register_sidebar( array(
'name' => 'Footer Style1 Column4',
'id' => 'footerarea-four',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widgettitle">',
'after_title' => '</h6>',
) );
register_sidebar( array(
'name' => 'Footer Style2 Column1',
'id' => 'footerarea2-one',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widgettitle">',
'after_title' => '</h6>',
) );
register_sidebar( array(
'name' => 'Footer Style2 Column2',
'id' => 'footerarea2-two',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widgettitle">',
'after_title' => '</h6>',
) );
register_sidebar( array(
'name' => 'Footer Style2 Column3',
'id' => 'footerarea2-three',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widgettitle">',
'after_title' => '</h6>',
) );
register_sidebar( array(
'name' => 'Footer Style2 Column4',
'id' => 'footerarea2-four',
'before_widget' => '<div class="chw-widget">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widgettitle">',
'after_title' => '</h6>',
) );
}
add_action( 'widgets_init', 'mentoring_custom_header_widget' );
require_once ( get_template_directory() . '/inc/class-notifications.php'); //Theme notifications
require_once ( get_template_directory() . '/inc/sidebars.php'); //Theme sidebars
require_once ( get_template_directory() . '/directory/front-end/hooks.php');
require_once ( get_template_directory() . '/inc/functions.php'); //Theme functionalty
require_once mentoring_override_templates('/inc/class-headers.php'); //headers
require_once mentoring_override_templates('/inc/class-titlebars.php'); //Sub headers
require_once ( get_template_directory() . '/inc/constants.php'); //Constants
require_once ( get_template_directory() . '/inc/class-woocommerce.php'); //Woocommerce
require_once ( get_template_directory() . '/inc/languages.php');
require_once ( get_template_directory() . '/inc/typo.php');
require_once ( get_template_directory() . '/inc/google_fonts.php'); // goolge fonts
require_once ( get_template_directory() . '/inc/hooks.php'); //Hooks
require_once ( get_template_directory() . '/inc/template-tags.php'); //Tags
require_once ( get_template_directory() . '/directory/front-end/class-dashboard-menu.php');
require_once ( get_template_directory() . '/directory/front-end/functions.php');
require_once ( get_template_directory() . '/directory/front-end/woo-hooks.php');
require_once ( get_template_directory() . '/directory/back-end/dashboard.php');
require_once ( get_template_directory() . '/directory/back-end/functions.php');
require_once ( get_template_directory() . '/directory/front-end/ajax-hooks.php');
require_once ( get_template_directory() . '/directory/front-end/term_walkers.php'); //Term walkers
if( class_exists( 'mentoringGlobalSettings' ) ) {
require_once ( get_template_directory() . '/inc/class-pdf.php'); //Hooks
}
function mentoring_custom_styles() {
wp_register_style('mentoring_dashboardcss', get_template_directory_uri(). '/assets/css/dashboard.css');
wp_enqueue_style('mentoring_dashboardcss');
}
add_action('wp_enqueue_scripts', 'mentoring_custom_styles');
add_filter( 'woocommerce_checkout_redirect_empty_cart', '__return_false' );
add_filter( 'woocommerce_should_load_paypal_standard', '__return_true' );
function mentoring_paginationblog() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
if ( $paged >= 1 ){
echo '
<div class="col-md-12 ">
<div class="post-pagination">
<ul class="paginations">' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li class="arrow">%s</li>' . "\n", get_previous_posts_link( __( '<i class="fas fa-angle-double-left"></i></i>', 'mentoring' ) ) );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li class="arrow">%s</li>' . "\n", get_next_posts_link( __( '<i class="fas fa-angle-double-right"></i>', 'mentoring' ) ) );
echo '</ul></div></div>' . "\n";
}
}
function mentoring_core_pagination($pages = '', $range = 2)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo '<div class="col-md-12 ">
<div class="post-pagination">
<ul class="paginations">';
if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'><i class='fas fa-angle-double-left'></i></a></li>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
if ($paged == $i) {
echo '<li class="active" data-paged="' . $i . '"><a href="' . get_pagenum_link($i) . '">' . $i . ' </a></li>';
} else {
echo '<li data-paged="' . $i . '"><a href="' . get_pagenum_link($i) . '">' . $i . '</a></li>';
}
/// echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged + 1)."'><i class='fas fa-angle-double-right'></i></a></li>";
echo '</ul></div></div>';
}
}
add_action('init', 'truelysell_update_can_register');
function truelysell_update_can_register() {
update_option('users_can_register', true);
}
function mytheme_register_block_styles() {
// Example: Register a custom style for the paragraph block
register_block_style('core/paragraph', array(
'name' => 'fancy-paragraph',
'label' => __('Fancy Paragraph', 'mentoring'),
));
}
add_action('init', 'mytheme_register_block_styles');
function mytheme_register_block_patterns() {
register_block_pattern('mytheme/my-custom-pattern', array(
'title' => __('My Custom Pattern', 'mentoring'),
'description' => __('A custom block pattern.', 'mentoring'),
'content' => '<!-- wp:paragraph --><p>' . __('Hello World!', 'mentoring') . '</p><!-- /wp:paragraph -->',
));
}
add_action('init', 'mytheme_register_block_patterns');
function mytheme_setup() {
add_theme_support('wp-block-styles');
}
add_action('after_setup_theme', 'mytheme_setup');
function mytheme_custom_header_setup() {
add_theme_support('custom-header', array(
'default-image' => get_template_directory_uri() . '/images/default-header.jpg', // Path to default header image
'width' => 1200,
'height' => 300,
'flex-height' => true,
'flex-width' => true,
'uploads' => true,
));
}
add_action('after_setup_theme', 'mytheme_custom_header_setup');
add_filter( 'site_status_tests', function( $tests ) {
unset( $tests['direct']['persistent_object_cache'] );
return $tests;
});
add_filter( 'site_status_tests', function( $tests ) {
unset( $tests['async']['background_updates'] );
return $tests;
});
add_filter( 'site_status_tests', function( $tests ) {
// Remove WooCommerce Action Scheduler late cron check
if ( isset( $tests['async']['action_scheduler_queue_runner'] ) ) {
unset( $tests['async']['action_scheduler_queue_runner'] );
}
return $tests;
}, 20 );
add_action( 'wp_enqueue_scripts', function () {
wp_add_inline_style(
'elementor-frontend',
'.elementor-section.elementor-section-boxed > .elementor-container{max-width:1320px;}'
);
});
// Security codes
// Remove WordPress version number
remove_action('wp_head', 'wp_generator');
// Disable XML-RPC
add_filter('xmlrpc_enabled', '__return_false');
function add_security_headers() {
header( 'X-Frame-Options: SAMEORIGIN' );
header( 'X-Content-Type-Options: nosniff' );
header( 'X-XSS-Protection: 1; mode=block' );
header( 'Referrer-Policy: strict-origin-when-cross-origin' );
}
add_action( 'send_headers', 'add_security_headers' );
add_filter('rest_authentication_errors', function($result){
if (!is_user_logged_in()) {
return new WP_Error('rest_forbidden', 'Login required', ['status'=>401]);
}
return $result;
});