GravityEdit: Turn on editing by default (without clicking the Toggle Inline Edit button)

You may want to make it so that users don't need to click the "Toggle Inline Edit" button when visiting a View. Instead, when visiting a View, you want the user to be able to start editing right away.

Why would you want to do this? One of our customers is the developer for a website used by many other users, and he didn't think the website users would know that they needed to click the "Toggle Inline Edit" button. He just wanted everything to be editable for them right away. They didn't want to receive questions like "Why can't we click to edit the fields?".

If you want Inline Edit enabled—without having to click the "Toggle Inline Edit" button—add this code to your website.

add_action('gravityview/template/before', 'set_gravityview_inline_edit_cookies');
/**
 * Set cookies toggling Inline Edit to on by default. Requires GravityView 2.0.
 *
 * @uses gravityview_get_current_view_data
 * @uses setcookie
 *
 * @return void
 */
function set_gravityview_inline_edit_cookies( \GV\Template_Context $gravityview = null ) {
	wp_print_scripts( 'jquery-cookie' );
?>
	<script>
		jQuery( window ).on( 'load', function() {
			if( jQuery.cookie ) {
			<?php
				printf( "jQuery.cookie( 'gv-inline-edit-view-%d', 'enabled', { path: '%s', domain: '%s' } );", $gravityview->view->ID, COOKIEPATH, COOKIE_DOMAIN, is_ssl() );
			?>
			} else {
				console.error("Could not set cookie for inline-edit.");
			}

		}); 
	</script>
<?php
}

Not sure how to add this code? Where to put code samples.

A few notes:

  • This still requires users to have permission to edit an entry.
  • If the user clicks the "Toggle Inline Edit" button, their preference will be saved (disabled/enabled). This code just sets the default editing value to enabled.
  • The code does not provide cookie usage notice for users in the European Union—you will need to provide that separately if your site serves EU users.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us