0

I have a plugin that expands a spanning shortcode into a <table>, and one of the parameters is the number of columns, eg:

[table cols=3]
Row 1
Data
33%
Row 2
Data
67%
[/table]

Now, using the raw HTML editor I might forget to add the cols, or I might enhance my plugin so that it can make an intelligent guess at the real number of columns, etc, but how can I report to the post editor that there is an error or warning? My usual workflow is to edit the post in a text editor, paste it into the HTML editor, save draft, then preview. What is the recommended way to pop up an error in either the backend or the preview window? If I'm in a hurry, for instance, I might not scroll down to the table to see an error message directly inserted into the stream at the [table] tag, so the simple solution is probably not suitable.

  • Please share the code responsible for the shortcode. – CodeMascot Jun 26 '17 at 1:27
1

Take a look at admin notices. If you the cols parameter isn't set use some code like this:

function sample_admin_notice_fail() {
    ?>
    <div class="notice notice-error is-dismissible">
        <p><?php _e( 'You forgot the cols parameter!', 'sample-text-domain' ); ?></p>
    </div>
    <?php
}

add_action( 'admin_notices','sample_admin_notice_fail' );

to display this notice: enter image description here on top of your admin page.

You find some more information about implementing admin notices on this page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.