Elementor Code Reference
  • Developers
  • Code Reference
  • Docs
  • Blog
  • Account
  • Developers
  • Code Reference
  • Docs
  • Blog
  • Account

Base_Reporter

Base_Reporter()

Elementor base reporter.


Description

A base abstract class that provides the needed properties and methods to manage and handle reporter in inheriting classes.


Changelog

Changelog
Version Description
1.0.0 Introduced.

Methods

  • __construct — Reporter base constructor.
  • filter_possible_properties — Filter possible properties.
  • get_fields — Get report fields.
  • get_properties_keys — Get properties keys.
  • get_report — Get report.
  • get_title — Get report title.
  • is_enabled — Is report enabled.
  • set_properties — Set properties.

Source

includes/settings/system-info/classes/abstracts/base-reporter.php

abstract class Base_Reporter {

	private $_properties;

	abstract public function get_title();

	abstract public function get_fields();

	public function is_enabled() {
		return true;
	}

	final public function get_report() {
		$result = [];

		foreach ( $this->get_fields() as $field_name => $field_label ) {
			$method = 'get_' . $field_name;

			if ( ! method_exists( $this, $method ) ) {
				return new \WP_error( "Getter method for the field '{$field_name}' wasn't found in " . get_called_class() );
			}

			$reporter_field = [
				'name' => $field_name,
				'label' => $field_label,
			];

			$reporter_field = array_merge( $reporter_field, $this->$method() );
			$result[ $field_name ] = $reporter_field;
		}

		return $result;
	}

	public static function get_properties_keys() {
		return [
			'name',
			'fields',
		];
	}

	final public static function filter_possible_properties( $properties ) {
		return Model_Helper::filter_possible_properties( self::get_properties_keys(), $properties );
	}

	final public function set_properties( $key, $value = null ) {
		if ( is_array( $key ) ) {
			$key = self::filter_possible_properties( $key );

			foreach ( $key as $sub_key => $sub_value ) {
				$this->set_properties( $sub_key, $sub_value );
			}

			return;
		}

		if ( ! in_array( $key, self::get_properties_keys() ) ) {
			return;
		}

		$this->_properties[ $key ] = $value;
	}

	public function __construct( $properties = null ) {
		$this->_properties = array_fill_keys( self::get_properties_keys(), null );

		if ( $properties ) {
			$this->set_properties( $properties, null );
		}
	}
}
Elementor Code Reference
  • Code Reference
  • Elementor Hooks
    • PHP Hooks
    • JS Hooks
  • Elementor Classes
  • Elementor Methods
  • Elementor Functions
Developer Resources

Visit the official Developer Resources to learn how to extend Elementor.

Get Involved

Visit Elementor GitHub repository to contribute code or suggest new ideas.

  • Contact
  • About Us
  • Terms of Service
  • Privacy Policy
  • Template Library
  • Features
  • Theme Builder
  • Get Pro
Theme by Pojo.me
//Made in Elementor Page Builder
Enter your email and be the first to learn about new updates and features.
No thanks, I just want to download Elementor