Receiving error: invalid arguement….

4.39K viewsCore
0

I’m attempting to override the user menu order as requested here http://open-wp.com/questions/question/1548/how-can-i-reorder-the-output-of-the-user-profile-menu/

Taking from anspress-user.php I’m using the following function in my functions.php

function custom_ap_user_menu(){
		$userid = ap_get_user_page_user();
	$user_page = get_query_var('user_page');
	$user_page = $user_page ? $user_page : 'profile';
	
	$menus = array(
		'profile' => array( 'name' => __('Profile', 'ap'), 'link' => ap_user_link($userid), 'icon' => 'ap-icon-user'),
		'favorites' => array( 'name' => __('Favorites', 'ap'), 'link' => ap_user_link($userid, 'favorites'), 'icon' => 'ap-icon-star'),
		'questions' => array( 'name' => __('Questions', 'ap'), 'link' => ap_user_link($userid, 'questions'), 'icon' => 'ap-icon-question'),
		'answers' => array( 'name' => __('Answers', 'ap'), 'link' => ap_user_link($userid, 'answers'), 'icon' => 'ap-icon-answer'),		
		'badges' => array( 'name' => __('Badges', 'ap'), 'link' => ap_user_link($userid, 'badges'), 'icon' => 'ap-icon-badge'),		
		'followers' => array( 'name' => __('Followers', 'ap'), 'link' => ap_user_link($userid, 'followers'), 'icon' => 'ap-icon-users'),
		'following' => array( 'name' => __('Following', 'ap'), 'link' => ap_user_link($userid, 'following'), 'icon' => 'ap-icon-users'),
		'edit_profile' => array( 'name' => __('Edit Profile', 'ap'), 'link' => ap_user_link($userid, 'edit_profile'), 'icon' => 'ap-icon-pencil', 'own' => true),
		//'settings' => array( 'name' => __('Settings', 'ap'), 'link' => ap_user_link($userid, 'settings'), 'icon' => 'ap-icon-cog'),		
	);
	
		/* filter for overriding menu */
	$menus = apply_filters('custom_ap_user_menu', $menus);
	
	$o ='';
	foreach($menus as $k => $m){
		if(!((isset($m['own']) && $m['own']) && $userid != get_current_user_id()))
			$o .= '<a href="'. $m['link'] .'">'.$m['name'].'</a>';
	}
	$o .= '';
	
	echo $o;

}
add_filter ( 'ap_user_menu' , 'custom_ap_user_menu' , 10, 2 );

My custom menu order displays correctly, but it is now throwing an error from within the plugin:

Warning: Invalid argument supplied for foreach() in /home/teatrade/public_html/dev.prometheusfire.me/interview-hacks/wp-content/plugins/anspress-question-answer/includes/anspress-user.php on line 509

Can you help me please sort this out. Everything looks right in the code as far as I can tell so I can’t see why I’m getting the error. Ultimately, I don’t care how its done, what I really want is to move the Favorites link next to the Profile link.

0

And also make sure to undo your last changes before adding my codes.

-1

I dont know what you did, but as per your need, simply do this:

function my_array_insert_after($key, &$array, $new_key, $new_value) {
	if (array_key_exists ($key, $array)) {
		$new = array();
		foreach ($array as $k => $value) {
			$new[$k] = $value;
			if ($k === $key) {
				$new[$new_key] = $new_value;
			}
		}
		return $new;
	}
	return FALSE;
}

add_filter('custom_ap_user_menu', 'my_custom_ap_user_menu');
function my_custom_ap_user_menu($menus){
	unset($menus['favorites']);
	$new_value = array( 'name' => __('Favorites', 'ap'), 'link' => ap_user_link($userid, 'favorites'), 'icon' => 'ap-icon-star');
	$menus = my_array_insert_after('profile', $menus, 'favorites', $new_value)
	
	return $menus;

}

and add this code to your theme functions.php

Rahul, that didn’t work, Favorites link is still in the wrong position.