Skip to content

Instantly share code, notes, and snippets.

@cklosowski
Last active October 14, 2026 21:28
Show Gist options
  • Select an option

  • Save cklosowski/0f0d605942e5372d4a41 to your computer and use it in GitHub Desktop.

Select an option

Save cklosowski/0f0d605942e5372d4a41 to your computer and use it in GitHub Desktop.
Registering EDD 3.7 settings with a subscriber class
<?php
/**
* Registers the extension's event subscribers once Easy Digital Downloads has loaded.
*
* @since 1.0.0
* @return void
*/
function myext_register_subscribers() {
if ( ! class_exists( '\\EDD\\EventManagement\\EventManager' ) ) {
return;
}
$events = new \EDD\EventManagement\EventManager();
$events->add_subscriber( new \MyExtension\Admin\Settings() );
}
add_action( 'plugins_loaded', 'myext_register_subscribers' );
<?php
/**
* Registers the My Extension settings with Easy Digital Downloads.
*
* @package MyExtension\Admin
* @copyright Copyright (c) 2026, Your Name
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/
namespace MyExtension\Admin;
use EDD\EventManagement\SubscriberInterface;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Settings class.
*
* @since 1.0.0
*/
class Settings implements SubscriberInterface {
/**
* The settings section ID.
*
* @since 1.0.0
* @var string
*/
const SECTION = 'myext';
/**
* Gets the events this class subscribes to.
*
* @since 1.0.0
* @return array
*/
public static function get_subscribed_events() {
return array(
'edd_settings_sections_extensions' => 'register_section',
'edd_settings_extensions' => 'register_settings',
);
}
/**
* Adds the My Extension section to the Extensions settings tab.
*
* @since 1.0.0
*
* @param array $sections The registered sections for the tab.
* @return array The sections, with ours added.
*/
public function register_section( $sections ) {
$sections[ self::SECTION ] = __( 'My Extension', 'my-extension' );
return $sections;
}
/**
* Adds the My Extension settings to its section.
*
* @since 1.0.0
*
* @param array $settings The registered settings for the tab, keyed by section.
* @return array The settings, with ours added.
*/
public function register_settings( $settings ) {
$settings[ self::SECTION ] = array(
'myext_enable_feature' => array(
'id' => 'myext_enable_feature',
'name' => __( 'Feature', 'my-extension' ),
'check' => __( 'Enable the feature.', 'my-extension' ),
'desc' => __( 'When enabled, My Extension adds the feature to your store.', 'my-extension' ),
'type' => 'checkbox_toggle',
),
);
return $settings;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment