How to fix a “globals” issue to avoid a rejected theme?

If you’re dealing with framework that holds values in a global variable then there isn’t much you can do about it. Here is an example of wrapping the variable in a static getter. if ( ! class_exists( ‘SMOFData’ ) ): class SMOFData { static public function is( $key, $compare ) { $value = static::get( $key … Read more

Will $current_user no longer be global?

The $current_user is still a valid global, however like all globals, you should avoid relying on them. If you need the current user in a function, do this instead: $current_user = wp_get_current_user(); Also be aware that this may return false if no user is logged in on the current request, while the global $current_user may … Read more

WordPress Multisite – global categories

function __add_global_categories( $term_id ) { if ( get_current_blog_id() !== BLOG_ID_CURRENT_SITE || ( !$term = get_term( $term_id, ‘category’ ) ) ) return $term_id; // bail if ( !$term->parent || ( !$parent = get_term( $term->parent, ‘category’ ) ) ) $parent = null; global $wpdb; $blogs = $wpdb->get_col( “SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = ‘{$wpdb->siteid}'” ); foreach … Read more

Change global values from templates

I think you could simplify much of what you are doing just by using the global $_SESSION variable. try something like this: add_action(‘wp_head’, ‘your_session_variable’ ); function your_session_variable(){ session_start(); $gender = isset($_GET[‘gender’]) ? $_GET[‘gender’] : $_SESSION[‘gender’]; $_SESSION[‘gender’] = $gender; } Now to access the session variable from the template make sure to use session_start() before grabbing … Read more

Pass variables from one widget to another widget

You don’t need to make it global. If your include a file from within a functions scope, any variables that you defined in that function (before that point) will be exposed in the included file as well. But because the variable you are talking about represents the state of the footer file inclusion (if I … Read more

Multisite Global Custom Posts

In case anyone comes across this question in the future, I found a plugin that does everything I want. The plugin is Multisite Post Duplicator which is a free plugin available in the WordPress plugin directory. Below are some of the plugin features. Features: Copies all custom fields Copies all related post meta Includes any … Read more