Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SOLVED How to hook filter to component content?
#1
I'm developing plugin for personal purposes.

I want to filter content of a component. I know that I can hook to page content through `add_filter('content', 'fun_name');` but it does not contain component content.

In template component content is returned through `<?php get_component('component-3'); ?>`.

It seems that neither `add_filter('component', 'fun_name');` or `add_filter('component-3', 'fun_name');` work.

How to filter component content?
Reply
#2
There is no such a hook exists. There is a function get_component(), but it is really useless because it does not return the component but processes it immediately (should normally be named "exec_component"). Don't waste your time on it, rather create a custom function/plugin instead.

You can execute your function on any action and alter the content of your component:
PHP Code:
add_action('theme-header''modify_component', array('your-component-slug')); 

And the function may look like this:
PHP Code:
function modify_component($id) {
 
   global $components;

 
   if(!$components) {
        
$components = array();
 
       if(file_exists(GSDATAOTHERPATH.'components.xml')) {
 
           $data getXML(GSDATAOTHERPATH.'components.xml');
 
           $components $data->item;
 
       }
 
   }
 
   
    foreach
($components as $component) {
 
       if($component->slug == $id) {
 
           $newValue 'New component value';
 
           $component->value $newValue;
 
       }
 
   }    

Reply
#3
Very useful code example, thanks for posting.

More about this here:
http://get-simple.info/wiki/plugins:creation
http://get-simple.info/wiki/core_docs:plugin_functions
Reply
#4
Thank you for your reply and useful resources.
Reply
#5
in 3.4 I think there is a get component xml or a way to get raw, i would have to look
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply




Users browsing this thread: 1 Guest(s)