GetSimple Support Forum
SOLVED How to hook filter to component content? - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: Developer Discussions (http://get-simple.info/forums/forumdisplay.php?fid=8)
+--- Thread: SOLVED How to hook filter to component content? (/showthread.php?tid=14958)



How to hook filter to component content? - tariel36 - 2020-08-26

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?


RE: How to hook filter to component content? - Bigin - 2020-08-26

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;
 
       }
 
   }    




RE: How to hook filter to component content? - Felix - 2020-08-27

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


RE: How to hook filter to component content? - tariel36 - 2020-08-27

Thank you for your reply and useful resources.


RE: How to hook filter to component content? - shawn_a - 2020-08-28

in 3.4 I think there is a get component xml or a way to get raw, i would have to look