Custom function for specific user role

The core has functions like current_user_can to check for an capability of a role or check the role directly. The follow example extend your source for this check so that the function not (!) run, if the current user haven’t the rights, the capability of his role. add_filter(‘request’, function( $vars ) { // Check the … Read more

Still relevant method of embedding images in WP Theme in 2018

someone questioned me today that I am not doing it correctly? <?php echo get_bloginfo(‘template_url’) ?>/images/logo.png There are 2 possible reasons this could be considered ‘incorrect’: get_bloginfo is a very old function that does multiple things, this particular function was replaced by get_template_directory_uri and get_stylesheet_directory_uri Security! You didn’t escape anything! The entire thing should be wrapped … Read more

How can I enable uploading excel files?

I think the proper filter would be mime_types found here. function wpse294198_mime_types( $mimes ) { $mimes[‘xls|xlsx’] = ‘application/vnd.ms-excel’; return $mimes; } add_filter( ‘mime_types’, ‘wpse294198_mime_types’ ); You can use command line tool file (linux|macOS) to see the mime type, e.g. file –mime-type -b somefile.xls

Missing argument 2 for a custom function widgets_init

widgets_init isn’t a function, it’s an action hook. The callback you specify for that hook is generate_sidebars which requires two parameters, but the widgets_init hook doesn’t pass any parameters to its callbacks. I think what you’re trying to do is this: add_action( ‘widgets_init’, ‘call_sidebar_function’ ); Which will call the call_sidebar_function() function which will then call … Read more