WP_Plugins_List_Table::add_dependencies_to_dependent_plugin_row()protectedWP 6.5.0

Prints a list of other plugins that the plugin depends on.

Method of the class: WP_Plugins_List_Table{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->add_dependencies_to_dependent_plugin_row( $dependent );
$dependent(string) (required)
The dependent plugin's filepath, relative to the plugins directory.

Changelog

Since 6.5.0 Introduced.

WP_Plugins_List_Table::add_dependencies_to_dependent_plugin_row() code WP 6.5.4

protected function add_dependencies_to_dependent_plugin_row( $dependent ) {
	$dependency_names = WP_Plugin_Dependencies::get_dependency_names( $dependent );

	if ( array() === $dependency_names ) {
		return;
	}

	$links = array();
	foreach ( $dependency_names as $slug => $name ) {
		$links[] = $this->get_dependency_view_details_link( $name, $slug );
	}

	$is_active = is_multisite() ? is_plugin_active_for_network( $dependent ) : is_plugin_active( $dependent );
	$comma     = wp_get_list_item_separator();
	$requires  = sprintf(
		/* translators: %s: List of dependency names. */
		__( '<strong>Requires:</strong> %s' ),
		implode( $comma, $links )
	);

	$notice        = '';
	$error_message = '';
	if ( WP_Plugin_Dependencies::has_unmet_dependencies( $dependent ) ) {
		if ( $is_active ) {
			$error_message = __( 'This plugin is active but may not function correctly because required plugins are missing or inactive.' );
		} else {
			$error_message = __( 'This plugin cannot be activated because required plugins are missing or inactive.' );
		}
		$notice = wp_get_admin_notice(
			$error_message,
			array(
				'type'               => 'error',
				'additional_classes' => array( 'inline', 'notice-alt' ),
			)
		);
	}

	printf(
		'<div class="requires"><p>%1$s</p><p>%2$s</p></div>',
		$requires,
		$notice
	);
}