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