woothemes /
sensei
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. |
||
| 3 | |||
| 4 | /** |
||
| 5 | * Sensei Course Categories Widget |
||
| 6 | * |
||
| 7 | * A WooThemes Sensei Course Categories widget. |
||
| 8 | * |
||
| 9 | * @package Views |
||
| 10 | * @subpackage Widgets |
||
| 11 | * @author Automattic |
||
| 12 | * |
||
| 13 | * @since 1.1.0 |
||
| 14 | */ |
||
| 15 | class WooThemes_Sensei_Course_Categories_Widget extends WP_Widget {
|
||
| 16 | protected $woo_widget_cssclass; |
||
| 17 | protected $woo_widget_description; |
||
| 18 | protected $woo_widget_idbase; |
||
| 19 | protected $woo_widget_title; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Constructor function. |
||
| 23 | * @since 1.1.0 |
||
| 24 | * @return void |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Adding a
@return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.
Adding a Please refer to the PHP core documentation on constructors. Loading history...
|
|||
| 25 | */ |
||
| 26 | View Code Duplication | public function __construct() {
|
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 27 | /* Widget variable settings. */ |
||
| 28 | $this->woo_widget_cssclass = 'widget_sensei_course_categories'; |
||
| 29 | $this->woo_widget_description = __( 'This widget will output a list of Course Categories.', 'woothemes-sensei' ); |
||
| 30 | $this->woo_widget_idbase = 'sensei_course_categories'; |
||
| 31 | $this->woo_widget_title = __( 'Sensei - Course Categories', 'woothemes-sensei' ); |
||
| 32 | |||
| 33 | /* Widget settings. */ |
||
| 34 | $widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description ); |
||
| 35 | |||
| 36 | /* Widget control settings. */ |
||
| 37 | $control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase ); |
||
| 38 | |||
| 39 | /* Create the widget. */ |
||
| 40 | parent::__construct( $this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops ); |
||
| 41 | } // End __construct() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Display the widget on the frontend. |
||
| 45 | * @since 1.1.0 |
||
| 46 | * @param array $args Widget arguments. |
||
| 47 | * @param array $instance Widget settings for this instance. |
||
| 48 | * @return void |
||
| 49 | */ |
||
| 50 | public function widget( $args, $instance ) {
|
||
| 51 | |||
| 52 | $before_widget = $args[ 'before_widget' ]; |
||
| 53 | $before_title = $args[ 'before_title' ]; |
||
| 54 | $after_title = $args[ 'after_title' ]; |
||
| 55 | $after_widget = $args[ 'after_widget' ]; |
||
| 56 | |||
| 57 | /* Our variables from the widget settings. */ |
||
| 58 | $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base );
|
||
| 59 | |||
| 60 | /* Before widget (defined by themes). */ |
||
| 61 | echo $before_widget; |
||
| 62 | |||
| 63 | /* Display the widget title if one was input (before and after defined by themes). */ |
||
| 64 | if ( $title ) { echo $before_title . $title . $after_title; }
|
||
| 65 | |||
| 66 | /* Widget content. */ |
||
| 67 | // Add actions for plugins/themes to hook onto. |
||
| 68 | do_action( $this->woo_widget_cssclass . '_top' ); |
||
| 69 | |||
| 70 | $this->load_component( $instance ); |
||
| 71 | |||
| 72 | // Add actions for plugins/themes to hook onto. |
||
| 73 | do_action( $this->woo_widget_cssclass . '_bottom' ); |
||
| 74 | |||
| 75 | /* After widget (defined by themes). */ |
||
| 76 | echo $after_widget; |
||
| 77 | |||
| 78 | } // End widget() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Method to update the settings from the form() method. |
||
| 82 | * @since 1.1.0 |
||
| 83 | * @param array $new_instance New settings. |
||
| 84 | * @param array $old_instance Previous settings. |
||
| 85 | * @return array Updated settings. |
||
| 86 | */ |
||
| 87 | public function update ( $new_instance, $old_instance ) {
|
||
| 88 | $instance = $old_instance; |
||
| 89 | |||
| 90 | /* Strip tags for title and name to remove HTML (important for text inputs). */ |
||
| 91 | $instance['title'] = strip_tags( $new_instance['title'] ); |
||
| 92 | |||
| 93 | /* The select box is returning a text value, so we escape it. */ |
||
| 94 | $instance['limit'] = esc_attr( $new_instance['limit'] ); |
||
| 95 | |||
| 96 | /* The check box is returning a boolean value. */ |
||
| 97 | $instance['count'] = $new_instance['count']; |
||
| 98 | $instance['hierarchical'] = $new_instance['hierarchical']; |
||
| 99 | |||
| 100 | return $instance; |
||
| 101 | } // End update() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * The form on the widget control in the widget administration area. |
||
| 105 | * Make use of the get_field_id() and get_field_name() function when creating your form elements. This handles the confusing stuff. |
||
| 106 | * @since 1.1.0 |
||
| 107 | * @param array $instance The settings for this instance. |
||
| 108 | * @return void |
||
| 109 | */ |
||
| 110 | public function form( $instance ) {
|
||
| 111 | |||
| 112 | /* Set up some default widget settings. */ |
||
| 113 | /* Make sure all keys are added here, even with empty string values. */ |
||
| 114 | $defaults = array( |
||
| 115 | 'title' => '', |
||
| 116 | 'limit' => 3, |
||
| 117 | 'count' => false, |
||
| 118 | 'hierarchical' => false |
||
| 119 | ); |
||
| 120 | |||
| 121 | $instance = wp_parse_args( (array) $instance, $defaults ); |
||
| 122 | ?> |
||
| 123 | <!-- Widget Title: Text Input --> |
||
| 124 | <p> |
||
| 125 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title (optional):', 'woothemes-sensei' ); ?></label> |
||
| 126 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" /> |
||
| 127 | </p> |
||
| 128 | <!-- Widget Limit: Text Input --> |
||
| 129 | <p> |
||
| 130 | <label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php _e( 'Number of Categories (optional):', 'woothemes-sensei' ); ?></label> |
||
| 131 | <input type="text" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>" value="<?php echo esc_attr( $instance['limit'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" /> |
||
| 132 | </p> |
||
| 133 | <!-- Widget Show Count: Checkbox Input --> |
||
| 134 | <p> |
||
| 135 | <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id('count') ); ?>" name="<?php echo esc_attr( $this->get_field_name('count') ); ?>"<?php checked( $instance['count'], 'on' ); ?> />
|
||
| 136 | <label for="<?php echo esc_attr( $this->get_field_id('count') ); ?>"><?php _e( 'Show post counts', 'woothemes-sensei' ); ?></label><br />
|
||
| 137 | </p> |
||
| 138 | <!-- Widget Show Hierarchy: Checkbox Input --> |
||
| 139 | <p> |
||
| 140 | <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id('hierarchical') ); ?>" name="<?php echo esc_attr( $this->get_field_name('hierarchical') ); ?>"<?php checked( $instance['hierarchical'], 'on' ); ?> />
|
||
| 141 | <label for="<?php echo esc_attr( $this->get_field_id('hierarchical') ); ?>"><?php _e( 'Show hierarchy', 'woothemes-sensei' ); ?></label></p>
|
||
| 142 | </p> |
||
| 143 | <?php |
||
| 144 | } // End form() |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Load the output. |
||
| 148 | * @param array $instance |
||
| 149 | * @since 1.1.0 |
||
| 150 | * @return void |
||
| 151 | */ |
||
| 152 | protected function load_component ( $instance ) {
|
||
| 153 | |||
| 154 | $limit = intval( $instance['limit'] ); |
||
| 155 | $count = isset($instance['count']) ? (bool) $instance['count'] :false; |
||
| 156 | $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false; |
||
| 157 | |||
| 158 | $cat_args = array( 'title_li' => '', 'taxonomy' => 'course-category', 'orderby' => 'name', 'show_count' => $count, 'hierarchical' => $hierarchical); |
||
| 159 | if ( 0 < $limit ) {
|
||
| 160 | $cat_args[ 'number' ] = $limit; |
||
| 161 | } // End If Statement |
||
| 162 | echo '<ul>'; |
||
| 163 | wp_list_categories( apply_filters('widget_course_categories_args', $cat_args) );
|
||
| 164 | echo '</ul>'; |
||
| 165 | } // End load_component() |
||
| 166 | } // End Class |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.