-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MU WPCOM: Port tags-education feature from ETK (#38210)
- Loading branch information
1 parent
2024b54
commit e4b409b
Showing
8 changed files
with
119 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
module.exports = { | ||
presets: [ [ '@automattic/jetpack-webpack-config/babel/preset' ] ], | ||
const config = { | ||
presets: [ | ||
[ | ||
'@automattic/jetpack-webpack-config/babel/preset', | ||
{ pluginReplaceTextdomain: { textdomain: 'jetpack-mu-wpcom' } }, | ||
], | ||
], | ||
}; | ||
|
||
module.exports = config; |
4 changes: 4 additions & 0 deletions
4
projects/packages/jetpack-mu-wpcom/changelog/mu-wpcom-tags-education
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,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
MU WPCOM: Port tags-education feature from ETK. |
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
34 changes: 34 additions & 0 deletions
34
projects/packages/jetpack-mu-wpcom/src/features/tags-education/tags-education.js
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,34 @@ | ||
import { useAnalytics } from '@automattic/jetpack-shared-extension-utils'; | ||
import { ExternalLink } from '@wordpress/components'; | ||
import { createHigherOrderComponent } from '@wordpress/compose'; | ||
import { addFilter } from '@wordpress/hooks'; | ||
|
||
const addTagsEducationLink = createHigherOrderComponent( PostTaxonomyType => { | ||
return props => { | ||
const { tracks } = useAnalytics(); | ||
|
||
if ( props.slug !== 'post_tag' || ! window.wpcomTagsEducation ) { | ||
return <PostTaxonomyType { ...props } />; | ||
} | ||
|
||
return ( | ||
<> | ||
<PostTaxonomyType { ...props } /> | ||
<ExternalLink | ||
href="https://wordpress.com/support/posts/tags/" | ||
onClick={ () => { | ||
tracks.recordEvent( 'jetpack_mu_wpcom_tags_education_link_click' ); | ||
} } | ||
> | ||
{ window.wpcomTagsEducation.actionText } | ||
</ExternalLink> | ||
</> | ||
); | ||
}; | ||
}, 'addTagsEducationLink' ); | ||
|
||
addFilter( | ||
'editor.PostTaxonomyType', | ||
'jetpack-mu-wpcom/add-tags-education-link', | ||
addTagsEducationLink | ||
); |
49 changes: 49 additions & 0 deletions
49
projects/packages/jetpack-mu-wpcom/src/features/tags-education/tags-education.php
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,49 @@ | ||
<?php | ||
/** | ||
* WPCOM addition to Gutenberg post tags section. | ||
* | ||
* @package automattic/jetpack-mu-wpcom | ||
*/ | ||
|
||
use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State; | ||
use Automattic\Jetpack\Connection\Manager as Connection_Manager; | ||
use Automattic\Jetpack\Jetpack_Mu_Wpcom; | ||
use Automattic\Jetpack\Status; | ||
use Automattic\Jetpack\Terms_Of_Service; | ||
use Automattic\Jetpack\Tracking; | ||
|
||
define( 'MU_WPCOM_TAGS_EDUCATION', true ); | ||
|
||
/** | ||
* Enqueue assets | ||
*/ | ||
function wpcom_enqueue_tags_education_assets() { | ||
$asset_file = include Jetpack_Mu_Wpcom::BASE_DIR . 'build/tags-education/tags-education.asset.php'; | ||
|
||
wp_enqueue_script( | ||
'wpcom-tags-education-script', | ||
plugins_url( 'build/tags-education/tags-education.js', Jetpack_Mu_Wpcom::BASE_FILE ), | ||
$asset_file['dependencies'] ?? array(), | ||
$asset_file['version'] ?? filemtime( Jetpack_Mu_Wpcom::BASE_DIR . 'build/tags-education/tags-education.js' ), | ||
true | ||
); | ||
|
||
wp_localize_script( | ||
'wpcom-tags-education-script', | ||
'wpcomTagsEducation', | ||
array( 'actionText' => __( 'Build your audience with tags', 'jetpack-mu-wpcom' ) ) | ||
); | ||
|
||
Connection_Initial_State::render_script( 'wpcom-tags-education-script' ); | ||
|
||
$status = new Status(); | ||
$connection = new Connection_Manager(); | ||
$tracking = new Tracking( 'jetpack-mu-wpcom', $connection ); | ||
$can_use_analytics = $tracking->should_enable_tracking( new Terms_Of_Service(), $status ); | ||
|
||
if ( $can_use_analytics ) { | ||
Tracking::register_tracks_functions_scripts( true ); | ||
} | ||
} | ||
|
||
add_action( 'enqueue_block_editor_assets', 'wpcom_enqueue_tags_education_assets', 100 ); |
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