Пример #1
0
 /**
  * Front-end display of widget
  *
  * Load template from parent or child theme if exists.
  *
  * @since 0.9
  * @param array $args Widget arguments
  * @param array $instance Widget instance
  */
 function widget($args, $instance)
 {
     global $post;
     // setup_postdata() needs this
     // Available widgets
     $widgets = ctfw_widgets();
     // Get template filename
     $template_file = $widgets[$this->id_base]['template_file'];
     // Check if template exists
     if ($template_path = locate_template(CTFW_THEME_WIDGET_DIR . '/' . $template_file)) {
         // false if does not exist
         // Sanitize widget instance (field values) before loading template
         $instance = $this->ctfw_sanitize($instance);
         // Make instance available to other methods used by template (e.g. get_posts())
         $this->ctfw_instance = $instance;
         // Load template with globals available (unlike locate_template())
         include $template_path;
     }
 }
Пример #2
0
/**
 * Filter widget fields
 *
 * Add filters for classes/widget.php to set visibility and override data on fields based on theme support.
 *
 * @since 0.9
 */
function ctfw_filter_widget_fields()
{
    // Loop widgets to filter their fields
    $widgets = ctfw_widgets();
    foreach ($widgets as $widget_id => $widget_data) {
        // Set Visible Fields
        add_filter('ctfw_widget_visible_fields-' . $widget_id, 'ctfw_set_visible_widget_fields', 10, 2);
        // Set Field Overrides
        add_filter('ctfw_widget_field_overrides-' . $widget_id, 'ctfw_set_widget_field_overrides', 10, 2);
    }
}