How to add css to wp_head depending on the user role?

Thanks to the help of two fellow members of this forum I have managed to get the snippet working. Here I leave the solution for any future answer seeker who happens to stop by. add_action( ‘wp_head’, function () { //Get current user ID, if the user is logged in. if ( is_user_logged_in() ) { $user_id … Read more

How to enable on custom shortcodes

You are using esc_attr in your table_data function. This will encode the html in your variable in such a way that it is no longer recognized as html. So the browser will display “<br>” rather than insert a line break.

PHP cookie not set within AJAX call

Apparently I was missing the time() attribute. So when adding this to the expire option in the setCookie function, the cookie is being set. Code: setcookie(‘user-zipcode’, $zipcode, time() + MONTH_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN); setcookie(‘delivery-today’, $cookieVal, time() + DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);

Custom Wp_query loop takes very long

I found a solution to my question. I used the following code: global $wpdb; if($t_query->have_posts()){ while($t_query->have_posts()){ $t_query->the_post(); echo $wpdb->last_query.”\r\n”; } } and it showed there was an action somewhere hooked to the_post hook, sending requests to update some meta every time a post was processed. So, the answer to my question is: I should have … Read more

how can a plugin return an error message on activation?

I use code similar to this to check for the minimum requirements for a plugin: if (is_admin()) { // check for required versions of WP and PHP $min_wp = ‘4.9.6’; $min_php = ‘7.2’; if (!check_requirements($min_wp, $min_php)) { add_action(‘admin_init’, ‘my_disable_plugin’); add_action(‘admin_notices’, ‘my_show_notice_disabled_plugin’); add_action(‘network_admin_init’, ‘my_disable_plugin’); add_action(‘network_admin_notices’, ‘my_show_notice_disabled_plugin’); my_deregister(); return; } } function check_requirements($min_wp, $min_php) { // see … Read more

Using useSelect creates “minified React error”

If you check the URL given with the error message, you will see the full text as: Rendered more hooks than during the previous render. Inspecting the code, I see two uses of hooks: export default function Edit() { const allCPTposts = useSelect(select => { // ^ first hook use return select(“core”).getEntityRecords(“postType”, “post”, {per_page: -1}) … Read more