weblib.php format_text and format_string

weblib.php format_text and format_string

by tim st.clair -
Number of replies: 1
Picture of Plugin developers

Is there a way to extend / overload / etc the format_text and format_string functions from a plugin or theme? I'm just toying with ideas at the moment, and want to toy with ALL string outputs from wherever they are in the system, be it my plugins or core or whatever.

If at all possible I don't want to just outright replace weblib.php because of the upgrade factor - changes overwritten and all that. If not possible without changing weblib, I'd like to add some kind of plugin check / perhaps a foreach(plugin) if function_exists(format_text) kind of loop to check local plugins (can't really see a better category), or perhaps just a require(my_theme/lib.php) if function_exists(format_text) kind of coding arrangement so that it can call out to before returning. e.g.

// weblib.php, Line ~1234
// this is probably going to be horrible for performance, but anyway ...
include_once($CFG->dirroot .'/theme/'.$PAGE->theme->name.'/lib.php');
$function = 'theme_'.$PAGE->theme->name.'_format_text';
if (function_exists($function)) {
$text = $function($text);
}

return $text;

Anyone ever tinkered with this stuff?

Average of ratings: -
In reply to tim st.clair

Re: weblib.php format_text and format_string

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Unless you are wanting to do something very strange with these functions, I suspect that creating a filter plugin will do what you want.