<?php
/**
* Affiliate Booster functions and definitions
*
* @link
https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package Affiliate_Booster
*/
if (!function_exists('affiliatebooster_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 affiliatebooster_setup()
{
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Affiliate Booster, use a find and replace
* to change 'affiliatebooster' to the name of your theme in all the template files.
*/
load_theme_textdomain('affiliatebooster', 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');
/*
* Gutenberg support
*/
add_theme_support( 'wp-block-styles' );
add_theme_support( 'align-wide' );
add_theme_support( 'responsive-embeds' );
add_theme_support('editor-styles');
add_editor_style( 'css/dist/editor-style.min.css' );
/**
* Add Theme support Title
*/
//add_theme_support( 'title-tag' );
// This theme uses wp_nav_menu() in one location.
// register_nav_menus(
// array(
// 'menu-1' => esc_html__( 'Primary', 'affiliatebooster' ),
// 'header-menu' => __( 'Header Menu', 'affiliatebooster'),
// 'extra-menu' => __( 'Extra Menu', 'affiliatebooster' )
// )
// );
/*
* 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(
'affiliatebooster_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,
// )
// );
}
endif;
add_action('after_setup_theme', 'affiliatebooster_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 affiliatebooster_content_width()
{
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters('affiliatebooster_content_width', 640);
}
add_action('after_setup_theme', 'affiliatebooster_content_width', 0);
/**
* Register widget area.
*
* @link
https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
// function affiliatebooster_widgets_init()
// {
// register_sidebar(
// array(
// 'name' => esc_html__('Sidebar', 'affiliatebooster'),
// 'id' => 'sidebar-1',
// 'description' => esc_html__('Add widgets here.', 'affiliatebooster'),
// 'before_widget' => '<section id="%1$s" class="widget %2$s">',
// 'after_widget' => '</section>',
// 'before_title' => '<h2 class="widget-title">',
// 'after_title' => '</h2>',
// )
// );
// }
//add_action('widgets_init', 'affiliatebooster_widgets_init');
/**
* Enqueue scripts and styles.
*/
function affiliatebooster_scripts()
{
wp_enqueue_style('affiliatebooster-style', get_stylesheet_uri(), array(), THEME_VERSION);
wp_style_add_data('affiliatebooster-style', 'rtl', 'replace');
//wp_enqueue_script( 'affiliatebooster-navigation', get_template_directory_uri() . '/js/navigation.js', array(), THEME_VERSION, true );
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'affiliatebooster_scripts');
/**
* Implement the Custom Header feature.
*/
//require get_template_directory() . '/inc/custom-header.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';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
if (defined('JETPACK__VERSION')) {
require get_template_directory() . '/inc/jetpack.php';
}
//----------------------NEW-------------------------------//
function my_theme_enqueue_styles()
{
//wp_enqueue_style('responsive', get_template_directory_uri() . '/css/dist/responsive.min.css');
wp_enqueue_style('responsive', get_template_directory_uri() . '/css/responsive.css');
wp_enqueue_style('bootstrap', get_template_directory_uri() . '/libs/bootstrap-4.5.0-dist/css/bootstrap.min.css');
//wp_enqueue_style('font-awesome', get_template_directory_uri() . '/libs/fontawesome-5.13.0-dist/css/all.min.css');
wp_enqueue_style('font-awesome', '
https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
//wp_enqueue_script('aff-custom-script', get_stylesheet_directory_uri() . '/js/dist/main.min.js', array('jquery'));
wp_enqueue_script('aff-custom-script', get_template_directory_uri() . '/js/main.js', array('jquery'));
}
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles');
add_image_size('aff-booster-recent-thumbnails', 55, 55, true);
add_theme_support('post-thumbnails');
function wpdocs_custom_excerpt_length($length)
{
return 30;
}
add_filter('excerpt_length', 'wpdocs_custom_excerpt_length', 999);
function load_custom_wp_admin_style()
{
//wp_register_style('custom_wp_admin_css', get_stylesheet_directory_uri() . '/css/dist/admin-style.min.css', false, '1.0.0');
wp_register_style('custom_wp_admin_css', get_template_directory_uri() . '/css/dist/admin-style.min.css', false, '1.0.0');
wp_enqueue_style('custom_wp_admin_css');
}
add_action('admin_enqueue_scripts', 'load_custom_wp_admin_style');
/**
* Metabox in posts additions.
*/
include(get_template_directory() . '/elements/aff_booster_elements_metabox.php');
include(get_template_directory() . '/elements/aff_boostre_embed_metabox.php');
/**
* Author Extra.
*/
require get_template_directory() . '/inc/author-extra.php';
/**
* Widgets.
*/
require get_template_directory() . '/inc/widgets.php';
require get_template_directory() . '/inc/widgets-area.php';
/**
* Markups.
*/
require get_template_directory() . '/inc/markup.php';
/**
* Options.
*/
require get_template_directory() . '/inc/options.php';
/**
* Kirki Customizer.
*/
include_once get_theme_file_path('inc/class-kirki-installer-section.php');
require get_template_directory() . '/inc/customizer-kirki.php';
/**
* Custom get_the_excerpt.
*/
function the_excerpt_max_charlength( $charlength ){
$excerpt = get_the_excerpt();
$charlength++;
if ( mb_strlen( $excerpt ) > $charlength ) {
$subex = mb_substr( $excerpt, 0, $charlength - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {
echo mb_substr( $subex, 0, $excut );
} else {
echo $subex;
}
echo '[...]';
} else {
echo $excerpt;
}
}
/**
* Theme License.
*/
$test_license = '';
$license_data = '';
define('DT_KEY', 'affiliate_booster_theme_license_key_status');
define('EDD_THM_SL_STORE_URL', '
https://www.affiliatebooster.com/'); /* IMPORTANT: Do not modify this line of code, the theme could stop working correctly */
define('EDD_SL_THEME_NAME', 'affiliatebooster'); /* IMPORTANT: Do not modify this line of code, the theme could stop working correctly */
define('EDD_SL_THEME_ITEM_ID', 17);
$theme = wp_get_theme();
if (!defined('THEME_VERSION')) {
// Replace the version number of the theme on each release.
// define( 'THEME_VERSION', '1.0.0' );
define('THEME_VERSION', $theme->Version);
}
if (!class_exists('AFFILIATE_BOOSTER_SL_Theme_Updater')) {
//include(dirname(__FILE__) . '/affiliate_boobster_sl_theme_updater.php');
}
function affiliate_booster_sl_theme_updater()
{
$theme = wp_get_theme();
$version = $theme->Version;
$test_license = trim(get_option('affiliate_booster_theme_license_key'));
//fix error
$edd_updater = new AFFILIATE_BOOSTER_SL_Theme_Updater(array(
'remote_api_url' => EDD_THM_SL_STORE_URL,
'version' => $version, /* IMPORTANT: Do not modify this line of code, the theme could stop working correctly */
'license' => $test_license,
'item_id' => EDD_SL_THEME_ITEM_ID,
'author' => ''
)); /* IMPORTANT: Do not modify this line of code, the theme could stop working correctly */
}
//add_action('admin_init', 'affiliate_booster_sl_theme_updater');
add_action('admin_menu', 'add_affiliate_booster_license_menu');
function add_affiliate_booster_license_menu()
{
add_theme_page('Theme License', 'Theme License', 'manage_options', 'affiliatebooster', 'affiliate_booster_theme_license_page');
}
include(dirname(__FILE__) . '/license/license.php');
function affiliate_booster_theme_license_page()
{
$license = get_option('affiliate_booster_theme_license_key');
$status = get_option('affiliate_booster_theme_license_key_status');
?>
<div id="acera-content" class="wrap affiliate-activation-wrapper tab-content" style="display: block;">
<h2><?php _e('Affiliate Booster Theme License Key', 'affiliatebooster'); ?></h2>
<h4><?php _e('How to Activate License Key.','affiliatebooster')?></h4>
<ul>
<li><?php _e('Step:1 Enter your license key.','affiliatebooster')?></li>
<li><?php _e('Step:2 Click on save changes button.','affiliatebooster')?></li>
<li><?php _e('Step:3 Click on Activate license button.','affiliatebooster')?></li>
</ul>
<form method="post" action="options.php">
<?php settings_fields('affiliate_booster_theme_license'); ?>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row" valign="top">
<?php _e('License Key', 'affiliatebooster'); ?>
</th>
<td>
<input id="affiliate_booster_theme_license_key" name="affiliate_booster_theme_license_key" type="text" class="regular-text mundotxt" value="<?php echo esc_attr($license); ?>" />
<label class="description" for="affbooster_plugin_license_key">
<?php if($license !== '' ){ if( $status !== false && $status == 'valid') { ?>
<span style="color:green;"><?php _e('Active'); ?></span>
<?php wp_nonce_field( 'affiliate_booster_themes_nonce', 'affiliate_booster_themes_nonce' ); ?>
<?php } else {
wp_nonce_field( 'affiliate_booster_themes_nonce', 'affiliate_booster_themes_nonce' ); ?>
<span class="error-message"><?php _e('Inactive','affiliatebooster'); ?></span>
<?php } } ?>
</label>
</td>
</tr>
<?php if (false !== $license) { ?>
<tr valign="top">
<th scope="row" valign="top"><?php _e('License Status', 'affiliatebooster'); ?></th>
<td>
<?php if ($status !== false && $status == 'valid') { ?>
<i class="cmsxx"><?php echo get_site_url(); ?></i>
<?php wp_nonce_field('affiliate_booster_themes_nonce', 'affiliate_booster_themes_nonce'); ?>
<input type="submit" class="button-secondary mundobt" name="affiliate_booster_theme_license_deactivate" value="<?php _e('Deactivate License', 'affiliatebooster'); ?>" />
<?php } else {
wp_nonce_field('affiliate_booster_themes_nonce', 'affiliate_booster_themes_nonce'); ?>
<i class="cmsxx"><?php echo get_site_url(); ?></i>
<input type="submit" class="button-secondary mundobt" name="affiliate_booster_theme_license_activate" value="<?php _e('Activate License', 'affiliatebooster'); ?>" />
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
function affiliate_booster_theme_register_option()
{
register_setting('affiliate_booster_theme_license', 'affiliate_booster_theme_license_key', 'affiliate_booster_theme_sanitize_license');
}
add_action('admin_init', 'affiliate_booster_theme_register_option');
function affiliate_booster_theme_sanitize_license($new)
{
$old = get_option('affiliate_booster_theme_license_key');
if ($old && $old != $new) {
delete_option('affiliate_booster_theme_license_key_status');
}
return $new;
}
// Activate license key
function affiliate_booster_theme_activate_license()
{
if (isset($_POST['affiliate_booster_theme_license_activate'])) {
if (!check_admin_referer('affiliate_booster_themes_nonce', 'affiliate_booster_themes_nonce'))
return;
global $wp_version;
update_option('affiliate_booster_theme_license_key_status', 'valid');
$message = '';
$base_url = admin_url( 'themes.php?page=affiliatebooster' );
$redirect = add_query_arg( array( 'theme_sl_activation' => 'true', 'message' => urlencode( $message ) ), $base_url );
wp_redirect( $redirect );
exit();
}
}
add_action('admin_init', 'affiliate_booster_theme_activate_license');
// deactivate current license
function affiliate_booster_theme_deactivate_license()
{
if (isset($_POST['affiliate_booster_theme_license_deactivate'])) {
if (!check_admin_referer('affiliate_booster_themes_nonce', 'affiliate_booster_themes_nonce'))
return;
$license = trim(get_option('affiliate_booster_theme_license_key'));
$api_params = array(
'edd_action' => 'deactivate_license',
'license' => $license,
'item_id' => urlencode(EDD_SL_THEME_ITEM_ID)
);
$response = wp_remote_get(add_query_arg($api_params, EDD_THM_SL_STORE_URL), array('timeout' => 15, 'sslverify' => false));
if (is_wp_error($response)){ return false; }
$license_data = json_decode(wp_remote_retrieve_body($response));
if ($license_data->license == 'deactivated')
delete_option('affiliate_booster_theme_license_key_status');
$message = '';
$base_url = admin_url( 'themes.php?page=affiliatebooster' );
$redirect = add_query_arg( array( 'theme_sl_activation' => 'false', 'message' => urlencode( $message ) ), $base_url );
wp_redirect( $redirect );
exit();
}
}
//add_action('admin_init', 'affiliate_booster_theme_deactivate_license');
// Check the license key
function affiliate_booster_theme_check_license()
{
global $wp_version;
return true;
}
/**
* This is a means of catching errors from the activation method above and displaying it to the customer
*/
function affiliate_booster_theme_notices() {
if ( isset( $_GET['theme_sl_activation'] ) && ! empty( $_GET['message'] ) ) {
switch( $_GET['theme_sl_activation'] ) {
case 'false':
$message = urldecode( $_GET['message'] );
?>
<div class="notice is-dismissible notice-error">
<p><?php echo $message; ?></p>
</div>
<?php
break;
case 'true':
$message = sprintf(__('Item Activated Successfully','affiliatebooster'));
?>
<div class="notice is-dismissible notice-success">
<p><?php echo $message; ?></p>
</div>
<?php
default:
// Developers can put a custom success message here for when activation is successful if they way.
break;
}
}
}
add_action( 'admin_notices', 'affiliate_booster_theme_notices' );