| Conditions | 3 |
| Paths | 4 |
| Total Lines | 46 |
| Code Lines | 25 |
| Lines | 9 |
| Ratio | 19.57 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 18 | public function render( $atts ) { |
||
| 19 | |||
| 20 | // Extract attributes and set default values. |
||
| 21 | $shortcode_atts = shortcode_atts( array( |
||
| 22 | 'title' => __( 'Related articles', 'wordlift' ), |
||
| 23 | 'with_carousel' => TRUE, |
||
| 24 | 'squared_thumbs' => FALSE |
||
| 25 | ), $atts ); |
||
| 26 | |||
| 27 | View Code Duplication | foreach ( |
|
|
|
|||
| 28 | array( |
||
| 29 | 'with_carousel', |
||
| 30 | 'squared_thumbs' |
||
| 31 | ) as $att |
||
| 32 | ) { |
||
| 33 | |||
| 34 | // See http://wordpress.stackexchange.com/questions/119294/pass-boolean-value-in-shortcode |
||
| 35 | $shortcode_atts[ $att ] = filter_var( |
||
| 36 | $shortcode_atts[ $att ], FILTER_VALIDATE_BOOLEAN |
||
| 37 | ); |
||
| 38 | } |
||
| 39 | |||
| 40 | // avoid building the widget when there is a list of posts. |
||
| 41 | if ( ! is_single() ) { |
||
| 42 | return ''; |
||
| 43 | } |
||
| 44 | |||
| 45 | $current_post = get_post(); |
||
| 46 | |||
| 47 | // Enqueue common shortcode scripts. |
||
| 48 | $this->enqueue_scripts(); |
||
| 49 | |||
| 50 | wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
||
| 51 | |||
| 52 | $navigator_id = uniqid( 'wl-navigator-widget-' ); |
||
| 53 | |||
| 54 | wp_localize_script( 'wordlift-ui', 'wl_navigator_params', array( |
||
| 55 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
||
| 56 | 'action' => 'wl_navigator', |
||
| 57 | 'post_id' => $current_post->ID, |
||
| 58 | 'attrs' => $shortcode_atts |
||
| 59 | ) |
||
| 60 | ); |
||
| 61 | |||
| 62 | return "<div id='$navigator_id' class='wl-navigator-widget'></div>"; |
||
| 63 | } |
||
| 64 | |||
| 66 |
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.