[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: class.widget-extends.php
<?php /** * This class simply add fields to widget admin that allows you to: * - Add additional css class to it for further styling. * - Add option to hide widget title (most of default widgets does not do this) * - Add option to create theme-based tag cloud without affecting default one. * * @author Case-Themes * @version 1.0 * @package alico * @since alico */ class Alico_Widget_Extends { /** * Construction */ function __construct() { global $pagenow; if ( is_admin() ) { add_action( 'in_widget_form', array( $this, 'extend_widget_form' ), 10, 3 ); add_filter( 'widget_update_callback', array( $this, 'extend_widget_update' ), 10, 4 ); } add_filter( 'dynamic_sidebar_params', array( $this, 'extend_widget_params'), 10, 2 ); } /** * Adds form fields to the end of Widget form * * @param $widget object WP_Widget | The widget instance, passed by reference. * @param $return null Return null if new fields are added. * @param $instance array An array of the widget's settings. * @return array An array of the new widget's settings. */ function extend_widget_form( $widget, $return, $instance ) { if ( ! isset( $instance['el_class'] ) ) { $instance['el_class'] = ''; } if ( is_a( $widget, 'WP_Widget_Tag_Cloud' ) ) { if ( ! isset( $instance['use_theme_style'] ) ) { $instance['use_theme_style'] = false; } else { $instance['use_theme_style'] = (bool)$instance['use_theme_style']; } ?> <p> <input type="checkbox" name="widget-<?php echo esc_attr( $widget->id_base . '[' . $widget->number . '][use_theme_style]' ); ?>" id="widget-<?php echo esc_attr( $widget->id_base . '-' . $widget->number ); ?>-use_theme_style" <?php checked( $instance['use_theme_style'] ); ?> /> <label for="widget-<?php echo esc_attr( $widget->id_base . '-' . $widget->number ); ?>-use_theme_style"><?php esc_html_e( 'Use Theme Style', 'alico' ); ?></label> </p> <?php } $hide_title = isset( $instance['hide_title'] ) ? (bool) $instance['hide_title'] : false; ?> <p> <label for="widget-<?php echo esc_attr( $widget->id_base . '-' . $widget->number ); ?>-el_class"><?php esc_html_e( 'CSS Class', 'alico' ); ?></label> <input type="text" class="widefat code" name="widget-<?php echo esc_attr( $widget->id_base . '[' . $widget->number . '][el_class]' ); ?>" id="widget-<?php echo esc_attr( $widget->id_base . '-' . $widget->number ); ?>-el_class" value="<?php echo esc_attr( $instance['el_class'] ); ?>" /> </p> <p> <input type="checkbox" name="widget-<?php echo esc_attr( $widget->id_base . '[' . $widget->number . '][hide_title]' ); ?>" id="widget-<?php echo esc_attr( $widget->id_base . '-' . $widget->number ); ?>-hide_title" <?php checked( $hide_title ); ?> /> <label for="widget-<?php echo esc_attr( $widget->id_base . '-' . $widget->number ); ?>-hide_title"><?php esc_html_e( 'Hide widget title', 'alico' ); ?></label> </p> <?php return $instance; } /** * Add css class param to the widget before saving * * @param $instance array The current widget instance's settings. * @param $new_instance array Array of new widget settings. * @return array An array of the new widget's settings. */ function extend_widget_update( $instance, $new_instance, $old_instance, $object ) { $instance['el_class'] = $new_instance['el_class']; $instance['hide_title'] = isset( $new_instance['hide_title'] ) ? (bool) $new_instance['hide_title'] : false; if ( is_a( $object, 'WP_Widget_Tag_Cloud' ) ) { $instance['use_theme_style'] = isset( $new_instance['use_theme_style'] ) ? (bool)$new_instance['use_theme_style'] : false; } return $instance; } /** * Add css class to widget front-end display by filtering widget params * @param $params array * @return array Extended widget parameters */ function extend_widget_params( $params ) { global $wp_registered_widgets; $widget_obj = $wp_registered_widgets[$params[0]['widget_id']]; $widget_num = $widget_obj['params'][0]['number']; $instances = get_option( $widget_obj['callback'][0]->option_name ); $instance = $instances[$widget_num]; if ( isset( $instance['el_class'] ) || is_a( $widget_obj['callback'][0], 'WP_Widget_Tag_Cloud' ) ) { $classes = array(); if ( is_a( $widget_obj['callback'][0], 'WP_Widget_Tag_Cloud' ) ) { if ( isset( $instance['use_theme_style'] ) && $instance['use_theme_style'] ) { $classes[] = 'use-theme-style'; } } if ( isset( $instance['el_class'] ) ) { $classes[] = $instance['el_class']; } $classes = array_map( 'esc_attr', $classes ); $class_string = join( ' ', $classes ); $class_string = trim( $class_string ); if ( strlen( $class_string ) ) { $params[0]['before_widget'] = preg_replace( '/class="/', "class=\"{$class_string} ", $params[0]['before_widget'], 1 ); } } if ( isset( $instance['hide_title'] ) && $instance['hide_title'] ) { $params[0]['before_title'] = '<div class="screen-reader-text">' . $params[0]['before_title']; $params[0]['after_title'] = $params[0]['after_title'] . '</div>'; } return $params; } } new Alico_Widget_Extends();
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.77 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002