Skip to content

Commit 7b8915d

Browse files
jeryjmatticbot
authored andcommitted
Move add-logo upsell code to jetpack-mu-wpcom (#42598)
The add-logo fiverr upsell is used on both wpcom and within wpcomsh as separate code. They have diverged when they were supposed to stay the same. This PR moves and fixes the code (linting errors) from WPcom into jetpack-mu-wpcom so it can be developed in one places. Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13997602917 Upstream-Ref: Automattic/jetpack@76e2028
1 parent 8d5099d commit 7b8915d

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This is an alpha version! The changes listed here are not final.
8888
- Launchpad: verify email task uses heuristic for visibility, regardless of experiment cohort
8989
- Launcpad: Include a hash to identifier for hosting tasks
9090
- Live Preview: Don't change the homepage when previewing a theme in the Site Editor
91+
- Move logo-tool to be within jetpack-mu-wpcom
9192
- MU WPCOM: Prevent site owner from editing user's account-level fields
9293
- Newspack Blocks: Updated from v4.5.2 → 4.7.0
9394
- Newspack Blocks Api: Check to avoid Warnings when accessing attachment image src

src/class-jetpack-mu-wpcom.php

+1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ public static function load_features() {
271271
require_once __DIR__ . '/features/holiday-snow/class-holiday-snow.php';
272272
require_once __DIR__ . '/features/import-customizations/import-customizations.php';
273273
require_once __DIR__ . '/features/launch-button/index.php';
274+
require_once __DIR__ . '/features/logo-tool/logo-tool.php';
274275
require_once __DIR__ . '/features/marketplace-products-updater/class-marketplace-products-updater.php';
275276
require_once __DIR__ . '/features/media/heif-support.php';
276277
require_once __DIR__ . '/features/post-categories/quick-actions.php';
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.customize-control .actions .create-logo-button {
2+
display: block !important;
3+
text-align: center;
4+
border-color: #6BA774;
5+
color: #6BA774;
6+
font-size: 14px;
7+
}
8+
9+
.customize-control .actions .create-logo-button:focus {
10+
box-shadow: 0 0 0 1px #6BA774;
11+
}
12+
13+
.create-logo-button .external-link-icon {
14+
vertical-align: text-bottom;
15+
margin-right: 4px;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* This file was automatically generated on Feb 08 2022 10:34:13 */
2+
3+
.customize-control .actions .create-logo-button {
4+
display: block !important;
5+
text-align: center;
6+
border-color: #6BA774;
7+
color: #6BA774;
8+
font-size: 14px;
9+
}
10+
11+
.customize-control .actions .create-logo-button:focus {
12+
box-shadow: 0 0 0 1px #6BA774;
13+
}
14+
15+
.create-logo-button .external-link-icon {
16+
vertical-align: text-bottom;
17+
margin-left: 4px;
18+
}
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* global wp, _LogoTool_ */
2+
( function ( $, wp, LogoTool ) {
3+
wp.customize.bind( 'ready', function () {
4+
let logoThumbnail;
5+
const logoControlId = '#customize-control-' + LogoTool.controlId;
6+
7+
// Could be a Core custom-logo, Jetpack site-logo, or a theme specific logo that uses the same image control.
8+
if ( wp.customize( LogoTool.settingId ) ) {
9+
logoThumbnail = $( logoControlId + ' .thumbnail' );
10+
wp.customize( LogoTool.settingId ).bind( 'change', function ( to ) {
11+
if ( ! to ) {
12+
insertLogoButton( logoControlId );
13+
showLogoDescription( logoControlId );
14+
} else {
15+
// Logo button is removed automatically.
16+
hideLogoDescription( logoControlId );
17+
}
18+
} );
19+
20+
if ( ! logoThumbnail.length ) {
21+
insertLogoButton( logoControlId );
22+
showLogoDescription( logoControlId );
23+
} else {
24+
// Logo button is removed automatically.
25+
hideLogoDescription( logoControlId );
26+
}
27+
}
28+
} );
29+
30+
/**
31+
* Insert the logo creation button.
32+
*
33+
* @param {string} id - The control ID.
34+
*/
35+
function insertLogoButton( id ) {
36+
const externalIcon =
37+
'<svg class="external-link-icon" width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5.97949 2.91699H4.91699C3.81242 2.91699 2.91699 3.81242 2.91699 4.91699V9.08366C2.91699 10.1882 3.81242 11.0837 4.91699 11.0837H9.08366C10.1882 11.0837 11.0837 10.1882 11.0837 9.08366V7.79431" stroke="#6BA774"/><path d="M8.68922 2.20873L11.9253 2.19411M11.9253 2.19411L11.8976 5.41706M11.9253 2.19411C10.5504 3.56904 8.76465 5.35476 7.44471 6.67469" stroke="#6BA774"/></svg>';
38+
const button = $(
39+
'<a class="button create-logo-button" target="_blank" href="' + LogoTool.referralLink + '" />'
40+
).text( LogoTool.l10n.create );
41+
button.prepend( externalIcon );
42+
// Timeout lets us render after the core control finishes.
43+
setTimeout( function () {
44+
$( id + ' .actions' ).prepend( button );
45+
}, 10 );
46+
}
47+
48+
/**
49+
* Show the logo description.
50+
*
51+
* @param {string} id - The control ID.
52+
*/
53+
function showLogoDescription( id ) {
54+
$( id + ' .description' ).show();
55+
}
56+
57+
/**
58+
* Hide the logo description.
59+
*
60+
* @param {string} id - The control ID.
61+
*/
62+
function hideLogoDescription( id ) {
63+
$( id + ' .description' ).hide();
64+
}
65+
} )( jQuery, wp, _LogoTool_ );

src/features/logo-tool/logo-tool.php

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Add a 'Create Logo' button to the Customizer when the theme supports a logo . The button directs customers to Fiverr .
4+
*
5+
* @package automattic/jetpack-mu-wpcom
6+
*/
7+
8+
if ( ! function_exists( 'add_logotool_button' ) ) {
9+
/**
10+
* Activate the Site Logo plugin.
11+
*
12+
* @uses current_theme_supports()
13+
*
14+
* @param WP_Customize_Manager $wp_customize Control manager for the Customizer.
15+
*/
16+
function add_logotool_button( $wp_customize ) {
17+
if ( ( function_exists( 'wpcom_is_vip' ) && wpcom_is_vip() ) || ! is_admin() ) {
18+
return;
19+
}
20+
21+
$logo_control = null;
22+
23+
if ( current_theme_supports( 'custom-logo' ) ) {
24+
// WP Core logo integration.
25+
$logo_control = $wp_customize->get_control( 'custom_logo' );
26+
} elseif ( current_theme_supports( 'site-logo' ) ) {
27+
// Jetpack logo integration.
28+
$logo_control = $wp_customize->get_control( 'site_logo' );
29+
} else {
30+
// Other custom logo integrations, for example in the dotorg versions of Lovecraft or Radcliffe themes.
31+
foreach ( $wp_customize->controls() as $control ) {
32+
if (
33+
// Control has the name logo in it.
34+
false !== strpos( $control->id, 'logo' ) &&
35+
// Control is not a `site_logo` or `custom_logo` (those are handled above).
36+
! in_array( $control->id, array( 'custom_logo', 'site_logo' ), true ) &&
37+
// Control is an instance of `WP_Customize_Image_Control` so we know how the UI is rendered to add the button.
38+
is_a( $control, 'WP_Customize_Image_Control' )
39+
) {
40+
$logo_control = $control;
41+
break;
42+
}
43+
}
44+
}
45+
46+
// Make sure we have a valid Customize Control.
47+
if ( $logo_control === null || ! is_a( $logo_control, 'WP_Customize_Control' ) ) {
48+
return;
49+
}
50+
51+
// And we have a valid setting attached to the control.
52+
if ( ! is_a( $logo_control->setting, 'WP_Customize_Setting' ) ) {
53+
return;
54+
}
55+
56+
$logo_control->description = __( 'Add a logo to display on your site. No logo? Buy a pro one today, powered by Fiverr — Click “Create logo” to start.', 'jetpack-mu-wpcom' );
57+
// Adding it back just overwrites the previous control instance.
58+
$wp_customize->add_control( $logo_control );
59+
60+
add_action(
61+
'customize_controls_enqueue_scripts',
62+
function () use ( $logo_control ) {
63+
wp_enqueue_script( 'jetpack-mu-wpcom-logo-tool', plugins_url( 'js/customizer.js', __FILE__ ), array( 'customize-controls' ), '20210706', true );
64+
wp_enqueue_style( 'jetpack-mu-wpcom-logo-tool', plugins_url( 'css/logo-tool.css', __FILE__ ), array(), '20220108' );
65+
wp_localize_script(
66+
'jetpack-mu-wpcom-logo-tool',
67+
'_LogoTool_',
68+
array(
69+
'l10n' => array( 'create' => __( 'Create logo in minutes', 'jetpack-mu-wpcom' ) ),
70+
'controlId' => $logo_control->id,
71+
'settingId' => $logo_control->setting->id,
72+
'referralLink' => 'https://wp.me/logo-maker/?utm_campaign=customizer' . ( defined( 'IS_ATOMIC' ) && IS_ATOMIC === true ? '-atomic' : '' ),
73+
)
74+
);
75+
}
76+
);
77+
}
78+
add_action( 'customize_register', 'add_logotool_button', 20 );
79+
}

0 commit comments

Comments
 (0)