%PDF- %PDF-
Direktori : /var/www/html/shaban/laviva/wp-content/themes/levelup/inc/ |
Current File : /var/www/html/shaban/laviva/wp-content/themes/levelup/inc/sidebar-generator.php |
<?php // File Security Check if ( ! defined( 'ABSPATH' ) ) { exit; } class LevelupSidebarGenerator { private $sidebar_names = array(); private $footer_sidebar_count = 0; private $footer_sidebar_names = array(); public function __construct() { $this->footer_sidebar_names = array( 'footer-1' => esc_html__('Footer Area 1', 'LEVELUP'), 'footer-2' => esc_html__('Footer Area 2', 'LEVELUP'), 'footer-3' => esc_html__('Footer Area 3', 'LEVELUP'), 'footer-4' => esc_html__('Footer Area 4', 'LEVELUP'), 'footer-5' => esc_html__('Footer Area 5', 'LEVELUP'), 'footer-6' => esc_html__('Footer Area 6', 'LEVELUP'), ); } public function register_sidebar(){ register_sidebar( array( 'name' => esc_html__( 'Blog Sidebar', 'LEVELUP' ), 'id' => 'sidebar-1', 'description' => '', 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>', ) ); register_sidebar( array( 'name' => esc_html__( 'Menu Widget', 'LEVELUP' ), 'id' => 'menu-1', 'description' => '', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<p class="title">', 'after_title' => '</p>', ) ); /*register_sidebar( array( 'name' => esc_html__( 'Footer Copyright Area', 'LEVELUP' ), 'id' => 'footer-copyright', 'description' => '', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<p class="title">', 'after_title' => '</p>', ) );*/ register_sidebar(array( 'name' => esc_html__( 'Woocommerce', 'LEVELUP' ), 'id' => 'birdy-woocommerce', 'before_widget' => '<div id="%1$s" class="woocommerce-sidebar %2$s">', 'after_widget' => '<div class="clear;"></div></div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>', )); register_sidebar(array( 'name' => esc_html__( 'Bottom Widget', 'LEVELUP' ), 'id' => 'pre-footer', 'before_widget' => '<div id="%1$s" class="widget pre-footer-sidebar %2$s">', 'after_widget' => '<div class="clear"></div></div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>', )); foreach ($this->sidebar_names as $name){ register_sidebar(array( 'name' => $name, 'description' => $name, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title">', 'after_title' => '</div>', )); } foreach ($this->footer_sidebar_names as $id => $name){ register_sidebar(array( 'id' => $id, 'name' => $name, 'description' => $name, 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title">', 'after_title' => '</div>', )); } } public function get_sidebar($post_id){ if (is_page() || is_home()) { $sidebar = $this->sidebar_names['page']; } if (is_search()) { $sidebar = $this->sidebar_names["search"]; } if (is_404()) { $sidebar = $this->sidebar_names["404"]; } if (is_archive()) { $sidebar = $this->sidebar_names["archive"]; } if (is_singular('post')) { $sidebar = $this->sidebar_names['single_post']; } if (is_singular('portfolio')) { $sidebar = $this->sidebar_names['single_portfolio']; } if (is_singular('news')) { $sidebar = $this->sidebar_names['single_news']; } if (is_archive()) { $sidebar = $this->sidebar_names["archive"]; } if (function_exists('is_woocommerce') && is_woocommerce() && is_archive()) { $sidebar = $this->sidebar_names["woocommerce"]; } if (function_exists('is_woocommerce') && is_woocommerce() && is_single()) { $sidebar = $this->sidebar_names["woocommerce_single"]; } if (function_exists('is_bbpress') && is_bbpress()) { $sidebar = $this->sidebar_names['page']; } if (!empty($post_id)) { $custom = get_post_meta($post_id, '_sidebar', true); if (!empty($custom)) { $sidebar = $custom; } } if (isset($sidebar)) { dynamic_sidebar($sidebar); } } public function get_footer_sidebar(){ global $post; $footer_id = $this->footer_sidebar_count + 1; if (is_singular()) { if ($this->footer_sidebar_count == 0) { $single_area = get_post_meta($post->ID, '_widget_first_col', true); if (!empty($single_area)) { dynamic_sidebar($single_area); } else { dynamic_sidebar($this->footer_sidebar_names['footer-' . $footer_id]); } } if ($this->footer_sidebar_count == 1) { $single_area = get_post_meta($post->ID, '_widget_second_col', true); if (!empty($single_area)) { dynamic_sidebar($single_area); } else { dynamic_sidebar($this->footer_sidebar_names['footer-' . $footer_id]); } } if ($this->footer_sidebar_count == 2) { $single_area = get_post_meta($post->ID, '_widget_third_col', true); if (!empty($single_area)) { dynamic_sidebar($single_area); } else { dynamic_sidebar($this->footer_sidebar_names['footer-' . $footer_id]); } } if ($this->footer_sidebar_count == 3) { $single_area = get_post_meta($post->ID, '_widget_fourth_col', true); if (!empty($single_area)) { dynamic_sidebar($single_area); } else { dynamic_sidebar($this->footer_sidebar_names['footer-' . $footer_id]); } } if ($this->footer_sidebar_count == 4) { $single_area = get_post_meta($post->ID, '_widget_fourth_col', true); if (!empty($single_area)) { dynamic_sidebar($single_area); } else { dynamic_sidebar($this->footer_sidebar_names['footer-' . $footer_id]); } } if ($this->footer_sidebar_count == 5) { $single_area = get_post_meta($post->ID, '_widget_fourth_col', true); if (!empty($single_area)) { dynamic_sidebar($single_area); } else { dynamic_sidebar($this->footer_sidebar_names['footer-' . $footer_id]); } } } else { dynamic_sidebar($this->footer_sidebar_names['footer-' . $footer_id]); } $single_area = ''; $this->footer_sidebar_count++; } } global $_rdy_sidebar_generator; $_rdy_sidebar_generator = new LevelupSidebarGenerator; add_action('widgets_init', array($_rdy_sidebar_generator,'register_sidebar')); function levelup_sidebar_generator($function){ global $_rdy_sidebar_generator; $args = array_slice( func_get_args(), 1 ); return call_user_func_array(array( &$_rdy_sidebar_generator, $function ), $args ); } if( ! class_exists( 'levelup_sidebar' ) ){ class levelup_sidebar { public $sidebars = array(); public $stored = ""; public function __construct(){ $this->stored = 'birdy_sidebars'; $this->title = esc_html__('Custom Widget Area','LEVELUP'); add_action('load-widgets.php', array(&$this, 'load_assets') , 5 ); add_action('widgets_init', array(&$this, 'register_custom_sidebars') , 1000 ); add_action('wp_ajax_levelup_ajax_delete_custom_sidebar', array(&$this, 'delete_sidebar_area') , 1000 ); } public function load_assets(){ add_action('admin_print_scripts', array(&$this, 'template_add_widget_field') ); add_action('load-widgets.php', array(&$this, 'add_sidebar_area'), 100); wp_enqueue_script('levelup_sidebar' , LEVELUP_TEMPLATE_URL . '/admin/assets/js/sidebar.js'); wp_enqueue_style( 'levelup_sidebar' , LEVELUP_TEMPLATE_URL . '/admin/assets/css/sidebar.css'); } public function template_add_widget_field(){ $nonce = wp_create_nonce ('birdy-delete-sidebar'); $nonce = '<input type="hidden" name="birdy-delete-sidebar" value="'.$nonce.'" />'; echo "\n<div id='birdy-add-widget'>"; echo "\n<form class='birdy-add-widget' method='POST'>"; echo "\n<h3>". $this->title ."</h3>"; echo "\n<span class='input_wrap'><input type='text' value='' placeholder = '" . esc_html__('Enter Name of the new Widget Area', 'LEVELUP') . "' name='birdy-add-widget' /></span>"; echo "\n<input class='button' type='submit' value='" . esc_html__('Add Widget Area', 'LEVELUP') . "' />"; echo "\n".$nonce; echo "\n</form>"; echo "\n</div>\n"; } public function add_sidebar_area(){ if (!empty($_POST['birdy-add-widget'])) { $this->sidebars = get_option($this->stored); $name = $this->get_name($_POST['birdy-add-widget']); if (empty($this->sidebars)) { $this->sidebars = array($name); } else { $this->sidebars = array_merge($this->sidebars, array($name)); } update_option($this->stored, $this->sidebars); wp_redirect(admin_url('widgets.php')); die(); } } public function delete_sidebar_area(){ check_ajax_referer('birdy-delete-sidebar'); if (!empty($_POST['name'])) { $name = stripslashes($_POST['name']); $this->sidebars = get_option($this->stored); if (($key = array_search($name, $this->sidebars)) !== false) { unset($this->sidebars[$key]); update_option($this->stored, $this->sidebars); echo "sidebar-deleted"; } } die(); } public function get_name($name){ if (empty($GLOBALS['wp_registered_sidebars'])) { return $name; } $taken = array(); foreach ($GLOBALS['wp_registered_sidebars'] as $sidebar) { $taken[] = $sidebar['name']; } if (empty($this->sidebars)) { $this->sidebars = array(); } $taken = array_merge($taken, $this->sidebars); if (in_array($name, $taken)) { $counter = substr($name, -1); $new_name = ""; if (!is_numeric($counter)) { $new_name = $name . " 1"; } else { $new_name = substr($name, 0, -1) . ((int)$counter + 1); } $name = $this->get_name($new_name); } return $name; } public function register_custom_sidebars(){ if(empty($this->sidebars)) { $this->sidebars = get_option($this->stored); } $args = array( 'before_widget' => '<div class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h5>', 'after_title' => '</h5>' ); $args = apply_filters('levelup_custom_widget_args', $args); if (is_array($this->sidebars)) { foreach ($this->sidebars as $sidebar) { $args['name'] = $sidebar; $args['id'] = $sidebar; $args['class'] = 'birdy-custom'; register_sidebar($args); } } } } } add_theme_support('levelup_sidebar'); if (get_theme_support('levelup_sidebar')) new levelup_sidebar();