Repository navigation
Premium Analytics: gate the video surfaces on VideoPress availability #51243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
32fe883
Premium Analytics: gate the video surfaces on VideoPress availability
chihsuan 2e47883
fix: read the VideoPress plan feature on Atomic too, and close the te…
chihsuan cc39f2b
test: drive the WPCOM VideoPress plan feature, and correct the gate's…
chihsuan 8a2ee4a
Merge remote-tracking branch 'origin/trunk' into change/gate-videos-o…
chihsuan 79f290f
docs: clarify VideoPress availability behavior
chihsuan f36abdd
docs: name the canonical VideoPress gates and fix two stale pointers
chihsuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
4 changes: 4 additions & 0 deletions
4
projects/packages/premium-analytics/changelog/wooa7s-1718-gate-videos-on-videopress
This file contains hidden or 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: patch | ||
| Type: changed | ||
|
|
||
| Make the Top videos widget, the Videos report, and the video detail page unavailable on sites without VideoPress, matching the Calypso Stats gating. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
105 changes: 105 additions & 0 deletions
105
projects/packages/premium-analytics/src/videopress-availability.php
This file contains hidden or 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,105 @@ | ||
| <?php | ||
| /** | ||
| * VideoPress availability, shared by the widget layer and the client routes. | ||
| * | ||
| * Calypso gates its Videos module on the `videopress` plan feature, which | ||
| * `wpcom_site_has_feature()` answers on the WPCOM platform. That function does | ||
| * not exist off-platform. `Current_Plan::supports()` grants `videopress` to | ||
| * every plan because of the free tier, while | ||
| * `Product::get_site_features_from_wpcom()` can make a synchronous WPCOM | ||
| * request and answers entitlement rather than whether VideoPress is running. | ||
| * The off-platform question is therefore answered from the module or plugin. | ||
| * | ||
| * The canonical gates already exist: `VideoPress\Status::is_active()` for the | ||
| * off-platform branch, the WPCOM arm of `Current_Plan::supports()` for the | ||
| * platform one. Neither `jetpack-videopress` nor `jetpack-plans` is in this | ||
| * package's dependency graph, so the detection below is local by necessity. | ||
| * Widen the graph before writing another detector. | ||
| * | ||
| * @package automattic/jetpack-premium-analytics | ||
| */ | ||
|
|
||
| namespace Automattic\Jetpack\PremiumAnalytics; | ||
|
|
||
| use Automattic\Jetpack\Constants; | ||
| use Automattic\Jetpack\Modules; | ||
| use Automattic\Jetpack\Status\Host; | ||
|
|
||
| /** | ||
| * Filter controlling whether the VideoPress-backed surfaces are available. | ||
| * | ||
| * @var string | ||
| */ | ||
| const VIDEOPRESS_AVAILABLE_FILTER = 'jetpack_premium_analytics_videopress_available'; | ||
|
|
||
| /** | ||
| * Whether the site can produce VideoPress play data. | ||
| * | ||
| * Atomic reads the plan feature alongside Simple, not the module: wpcomsh | ||
| * provides `wpcom_site_has_feature()` there, and the VideoPress module has no | ||
| * `Auto Activate` header, so a plan that includes VideoPress routinely comes | ||
| * with the module off. wpcomsh grants `videopress` to every business-and-higher | ||
| * plan and WoA only exists on those, so the platform branch effectively gates | ||
| * Simple alone: an Atomic site with the module off keeps the video surfaces. | ||
| * That is intended — hosting is service-level on WPCOM, so the module would be | ||
| * a false negative there. | ||
| * | ||
| * Off-platform the question becomes "is VideoPress running here", not "is it | ||
| * paid for" — without the module there is no new play data to report. That is | ||
| * deliberately narrower than `Initial_State::has_videopress_access()`, which | ||
| * never looks at the module and counts the paid storage tiers instead. | ||
| * | ||
| * `Current_Plan::supports( 'videopress' )` is avoided because off-platform it | ||
| * returns true for every plan, thanks to the VideoPress free tier. | ||
| * | ||
| * @return bool Whether Premium Analytics treats VideoPress as available. | ||
| */ | ||
| function is_videopress_available() { | ||
| if ( ( new Host() )->is_wpcom_platform() ) { | ||
| $is_available = function_exists( 'wpcom_site_has_feature' ) && \wpcom_site_has_feature( 'videopress' ); | ||
| } else { | ||
| // `false` skips the module registry the standalone Premium Analytics plugin | ||
| // does not ship, which would otherwise report every module inactive. | ||
| $is_available = ( new Modules() )->is_active( 'videopress', false ) | ||
| || Constants::is_defined( 'JETPACK_VIDEOPRESS_ROOT_FILE' ); | ||
| } | ||
|
|
||
| /** | ||
| * Filters whether Premium Analytics treats VideoPress as available. | ||
| * | ||
| * Hides the Top videos widget, the Videos report, and the video detail page | ||
| * when false. | ||
| * | ||
| * @param bool $is_available Whether VideoPress was detected in the current request. | ||
| */ | ||
| return (bool) apply_filters( VIDEOPRESS_AVAILABLE_FILTER, $is_available ); | ||
| } | ||
|
|
||
| /** | ||
| * Configures the VideoPress script data. | ||
| * | ||
| * @return void | ||
| */ | ||
| function configure_videopress_availability() { | ||
| add_filter( 'jetpack_admin_js_script_data', __NAMESPACE__ . '\\inject_videopress_script_data', 20 ); | ||
| } | ||
|
|
||
| /** | ||
| * Injects the VideoPress availability flag into JetpackScriptData. | ||
| * | ||
| * The client cannot read `site.plan.features` for this: that key is only | ||
| * populated when the Publicize package happens to be loaded, which the | ||
| * standalone Premium Analytics plugin never loads. | ||
| * | ||
| * @param array $data The script data passed by the assets package. | ||
| * @return array | ||
| */ | ||
| function inject_videopress_script_data( array $data ): array { | ||
| if ( ! isset( $data['premium_analytics'] ) || ! is_array( $data['premium_analytics'] ) ) { | ||
| $data['premium_analytics'] = array(); | ||
| } | ||
|
|
||
| $data['premium_analytics']['has_videopress'] = is_videopress_available(); | ||
|
|
||
| return $data; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking; nothing in the logic needs to change. One ask: on the
is_videopress_available()docblock.The off-platform branch is
VideoPress\Status::is_active(), the same two signals and the gate four places in the VideoPress package already use. The platform branch is the WPCOM hijack insideCurrent_Plan::supports(). Neither is reachable:jetpack-plansandjetpack-videopressaren't in this package's dependency graph, so local detection is the only option today.The docblock rules out
Current_Plan::supports()on semantic grounds, which is right, but doesn't mentionStatus::is_active(), which is semantically this branch and only out of reach. Worth naming it plus the boundary, so the next person finds the trail instead of writing a fifth detector.Also worth stating: the platform branch never fires on Atomic, since wpcomsh grants
videopresstoWPCOM_BUSINESS_AND_HIGHER_PLANSand WoA only exists there. I don't think that's wrong (hosting is service-level on WPCOM, so the module is a false negative), but the effective coverage is Simple plus self-hosted, and an Atomic site with the module off and no videos keeps both empty surfaces.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I've named it in the docblock along with why it's out of reach.