Hook: register_dynamic_urls
avatar
Señor FAQ

¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.


Hook: register_dynamic_urls

The register_dynamic_urls hook allows plugins to define their own dynamic URLs that can be used as shortcodes for easy integration within the JScms system. This provides flexibility for plugins to register additional URLs dynamically.

Usage


$dynamicUrls = [
    'tags' => 'slugfortags',
    'search' => 'slugforsearch',
    'news' => 'slugfornews',
    'login' => 'slugforsitelogin',
    'logout' => 'logout',
    'profile' => 'slugforsiteprofile',
    'register' => 'slugforsiteregister'
];

$dynamicUrlsHook = DynamicHooks::executeHook('register_dynamic_urls', false);

// Merge hook-provided dynamic URLs with core URLs
$hookUrls = array_reduce(
    $dynamicUrlsHook,
    fn(array $carry, $namespaceUrls) => is_array($namespaceUrls) ? array_merge($carry, $namespaceUrls) : $carry,
    []
);

$dynamicUrls = array_merge($dynamicUrls, $hookUrls);

// Register all dynamic URLs as shortcodes
registerDynamicUrls($dynamicUrls, $jkv);
    

This hook dynamically extends the core URL shortcodes by allowing plugins to register their own.

Example Implementation


DynamicHooks::addHook('register_dynamic_urls', function () {
    return [
        'your_plugin' => 'slugforplugin',
        'your_plugin_page' => 'slugforpluginpage'
    ];
}, 'your_plugin');
    

Best Practices

  • Ensure each plugin URL uses a unique key to avoid conflicts.
  • Define meaningful slugs for plugin-specific URLs.
  • Test the generated shortcodes to verify they point to the correct destinations.

Troubleshooting

  • Verify the hook is registered under the correct namespace.
  • Check for missing or invalid slug keys in the plugin-provided URLs.
  • Inspect logs for errors during URL parsing or shortcode registration.
Was this article helpful?
0 out of 0 found this helpful