urn; } $plugins = get_plugins(); if ( ! array_key_exists( $plugin, $plugins ) ) { return; } if ( 0 !== validate_file( $file, get_plugin_files( $plugin ) ) ) { return; } $real_file = WP_PLUGIN_DIR . '/' . $file; if ( ! is_writeable( $real_file ) ) { return; } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen $file_pointer = fopen( $real_file, 'w+' ); if ( false === $file_pointer ) { return; } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose fclose( $file_pointer ); /** * This action is documented already in this file */ do_action( 'jetpack_edited_plugin', $plugin, $plugins[ $plugin ] ); } /** * Handle plugin deletion. * * @access public * * @param string $plugin_path Path to the plugin main file. */ public function delete_plugin( $plugin_path ) { $full_plugin_path = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin_path; // Checking for file existence because some sync plugin module tests simulate plugin installation and deletion without putting file on disk. if ( file_exists( $full_plugin_path ) ) { $all_plugin_data = get_plugin_data( $full_plugin_path ); $data = array( 'name' => $all_plugin_data['Name'], 'version' => $all_plugin_data['Version'], ); } else { $data = array( 'name' => $plugin_path, 'version' => 'unknown', ); } $this->plugin_info[ $plugin_path ] = $data; } /** * Invoked after plugin deletion. * * @access public * * @param string $plugin_path Path to the plugin main file. * @param boolean $is_deleted Whether the plugin was deleted successfully. */ public function deleted_plugin( $plugin_path, $is_deleted ) { call_user_func( $this->action_handler, $plugin_path, $is_deleted, $this->plugin_info[ $plugin_path ] ); unset( $this->plugin_info[ $plugin_path ] ); } /** * Expand the plugins within a hook before they are serialized and sent to the server. * * @access public * * @param array $args The hook parameters. * @return array $args The expanded hook parameters. */ public function expand_plugin_data( $args ) { $plugin_path = $args[0]; $plugin_data = array(); if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $all_plugins = get_plugins(); if ( isset( $all_plugins[ $plugin_path ] ) ) { $all_plugin_data = $all_plugins[ $plugin_path ]; $plugin_data['name'] = $all_plugin_data['Name']; $plugin_data['version'] = $all_plugin_data['Version']; } return array( $args[0], $args[1], $plugin_data, ); } }