-
-
Notifications
You must be signed in to change notification settings - Fork 34
Actions and Hooks
The default timeout for dismissal of a notification is 7 days. There is a filter wp_dependency_timeout
to adjust this on a per project basis.
add_filter(
'wp_dependency_timeout',
function( $timeout, $source ) {
$timeout = basename( __DIR__ ) !== $source ? $timeout : 14;
return $timeout;
}, 10, 2
);
To help the end user before installation, you can also display your plugin name within dismissable notifications through the wp_dependency_dismiss_label
filter:
add_filter(
'wp_dependency_dismiss_label',
function( $label, $source ) {
$label = basename( __DIR__ ) !== $source ? $label : __( 'My Plugin Name', 'my-plugin-domain' );
return $label;
},
10,
2
);
You can also display additional admin notices through using this filter:
add_filter(
'wp_dependency_notices',
function wpdi_notices( $notices, $slug ) {
$wpdi = WP_Dependency_Installer::instance( __DIR__ );
$dependency = $wpdi->get_config( $slug );
if ( $wpdi->is_active( $slug ) && $wpdi->is_required( $slug ) ) {
array_unshift(
$notices, [
'status' => 'info',
/* translators: %s: Plugin name */
'message' => sprintf( esc_html__( 'The %s plugin is a mandatory plugin.' ), $dependency['name'] ),
'source' => $dependency['source'],
]);
}
return $notices;
},
10,
2
);
To assist users while using this library, WPDI make some visual changes to the default WordPress interface.
You can selectively disable them through using these filters:
// Disable "Required Plugin" label ( plugin_actions_links )
add_filter( 'wp_dependency_required_label', '__return_false' );
// Disable "Required by" row ( plugin_row_meta ).
add_filter( 'wp_dependency_required_row_meta', '__return_false' );
// Restore "deactivate" and "delete" links ( plugin_actions_links ).
add_filter( 'wp_dependency_unset_action_links', '__return_false' );
The download link can be filtered using the filter hook wp_dependency_download_link
. The $download_link
and the $dependency
are passed as parameters.
This is just a general purpose configuration filter (use it with caution!) and it's defined as late as possible within the apply_config()
function.
add_filter(
"wp_dependency_config",
function( $config ) {
if ( "github" === $config['host'] ) {
$config['token'] = "blah blah blah"; // <-- i.e. force to use specific Github Token ( prevent null values )
}
return $config;
}
);