diff --git a/includes/class-admin.php b/includes/class-admin.php new file mode 100644 index 00000000..2ec87e62 --- /dev/null +++ b/includes/class-admin.php @@ -0,0 +1,188 @@ + Site_Role::OPTION_NAME, + 'label' => esc_html__( 'Site Role', 'newspack-network' ), + 'callback' => [ __CLASS__, 'site_role_callback' ], + 'args' => [ + 'sanitize_callback' => [ 'Newspack_Network\Site_Role', 'sanitize' ], + ], + ], + ]; + foreach ( $settings as $setting ) { + add_settings_field( + $setting['key'], + $setting['label'], + $setting['callback'], + self::PAGE_SLUG, + self::SETTINGS_SECTION + ); + register_setting( + self::PAGE_SLUG, + $setting['key'], + $setting['args'] ?? [] + ); + } + } + + /** + * The Settings page callback + * + * @return void + */ + public static function section_callback() { + // Nothing here for now. + } + + /** + * The hub_url setting callback + * + * @return void + */ + public static function site_role_callback() { + $role = Site_Role::get(); + ?> + + +
+ +
+ +

+ ' /> +

+
+
+ id !== $page_slug ) { return; } diff --git a/includes/hub/class-admin.php b/includes/hub/class-admin.php index 0635beab..701ad9e7 100644 --- a/includes/hub/class-admin.php +++ b/includes/hub/class-admin.php @@ -11,81 +11,15 @@ * Class to handle the plugin admin pages */ class Admin { - const PAGE_SLUG = 'newspack-hub'; /** * Runs the initialization. */ public static function init() { - add_action( 'admin_menu', array( __CLASS__, 'add_admin_menu' ) ); - Admin\Event_Log::init(); Admin\Subscriptions::init(); Admin\Orders::init(); Distributor_Settings::init(); } - /** - * Adds the admin page - * - * @return void - */ - public static function add_admin_menu() { - $page_suffix = add_menu_page( - __( 'Newspack Hub', 'newspack-network-hub' ), - __( 'Newspack Hub', 'newspack-network-hub' ), - 'manage_options', - self::PAGE_SLUG, - array( __CLASS__, 'render_page' ) - ); - - add_action( 'load-' . $page_suffix, array( __CLASS__, 'admin_init' ) ); - } - - /** - * Adds a child admin page to the main Newspack Hub admin page - * - * @param string $title The menu title. - * @param string $slug The menu slug. - * @param callable $callback The function to be called to output the content for this page. - * @return string|false The resulting page's hook_suffix, or false if the user does not have the capability required. - */ - public static function add_submenu_page( $title, $slug, $callback ) { - return add_submenu_page( - self::PAGE_SLUG, - $title, - $title, - 'manage_options', - $slug, - $callback - ); - } - - /** - * Renders the page content - * - * @return void - */ - public static function render_page() { - echo '
'; - } - - /** - * Callback for the load admin page hook. - * - * @return void - */ - public static function admin_init() { - add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); - } - - /** - * Enqueue admin page assets. - * - * @return void - */ - public static function enqueue_scripts() { - - } - } diff --git a/includes/hub/class-distributor-settings.php b/includes/hub/class-distributor-settings.php index d5a287f3..f2e40512 100644 --- a/includes/hub/class-distributor-settings.php +++ b/includes/hub/class-distributor-settings.php @@ -9,6 +9,7 @@ use Newspack\Data_Events; use Newspack_Network\Accepted_Actions; +use Newspack_Network\Admin as Network_Admin; /** * Class to handle Node settings page @@ -69,7 +70,7 @@ public static function get_canonical_node() { * @return void */ public static function add_menu() { - Admin::add_submenu_page( __( 'Distributor Settings', 'newspack-network' ), self::PAGE_SLUG, [ __CLASS__, 'render' ] ); + Network_Admin::add_submenu_page( __( 'Distributor Settings', 'newspack-network' ), self::PAGE_SLUG, [ __CLASS__, 'render' ] ); } /** diff --git a/includes/hub/class-nodes.php b/includes/hub/class-nodes.php index c4860dcb..a0b997af 100644 --- a/includes/hub/class-nodes.php +++ b/includes/hub/class-nodes.php @@ -8,6 +8,7 @@ namespace Newspack_Network\Hub; use Newspack_Network\Crypto; +use Newspack_Network\Admin as Network_Admin; /** * Class to handle Nodes post type @@ -137,7 +138,7 @@ public static function register_post_type() { 'hierarchical' => false, 'public' => false, 'show_ui' => true, - 'show_in_menu' => Admin::PAGE_SLUG, + 'show_in_menu' => Network_Admin::PAGE_SLUG, 'can_export' => false, 'capability_type' => 'page', 'show_in_rest' => false, diff --git a/includes/hub/database/class-orders.php b/includes/hub/database/class-orders.php index fd458c1b..f4217140 100644 --- a/includes/hub/database/class-orders.php +++ b/includes/hub/database/class-orders.php @@ -8,6 +8,7 @@ namespace Newspack_Network\Hub\Database; use Newspack_Network\Hub\Admin; +use Newspack_Network\Admin as Network_Admin; use Newspack_Network\Debugger; /** @@ -76,7 +77,7 @@ public static function register_post_type() { 'hierarchical' => false, 'public' => false, 'show_ui' => true, - 'show_in_menu' => Admin::PAGE_SLUG, + 'show_in_menu' => Network_Admin::PAGE_SLUG, 'can_export' => false, 'capability_type' => 'post', 'show_in_rest' => false, diff --git a/includes/hub/database/class-subscriptions.php b/includes/hub/database/class-subscriptions.php index 257353b3..b7526186 100644 --- a/includes/hub/database/class-subscriptions.php +++ b/includes/hub/database/class-subscriptions.php @@ -8,6 +8,7 @@ namespace Newspack_Network\Hub\Database; use Newspack_Network\Hub\Admin; +use Newspack_Network\Admin as Network_Admin; use Newspack_Network\Debugger; /** @@ -76,7 +77,7 @@ public static function register_post_type() { 'hierarchical' => false, 'public' => false, 'show_ui' => true, - 'show_in_menu' => Admin::PAGE_SLUG, + 'show_in_menu' => Network_Admin::PAGE_SLUG, 'can_export' => false, 'capability_type' => 'post', 'show_in_rest' => false, diff --git a/includes/node/class-admin.php b/includes/node/class-admin.php deleted file mode 100644 index 8acec3fe..00000000 --- a/includes/node/class-admin.php +++ /dev/null @@ -1,86 +0,0 @@ -'; - } - - /** - * Callback for the load admin page hook. - * - * @return void - */ - public static function admin_init() { - add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); - } - - /** - * Enqueue admin page assets. - * - * @return void - */ - public static function enqueue_scripts() { - - } - -} diff --git a/includes/node/class-settings.php b/includes/node/class-settings.php index 5a14f41f..23ce3e28 100644 --- a/includes/node/class-settings.php +++ b/includes/node/class-settings.php @@ -7,6 +7,8 @@ namespace Newspack_Network\Node; +use Newspack_Network\Admin; + /** * Class to handle Node settings page */