I use a theme which has a public static function to display a part of a page like:
trait SomeTrait {
public static function some_function() {
?>
<div class="some_class">Some content</div>
<?
}
}
and the helper file looks like:
class Helper {
use SomeTrait;
// ...
}
I need to override the function in my plugin.
In the plugin I try the code:
/*
Plugin Name: MyPlugin
Description: -
Version: 1.0
Author: -
*/
if ( ! defined( 'ABSPATH' ) ) exit;
class Extra extends Helper {
trait SomeTrait{
function some_function() {
?>
<div>Test</div>
<?php
}
}
}
But I receive the fatal error: Class ‘Helper’ not found in …
UPDATE
If I try:
function my_function() {
class Extra extends Helper {
public static function some_function() {
?>
<div>Test</div>
<?php
}
}
}
add_action( 'init', 'my_function' ); // with the 'after_theme_setup' the result is the same
I don’t receive any errors, but my function doesn’t override the existing one