Automattic\WooCommerce\Internal\Utilities

PluginInstaller::handle_plugin_list_rows()publicWC 1.0

Handler for the 'plugin_list_rows' hook, it will display a notice under the name of the plugins that have been installed using this class (unless the woocommerce_show_autoinstalled_plugin_notices returns false) in the plugins list page.

Метод класса: PluginInstaller{}

Возвращает

null. Ничего (null).

Использование

$PluginInstaller = new PluginInstaller();
$PluginInstaller->handle_plugin_list_rows( $plugin_file, $plugin_data );
$plugin_file(строка) (обязательный)
Name of the plugin.
$plugin_data(массив) (обязательный)
Plugin data.

Код PluginInstaller::handle_plugin_list_rows() WC 9.7.1

<?php
public function handle_plugin_list_rows( $plugin_file, $plugin_data ) {
	global $wp_list_table;

	if ( is_null( $wp_list_table ) ) {
		return;
	}

	/**
	 * Filter to suppress the notice about autoinstalled plugins in the plugins list page.
	 *
	 * @since 8.8.0
	 *
	 * @param bool $display_notice Whether notices should be displayed or not.
	 * @returns bool
	 */
	if ( ! apply_filters( 'woocommerce_show_autoinstalled_plugin_notices', '__return_true' ) ) {
		return;
	}

	$auto_installed_plugins_info = get_site_option( 'woocommerce_autoinstalled_plugins', array() );
	$current_plugin_info         = $auto_installed_plugins_info[ $plugin_file ] ?? null;
	if ( is_null( $current_plugin_info ) || $current_plugin_info['version'] !== $plugin_data['Version'] ) {
		return;
	}

	$installed_by = $current_plugin_info['metadata']['installed_by'] ?? 'WooCommerce';
	$info_link    = $current_plugin_info['metadata']['info_link'] ?? null;
	if ( $info_link ) {
		/* translators: 1 = who installed the plugin, 2 = ISO-formatted date and time, 3 = URL */
		$message = sprintf( __( 'Plugin installed by %1$s on %2$s. <a target="_blank" href="%3$s">More information</a>', 'woocommerce' ), $installed_by, $current_plugin_info['date'], $info_link );
	} else {
		/* translators: 1 = who installed the plugin, 2 = ISO-formatted date and time */
		$message = sprintf( __( 'Plugin installed by %1$s on %2$s.', 'woocommerce' ), $installed_by, $current_plugin_info['date'] );
	}

	$columns_count      = $wp_list_table->get_column_count();
	$is_active          = is_plugin_active( $plugin_file );
	$is_active_class    = $is_active ? 'active' : 'inactive';
	$is_active_td_style = $is_active ? "style='border-left: 4px solid #72aee6;'" : '';

	// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
	?>
	<tr class='plugin-update-tr update <?php echo $is_active_class; ?>' data-plugin='<?php echo $plugin_file; ?>' data-plugin-row-type='feature-incomp-warn'>
		<td colspan='<?php echo $columns_count; ?>' class='plugin-update'<?php echo $is_active_td_style; ?>>
			<div class='notice inline notice-success notice-alt'>
				<p>
					ℹ️ <?php echo $message; ?>
				</p>
			</div>
		</td>
	</tr>
	<?php
	// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
}