| Conditions | 19 |
| Paths | 29 |
| Total Lines | 58 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 97 | public function sharing_buttons( $buttons = array( 'facebook', 'twitter', 'pinterest' ), $echo = false, $post_id = false ) { |
||
| 98 | $sharing_content = ''; |
||
| 99 | |||
| 100 | if ( ( is_preview() || is_admin() ) && ! ( defined('DOING_AJAX') && DOING_AJAX ) ) { |
||
| 101 | return ''; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ( empty($this->options) ) { |
||
| 105 | $this->options = array(); |
||
| 106 | } |
||
| 107 | |||
| 108 | //Set our variables |
||
| 109 | global $post; |
||
| 110 | $share_post = $post; |
||
| 111 | if ( false !== $post_id ) { |
||
| 112 | $share_post = get_post($post_id); |
||
| 113 | $post_type = get_post_type($post_id); |
||
| 114 | } else { |
||
| 115 | $post_type = get_post_type(); |
||
| 116 | } |
||
| 117 | |||
| 118 | if ( \lsx\sharing\includes\functions\is_disabled() || \lsx\sharing\includes\functions\is_pt_disabled($post_type) ) { |
||
| 119 | return ''; |
||
| 120 | } |
||
| 121 | |||
| 122 | if ( ( is_array($buttons) && count($buttons) > 0 ) ) { |
||
| 123 | $sharing_content .= '<div class="lsx-sharing-content"><p>'; |
||
| 124 | |||
| 125 | $sharing_text = \lsx\sharing\includes\functions\get_sharing_text($post_type); |
||
| 126 | if ( '' !== $sharing_text ) { |
||
| 127 | $sharing_content .= '<span class="lsx-sharing-label">' . $sharing_text . '</span>'; |
||
| 128 | } |
||
| 129 | |||
| 130 | foreach ( $buttons as $id => $button ) { |
||
| 131 | $button_obj = new \lsx\sharing\classes\frontend\Button($button, $this->options, $post_type); |
||
| 132 | |||
| 133 | if ( ! empty($button_obj) ) { |
||
| 134 | $url = $button_obj->get_link($share_post); |
||
| 135 | |||
| 136 | if ( ! empty($url) ) { |
||
| 137 | if ( 'email' === $button ) { |
||
| 138 | if ( ! isset($this->options['display']) || empty($this->options['display']['sharing_email_form_id']) ) { |
||
| 139 | continue; |
||
| 140 | } |
||
| 141 | $sharing_content .= '<span class="lsx-sharing-button lsx-sharing-button-' . esc_attr($button) . '"><a href="#lsx-sharing-email" data-toggle="modal" data-link="' . esc_url($url) . '"><span class="fa" aria-hidden="true"></span></a></span>'; |
||
| 142 | } else { |
||
| 143 | $sharing_content .= '<span class="lsx-sharing-button lsx-sharing-button-' . esc_attr($button) . '"><a href="' . esc_url($url) . '" target="_blank" rel="noopener noreferrer"><span class="fa" aria-hidden="true"></span></a></span>'; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | $sharing_content .= '</p></div>'; |
||
| 149 | } |
||
| 150 | |||
| 151 | if ( $echo ) { |
||
| 152 | echo wp_kses_post($sharing_content); |
||
| 153 | } else { |
||
| 154 | return $sharing_content; |
||
| 155 | } |
||
| 232 |