Support » Plugin: If Menu - Visibility control for Menu Items » New feature: Power to the conditions

  • Hi Andrei,

    The conditions could be so much powerful if you provided the current menu item object to the condition. I have added “, $item” to the parameters for the condition:

    if-menu.php Line 78:
    $condition_result = call_user_func( $conditions[$condition][‘condition’], $item );

    That enables me to check neat stuff like if the linked page is enabled or not:

    add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );
    function my_new_menu_conditions( $conditions ) {
        $conditions[] = array(
            'name'      =>  'Page is published',	// name of the condition
            'condition' =>  function($item) {		// callback - must return TRUE or FALSE
    			// Only applies to page menu items
    			if ($item->object != 'page')
    				return true;
    			// Get the linked page status
    			$post_status = get_post_field( 'post_status', $item->object_id );
    			// Return true if the page is published
                return $post_status == 'publish';
    	return $conditions;

  • The topic ‘New feature: Power to the conditions’ is closed to new replies.