Conditions | 6 |
Paths | 32 |
Total Lines | 130 |
Lines | 20 |
Ratio | 15.38 % |
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 |
||
99 | public function get_settings() { |
||
100 | global $blog_id; |
||
101 | |||
102 | $settings = array(); |
||
103 | |||
104 | $settings[] = array( |
||
105 | 'title' => esc_html__( 'Theme Selectors', 'auto-load-next-post' ), |
||
106 | 'type' => 'title', |
||
107 | 'desc' => sprintf( esc_html__( 'Here you set the theme selectors below according to your active theme. All are required for %s to work.', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ), |
||
108 | 'id' => 'theme_selectors_options' |
||
109 | ); |
||
110 | |||
111 | // Provide the theme customizer option if theme is not already supported. |
||
112 | if ( ! is_alnp_supported() ) { |
||
113 | $query = array( |
||
114 | 'autofocus[panel]' => 'alnp', |
||
115 | 'autofocus[section]' => 'auto_load_next_post_theme_selectors', |
||
116 | 'url' => alnp_get_random_page_permalink(), |
||
117 | 'return' => add_query_arg( array( 'page' => 'auto-load-next-post', 'view' => 'theme-selectors' ), admin_url( 'options-general.php' ) ), |
||
118 | ); |
||
119 | $customizer_link = add_query_arg( $query, admin_url( 'customize.php' ) ); |
||
120 | |||
121 | $settings[] = array( |
||
122 | 'title' => esc_html__( 'Theme Customizer', 'auto-load-next-post' ), |
||
123 | 'desc' => esc_html__( 'Use the theme customizer to enter the theme selectors while you inspect the theme.', 'auto-load-next-post' ), |
||
124 | 'id' => 'auto_load_next_post_customizer', |
||
125 | 'value' => esc_html__( 'Open Theme Customizer', 'auto-load-next-post' ), |
||
126 | 'url' => $customizer_link, |
||
127 | 'type' => 'button' |
||
128 | ); |
||
129 | } |
||
130 | |||
131 | // Defines input field status |
||
132 | $container_readonly = 'no'; |
||
133 | $post_title_readonly = 'no'; |
||
134 | $post_navigation_readonly = 'no'; |
||
135 | $comments_container_readonly = 'no'; |
||
136 | |||
137 | // Defines if we should show default selector. |
||
138 | $container_default = ''; |
||
139 | $post_title_default = ''; |
||
140 | $post_navigation_default = ''; |
||
141 | $comments_container_default = ''; |
||
142 | |||
143 | // Checks if the Content Container selector has been set by theme support. |
||
144 | View Code Duplication | if ( ! empty( alnp_get_theme_support( 'content_container' ) ) ) { |
|
145 | $container_readonly = 'yes'; |
||
146 | } else { |
||
147 | $container_default = sprintf( __( 'Default: %s', 'auto-load-next-post' ), '<code>main.site-main</code>' ); |
||
148 | } |
||
149 | |||
150 | $settings[] = array( |
||
151 | 'title' => esc_html__( 'Content Container', 'auto-load-next-post' ), |
||
152 | 'desc' => sprintf( __( 'The primary container where the post content is loaded in. %s', 'auto-load-next-post' ), $container_default ), |
||
153 | 'id' => 'auto_load_next_post_content_container', |
||
154 | 'default' => 'main.site-main', |
||
155 | 'placeholder' => sprintf( esc_html__( 'e.g. %s', 'auto-load-next-post' ), 'main.site-main' ), |
||
156 | 'readonly' => $container_readonly, |
||
157 | 'type' => 'text', |
||
158 | 'css' => 'min-width:300px;', |
||
159 | 'class' => 'required', |
||
160 | 'autoload' => false |
||
161 | ); |
||
162 | |||
163 | // Checks if the Post Title selector has been set by theme support. |
||
164 | View Code Duplication | if ( ! empty( alnp_get_theme_support( 'title_selector' ) ) ) { |
|
165 | $post_title_readonly = 'yes'; |
||
166 | } else { |
||
167 | $post_title_default = sprintf( __( 'Default: %s', 'auto-load-next-post' ), '<code>h1.entry-title</code>' ); |
||
168 | } |
||
169 | |||
170 | $settings[] = array( |
||
171 | 'title' => esc_html__( 'Post Title', 'auto-load-next-post' ), |
||
172 | 'desc' => sprintf( __( 'Used to identify which article the user is reading and track should Google Analytics or other analytics be enabled. %s', 'auto-load-next-post' ), $post_title_default ), |
||
173 | 'id' => 'auto_load_next_post_title_selector', |
||
174 | 'default' => 'h1.entry-title', |
||
175 | 'placeholder' => sprintf( esc_html__( 'e.g. %s', 'auto-load-next-post' ), 'h1.entry-title' ), |
||
176 | 'readonly' => $post_title_readonly, |
||
177 | 'type' => 'text', |
||
178 | 'css' => 'min-width:300px;', |
||
179 | 'class' => 'required', |
||
180 | 'autoload' => false |
||
181 | ); |
||
182 | |||
183 | // Checks if the Post Navigation selector has been set by theme support. |
||
184 | View Code Duplication | if ( ! empty( alnp_get_theme_support( 'navigation_container' ) ) ) { |
|
185 | $post_navigation_readonly = 'yes'; |
||
186 | } else { |
||
187 | $post_navigation_default = sprintf( __( 'Default: %s', 'auto-load-next-post' ), '<code>nav.post-navigation</code>' ); |
||
188 | } |
||
189 | |||
190 | $settings[] = array( |
||
191 | 'title' => esc_html__( 'Post Navigation', 'auto-load-next-post' ), |
||
192 | 'desc' => sprintf( __( 'Used to identify which post to load next if any. %s', 'auto-load-next-post' ), $post_navigation_default ), |
||
193 | 'id' => 'auto_load_next_post_navigation_container', |
||
194 | 'default' => 'nav.post-navigation', |
||
195 | 'placeholder' => sprintf( esc_html__( 'e.g. %s', 'auto-load-next-post' ), 'nav.post-navigation' ), |
||
196 | 'readonly' => $post_navigation_readonly, |
||
197 | 'type' => 'text', |
||
198 | 'css' => 'min-width:300px;', |
||
199 | 'class' => 'required', |
||
200 | 'autoload' => false |
||
201 | ); |
||
202 | |||
203 | // Checks if the Comments Container selector has been set by theme support. |
||
204 | View Code Duplication | if ( ! empty( alnp_get_theme_support( 'comments_container' ) ) ) { |
|
205 | $comments_container_readonly = 'yes'; |
||
206 | } else { |
||
207 | $comments_container_default = sprintf( __( 'Default: %s', 'auto-load-next-post' ), '<code>div#comments</code>' ); |
||
208 | } |
||
209 | |||
210 | $settings[] = array( |
||
211 | 'title' => esc_html__( 'Comments Container', 'auto-load-next-post' ), |
||
212 | 'desc' => sprintf( __( 'Used to remove comments if enabled under %1$sMisc%2$s settings. %3$s', 'auto-load-next-post' ), '<strong><a href="' . add_query_arg( array( 'page' => 'auto-load-next-post', 'view' => 'misc' ), get_admin_url( $blog_id, 'options-general.php' ) ) . '">', '</a></strong>', $comments_container_default ), |
||
213 | 'id' => 'auto_load_next_post_comments_container', |
||
214 | 'default' => 'div#comments', |
||
215 | 'placeholder' => sprintf( esc_html__( 'e.g. %s', 'auto-load-next-post' ), 'div#comments' ), |
||
216 | 'readonly' => $comments_container_readonly, |
||
217 | 'type' => 'text', |
||
218 | 'css' => 'min-width:300px;', |
||
219 | 'autoload' => false |
||
220 | ); |
||
221 | |||
222 | $settings[] = array( |
||
223 | 'type' => 'sectionend', |
||
224 | 'id' => 'theme_selectors_options' |
||
225 | ); |
||
226 | |||
227 | return apply_filters( 'alnp_selectors_settings', $settings ); |
||
228 | } // END get_settings() |
||
229 | |||
260 |