Code Structure

This topic contains 3 replies, has 2 voices, and was last updated by  Dschoni 11 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #3337

    Hi there,
    I just started using your plugin, and it is amazing. The documentation for me is a little cryptic, so here comes my question:
    on that site

    http://wp-event-organiser.com/documentation/hook/eventorganiser_widget_calendar_date_link/

    you give a pretty simple and straight-forward explanation of the hooks. But for me as a php noob that is still not clear enough.
    So, when I want to implement that simple change in the example, what do I have to insert where in the code? I guess, that I have to edit the mentioned php file from line 226 on? Or am I totally missing something? So basically I want the exact behaviour you are describing. If I get this to work, I might think of more fancy stuff (like leading to a list of events if there are more than one on this day, leading directly to the event if it’s the only one…)
    One more thing: I want the order of the Event page reversed, so that the description comes before the details with maps and so on. For this one I should change the template of the single event site, right?
    Thanks for your time.

    Dschoni
    #3340

    Hi Dschoni,

    You should avoid making any changes to Event Organiser as these will be lost when you update.

    The recommended method is to put the code in a ‘site functionality plug-in’ – which contains all your site-specific code snippets that you use. (See this article: http://wpcandy.com/teaches/how-to-create-a-functionality-plugin/).

    Alternatively you can put it in your theme’s functions.php. But again, if you put it in the parent theme it’ll be lost with an update, so its recommended to implement a child theme. But even that means if you want to change your theme, you need to re-add the code snippets into the new theme (which is partly why a site functionality plug-in is recommended).

    Stephen Harris
    #3347

    Thanks for the fast answer, this is unusual in the development world 😉

    So I read and understood the discussion of the plugin thing, but it seems to not be enough to just drop the code in a plugin and activate it. I guess I am not understanding the hooking itself. So could you give me an example of an implementation of the abovementioned code? The plugin code is clear, I don’t get the hooking part. Thanks in advance.

    Dschoni
    #3366

    Yes, so essentially you can drop that into any active plug-in – the idea of a site functionality plug-in is that its simply another plug-in where you place any code snippets that you don’t want to loose if you should upgrade/change plug-ins or themes.

    In the example you refer to the code there is complete and should work ‘as is’.

    Actions & Filters

    An action is simply a way of ‘announcing’ something has been performed. (For instance the save_post is triggered when a post is saved). By hooking onto an action, you are using WordPress to run your function whenever that action is performed. In a sort ‘WordPress, when you do this, also do that’ sort of way. You can use the save_post action, for example, so that every time a post is saved you e-mail an admin (if you don’t mind you inbox being littered!),

    Filters are similar, but rather ‘announcing’ an action – they filter a variable. This means by hooking onto that filter, you can change that variable. In this case its sort of ‘Whenever WordPress filters this variable, I want to change it to this’. In the example of eventorganiser_widget_calendar_date_link, the plug-in is filtering the link for the widget calendar – so by ‘hooking’ onto that filter, you can tell WordPress that you want to change the value of that link. You change the value by returning whatever you want it to be, and so to leave it the same you would just return what you were given.

    Of course you probably want to change the link differently for each date, or based on the event(s) that start on that date. So not only can you function recieve the value to be filtered (which is always the first one), it also recieves additional variables – in this case a datetime object and array of events.

    The upshot is that the code snippet adds itself to the filter, and so WordPress ‘consults’ the hooked function before it uses the variable.

    Hope that makes sense!


    (P.s. Tom McFarlin a fellow author at WP.Tuts did a great post explaining actions/filters: http://wp.tutsplus.com/tutorials/the-beginners-guide-to-wordpress-actions-and-filters/)

    Stephen Harris
    #3420

    Man….what more to say…you are awesome 🙂

    Dschoni
Viewing 5 posts - 1 through 5 (of 5 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.