Ejemplo n.º 1
0
function iterator($id_base, $class, $callback)
{
    global $wp_registered_widgets;
    $sidebars_widgets = wp_get_sidebars_widgets();
    if (is_array($sidebars_widgets)) {
        foreach ($sidebars_widgets as $sidebar => $widgets) {
            if ('wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr($sidebar, 0, 16)) {
                continue;
            }
            if (is_array($widgets)) {
                foreach ($widgets as $widget) {
                    $widget_base = _get_widget_id_base($widget);
                    if ($widget_base == $id_base) {
                        $widgetclass = new $class();
                        $allsettings = $widgetclass->get_settings();
                        $settings = isset($allsettings[str_replace($widget_base . '-', '', $widget)]) ? $allsettings[str_replace($widget_base . '-', '', $widget)] : false;
                        if (!$callback($settings)) {
                            return;
                        }
                    }
                }
            }
        }
    }
}
Ejemplo n.º 2
0
 /**
  * Get the visible ACF fields.
  * @return array
  */
 public function get_visible_acf_fields($widget_id = null)
 {
     global $wp_registered_widgets;
     $visible_fields = array();
     // build field group filters required for current screen
     $filter = $this->get_acf_field_group_filters();
     if (count($filter) === 0) {
         return $visible_fields;
     }
     // widgets need some special handling since they
     // require multiple acf_get_field_group_visibility()
     // calls in order to return all the visible fields
     if (acf_is_screen('widgets') || acf_is_screen('customize')) {
         if ($widget_id) {
             $filter['widget'] = _get_widget_id_base($widget_id);
         } else {
             // process each widget form individually for any visible fields
             foreach ($wp_registered_widgets as $widget) {
                 $visible_fields += $this->get_visible_acf_fields($widget['id']);
             }
             return $visible_fields;
         }
     }
     $supported_field_types = array('email', 'text', 'textarea', 'repeater', 'flexible_content', 'qtranslate_file', 'qtranslate_image', 'qtranslate_text', 'qtranslate_textarea', 'qtranslate_wysiwyg');
     foreach (acf_get_field_groups($filter) as $field_group) {
         $fields = acf_get_fields($field_group);
         foreach ($fields as $field) {
             if (in_array($field['type'], $supported_field_types)) {
                 $visible_fields[] = array('id' => 'acf-' . $field['key']);
             }
         }
     }
     return $visible_fields;
 }
Ejemplo n.º 3
0
function category_posts_should_enqueue($id_base, $class)
{
    global $wp_registered_widgets;
    $ret = false;
    $sidebars_widgets = wp_get_sidebars_widgets();
    if (is_array($sidebars_widgets)) {
        foreach ($sidebars_widgets as $sidebar => $widgets) {
            if ('wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr($sidebar, 0, 16)) {
                continue;
            }
            if (is_array($widgets)) {
                foreach ($widgets as $widget) {
                    $widget_base = _get_widget_id_base($widget);
                    if ($widget_base == $id_base) {
                        $widgetclass = new $class();
                        $allsettings = $widgetclass->get_settings();
                        $settings = $allsettings[str_replace($widget_base . '-', '', $widget)];
                        if (!isset($settings['disable_css'])) {
                            // checks if css disable is not set
                            $ret = true;
                        }
                    }
                }
            }
        }
    }
    return $ret;
}
/**
 * Whether widget is displayed on the front-end.
 *
 * Either $callback or $id_base can be used
 * $id_base is the first argument when extending WP_Widget class
 * Without the optional $widget_id parameter, returns the ID of the first sidebar
 * in which the first instance of the widget with the given callback or $id_base is found.
 * With the $widget_id parameter, returns the ID of the sidebar where
 * the widget with that callback/$id_base AND that ID is found.
 *
 * NOTE: $widget_id and $id_base are the same for single widgets. To be effective
 * this function has to run after widgets have initialized, at action 'init' or later.
 *
 * @since 2.2.0
 *
 * @param string $callback Optional, Widget callback to check.
 * @param int $widget_id Optional, but needed for checking. Widget ID.
 * @param string $id_base Optional, the base ID of a widget created by extending WP_Widget.
 * @param bool $skip_inactive Optional, whether to check in 'wp_inactive_widgets'.
 * @return mixed false if widget is not active or id of sidebar in which the widget is active.
 */
function is_active_widget($callback = false, $widget_id = false, $id_base = false, $skip_inactive = true)
{
    global $wp_registered_widgets;
    $sidebars_widgets = wp_get_sidebars_widgets();
    if (is_array($sidebars_widgets)) {
        foreach ($sidebars_widgets as $sidebar => $widgets) {
            if ($skip_inactive && 'wp_inactive_widgets' == $sidebar) {
                continue;
            }
            if (is_array($widgets)) {
                foreach ($widgets as $widget) {
                    if ($callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback || $id_base && _get_widget_id_base($widget) == $id_base) {
                        if (!$widget_id || $widget_id == $wp_registered_widgets[$widget]['id']) {
                            return $sidebar;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Ejemplo n.º 5
0
 /**
  * This function adjusts the sidebar parameters for widgets.
  */
 public function dynamic_sidebar_params($params)
 {
     // Bail if we're not on the front-end
     if (is_admin()) {
         return $params;
     }
     // If Note exists
     if (function_exists('Note_Widget')) {
         // Grab the Note Widget instance
         $note_widget = Note_Widget();
         // Only on Note Widgets
         if (_get_widget_id_base($params[0]['widget_id']) === $note_widget->id_base) {
             // Store a reference to the widget settings (all Note Widgets)
             $note_widget_settings = $note_widget->get_settings();
             // Determine if this is a valid Note widget
             if (array_key_exists($params[1]['number'], $note_widget_settings)) {
                 // Grab widget settings
                 $instance = $note_widget_settings[$params[1]['number']];
                 // If we have a template
                 if (property_exists($note_widget, 'templates') && isset($instance['template']) && !empty($instance['template']) && array_key_exists($instance['template'], $note_widget->templates)) {
                     // Grab the template details for this widget
                     $template = $note_widget->templates[$instance['template']];
                     // CSS Classes
                     $css_classes = array();
                     // Check the template type first
                     if (isset($template['type'])) {
                         $css_classes[] = sanitize_html_class($template['type'] . '-widget');
                     }
                     // Then check the template
                     if (empty($css_classes) && isset($template['template'])) {
                         $css_classes[] = sanitize_html_class($template['template'] . '-widget');
                     }
                     // Otherwise fallback to the name
                     if (empty($css_classes)) {
                         $css_classes[] = sanitize_html_class($instance['template'] . '-widget');
                     }
                     // Adjust the before_widget parameter (only replacing once to ensure only the outer most wrapper element gets the CSS class adjustment)
                     $params[0]['before_widget'] = preg_replace('/class="/', 'class="' . esc_attr(implode(' ', $css_classes)) . ' ', $params[0]['before_widget'], 1);
                 }
             }
         }
     }
     // If Conductor exists
     if (function_exists('Conduct_Widget')) {
         // Grab the Conductor Widget instance
         $conductor_widget = Conduct_Widget();
         // Only on Conductor Widgets
         if (_get_widget_id_base($params[0]['widget_id']) === $conductor_widget->id_base) {
             // Store a reference to the widget settings (all Conductor Widgets)
             $conductor_widget_settings = $conductor_widget->get_settings();
             // Determine if this is a valid Conductor widget
             if (array_key_exists($params[1]['number'], $conductor_widget_settings)) {
                 // Grab widget settings
                 $instance = $conductor_widget_settings[$params[1]['number']];
                 // If we have flexbox display in the Front Page Sidebar
                 if ($params[0]['id'] === 'front-page-sidebar' && $this->conductor_has_flexbox_display()) {
                     // Grab this widget's display configuration
                     $widget_display_config = isset($instance['widget_size']) && isset($conductor_widget->displays[$instance['widget_size']]) ? $conductor_widget->displays[$instance['widget_size']] : false;
                     // Verify that the widget size supports columns
                     //isset( $instance['widget_size'] ) && $instance['widget_size'] === 'flexbox'
                     if (!empty($widget_display_config) && $conductor_widget->widget_display_supports_customize_property($widget_display_config, 'columns')) {
                         // Adjust the before_widget parameter (only replacing once to ensure only the outer most wrapper element gets the CSS class adjustment)
                         $params[0]['before_widget'] = preg_replace('/<div class="in front-page-widget-in cf">/', '', $params[0]['before_widget'], 1);
                         // Adjust the after_widget parameter (only replacing once to ensure only the outer most wrapper element gets the CSS class adjustment)
                         $params[0]['after_widget'] = preg_replace('/<\\/div>/', '', $params[0]['after_widget'], 1);
                     }
                 }
             }
         }
     }
     return $params;
 }
Ejemplo n.º 6
0
 function add_custom_widget_classes($params)
 {
     switch (_get_widget_id_base($params[0]['widget_id'])) {
         case 'product_categories':
             $params[0]['before_widget'] = str_replace('widget_product_categories', 'widget_product_categories g1-links', $params[0]['before_widget']);
             break;
     }
     return $params;
 }
Ejemplo n.º 7
0
 /**
  * This function sets up Note Widget localize data.
  */
 public function setup_note_widget_localize_data()
 {
     global $wp_registered_widgets;
     $note_widget = Note_Widget();
     // Note Widget instance
     // Re-add the widgets key if it doesn't exist (due to filtering above)
     if (!isset($this->note_localize['widgets'])) {
         $this->note_localize['widgets'] = array('defaults' => array(), 'settings' => array(), 'templates' => array());
     }
     // Setup the defaults data
     $this->note_localize['widgets']['defaults'] = $note_widget->defaults;
     // Setup the template data
     $this->note_localize['widgets']['templates'] = $note_widget->templates;
     // Setup the background image CSS
     $this->note_localize['widgets']['background_image_css'] = $note_widget->background_image_css;
     // Find Note Widgets in sidebars
     // TODO: The following logic will fetch data for all Note Widgets in all sidebars, can we just output data for displayed widgets?
     $sidebars_widgets = wp_get_sidebars_widgets();
     $note_widget_settings = array();
     if (is_array($sidebars_widgets)) {
         // Loop through sidebars
         foreach ($sidebars_widgets as $sidebar => $widgets) {
             // Ignore inactive or orphaned
             if ($sidebar !== 'wp_inactive_widgets' && substr($sidebar, 0, 16) !== 'orphaned_widgets' && is_array($widgets)) {
                 // Loop through widgets
                 foreach ($widgets as $widget) {
                     // Verify that this is a Note Widget
                     if ($note_widget->id_base === _get_widget_id_base($widget)) {
                         // Make sure this widget has a callback
                         if (isset($wp_registered_widgets[$widget])) {
                             // Store a reference to this widget object
                             $wp_widget = $wp_registered_widgets[$widget];
                             $widget_number = $wp_widget['params'][0]['number'];
                             // Store a reference to the widget settings (all Note Widgets)
                             if (empty($note_widget_settings)) {
                                 $note_widget_settings = $note_widget->get_settings();
                             }
                             // Find this widget in settings
                             if (array_key_exists($widget_number, $note_widget_settings)) {
                                 // Widget settings (parse with Note Widget defaults to prevent PHP warnings and missing setting values)
                                 $this->note_localize['widgets']['settings'][$widget_number] = wp_parse_args((array) $note_widget_settings[$widget_number], $note_widget->defaults);
                                 // Store a reference to the widget number
                                 $this->note_localize['widgets']['settings'][$widget_number]['widget_number'] = $widget_number;
                                 // Store a reference to the widget ID
                                 $this->note_localize['widgets']['settings'][$widget_number]['widget_id'] = $widget;
                                 // Store a reference to the sidebar ID
                                 $this->note_localize['widgets']['settings'][$widget_number]['sidebar_id'] = $sidebar;
                             }
                         }
                     }
                 }
             }
         }
     }
     // Allow for filtering of localization widget data
     $this->note_localize['widgets'] = apply_filters('note_localize_widgets', $this->note_localize['widgets'], $this);
 }
Ejemplo n.º 8
0
function wp_register_sidebar_widget($id, $name, $output_callback, $options = array())
{
    global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks;
    $id = strtolower($id);
    if (empty($output_callback)) {
        unset($wp_registered_widgets[$id]);
        return;
    }
    $id_base = _get_widget_id_base($id);
    if (in_array($output_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($output_callback)) {
        unset($wp_registered_widget_controls[$id]);
        unset($wp_registered_widget_updates[$id_base]);
        return;
    }
    $defaults = array('classname' => $output_callback);
    $options = wp_parse_args($options, $defaults);
    $widget = array('name' => $name, 'id' => $id, 'callback' => $output_callback, 'params' => array_slice(func_get_args(), 4));
    $widget = array_merge($widget, $options);
    if (is_callable($output_callback) && (!isset($wp_registered_widgets[$id]) || did_action('widgets_init'))) {
        do_action('wp_register_sidebar_widget', $widget);
        $wp_registered_widgets[$id] = $widget;
    }
}
Ejemplo n.º 9
0
function nm_add_woocommerce_widget_ids($sidebars_widgets, $old_sidebars_widgets = array())
{
    $shop_sidebar_id = 'widgets-shop';
    $shop_widgets = $sidebars_widgets[$shop_sidebar_id];
    if (is_array($shop_widgets)) {
        foreach ($shop_widgets as $widget) {
            $widget_id = _get_widget_id_base($widget);
            if ($widget_id === 'nm_woocommerce_price_filter') {
                $sidebars_widgets[$shop_sidebar_id][] = 'woocommerce_price_filter-12345';
            } else {
                if ($widget_id === 'nm_woocommerce_color_filter') {
                    $sidebars_widgets[$shop_sidebar_id][] = 'woocommerce_layered_nav-12345';
                }
            }
        }
    }
    return $sidebars_widgets;
}
Ejemplo n.º 10
0
function g1_add_custom_widget_classes($params)
{
    switch (_get_widget_id_base($params[0]['widget_id'])) {
        case 'archives':
        case 'categories':
        case 'meta':
        case 'links':
        case 'pages':
        case 'recent-posts':
        case 'nav_menu':
            $params[0]['before_widget'] = str_replace('g1-widget--cssclass', 'g1-links', $params[0]['before_widget']);
            break;
    }
    return $params;
}
 function udesign_woocommerce_filter_widget($params)
 {
     switch (_get_widget_id_base($params[0]['widget_id'])) {
         case 'woocommerce_login':
         case 'product_categories':
             $params[0]['before_widget'] = str_replace('substitute_widget_class', 'custom-formatting', $params[0]['before_widget']);
             // add the 'custom-formatting' class
             return $params;
             break;
         default:
             return $params;
     }
 }
Ejemplo n.º 12
0
function filter_widget($params)
{
    switch (_get_widget_id_base($params[0]['widget_id'])) {
        case 'recent-posts':
        case 'categories':
        case 'archives':
        case 'pages':
        case 'links':
        case 'meta':
        case 'custom-category-widget':
            // U-Design: Custom Category
        // U-Design: Custom Category
        case 'loginform-widget':
            // U-Design: Login Form
        // U-Design: Login Form
        case 'subpages-widget':
            // U-Design: Subpages
        // U-Design: Subpages
        case 'nav_menu':
            // WP 3 widget menu support
            $params[0]['before_widget'] = str_replace('substitute_widget_class', 'custom-formatting', $params[0]['before_widget']);
            // add the 'custom-formatting' class
            return $params;
            break;
        case 'rss':
            $params[0]['before_widget'] = str_replace('substitute_widget_class', 'custom-rss-formatting', $params[0]['before_widget']);
            // add the 'custom-formatting' class
            return $params;
            break;
        default:
            //var_dump( _get_widget_id_base($params[0]['widget_id']) );
            //var_dump( $params );
            return $params;
    }
}