????
| Current Path : /home2/morganrand/www/wp-content-bkp/themes/wanderfuls/framework/addons/ |
| Current File : /home2/morganrand/www/wp-content-bkp/themes/wanderfuls/framework/addons/footer-builder.php |
<?php
/**
* Footer Builder Addon
*
* @package Wanderfuls WordPress theme
* @subpackage Framework
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Start Class
class TB_Footer_Builder {
/**
* Start things up
*
* @since 2.0.0
*/
public function __construct() {
// Define footer ID
$this->footer_builder_id = tb_get_mod( 'footer_builder_page_id' );
// Add admin page
add_action( 'admin_menu', array( $this, 'add_page' ), 20 );
// Register admin options
add_action( 'admin_init', array( $this, 'register_page_options' ) );
// Run actions and filters if footer_builder ID is defined
if ( $this->footer_builder_id ) {
// Alter the footer on init
add_action( 'init', array( $this, 'alter_footer' ) );
// Remove all actions from wp_head on footer builder page
add_action( 'wp_head', array( $this, 'remove_actions' ) );
// Make sure custom VC CSS for this page is added on all pages
add_action( 'tb_head_css', array( $this, 'vc_css' ) );
// Remove sidebar on footer builder page
add_filter( 'tb_post_layout_class', array( $this, 'remove_sidebar_on_footer_builder' ) );
// Remove footer customizer settings
add_filter( 'tb_customizer_panels', array( $this, 'remove_customizer_footer_panel' ) );
}
}
/**
* Add sub menu page
*
* @since 2.0.0
*/
public function add_page() {
$admin_page = add_submenu_page(
TB_THEME_PANEL_SLUG,
__( 'Footer Builder', 'tb' ),
__( 'Footer Builder', 'tb' ),
'administrator',
TB_THEME_PANEL_SLUG .'-footer-builder',
array( $this, 'create_admin_page' )
);
// Adds my_help_tab when admin_page loads
global $tb_admin_help_tabs;
if ( $tb_admin_help_tabs ) {
add_action( 'load-'. $admin_page, array( $this, 'help_tab' ) );
}
}
/**
* Adds help tab to this admin page
*
* @since 2.0.0
*/
public static function help_tab() {
// Get current screen
$screen = get_current_screen();
// Define content
$content = '<p><h3>'. __( 'Documentation', 'tb' ) .'</h3><ul>';
$content .= '<li><a href="http://tbplorer-themes.com/total/docs/footer-builder/" target="_blank">http://tbplorer-themes.com/total/docs/footer-builder/</a></li>';
$content .= '</ul></p>';
// Add tb_footer_builder help tab if current screen is My Admin Page
$screen->add_help_tab( array(
'id' => 'tb_footer_builder',
'title' => __( 'Documentation', 'tb' ),
'content' => $content,
) );
}
/**
* Function that will register admin page options
*
* @since 2.0.0
*/
public function register_page_options() {
// Register settings
register_setting( 'tb_footer_builder', 'footer_builder', array( $this, 'sanitize' ) );
// Add main section to our options page
add_settings_section( 'tb_footer_builder_main', false, array( $this, 'section_main_callback' ), 'tb-footer-builder-admin' );
// Custom Page ID
add_settings_field(
'footer_builder_page_id',
__( 'Footer Builder page', 'tb' ),
array( $this, 'content_id_field_callback' ),
'tb-footer-builder-admin',
'tb_footer_builder_main'
);
}
/**
* Sanitization callback
*
* @since 2.0.0
*/
public static function sanitize( $options ) {
// Set theme mods
if ( isset( $options['content_id'] ) ) {
set_theme_mod( 'footer_builder_page_id', $options['content_id'] );
}
// Set options to nothing since we are storing in the theme mods
$options = '';
return $options;
}
/**
* Main Settings section callback
*
* @since 2.0.0
*/
public static function section_main_callback( $options ) {
// Leave blank
}
/**
* Fields callback functions
*
* @since 2.0.0
*/
// Footer Builder Page ID
public static function content_id_field_callback() { ?>
<?php
// Get footer builder page ID
$page_id = tb_get_mod( 'footer_builder_page_id' ); ?>
<?php
// Display dropdown of pages
wp_dropdown_pages( array(
'echo' => true,
'selected' => $page_id,
'name' => 'footer_builder[content_id]',
'show_option_none' => __( 'None - Display Widgetized Footer', 'tb' ),
) ); ?>
<br />
<p class="description"><?php _e( 'Select your custom page for your footer layout.', 'tb' ) ?></p>
<?php
// If page_id is defined display edit and preview links
if ( $page_id ) { ?>
<br />
<a href="<?php echo admin_url( 'post.php?post='. $page_id .'&action=edit' ); ?>" class="button" target="_blank">
<?php _e( 'Backend Edit', 'tb' ); ?>
</a>
<?php if ( TB_VC_ACTIVE ) { ?>
<a href="<?php echo admin_url( 'post.php?vc_action=vc_inline&post_id='. $page_id .'&post_type=page' ); ?>" class="button" target="_blank">
<?php _e( 'Frontend Edit', 'tb' ); ?>
</a>
<?php } ?>
<a href="<?php echo get_permalink( $page_id ); ?>" class="button" target="_blank">
<?php _e( 'Preview', 'tb' ); ?>
</a>
<?php } ?>
<?php }
/**
* Settings page output
*
* @since 2.0.0
*/
public static function create_admin_page() { ?>
<div class="wrap">
<h2><?php _e( 'Footer Builder', 'tb' ); ?></h2>
<p>
<?php echo _x( 'By default the footer consists of a simple widgetized area. For more complex layouts you can use the option below to select a page which will hold the content and layout for your site footer. Selecting a custom footer will remove all footer functions (footer widgets and footer customizer options) so you can create an entire footer using the Visual Composer and not load that extra functions.', 'Footer Builder Description', 'tb' ); ?>
</p>
<form method="post" action="options.php">
<?php settings_fields( 'tb_footer_builder' ); ?>
<?php do_settings_sections( 'tb-footer-builder-admin' ); ?>
<?php submit_button(); ?>
</form>
</div><!-- .wrap -->
<?php }
/**
* Remove the footer and add custom footer if enabled
*
* @since 2.0.0
*/
public function alter_footer() {
// Remove theme footer
remove_action( 'tb_hook_wrap_bottom', 'tb_footer', 10 );
// Remove all actions in footer hooks
$hooks = tb_theme_hooks();
if ( isset( $hooks['footer']['hooks'] ) ) {
foreach( $hooks['footer']['hooks'] as $hook ) {
remove_all_actions( $hook, false );
}
}
// Add builder footer
add_action( 'tb_hook_wrap_bottom', array( $this, 'get_part' ), 10 );
// Remove widgets
unregister_sidebar( 'footer_one' );
unregister_sidebar( 'footer_two' );
unregister_sidebar( 'footer_three' );
unregister_sidebar( 'footer_four' );
}
/**
* Load VC CSS
*
* @since 2.0.0
*/
public function vc_css( $css ) {
if ( $vc_css = get_post_meta( $this->footer_builder_id, '_wpb_shortcodes_custom_css', true ) ) {
$css .='/*FOOTER BUILDER CSS*/'. $vc_css;
}
return $css;
}
/**
* Remove all theme actions
*
* @since 2.0.0
*/
public function remove_actions() {
if ( is_page( $this->footer_builder_id ) ) {
tb_remove_actions();
}
}
/**
* Remove the footer and add custom footer if enabled
*
* @since 2.0.0
*/
public static function remove_customizer_footer_panel( $panels ) {
unset( $panels['footer_widgets'] );
unset( $panels['footer_bottom'] );
return $panels;
}
/**
* Make Footer builder page full-width (no sidebar)
*
* @since 2.0.0
*/
public function remove_sidebar_on_footer_builder( $class ) {
// Set the footer builder to "full-width" by default
if ( is_page( $this->footer_builder_id ) ) {
$class = 'full-width';
}
// Return correct class
return $class;
}
/**
* Gets the footer builder template part if the footer is enabled
*
* @since 2.0.0
*/
public static function get_part() {
if ( tb_global_obj( 'has_footer' ) ) {
get_template_part( 'partials/footer/footer-builder' );
}
}
}
$tb_footer_builder = new TB_Footer_Builder();