Function not working inside of a function in functions.php

Remove the function inside the function, and instead call the wp_register_script and register_block_type inside the large function. Finally, remove the inner add_action() call, so you only have the ending one for the large function. function irm_lockdown_author_role() { if (isset($userrole->roles[0])) { $current_role = $userrole->roles[0]; } else { $current_role=”no_role”; } if (‘author’ == $current_role) { /* function … Read more

Extending a custom framework built into WordPress to automatically turn the ‘Search Engine Visibility’ setting ON / OFF, dependant on environment

Those “definable settings” are constants. WordPress defines its default constants in this file. If a constant definition is wrapped in a defined() check, like this: if ( ! defined( ‘WP_DEBUG_DISPLAY’ ) ) { define( ‘WP_DEBUG_DISPLAY’, true ); } Then it means you can define it first in the wp-config.php file (or, apparently, this framework’s config … Read more

Wp-query Order By problem

The “problem” seems to be the default value that order receives, its always DESC unless told otherwise. You will need to create your own order after getting the posts, so something like this. $my_query = new WP_Query($query_args); $ordered_posts = []; foreach(explode(‘,’, $idpaginas) as $rpid) { foreach($my_query->posts as $index => $fpid) { if($fpid->ID == $rpid) $ordered_posts[] … Read more

Unable to return values from function

The foreach surrounding your return line means only the first item will be returned – perhaps that’s what you want? If not, then you should assign $value[2] to a local variable (concatenating if you want a string, or an array perhaps?) and the return the local variable after the loop. function get_admin_menus() { global $submenu, … Read more

current_user_can comma list vs OR (||) list

The current_user_has_role() is not a WordPress core function, on the other hand there’s wc_current_user_has_role( $role ) in WooCommerce where $role is a string, but 3rd party plugins are general off-topic. Creating this function was closed as wontfix in this ticket: https://core.trac.wordpress.org/ticket/22624 where Andrew Nacin summarized it neatly: Roles are merely a grouping of capabilities that … Read more

How to cut off question mark in url with functions.php

Try this, which uses the parse_request hook: (you can add other conditions, e.g. check whether $wp->query_vars[‘name’] is not empty, if you want to) add_action( ‘parse_request’, ‘wpse_400900_parse_request’, 1 ); function wpse_400900_parse_request( $wp ) { // Redirect if the URL ends with a ? like https://example.com? if ( ! empty( $_SERVER[‘REQUEST_URI’] ) && ltrim( $_SERVER[‘REQUEST_URI’], “https://wordpress.stackexchange.com/” ) … Read more

how to get the post ID from wp_insert_post

I’ve just tested your code in a function hooked on wp_body_open and it works: add_action( ‘wp_body_open’, ‘function_test’ ); function function_test() { $tittle=”My new page”; $newPage = array( ‘post_type’ => ‘page’, ‘post_title’ => $tittle, ‘post_status’ => ‘publish’ ); $post_id = wp_insert_post( $newPage); print_r($post_id); } Where do you use this code ?