• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Overwrite public function in

Marcus

Well-known member
#1
To overwrite private function protected static function _getDefaultAvatarUrl() my plan is to overwrite the public function public static function getAvatarUrl() that uses the private one exclusively.*

How could I overwrite the public function? My addon listens on load_class_model and once the class is XenForo_Template_Helper_Core where the public function is located I extend that to my personal Core.php:
PHP:
<?php
class MyAddon_Core extends XFCP_MyAddon_Core
 
public static function getAvatarUrl(array $user, $size, $forceType = '')
{  return ''; }
I want to disable all avatars with this test, however everything works as usual. Any ideas?


(* with the exception of gravatar functionality I disabled)

Similar thread: http://xenforo.com/community/thread...-class-and-override-protected-function.25889/
 

infis

Well-known member
#3
In library/config.php add:
Code:
Proxy_Autoloader::proxyInstance();
After need copy library/XenForo/Template/Helper/Core.php to library/Proxy/XenForo/Template/Helper/Core.php and change code as you want. In runtime will be used class from proxy.
It work without extending original class.
 

Marcus

Well-known member
#4
This is a great idea. However I want to make the changes as small as possible. The class Core.php is rather huge and I would very much prefer to only manipulate what I really have to change.