Are there any hooks available to disable the template library completely, or modify the templates that appear? I saw there were some other requests for this, but those were from a while ago, so I’m hoping there’s at least a workaround now.
I also wanted to mention that I reached out about this through support and they said to post here.
Using some pretty hacky JavaScript code in the admin we were able to hide the template library. It essentially bypasses the library by automatically clicking to create a “Blank Form”. I’ve added the code below in case anyone wants to use it or has suggestions on how to make it better.
document.addEventListener( 'DOMContentLoaded', function() {
const templateLibraryContainer = document.querySelector( '[data-js=\"gf-template-library\"]' );
// Only run this code if the template library is present.
if ( templateLibraryContainer !== null ) {
// Watch for the template library contents to be added to the DOM after page load.
const mutationObserver = new MutationObserver( ( mutationsList ) => {
for ( const mutation of mutationsList ) {
const blankFormButton = templateLibraryContainer.querySelector( '.gform-card__form-template-blank-button' );
if ( blankFormButton === null ) {
return;
}
// Watch for the "Blank Form" button to appear on the screen, then click it immediately.
const blankFormButtonObserver = new IntersectionObserver( ( entries, observer ) => {
entries.forEach( entry => {
if ( entry.isIntersecting ) {
setTimeout( () => { blankFormButton.click(); }, 100 );
}
});
});
blankFormButtonObserver.observe( blankFormButton );
// If the user clicks to close the new form details, immediately close the template library so it's not shown.
const newFormDetailsCloseButton = document.querySelector( '.gform-flyout--no-description .gform-flyout__close' );
const newFormDetailsCancelButton = document.querySelector( '.gform-flyout--no-description .gform-flyout__footer-secondary-button' );
const templateLibraryCloseButton = document.querySelector( '.gform-template-library__exit-button' );
if ( newFormDetailsCloseButton && newFormDetailsCancelButton && templateLibraryCloseButton ) {
newFormDetailsCloseButton.addEventListener( 'click', () => { templateLibraryCloseButton.click(); } );
newFormDetailsCancelButton.addEventListener( 'click', () => { templateLibraryCloseButton.click(); } );
}
mutationObserver.disconnect();
}
});
const config = { childList: true, subtree: true };
mutationObserver.observe( templateLibraryContainer, config );
}
});