| Conditions | 13 |
| Paths | 128 |
| Total Lines | 74 |
| Lines | 14 |
| Ratio | 18.92 % |
| 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 |
||
| 44 | public function get_active_plugins( $include_deactivating = true ) { |
||
| 45 | global $jetpack_autoloader_activating_plugins_paths; |
||
| 46 | global $jetpack_autoloader_including_latest; |
||
| 47 | |||
| 48 | // We're going to build a unique list of plugins from a few different sources |
||
| 49 | // to find all of our "active" plugins. While we need to return an integer |
||
| 50 | // array, we're going to use an associative array internally to reduce |
||
| 51 | // the amount of time that we're going to spend checking uniqueness |
||
| 52 | // and merging different arrays together to form the output. |
||
| 53 | $active_plugins = array(); |
||
| 54 | |||
| 55 | // Make sure that plugins which have activated this request are considered as "active" even though |
||
| 56 | // they probably won't be present in any option. |
||
| 57 | if ( is_array( $jetpack_autoloader_activating_plugins_paths ) ) { |
||
| 58 | foreach ( $jetpack_autoloader_activating_plugins_paths as $path ) { |
||
| 59 | $active_plugins[ $path ] = $path; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | // This option contains all of the plugins that have been activated. |
||
| 64 | $plugins = $this->plugin_locator->find_using_option( 'active_plugins' ); |
||
| 65 | foreach ( $plugins as $path ) { |
||
| 66 | $active_plugins[ $path ] = $path; |
||
| 67 | } |
||
| 68 | |||
| 69 | // This option contains all of the multisite plugins that have been activated. |
||
| 70 | if ( is_multisite() ) { |
||
| 71 | $plugins = $this->plugin_locator->find_using_option( 'active_sitewide_plugins', true ); |
||
| 72 | foreach ( $plugins as $path ) { |
||
| 73 | $active_plugins[ $path ] = $path; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | // These actions contain plugins that are being activated during this request. |
||
| 78 | $plugins = $this->plugin_locator->find_using_request_action( array( 'activate', 'activate-selected' ) ); |
||
| 79 | foreach ( $plugins as $path ) { |
||
| 80 | $active_plugins[ $path ] = $path; |
||
| 81 | } |
||
| 82 | |||
| 83 | // While it's true that the deactivating plugins are more than likely already in the active list |
||
| 84 | // at this point, we should make sure in order to avoid any strange misbehavior. |
||
| 85 | View Code Duplication | if ( $include_deactivating ) { |
|
| 86 | // These actions contain plugins that are being deactivated during this request. |
||
| 87 | $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); |
||
| 88 | foreach ( $plugins as $path ) { |
||
| 89 | $active_plugins[ $path ] = $path; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | // When the current plugin isn't considered "active" there's a problem. |
||
| 94 | // Since we're here, the plugin is active and currently being loaded. |
||
| 95 | // We can support this case (mu-plugins and non-standard activation) |
||
| 96 | // by adding the current plugin to the active list and marking it |
||
| 97 | // as an unknown (activating) plugin. This also has the benefit |
||
| 98 | // of causing a reset because the active plugins list has |
||
| 99 | // been changed since it was saved in the global. |
||
| 100 | $current_plugin = $this->plugin_locator->find_current_plugin(); |
||
| 101 | if ( ! in_array( $current_plugin, $active_plugins, true ) && ! $jetpack_autoloader_including_latest ) { |
||
| 102 | $active_plugins[ $current_plugin ] = $current_plugin; |
||
| 103 | $jetpack_autoloader_activating_plugins_paths[] = $current_plugin; |
||
| 104 | } |
||
| 105 | |||
| 106 | // When deactivating plugins aren't desired we should entirely remove them from the active list. |
||
| 107 | View Code Duplication | if ( ! $include_deactivating ) { |
|
| 108 | // These actions contain plugins that are being deactivated during this request. |
||
| 109 | $plugins = $this->plugin_locator->find_using_request_action( array( 'deactivate', 'deactivate-selected' ) ); |
||
| 110 | foreach ( $plugins as $path ) { |
||
| 111 | unset( $active_plugins[ $path ] ); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | // Transform the array so that we don't have to worry about the keys interacting with other array types later. |
||
| 116 | return array_values( $active_plugins ); |
||
| 117 | } |
||
| 118 | |||
| 172 |