WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Widget
[closed] Can't use the button to insert Content Blocks (30 posts)

  1. cassiedong
    Member
    Posted 8 months ago #

    Tried to insert a Content Block using the "Add Content Block" button, but it kept saying "Please select a Content Block" when a content block is already selected - see http://screencast.com/t/uPQJA2awXun

    I'm not sure if this is due the recent upgrade that we did to WordPress.

    You help would be appreciated.

    http://wordpress.org/plugins/custom-post-widget/

  2. Johan van der Wijk
    Member
    Plugin Author

    Posted 8 months ago #

    Hi Cassie,

    I have tested the plugin in both WordPress 3.7.1 and 3.8 beta 1 but I cannot replicate the issue. It is working fine for me.

    I saw in this topic that you made a modification to the plugin file which might be the cause of the issue. Could you please check if using the unmodified plugin helps?

  3. mpmchugh
    Member
    Posted 7 months ago #

    I'm seeing this as well on 3.7.1.

    I'm guessing it might be a plugin conflict of some sort, but have not yet been able to track it down.

  4. cassiedong
    Member
    Posted 7 months ago #

    Hi Johan,

    Thanks for your reply. Thanks mpmchugh as well, glad to know it's not just me. In that case it would be a conflict with one of the plugins or the theme. I might do some troubleshooting and see if I can track down which plugin it is.

    I'm thinking about implementing that modification, but haven't done it just yet. I would like to see that feature being built into the plugin hence the comment (never a big fan of modifying the core).

    Thanks!

  5. Johan van der Wijk
    Member
    Plugin Author

    Posted 7 months ago #

    Hi Cassie,

    Are you still experiencing this issue?

  6. mpmchugh
    Member
    Posted 6 months ago #

    I'm still seeing this issue. I suspect it's a Javascript bug or conflict, as it's not realizing the Content Block is selected.

    [ Here's a screenshot. ]

  7. psteinweber
    Member
    Posted 6 months ago #

    I'm experiencing the same issue! No modifications to the plugin itself.

  8. Johan van der Wijk
    Member
    Plugin Author

    Posted 6 months ago #

    I am sorry that you are also experiencing this issue. Because I cannot replicate it myself (used IE11 and Firefox 26) there is not much I can do about it.

    It is most likely a javaScript issue but without any debug information I cannot be sure about this.

    Here are some suggestions for troubleshooting this issue:
    - Try a different web-browser
    - If the issue occurs in all browsers; install a debug tool such as the Web Developer toolbar for Mozilla Firefox to check if you get any javaScript errors
    - Try disabling all other plugins and switch back to the default Twenty Thirteen theme. Then check if the issue is solved and if so; enable the used theme and disabled plugins one-by-one each time checking the issue returns.

    If the above does not help it could also be that some kind of Internet Security software such as McAfee is blocking the javaScript.

  9. mpmchugh
    Member
    Posted 6 months ago #

    For me, it seems to be a conflict with "Advanced Custom Fields".

    When I disabled ACF it in our test environment the overlay for placing Content Blocks worked again.

    Perhaps you can contact them and see about resolving, if you can't yourself once you install it and test it with. I've notified the ACF authors as well.

    I know this was addressed in another thread, but even if you don't amend your plugin to place them by slug, it'd be nice for the overlay to drop the Content Block's name in the short code even as a label, so we can see what it is once it's placed. It's very confusing without some sort of name present, especially when you have multiples on the same page.

    Something like this perhaps: [content_block id=3329 title='Form - Jobs']

    Thanks,
    Michael

  10. Johan van der Wijk
    Member
    Plugin Author

    Posted 6 months ago #

    Thank you for letting me know about this plugin conflict! I have installed ACF on my test install and have been able to reproduce the problem.

    Unfortunately I haven't found the bug yet but I am hopeful that I will be able to solve this issue soon.

    Adding the title to the shortcode seems like a good compromise, thanks for the suggestion!

  11. Sith Lord Goz
    Member
    Posted 6 months ago #

    Hi Johan -

    I'm having a similar issue, and I think it occurs when there are multiple WYSIWYG fields on the Edit screen. This is a pretty common situation when using any kind of advanced TinyMCE editor, or custom post type fields that use the WYSIWYG control.

    I think the issue occurs because every WYSIWYG instance causes a new dropdown to be created, but they all use the same DOM ID ("add-content-block-id").

    So when the jQ hook looks to see which content block was selected, it only finds the first instance of "#add-content-block-id" (the Post Content field) and returns false.

    If possible, could you tweak that jQ to produce a <select> element with a class (instead of ID) and then use the $.each() function to support the Content Block insertion from one of many WYSIWYG blocks?

    That way, everything should play nicely when multiple editors are present.

    Keep up the great work!

    -Goz

  12. Johan van der Wijk
    Member
    Plugin Author

    Posted 6 months ago #

    Hi all, I think I have fixed this now. Could you please download and install this beta version: http://downloads.wordpress.org/plugin/custom-post-widget.2.4.5.zip

    Please let me know if this has solved the issue so I can release it asap :)

  13. Sith Lord Goz
    Member
    Posted 6 months ago #

    Hi Johan -

    I downloaded and tested your 2.4.5 version with multiple TinyMCEs present and it works GREAT!

    Fantastic response time and fix mate - looking fwd to it getting rolled to WP repo.

    Cheers!

  14. Johan van der Wijk
    Member
    Plugin Author

    Posted 6 months ago #

    Thanks Sith, that is excellent news!

    It would be great if the original reporter of the issue, cassiedong and the others in this thread like mpmchugh and psteinweber could also check if their issue has been solved.

    Could you please test this new version I made for you and let me know the outcome?

    http://downloads.wordpress.org/plugin/custom-post-widget.2.4.5.zip

  15. mpmchugh
    Member
    Posted 6 months ago #

    Just saw this. I've installed and confirmed in our staging environment that the issue with ACF is resolved in the 2.4.5 version.

    Oh, also glad you like the idea of adding the title to the short code. Greatly looking forward to that, as it will make using the plugin a lot easier!

    Thanks!

  16. Johan van der Wijk
    Member
    Plugin Author

    Posted 6 months ago #

    Ok, I have now released V2.4.5 to fix this issue.

    Let's hope this change has not introduced any new conflicts with other plugins :)

  17. mpmchugh
    Member
    Posted 6 months ago #

    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

  18. Sith Lord Goz
    Member
    Posted 6 months ago #

    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!!

  19. Johan van der Wijk
    Member
    Plugin Author

    Posted 6 months ago #

    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 :) )

  20. Sith Lord Goz
    Member
    Posted 6 months ago #

    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 :)

  21. GermanKiwi
    Member
    Posted 5 months ago #

    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! :)

  22. anderscarlen
    Member
    Posted 5 months ago #

    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!

  23. Johan van der Wijk
    Member
    Plugin Author

    Posted 5 months ago #

    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: http://wordpress.org/plugins/custom-post-widget/developers/

  24. Sith Lord Goz
    Member
    Posted 5 months ago #

    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)

  25. mpmchugh
    Member
    Posted 5 months ago #

    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.

  26. Nikoya
    Member
    Posted 5 months ago #

    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 );
    			});
    
    		});
  27. Pirer
    Member
    Posted 5 months ago #

    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!

  28. Joseph Dickson
    Member
    Posted 5 months ago #

    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.

  29. Sith Lord Goz
    Member
    Posted 4 months ago #

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

  30. esmi
    Forum Moderator
    Posted 4 months ago #

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

    This topic references an old version of WordPress.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic