Skip to content
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

Add Traffic Boost permissions infrastructure #2939

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/admin-settings.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '3f06d1e94aa796c8627c');
<?php return array('dependencies' => array(), 'version' => '6f809310fd8f52110266');
2 changes: 1 addition & 1 deletion build/admin-settings.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/UI/class-dashboard-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Parsely\UI;

use Parsely\Parsely;
use Parsely\Permissions;
use Parsely\Utils\Utils;

use const Parsely\PARSELY_FILE;
Expand All @@ -21,6 +22,24 @@
* @since 3.18.0
*/
final class Dashboard_Page {
/**
* Instance of Parsely class.
*
* @var Parsely
*/
private $parsely;

/**
* Constructor.
*
* @since 3.18.0
*
* @param Parsely $parsely Instance of Parsely class.
*/
public function __construct( Parsely $parsely ) {
$this->parsely = $parsely;
}

/**
* Registers the dashboard page.
*
Expand Down Expand Up @@ -59,6 +78,19 @@ public function add_dashboard_page_to_menu(): void {
*/
public function add_dashboard_page_placeholder(): void {
echo '<div id="parsely-dashboard-page"></div>';

// TODO: The codeblock below is for demonstration purposes only and
// will be removed in the future.
if (
Permissions::current_user_can_use_pch_feature(
'traffic_boost',
$this->parsely->get_options()['content_helper']
)
) {
echo 'Traffic Boost is enabled.';
} else {
echo 'Traffic Boost is disabled.';
}
acicovic marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/UI/class-settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
* smart_linking?: Parsely_Settings_Options_Content_Helper_Feature,
* title_suggestions?: Parsely_Settings_Options_Content_Helper_Feature,
* excerpt_suggestions?: Parsely_Settings_Options_Content_Helper_Feature,
* traffic_boost?: Parsely_Settings_Options_Content_Helper_Feature,
* }
*
* @phpstan-type Parsely_Settings_Options_Content_Helper_Feature array{
Expand Down Expand Up @@ -118,6 +119,7 @@ final class Settings_Page {
'smart_linking',
'title_suggestions',
'excerpt_suggestions',
'traffic_boost',
);

/**
Expand Down Expand Up @@ -506,6 +508,22 @@ private function initialize_content_helper_section(): void {
$section_key,
$field_args
);

// Traffic Boost.
$field_id = 'content_helper[traffic_boost]';
$field_args = array(
'option_key' => $field_id,
'label_for' => $field_id,
'legend' => __( 'Traffic Boost', 'wp-parsely' ),
);
add_settings_field(
$field_id,
__( 'Traffic Boost', 'wp-parsely' ),
array( $this, 'print_content_helper_ai_feature_section' ),
Parsely::MENU_SLUG,
$section_key,
$field_args
);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/class-parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* smart_linking: Parsely_Options_Content_Helper_Feature,
* title_suggestions: Parsely_Options_Content_Helper_Feature,
* excerpt_suggestions: Parsely_Options_Content_Helper_Feature,
* traffic_boost: Parsely_Options_Content_Helper_Feature,
* }
*
* @phpstan-type Parsely_Options_Content_Helper_Feature array{
Expand Down Expand Up @@ -128,6 +129,10 @@ class Parsely {
'enabled' => true,
'allowed_user_roles' => array( 'administrator' ),
),
'traffic_boost' => array(
'enabled' => true,
'allowed_user_roles' => array( 'administrator' ),
),
),
'track_authenticated_users' => false,
'lowercase_tags' => true,
Expand Down
5 changes: 5 additions & 0 deletions src/class-permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public static function get_pch_permissions_json( $pch_options ): string {
'SmartLinking' => 'smart_linking',
'TitleSuggestions' => 'title_suggestions',
'ExcerptSuggestions' => 'excerpt_suggestions',
'TrafficBoost' => 'traffic_boost',
);

foreach ( $features as $key => $value ) {
Expand Down Expand Up @@ -205,6 +206,10 @@ public static function build_pch_permissions_settings_array(
'enabled' => $enabled,
'allowed_user_roles' => $allowed_user_roles,
),
'traffic_boost' => array(
'enabled' => $enabled,
'allowed_user_roles' => $allowed_user_roles,
),
);
}
}
3 changes: 2 additions & 1 deletion src/js/admin-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function addContentHelperTabEventHandlers(): void {
const featureCheckboxes = document.querySelectorAll<HTMLInputElement>(
'input#content_helper_smart_linking_enabled, ' +
'input#content_helper_title_suggestions_enabled, ' +
'input#content_helper_excerpt_suggestions_enabled'
'input#content_helper_excerpt_suggestions_enabled, ' +
'input#content_helper_traffic_boost_enabled'
);

// Selector for all fieldsets in the Content Helper section.
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/PermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ final class PermissionsTest extends TestCase {
'excerpt_suggestions',
'smart_linking',
'title_suggestions',
'traffic_boost',
);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/UI/SettingsPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ private function transform_pch_options_for_validation( $options ) {
$options['content_helper']['smart_linking']['allowed_user_roles'] = array( 'administrator' => true );
$options['content_helper']['title_suggestions']['allowed_user_roles'] = array( 'administrator' => true );
$options['content_helper']['excerpt_suggestions']['allowed_user_roles'] = array( 'administrator' => true );
$options['content_helper']['traffic_boost']['allowed_user_roles'] = array( 'administrator' => true );

return $options;
}
Expand Down
2 changes: 1 addition & 1 deletion wp-parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function parsely_wp_admin_early_register(): void {
$GLOBALS['parsely_settings_page']->run();

// Plugin dashboard page.
$GLOBALS['parsely_dashboard_page'] = new Dashboard_Page();
$GLOBALS['parsely_dashboard_page'] = new Dashboard_Page( $GLOBALS['parsely'] );
$GLOBALS['parsely_dashboard_page']->run();

$network_admin_sites_list = new Network_Admin_Sites_List( $GLOBALS['parsely'] );
Expand Down
Loading