4Podcast hooks
You can modify or extend 4Podcast behavior programmatically by using one or more of the hooks listed below. Hooks let you modify internal PHP structures or results computed by 4Podcast to better accomodate your website specific requirements.
They are events that are triggered at various moments by 4Podcast, providing code you write with internal information and possibly letting you modify this information.
Hooks are not altered when 4Podcast is updated
All the customization you do using hooks will survive 4Podcast updates. The hooks definition themselves will not change or be removed, unless the corresponding feature is modified or removed from 4Podcast of course.
When using hooks with 4Podcast, the following apply:
- we cannot provide any form of support to the customization you make. You are on your own and the below documentation is the extent of information we'll provide to you.
- you'll need suitable programming knowledge and understanding of Joomla internals to be able to write your own hooks handler
- you may have to study 4Podcast code to learn if what you want to do is possible and how to do it. Again, we won't help your there, at least as part of regular support.
Usage
If you added any hook handler, make sure to absolutely always mention that whenever you open a support ticket. Your custom hooks can alter the way 4Podcast works, and may have consequences. We need to be aware of the existence of your hooks at all times.
Types
There are 2 types of hooks: filters and actions. Both are events that are triggered at different moment and to which you can respond.
The difference between them is:
- filters: you receive some data, and you can return modified data. 4Podcast will subsequently use your modified data
- action: you receive some data, but you cannot modify it. Or rather, you can modify it but 4Podcast will not use the result anyway
How to
As hooks are basically events, you must register your custom handler with 4Podcast for any hook you want to use. 4Podcast will then call your handler when the hook is run.
The most convenient way to register your hooks handler and include your custom code is to use 4Podcast functions file. The function file is unique and lives at:
/libraries/weeblr/forpodcast_functions.php
Create the file if it does not exist yet. You can put all your custom code in that file, or just use it to interface with 4Podcast and include more PHP code from wherever you want.
The 4Podcast function file must always start with:
<?php
/**
* 4Podcast hooks file
*
* You can use 2 variables to access 4Podcast content:
*
* $factory: access variables
* $hooks: add handlers
*/
// no direct access
defined('WBLIB_EXEC') || die;
If this preamble is missing, just copy/paste it at the top of the file.
After that, you can add your hook handler and your custom code. Here is a typical example, which lets us customize the GUID 4Podcast outputs in your RSS feed:
$hooks->add(
'forpodcast_feed_episode_data',
function ($displayData,
$article,
$itemData,
$field) {
$displayData['guid'] = $displayData['media_file'];
return $displayData;
}
);
The $hooks variable shown in the example is always available to you inside the functions files, 4Podcast creates it for you.
Inside the functions file, you are inside of Joomla, meaning you can use Joomla API as you would in other contexts. You can for instance use the Joomla Factory class to access the application object. Make sure to add the proper namespace use statements if you do so.
Summary
Actions
Filters
Group: Feed
forpodcast_feed_batch_size
Feed filter
Filter the batch size used when reading articles to build the RSS feed.
@param int $batchSize @param \stdClass $field
@return int
@since 3.7.0
in /plugins/system/forpodcast/forpodcast.php
@line 729
forpodcast_feed_episode_data
Feed filter
Filter the data used to render one episode item in the RSS feed.
@param array $displayData @param \stdClass $article @param \stdClass $itemData @param \stdClass $field
@return array
@since 3.7.0
in /plugins/system/forpodcast/forpodcast.php
@line 1217
forpodcast_feed_show_data
Feed filter
Filter the show data used to render the RSS feed channel, episodes excluded.
@param array $displayData @param \stdClass $field
@return array
@since 3.7.0
in /plugins/system/forpodcast/forpodcast.php
@line 937