Skip to content

Conversation

@subodhr258
Copy link
Collaborator

@subodhr258 subodhr258 commented Nov 11, 2025

Issue - https://github.com/rtCamp/godam.io/issues/383

This pull request introduces a change to improve the positioning of the rtgodam menu item in the WordPress admin dashboard. The main enhancement is ensuring that the rtgodam menu appears immediately after the upload.php (Media) menu item, providing a more intuitive and accessible menu structure.

Menu ordering improvements:

  • Added a new filter and function (custom_menu_order) to enable and customize the admin menu order, ensuring rtgodam appears right after upload.php in the menu. This includes enabling custom menu ordering and implementing logic to reposition rtgodam if both menu items are present.

Copy link
Contributor

@rtBot rtBot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code analysis identified issues

action-phpcs-code-review has identified potential problems in this pull request during automated scanning. We recommend reviewing the issues noted and that they are resolved.

phpcs scanning turned up:

⚠️ 2 warnings


Powered by rtCamp's GitHub Actions Library

*/
function custom_menu_order( $menu_order ) {
// Find the position of upload.php & rtgodam.
$media_position = array_search( 'upload.php', $menu_order );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Warning: Not using strict comparison for array_search; supply true for $strict argument (WordPress.PHP.StrictInArray.MissingTrueStrict).

// Find the position of upload.php & rtgodam.
$media_position = array_search( 'upload.php', $menu_order );

$rtgodam_position = array_search( 'rtgodam', $menu_order );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Warning: Not using strict comparison for array_search; supply true for $strict argument (WordPress.PHP.StrictInArray.MissingTrueStrict).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds custom menu ordering functionality to position the GoDAM plugin's menu item (rtgodam) immediately after the WordPress Media menu (upload.php) in the admin dashboard for improved accessibility and user experience.

Key changes:

  • Introduces a custom menu order filter to enable menu repositioning
  • Implements logic to dynamically reorder the admin menu by moving rtgodam after upload.php

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +137 to +140
// Reinsert rtgodam right after upload.php.
array_splice( $menu_order, $media_position + 1, 0, 'rtgodam' );
// Reindex the array to maintain proper order.
$menu_order = array_values( $menu_order );
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a potential bug in the menu reordering logic. After unset($menu_order[$rtgodam_position]) on line 136, the array keys are not reindexed, which means $media_position may no longer be a valid sequential index for array_splice() on line 138. This could cause array_splice() to insert the item at an incorrect position.

To fix this, you should call array_values() to reindex the array before calculating the insertion position:

// Remove rtgodam from its current position.
unset( $menu_order[ $rtgodam_position ] );
// Reindex the array before splicing.
$menu_order = array_values( $menu_order );
// Recalculate media position after reindexing.
$media_position = array_search( 'upload.php', $menu_order );
// Reinsert rtgodam right after upload.php.
array_splice( $menu_order, $media_position + 1, 0, 'rtgodam' );
Suggested change
// Reinsert rtgodam right after upload.php.
array_splice( $menu_order, $media_position + 1, 0, 'rtgodam' );
// Reindex the array to maintain proper order.
$menu_order = array_values( $menu_order );
// Reindex the array before splicing.
$menu_order = array_values( $menu_order );
// Recalculate media position after reindexing.
$media_position = array_search( 'upload.php', $menu_order );
// Reinsert rtgodam right after upload.php.
array_splice( $menu_order, $media_position + 1, 0, 'rtgodam' );

Copilot uses AI. Check for mistakes.
Comment on lines +137 to +140
// Reinsert rtgodam right after upload.php.
array_splice( $menu_order, $media_position + 1, 0, 'rtgodam' );
// Reindex the array to maintain proper order.
$menu_order = array_values( $menu_order );
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "Reindex the array to maintain proper order" is misleading at this location. The array should be reindexed immediately after the unset() operation on line 136 and before using array_splice() on line 138 to ensure correct positioning. Reindexing after array_splice() doesn't address the core issue with the insertion logic.

Suggested change
// Reinsert rtgodam right after upload.php.
array_splice( $menu_order, $media_position + 1, 0, 'rtgodam' );
// Reindex the array to maintain proper order.
$menu_order = array_values( $menu_order );
// Reindex the array to maintain proper order before reinserting.
$menu_order = array_values( $menu_order );
// Reinsert rtgodam right after upload.php.
array_splice( $menu_order, $media_position + 1, 0, 'rtgodam' );

Copilot uses AI. Check for mistakes.

// Enable custom menu order to make sure rtgodam appears right after upload.php.
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', 'custom_menu_order', PHP_INT_MAX );
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback reference 'custom_menu_order' should be updated if the function is renamed to follow the rtgodam_ prefix convention (as suggested in the naming comment). This ensures the filter correctly references the renamed function.

Copilot uses AI. Check for mistakes.

// Enable custom menu order to make sure rtgodam appears right after upload.php.
add_filter( 'custom_menu_order', '__return_true' );
add_filter( 'menu_order', 'custom_menu_order', PHP_INT_MAX );
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using PHP_INT_MAX as the priority for the menu_order filter is unnecessarily extreme and could indicate a code smell. This ensures the callback runs last, but it also makes it difficult for other plugins to run after this if needed, and could lead to conflicts. Consider using a more reasonable priority like 999 or 9999, which still ensures late execution but allows for some flexibility. WordPress core typically uses priorities in the range of 1-100, and well-behaved plugins use values like 10, 20, 100, or occasionally 999.

Suggested change
add_filter( 'menu_order', 'custom_menu_order', PHP_INT_MAX );
add_filter( 'menu_order', 'custom_menu_order', 999 );

Copilot uses AI. Check for mistakes.
* @param array $menu_order Array of menu order items.
* @return array Modified menu order array.
*/
function custom_menu_order( $menu_order ) {
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function should validate that $menu_order is an array before processing. While WordPress typically passes an array to the menu_order filter, defensive programming suggests adding a type check to prevent potential PHP errors if the input is unexpected:

function custom_menu_order( $menu_order ) {
	if ( ! is_array( $menu_order ) ) {
		return $menu_order;
	}
	// ... rest of the function
}
Suggested change
function custom_menu_order( $menu_order ) {
function custom_menu_order( $menu_order ) {
// Defensive: Ensure $menu_order is an array before processing.
if ( ! is_array( $menu_order ) ) {
return $menu_order;
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants