Conditions | 15 |
Paths | 255 |
Total Lines | 72 |
Lines | 12 |
Ratio | 16.67 % |
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 |
||
123 | public function add_notices() { |
||
124 | global $current_user; |
||
125 | |||
126 | // If the current user can not install plugins then return nothing! |
||
127 | if ( ! current_user_can( 'install_plugins' ) ) { |
||
128 | return false; |
||
129 | } |
||
130 | |||
131 | $screen = get_current_screen(); |
||
132 | $screen_id = $screen ? $screen->id : ''; |
||
133 | |||
134 | // Notices should only show on the main dashboard and on the plugins screen. |
||
135 | if ( ! in_array( $screen_id, alnp_get_admin_screens() ) ) { |
||
136 | return false; |
||
137 | } |
||
138 | |||
139 | // Is admin welcome notice hidden? |
||
140 | $hide_welcome_notice = get_user_meta( $current_user->ID, 'auto_load_next_post_hide_welcome_notice', true ); |
||
141 | |||
142 | // Check if we need to display the welcome notice. |
||
143 | View Code Duplication | if ( empty( $hide_welcome_notice ) ) { |
|
144 | // If the user has just installed the plugin for the first time then welcome the user. |
||
145 | if ( ( intval( time() - self::$install_date ) / WEEK_IN_SECONDS ) % 52 <= 2 ) { |
||
146 | add_action( 'admin_notices', array( $this, 'welcome_notice' ) ); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | // Is admin review notice hidden? |
||
151 | $hide_review_notice = get_user_meta( $current_user->ID, 'auto_load_next_post_hide_review_notice', true ); |
||
152 | |||
153 | // Check if we need to display the review plugin notice. |
||
154 | View Code Duplication | if ( empty( $hide_review_notice ) ) { |
|
155 | // If it has been a week or more since activating the plugin then display the review notice. |
||
156 | if ( ( intval( time() - self::$install_date ) ) > WEEK_IN_SECONDS ) { |
||
157 | add_action( 'admin_notices', array( $this, 'plugin_review_notice' ) ); |
||
158 | } |
||
159 | } |
||
160 | |||
161 | // Is this version of Auto Load Next Post a beta release? |
||
162 | if ( is_alnp_beta() && empty( get_transient( 'alnp_beta_notice_hidden' ) ) ) { |
||
163 | add_action( 'admin_notices', array( $this, 'beta_notice' ) ); |
||
164 | } |
||
165 | |||
166 | $template = get_option( 'template' ); |
||
167 | |||
168 | // Checks if the theme supports Auto Load Next Post and not provided via a plugin. |
||
169 | if ( is_alnp_supported() ) { |
||
170 | $plugin_supported = alnp_get_theme_support( 'plugin_support' ); |
||
171 | |||
172 | // Return if theme is supported via plugin. |
||
173 | if ( ! empty( $plugin_supported ) && $plugin_supported == 'yes' ) { |
||
174 | update_option( 'auto_load_next_post_theme_supported', $template ); |
||
175 | return false; |
||
176 | } |
||
177 | |||
178 | // If supported theme does not match active theme then show notice. |
||
179 | if ( get_option( 'auto_load_next_post_theme_supported' ) !== $template ) { |
||
180 | add_action( 'admin_notices', array( $this, 'theme_ready_notice' ) ); |
||
181 | update_option( 'auto_load_next_post_theme_supported', $template ); |
||
182 | } |
||
183 | } else { |
||
184 | // If theme not supported then delete option. |
||
185 | delete_option( 'auto_load_next_post_theme_supported' ); |
||
186 | } |
||
187 | |||
188 | // Upgrade warning notice that will disappear once the new release is installed. |
||
189 | $upgrade_version = '1.6.0'; |
||
190 | |||
191 | if ( version_compare( AUTO_LOAD_NEXT_POST_VERSION, $upgrade_version, '<' ) ) { |
||
192 | add_action( 'admin_notices', array( $this, 'upgrade_warning' ) ); |
||
193 | } |
||
194 | } // END add_notices() |
||
195 | |||
266 |