• Some snippets can’t be edited via the plugin’s editor.
    Any attempt generates a 501 Error page.
    But if I paste the edited snippet directly into its database field with PHPMyAdmin, it works fine.

    • This topic was modified 2 years, 9 months ago by aljuk.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Are you able to provide an example of one of these snippets?

    Thread Starter aljuk

    (@aljuk)

    Sure. The complete snippet is really long, so I’ll just include a bit of it and describe the scenario that triggers the error. The snippet creates meta boxes (using CMB2) which is something I’ve been doing with Code Snippets for a long time, and here is a bit of it, creating a dropdown of options to set some post meta data …

    add_action( 'cmb2_admin_init', 'register_metabox' );
    function register_metabox() {
    	$meta_boxes_1->add_field( array(
    		'name'       => esc_html__( 'Languages', 'admin-cmb' ),
    		'desc'       => esc_html__( '(tick all that apply)', 'admin-cmb' ),
    		'id'         => 'agent_languages',
    		'type'       => 'multicheck',
    		'options' => array(
    			'cn' => esc_html__('Chinese','admin-cmb'),
    			'de' => esc_html__('German','admin-cmb'),
    			'en' => esc_html__('English','admin-cmb'),
    			'es' => esc_html__('Spanish','admin-cmb'),
    		),
    	) );
    }

    To add another option (ie. in this case another language choice), I copy one that exists, hit the return key to create an empty line, paste it in, change it as necessary, and click save. This is what started throwing 501 errors on me today, as soon as I tried to save. If I copy the whole snippet, paste it into a stand-alone code editor, edit it, then copy and paste the whole snippet back into Code Snippets, 501 again. If instead I paste it straight to the Snippets field in the database, it accepts it and everything’s normal.

    At one stage I had the order of two of the options wrong, and wanted to swap them around. It wouldn’t save it, whether I copied just the bit of code and made a new line to paste it into, or copy/pasted the whole line.

    I kept an eye on the browser console, but nothing was evident.

    • This reply was modified 2 years, 9 months ago by aljuk.
    Plugin Author Shea Bunge

    (@bungeshea)

    I’m not really sure what the issue is here. I can’t see anything wrong with the code you’ve posted, and it saved and activates fine when I try it out.

    If I had to guess, I’d say that the problem is the use of what I imagine to be a pretty common function name, register_metabox. If you have not yet, I would recommend rewriting this to use an anonymous function and then trying it out:

    add_action( 'cmb2_admin_init', function () {
    	$meta_boxes_1->add_field( array(
    		'name'       => esc_html__( 'Languages', 'admin-cmb' ),
    		'desc'       => esc_html__( '(tick all that apply)', 'admin-cmb' ),
    		'id'         => 'agent_languages',
    		'type'       => 'multicheck',
    		'options' => array(
    			'cn' => esc_html__('Chinese','admin-cmb'),
    			'de' => esc_html__('German','admin-cmb'),
    			'en' => esc_html__('English','admin-cmb'),
    			'es' => esc_html__('Spanish','admin-cmb'),
    		),
    	) );
    } );
    Thread Starter aljuk

    (@aljuk)

    “I’m not really sure what the issue is here”

    The issue is that the snippet can’t be edited or changed in the editor, and attempting to do so, or to make any changes in the editor at all (even like creating a new line), causes a 501 when I attempt to save.

    I don’t think it has anything to do with the content of the snippet per se.

    When I copy and save the snippet straight into its database field via phpmyadmin, everything’s fine.

    I can only imagine perhaps some issue with text encoding or length (it’s a long snippet) or something of that nature. Maybe I’m somehow triggering an edge-case of some sort.

    Plugin Author Shea Bunge

    (@bungeshea)

    By “I’m not really sure what the issue is here” I meant that I am unsure what’s causing the problem, not that I doubt there is one.

    It’s difficult to give advice when I’m not sure how to investigate this. If it is a DB encoding problem, then something to try is exporting all snippets, removing the database table, and then importing them.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘501 Errors’ is closed to new replies.