Skip to content

Commit

Permalink
feat: settings php initial
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredrethman committed Jun 4, 2024
1 parent 9a3740c commit e039c4b
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 14 deletions.
29 changes: 15 additions & 14 deletions includes/class-wizards.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ class Wizards {
*/
public static function init() {
self::$wizards = [
'setup' => new Setup_Wizard(),
'dashboard' => new Dashboard(),
'site-design' => new Site_Design_Wizard(),
'reader-revenue' => new Reader_Revenue_Wizard(),
'advertising' => new Advertising_Wizard(),
'syndication' => new Syndication_Wizard(),
'analytics' => new Analytics_Wizard(),
'components-demo' => new Components_Demo(),
'seo' => new SEO_Wizard(),
'health-check' => new Health_Check_Wizard(),
'engagement' => new Engagement_Wizard(),
'popups' => new Popups_Wizard(),
'connections' => new Connections_Wizard(),
'settings' => new Settings(),
'setup' => new Setup_Wizard(),
'dashboard' => new Dashboard(),
'site-design' => new Site_Design_Wizard(),
'reader-revenue' => new Reader_Revenue_Wizard(),
'advertising' => new Advertising_Wizard(),
'syndication' => new Syndication_Wizard(),
'analytics' => new Analytics_Wizard(),
'components-demo' => new Components_Demo(),
'seo' => new SEO_Wizard(),
'health-check' => new Health_Check_Wizard(),
'engagement' => new Engagement_Wizard(),
'popups' => new Popups_Wizard(),
'connections' => new Connections_Wizard(),
'settings' => new Settings(),
'newspack-settings' => new Newspack_Settings(),
];
}

Expand Down
110 changes: 110 additions & 0 deletions includes/wizards/class-newspack-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* Newspack Settings Admin Page
*
* @package Newspack
*/

namespace Newspack;

defined( 'ABSPATH' ) || exit;

require_once NEWSPACK_ABSPATH . '/includes/wizards/class-wizard.php';

/**
* Common functionality for admin wizards. Override this class.
*/
class Newspack_Settings extends Wizard {

/**
* The slug of this wizard.
*
* @var string
*/
protected $slug = 'newspack-settings';

/**
* The capability required to access this.
*
* @var string
*/
protected $capability = 'manage_options';

/**
* Priority setting for ordering admin submenu items. Dashboard must come first.
*
* @var int.
*/
protected $menu_priority = 1;

/**
* Initialize.
*/
public function __construct() {
add_action( 'admin_menu', [ $this, 'add_page' ], 1 );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts_and_styles' ] );
}

/**
* Get Dashboard data
*
* @return []
*/
public function get_local_data() {
return [];
}

/**
* Get the name for this wizard.
*
* @return string The wizard name.
*/
public function get_name() {
return esc_html__( 'Newspack', 'newspack' );
}

/**
* Add an admin page for the wizard to live on.
*/
public function add_page() {
add_submenu_page(
'newspack',
__( 'Newspack / Settings', 'newspack-plugin' ),
__( 'Settings', 'newspack-plugin' ),
$this->capability,
$this->slug,
[ $this, 'render_wizard' ]
);
}

/**
* Load up JS/CSS.
*/
public function enqueue_scripts_and_styles() {
parent::enqueue_scripts_and_styles();

if ( filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) !== $this->slug ) {
return;
}

wp_register_script(
'newspack-settings',
Newspack::plugin_url() . '/dist/newspack-settings.js',
$this->get_script_dependencies(),
NEWSPACK_PLUGIN_VERSION,
true
);

$site_name = get_bloginfo( 'name' );
$theme_mods = get_theme_mods();

wp_localize_script(
'newspack-settings',
'newspack_settings',
[
'settings' => '',
]
);
wp_enqueue_script( 'newspack-settings' );
}
}

0 comments on commit e039c4b

Please sign in to comment.