Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 156
0.00% covered (danger)
0.00%
0 / 4
CRAP
n/a
0 / 0
wpcom_add_marketing_submenu
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
load_marketing_tools_page
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
enqueue_marketing_tools_assets
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
wpcom_display_marketing_tools_page
0.00% covered (danger)
0.00%
0 / 138
0.00% covered (danger)
0.00%
0 / 1
110
1<?php
2/**
3 * WordPress.com Marketing Tools
4 *
5 * @package automattic/jetpack-mu-wpcom
6 */
7
8use Automattic\Jetpack\Jetpack_Mu_Wpcom\Common;
9use Automattic\Jetpack\Plans;
10use Automattic\Jetpack\Status;
11use Automattic\Jetpack\Status\Host;
12
13/**
14 * Registers the Tools > Marketing menu.
15 */
16function wpcom_add_marketing_submenu() {
17    $hook_suffix = add_submenu_page(
18        'tools.php',
19        __( 'Marketing', 'jetpack-mu-wpcom' ),
20        __( 'Marketing', 'jetpack-mu-wpcom' ),
21        'manage_options',
22        'wpcom-marketing-tools',
23        'wpcom_display_marketing_tools_page',
24        1
25    );
26    add_action( 'load-' . $hook_suffix, 'load_marketing_tools_page' );
27}
28add_action( 'admin_menu', 'wpcom_add_marketing_submenu', 999999 );
29
30/**
31 * Initializes the Marketing Tools page.
32 */
33function load_marketing_tools_page() {
34    add_action( 'admin_enqueue_scripts', 'enqueue_marketing_tools_assets' );
35}
36
37/**
38 * Enqueues the Marketing Tools assets.
39 */
40function enqueue_marketing_tools_assets() {
41    jetpack_mu_wpcom_enqueue_assets( 'marketing', array( 'js', 'css' ) );
42    wp_add_inline_script(
43        'jetpack-mu-wpcom-marketing',
44        'const wpcomMarketing = ' . wp_json_encode( array( 'siteId' => get_wpcom_blog_id() ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';',
45        'before'
46    );
47}
48
49/**
50 * Displays the WordPress Marketing Tools page.
51 */
52function wpcom_display_marketing_tools_page() {
53    $domain     = wp_parse_url( home_url(), PHP_URL_HOST );
54    $is_private = ( new Status() )->is_private_site();
55
56    $features = array(
57        array(
58            'title'       => __( 'Let our WordPress.com experts build your site!', 'jetpack-mu-wpcom' ),
59            'description' => __(
60                "Hire our dedicated experts to build a handcrafted, personalized website. Share some details about what you're looking for, and we'll make it happen.",
61                'jetpack-mu-wpcom'
62            ),
63            'action'      => __( 'Get started', 'jetpack-mu-wpcom' ),
64            'icon'        => plugins_url( 'images/wordpress-logo.svg', __FILE__ ),
65            'url'         => 'https://wordpress.com/start/do-it-for-me/new-or-existing-site',
66            'event'       => 'calypso_marketing_tools_built_by_wp_button_click',
67        ),
68        array(
69            'title'       => __( 'Monetize your site', 'jetpack-mu-wpcom' ),
70            'description' => __(
71                'Accept payments or donations with our native payment blocks, limit content to paid subscribers only, opt into our ad network to earn revenue, and refer friends to WordPress.com for credits.',
72                'jetpack-mu-wpcom'
73            ),
74            'action'      => __( 'Start earning', 'jetpack-mu-wpcom' ),
75            'icon'        => plugins_url( 'images/earn.svg', __FILE__ ),
76            'url'         => 'https://wordpress.com/earn/' . $domain,
77            'event'       => 'calypso_marketing_tools_earn_button_click',
78        ),
79        array(
80            'title'       => __( 'Fiverr logo maker', 'jetpack-mu-wpcom' ),
81            'description' => __(
82                'Create a standout brand with a custom logo. Our partner makes it easy and quick to design a professional logo that leaves a lasting impression.',
83                'jetpack-mu-wpcom'
84            ),
85            'action'      => __( 'Make your brand', 'jetpack-mu-wpcom' ),
86            'icon'        => plugins_url( 'images/fiverr-logo.svg', __FILE__ ),
87            'url'         => 'https://wp.me/logo-maker/?utm_campaign=marketing_tab',
88            'event'       => 'calypso_marketing_tools_create_a_logo_button_click',
89            'target'      => '_blank',
90        ),
91    );
92
93    // Show the Facebook feature only between July-October 2025 (see pfUMqg-5a-p2).
94    $current_date  = new DateTime();
95    $current_year  = (int) $current_date->format( 'Y' );
96    $current_month = (int) $current_date->format( 'n' );
97    if ( $current_year === 2025 && $current_month >= 7 && $current_month <= 10 ) {
98        $features[] = array(
99            'title'       => __( 'Want to connect with your audience on Facebook and Instagram?', 'jetpack-mu-wpcom' ),
100            'description' => sprintf(
101            /* translators: %1$s - Name of the Business plan, %2$s - Name of Commerce plan. */
102                __(
103                    'Discover an easy way to advertise your brand across Facebook and Instagram. Capture website actions to help you target audiences and measure results. Available on %1$s and %2$s plans.',
104                    'jetpack-mu-wpcom'
105                ),
106                Plans::get_plan_short_name( 'business-bundle' ),
107                Plans::get_plan_short_name( 'ecommerce-bundle' )
108            ),
109            'action'      => __( 'Add Facebook for WordPress.com', 'jetpack-mu-wpcom' ),
110            'icon'        => plugins_url( 'images/facebook-logo.png', __FILE__ ),
111            'url'         => 'https://wordpress.com/plugins/official-facebook-pixel/' . $domain,
112            'event'       => 'calypso_marketing_tools_facebook_button_click',
113        );
114    }
115
116    if ( ( new Host() )->is_wpcom_simple() && ! $is_private && ! wpcom_activitypub_is_active() ) {
117        $features[] = array(
118            'title'       => __( 'Share your blog with a new audience', 'jetpack-mu-wpcom' ),
119            'description' => __(
120                'Connect your WordPress.com site to the social web. Let people follow your posts from platforms like Mastodon, Threads, and more—no extra work needed.',
121                'jetpack-mu-wpcom'
122            ),
123            'action'      => __( 'Join the open social web', 'jetpack-mu-wpcom' ),
124            'icon'        => plugins_url( 'images/activitypub-logo.svg', __FILE__ ),
125            'url'         => admin_url( 'options-general.php?page=activitypub' ),
126            'event'       => 'calypso_marketing_tools_activitypub_button_click',
127            'callback'    => 'enableActivityPub',
128        );
129    }
130
131    $features[] = array(
132        'title'       => __( 'Hire an SEO expert', 'jetpack-mu-wpcom' ),
133        'description' => __(
134            'In today‘s digital age, visibility is key. Hire an SEO expert to boost your online presence and capture valuable opportunities.',
135            'jetpack-mu-wpcom'
136        ),
137        'action'      => __( 'Talk to an SEO expert today', 'jetpack-mu-wpcom' ),
138        'icon'        => plugins_url( 'images/fiverr-logo.svg', __FILE__ ),
139        'url'         => 'https://wp.me/hire-seo-expert/?utm_source=marketing_tab',
140        'event'       => 'calypso_marketing_tools_hire_an_seo_expert_button_click',
141        'target'      => '_blank',
142    );
143
144    if ( ! $is_private ) {
145        $features[] = array(
146            'title'       => __( 'Share your blog posts with everyone', 'jetpack-mu-wpcom' ),
147            'description' => __(
148                "Use your site's Jetpack Social tools to connect your site and your social media accounts, and share your new posts automatically. Connect to Facebook, LinkedIn, and more.",
149                'jetpack-mu-wpcom'
150            ),
151            'action'      => __( 'Start sharing', 'jetpack-mu-wpcom' ),
152            'icon'        => plugins_url( 'images/social-media-logos.svg', __FILE__ ),
153            'url'         => admin_url( 'admin.php?page=jetpack-social' ),
154            'event'       => 'calypso_marketing_tools_start_sharing_button_click',
155        );
156    }
157
158    $locale = Common\determine_iso_639_locale();
159    if ( $locale === 'en' ) {
160        $features[] = array(
161            'title'       => __( 'Increase traffic to your WordPress.com site', 'jetpack-mu-wpcom' ),
162            'description' => __(
163                'Take our free introductory course about search engine optimization (SEO) and learn how to improve your site or blog for both search engines and humans.',
164                'jetpack-mu-wpcom'
165            ),
166            'action'      => __( 'Watch the course', 'jetpack-mu-wpcom' ),
167            'icon'        => plugins_url( 'images/rocket.svg', __FILE__ ),
168            'url'         => 'https://wordpress.com/support/courses/seo/',
169            'event'       => 'calypso_marketing_tools_seo_course_button_click',
170            'target'      => '_blank',
171        );
172    }
173
174    ?>
175    <style>
176        :root {
177            --premium-plugins-bg: url( <?php echo esc_url( plugins_url( 'images/dot-grid.png', __FILE__ ) ); ?> );
178        }
179    </style>
180    <div class="wrap">
181        <h1><?php esc_html_e( 'Marketing Tools', 'jetpack-mu-wpcom' ); ?></h1>
182        <p class="wpcom-marketing-tools-description"><?php esc_html_e( 'Explore tools to build your audience, market your site, and engage your visitors.', 'jetpack-mu-wpcom' ); ?></p>
183
184        <div class="wpcom-marketing-tools-premium-plugins">
185            <div class="wpcom-marketing-tools-premium-plugins__info">
186                <h2><?php esc_html_e( 'Explore our premium plugins', 'jetpack-mu-wpcom' ); ?></h2>
187                <p><?php esc_html_e( "We've added premium plugins to boost your site's capabilities. From bookings and subscriptions to email marketing and SEO tools, we have you covered.", 'jetpack-mu-wpcom' ); ?></p>
188                <a href="<?php echo esc_url( 'https://wordpress.com/plugins/' . $domain . '?ref=wpcom-marketing-tools' ); ?>" class="button button-primary">
189                    <?php esc_html_e( 'Get started', 'jetpack-mu-wpcom' ); ?>
190                </a>
191            </div>
192            <div class="wpcom-marketing-tools-premium-plugins__image">
193                <img src="<?php echo esc_url( plugins_url( 'images/premium-plugins.png', __FILE__ ) ); ?>" alt="">
194            </div>
195        </div>
196
197        <div class="wpcom-marketing-tools-features">
198            <?php foreach ( $features as $feature ) { ?>
199                <div class="wpcom-marketing-tools-feature">
200                    <img src="<?php echo esc_url( $feature['icon'] ); ?>" alt="">
201                    <h3><?php echo esc_html( $feature['title'] ); ?></h3>
202                    <p><?php echo esc_html( $feature['description'] ); ?></p>
203                    <a
204                        href="<?php echo esc_url( $feature['url'] ); ?>"
205                        target="<?php echo esc_attr( $feature['target'] ?? '_self' ); // @phan-suppress-current-line PhanCoalescingNeverNullInLoop ?>"
206                        data-event="<?php echo esc_attr( $feature['event'] ); ?>"
207                        data-callback="<?php echo esc_attr( $feature['callback'] ?? '' ); // @phan-suppress-current-line PhanCoalescingNeverNullInLoop ?>"
208                    >
209                        <?php echo esc_html( $feature['action'] ); ?>
210                        <span class="dashicons dashicons-arrow-right-alt"></span>
211                    </a>
212                </div>
213            <?php } ?>
214        </div>
215    </div>
216    <?php
217}