Viewing 14 replies - 16 through 29 (of 29 total)
  • Well, it seems to work on the site I was having a conflict with ACF.

    However, I just upgraded it on another site I just installed it on recently without ACF, and it does not work. I don’t get the error, but after selecting a Content Block, clicking the “Insert Content Block” button in the overlay on that site does nothing. ??

    I’ll see if I can track down the conflict there. It might take a while though, as I don’t have an active staging server setup for that one.

    This is the error the Safari console is giving when the button is clicked on that site.

    [Error] ReferenceError: Can't find variable: content_id
    	insertContentBlockShortcode (post.php, line 903)
    	onclick (post.php, line 924)

    -Michael

    Hi Johan –

    There are a few issues with this update ??

    1) The variable contend_id isn’t defined – this is because you’ve not set the scope, and are testing for = “” instead of typeof() == ‘undefined’

    2) Shouldn’t the jQuery hook come inside a jQuery(document).on(‘ready’) block to be sure it executes after the DOM has loaded? Right now it would appear the hook is called before the <select> element has been written.

    3) Multiple WYSWYG editors on a page still generate elements with the same ID attribute, like
    <div id="content-block-form">. I’d suggest avoiding IDs in your injected code – instead use unique sets of classes.

    4) Maybe remove the inline “onclick” handler, and just use jQuery to hook the click button

    5) Should probably comment out/ remove the console.log() line ??

    I would submit this (or something like it) as an alternative (dummy content blocks added for clarity)

    <script type="text/javascript">
    		jQuery(document).ready(function($) {
    
    			// Iterate through all Content Block groups
    			$('.content-block-form').each(function(index, element) {
    
    				// Hook the Insert button
    				$('input.insert', element).on('click', function(evt) {
    
    					// Get select element and selected ID
    					var win = window.dialogArguments || opener || parent || top,
    						$el_select = $(this).closest('.content-block-form').filter('select.add-content-block-id'),
    						content_block_id = $el_select.val();
    
    					if( content_block_id == "" ) {
    						alert( "Please select a Content Block" );
    						return false;
    					};
    
    					// Success
    					win.send_to_editor( "[content_block id=" + content_block_id + "]" );
    				});
    			});
    		});
    	</script>
    
    	<div class="content-block-form">
    		<h3>Insert Content Block</h3>
    		<p>
    			Select a Content Block below to add it to your post or page.
    		</p>
    		<p>
    			<select class="add-content-block-id">
    				<option value="">Select a Content Block</option>
    				<option value="1">Test content block 1</option>
    				<option value="2">Test content block 2</option>
    				<option value="3">Test content block 3</option>
    			</select>
    		</p>
    		<p>
    			<input type="button" class="button-primary insert" value="Insert Content Block" />
    		</p>
    	</div>

    I’ve not tested this code or anything, but something close to this should work for multiple editors and avoid conflicts.

    Hope it helps!!

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    Hi Sith,

    Thanks for your extensive code review of the latest update! I shall take your suggestions in consideration for the next update (especially the sloppy console.log ?? )

    Cool. Just a reminder that the Content Block selection script in the current version (2.4.5) doesn’t work out-of-the-box, so I’m sure people are excited for a fix in 2.4.6 ??

    Just been reading this thread, as I’m experiencing the same issue that mpmchugh most recently described above (with v2.4.5) – specifically, when I click the Insert Content Block button, absolutely nothing happens – no error message, no shortcode added.

    I’ll wait for the next version and hopefully that’ll fix things! ??

    Just to echo the previous comments – I am too eagerly waiting for 2.4.6 since your Content Block plugin is one of my favourites for working with re-usable content. But as GermanKiwi and others have reported, at the moment the selection script is not working.
    Keep up the good work Johan!

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    It is working fine for me and some others on this forum, so I am not sure what is cause here. I will investigate and try to fix it. Unfortunately I first have to finish some projects that pay my rent, so it will take some days before I’ll have time for this.

    In the meantime, as a workaround you can find the previous versions of the plugin here: https://www.ads-software.com/plugins/custom-post-widget/developers/

    I’m sure we totally understand that this is a great FREE plugin, and that you need to do paid work first & foremost!

    Just to help debug: you can replicate the error easily by installing a completely new, clean WP 3.8.1 install, install the Custom Post Widgets 2.4.5, then try to create & insert a content block on a page. The selector will not work because “content_id” is not defined.

    (See my earlier post for corrections)

    I’m seeing the insertion problem again as well. Oddly it was working fine with the beta you’d released a while back, but the latest release one does not.

    Nikoya

    (@nicolas-andre)

    Hi all,
    I can’t add block reason : “content_id” not defined.

    I seems we just need to wait document ius ready.

    So i suggest to REPLACE :

    jQuery( '.add-content-block-id' ).change( function() {
    				content_id = jQuery( this ).val();
    				console.log( 'content_id: ' + content_id );
    			});

    BY

    jQuery( document ).ready(function() {
    
    			jQuery( '.add-content-block-id' ).change( function() {
    				content_id = jQuery( this ).val();
    				console.log( 'content_id: ' + content_id );
    			});
    
    		});

    I was having exactly the same issue that Nikoya, and after editing the plugin (for those who don’t know which file should be edited, it is at the beginning of “popup.php”).

    Now it’s working fine. Thanks a lot!

    For another thing, Johan, maybe you can just show the shortcode (something like [content_block id=502]) in the pop-up so if the button isn’t working, it is still possible to copy it. (it’s very difficult to get the ID of a content block otherwise). Btw, very nice plugin, thanks a lot for sharing it!

    Nikoya’s solution fixed the problem.

    In my case I wasn’t receiving an error message but the “insert content block” button didn’t function.

    Please add this code to the next update if possible.

    Thanks Nikoya.

    Still no fix!? I confirmed the insertion button does not work out-of-the-box with a clean WP 3.8.1 install.

    If you require assistance then, as per the Forum Welcome, please post your own topic.

    This topic references an old version of WordPress.

Viewing 14 replies - 16 through 29 (of 29 total)
  • The topic ‘Can't use the button to insert Content Blocks’ is closed to new replies.