bcn_widget

The Breadcrumb NavXT bcn widget class.

Defined (1)

The class is defined in the following location(s).

/class.bcn_widget.php  
  1. class bcn_widget extends WP_Widget 
  2. const version = '5.6.0'; 
  3. protected $defaults = array('title' => '', 'pretext' => '', 'type' => 'microdata', 'linked' => true, 'reverse' => false, 'front' => false, 'force' => false); 
  4. //Default constructor 
  5. function __construct() 
  6. //@see https://core.trac.wordpress.org/ticket/10527 
  7. if(!is_textdomain_loaded('breadcrumb-navxt')) 
  8. load_plugin_textdomain('breadcrumb-navxt', false, 'breadcrumb-navxt/languages'); 
  9. $ops = array('classname' => 'widget_breadcrumb_navxt', 'description' => __('Adds a breadcrumb trail to your sidebar', 'breadcrumb-navxt')); 
  10. parent::__construct('bcn_widget', 'Breadcrumb NavXT', $ops); 
  11. function widget($args, $instance) 
  12. //Make sure we grab defaults in the case of out of date instance settings being sent 
  13. $instance = wp_parse_args((array) $instance, $this->defaults); 
  14. $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); 
  15. $instance['pretext'] = apply_filters('widget_text', $instance['pretext'], $instance); 
  16. //A bit of a hack but we need the DB settings to know if we should exit early 
  17. $opt = get_option('bcn_options'); 
  18. //If we are on the front page and don't display on the front, return early 
  19. if($instance['front'] && is_front_page() && !(is_paged() && $opt['bpaged_display'])) 
  20. return; 
  21. //Manditory before widget junk 
  22. echo $args['before_widget']; 
  23. if(!empty($instance['title'])) 
  24. echo $args['before_title'] . $instance['title'] . $args['after_title']; 
  25. //We'll want to switch between the two breadcrumb output types 
  26. if($instance['type'] == 'list') 
  27. //Display the list output breadcrumb 
  28. echo $instance['pretext'] . '<ol class="breadcrumb_trail breadcrumbs">'; 
  29. bcn_display_list(false, $instance['linked'], $instance['reverse'], $instance['force']); 
  30. echo '</ol>'; 
  31. else if($instance['type'] == 'microdata') 
  32. echo '<div class="breadcrumbs" vocab="https://schema.org/" typeof="BreadcrumbList">' . $instance['pretext']; 
  33. //Display the regular output breadcrumb 
  34. bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']); 
  35. echo '</div>'; 
  36. else if($instance['type'] == 'plain') 
  37. //Display the pretext 
  38. echo $instance['pretext']; 
  39. //Display the regular output breadcrumb 
  40. bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']); 
  41. else 
  42. //If we recieved a type that is not of the built in displays, it must be relegated to an extension plugin 
  43. do_action('bcn_widget_display_trail', $instance); 
  44. //Manditory after widget junk 
  45. echo $args['after_widget']; 
  46. function update($new_instance, $old_instance) 
  47. //Filter out anything that could be invalid 
  48. $old_instance['title'] = strip_tags($new_instance['title']); 
  49. $old_instance['pretext'] = strip_tags($new_instance['pretext']); 
  50. $old_instance['type'] = strip_tags($new_instance['type']); 
  51. $old_instance['linked'] = isset($new_instance['linked']); 
  52. $old_instance['reverse'] = isset($new_instance['reverse']); 
  53. $old_instance['front'] = isset($new_instance['front']); 
  54. $old_instance['force'] = isset($new_instance['force']); 
  55. return $old_instance; 
  56. function form($instance) 
  57. $instance = wp_parse_args((array) $instance, $this->defaults);?> 
  58. <p> 
  59. <label for="<?php echo $this->get_field_id('title'); ?>"> <?php _e('Title:', 'breadcrumb-navxt'); ?></label> 
  60. <input class="widefat" type="text" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" value="<?php echo esc_attr($instance['title']);?>" /> 
  61. </p> 
  62. <p> 
  63. <label for="<?php echo $this->get_field_id('pretext'); ?>"> <?php _e('Text to show before the trail:', 'breadcrumb-navxt'); ?></label> 
  64. <input class="widefat" type="text" name="<?php echo $this->get_field_name('pretext'); ?>" id="<?php echo $this->get_field_id('pretext'); ?>" value="<?php echo esc_attr($instance['pretext']);?>" /> 
  65. </p> 
  66. <p> 
  67. <label for="<?php echo $this->get_field_id('type'); ?>"> <?php _e('Output trail as:', 'breadcrumb-navxt'); ?></label> 
  68. <select name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>"> 
  69. <option value="list" <?php selected('list', $instance['type']);?>><?php _e('List', 'breadcrumb-navxt'); ?></option> 
  70. <option value="microdata" <?php selected('microdata', $instance['type']);?>><?php _e('Google (RDFa) Breadcrumbs', 'breadcrumb-navxt'); ?></option> 
  71. <option value="plain" <?php selected('plain', $instance['type']);?>><?php _e('Plain', 'breadcrumb-navxt'); ?></option> 
  72. <?php do_action('bcn_widget_display_types', $instance);?> 
  73. </select> 
  74. </p> 
  75. <p> 
  76. <input class="checkbox" type="checkbox" name="<?php echo $this->get_field_name('linked'); ?>" id="<?php echo $this->get_field_id('linked'); ?>" value="true" <?php checked(true, $instance['linked']);?> /> 
  77. <label for="<?php echo $this->get_field_id('linked'); ?>"> <?php _e('Link the breadcrumbs', 'breadcrumb-navxt'); ?></label><br /> 
  78. <input class="checkbox" type="checkbox" name="<?php echo $this->get_field_name('reverse'); ?>" id="<?php echo $this->get_field_id('reverse'); ?>" value="true" <?php checked(true, $instance['reverse']);?> /> 
  79. <label for="<?php echo $this->get_field_id('reverse'); ?>"> <?php _e('Reverse the order of the trail', 'breadcrumb-navxt'); ?></label><br /> 
  80. <input class="checkbox" type="checkbox" name="<?php echo $this->get_field_name('front'); ?>" id="<?php echo $this->get_field_id('front'); ?>" value="true" <?php checked(true, $instance['front']);?> /> 
  81. <label for="<?php echo $this->get_field_id('front'); ?>"> <?php _e('Hide the trail on the front page', 'breadcrumb-navxt'); ?></label><br /> 
  82. <input class="checkbox" type="checkbox" name="<?php echo $this->get_field_name('force'); ?>" id="<?php echo $this->get_field_id('force'); ?>" value="true" <?php checked(true, $instance['force']);?> /> 
  83. <label for="<?php echo $this->get_field_id('force'); ?>"> <?php _e('Ignore breadcrumb cache', 'breadcrumb-navxt'); ?></label><br /> 
  84. </p> 
  85. <?php