Conditions | 22 |
Paths | 26 |
Total Lines | 107 |
Code Lines | 79 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 |
||
61 | public function render( $field, $value, $object_id, $object_type, $field_type ) { |
||
62 | $this->setup_admin_scripts(); |
||
63 | $field_name = $field->_name(); |
||
64 | |||
65 | if ( $field->args( 'limit' ) > 1 ) { |
||
66 | echo '<ul class="cmb-post-search-ajax-results" id="' . $field_name . '_results">'; |
||
67 | if ( isset( $value ) && ! empty( $value ) ) { |
||
68 | |||
69 | if ( ! is_array( $value ) ) { |
||
70 | $value = explode( ',', $value ); |
||
71 | } |
||
72 | if ( ! is_array( $value ) ) { |
||
73 | $value = array( $value ); |
||
74 | } |
||
75 | $value = array_unique( $value ); |
||
76 | foreach ( $value as $val ) { |
||
77 | $handle = ( $field->args( 'sortable' ) ) ? '<span class="hndl"></span>' : ''; |
||
78 | $li_css = ''; |
||
79 | if ( $field->args( 'object_type' ) == 'user' ) { |
||
80 | $guid = get_edit_user_link( $val ); |
||
81 | $user = get_userdata( $val ); |
||
82 | $title = $user->display_name; |
||
83 | } else { |
||
84 | $guid = get_edit_post_link( $val ); |
||
85 | $title = get_the_title( $val ) . ' - ' . '#' . $val; |
||
86 | if ( 'trash' === get_post_status( $val ) ) { |
||
87 | $li_css = 'display:none;'; |
||
88 | } |
||
89 | $post_parent = wp_get_post_parent_id( $val ); |
||
90 | if ( 0 !== $post_parent && false !== $post_parent ) { |
||
91 | $title = get_the_title( $post_parent ) . ' -> ' . $title; |
||
92 | } |
||
93 | } |
||
94 | echo '<li style="' . $li_css . '">' . $handle . '<input type="hidden" name="' . $field_name . '_results[]" value="' . $val . '"><a href="' . $guid . '" target="_blank" class="edit-link">' . $title . '</a><a class="remover"><span class="dashicons dashicons-no"></span><span class="dashicons dashicons-dismiss"></span></a></li>'; |
||
95 | } |
||
96 | } |
||
97 | echo '</ul>'; |
||
98 | $field_value = ''; |
||
99 | if ( isset( $field->group ) ) { |
||
100 | $store_name = str_replace( '][', '_', $field_name ); |
||
101 | $store_name = str_replace( ']', '', $store_name ); |
||
102 | $store_name = str_replace( '[', '_', $store_name ); |
||
103 | |||
104 | echo $field_type->input( |
||
105 | array( |
||
106 | 'type' => 'hidden', |
||
107 | 'id' => $field_name . '_store', |
||
108 | 'name' => $store_name . '_store', |
||
109 | 'class' => 'cmb-post-search-ajax-store', |
||
110 | 'value' => implode( ',', $value ), |
||
111 | 'desc' => false, |
||
112 | ) |
||
113 | ); |
||
114 | } |
||
115 | } else { |
||
116 | if ( is_array( $value ) ) { |
||
117 | $value = $value[0]; |
||
118 | } |
||
119 | if ( $field->args( 'object_type' ) == 'user' ) { |
||
120 | $field_value = ( $value ? get_userdata( $value )->display_name : '' ); |
||
121 | } else { |
||
122 | $field_value = ( $value ? get_the_title( $value ) : '' ); |
||
123 | } |
||
124 | echo $field_type->input( |
||
125 | array( |
||
126 | 'type' => 'hidden', |
||
127 | 'name' => $field_name . '_results', |
||
128 | 'value' => $value, |
||
129 | 'desc' => false, |
||
130 | ) |
||
131 | ); |
||
132 | if ( isset( $field->group ) ) { |
||
133 | $store_name = str_replace( '][', '_', $field_name ); |
||
134 | $store_name = str_replace( ']', '', $store_name ); |
||
135 | $store_name = str_replace( '[', '_', $store_name ); |
||
136 | |||
137 | echo $field_type->input( |
||
138 | array( |
||
139 | 'type' => 'hidden', |
||
140 | 'id' => $field_name . '_store', |
||
141 | 'name' => $store_name . '_store', |
||
142 | 'class' => 'cmb-post-search-ajax-store', |
||
143 | 'value' => $value, |
||
144 | 'desc' => false, |
||
145 | ) |
||
146 | ); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | echo $field_type->input( |
||
151 | array( |
||
152 | 'type' => 'text', |
||
153 | 'name' => $field_name, |
||
154 | 'id' => $field_name, |
||
155 | 'class' => 'cmb-post-search-ajax', |
||
156 | 'value' => $field_value, |
||
157 | 'desc' => false, |
||
158 | 'data-limit' => $field->args( 'limit' ) ? $field->args( 'limit' ) : '1', |
||
159 | 'data-sortable' => $field->args( 'sortable' ) ? $field->args( 'sortable' ) : '0', |
||
160 | 'data-object' => $field->args( 'object_type' ) ? $field->args( 'object_type' ) : 'post', |
||
161 | 'data-queryargs'=> $field->args( 'query_args' ) ? htmlspecialchars( json_encode( $field->args( 'query_args' ) ), ENT_QUOTES, 'UTF-8' ) : '' |
||
162 | ) |
||
163 | ); |
||
164 | |||
165 | echo '<img src="' . admin_url( 'images/spinner.gif' ) . '" class="cmb-post-search-ajax-spinner" />'; |
||
166 | |||
167 | $field_type->_desc( true, true ); |
||
168 | |||
337 |