first commit

This commit is contained in:
2023-11-23 22:14:40 +01:00
commit 6c5e83d1b2
2779 changed files with 640726 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
if ( ! function_exists( 'calla_elated_map_sidebar_meta' ) ) {
function calla_elated_map_sidebar_meta() {
$eltdf_sidebar_meta_box = calla_elated_create_meta_box(
array(
'scope' => apply_filters( 'calla_elated_set_scope_for_meta_boxes', array( 'page' ), 'sidebar_meta' ),
'title' => esc_html__( 'Sidebar', 'calla' ),
'name' => 'sidebar_meta'
)
);
calla_elated_create_meta_box_field(
array(
'name' => 'eltdf_sidebar_layout_meta',
'type' => 'select',
'label' => esc_html__( 'Sidebar Layout', 'calla' ),
'description' => esc_html__( 'Choose the sidebar layout', 'calla' ),
'parent' => $eltdf_sidebar_meta_box,
'options' => calla_elated_get_custom_sidebars_options( true )
)
);
$eltdf_custom_sidebars = calla_elated_get_custom_sidebars();
if ( count( $eltdf_custom_sidebars ) > 0 ) {
calla_elated_create_meta_box_field(
array(
'name' => 'eltdf_custom_sidebar_area_meta',
'type' => 'selectblank',
'label' => esc_html__( 'Choose Widget Area in Sidebar', 'calla' ),
'description' => esc_html__( 'Choose Custom Widget area to display in Sidebar"', 'calla' ),
'parent' => $eltdf_sidebar_meta_box,
'options' => $eltdf_custom_sidebars,
'args' => array(
'select2' => true
)
)
);
}
}
add_action( 'calla_elated_meta_boxes_map', 'calla_elated_map_sidebar_meta', 31 );
}

View File

@@ -0,0 +1,49 @@
<?php
if ( ! function_exists( 'calla_elated_sidebar_options_map' ) ) {
function calla_elated_sidebar_options_map() {
calla_elated_add_admin_page(
array(
'slug' => '_sidebar_page',
'title' => esc_html__( 'Sidebar Area', 'calla' ),
'icon' => 'fa fa-indent'
)
);
$sidebar_panel = calla_elated_add_admin_panel(
array(
'title' => esc_html__( 'Sidebar Area', 'calla' ),
'name' => 'sidebar',
'page' => '_sidebar_page'
)
);
calla_elated_add_admin_field( array(
'name' => 'sidebar_layout',
'type' => 'select',
'label' => esc_html__( 'Sidebar Layout', 'calla' ),
'description' => esc_html__( 'Choose a sidebar layout for pages', 'calla' ),
'parent' => $sidebar_panel,
'default_value' => 'no-sidebar',
'options' => calla_elated_get_custom_sidebars_options()
) );
$calla_custom_sidebars = calla_elated_get_custom_sidebars();
if ( count( $calla_custom_sidebars ) > 0 ) {
calla_elated_add_admin_field( array(
'name' => 'custom_sidebar_area',
'type' => 'selectblank',
'label' => esc_html__( 'Sidebar to Display', 'calla' ),
'description' => esc_html__( 'Choose a sidebar to display on pages. Default sidebar is "Sidebar"', 'calla' ),
'parent' => $sidebar_panel,
'options' => $calla_custom_sidebars,
'args' => array(
'select2' => true
)
) );
}
}
add_action( 'calla_elated_options_map', 'calla_elated_sidebar_options_map', 6 );
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* Elated Sidebar
* Class for adding custom widget area and choose them on single pages/posts/portfolios
*/
if ( ! class_exists( 'CallaElatedSidebar' ) ) {
class CallaElatedSidebar {
var $sidebars = array();
var $stored = "";
// load needed stuff on widget page
function __construct() {
$this->stored = 'eltdf_sidebars';
$this->title = esc_html__( 'Custom Widget Area', 'calla' );
add_action( 'load-widgets.php', array( &$this, 'load_assets' ), 5 );
add_action( 'widgets_init', array( &$this, 'register_custom_sidebars' ), 1000 );
add_action( 'wp_ajax_eltd_ajax_delete_custom_sidebar', array( &$this, 'delete_sidebar_area' ), 1000 );
}
//load css, js and add hooks to the widget page
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( 'calla-elated-sidebar', ELATED_ROOT . '/framework/admin/assets/js/eltdf-ui/eltdf-sidebar.js' );
wp_enqueue_style( 'calla-elated-sidebar', ELATED_ROOT . '/framework/admin/assets/css/eltdf-sidebar.css' );
}
//widget form template
function template_add_widget_field() {
$nonce = '<input type="hidden" name="eltdf-delete-sidebar" value="' . wp_create_nonce('eltdf-delete-sidebar') . '" />';
echo "\n<script type='text/html' id='eltdf-add-widget'>";
echo "\n <form class='eltdf-add-widget' method='POST'>";
echo "\n <h3>" . esc_html($this->title) . "</h3>";
echo "\n <span class='input_wrap'><input type='text' value='' placeholder = '" . esc_html__('Enter Name of the new Widget Area', 'calla') . "' name='eltdf-add-widget' /></span>";
echo "\n <input class='button' type='submit' value='" . esc_html__('Add Widget Area', 'calla') . "' />";
echo "\n " . $nonce;
echo "\n </form>";
echo "\n</script>\n";
}
//add sidebar area to the db
function add_sidebar_area() {
if ( ! empty( $_POST['eltdf-add-widget'] ) ) {
$this->sidebars = get_option( $this->stored );
$name = $this->get_name(sanitize_text_field($_POST['eltdf-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();
}
}
//delete sidebar area from the db
function delete_sidebar_area() {
check_ajax_referer( 'eltdf-delete-sidebar' );
if ( ! empty( $_POST['name'] ) ) {
$name = stripslashes(sanitize_text_field($_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();
}
//checks the user submitted name and makes sure that there are no colitions
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 = ! is_numeric( $counter ) ? $name . " 1" : substr( $name, 0, - 1 ) . ( (int) $counter + 1 );
$name = $this->get_name( $new_name );
}
return $name;
}
//register custom sidebar areas
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' => '<div class="eltdf-widget-title-holder"><h6 class="eltdf-widget-title">',
'after_title' => '</h6></div>'
);
$args = apply_filters( 'calla_elated_custom_widget_args', $args );
if ( is_array( $this->sidebars ) ) {
foreach ( $this->sidebars as $sidebar ) {
$args['name'] = $sidebar;
$args['id'] = sanitize_title( $sidebar );
$args['class'] = 'eltdf-custom';
register_sidebar( $args );
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
<?php
include_once ELATED_FRAMEWORK_MODULES_ROOT_DIR . '/sidebar/sidebar.php';
include_once ELATED_FRAMEWORK_MODULES_ROOT_DIR . '/sidebar/eltdf-custom-sidebar.php';
include_once ELATED_FRAMEWORK_MODULES_ROOT_DIR . '/sidebar/sidebar-functions.php';
//load global sidebar options
include_once ELATED_FRAMEWORK_MODULES_ROOT_DIR . '/sidebar/admin/options-map/sidebar-map.php';
//load per page sidebar options
include_once ELATED_FRAMEWORK_MODULES_ROOT_DIR . '/sidebar/admin/meta-boxes/sidebar-meta-boxes.php';

View File

@@ -0,0 +1,188 @@
<?php
if ( ! function_exists( 'calla_elated_sidebar_layout' ) ) {
/**
* Function that check is sidebar is enabled and return type of sidebar layout
*/
function calla_elated_sidebar_layout() {
$sidebar_layout = '';
$sidebar_layout_meta = calla_elated_get_meta_field_intersect( 'sidebar_layout' );
$archive_sidebar_layout = calla_elated_options()->getOptionValue( 'archive_sidebar_layout' );
$search_sidebar_layout = calla_elated_options()->getOptionValue( 'search_page_sidebar_layout' );
$single_sidebar_layout = calla_elated_get_meta_field_intersect( 'blog_single_sidebar_layout' );
if ( ! empty( $sidebar_layout_meta ) ) {
$sidebar_layout = $sidebar_layout_meta;
}
if ( is_singular( 'post' ) && ! empty( $single_sidebar_layout ) ) {
$sidebar_layout = $single_sidebar_layout;
}
if ( is_search() && ! calla_elated_is_woocommerce_shop() && ! empty( $search_sidebar_layout ) ) {
$sidebar_layout = $search_sidebar_layout;
}
if ( ( is_archive() || ( is_home() && is_front_page() ) ) && ! calla_elated_is_woocommerce_page() && ! empty( $archive_sidebar_layout ) ) {
$sidebar_layout = $archive_sidebar_layout;
}
if ( ! empty( $sidebar_layout ) && ! is_active_sidebar( calla_elated_get_sidebar() ) ) {
$sidebar_layout = '';
}
return apply_filters( 'calla_elated_sidebar_layout', $sidebar_layout );
}
}
if ( ! function_exists( 'calla_elated_get_content_sidebar_class' ) ) {
/**
* Return classes for content holder when sidebar is active
*
* @return string
*/
function calla_elated_get_content_sidebar_class() {
$sidebar_layout = calla_elated_sidebar_layout();
$content_class = array( 'eltdf-page-content-holder' );
switch ( $sidebar_layout ) {
case 'sidebar-33-right':
$content_class[] = 'eltdf-grid-col-8';
break;
case 'sidebar-25-right':
$content_class[] = 'eltdf-grid-col-9';
break;
case 'sidebar-20-right':
$content_class[] = 'eltdf-grid-col-10';
break;
case 'sidebar-33-left':
$content_class[] = 'eltdf-grid-col-8';
$content_class[] = 'eltdf-grid-col-push-4';
break;
case 'sidebar-25-left':
$content_class[] = 'eltdf-grid-col-9';
$content_class[] = 'eltdf-grid-col-push-3';
break;
case 'sidebar-20-left':
$content_class[] = 'eltdf-grid-col-10';
$content_class[] = 'eltdf-grid-col-push-2';
break;
default:
$content_class[] = 'eltdf-grid-col-12';
break;
}
return calla_elated_get_class_attribute( $content_class );
}
}
if ( ! function_exists( 'calla_elated_get_sidebar_holder_class' ) ) {
/**
* Return classes for sidebar holder when sidebar is active
*
* @return string
*/
function calla_elated_get_sidebar_holder_class() {
$sidebar_layout = calla_elated_sidebar_layout();
$sidebar_class = array( 'eltdf-sidebar-holder' );
switch ( $sidebar_layout ) {
case 'sidebar-33-right':
$sidebar_class[] = 'eltdf-grid-col-4';
break;
case 'sidebar-25-right':
$sidebar_class[] = 'eltdf-grid-col-3';
break;
case 'sidebar-20-right':
$sidebar_class[] = 'eltdf-grid-col-2';
break;
case 'sidebar-33-left':
$sidebar_class[] = 'eltdf-grid-col-4';
$sidebar_class[] = 'eltdf-grid-col-pull-8';
break;
case 'sidebar-25-left':
$sidebar_class[] = 'eltdf-grid-col-3';
$sidebar_class[] = 'eltdf-grid-col-pull-9';
break;
case 'sidebar-20-left':
$sidebar_class[] = 'eltdf-grid-col-2';
$sidebar_class[] = 'eltdf-grid-col-pull-10';
}
return calla_elated_get_class_attribute( $sidebar_class );
}
}
if ( ! function_exists( 'calla_elated_get_sidebar' ) ) {
/**
* Return Sidebar name
*
* @return string
*/
function calla_elated_get_sidebar() {
$sidebar_name = 'sidebar';
$custom_sidebar_area = calla_elated_get_meta_field_intersect( 'custom_sidebar_area' );
$custom_archive_sidebar_area = calla_elated_options()->getOptionValue( 'archive_custom_sidebar_area' );
$custom_search_sidebar_area = calla_elated_options()->getOptionValue( 'search_custom_sidebar_area' );
$custom_single_sidebar_area = calla_elated_get_meta_field_intersect( 'blog_single_custom_sidebar_area' );
if ( ! empty( $custom_sidebar_area ) ) {
$sidebar_name = $custom_sidebar_area;
}
if ( is_singular( 'post' ) && ! empty( $custom_single_sidebar_area ) ) {
$sidebar_name = $custom_single_sidebar_area;
}
if ( is_search() && ! empty( $custom_search_sidebar_area ) ) {
$sidebar_name = $custom_search_sidebar_area;
}
if ( ( is_archive() || ( is_home() && is_front_page() ) ) && ! calla_elated_is_woocommerce_page() && ! empty( $custom_archive_sidebar_area ) ) {
$sidebar_name = $custom_archive_sidebar_area;
}
return apply_filters( 'calla_elated_sidebar_name', $sidebar_name );
}
}
if ( ! function_exists( 'calla_elated_get_custom_sidebars' ) ) {
/**
* Function that returns all custom made sidebars.
*
* @uses get_option()
* @return array array of custom made sidebars where key and value are sidebar name
*/
function calla_elated_get_custom_sidebars() {
$calla_custom_sidebars = get_option( 'eltdf_sidebars' );
$formatted_array = array();
if ( is_array( $calla_custom_sidebars ) && count( $calla_custom_sidebars ) ) {
foreach ( $calla_custom_sidebars as $custom_sidebar ) {
$formatted_array[ sanitize_title( $custom_sidebar ) ] = $custom_sidebar;
}
}
return $formatted_array;
}
}
if ( ! function_exists( 'calla_elated_get_custom_sidebars_options' ) ) {
function calla_elated_get_custom_sidebars_options( $enable_default = false ) {
$sidebar_options = array();
if ( $enable_default ) {
$sidebar_options[''] = esc_html__( 'Default', 'calla' );
}
$sidebar_options['no-sidebar'] = esc_html__( 'No Sidebar', 'calla' );
$sidebar_options['sidebar-33-right'] = esc_html__( 'Sidebar 1/3 Right', 'calla' );
$sidebar_options['sidebar-25-right'] = esc_html__( 'Sidebar 1/4 Right', 'calla' );
$sidebar_options['sidebar-20-right'] = esc_html__( 'Sidebar 1/5 Right', 'calla' );
$sidebar_options['sidebar-33-left'] = esc_html__( 'Sidebar 1/3 Left', 'calla' );
$sidebar_options['sidebar-25-left'] = esc_html__( 'Sidebar 1/4 Left', 'calla' );
$sidebar_options['sidebar-20-left'] = esc_html__( 'Sidebar 1/5 Left', 'calla' );
return $sidebar_options;
}
}

View File

@@ -0,0 +1,38 @@
<?php
if ( ! function_exists( 'calla_elated_register_sidebars' ) ) {
/**
* Function that registers theme's sidebars
*/
function calla_elated_register_sidebars() {
register_sidebar(
array(
'id' => 'sidebar',
'name' => esc_html__( 'Sidebar', 'calla' ),
'description' => esc_html__( 'Default Sidebar', 'calla' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="eltdf-widget-title-holder"><h6 class="eltdf-widget-title">',
'after_title' => '</h6></div>'
)
);
}
add_action( 'widgets_init', 'calla_elated_register_sidebars', 1 );
}
if ( ! function_exists( 'calla_elated_add_support_custom_sidebar' ) ) {
/**
* Function that adds theme support for custom sidebars. It also creates CallaElatedSidebar object
*/
function calla_elated_add_support_custom_sidebar() {
add_theme_support( 'CallaElatedSidebar' );
if ( get_theme_support( 'CallaElatedSidebar' ) ) {
new CallaElatedSidebar();
}
}
add_action( 'after_setup_theme', 'calla_elated_add_support_custom_sidebar' );
}