• 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)