init();
return $font_library;
}
/**
* Hook for "init" wp action
*/
function tve_dash_init_action() {
tve_dash_set_dash_url();
defined( 'TVE_DASH_IMAGES_URL' ) || define( 'TVE_DASH_IMAGES_URL', TVE_DASH_URL . '/css/images' );
require_once( TVE_DASH_PATH . '/inc/font-import-manager/classes/Tve_Dash_Font_Import_Manager.php' );
require_once( TVE_DASH_PATH . '/inc/font-manager/font-manager.php' );
/**
* Load the Font Library module.
* This is a separate module from the Font Manager.
*/
tve_font_library();
/**
* Run any database migrations
*/
if ( defined( 'TVE_TESTS_RUNNING' ) || is_admin() ) {
TD_DB_Manager::collect_migration_managers();
}
}
/**
* Add main Thrive Dashboard item to menu
*/
function tve_dash_admin_menu() {
add_menu_page(
'Thrive Dashboard',
'Thrive Dashboard',
TVE_DASH_CAPABILITY,
'tve_dash_section',
'tve_dash_section',
TVE_DASH_IMAGES_URL . '/logo-icon.png'
);
if ( is_super_admin() ) {
add_submenu_page(
'',
__( 'Access Manager', 'thrive-dash' ),
__( 'Access Manager', 'thrive-dash' ),
'manage_options',
'tve_dash_access_manager',
function () {
require_once( TVE_DASH_PATH . '/inc/access-manager/includes/templates/access-manager.php' );
}
);
}
add_submenu_page(
'',
__( 'System Info', 'thrive-dash' ),
__( 'System Info', 'thrive-dash' ),
'manage_options',
'tve-debug',
function () {
tve_dash_enqueue();
require_once( TVE_DASH_PATH . '/inc/plugin-updates/debug-screen.php' );
}
);
add_submenu_page(
'',
__( 'Update Info', 'thrive-dash' ),
__( 'Update Info', 'thrive-dash' ),
'manage_options',
'tve-updates',
static function () {
require_once( TVE_DASH_PATH . '/inc/plugin-updates/update-channel.php' );
}
);
add_submenu_page(
'',
__( 'Update Info', 'thrive-dash' ),
__( 'Update Info', 'thrive-dash' ),
'manage_options',
'tve-update-switch-stable-channel',
static function () {
//Nonce check
check_admin_referer( 'tvd_switch_stable_channel_nonce' );
$defaults = array(
'page' => 'tve-update-switch-stable-channel',
'name' => '',
'current_version' => 0, //Needed only for UI
'plugin_file' => '',
'_wpnonce' => '', //Nonce key
'plugin_slug' => '',
'type' => '', //Theme OR Plugin
);
$args = wp_parse_args( $_GET, $defaults );
if ( ! empty( $args['type'] ) && ! empty( $args['tvd_channel'] ) && $args['tvd_channel'] === 'tvd_switch_to_stable_channel' && in_array( $args['type'], [
'plugin',
'theme',
] ) ) {
$name = sanitize_text_field( $args['name'] );
if ( $args['type'] === 'theme' ) {
$theme = 'thrive-theme';
require_once( TVE_DASH_PATH . '/inc/plugin-updates/classes/class-tvd-theme-upgrader.php' );
$theme_upgrader = new TVD_Theme_Upgrader( new Theme_Upgrader_Skin( array(
'title' => $name,
'nonce' => 'upgrade-plugin_' . $theme,
'url' => 'index.php?page=' . esc_url( $args['page'] ) . '&theme_file=' . $theme . 'action=upgrade-theme',
'theme' => $theme,
) ) );
$theme_upgrader->get_latest_version( $theme );
} else if ( $args['type'] === 'plugin' ) {
require_once( TVE_DASH_PATH . '/inc/plugin-updates/classes/class-tvd-plugin-upgrader.php' );
$plugin_upgrader = new TVD_Plugin_Upgrader( new Plugin_Upgrader_Skin( array(
'title' => $name,
'nonce' => 'upgrade-plugin_' . esc_html( $args['plugin_slug'] ),
'url' => 'index.php?page=' . esc_url( $args['page'] ) . '&plugin_file=' . esc_url( $args['plugin_file'] ) . 'action=upgrade-plugin',
'plugin' => esc_html( $args['plugin_slug'] ),
) ) );
$plugin_upgrader->get_latest_version( $args['plugin_file'] );
}
} else {
tve_dash_enqueue();
require_once( TVE_DASH_PATH . '/inc/plugin-updates/update-switch-stable-channel.php' );
}
}
);
/**
* @param tve_dash_section parent slug
*/
do_action( 'tve_dash_add_menu_item', 'tve_dash_section' );
$menus = array(
'license_manager' => array(
'parent_slug' => tve_dash_is_plugin_active( 'thrive-product-manager' ) ? '' : 'tve_dash_section',
'page_title' => __( 'Thrive License Manager', 'thrive-dash' ),
'menu_title' => __( 'License Manager', 'thrive-dash' ),
'capability' => 'manage_options',
'menu_slug' => 'tve_dash_license_manager_section',
'function' => 'tve_dash_license_manager_section',
),
'general_settings' => array(
'parent_slug' => '',
'page_title' => __( 'Thrive General Settings', 'thrive-dash' ),
'menu_title' => __( 'General Settings', 'thrive-dash' ),
'capability' => TVE_DASH_CAPABILITY,
'menu_slug' => 'tve_dash_general_settings_section',
'function' => 'tve_dash_general_settings_section',
),
/* Font Library Page */
'font_library' => array(
'parent_slug' => '',
'page_title' => __( 'Font Library', 'thrive-dash' ),
'menu_title' => __( 'Font Library', 'thrive-dash' ),
'capability' => 'manage_options',
'menu_slug' => Font_Library_Admin::SLUG,
'function' => [ Font_Library_Admin::class, 'get_template' ],
),
/* Font Manager Page */
'font_manager' => array(
'parent_slug' => '',
'page_title' => __( 'Thrive Font Manager', 'thrive-dash' ),
'menu_title' => __( 'Thrive Font Manager', 'thrive-dash' ),
'capability' => TVE_DASH_CAPABILITY,
'menu_slug' => 'tve_dash_font_manager',
'function' => 'tve_dash_font_manager_main_page',
),
/* Font Import Manager Page */
'font_import_manager' => array(
'parent_slug' => '',
'page_title' => __( 'Thrive Font Import Manager', 'thrive-dash' ),
'menu_title' => __( 'Thrive Font Import Manager', 'thrive-dash' ),
'capability' => TVE_DASH_CAPABILITY,
'menu_slug' => 'tve_dash_font_import_manager',
'function' => 'tve_dash_font_import_manager_main_page',
),
'icon_manager' => array(
'parent_slug' => '',
'page_title' => __( 'Icon Manager', 'thrive-dash' ),
'menu_title' => __( 'Icon Manager', 'thrive-dash' ),
'capability' => TVE_DASH_CAPABILITY,
'menu_slug' => 'tve_dash_icon_manager',
'function' => 'tve_dash_icon_manager_main_page',
),
'growth_tools' => array(
'parent_slug' => 'tve_dash_section',
'page_title' => __( 'About Us', 'thrive-dash' ),
'menu_title' => __( 'About Us', 'thrive-dash' ),
'capability' => TVE_DASH_CAPABILITY,
'menu_slug' => 'about_tve_theme_team',
'function' => 'tve_dash_growth_tools_dashboard',
),
);
$thrive_products_order = tve_dash_get_menu_products_order();
$menus = array_merge( $menus, apply_filters( 'tve_dash_admin_product_menu', array() ) );
foreach ( $thrive_products_order as $order => $menu_short ) {
if ( array_key_exists( $menu_short, $menus ) ) {
add_submenu_page( $menus[ $menu_short ]['parent_slug'] ?: '', $menus[ $menu_short ]['page_title'], $menus[ $menu_short ]['menu_title'], $menus[ $menu_short ]['capability'], $menus[ $menu_short ]['menu_slug'], $menus[ $menu_short ]['function'] );
}
}
}
/**
* Plugin Action Links
*
* Injects a stable link into plugin actions links used to switch Beta Versions of Thrive Plugins to Stable Versions
*
* @param $actions
* @param $plugin_file
* @param $plugin_data
* @param $context
*
* @return array $actions
*/
add_filter( 'plugin_action_links', static function ( $actions, $plugin_file, $plugin_data, $context ) {
if ( ! isset( $plugin_data['Version'] ) || ( function_exists( 'is_plugin_active' ) && ! is_plugin_active( $plugin_file ) ) ) {
return $actions;
}
// Multisite check.
if ( is_multisite() && ( ! is_network_admin() && ! is_main_site() ) ) {
return $actions;
}
$slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : dirname( plugin_basename( $plugin_file ) );
if ( strpos( $slug, 'thrive-' ) !== false && strpos( $plugin_data['Version'], 'beta' ) !== false && tvd_update_is_using_stable_channel() ) {
$stable_url = add_query_arg(
array(
'current_version' => urlencode( $plugin_data['Version'] ),
'name' => urlencode( $plugin_data['Name'] ),
'plugin_slug' => urlencode( $slug ),
'_wpnonce' => wp_create_nonce( 'tvd_switch_stable_channel_nonce' ),
'type' => 'plugin',
'plugin_file' => $plugin_file,
'page' => 'tve-update-switch-stable-channel',
), admin_url( 'admin.php' ) );
$actions['tvd-switch-stable-update'] = '' . __( 'Switch to stable version', 'thrive-dash' ) . '';
}
return $actions;
}, 10, 4 );
function tve_dash_icon_manager_main_page() {
$tve_icon_manager = Tve_Dash_Thrive_Icon_Manager::instance();
$tve_icon_manager->mainPage();
}
function tve_dash_growth_tools_dashboard() {
$growth_tools = Tve_Dash_Growth_Tools::instance();
$growth_tools->dashboard();
}
function tve_dash_font_import_manager_main_page() {
$font_import_manager = Tve_Dash_Font_Import_Manager::getInstance();
$font_import_manager->mainPage();
}
/**
* Checks if the current screen (current admin screen) needs to have the dashboard scripts and styles enqueued
*
* @param string $hook current admin page hook
*/
function tve_dash_needs_enqueue( $hook ) {
$accepted_hooks = array(
'toplevel_page_tve_dash_section',
'thrive-dashboard_page_tve_dash_license_manager_section',
'admin_page_tve_dash_api_connect',
'admin_page_tve_dash_api_error_log',
'admin_page_tve_dash_api_connect',
'thrive-dashboard_page_tve_dash_access_manager',
'admin_page_tve-updates',
Font_Library_Admin::SCREEN,
);
$accepted_hooks = apply_filters( 'tve_dash_include_ui', $accepted_hooks, $hook );
return in_array( $hook, $accepted_hooks );
}
function tve_dash_admin_enqueue_scripts( $hook ) {
if ( $hook === 'themes.php' && tve_dash_is_ttb_active() ) {
$thrive_theme = wp_get_theme();
if ( tvd_update_is_using_stable_channel() && strpos( $thrive_theme->get( 'Version' ), 'beta' ) !== false ) {
$stable_url = add_query_arg(
array(
'current_version' => urlencode( $thrive_theme->get( 'Version' ) ),
'name' => urlencode( $thrive_theme->get( 'Name' ) ),
'plugin_slug' => urlencode( 'thrive-theme' ),
'_wpnonce' => wp_create_nonce( 'tvd_switch_stable_channel_nonce' ),
'type' => 'theme',
'page' => 'tve-update-switch-stable-channel',
), admin_url( 'admin.php' ) );
wp_enqueue_script( 'tve-dash-theme-switch-stable', TVE_DASH_URL . '/inc/plugin-updates/js/themes-switch-stable.js', array(
'jquery',
'backbone',
'theme',
), false, true );
wp_localize_script( 'tve-dash-theme-switch-stable', 'TVD_STABLE_THEME',
array(
'name' => $thrive_theme->name,
'link_html' => 'Switch to stable version',
)
);
}
}
if ( tve_dash_needs_enqueue( $hook ) ) {
tve_dash_enqueue();
wp_enqueue_media(); //Weeded for wp object localization in JS
}
/**
* Enqueue roboto from gutenberg blocks
*/
if ( ! tve_dash_is_google_fonts_blocked() && tve_should_load_blocks() ) {
tve_dash_enqueue_style( 'tve-block-font', '//fonts.googleapis.com/css?family=Roboto:400,500,700' );
}
}
/**
* Whether we should thrive blocks
*
* @return bool
*/
function tve_should_load_blocks() {
$allow = false;
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( $screen !== null ) {
$allow = $screen->is_block_editor();
}
return $allow;
}
/**
* Dequeue conflicting scripts
*
* @param string $hook
*/
function tve_dash_admin_dequeue_conflicting( $hook ) {
if ( isset( $GLOBALS['tve_dash_resources_enqueued'] ) || tve_dash_needs_enqueue( $hook ) ) {
// NewsPaper messing about and including css / scripts all over the admin panel
wp_dequeue_style( 'select2' );
wp_deregister_style( 'select2' );
wp_dequeue_script( 'select2' );
wp_deregister_script( 'select2' );
//FS poster select2
wp_dequeue_style( 'fsp-select2' );
wp_deregister_style( 'fsp-select2' );
wp_dequeue_style( 'fsp-select2-custom' );
wp_deregister_style( 'fsp-select2-custom' );
wp_dequeue_script( 'fsp-select2' );
wp_deregister_script( 'fsp-select2' );
}
}
/**
* Additional generic data for Vue views
* Should be included only in Dashboard pages that use Vue
*
* @return void
*/
function tve_dash_enqueue_vue() {
include_once TVE_DASH_PATH . '/css/font/dashboard-icons.svg';
wp_enqueue_style( 'media' );
wp_enqueue_media();
tve_dash_enqueue_script( 'tve-dash-main-vue', TVE_DASH_URL . '/assets/dist/js/dash-vue.js', [
'lodash',
'jquery',
] );
wp_localize_script( 'tve-dash-main-vue', 'TD', [
'rest_nonce' => wp_create_nonce( 'wp_rest' ),
'dash_url' => esc_url( admin_url( 'admin.php?page=tve_dash_section' ) ),
] );
wp_enqueue_style( 'td-font', 'https://fonts.bunny.net/css?family=Roboto:200,300,400,500,600,700,800' );
/**
* SUPP-15199 remove active campaign calendar that overwrites setfullyear and breaks other things
*/
remove_filter( 'mce_external_plugins', 'activecampaign_add_buttons' );
}
function tve_dash_enqueue_licensing_assets() {
add_action( 'admin_print_footer_scripts', static function () {
tve_dash_output_backbone_templates( [ 'license-modal' => TVE_DASH_PATH . '/templates/backbone/license-modal.phtml' ] );
} );
tve_dash_enqueue_style( 'tve-dash-licensing-css', TVE_DASH_URL . '/css/licensing.css' );
tve_dash_enqueue_script( 'tve-dash-main-js', TVE_DASH_URL . '/js/dist/tve-dash' . ( tve_dash_is_debug_on() ? '.js' : '.min.js' ), array(
'jquery',
'backbone',
) );
wp_localize_script( 'tve-dash-main-js', 'TVE_Dash_Const', tve_dash_get_dash_const_options() );
}
/**
* js localized options
*/
function tve_dash_get_dash_const_options() {
$options = array(
'nonce' => wp_create_nonce( 'tve-dash' ),
'dash_url' => TVE_DASH_URL,
'actions' => array(
'backend_ajax' => 'tve_dash_backend_ajax',
'ajax_delete_api_log' => 'tve_dash_api_delete_log',
'ajax_retry_api_log' => 'tve_dash_api_form_retry',
),
'routes' => array(
'settings' => 'generalSettings',
'license' => 'license',
'active_states' => 'activeState',
'error_log' => 'getErrorLogs',
'affiliate_links' => 'affiliateLinks',
'add_aff_id' => 'saveAffiliateId',
'get_aff_id' => 'getAffiliateId',
'token' => 'token',
'save_token' => 'saveToken',
'delete_token' => 'deleteToken',
'change_capability' => 'changeCapability',
'update_user_functionality' => 'updateUserFunctionality',
'reset_capabilities_to_default' => 'resetCapabilitiesToDefault',
),
'translations' => array(
'UnknownError' => __( 'Unknown error', 'thrive-dash' ),
'Deleting' => __( 'Deleting...', 'thrive-dash' ),
'Testing' => __( 'Testing...', 'thrive-dash' ),
'Loading' => __( 'Loading...', 'thrive-dash' ),
'ConnectionWorks' => __( 'Connection works!', 'thrive-dash' ),
'ConnectionFailed' => __( 'Connection failed!', 'thrive-dash' ),
'Unlimited' => __( 'Unlimited', 'thrive-dash' ),
'CapabilityError' => __( 'You are not allowed to remove this capability!', 'thrive-dash' ),
'RequestError' => 'Request error, please contact Thrive developers !',
'Copy' => 'Copy',
'ImportedKit' => __( 'Kit successfully imported', 'thrive-dash' ),
'RemovedKit' => __( 'Kit removed', 'thrive-dash' ),
),
'products' => array(
TVE_Dash_Product_LicenseManager::ALL_TAG => 'All products',
TVE_Dash_Product_LicenseManager::TCB_TAG => 'Thrive Architect',
TVE_Dash_Product_LicenseManager::TL_TAG => 'Thrive Leads',
TVE_Dash_Product_LicenseManager::TCW_TAG => 'Thrive Clever Widgets',
),
'license_types' => array(
'individual' => __( 'Individual product', 'thrive-dash' ),
'full' => __( 'Full membership', 'thrive-dash' ),
),
'is_polylang_active' => tve_dash_is_plugin_active( 'polylang' ),
'tvd_fa_kit' => get_option( 'tvd_fa_kit', '' ),
'license_rest_url' => get_rest_url() . 'td/v1/license_warning',
);
/**
* Allow vendors to hook into this
* TVE_Dash is the output js object
*/
return apply_filters( 'tve_dash_localize', $options );
}
/**
* enqueue the dashboard CSS and javascript files
*/
function tve_dash_enqueue() {
$js_suffix = tve_dash_is_debug_on() ? '.js' : '.min.js';
tve_dash_enqueue_script( 'tve-dash-main-js', TVE_DASH_URL . '/js/dist/tve-dash' . $js_suffix, array(
'jquery',
'backbone',
) );
wp_enqueue_script( 'jquery-zclip', TVE_DASH_URL . '/js/util/jquery.zclip.1.1.1/jquery.zclip.min.js', array( 'jquery' ) );
tve_dash_enqueue_style( 'tve-dash-styles-css', TVE_DASH_URL . '/css/styles.css' );
wp_localize_script( 'tve-dash-main-js', 'TVE_Dash_Const', tve_dash_get_dash_const_options() );
tve_dash_enqueue_script( 'tvd-fa-kit', get_option( 'tvd_fa_kit', '' ) );
/**
* Localize token data
*/
$token_options = array();
$token_options['model'] = get_option( 'thrive_token_support' );
if ( ! empty( $token_options['model']['token'] ) && ! get_option( 'tve_dash_generated_token' ) ) {
/* Backwards-compat: store this option separately in the database */
update_option( 'tve_dash_generated_token', array(
'token' => $token_options['model']['token'],
'referer' => $token_options['model']['referer'],
) );
}
wp_localize_script( 'tve-dash-main-js', 'TVE_Token', $token_options );
/**
* output the main tpls for backbone views used in dashboard
*/
add_action( 'admin_print_footer_scripts', 'tve_dash_backbone_templates' );
Tve_Dash_Icon_Manager::enqueue_fontawesome_styles();
/**
* set this flag here so we can later remove conflicting scripts / styles
*/
$GLOBALS['tve_dash_resources_enqueued'] = true;
}
/**
* main entry point for the incoming ajax requests
*
* passes the request to the TVE_Dash_AjaxController for processing
*/
function tve_dash_backend_ajax() {
check_ajax_referer( 'tve-dash' );
if ( ! current_user_can( TVE_DASH_CAPABILITY ) ) {
wp_die( '' );
}
$response = TVE_Dash_AjaxController::instance()->handle();
wp_send_json( $response );
}
function tve_dash_reset_license() {
$options = array(
'tcb' => 'tve_license_status|tve_license_email|tve_license_key',
'tl' => 'tve_leads_license_status|tve_leads_license_email|tve_leads_license_key',
'tcw' => 'tcw_license_status|tcw_license_email|tcw_license_key',
'themes' => 'thrive_license_status|thrive_license_key|thrive_license_email',
'dash' => 'thrive_license',
);
if ( ! empty( $_POST['products'] ) ) {
$filtered = array_intersect_key( $options, array_map( 'sanitize_text_field', array_flip( $_POST['products'] ) ) );
foreach ( explode( '|', implode( '|', $filtered ) ) as $option ) {
delete_option( $option );
}
$message = 'Licenses reset for: ' . implode( ', ', array_keys( $filtered ) );
$dash_license = get_option( 'thrive_license', array() );
foreach ( array_map( 'sanitize_text_field', $_POST['products'] ) as $prod ) {
unset( $dash_license[ $prod ] );
}
update_option( 'thrive_license', $dash_license );
}
require dirname( dirname( ( __FILE__ ) ) ) . '/templates/settings/reset.phtml';
}
function tve_dash_load_text_domain() {
$domain = 'thrive-dash';
$locale = $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
$path = 'thrive-dashboard/languages';
//$path = apply_filters('tve_dash_filter_plugin_languages_path', $path);
load_textdomain( $domain, WP_LANG_DIR . '/thrive/' . $domain . "-" . $locale . ".mo" );
load_plugin_textdomain( $domain, false, $path );
}
/**
*
* fetches and outputs the backbone templates needed for thrive dashboard
*
* called on 'admin_print_footer_scripts'
*
*/
function tve_dash_backbone_templates() {
$templates = tve_dash_get_backbone_templates( plugin_dir_path( dirname( __FILE__ ) ) . 'templates/backbone', 'backbone' );
$templates_modal = tve_dash_get_backbone_templates( plugin_dir_path( dirname( __FILE__ ) ) . 'templates/modal', 'templates' );
tve_dash_output_backbone_templates( array_merge( $templates, $templates_modal ) );
}
/**
* Returns the disable state of the google fonts
*
* @return bool
*/
function tve_dash_is_google_fonts_blocked() {
return (bool) get_option( 'tve_google_fonts_disable_api_call', '' );
}
/**
* Returns the disable state of the google fonts
*
* @return bool
*/
function tve_dash_allow_video_src() {
return (bool) get_option( 'tve_allow_video_src', '' );
}
/**
* output script nodes for backbone templates
*
* @param array $templates
*/
function tve_dash_output_backbone_templates( $templates, $prefix = '', $suffix = '' ) {
foreach ( $templates as $tpl_id => $path ) {
$tpl_id = $prefix . $tpl_id . $suffix;
ob_start();
include $path;
$content = ob_get_clean();
echo '';
}
}
/**
* Some plugins add inline scripts thinking that this is the frontend render, which ruins the backbone html tags and breaks the HTML afterwards.
* As a fix, we replace the inner script tags with , and reverse this operation when we apply backbone templates in the editor.
*
* @param $content
*
* @return string|string[]
*/
function tve_dash_escape_script_tags( $content ) {
return str_replace( array( '