• Welcome to PHPVIBE Forums. Please log in.
avatar_Marius P.

Filters and Hooks in PHPVibe

Started by Marius P.,

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Marius P.Topic starter

add_filter() and apply_filter()

PHPVibe's add__filter() hooks a function to a specific filter action.

Usage:

add_filter( $tag, $function_to_add );
Example:

If you wish to dynamically inject a new title to the PHPVibe page:

function seotitle( $text ) {
return "My static title";
/* clearly you can build some php and use some globals here, not just use text ;) */}
add_filter( 'phpvibe_title', 'seotitle' );
PHPVibe's apply_filter()
Calls the functions added to a filter hook.
The callback functions attached to the filter hook $tag are invoked by calling this function. This function can be used to create a new filter hook by simply calling this function with the name of the new hook specified using the $tag parameter.

Usage:

apply_filters( $tag, $value, $var ... );
Example:

//SEO
function seo_title() {
return apply_filters( 'phpvibe_title', get_option('seo_title'));
}
function seo_desc() {
return apply_filters( 'phpvibe_desc', get_option('seo_desc'));
}

Useful hooks in PHPVibe
These two hooks may also help a lot (after the SEO hooks explained upper):
function extra_js() {
return apply_filter( 'filter_extrajs', false );
}
function extra_css() {
return apply_filter( 'filter_extracss', false );
}
They inject custom css and js in your template file. You can attach an add_filter() to them easily.
function more_css( $text ) {
$mycss = '';
return $text.$mycss;
}
add_filter( 'filter_extracss', 'more_css' );
Happy with my help? Buy me a coffee.
Please, always use the search before opening a new topic! We're all here on our (limited) free time! Make sure you help yourself too!
  •  
    The following users thanked this post: fox_mulder

Marius P.Topic starter

The PHPVibe do_action() hook is inspired by the hook with the same name used by WordPress.

It allows you to place actions that run on typical requests just as on WordPress.

 

Common actions in PHPVibe are:
//Common actions
function the_header(){
do_action('vibe_header');
}
function the_footer() {
do_action('vibe_footer');
}
function the_sidebar() {
if(is_admin() || (get_option('site-offline', 0) == 0 )) {
do_action('vibe_sidebar');
}
}
function right_sidebar() {
do_action('right_sidebar');
}
All are located in the file lib/functions.php

You can hook a function to an action hook using add_action().

Usage:
do_action( $tag, $arg );
Parameters
$tag
(string) (required) The name of the hook you wish to execute.
Default: None
$arg
(mixed) (optional) The list of arguments to send to this hook.
Default: Empty string
Happy with my help? Buy me a coffee.
Please, always use the search before opening a new topic! We're all here on our (limited) free time! Make sure you help yourself too!
  •  
    The following users thanked this post: fox_mulder

 

Similar topics (7)

Important Announcement: PHPVibe Video Sharing CMS End of Life

Started by Marius P.


Replies: 1
Views: 37192

The PHPVibe Archive is now public

Started by Marius P.


Replies: 0
Views: 16392

[ Video Sharing CMS v4 ] VideoSwiper Now Works with PHPVibe

Started by Digipath14


Replies: 1
Views: 1137

PHPVibe v5 Add Own Links for Different Player Resolutions.

Started by DeadFish


Replies: 3
Views: 1804

[ Video Sharing CMS v4 ] How is behave phpVibe at 600 users online

Started by AlexH


Replies: 5
Views: 3704

[ Video Sharing CMS v4 ] PHPvibe 4 Old captcha change new recaprcha

Started by hexertem


Replies: 3
Views: 1701