| Conditions | 15 |
| Paths | 111 |
| Total Lines | 81 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 34 | View Code Duplication | if ( ! isset( $details['type'] ) || |
|
| 35 | 'plugin' !== $details['type'] || |
||
| 36 | is_wp_error( $upgrader->skin->result ) || |
||
| 37 | ! method_exists( $upgrader, 'plugin_info' ) |
||
| 38 | ) { |
||
| 39 | return; |
||
| 40 | } |
||
| 41 | |||
| 42 | if ( 'install' === $details['action'] ) { |
||
| 43 | $plugin_path = $upgrader->plugin_info(); |
||
| 44 | $plugins = get_plugins(); |
||
| 45 | $plugin_info = $plugins[ $plugin_path ]; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Signals to the sync listener that a plugin was installed and a sync action |
||
| 49 | * reflecting the installation and the plugin info should be sent |
||
| 50 | * |
||
| 51 | * @since 4.9.0 |
||
| 52 | * |
||
| 53 | * @param string $plugin_path Path of plugin installed |
||
| 54 | * @param mixed $plugin_info Array of info describing plugin installed |
||
| 55 | */ |
||
| 56 | do_action( 'jetpack_installed_plugin', $plugin_path, $plugin_info ); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | public function check_plugin_edit() { |
||
| 61 | $screen = get_current_screen(); |
||
| 62 | if ( 'plugin-editor' !== $screen->base || |
||
| 63 | ! isset( $_POST['newcontent'] ) || |
||
| 64 | ! isset( $_POST['plugin'] ) |
||
| 65 | ) { |
||
| 66 | return; |
||
| 67 | } |
||
| 68 | |||
| 69 | $plugin = $_POST['plugin']; |
||
| 70 | $plugins = get_plugins(); |
||
| 71 | if ( ! isset( $plugins[ $plugin ] ) ) { |
||
| 72 | return; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Helps Sync log that a plugin was edited |
||
| 77 | * |
||
| 78 | * @since 4.9.0 |
||
| 79 | * |
||
| 80 | * @param string $plugin, Plugin slug |
||
| 81 | * @param mixed $plugins[ $plugin ], Array of plugin data |
||
| 82 | */ |
||
| 83 | do_action( 'jetpack_edited_plugin', $plugin, $plugins[ $plugin ] ); |
||
| 84 | } |
||
| 85 | |||
| 86 | public function plugin_edit_ajax() { |
||
| 87 | // this validation is based on wp_edit_theme_plugin_file() |
||
| 88 | $args = wp_unslash( $_POST ); |
||
| 89 | if ( empty( $args['file'] ) ) { |
||
| 90 | return; |
||
| 91 | } |
||
| 92 | |||
| 93 | $file = $args['file']; |
||
| 94 | if ( 0 !== validate_file( $file ) ) { |
||
| 95 | return; |
||
| 96 | } |
||
| 97 | |||
| 98 | if ( ! isset( $args['newcontent'] ) ) { |
||
| 99 | return; |
||
| 100 | } |
||
| 101 | |||
| 102 | if ( ! isset( $args['nonce'] ) ) { |
||
| 103 | return; |
||
| 104 | } |
||
| 105 | |||
| 106 | if ( empty( $args['plugin'] ) ) { |
||
| 107 | return; |
||
| 108 | } |
||
| 109 | |||
| 110 | $plugin = $args['plugin']; |
||
| 111 | if ( ! current_user_can( 'edit_plugins' ) ) { |
||
| 112 | return; |
||
| 113 | } |
||
| 114 | |||
| 115 | if ( ! wp_verify_nonce( $args['nonce'], 'edit-plugin_' . $file ) ) { |
||
| 190 |