Add Slug Metabox to posts for contributors

I approached by doing the opposite with using remove_meta_box() for the Slug metabox if the user is not an administrator or contributor: add_action( ‘admin_menu’, ‘wpse_237291_remove_slug_metabox’ ); function wpse_237291_remove_slug_metabox() { $user = wp_get_current_user(); $allowed_roles = array( ‘administrator’, ‘contributor’ ); if ( !array_intersect( $allowed_roles, $user -> roles ) ) { remove_meta_box( ‘slugdiv’, ‘post’, ‘normal’ ); } }

How to put Periods and Spaces for Array Values (Meta Key)

You may have build your meta box wrong: If your custom field names are not valid variable names PHP will convert all characters not matching [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff] to underscores. The reason: register_globals. A request field must be able to work as a variable. There are two workarounds: Name the field like an array: <input name=”foo[TrackNumber mp3.Artist]”>. … Read more

make a excerpt on data from a meta box?

You could make use of wp_trim_words: <p><?php echo wp_trim_words( get_post_meta( $post->ID, ‘twpb_news_textnews’, true ), 55, ‘[&hellip;]’ ); ?></p> Or, if you want the filters applicable to the regular excerpts to be used as well, write your own wrapper for it: function wpse115106_news_excerpt( $text=”” ) { $excerpt_length = apply_filters( ‘excerpt_length’, 55 ); $excerpt_more = apply_filters( ‘excerpt_more’, … Read more

I’m confused about URL sanitization in meta boxes

Choice between esc_url and esc_url_raw depends on the use you have to do with the url. If you have to use the url to display inside html use esc_url, E.g.: $my_link = get_post_meta( $post->ID, ‘mod_modbox_link’, true ); echo ‘<a href=”‘ . esc_url($my_link) . ‘”>Open link</a>’ esc_url_raw should be used for any other use, where the … Read more