Output custom post shortcode. Help spot the error.

You’re resetting the value of $output each time you go through the loop: foreach ($row as $post) { // etc. $output=”<div class=”col-md-6 event-item”>”; // Here $output // etc. } That $output assignment is resetting the value of $output to ‘<div class=”col-md-6 event-item”>’, throwing out everything that had been appended to it. You’re also returning $output … Read more

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

Limit the number of plugins that can be installed in a WordPress installation

The most performant way to do this is probably by hooking into map_meta_cap to conditionally disallow the install_plugins capability. There are no database calls involved with that. Here’s an (untested) example: add_filter( ‘map_meta_cap’, ‘wpse291964_limit_plugins’, 10, 2 ); function wpse291964_limit_plugins( $caps, $cap ) { if ( ‘install_plugins’ === $cap ) { $plugins = get_plugins(); // Only … 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

How to check If Oembed is empty or not

The wp_oembed_get() only works for supported oEmbed providers. The return value is also is a URL of false, as mentioned per codex: If $url is a valid url to a supported provider, the function returns the embed code provided to it from the oEmbed protocol. Otherwise, it will return false. Therefore, is the input is … Read more