Skip to content

Instantly share code, notes, and snippets.

@mustafauysal
Created November 20, 2025 20:20
Show Gist options
  • Select an option

  • Save mustafauysal/75df37be5b95b193515a602707e745e7 to your computer and use it in GitHub Desktop.

Select an option

Save mustafauysal/75df37be5b95b193515a602707e745e7 to your computer and use it in GitHub Desktop.
Moves "Powered Cache" menu under general settings
<?php
add_action( 'admin_menu', 'move_powered_cache_under_settings', 999 );
function move_powered_cache_under_settings() {
if ( ! is_admin() ) {
return;
}
global $menu, $submenu;
$parent_target = 'options-general.php';
if ( ! isset( $menu ) || ! is_array( $menu ) ) {
return;
}
if ( ! isset( $submenu[ $parent_target ] ) || ! is_array( $submenu[ $parent_target ] ) ) {
$submenu[ $parent_target ] = array();
}
// Collect all top-level menu keys that look like Powered Cache
$keys_to_move = array();
foreach ( $menu as $key => $item ) {
if ( empty( $item[2] ) ) {
continue;
}
$slug = $item[2];
$title = strip_tags( $item[0] );
if ( false !== stripos( $slug, 'powered-cache' ) || false !== stripos( $title, 'powered cache' ) ) {
$keys_to_move[] = $key;
}
}
if ( empty( $keys_to_move ) ) {
return;
}
// Helper: check duplicate under Settings by slug or title
$is_duplicate = function ( $check_slug, $check_title ) use ( &$submenu, $parent_target ) {
if ( empty( $submenu[ $parent_target ] ) || ! is_array( $submenu[ $parent_target ] ) ) {
return false;
}
foreach ( $submenu[ $parent_target ] as $existing ) {
$existing_slug = isset( $existing[2] ) ? $existing[2] : '';
$existing_title = isset( $existing[0] ) ? strip_tags( $existing[0] ) : '';
if ( $existing_slug === $check_slug ) {
return true;
}
if ( $existing_title && $check_title && ( stripos( $existing_title, $check_title ) !== false || stripos( $check_title, $existing_title ) !== false ) ) {
return true;
}
}
return false;
};
// Move each found top-level menu and its submenus, avoid duplicates, remove originals
foreach ( $keys_to_move as $key ) {
if ( ! isset( $menu[ $key ] ) ) {
continue;
}
$item = $menu[ $key ];
$slug = $item[2];
$title = strip_tags( $item[0] );
// Add main entry if not duplicate
if ( ! $is_duplicate( $slug, $title ) ) {
$submenu[ $parent_target ][] = array( $item[0], $item[1], $slug );
}
// Move plugin submenus if present
if ( isset( $submenu[ $slug ] ) && is_array( $submenu[ $slug ] ) ) {
foreach ( $submenu[ $slug ] as $sub ) {
$sub_slug = isset( $sub[2] ) ? $sub[2] : '';
$sub_title = isset( $sub[0] ) ? strip_tags( $sub[0] ) : '';
if ( ! $is_duplicate( $sub_slug, $sub_title ) ) {
$submenu[ $parent_target ][] = $sub;
}
}
unset( $submenu[ $slug ] );
}
// Remove original top-level entry
unset( $menu[ $key ] );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment