WordPress.org

Ready to get started?Download WordPress

Forums

Need to edit galleries from text editor (2 posts)

  1. kvignos
    Member
    Posted 9 months ago #

    We need to be able to edit previously created galleries from text editor. Our installation has the visual editor disabled because we've had problems with it eating posts (stripping content).

    How can we provide a workaround to edit galleries from text mode?

    I'm trying to add new menu items for each gallery to the Insert Media modal, but it's complicated since we need to grab each instance of the gallery shortcode (since there can be multiple galleries on a post), and then provide a link to the Edit Gallery modal.

    I know how to add a link to the Insert Media modal:

    Edit_my_gallery_string = 'Edit Gallery 1';
    Edit_my_gallery = new wp.media.view.RouterItem( _.extend( options, { text: Edit_my_gallery_string } ) );
    workflow.menu.view.views.set( '.media-menu', Edit_my_gallery, _.extend( options, { add: true	 } ) );

    But I'm not sure 1) how to set up a link for each gallery dynamically and 2) once that link is on the Insert Media menu item toolbar, how to open the Edit Gallery modal by passing the correct gallery ids.

    Thanks for any help anyone can provide!

  2. kvignos
    Member
    Posted 9 months ago #

    More details about our attempts:

    First issue is that my Edit Gallery 1 link gets generated by the code in my original post as:

    <a href="#" class="media-menu-item">Edit Gallery 1</a>

    the class name ("media-menu-item") is not unique, so if I add

    jQuery(document).on( 'click', '.media-menu-item', function( event ){
    		event.preventDefault();
    		wp.media.gallery.edit('[gallery ids="19580,19579,19578,19577,19576"]');
    	});

    I can get the gallery modal to open, but it breaks all the other media-menu-item element links (of course).

    How do I identify the "Edit Gallery 1" link so I can apply the on('click') event to it? How can I add an id attribute, for instance?

    How do I get and pass the correct shortcode instead of having it hardcoded in wp.media.gallery.edit()? I tried playing around with wp.shortcode.string; but it's not clear how to loop through and get each shortcode string and then set up the "Edit Gallery n" link (and then pass the correct shortcode).

Reply

You must log in to post.

About this Topic

Tags

No tags yet.