Need Help about some Coding Issues

I have below code to create custom metabox in my theme function.php.I couldnt find to how to sanizite it.Can you help me?

echo '<input type="hidden" name="mytheme_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
;
    echo '<table class="form-table">'

 switch ($field['type']) {
            case 'text':
                echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" />',
                '<br />', $field['desc'];
                break;
            case 'textarea':
                echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>',
                '<br />', $field['desc'];
                break;
            case 'checkbox':
                echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />';
                break;

Also, How can I create pot file for theme and plugin automatically? The phrases are escaped and have domain.

You need to use esc_attr functions on those fields.

As for the .pot file, use POedit software. There are plenty of tutorials about it on the internet.

Thanks for reply.Can you use the function in the code snippet as an example? I worry to make mistake on submitting.

Sure, but with all due respect, if you are not able to figure such basic thing yourself then I am not sure you are ready to submit anything on Envato. But that is up to you of course.

... name="' . esc_attr( $field[ 'id' ] ) . '" ...

1 Like

If you are creating a theme for ThemeForest, custom meta box must be in the plugin, not in the theme functions.php

thanks, yes know, I will transfer the code to plugin

1 Like