How to get submenu of admin menu?

You can use the global variable $submenu. Example to list the child menu of parent post menu:- function admin_init_callback() { global $submenu; $sumenu_list = $submenu[‘edit.php’]; var_dump($sumenu_list); //array of submenu } add_action(‘admin_init’, ‘admin_init_callback’, 999); Profi660 EDIT: Not needed to be used with admin_init hook. I used this in my plugin page and worked very well.

WP user agent returns random variables

You can examine wp-includes/vars.php for specific logic which implements sniffing for these globals in WordPress. In a nutshell the checks are very basic, especially considering user agent sniffing is inherently a mess. If you need a more reliable implementation you would have to get one elsewhere (or code it yourself). That or use different technique … Read more

Recommendations on accessing current user data in WordPress

You can use wp_get_current_user() instead of using the $current_user global. $my_current_user = wp_get_current_user(); if ( $my_current_user->display_name ) { echo ‘<p>Welcome ‘ . $my_current_user->display_name . ‘</p>’; } Note that I used $my_current_user instead of $current_user as a variable name, because you can run into trouble if you use the global variable’s name.

Why is overwriting $GLOBALS killing the_content()?

Template tags like the_content() and the_title() are dependent on the global $post variable ($GLOBALS[‘post’]). See the source code for get_post(), which get_the_title(), for example, uses to get the current post so it can get its title: function get_post( $post = null, $output = OBJECT, $filter=”raw” ) { if ( empty( $post ) && isset( $GLOBALS[‘post’] … Read more

How does WordPress make its functions globally available?

Themes and plugins are just files that are loaded alongside all the other WordPress files that contain its functions, and those are all loaded whenever WordPress is run. So there’s no special trick or anything weird going on. WordPress just loads the files that contain these functions before it loads themes and plugins. Keep in … Read more

What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?

filter_input is the proper way to go. If it doesn’t return anything valid, it will return null: $myvar = filter_input( INPUT_POST, ‘something’, FILTER_SANITIZE_STRING ); if ( empty( $myvar ) ) { // Do whatever you would have done for ! isset( $_POST[‘something’] ) } // Use $myvar filter_input won’t throw any notices if the requested … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)