Conditions | 11 |
Paths | 22 |
Total Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
107 | function enqueue_style_to_persist($style_handle, $src, $deps = array(), $ver = false, $media = 'all') { |
||
108 | global $wp_query, $enqueued_foogallery_styles, $foogallery_styles_to_persist; |
||
109 | |||
110 | //we only want to do this if we are looking at a single post |
||
111 | if ( ! is_singular() ) { |
||
112 | return; |
||
113 | } |
||
114 | |||
115 | $post_id = $wp_query->post->ID; |
||
116 | if ( $post_id ) { |
||
117 | |||
118 | //check if the saved stylesheet needs to be cache busted |
||
119 | if ( is_array( $enqueued_foogallery_styles ) && array_key_exists( $style_handle, $enqueued_foogallery_styles ) ) { |
||
120 | $registered_cache_buster_key = $enqueued_foogallery_styles[$style_handle]; |
||
121 | |||
122 | //generate the key we want |
||
123 | $cache_buster_key = $this->create_cache_buster_key( $style_handle, $ver, home_url() ); |
||
124 | |||
125 | if ( $registered_cache_buster_key !== $cache_buster_key ) { |
||
126 | //we need to bust this cached stylesheet! |
||
127 | $style = $this->get_old_style_post_meta_value( $post_id, $style_handle ); |
||
128 | |||
129 | if ( false !== $style ) { |
||
130 | delete_post_meta( $post_id, FOOGALLERY_META_POST_USAGE_CSS, array( $style_handle => $style ) ); |
||
131 | |||
132 | //unset the handle from, to force the save of the post meta |
||
133 | unset( $enqueued_foogallery_styles[$style_handle] ); |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | |||
138 | //first check that the template has not been enqueued before |
||
139 | if ( is_array( $enqueued_foogallery_styles ) && ! array_key_exists( $style_handle, $enqueued_foogallery_styles ) ) { |
||
140 | |||
141 | $style = array( |
||
142 | 'src' => $src, |
||
143 | 'deps' => $deps, |
||
144 | 'ver' => $ver, |
||
145 | 'media' => $media, |
||
146 | 'site' => home_url() |
||
147 | ); |
||
148 | |||
149 | if ( !is_array( $foogallery_styles_to_persist ) ) { |
||
150 | $foogallery_styles_to_persist = array(); |
||
151 | } |
||
152 | |||
153 | if ( !array_key_exists( $style_handle, $foogallery_styles_to_persist ) ) { |
||
154 | $foogallery_styles_to_persist[$style_handle] = $style; |
||
155 | } |
||
156 | |||
157 | // add_post_meta( $post_id, FOOGALLERY_META_POST_USAGE_CSS, array( $style_handle => $style ), false ); |
||
158 | // |
||
159 | // $cache_buster_key = $this->create_cache_buster_key( $style_handle, $ver, home_url() ); |
||
160 | // $enqueued_foogallery_styles[$style_handle] = $cache_buster_key; |
||
161 | } |
||
162 | } |
||
163 | } |
||
164 | |||
187 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.