diff --git a/includes/class-newspack.php b/includes/class-newspack.php index e0e88f02de..95caa527be 100644 --- a/includes/class-newspack.php +++ b/includes/class-newspack.php @@ -124,6 +124,7 @@ private function includes() { include_once NEWSPACK_ABSPATH . 'includes/revisions-control/class-revisions-control.php'; include_once NEWSPACK_ABSPATH . 'includes/authors/class-authors-custom-fields.php'; include_once NEWSPACK_ABSPATH . 'includes/corrections/class-corrections.php'; + include_once NEWSPACK_ABSPATH . 'includes/class-syndication.php'; include_once NEWSPACK_ABSPATH . 'includes/bylines/class-bylines.php'; include_once NEWSPACK_ABSPATH . 'includes/starter_content/class-starter-content-provider.php'; @@ -142,6 +143,7 @@ private function includes() { include_once NEWSPACK_ABSPATH . 'includes/wizards/newspack/class-newspack-dashboard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/newspack/class-newspack-settings.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/newspack/class-custom-events-section.php'; + include_once NEWSPACK_ABSPATH . 'includes/wizards/newspack/class-syndication-section.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/newspack/class-seo-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/newspack/class-pixels-section.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/newspack/class-recirculation-section.php'; @@ -168,10 +170,8 @@ private function includes() { include_once NEWSPACK_ABSPATH . 'includes/wizards/class-newsletters-wizard.php'; /* Unified Wizards */ - include_once NEWSPACK_ABSPATH . 'includes/wizards/class-settings.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/class-analytics-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/class-engagement-wizard.php'; - include_once NEWSPACK_ABSPATH . 'includes/wizards/class-syndication-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/class-health-check-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/wizards/class-connections-wizard.php'; include_once NEWSPACK_ABSPATH . 'includes/class-wizards.php'; diff --git a/includes/wizards/class-settings.php b/includes/class-syndication.php similarity index 57% rename from includes/wizards/class-settings.php rename to includes/class-syndication.php index 73230224c3..451b1f9d5a 100644 --- a/includes/wizards/class-settings.php +++ b/includes/class-syndication.php @@ -1,6 +1,6 @@ hidden = true; } /** * Get all settings. */ - private static function get_settings() { + public static function get_settings() { $default_settings = [ self::MODULE_ENABLED_PREFIX . 'rss' => false, self::MODULE_ENABLED_PREFIX . 'media-partners' => false, ]; - return wp_parse_args( get_option( self::SETTINGS_OPTION_NAME ), $default_settings ); + return wp_parse_args( get_option( self::OPTION_NAME ), $default_settings ); } /** * Get the list of available optional modules. */ - private static function get_available_optional_modules() { + public static function get_available_optional_modules() { return [ 'rss' ]; } @@ -73,7 +67,7 @@ public static function api_get_settings() { * @param string $module_name Name of the module. */ public static function is_optional_module_active( $module_name ) { - $settings = self::api_get_settings(); + $settings = self::get_settings(); $setting_name = self::MODULE_ENABLED_PREFIX . $module_name; if ( isset( $settings[ $setting_name ] ) ) { return $settings[ $setting_name ]; @@ -100,7 +94,7 @@ private static function update_setting( $key, $value ) { $settings = self::get_settings(); if ( isset( $settings[ $key ] ) ) { $settings[ $key ] = $value; - update_option( self::SETTINGS_OPTION_NAME, $settings ); + update_option( self::OPTION_NAME, $settings ); } return $settings; } @@ -117,45 +111,8 @@ public static function api_update_settings( $request ) { $setting_name = self::MODULE_ENABLED_PREFIX . $module_name; $settings[ $setting_name ] = $request->get_param( $setting_name ); } - update_option( self::SETTINGS_OPTION_NAME, $settings ); - return self::api_get_settings(); - } - - /** - * Register the endpoints needed for the wizard screens. - */ - public function register_api_endpoints() { - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug, - [ - 'methods' => \WP_REST_Server::READABLE, - 'callback' => [ $this, 'api_get_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - ] - ); - - $required_args = array_reduce( - self::get_available_optional_modules(), - function( $acc, $module_name ) { - $acc[ self::MODULE_ENABLED_PREFIX . $module_name ] = [ - 'required' => true, - 'sanitize_callback' => 'rest_sanitize_boolean', - ]; - return $acc; - }, - [] - ); - register_rest_route( - NEWSPACK_API_NAMESPACE, - '/wizard/' . $this->slug, - [ - 'methods' => \WP_REST_Server::EDITABLE, - 'callback' => [ $this, 'api_update_settings' ], - 'permission_callback' => [ $this, 'api_permissions_check' ], - 'args' => $required_args, - ] - ); + update_option( self::OPTION_NAME, $settings ); + return self::get_settings(); } /** @@ -164,7 +121,7 @@ function( $acc, $module_name ) { * @return string The wizard name. */ public function get_name() { - return \esc_html__( 'Settings', 'newspack' ); + return esc_html__( 'Settings', 'newspack' ); } /** @@ -173,7 +130,7 @@ public function get_name() { * @return string The wizard description. */ public function get_description() { - return \esc_html__( 'Configure settings.', 'newspack' ); + return esc_html__( 'Configure settings.', 'newspack' ); } /** diff --git a/includes/class-wizards.php b/includes/class-wizards.php index 3ab79a96c2..8f92eaee03 100644 --- a/includes/class-wizards.php +++ b/includes/class-wizards.php @@ -29,14 +29,12 @@ class Wizards { */ public static function init() { self::$wizards = [ - '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(), 'connections' => new Connections_Wizard(), - 'settings' => new Settings(), // v2 Information Architecture. 'newspack-dashboard' => new Newspack_Dashboard(), 'setup' => new Setup_Wizard(), @@ -46,6 +44,7 @@ public static function init() { 'custom-events' => 'Newspack\Wizards\Newspack\Custom_Events_Section', 'social-pixels' => 'Newspack\Wizards\Newspack\Pixels_Section', 'recirculation' => 'Newspack\Wizards\Newspack\Recirculation_Section', + 'syndication' => 'Newspack\Wizards\Newspack\Syndication_Section', ], ] ), diff --git a/includes/optional-modules/class-media-partners.php b/includes/optional-modules/class-media-partners.php index 26c6d67370..149299d6b4 100644 --- a/includes/optional-modules/class-media-partners.php +++ b/includes/optional-modules/class-media-partners.php @@ -19,7 +19,7 @@ class Media_Partners { * Initialize everything. */ public static function init() { - if ( ! Settings::is_optional_module_active( 'media-partners' ) ) { + if ( ! Syndication::is_optional_module_active( 'media-partners' ) ) { return; } diff --git a/includes/optional-modules/class-rss.php b/includes/optional-modules/class-rss.php index a8fdbe995e..676a940bc1 100644 --- a/includes/optional-modules/class-rss.php +++ b/includes/optional-modules/class-rss.php @@ -21,7 +21,7 @@ class RSS { * Initialise. */ public static function init() { - if ( ! Settings::is_optional_module_active( 'rss' ) ) { + if ( ! Syndication::is_optional_module_active( 'rss' ) ) { return; } diff --git a/includes/wizards/class-syndication-wizard.php b/includes/wizards/class-syndication-wizard.php deleted file mode 100644 index 2c127e3220..0000000000 --- a/includes/wizards/class-syndication-wizard.php +++ /dev/null @@ -1,75 +0,0 @@ -slug ) { - return; - } - - \wp_enqueue_script( - 'newspack-syndication-wizard', - Newspack::plugin_url() . '/dist/syndication.js', - $this->get_script_dependencies(), - NEWSPACK_PLUGIN_VERSION, - true - ); - } -} diff --git a/includes/wizards/newspack/class-syndication-section.php b/includes/wizards/newspack/class-syndication-section.php new file mode 100644 index 0000000000..3c8f65555e --- /dev/null +++ b/includes/wizards/newspack/class-syndication-section.php @@ -0,0 +1,74 @@ +wizard_slug . '/syndication', + [ + 'methods' => WP_REST_Server::READABLE, + 'callback' => [ Syndication::class, 'api_get_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + ] + ); + + $required_args = array_reduce( + Syndication::get_available_optional_modules(), + function( $acc, $module_name ) { + $acc[ Syndication::MODULE_ENABLED_PREFIX . $module_name ] = [ + 'required' => true, + 'sanitize_callback' => 'rest_sanitize_boolean', + ]; + return $acc; + }, + [] + ); + register_rest_route( + NEWSPACK_API_NAMESPACE, + '/wizard/' . $this->wizard_slug . '/syndication', + [ + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => [ Syndication::class, 'api_update_settings' ], + 'permission_callback' => [ $this, 'api_permissions_check' ], + 'args' => $required_args, + ] + ); + } +} diff --git a/src/wizards/newspack/views/settings/syndication/rss.tsx b/src/wizards/newspack/views/settings/syndication/rss.tsx index 680b974474..8ea6fa5af1 100644 --- a/src/wizards/newspack/views/settings/syndication/rss.tsx +++ b/src/wizards/newspack/views/settings/syndication/rss.tsx @@ -10,20 +10,26 @@ import WizardsActionCard from '../../../../wizards-action-card'; import useWizardApiFetchToggle from '../../../../hooks/use-wizard-api-fetch-toggle'; function Rss() { - const { description, apiData, isFetching, actionText, apiFetchToggle, errorMessage } = - useWizardApiFetchToggle< RssData >( { - path: '/newspack/v1/wizard/newspack-settings-wizard', - apiNamespace: 'newspack-settings/syndication/rss', - refreshOn: [ 'POST' ], - data: { - module_enabled_rss: false, - 'module_enabled_media-partners': false, - }, - description: __( - 'Create and manage customized RSS feeds for syndication partners', - 'newspack-plugin' - ), - } ); + const { + description, + apiData, + isFetching, + actionText, + apiFetchToggle, + errorMessage, + } = useWizardApiFetchToggle< RssData >( { + path: '/newspack/v1/wizard/newspack-settings/syndication', + apiNamespace: 'newspack-settings/syndication/rss', + refreshOn: [ 'POST' ], + data: { + module_enabled_rss: false, + 'module_enabled_media-partners': false, + }, + description: __( + 'Create and manage customized RSS feeds for syndication partners', + 'newspack-plugin' + ), + } ); return ( - apiFetchToggle( { ...apiData, module_enabled_rss: value }, true ) + apiFetchToggle( + { ...apiData, module_enabled_rss: value }, + true + ) } /> ); diff --git a/src/wizards/syndication/index.js b/src/wizards/syndication/index.js deleted file mode 100644 index 20dd4637c0..0000000000 --- a/src/wizards/syndication/index.js +++ /dev/null @@ -1,36 +0,0 @@ -import '../../shared/js/public-path'; - -/** - * Syndication - */ - -/** - * WordPress dependencies. - */ -import { render, createElement } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; - -/** - * Internal dependencies. - */ -import { Wizard } from '../../components/src'; -import { Intro } from './views'; - -const SyndicationWizard = () => ( - -); - -render( - createElement( SyndicationWizard ), - document.getElementById( 'newspack-syndication-wizard' ) -); diff --git a/src/wizards/syndication/views/index.js b/src/wizards/syndication/views/index.js deleted file mode 100644 index d92bbe045a..0000000000 --- a/src/wizards/syndication/views/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as Intro } from './intro'; diff --git a/src/wizards/syndication/views/intro/index.js b/src/wizards/syndication/views/intro/index.js deleted file mode 100644 index c01570b577..0000000000 --- a/src/wizards/syndication/views/intro/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { useDispatch } from '@wordpress/data'; - -/** - * Internal dependencies - */ -import { PluginToggle, ActionCard, Wizard } from '../../../../components/src'; - -const Intro = () => { - const settingsData = Wizard.useWizardData( 'newspack-settings-wizard' ); - const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE ); - return ( - <> - { - saveWizardSettings( { - slug: 'newspack-settings-wizard', - updatePayload: { - path: [ 'module_enabled_rss' ], - value, - }, - } ).then( () => { - window.location.reload( true ); - } ); - } } - /> - - - ); -}; - -export default Intro; diff --git a/tests/unit-tests/settings.php b/tests/unit-tests/syndication.php similarity index 75% rename from tests/unit-tests/settings.php rename to tests/unit-tests/syndication.php index 8730f011ce..04fb110a64 100644 --- a/tests/unit-tests/settings.php +++ b/tests/unit-tests/syndication.php @@ -5,7 +5,7 @@ * @package Newspack\Tests */ -use Newspack\Settings; +use Newspack\Syndication; /** * Tests the Settings. @@ -15,7 +15,7 @@ class Newspack_Test_Settings extends WP_UnitTestCase { * Setup for the tests. */ public function set_up() { - delete_option( Settings::SETTINGS_OPTION_NAME ); + delete_option( Syndication::OPTION_NAME ); } /** @@ -23,7 +23,7 @@ public function set_up() { */ public function test_settings_defaults() { self::assertEquals( - Settings::api_get_settings(), + Syndication::get_settings(), [ 'module_enabled_rss' => false, 'module_enabled_media-partners' => false, @@ -38,9 +38,9 @@ public function test_settings_defaults() { public function test_settings_update() { $request = new WP_REST_Request(); $request->set_param( 'module_enabled_rss', true ); - Settings::api_update_settings( $request ); + Syndication::api_update_settings( $request ); self::assertEquals( - Settings::api_get_settings(), + Syndication::get_settings(), [ 'module_enabled_rss' => true, 'module_enabled_media-partners' => false, @@ -49,9 +49,9 @@ public function test_settings_update() { ); $request->set_param( 'non_existent_setting', true ); - Settings::api_update_settings( $request ); + Syndication::api_update_settings( $request ); self::assertEquals( - Settings::api_get_settings(), + Syndication::get_settings(), [ 'module_enabled_rss' => true, 'module_enabled_media-partners' => false, @@ -65,15 +65,15 @@ public function test_settings_update() { */ public function test_settings_optional_modules() { self::assertEquals( - Settings::is_optional_module_active( 'rss' ), + Syndication::is_optional_module_active( 'rss' ), false, 'RSS module is not active by default.' ); - Settings::activate_optional_module( 'rss' ); + Syndication::activate_optional_module( 'rss' ); self::assertEquals( - Settings::is_optional_module_active( 'rss' ), + Syndication::is_optional_module_active( 'rss' ), true, 'RSS module is active after being activated.' );