| Conditions | 18 |
| Paths | 15 |
| Total Lines | 54 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 85 | public function sharing_buttons( $buttons = array( 'facebook', 'twitter', 'pinterest' ), $echo = false, $post_id = false ) { |
||
| 86 | $sharing_content = ''; |
||
| 87 | |||
| 88 | if ( ( is_preview() || is_admin() ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
||
| 89 | return ''; |
||
| 90 | } |
||
| 91 | |||
| 92 | //Set our variables |
||
| 93 | global $post; |
||
| 94 | $share_post = $post; |
||
| 95 | if ( false !== $post_id ) { |
||
| 96 | $share_post = get_post( $post_id ); |
||
| 97 | $post_type = get_post_type( $post_id ); |
||
| 98 | } else { |
||
| 99 | $post_type = get_post_type(); |
||
| 100 | } |
||
| 101 | |||
| 102 | if ( \lsx\sharing\includes\functions\is_disabled() || \lsx\sharing\includes\functions\is_pt_disabled( $post_type ) ) { |
||
| 103 | return ''; |
||
| 104 | } |
||
| 105 | |||
| 106 | if ( ( is_array( $buttons ) && count( $buttons ) > 0 ) ) { |
||
| 107 | $sharing_content .= '<div class="lsx-sharing-content"><p>'; |
||
| 108 | |||
| 109 | $sharing_text = \lsx\sharing\includes\functions\get_sharing_text( $post_type ); |
||
| 110 | if ( '' !== $sharing_text ) { |
||
| 111 | $sharing_content .= '<span class="lsx-sharing-label">' . $sharing_text . '</span>'; |
||
| 112 | } |
||
| 113 | |||
| 114 | foreach ( $buttons as $id => $button ) { |
||
| 115 | $button_obj = new \lsx\sharing\classes\frontend\Button( $button, $this->options, $post_type ); |
||
| 116 | |||
| 117 | if ( ! empty( $button_obj ) ) { |
||
| 118 | $url = $button_obj->get_link( $share_post ); |
||
| 119 | |||
| 120 | if ( ! empty( $url ) ) { |
||
| 121 | if ( 'email' === $button ) { |
||
| 122 | if ( ! isset( $this->options['display'] ) || empty( $this->options['display']['sharing_email_form_id'] ) ) { |
||
| 123 | continue; |
||
| 124 | } |
||
| 125 | $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>'; |
||
| 126 | } else { |
||
| 127 | $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>'; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } |
||
| 132 | $sharing_content .= '</p></div>'; |
||
| 133 | } |
||
| 134 | |||
| 135 | if ( $echo ) { |
||
| 136 | echo wp_kses_post( $sharing_content ); |
||
| 137 | } else { |
||
| 138 | return $sharing_content; |
||
| 139 | } |
||
| 178 |