ulgm_before_register_group_signup_permalink
Fires before the group signup permalink is registered, allowing modification of the process.
add_action( 'ulgm_before_register_group_signup_permalink', $callback, 10, 1 );
Description
Fires before the rewrite rule for LearnDash group sign-up permalinks is registered. Developers can use this hook to modify or prevent the registration of the 'sign-up/{group_slug}/' permalink, allowing custom routing or additional logic before the rule is added to WordPress.
Usage
add_action( 'ulgm_before_register_group_signup_permalink', 'your_function_name', 10, 1 );
Examples
add_action( 'ulgm_before_register_group_signup_permalink', function() {
// Potentially add some custom rewrite rules or modifications *before* the default one.
// For example, you might want to check if a specific group type is being signed up for
// and conditionally add a different rewrite rule.
// This is a hypothetical example. In a real scenario, you'd have actual logic here.
// For demonstration, let's assume we want to intercept signups for a specific group type
// and redirect them to a custom page for processing.
$special_group_slug = 'premium-cohort-alpha'; // Example of a special group slug
// This check would be more robust in a real plugin, likely involving querying the database
// to determine if the group slug belongs to a 'special' category.
// Since we're in `ulgm_before_register_group_signup_permalink`, we don't have the group slug directly.
// However, if there was a way to access it or a related setting, this is where you'd use it.
// A more realistic scenario might be to add conditions that affect the *default* rewrite rule.
// For instance, if you wanted to ENSURE the default rule is *not* added under certain conditions.
// Let's imagine a scenario where if a plugin setting is enabled to prevent direct signup links
// for certain groups, we could modify the behavior.
if ( get_option( 'ulgm_disable_direct_signup_for_some_groups' ) === 'yes' ) {
// In a real case, you might not `remove_action` here as this hook runs before it.
// Instead, you would directly control the `add_rewrite_rule` itself, or offer an alternative.
// For this example, we'll show a conditional rewrite rule addition.
// Example: Add a specific rewrite rule for a special group if the option is enabled.
// This is illustrative, as the default rule is generic.
// A more practical use would be to have a separate mechanism or modify the default one's conditions.
// For now, let's assume we want to preprocess the default rule.
// This hook is too early to modify the *existing* default rule directly with `remove_rewrite_rule`.
// The primary use case here is to *add* or *influence* the rules that follow.
// Example: Let's say we want to log when this hook is fired for debugging.
error_log( 'ulgm_before_register_group_signup_permalink fired. Preparing to add rewrite rules.' );
}
}, 10, 0 ); // Priority 10, 0 accepted arguments.
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/learn-dash-group-sign-up.php:1097
public static function register_group_signup_permalink(){
do_action( 'ulgm_before_register_group_signup_permalink' );
add_rewrite_rule( '^sign-up/([^/]+)/?$', 'index.php?ulgm_group_slug=$matches[1]&ulgm_signup=1', 'top' );
do_action( 'ulgm_after_register_group_signup_permalink' );
// @todo: We need a way to run this for this specific module once the module gets initialized for the first time or gets initialized or re-enabled.
flush_rewrite_rules();
}