-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a3740c
commit e039c4b
Showing
2 changed files
with
125 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | ||
} | ||
} |