Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: only remove non-faust Nav Menu locations if the user opts-in to it #1926

Merged
merged 7 commits into from
Aug 8, 2024
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
5 changes: 5 additions & 0 deletions .changeset/fast-queens-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@faustwp/wordpress-plugin': minor
---

Introduces a new setting on the Faust settings page that allows users to opt-in or out of Faust removing Nav Menu Locations that are not registered on the Faust Settings page.
12 changes: 6 additions & 6 deletions .github/workflows/e2e-test-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ jobs:
- name: Setup Containers
working-directory: plugins/faustwp
run: |
docker-compose build \
docker compose build \
--build-arg WP_VERSION=6.4
docker-compose up -d
docker compose up -d
- name: Sleep 15 seconds
run: sleep 15
- name: Maybe upgrade WP DB
working-directory: plugins/faustwp
run: docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp core update-db --allow-root
run: docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) wp core update-db --allow-root
- name: Init Testing Environment
working-directory: plugins/faustwp
run: docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) init-testing-environment.sh
run: docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) init-testing-environment.sh
- name: Install WP GraphQL
working-directory: plugins/faustwp
run: |
docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp plugin install wp-graphql --activate --allow-root
docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) wp plugin install wp-graphql --activate --allow-root
- name: Setup testing data
working-directory: plugins/faustwp
run: |
docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp db export tests/_data/dump.sql --allow-root
docker exec --workdir=/var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) wp db export tests/_data/dump.sql --allow-root
- name: Copy env file
working-directory: plugins/faustwp
run: cp .env.testing.example .env.testing
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/unit-test-plugin-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
- name: Create Docker Containers
working-directory: ./plugins/faustwp
run: |
docker-compose build \
docker compose build \
--build-arg WP_VERSION=6.5
docker-compose up -d
docker compose up -d

- name: Wait for db
run: |
Expand All @@ -28,23 +28,23 @@ jobs:

- name: Setup testing framework
working-directory: ./plugins/faustwp
run: docker exec -e COVERAGE=1 $(docker-compose ps -q wordpress) init-testing-environment.sh
run: docker exec -e COVERAGE=1 $(docker compose ps -q wordpress) init-testing-environment.sh

- name: Ensure Correct WordPress version
working-directory: ./plugins/faustwp
run: |
docker exec -w /var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp core version --allow-root
docker exec -w /var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp core upgrade --version=nightly --force --allow-root
docker exec -w /var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp core version --allow-root
docker exec -w /var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) wp core version --allow-root
docker exec -w /var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) wp core upgrade --version=nightly --force --allow-root
docker exec -w /var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) wp core version --allow-root

- name: Install and activate WP GraphQL
working-directory: ./plugins/faustwp
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp plugin install wp-graphql --activate --allow-root
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) wp plugin install wp-graphql --activate --allow-root

- name: Install Dependencies
working-directory: ./plugins/faustwp
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) composer install
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) composer install

- name: Run unit tests
working-directory: ./plugins/faustwp
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) composer test
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) composer test
12 changes: 6 additions & 6 deletions .github/workflows/unit-test-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
WP_VERSION: ${{ matrix.wordpress }}
working-directory: ./plugins/faustwp
run: |
docker-compose build \
docker compose build \
--build-arg WP_VERSION=${{ matrix.wordpress }}
docker-compose up -d
docker compose up -d

- name: Wait for db
run: |
Expand All @@ -33,16 +33,16 @@ jobs:

- name: Setup testing framework
working-directory: ./plugins/faustwp
run: docker exec -e COVERAGE=1 $(docker-compose ps -q wordpress) init-testing-environment.sh
run: docker exec -e COVERAGE=1 $(docker compose ps -q wordpress) init-testing-environment.sh

- name: Install and activate WP GraphQL
working-directory: ./plugins/faustwp
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) wp plugin install wp-graphql --activate --allow-root
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) wp plugin install wp-graphql --activate --allow-root

- name: Install Dependencies
working-directory: ./plugins/faustwp
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) composer install
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) composer install

- name: Run unit tests
working-directory: ./plugins/faustwp
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker-compose ps -q wordpress) composer test
run: docker exec -e COVERAGE=1 -w /var/www/html/wp-content/plugins/faustwp $(docker compose ps -q wordpress) composer test
8 changes: 8 additions & 0 deletions plugins/faustwp/includes/menus/callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
* Unregisters menu locations such as those provided by the active PHP theme.
*/
function remove_menu_locations() {

$remove_menus = faustwp_get_setting( 'remove_additional_menu_locations', false );

// If additional menus are not set to be removed, do nothing.
if ( false === $remove_menus ) {
return;
}

$menus = array_keys( get_registered_nav_menus() );

array_walk( $menus, 'unregister_nav_menu' );
Expand Down
26 changes: 26 additions & 0 deletions plugins/faustwp/includes/settings/callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ function register_settings_fields() {
)
);

add_settings_field(
'remove_additional_menu_locations',
__( 'Remove Additional Nav Menu Locations', 'faustwp' ),
__NAMESPACE__ . '\\display_remove_additional_menu_locations_field',
'faustwp-settings',
'settings_section'
);

add_settings_field(
'enable_disable',
__( 'Features', 'faustwp' ),
Expand Down Expand Up @@ -214,6 +222,7 @@ function sanitize_faustwp_settings( $settings, $option ) {
$settings[ $name ] = sanitize_text_field( $value );
break;

case 'remove_additional_menu_locations':
case 'enable_redirects':
case 'enable_rewrites':
case 'disable_theme':
Expand Down Expand Up @@ -327,6 +336,23 @@ function display_menu_locations_field() {
<?php
}

/**
* Callback for WordPress add_settings_field() method parameter.
*
* Display the "Remove Additional Menu Locations" checkbox field.
*
* @return void
*/
function display_remove_additional_menu_locations_field() {
$removed = faustwp_get_setting( 'remove_additional_menu_locations', false );
?>
<label for="remove_additional_menu_locations">
<input type="checkbox" id="remove_additional_menu_locations" name="faustwp_settings[remove_additional_menu_locations]" value="1" <?php checked( $removed ); ?> /><?php esc_html_e( 'Remove all Nav Menu locations that are not registered on this screen.', 'faustwp' ); ?>
<p class="description"><?php esc_html_e( 'By checking this, the only Nav Menu locations will be the ones registered on this page. Leaving this un-checked will combine the menu locations on this page with menu locations registered by other plugins or themes. This has an impact on the nav menu manager in the WordPress admin and API access to menus.', 'faustwp' ); ?></p>
</label>
<?php
}

/**
* Callback for WordPress add_settings_field() method parameter.
*
Expand Down
13 changes: 13 additions & 0 deletions plugins/faustwp/tests/acceptance/SettingsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,17 @@ public function i_can_cancel_my_secret_key_from_being_regenerated(AcceptanceTest
$I->cancelPopup();
$I->seeInField('faustwp_settings[secret_key]', $secret_key);
}

public function i_can_check_remove_all_nav_menus_not_registered_by_faust(AcceptanceTester $I)
{
$I->loginAsAdmin();
$I->amOnFaustWPSettingsPage();

$I->dontSeeCheckboxIsChecked('#remove_additional_menu_locations');
$I->checkOption('#remove_additional_menu_locations');
$I->click("Save Changes");

$I->see("Settings saved.");
$I->seeCheckboxIsChecked('#remove_additional_menu_locations');
}
}
Loading