WordPress.org

Ready to get started?Download WordPress

Forums

WP MVC
Does wp-mvc support shortcode and widget ? (4 posts)

  1. zia555
    Member
    Posted 1 year ago #

    Hi,

    I have to build widget and shortcode using wp-mvc. How can I do that ? Is there any command like this "./wpmvc generate widgets MyPlugin Mywidget","./wpmvc generate shortcodes MyPlugin Myshortcode" ?

    Thanks

    http://wordpress.org/extend/plugins/wp-mvc/

  2. davelopware
    Member
    Posted 1 year ago #

    I've just added a shortcode functionality patch to my branch on github.

    It's really simple if I do say so myself - you just need to add a bit of config in your app/config/bootstrap.php which maps a new shortcode to controller/action and substitutes the result of the associated view when displayed.

    There's even an example in the commit comment here:

    https://github.com/damphlett/wp-mvc/commit/7867af1b2ab9fcdfb73331341cda06ecf2130215

    The example might seem slightly complicated because it covers the extra functionality that lets you to specify, in the config, allow_actions and deny_actions. This is because you can specify the action as a parameter to the shortcode to hit any action on the mapped controller.

    But because shortcodes can often be entered by low-privileged users, it makes sense to be able to limit what actions they can perform with a shortcode.

  3. dodmax
    Member
    Posted 1 year ago #

    I can confirm that Davelopware patch works well!

    Also although it doesn't seem to be documented, wp-mvc can automatically register widgets for you.

    Just create a my-plugin/app/widgets folder and create a php file for each widget, for example my_widget.php.

    Each file should contain a class following the wordpress widget documentation

    Also your widget class name needs to follow the following naming convention: CamelPluginName_CamelWidgetFileName

    In the previous example your class would be named MyPlugin_MyWidget

  4. davelopware
    Member
    Posted 1 year ago #

    Thanks dodmax - great tip on the widgets.

    I know the documentation is a somewhat self-referential example of using wp-mvc itself, but I keep wishing it was a wiki that we could all pitch in with :|

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags