• Resolved Rosemary Senjem

    (@rosemarydesigns)


    Hi,

    Love your plugin and in the last two days we have suddenly run into a conflict of some kind.

    For some reason, any content_block that is edited now gets reassigned as a post content type.

    Note that the first time a new content_block is added, it saves as a content_block. Then when it is edited for the first time, with only text changes to the content area, it becomes a post.

    Very problematic.

    Is anyone else having this issue? I’m not sure if its fighting with another plugin or what…

    At one point I thought it was happening due to All-in-One SEO plugin, but that does not now seem to be the culprit.

    Any help is welcome.

    https://www.ads-software.com/extend/plugins/custom-post-widget/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Johan van der Wijk

    (@vanderwijk)

    Hi Rosemary, if this is something that has started happening after you had used the Custom Post Widget plugin for a while, it is most likely related to another plugin you installed.

    I have never heard of this kind of issue, but I guess you might have another plugin installed for managing custom post types which is causing a conflict.

    There are a couple PHP notices when a widget is dragged into the active area:

    Notice: Undefined index: custom_post_id in /path/to/wp-content/plugins/custom-post-widget/post-widget.php on line 11

    Notice: Undefined variable: widgetExtraTitle in /path/to/wp-content/plugins/custom-post-widget/post-widget.php on line 33

    Notice: Undefined index: show_custom_post_title in /path/to/wp-content/plugins/custom-post-widget/post-widget.php on line 44

    Those evaporate after the widget has been saved. I don’t think this relates to Rosemary’s issue, though… I couldn’t reproduce the behavior.

    Hi Johan,

    I’m having a problem related to what fireproofsocks posted.

    After dragging the widget into active area the whole form in the widget disappears, except Delete/Close/Save buttons. They come back after the widget has been saved.

    Jusi — you’re experiencing the same thing, I think, except your PHP errors are not set to display. If you add the following to your wp-config.php file, I think you’ll see the same thing I did:

    define('WP_DEBUG', true);

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    Hi Fireproofsock,

    The errors you get are related to the fact that the content block has not been defined yet when you drag the Custom Post Widget into the widget area. In a future version I will add some isset checks to the plugin, but these error messages are harmless and will go away after saving the content block.

    Thanks Johan, for your response and for your willingness to correct the issue in a future version. Please keep in mind that there are situations on some servers where even a notice or an error can mean that the program fails. It’s a common response I hear from PHP developers for this common issue, but there is *no* situation where a PHP notice or a warning can be simply ignored. If for no other reason, when a user sees those errors, he knows immediately that something is off with the code.

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    Would you have any suggestions on how to fix these particular error messages? I want to keep my code as clean and simple as possible and after looking at your website, you are the right person to ask! I’m a front-end developer and still have a lot to learn when it comes to coding in php ??

    It’s just a matter of using isset() checks throughout your code, just as you had (correctly) mentioned. E.g. inside your post-widget.php file, instead of this line:

    $custom_post_id = esc_attr($instance['custom_post_id']);

    Try it this way:

    $custom_post_id = ''; // initialize the variable
    if (isset($instance['custom_post_id'])) {
        $custom_post_id = esc_attr($instance['custom_post_id']);
    }

    Later in that same file, you print out the $widgetExtraTitle variable:
    <?php echo $widgetExtraTitle; ?>

    But it’s not always initialized, so it too can generate a warning. It’s good to initialize your variables with a suitable default value, so maybe near the top of your form() function, declare the variable with a default value, e.g.

    $widgetExtraTitle = __('My Default Title', 'custom-post-widget');

    If there’s a value, it will get overwritten with the user’s declared value, but if not, the variable will still be in scope and no notice will be generated.

    You should also check whether the $instance[‘show_custom_post_title’] array key is set before you use it — it too is generating a notice.

    Hope that helps — it’s just those little details that make code clean, polished, and more secure, and quite importantly, it ensures that people will use it and benefit from your hard work. Brian and I talk about this stuff in our book if you’re interested in learning more: https://www.packtpub.com/wordpress-3-plugin-development-essentials/book

    Also, you may want to ensure that the post-type “content_block” is not registered by some other plugin and message the user if there’s a conflict.

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    Thanks for your help! I’ll incorporate your suggested solutions in the next version of the plugin!

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    I have (finally!) fixed the errors that appeared when dragging a new widget into a widget area. It would be really helpful if you could test this new version and let me know if this works for you:

    https://downloads.www.ads-software.com/plugin/custom-post-widget.1.9.6.zip

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Plugin: Custom Post Widget] Content Type re-assigning to Post on edit’ is closed to new replies.