namespace WPForms\Admin\Education;
use WPForms\Admin\Addons\Addons;
use WPForms\Requirements\Requirements;
* Base class for all "addon item" type Education features.
abstract class AddonsItemBase implements EducationInterface {
* Instance of the Education\Core class.
* Instance of the Education\Addons class.
* Template name for rendering single addon item.
protected $single_addon_template;
* Indicate if the current Education feature is allowed to load.
* Should be called from the child feature class.
* @noinspection PhpMissingReturnTypeInspection
* @noinspection ReturnTypeCanBeDeclaredInspection
abstract public function allow_load();
* @noinspection ReturnTypeCanBeDeclaredInspection
if ( ! $this->allow_load() ) {
// Store the instance of the Education core class.
$this->education = wpforms()->obj( 'education' );
// Store the instance of the Education\Addons class.
$this->addons = wpforms()->obj( 'addons' );
abstract public function hooks();
* Display single addon item.
* @param array $addon Addon data.
* @noinspection ReturnTypeCanBeDeclaredInspection
* @noinspection PhpMissingParamTypeInspection
protected function display_single_addon( $addon ) {
* Filter to disallow addons to be displayed in the Education feature.
* @param bool $display Whether to hide the addon.
* @param array $slug Addon data.
$is_disallowed = (bool) apply_filters( 'wpforms_admin_education_addons_item_base_display_single_addon_hide', false, $addon );
if ( empty( $addon ) || $is_disallowed ) {
echo wpforms_render( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$this->single_addon_template,
* Prepare field data-attributes for the education actions.
* E.g., install, activate, incompatible.
* @param array $addon Current addon information.
protected function prepare_field_action_data( array $addon ): array {
if ( empty( $addon['plugin_allow'] ) ) {
if ( $addon['action'] === 'install' ) {
'name' => $addon['modal_name'],
'nonce' => wp_create_nonce( 'wpforms-admin' ),
'license' => $addon['license_level'],
'class' => 'education-modal',
if ( $addon['action'] === 'activate' ) {
'name' => sprintf( /* translators: %s - addon name. */
esc_html__( '%s addon', 'wpforms-lite' ),
'path' => $addon['path'],
'nonce' => wp_create_nonce( 'wpforms-admin' ),
'class' => 'education-modal',
if ( $addon['action'] === 'incompatible' ) {
'action' => 'incompatible',
'message' => Requirements::get_instance()->get_notice( $addon['path'] ),
'class' => 'education-modal',