Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 20 | class ALNP_Install { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Constructor. |
||
| 24 | * |
||
| 25 | * @since 1.0.0 |
||
| 26 | * @version 1.6.0 |
||
| 27 | * @access public |
||
| 28 | */ |
||
| 29 | public function __construct() { |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Check plugin version and run the updater if necessary. |
||
| 45 | * |
||
| 46 | * This check is done on all requests and runs if the versions do not match. |
||
| 47 | * |
||
| 48 | * @access public |
||
| 49 | * @static |
||
| 50 | * @since 1.4.10 |
||
| 51 | * @version 1.6.0 |
||
| 52 | */ |
||
| 53 | public static function check_version() { |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Install Auto Load Next Post. |
||
| 67 | * |
||
| 68 | * @access public |
||
| 69 | * @static |
||
| 70 | * @since 1.0.0 |
||
| 71 | * @version 1.6.0 |
||
| 72 | */ |
||
| 73 | public static function install() { |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Set theme selectors for the current active theme should it |
||
| 117 | * support Auto Load Next Post and have the theme selectors set. |
||
| 118 | * |
||
| 119 | * @access private |
||
| 120 | * @static |
||
| 121 | * @since 1.5.0 |
||
| 122 | */ |
||
| 123 | private static function set_theme_selectors() { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Sets Auto Load Next Post to load in the footer if the |
||
| 139 | * current active theme requires it and lock it so the |
||
| 140 | * user can not disable it should the theme not work any other way. |
||
| 141 | * |
||
| 142 | * @access private |
||
| 143 | * @static |
||
| 144 | * @since 1.5.0 |
||
| 145 | * @version 1.5.3 |
||
| 146 | */ |
||
| 147 | private static function set_js_in_footer() { |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Sets the template directory for the current active theme should it |
||
| 159 | * support Auto Load Next Post and have the template directory specified. |
||
| 160 | * |
||
| 161 | * @access private |
||
| 162 | * @static |
||
| 163 | * @since 1.6.0 |
||
| 164 | */ |
||
| 165 | private static function set_template_directory() { |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Update plugin version to current. |
||
| 175 | * |
||
| 176 | * @access private |
||
| 177 | * @static |
||
| 178 | */ |
||
| 179 | private static function update_version() { |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Set the time the plugin was installed. |
||
| 185 | * |
||
| 186 | * @access public |
||
| 187 | * @static |
||
| 188 | * @since 1.4.4 |
||
| 189 | * @version 1.5.0 |
||
| 190 | */ |
||
| 191 | public static function set_install_date() { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Default Options |
||
| 204 | * |
||
| 205 | * Sets up the default options defined on the settings pages. |
||
| 206 | * |
||
| 207 | * @access public |
||
| 208 | * @static |
||
| 209 | * @since 1.0.0 |
||
| 210 | * @version 1.5.1 |
||
| 211 | */ |
||
| 212 | public static function create_options() { |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Add rewrite endpoint for Auto Load Next Post. |
||
| 230 | * |
||
| 231 | * @access public |
||
| 232 | * @static |
||
| 233 | * @since 1.0.0 |
||
| 234 | * @version 1.5.0 |
||
| 235 | */ |
||
| 236 | public static function add_rewrite_endpoint() { |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Flush rewrite rules. |
||
| 242 | * |
||
| 243 | * @access public |
||
| 244 | * @static |
||
| 245 | * @since 1.5.0 |
||
| 246 | */ |
||
| 247 | public static function flush_rewrite_rules() { |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Resets all Auto Load Next Post settings. |
||
| 253 | * |
||
| 254 | * @access public |
||
| 255 | * @static |
||
| 256 | * @since 1.5.11 |
||
| 257 | * @version 1.6.0 |
||
| 258 | * @global object $wpdb |
||
| 259 | */ |
||
| 260 | public static function reset_alnp() { |
||
| 261 | if ( current_user_can( 'install_plugins' ) && isset( $_GET['reset-alnp'] ) && $_GET['reset-alnp'] == 'yes' ) { |
||
| 262 | global $wpdb; |
||
| 263 | |||
| 264 | // If we made it till here nothing is running yet, lets set the transient now for two minutes. |
||
| 265 | set_transient( 'alnp_resetting', 'yes', MINUTE_IN_SECONDS * 2 ); |
||
| 266 | |||
| 267 | // Make sure it is only a single site we are resetting. |
||
| 268 | if ( ! is_multisite() ) { |
||
| 269 | // Delete options |
||
| 270 | $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'auto_load_next_post_%'"); |
||
| 271 | |||
| 272 | // Delete user interactions |
||
| 273 | $wpdb->query("DELETE FROM $wpdb->usermeta WHERE meta_key LIKE 'auto_load_next_post_%'"); |
||
| 274 | } |
||
| 275 | else { |
||
| 276 | // Delete Uninstall Data |
||
| 277 | delete_site_option( 'auto_load_next_post_uninstall_data' ); |
||
| 278 | |||
| 279 | // Delete Install Date |
||
| 280 | delete_site_option( 'auto_load_next_post_install_date' ); |
||
| 281 | } |
||
| 282 | |||
| 339 |