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