Cornflower Design Development

SharePoint’s People Picker Error

Posted within Administration Development on by Ryan Ball

Since the roll out of Internet Explorer 10, our users were having trouble whenever they attempted to give someone access to their SharePoint 2010 area via the Grant Permissions dialog. Whenever they clicked the Browse icon, they’d receive a “An unexpected error has occurred” message.

One solution that seemed to solve this issue was to add the domain of the SharePoint site into the browser’s Compatibility View Settings – but that would effect all sites using the domain (including non-SharePoint sites).

While researching the issue I found a suggestion that it could be corrected by appending a META tag to one of the MasterPages.

Normally I wouldn’t dare edit one of the SharePoint core files, but as this was effecting so many users and we’ll be migrating to SharePoint 2013 in the near future, the benefits outweighed the risks.

  1. Browse to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS and locate the pickerdialog.master file.
  2. Immediately after the opening HEAD tag, insert the following line: <meta http-equiv=”X-UA-Compatible” content=”IE=EmulateIE8″ />

The changes appear to have resolved the issue completely.

Hiding Disqus Comments

Posted within Development on by Cornflower Design

While the Disqus commenting system may be fine for standard post types, sometimes clients don’t wish to use them on specific custom post types. Previously (c. 2013), the following code worked for me…

add_filter( 'the_content' , 'dsq_comments_template_remove' );

function dsq_comments_template_remove( $content ) {
	global $post;

	if ( function_exists( 'dsq_comments_template' ) && 'post' != get_post_type( $post ) ) {
		remove_filter( 'comments_template', 'dsq_comments_template' );
	}
	
	return $content;
}

Now I have to use this code:

add_filter( 'comments_template' , 'dsq_comments_template_remove', 1 );

function dsq_comments_template_remove( $file ) {
	if ( 'question' == get_post_type() ) {
		remove_filter( 'comments_template', 'dsq_comments_template' );
	}

	return $file; 
}

Source: <a href="http://www.wpbeginner.com/wp-tutorials/how-to-disable-disqus-on-custom-post-types-in-wordpress/">How to Disable Disqus on Custom Post Types in WordPress</a>

Value does not fall within the expected range

Posted within Development on by Cornflower Design

The following code, which was supposed to update the “Current” Composed Look, was throwing a “value does not fall within the expected range” error each time I ran it.

SPWeb web = properties.Feature.Parent as SPWeb;
SPList gallery = web.GetCatalog(SPListTemplateType.DesignCatalog);

if (gallery != null)
{
    SPQuery q = new SPQuery();
    q.RowLimit = 1;
    q.Query = "<Where><Eq><FieldRef Name='DisplayOrder'/><Value Type='Number'>0</Value></Eq></Where>";
    q.ViewFields = "<FieldRef Name='DisplayOrder'/>";
    q.ViewFieldsOnly = true;

    SPListItemCollection items = gallery.GetItems(q);

    foreach (SPListItem item in items)
    {
        item["MasterPageUrl"] = web.MasterUrl;
        item.Update();
    }

}

After a lot of head scratching, it boiled down to the ViewFieldsOnly property which, which I had left set to true. Doh! Updating the property to false corrected the error.

See: SPQuery.ViewFieldsOnly property

SharePoint 2013: Focus on Content

Posted within Development on by Cornflower Design

SharePoint 2013 has introduced a small Focus on Content icon to the ribbon bar which, for the MasterPages that support it, will show and hide portions of the page when clicked. This can be useful for hiding non-essential page elements.

When the icon is clicked, JavaScript will do two things:

  1. It creates a cookie, so the selection is remembered the next time the page is visited.
  2. It adds a new ms-fullscreenmode class to the page’s BODY tag.

So, via CSS, we can decide which elements of the page should be hidden via the Focus on Content functionality.

.ms-fullscreenmode #nonessentialcontent { display: none; }

How Many Users In An Active Directory Group?

Posted within Development on by Cornflower Design

This is a useful PowerShell snippet for determining how many users there are in an Active Directory group.

(Get-ADGroup "CN=MyGroup,DC=domain,DC=co,DC=uk" -Properties *).Member.Count

Oops! Twitter Feeds Now Working

Posted within Announcements Development on by Cornflower Design

I missed the June announcement from Twitter informing everyone that their API v1 was about to be retired – meaning that feeds on my homepage had been failing to update.

Along with the introduction of rate limits and ditching support for RSS as a response format, API v1.1 has implemented OAuth 2.0 for its authentication. Its not the most straight-forward thing to get your head around, but I found a useful post on CodeForest that helped me to update my own WordPress widgets.

CSS and Nested Border-Radii

Posted within Development on by Cornflower Design

Now, this is an issue I’ve stumbled across while putting together CSS for websites.

You have two elements, one nested within the other, and both have rounded borders. Unless you get the radius of the nested element just right, you’ll end up with a nasty looking ‘hump’ where there should be a nice smooth curve (See Chris Coyier’s post for a visual example).

Fortunately, Joshua Hibbert has blogged about the problem, documented the math­em­at­ical for­mu­las and even coded a tool for the job. Great!

Hiding SharePoint WebParts via Code

Posted within Administration Development on by Cornflower Design

Another note to myself…

When wanting to programmatically hide a WebPart, don’t try to set it’s Visible property to False. This will cause you lots of trouble and create errrors. The correct method is to set its Hidden property to True.

if (items.Count == 0)
{
   this.Hidden = true;
   return;
}

 

PowerShell Snippets for Microsoft Exchange

Posted within Development on by Cornflower Design

These are two very handy PowerShell snippets that I use again and again within our work environment.

Retreive List of All Group Members

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
csvde -f C:\report.csv -s mydomain.co.uk -r "memberof=CN=Dept:MyTartgetGroup,OU=Domain Groups,DC=mydomain,DC=ac,DC=uk" -l "sAMAccountName,name, mail"

Retreive List of All Users with Permission to Email a Group

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Get-DistributionGroup "Dept:MyTargetGroup" | Select name,@{Name="AcceptMessagesOnlyFrom";Expression={[string]::join(";",($_.AcceptMessagesOnlyFrom | foreach {$_.Name}))}} | Export-Csv C:\report.csv

The Post Slug

Posted within Development on by Cornflower Design

While within The Loop, WordPress provides many functions to quickly access the properties of the Post – but it doesn’t include a built-in function to get the slug for the current Post (although, admittedly, you could simply use $post->post_name).  This functionality can be easily included by adding the following two mini-functions within the functions.php file.

function get_the_slug() {
	global $post;
	return $post->post_name;
}

function the_slug() {
	echo get_the_slug();
}

Update (26 August 2012)

To be absolutely correct, to avoid possible conflicts with other core WordPress or third-party functions, the two sample functions should really be prefixed with a unique identifier, e.g. cornflowerdesign_get_the_post(). I would also recommend wrapping the functions with a function_exists() check, like so.

if ( !function_exists( 'cornflowerdesign_get_the_slug' ) ) {
	function cornflowerdesign_get_the_slug() {
		global $post;
		return $post->post_name;
	}
}