File: /home/dfwparty/bizcoach.biz/wp-content/themes/mh-magazine/functions.php
<?php
if ( !function_exists( 'mh_freemius' ) ) {
// Create a helper function for easy SDK access.
function mh_freemius() {
global $mh_freemius;
if ( !isset( $mh_freemius ) ) {
// Include Freemius SDK.
require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
$mh_freemius = fs_dynamic_init( array(
'id' => '14600',
'slug' => 'mh-magazine-lite',
'premium_slug' => 'mh-magazine',
'type' => 'theme',
'public_key' => 'pk_626dc4f6d1acf0ab77f73de2c413e',
'is_premium' => true,
'has_addons' => false,
'has_paid_plans' => true,
'has_affiliation' => 'selected',
'menu' => array(
'slug' => 'mh-magazine',
'contact' => false,
'affiliation' => false,
'support' => false,
'pricing' => false,
'parent' => array(
'slug' => 'themes.php',
),
),
'is_live' => true,
) );
}
return $mh_freemius;
}
// Init Freemius.
mh_freemius();
// Signal that SDK was initiated.
do_action( 'mh_freemius_loaded' );
// Override Freemius i18n strings.
add_action( 'after_setup_theme', function () {
mh_freemius()->override_i18n( [
'account' => __( 'License', 'mh-magazine' ),
'affiliation' => __( 'Affiliate Program', 'mh-magazine' ),
] );
} );
/**
* Returning URL to License Activation.
*
* @return string|null
*/
function mh_fs_settings_url() {
return admin_url( 'themes.php?page=mh-magazine&tab=license' );
}
/**
* Returning Path to the Icon for License Activation screen.
*
* @return string
*/
function mh_fs_icon_url() {
return dirname( __FILE__ ) . '/includes/core/assets/images/freemius-theme-icon.png';
}
mh_freemius()->add_filter( 'connect_url', 'mh_fs_settings_url' );
mh_freemius()->add_filter( 'after_skip_url', 'mh_fs_settings_url' );
mh_freemius()->add_filter( 'after_connect_url', 'mh_fs_settings_url' );
mh_freemius()->add_filter( 'after_pending_connect_url', 'mh_fs_settings_url' );
mh_freemius()->add_filter( 'plugin_icon', 'mh_fs_icon_url' );
}
/**
* Migrate EDD license key to freemius.
*
* @since 2.2.0
*/
function mh_edd_to_fs_license_key_migration() {
// Migration already run.
if ( !empty( get_option( 'mh_edd_license_key_migration_completed' ) ) ) {
return;
}
$license_key = trim( get_option( sanitize_key( get_template() ) . '_license_key' ) );
// No license key to migrate.
if ( empty( $license_key ) ) {
return;
}
// Get the first 32 characters.
$license_key = substr( $license_key, 0, 32 );
try {
$next_page = mh_freemius()->activate_migrated_license( $license_key );
} catch ( Exception $e ) {
update_option( 'mh_edd_license_key_migration_completed', 'unexpected_error' );
return;
}
if ( mh_freemius()->can_use_premium_code() ) {
update_option( 'mh_edd_license_key_migration_completed', 'done' );
if ( is_string( $next_page ) ) {
fs_redirect( $next_page );
} elseif ( is_array( $next_page ) && $next_page['next_page'] ) {
wp_safe_redirect( $next_page['next_page'] );
exit;
}
} else {
update_option( 'mh_edd_license_key_migration_completed', 'failed' );
}
}
add_action( 'admin_init', 'mh_edd_to_fs_license_key_migration', 20 );
// Include Core Theme Files
include get_template_directory() . '/includes/core/core.php';
// Include Premium Theme Files
if ( is_dir( get_template_directory() . '/includes/premium' ) ) {
// Include Premium Theme Files
include get_template_directory() . '/includes/premium/premium.php';
}
// Include Backwards Compatibility Functions (after core functions are loaded)
include get_template_directory() . '/includes/core/globals/backwards-compatibility.php';
$mh_core_customizer = new MH_Core_Customizer();
/***** Fetch Theme Data & Options *****/
$mh_data = wp_get_theme( 'mh-magazine' );
$mh_version = $mh_data['Version'];
$mh_options = get_option( 'mh_magazine_options' );
/***** Custom Hooks *****/
function mh_html_class() {
do_action( 'mh_html_class' );
}
function mh_before_header() {
do_action( 'mh_before_header' );
}
function mh_after_header() {
do_action( 'mh_after_header' );
}
function mh_before_page_content() {
do_action( 'mh_before_page_content' );
}
function mh_after_page_content() {
do_action( 'mh_after_page_content' );
}
function mh_before_post_content() {
do_action( 'mh_before_post_content' );
}
function mh_after_post_content() {
do_action( 'mh_after_post_content' );
}
function mh_post_header() {
do_action( 'mh_post_header' );
}
function mh_post_content_top() {
do_action( 'mh_post_content_top' );
}
function mh_post_content_bottom() {
do_action( 'mh_post_content_bottom' );
}
function mh_loop_content() {
do_action( 'mh_loop_content' );
}
function mh_cat_header() {
do_action( 'mh_cat_header' );
}
function mh_before_footer() {
do_action( 'mh_before_footer' );
}
function mh_after_footer() {
do_action( 'mh_after_footer' );
}
function mh_before_container_close() {
do_action( 'mh_before_container_close' );
}
/***** Theme Setup *****/
if ( !function_exists( 'mh_theme_setup' ) ) {
function mh_theme_setup() {
load_theme_textdomain( 'mh-magazine', get_template_directory() . '/languages' );
add_filter( 'use_default_gallery_style', '__return_false' );
add_theme_support( 'title-tag' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'html5', array(
'comment-list',
'comment-form',
'search-form',
'gallery',
'caption'
) );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'post-formats', array(
'image',
'video',
'gallery',
'audio'
) );
add_theme_support( 'custom-background', array(
'default-color' => 'f7f7f7',
) );
add_theme_support( 'custom-header', array(
'default-image' => '',
'default-text-color' => '000',
'width' => 1080,
'height' => 250,
'flex-width' => true,
'flex-height' => true,
) );
add_theme_support( 'custom-logo', array(
'width' => 300,
'height' => 100,
'flex-width' => true,
'flex-height' => true,
) );
add_theme_support( 'customize-selective-refresh-widgets' );
}
}
add_action( 'after_setup_theme', 'mh_theme_setup' );
/***** Add Custom Menus *****/
if ( !function_exists( 'mh_custom_menus' ) ) {
function mh_custom_menus() {
register_nav_menus( array(
'mh_header_nav' => esc_html__( 'Header Navigation', 'mh-magazine' ),
'mh_social_nav' => esc_html__( 'Social Icons in Header', 'mh-magazine' ),
'mh_main_nav' => esc_html__( 'Main Navigation', 'mh-magazine' ),
'mh_extra_nav' => esc_html__( 'Additional Navigation (below Main Navigation)', 'mh-magazine' ),
'mh_footer_nav' => esc_html__( 'Footer Navigation', 'mh-magazine' ),
'mh_social_widget' => esc_html__( 'MH Social Widget', 'mh-magazine' ),
) );
}
}
add_action( 'after_setup_theme', 'mh_custom_menus' );
/***** Add Custom Image Sizes *****/
if ( !function_exists( 'mh_image_sizes' ) ) {
function mh_image_sizes() {
add_image_size(
'mh-magazine-slider',
1030,
438,
true
);
add_image_size(
'mh-magazine-content',
678,
381,
true
);
add_image_size(
'mh-magazine-large',
678,
509,
true
);
add_image_size(
'mh-magazine-medium',
326,
245,
true
);
add_image_size(
'mh-magazine-small',
80,
60,
true
);
}
}
add_action( 'after_setup_theme', 'mh_image_sizes' );
/***** Set Content Width *****/
if ( !function_exists( 'mh_content_width' ) ) {
function mh_content_width() {
global $content_width;
$mh_core_customizer = new MH_Core_Customizer();
$mh_options = $mh_core_customizer->mh_theme_options();
if ( !isset( $content_width ) ) {
if ( $mh_options['sidebars'] == 'no' ) {
$content_width = 1030;
} elseif ( is_page_template( 'template-full.php' ) ) {
if ( $mh_options['sidebars'] == 'two' ) {
$content_width = 1381;
} else {
$content_width = 1030;
}
} else {
$content_width = 678;
}
}
}
}
add_action( 'template_redirect', 'mh_content_width' );
/***** Load CSS & JavaScript *****/
if ( !function_exists( 'mh_scripts' ) ) {
function mh_scripts() {
global $mh_version;
$minified = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' );
wp_enqueue_style(
'mh-font-awesome',
get_template_directory_uri() . '/includes/core/assets/css/font-awesome' . $minified . '.css',
array(),
null
);
wp_enqueue_style(
'mh-magazine',
get_stylesheet_uri(),
false,
$mh_version
);
wp_enqueue_script(
'mh-scripts',
get_template_directory_uri() . '/includes/core/assets/js/scripts.js',
array('jquery'),
$mh_version
);
wp_localize_script( 'mh-scripts', 'mh', [
'text' => [
'toggle_menu' => __( 'Toggle Menu', 'mh-magazine' ),
],
] );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) == 1 ) {
wp_enqueue_script( 'comment-reply' );
}
}
}
add_action( 'wp_enqueue_scripts', 'mh_scripts' );
/***** Temporary solution to switch to default widgets *****/
add_filter( 'use_widgets_block_editor', '__return_false', 0 );
// Disables the block editor from managing widgets in the Gutenberg plugin.
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false', 0 );
if ( mh_freemius()->is__premium_only() ) {
if ( !function_exists( 'mh_add_appearance_submenu' ) ) {
/**
* Adds a submenu page under Appearance in the WordPress admin menu.
*/
function mh_add_appearance_submenu() {
// Check if the theme is activated with Freemius
$freemius = mh_freemius();
$is_activated = $freemius->is_paying();
if ( !$is_activated ) {
add_theme_page(
__( 'Activate License', 'mh-magazine' ),
// Page title
'<span class="dashicons dashicons-admin-network"></span> ' . __( 'Activate License', 'mh-magazine' ),
// Menu title with icon
'edit_theme_options',
// Capability required to access the page
'mh-magazine-license',
// Menu slug
'mh_redirect_to_license_page'
);
// Add custom styles for the license menu item
add_action( 'admin_footer', function () {
echo '
<style>
#adminmenu .wp-submenu a[href*="mh-magazine-license"] {
background-color: red !important;
color: white !important;
}
#adminmenu .wp-submenu a[href*="mh-magazine-license"] .dashicons {
vertical-align: middle;
margin-right: 5px;
}
#adminmenu .wp-submenu li.current a[href*="mh-magazine-license"] {
background-color: red !important;
color: white !important;
}
</style>';
} );
// Add JavaScript for redirection
add_action( 'admin_footer', function () {
echo '
<script type="text/javascript">
document.querySelectorAll("#adminmenu .wp-submenu a[href*=\\"mh-magazine-license\\"]").forEach(function(element) {
element.addEventListener("click", function(event) {
event.preventDefault();
window.location.href = "' . admin_url( 'themes.php?page=mh-magazine&tab=license' ) . '";
});
});
</script>';
} );
}
}
/**
* Redirects to the license page.
*/
function mh_redirect_to_license_page() {
wp_redirect( admin_url( 'themes.php?page=mh-magazine&tab=license' ) );
exit;
}
add_action( 'admin_menu', 'mh_add_appearance_submenu' );
}
}