custom css for admin only

The code that you’ve tried already adds the role CSS class to the admin_body_class, which only affects the admin area/backend. Simply change the filter to alter the frontend body class body_class, eg. function wpa66834_role_admin_body_class( $classes ) { global $current_user; foreach( $current_user->roles as $role ) $classes .= ‘ role-‘ . $role; return trim( $classes ); } … Read more

Include a PHP file inside an array

Please Use Below code <?php $addcats = array(); ob_start(); require ‘custom_menu_addon.php’; $addCats = ob_get_clean(); wp_nav_menu(array( ‘theme_location’ => ‘menu-1’, ‘menu_id’ => ‘primary-menu’, ‘items_wrap’ => ‘<ul id=”%1$s” class=”%2$s”>%3$s<div class=”my-div”>’ . $addCats . ‘</div></ul>’ )); I’ve edited this answer after some research into the usage of this object array and put it in context with my code, works … Read more

Call to undefined function get_userdata() in plugin

Solution found: the reason was that the code including those lines were included in plug-in’s main file and were wrapped in the shortcode launch anymore. I had to put things in another file,like for example function load_shortcode( $atts ){ require_once(getPluginPath().(‘my-project.start.php’)); } add_shortcode( ‘my-project’, ‘load_shortcode’ ); and lines had to be in my-project.start.php getPluginPath() is NOT … Read more

php syntax : [ && ] between commands [closed]

I think its actually not allowed or discouraged in WP coding standards. Its is basically saying “If true go ahead”. It’s a short form of this: if ( did_action( ‘init’ ) ) { $scripts->add_inline_script( ‘lodash’, ‘window.lodash = _.noConflict();’ ); } You can also think of this as if it’s inside brackets of an if statement … Read more

Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?

You’ll need to look at the server side logs to see what’s actually causing the 400. Without this, it’s just conjecture. With it, you should see exactly what’s causing the problem. However, I conjecture that you’re lacking authentication headers, or an authentication request. I’m not seeing anything related to authentication in your AJAX request, and … Read more

Can anyone offer any help with this function?

The filter you are using posts_where affects the creation of SQL query, so by definition it is executed before query runs and you have any search results. So you cannot loop through results at this point, what you can do is retrieve or hardcode list of unwanted items from elsewhere and use them to modify … Read more