I'm using a plugin where I have manipulated a function within a class of the plugin. However I would like to put this function in my theme instead since if someone updates the plugin, my edits to the function will be replaced. But if I lift out my edited function and put in the theme I get the error that "Fatal error: Cannot declare class Groups_Post_Access, because the name is already in use in ..."
The function within class Groups_Post_Access originally looks like this:
public static function wp_get_nav_menu_items( $items = null, $menu = null, $args = null ) {
$result = array();
if ( apply_filters( 'groups_post_access_wp_get_nav_menu_items_apply', true, $items, $menu, $args ) ) {
$user_id = get_current_user_id();
foreach ( $items as $item ) {
// @todo might want to check $item->object and $item->type first,
// for example these are 'page' and 'post_type' for a page
if ( self::user_can_read_post( $item->object_id, $user_id ) ) {
$result[] = $item;
}
}
} else {
$result = $items;
}
return $result;
}
And my version is like this:
public static function wp_get_nav_menu_items( $items = null, $menu = null, $args = null ) {
$result = array();
if ( apply_filters( 'groups_post_access_wp_get_nav_menu_items_apply', true, $items, $menu, $args ) ) {
$user_id = get_current_user_id();
foreach ( $items as $item ) {
// @todo might want to check $item->object and $item->type first,
// for example these are 'page' and 'post_type' for a page
if ( self::user_can_read_post( $item->object_id, $user_id ) ) {
$group_ids = self::get_read_group_ids( $item->object_id );
if ( count( $group_ids ) > 0 ) {
$item->title .= '<i class="unlocked"></i>';
}
$result[] = $item;
} else {
$item->title .= '<i class="locked"></i>';
$result[] = $item;
}
}
} else {
$result = $items;
}
return $result;
}
So is there a way to override the function, or disable the class somehow from my theme? So it keeps separate from all the plugins file and then don't get replaced by an update for an example.