Insomnia1988
Grünschnabel
Hi,
ich hänge hier gerade fest. Ich habe ein Plugin in Wordpress, welches als Klasse (plugin.php) aufgebaut ist. In dieser Klasse include ich andere Klassen und setze sie als public Variablen.
Eine Methode der plugin.php nutzt nun eine Wordpress/Elementor Funktion um eine andere Klasse (current-year.php) zu callen (
Und hier liegt das Problem: Ich weiß nicht wie ich von dieser gecallten Klasse auf die Funktion der plugin.php zugreifen kann (sie ist keine Eltern Klasse per Definition sondern nur weil sie Sachen vererben kann).
Nochmal als Beispiel-Code:
plugin.php
current-year.php
ich hänge hier gerade fest. Ich habe ein Plugin in Wordpress, welches als Klasse (plugin.php) aufgebaut ist. In dieser Klasse include ich andere Klassen und setze sie als public Variablen.
Eine Methode der plugin.php nutzt nun eine Wordpress/Elementor Funktion um eine andere Klasse (current-year.php) zu callen (
register_tag
).Und hier liegt das Problem: Ich weiß nicht wie ich von dieser gecallten Klasse auf die Funktion der plugin.php zugreifen kann (sie ist keine Eltern Klasse per Definition sondern nur weil sie Sachen vererben kann).
Nochmal als Beispiel-Code:
plugin.php
Code:
namespace My_App_Config;
class My_App_Config {
private static $_instance = null;
public $functions;
public static function instance() {
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct() {
add_action('plugins_loaded', [$this, 'init']);
}
public function init() {
include_once plugin_dir_path(__FILE__).'includes/class.Functions.php';
$this->functions = new \CustomFunctions();
add_action('elementor/dynamic_tags/register_tags', [$this, 'init_dynamic_tags'], 20);
}
public function init_dynamic_tags($dynamic_tags) {
require_once __DIR__ . '/includes/dynamic-tags/current-year.php';
$dynamic_tags->register_tag('Elementor_Current_Year');
}
}
My_App_Config::instance();
current-year.php
Code:
Class Elementor_Current_year extends \Elementor\Core\DynamicTags\Data_Tag {
public function get_name() {
return 'current-year';
}
public function get_title() {
return 'Current Year';
}
public function get_group() {
return [ 'site' ];
}
public function get_value( array $options = [] ) {
$img_path = $this->functions->get_image_path(); // this throws an error because it's not there (obviously)
return [
'id' => null,
'url' => $img_path,
];
}
public function get_categories() {
return [ 'image' ];
}
}