wpstarter / framework

The WpStarter Framework - Laravel Framework for WordPress
https://wpstarter.dev
MIT License
15 stars 4 forks source link

Not possible to register more than one shortcode #51

Closed fabarea closed 1 year ago

fabarea commented 1 year ago

It seems that registering more than one shortcode is not possible, or at least it is not working for me.

Let's consider a scenario where we declare two shortcodes in the routes/wp.php file. For simplicity, we intentionally bind both shortcodes to the same controller.

Route::get('welcome-shortcode', [\App\Http\Controllers\WelcomeController::class, 'shortcode']);
Route::get('foo-shortcode', [\App\Http\Controllers\WelcomeController::class, 'shortcode']);

Now, on any WordPress page, let's declare two shortcodes as follows: [welcome-shortcode] and [foo-shortcode]. Only the first shortcode is interpreted by me. The other stay as not "interpreted" (e.g. [foo-shortcode]) We can experiment by swapping the routes in routes/wp.php, and we'll observe the shortcodes interpretation.

Am I missing a point?

Thanks BTW by your great work!

fabarea commented 1 year ago

Ah, it seems I was confused. Meanwhile, I noticed the Shortcut facade that can be used to register new shortcuts. I haven't played yet, but I bet that is the way to register shortcodes.

\WpStarter\Wordpress\Facades\Shortcode::add()
as247 commented 1 year ago

It seems that registering more than one shortcode is not possible, or at least it is not working for me.

Let's consider a scenario where we declare two shortcodes in the routes/wp.php file. For simplicity, we intentionally bind both shortcodes to the same controller.

Route::get('welcome-shortcode', [\App\Http\Controllers\WelcomeController::class, 'shortcode']);
Route::get('foo-shortcode', [\App\Http\Controllers\WelcomeController::class, 'shortcode']);

Now, on any WordPress page, let's declare two shortcodes as follows: [welcome-shortcode] and [foo-shortcode]. Only the first shortcode is interpreted by me. The other stay as not "interpreted" (e.g. [foo-shortcode]) We can experiment by swapping the routes in routes/wp.php, and we'll observe the shortcodes interpretation.

Am I missing a point?

Thanks BTW by your great work!

This feature called shortcode routing. You will use shortcode to route instead of path, then that single shortcode per route