diff --git a/projects/packages/blaze/changelog/add-blaze-new-filters b/projects/packages/blaze/changelog/add-blaze-new-filters new file mode 100644 index 0000000000000..bfb4db7a926dc --- /dev/null +++ b/projects/packages/blaze/changelog/add-blaze-new-filters @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Adds new filters for the Blaze module diff --git a/projects/packages/blaze/composer.json b/projects/packages/blaze/composer.json index 7c89848e2b5e2..281ecab1ecc07 100644 --- a/projects/packages/blaze/composer.json +++ b/projects/packages/blaze/composer.json @@ -64,7 +64,7 @@ "link-template": "https://github.com/automattic/jetpack-blaze/compare/v${old}...v${new}" }, "branch-alias": { - "dev-trunk": "0.20.x-dev" + "dev-trunk": "0.21.x-dev" }, "textdomain": "jetpack-blaze", "version-constants": { diff --git a/projects/packages/blaze/package.json b/projects/packages/blaze/package.json index e13decc2a00b6..1fb5c77b1774a 100644 --- a/projects/packages/blaze/package.json +++ b/projects/packages/blaze/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@automattic/jetpack-blaze", - "version": "0.20.3", + "version": "0.21.0-alpha", "description": "Attract high-quality traffic to your site using Blaze. Using this service, you can advertise a post or page on some of the millions of pages across WordPress.com and Tumblr from just $5 per day.", "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/blaze/#readme", "bugs": { diff --git a/projects/packages/blaze/src/class-blaze.php b/projects/packages/blaze/src/class-blaze.php index 5274c4141244a..41066bd05181e 100644 --- a/projects/packages/blaze/src/class-blaze.php +++ b/projects/packages/blaze/src/class-blaze.php @@ -92,23 +92,13 @@ public static function is_dashboard_enabled() { return apply_filters( 'jetpack_blaze_dashboard_enable', $is_dashboard_enabled ); } - /** - * Is the Woo Blaze plugin active? - * The dashboard provided by that plugin takes precedence over Jetpack Blaze - * - * @return bool - */ - public static function is_woo_blaze_active() { - return is_plugin_active( 'woocommerce/woocommerce.php' ) && is_plugin_active( 'woo-blaze/woo-blaze.php' ); - } - /** * Enable the Blaze menu. * * @return void */ public static function enable_blaze_menu() { - if ( ! self::should_initialize() || self::is_woo_blaze_active() ) { + if ( ! self::should_initialize() ) { return; } @@ -256,19 +246,12 @@ public static function should_initialize() { * @return array An array with the link, and whether this is a Calypso or a wp-admin link. */ public static function get_campaign_management_url( $post_id ) { - $is_woo_blaze_active = self::is_woo_blaze_active(); - - if ( self::is_dashboard_enabled() || $is_woo_blaze_active ) { - // Woo Blaze uses a different admin section and path prefix - $admin_section = $is_woo_blaze_active ? 'admin.php' : 'tools.php'; - $blaze_path_prefix = $is_woo_blaze_active ? 'wc-blaze' : 'advertising'; - - $admin_url = admin_url( sprintf( '%1$s?page=%2$s', $admin_section, $blaze_path_prefix ) ); + if ( self::is_dashboard_enabled() ) { + $admin_url = admin_url( 'tools.php?page=advertising' ); $hostname = wp_parse_url( get_site_url(), PHP_URL_HOST ); $blaze_url = sprintf( - '%1$s#!/%2$s/posts/promote/post-%3$s/%4$s', + '%1$s#!/advertising/posts/promote/post-%2$s/%3$s', $admin_url, - $blaze_path_prefix, esc_attr( $post_id ), $hostname ); diff --git a/projects/packages/blaze/src/class-dashboard-config-data.php b/projects/packages/blaze/src/class-dashboard-config-data.php index 603fb9f8fb1d4..30fbf0e6c37b1 100644 --- a/projects/packages/blaze/src/class-dashboard-config-data.php +++ b/projects/packages/blaze/src/class-dashboard-config-data.php @@ -17,6 +17,32 @@ * Class Dashboard_Config_Data */ class Dashboard_Config_Data { + + /** + * Blaze dashboard admin page. Default is tools.php. + * + * @var string + */ + private $admin_page; + + /** + * Blaze dashboard menu slug. Default is 'advertising'. + * + * @var string + */ + private $menu_slug; + + /** + * Dashboard config constructor. + * + * @param string $admin_page Dashboard admin page. Default is tools.php. + * @param string $menu_slug Dashboard menu slug. Default is 'advertising'. + */ + public function __construct( $admin_page = 'tools.php', $menu_slug = 'advertising' ) { + $this->admin_page = $admin_page; + $this->menu_slug = $menu_slug; + } + /** * Set configData to window.configData. * @@ -38,7 +64,7 @@ public function get_data() { $user = $this->get_connected_user_identity(); - return array( + $data = array( 'admin_page_base' => $this->get_admin_path(), 'api_root' => esc_url_raw( rest_url() ), 'blog_id' => $blog_id, @@ -87,6 +113,15 @@ public function get_data() { ), ), ); + + /** + * Filter to allow modification of the Blaze dashboard config data. + * + * @param bool $data Blaze dashboard config data. + * + * @since $$next-version$$ + */ + return apply_filters( 'jetpack_blaze_dashboard_config_data', $data ); } /** @@ -129,7 +164,9 @@ protected function get_gmt_offset() { protected function get_admin_path() { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized if ( ! isset( $_SERVER['PHP_SELF'] ) || ! isset( $_SERVER['QUERY_STRING'] ) ) { - $parsed = wp_parse_url( admin_url( 'tools.php?page=advertising' ) ); + $admin_path = $this->admin_page . '?page=' . $this->menu_slug; + $parsed = wp_parse_url( admin_url( $admin_path ) ); + return $parsed['path'] . '?' . $parsed['query']; } // We do this because page.js requires the exactly page base to be set otherwise it will not work properly. diff --git a/projects/packages/blaze/src/class-dashboard.php b/projects/packages/blaze/src/class-dashboard.php index 330fc45d2cac4..369b67387eabd 100644 --- a/projects/packages/blaze/src/class-dashboard.php +++ b/projects/packages/blaze/src/class-dashboard.php @@ -21,7 +21,7 @@ class Dashboard { * * @var string */ - const PACKAGE_VERSION = '0.20.3'; + const PACKAGE_VERSION = '0.21.0-alpha'; /** * List of dependencies needed to render the dashboard in wp-admin. @@ -58,6 +58,40 @@ class Dashboard { */ const BLAZEDASH_CACHE_BUSTER_CACHE_KEY = 'jetpack_blaze_admin_asset_cache_buster'; + /** + * Blaze dashboard admin page. Default is tools.php. + * + * @var string + */ + private $admin_page; + + /** + * Blaze dashboard menu slug. Default is 'advertising'. + * + * @var string + */ + private $menu_slug; + + /** + * Blaze dashboard css prefix. Default is 'jp-blaze'. + * + * @var string + */ + private $css_prefix; + + /** + * Dashboard constructor. + * + * @param string $admin_page Dashboard admin page. Default is tools.php. + * @param string $menu_slug Dashboard menu slug. Default is 'advertising'. + * @param string $css_prefix Dashboard css prefix. Default is 'jp-blaze'. + */ + public function __construct( $admin_page = 'tools.php', $menu_slug = 'advertising', $css_prefix = 'jp-blaze' ) { + $this->admin_page = $admin_page; + $this->menu_slug = $menu_slug; + $this->css_prefix = $css_prefix; + } + /** * Override render funtion * @@ -65,11 +99,11 @@ class Dashboard { */ public function render() { ?> -