Closed Raruto closed 4 years ago
Is your code example in your own code? I don't see it here.
Is this to be used somewhere in the framework or outside of it?
Is this to be used somewhere in the framework or outside of it?
That function is already public, but I think it could be fine for both purposes
// Current code.
$this->config[ $slug ]["sources"];
// Proposal code.
$this->get_config( $slug, "sources" );
Is your code example in your own code? I don't see it here.
https://github.com/afragen/wp-dependency-installer/pull/55#issue-378023713
Here's how it would become my code:
/**
* Get plugin notices.
*
* @param string $slug Plugin slug.
*
* @return array Admin notices.
*/
function wpdi_notices( $notices, $slug ) {
$wpdi = WP_Dependency_Installer::instance();
if ( ! $wpdi->is_active( $slug ) ) {
return $notices;
}
// $dependency = $wpdi->get_config( $slug );
// foreach ( $dependency['sources'] as $source ) {
foreach ( $wpdi->get_config( $slug, 'sources' ) as $source ) {
// Check if we were trying to deactivate a manadatory plugin.
if ( isset( $_REQUEST['wpdi_required'] ) && $slug === $_REQUEST['wpdi_required'] ) {
array_unshift(
$notices, [
'status' => 'error',
/* translators: %s: Plugin name */
'message' => sprintf( esc_html__( 'The %s plugin is a mandatory plugin.' ), $dependency['name'] ),
'source' => $source,
]
);
}
}
return $notices;
}
OK, now I understand. Looks simpler.
OK, now I understand. Looks simpler.
Ok, I do in the coming days.
In writing this piece of code, I stumbled upon this point:
It would make sense to modify the
get_config
function to allow us to easily make the following calls?Adds optional
$key
parameter: