D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
sadaunjx
/
public_html
/
wp-content
/
themes
/
newsplus1
/
inc
/
Filename :
functions-widgets.php
back
Copy
<?php /* Copyrights (C) Arb4Host Network */ ?> <?php function a4h_widget_case($sidebars_widgets) { if ( is_admin() ) { return $sidebars_widgets; } foreach ( $sidebars_widgets as $sidebar_id => $sidebar_widgets ) { if ( $sidebar_id == 'wp_inactive_widgets' || empty($sidebar_widgets) ) { continue; } foreach ( $sidebar_widgets as $index => $widget_id ) { $widget_base = _get_widget_id_base($widget_id); $widget_base_instance = get_option('widget_'.$widget_base); $widget_number = str_replace($widget_base.'-', '', $widget_id); $widget_instance = $widget_base_instance[$widget_number]; $widget_case_field = !empty($widget_instance['widget_case']) ? $widget_instance['widget_case'] : true; $widget_case = eval("return ($widget_case_field);"); if ( !$widget_case ) { unset($sidebars_widgets[$sidebar_id][$index]); } } } return $sidebars_widgets; } add_filter('sidebars_widgets', 'a4h_widget_case'); function a4h_empty_widget_title_detect($title, $instance = array()) { return empty($instance['title']) ? '' : $title; } add_filter('widget_title', 'a4h_empty_widget_title_detect', 10, 2); function a4h_widget_title_vars($title, $instance = array()) { $categories = get_the_category(); if ( $categories ) { $category_id = $categories[0]->cat_ID; $current_cat = get_cat_name($category_id); $title = str_replace("%%التصنيف%%", $current_cat, $title); } return $title; } add_filter('widget_title', 'a4h_widget_title_vars', 10, 2); function a4h_dynamic_sidebar_params($params) { global $wp_registered_widgets; $settings_getter = $wp_registered_widgets[$params[0]['widget_id']]['callback'][0]; if ( !is_object($settings_getter) ) { return $params; } $instance = $settings_getter->get_settings(); $instance = $instance[$params[1]['number']]; $widget_id = $params[0]['widget_id']; $class = array(); $class[] = empty($instance['title']) ? '' : 'has-title'; $class[] = empty($instance['widget_width']) ? '' : 'col-lg-'.$instance['widget_width']; $class[] = !empty($instance['hide_on']) && $instance['hide_on'] == 'mobile' ? 'd-none d-lg-flex' : ''; $class[] = !empty($instance['hide_on']) && $instance['hide_on'] == 'desktop' ? 'd-lg-none' : ''; $class[] = empty($instance['widget_class']) ? '' : $instance['widget_class']; $class = implode(' ', array_filter($class)); $params[0]['before_widget'] = preg_replace('/(class="[^"]*)/', "$1 $class", $params[0]['before_widget'], 1); $params[0]['before_widget'] .= empty($instance['title']) ? '<div class="widget-content">' : ''; return $params; } add_filter('dynamic_sidebar_params', 'a4h_dynamic_sidebar_params'); function a4h_in_widget_form_update($instance, $new_instance, $old_instance) { $instance['widget_width'] = $new_instance['widget_width']; $instance['widget_case'] = sanitize_text_field($new_instance['widget_case']); $instance['hide_on'] = $new_instance['hide_on']; $instance['widget_class'] = sanitize_text_field($new_instance['widget_class']); return $instance; } add_filter('widget_update_callback', 'a4h_in_widget_form_update', 5, 3); function a4h_in_widget_form($t, $return, $instance) { $widget_width = empty($instance['widget_width']) ? '' : $instance['widget_width']; $hide_on = empty($instance['hide_on']) ? '' : $instance['hide_on']; $widget_class = empty($instance['widget_class']) ? '' : $instance['widget_class']; $widget_case = empty($instance['widget_case']) ? '' : $instance['widget_case']; ?> <div style="margin: 10px 0px; padding: 0px 10px; background: #EEEEEE; overflow: hidden;"> <p> <label for="<?php echo $t->get_field_id('widget_width'); ?>"><?php _e('Widget Width', THEME_TEXT_DOMAIN); ?>:</label> <select id="<?php echo $t->get_field_id('widget_width'); ?>" name="<?php echo $t->get_field_name('widget_width'); ?>"> <?php $options = range(12,1); foreach ( $options as $option ) { ?> <option <?php selected($option, $widget_width); ?> value="<?php echo $option; ?>"><?php echo $option; ?>/12</option> <?php } ?> </select> </p> </div> <div style="margin: 10px 0px; padding: 0px 10px; background: #EEEEEE; overflow: hidden;"> <p> <label for="<?php echo $t->get_field_id('hide_on'); ?>">إخفاء على:</label> <select id="<?php echo $t->get_field_id('hide_on'); ?>" name="<?php echo $t->get_field_name('hide_on'); ?>"> <option value="">----------</option> <option <?php selected('mobile', $hide_on); ?> value="mobile">الموبايل</option> <option <?php selected('desktop', $hide_on); ?> value="desktop">الكمبيوتر</option> </select> </p> </div> <div style="margin: 10px 0px; padding: 0px 10px; background: #EEEEEE; overflow: hidden;"> <p> <label for="<?php echo $t->get_field_id('widget_class'); ?>">CSS Class:</label> <input class="widefat ltr" type="text" id="<?php echo $t->get_field_id('widget_class'); ?>" name="<?php echo $t->get_field_name('widget_class'); ?>" value="<?php echo $widget_class; ?>" /> </p> </div> <div style="margin: 10px 0px; padding: 0px 10px; background: #EEEEEE; overflow: hidden;"> <p> <label for="<?php echo $t->get_field_id('widget_case'); ?>">Conditional Tags:</label> <input class="widefat ltr" type="text" id="<?php echo $t->get_field_id('widget_case'); ?>" name="<?php echo $t->get_field_name('widget_case'); ?>" value="<?php echo $widget_case; ?>" /> </p> </div> <?php return array($t, $return, $instance); } add_action('in_widget_form', 'a4h_in_widget_form', 5, 3); function a4h_widgets_input_fields($_this, $instance, $type, $slug, $title, $data = array()) { $instance[$slug] = isset($instance[$slug]) ? $instance[$slug] : ''; if ( $type == 'text') { ?> <p> <?php if ( $title ) { ?><label for="<?php echo $_this->get_field_id($slug); ?>"><?php echo $title; ?>:</label><?php } ?> <?php if ( !empty($data['prepend']) ) echo $data['prepend']; ?> <input type="text" id="<?php echo $_this->get_field_id($slug); ?>" name="<?php echo $_this->get_field_name($slug); ?>" class="widefat <?php if ( !empty($data['class']) ) echo $data['class']; ?>" placeholder="<?php if ( !empty($data['placeholder']) ) echo $data['placeholder']; ?>" value="<?php echo $instance[$slug]; ?>" /> <?php if ( !empty($data['append']) ) echo $data['append']; ?> </p> <?php } if ( $type == 'checkbox') { ?> <p> <input type="checkbox" id="<?php echo $_this->get_field_id($slug); ?>" name="<?php echo $_this->get_field_name($slug); ?>" value="1" <?php checked(1, $instance[$slug]); ?>><?php if ( $title ) { ?><label for="<?php echo $_this->get_field_id($slug); ?>"><?php echo $title; ?></label><?php } ?> </p> <?php } if ( $type == 'textarea') { ?> <p> <?php if ( $title ) { ?><label for="<?php echo $_this->get_field_id($slug); ?>"><?php echo $title; ?>:</label><?php } ?> <textarea id="<?php echo $_this->get_field_id($slug); ?>" name="<?php echo $_this->get_field_name($slug); ?>" class="widefat <?php if ( !empty($data['class']) ) echo $data['class']; ?>" placeholder="<?php if ( !empty($data['placeholder']) ) echo $data['placeholder']; ?>" cols="<?php if ( !empty($data['cols']) ) echo $data['cols']; ?>" rows="<?php if ( !empty($data['rows']) ) echo $data['rows']; ?>"><?php echo $instance[$slug]; ?></textarea> </p> <?php } if ( $type == 'select') { ?> <p> <?php if ( $title ) { ?><label for="<?php echo $_this->get_field_id($slug); ?>"><?php echo $title; ?>:</label><?php } ?> <select id="<?php echo $_this->get_field_id($slug); ?>" name="<?php echo $_this->get_field_name($slug); ?>" class="widefat <?php if ( !empty($data['class']) ) echo $data['class']; ?>"> <?php $options = !empty($data['options']) ? $data['options'] : ''; ?> <?php foreach ( $options as $option_slug => $option_title ) { ?> <?php if ( strpos($option_slug, '_group_start_') !== false ) { ?> <optgroup label="<?php echo $option_title; ?>"> <?php } ?> <?php if ( strpos($option_slug, '_group_start_') === false && strpos($option_slug, '_group_end_') === false ) { ?> <option <?php selected($option_slug, $instance[$slug]); ?> value="<?php echo $option_slug; ?>"><?php echo $option_title; ?></option> <?php } ?> <?php if ( strpos($option_slug, '_group_end_') !== false ) { ?> </optgroup> <?php } ?> <?php } ?> </select> </p> <?php } if ( $type == 'upload') { ?> <p> <?php if ( $title ) { ?><label for="<?php echo $_this->get_field_id($slug); ?>"><?php echo $title; ?>:</label><?php } ?> <?php if ( !empty($data['prepend']) ) echo $data['prepend']; ?> <input type="text" class="widefat ltr mz-image-src" placeholder="http://" value="<?php echo !empty($instance[$slug]['src']) ? $instance[$slug]['src'] : ''; ?>" disabled="disabled" /> <input type="button" class="button button-secondary upload-image-button" value="اختيار صورة" /> <?php if ( !empty($data['append']) ) echo $data['append']; ?> <span class="mz-image-preview <?php if ( !empty($instance[$slug]['src']) ) { echo 'active'; } ?>"> <img src="<?php if ( !empty($instance[$slug]['src']) ) { echo $instance[$slug]['src']; } ?>" /> <input type="button" class="button button-secondary remove-image-button" value="إزالة الصورة" style="vertical-align: text-bottom;" /> </span> <input type="hidden" class="mz-image-src" name="<?php echo $_this->get_field_name($slug); ?>[src]" value="<?php echo !empty($instance[$slug]['src']) ? $instance[$slug]['src'] : ''; ?>" /> <input type="hidden" class="mz-image-width" name="<?php echo $_this->get_field_name($slug); ?>[width]" value="<?php echo !empty($instance[$slug]['width']) ? $instance[$slug]['width'] : ''; ?>" /> <input type="hidden" class="mz-image-height" name="<?php echo $_this->get_field_name($slug); ?>[height]" value="<?php echo !empty($instance[$slug]['height']) ? $instance[$slug]['height'] : ''; ?>" /> <input type="hidden" class="mz-image-id" name="<?php echo $_this->get_field_name($slug); ?>[id]" value="<?php echo !empty($instance[$slug]['id']) ? $instance[$slug]['id'] : ''; ?>" /> </p> <?php } if ( $type == 'number') { ?> <p> <?php if ( $title ) { ?><label for="<?php echo $_this->get_field_id($slug); ?>"><?php echo $title; ?>:</label><?php } ?> <?php if ( !empty($data['prepend']) ) echo $data['prepend']; ?> <input type="number" id="<?php echo $_this->get_field_id($slug); ?>" name="<?php echo $_this->get_field_name($slug); ?>" class="widefat <?php if ( !empty($data['class']) ) echo $data['class']; ?>" placeholder="<?php if ( !empty($data['placeholder']) ) echo $data['placeholder']; ?>" value="<?php echo $instance[$slug]; ?>" /> <?php if ( !empty($data['append']) ) echo $data['append']; ?> </p> <?php } } function a4h_widget_options_functions($_this, $instance, $type) { if ( $type == 'select_category') { $instance['cat'] = isset($instance['cat']) ? $instance['cat'] : ''; ?> <p> <label for="<?php echo $_this->get_field_id('cat'); ?>"><?php _e('Selected Category', THEME_TEXT_DOMAIN); ?>:</label> <?php $categories = get_categories('hide_empty=0&orderby=name'); ?> <select id="<?php echo $_this->get_field_id('cat'); ?>" name="<?php echo $_this->get_field_name('cat'); ?>" class="widefat"> <?php foreach ( $categories as $category ) { ?> <option <?php selected($category->term_id, $instance['cat']); ?> value="<?php echo $category->term_id; ?>"><?php echo $category->name; ?></option> <?php } ?> </select> </p> <?php } if ( $type == 'select_categories') { $instance['cats'] = isset($instance['cats']) ? $instance['cats'] : array(); ?> <p> <label for="<?php echo $_this->get_field_id('cats'); ?>"><?php _e('Selected Categories', THEME_TEXT_DOMAIN); ?>:</label> <?php $categories = get_categories('hide_empty=0&orderby=name'); ?> <select id="<?php echo $_this->get_field_id('cats'); ?>" name="<?php echo $_this->get_field_name('cats'); ?>[]" class="widefat" multiple="multiple" size="10"> <option <?php selected(1, in_array('all', $instance['cats'])); ?> value="all">-- <?php _e('All Categories', THEME_TEXT_DOMAIN); ?> --</option> <option <?php selected(1, in_array('current', $instance['cats'])); ?> value="current">-- <?php _e('Current category', THEME_TEXT_DOMAIN); ?> --</option> <?php foreach ( $categories as $category ) { ?> <option <?php selected(1, in_array($category->term_id, $instance['cats'])); ?> value="<?php echo $category->term_id; ?>"><?php echo $category->name; ?></option> <?php } ?> </select> </p> <?php } if ( $type == 'select_taxonomy') { $instance['tax'] = isset($instance['tax']) ? $instance['tax'] : ''; ?> <p> <label for="<?php echo $_this->get_field_id('tax'); ?>"><?php _e('Taxonomy', THEME_TEXT_DOMAIN); ?>:</label> <?php $taxonomies = get_taxonomies(array('public' => true)); ?> <select id="<?php echo $_this->get_field_id('tax'); ?>" name="<?php echo $_this->get_field_name('tax'); ?>" class="widefat"> <?php foreach ( $taxonomies as $taxonomy ) { ?> <option <?php selected($taxonomy, $instance['tax']); ?> value="<?php echo $taxonomy; ?>"><?php echo $taxonomy; ?></option> <?php } ?> </select> </p> <?php } }