Skip to content

Commit d20b12a

Browse files
committed
Update to use new config endpoint
1 parent fe5c912 commit d20b12a

File tree

4 files changed

+5
-18
lines changed

4 files changed

+5
-18
lines changed

projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,6 @@ public static function load_editor_scripts() {
795795
'assetsUrl' => Jetpack_Forms::assets_url(),
796796
'preferredView' => $preferred_view,
797797
'isMailPoetEnabled' => Jetpack_Forms::is_mailpoet_enabled(),
798-
'canInstallPlugins' => current_user_can( 'install_plugins' ),
799-
'canActivatePlugins' => current_user_can( 'activate_plugins' ),
800798
),
801799
);
802800

projects/packages/forms/src/blocks/contact-form/components/jetpack-integrations-modal/integration-card/plugin-action-button.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { __ } from '@wordpress/i18n';
66
/**
77
* Internal dependencies
88
*/
9-
import { config as dashboardConfig } from '../../../../../dashboard';
9+
import useFormsConfig from '../../../../../hooks/use-forms-config';
1010
import { usePluginInstallation } from '../hooks/use-plugin-installation';
11-
import type { JPFormsBlocksDefaults } from '../../../../../types';
1211

1312
type PluginActionButtonProps = {
1413
slug: string;
@@ -32,14 +31,10 @@ const PluginActionButton = ( {
3231
trackEventName
3332
);
3433

35-
// Permissions checks. We need to check both the editor-provided jpFormsBlocks
36-
// and the dashboard config since this component loads in both places.
37-
// In a future PR, we should consolidate this to a single source of truth.
38-
const jpDefaults: JPFormsBlocksDefaults | undefined = window.jpFormsBlocks?.defaults;
39-
const canUserInstallPlugins =
40-
Boolean( jpDefaults?.canInstallPlugins ) || Boolean( dashboardConfig( 'canInstallPlugins' ) );
41-
const canUserActivatePlugins =
42-
Boolean( jpDefaults?.canActivatePlugins ) || Boolean( dashboardConfig( 'canActivatePlugins' ) );
34+
// Permissions from consolidated Forms config (shared across editor and dashboard)
35+
const config = useFormsConfig();
36+
const canUserInstallPlugins = Boolean( config?.canInstallPlugins );
37+
const canUserActivatePlugins = Boolean( config?.canActivatePlugins );
4338

4439
const canPerformAction = isInstalled ? canUserActivatePlugins : canUserInstallPlugins;
4540
const isDisabled = isInstalling || ! canPerformAction;

projects/packages/forms/src/dashboard/class-dashboard.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ public function render_dashboard( $extra_config = array() ) {
230230
'renderMigrationPage' => $this->switch->is_jetpack_forms_announcing_new_menu(),
231231
'dashboardURL' => add_query_arg( 'jetpack_forms_migration_announcement_seen', 'yes', $this->switch->get_forms_admin_url() ),
232232
'isMailpoetEnabled' => Jetpack_Forms::is_mailpoet_enabled(),
233-
'canInstallPlugins' => current_user_can( 'install_plugins' ),
234-
'canActivatePlugins' => current_user_can( 'activate_plugins' ),
235233
);
236234

237235
if ( ! empty( $extra_config ) ) {

projects/packages/forms/src/types/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ export interface JPFormsBlocksDefaults {
104104
formsResponsesSpamUrl?: string;
105105
/** Whether MailPoet integration is enabled. */
106106
isMailPoetEnabled?: boolean;
107-
/** Whether the current user can install plugins. */
108-
canInstallPlugins?: boolean;
109-
/** Whether the current user can activate plugins. */
110-
canActivatePlugins?: boolean;
111107
}
112108

113109
/**

0 commit comments

Comments
 (0)