- Solution for unlocking items locked by a specific user.
Get-ChildItem master:\content -rec -Language * |
Where-Object { $_.Locking.GetOwner() -eq "sitecore\USERNAME" } |
% { $_.Locking.Unlock() }
- Unlock Item command button in Sitecore Content Editor. Allow access of this button to specific role only.
public class UnlockItem : Command
{
public override void Execute(CommandContext context)
{
if (context.Items.Length != 1)
return;
var item = context.Items[0];
if (item.Locking.IsLocked() && item.Access.CanWrite())
{
using (new Sitecore.SecurityModel.SecurityDisabler())
{
item.Locking.Unlock();
}
}
}
public override CommandState QueryState(CommandContext context)
{
if (context.Items.Length != 1)
return CommandState.Hidden;
var item = context.Items[0];
if (!item.Locking.IsLocked() || !item.Access.CanWrite())
return CommandState.Hidden;
return base.QueryState(context);
}
}
Patch config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<commands>
<command name="contenteditor:unlockitem" type="MyAssembly.Namespace.UnlockItem, MyAssembly" />
</commands>
</sitecore>
</configuration>
And add a new button in core database under: /sitecore/content/Applications/Content Editor/Ribbons/Chunks/Locks item
Credit: https://www.skillcore.net/sitecore/sitecore-unlock-item-command
Hope it helps!