Access the environment of an admin page from another admin page

Ok, this could be achieved this way, probably. add_action(‘add_meta_boxes_my_super_duper_post_type’, ‘get_metabox_global_ajax’, 9999 ); function get_metabox_global_ajax(){ if( isset($_GET[‘mgv’]) && $_GET[‘mgv’] == ‘1’ ){ global $wp_meta_boxes; @error_reporting( 0 ); header( ‘Content-type: application/json’ ); die( json_encode( $wp_meta_boxes )); } } Now, you send a request from your plugin page to post-new.php?post_type=my_super_duper_post_type&mgv=1 through ajax, and use the returned json response … Read more

How to var_dump nav menu items from anywhere?

The items are set up in wp_nav_menu(). There is a useful filter you can use: ‘wp_nav_menu_objects’. It offers the items as $sorted_menu_items and the arguments of the wp_nav_menu() call as $args. From wp-includes/nav-menu-template.php::wp_nav_menu(): $sorted_menu_items = apply_filters( ‘wp_nav_menu_objects’, $sorted_menu_items, $args ); So … hook into this filter, store the data somewhere, return the $sorted_menu_items unchanged and … Read more

Retrieve the template directory URI via global or get_template_directory_uri() every time?

I would stay stick to the function. PHP caches functions for speed and efficiency. In some situations, using a function is faster then using a variable. There are other benefits too – imagine if you changed the name of your variable – you would have to go and update every piece of code where it’s … Read more

How do I pass an argument to my custom walker?

Native walker are triggered with walk() method and are not set up to receive data on creation. You can define custom property and constructor method for this purpose: class plus_walker extends Walker_Nav_Menu { var $refine; function __construct($refine) { $this->refine = $refine; } } //stuff ‘walker’ => new plus_walker(‘review’); After this you can access your custom … Read more

How to set global variable in functions.php

You can turn your snippet into a function that returns the post thumbnail URL of a post: function wpse81577_get_small_thumb_url( $post_id ) { $thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), ‘small’ ); return $thumbSmall[‘0’]; } Usage, supplying the ID of a post: <?php echo wpse81577_get_small_thumb_url( 59 ); ?>

How do I make my function add variables/values to the $post object?

Like any other php object, you can add items to the $post object like so: $post->my_new_val_name=”my new value”; I don’t know exactly what you’re trying to do, but inside a function hooked to the_post, you can assign new values and return the object. function my_func($post) { $post->my_new_val_name=”my new value”; return $post; } add_action( ‘the_post’, ‘my_func’ … Read more

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