The $GLOBALS
array can be used instead:
$GLOBALS['a'] = 'localhost'; function body(){ echo $GLOBALS['a']; }
From the Manual:
An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.
If you have a set of functions that need some common variables, a class with properties may be a good choice instead of a global:
class MyTest { protected $a; public function __construct($a) { $this->a = $a; } public function head() { echo $this->a; } public function footer() { echo $this->a; } } $a = 'localhost'; $obj = new MyTest($a);
Related Posts:
- Nginx FastCGI_Cache Vs PHP Caching
- $wpdb->delete column values IN ARRAY()?
- Remove Woocommerce product link
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- How To Customize Position of »add to cart« of WooCommerce on Product Page [closed]
- How to Remove Parents Category Permalink from Posts
- Sort posts from multiple sites by date
- OOP Plugin Development. Including external object
- Authenticating to WordPress, using my own authentication two-factor system
- Dynamically loaded Theme components based on Customizer Settings values : changes not appearing in Customizer preview – (Workaround found)
- Change Width of Featured Image Thumbnail on Add/Edit Post Page
- How can I default to all WordPress roles when parameter is not included in shortcode?
- Create table in database when activating plugin
- Implement a multi-value input field where the number of entries is not limited
- Getting my head round WordPress filter
- Export WordPress Table to CSV from page
- Need to turn this php into WP shortcode
- Check if user is logged in when clicking certain links on certain pages
- WordPress – query 5 posts with a specific post in top
- How to speed up a wordpress function with multiple loops?
- wp_editor and WPAlchemy messes up tags when updating
- WordPress Player Profiles + PHP
- Trying to regain access to a wordpress based website
- WP_cron won’t trigger my action
- An extra ‘ is displayed in the title
- woocommerce registration form with klaviyo(don’t work with current user)
- How to get a list of all possible values of a specific user meta key?
- Use object in template part
- Menu — How to add “current-menu-grand-ancestor” css class
- Customizer – Prefix Class Extension
- Create onClick Event to Re-load a Widget
- Output Buffering – Everything between wp_head and wp_print_footer_scripts?
- functions.php is being included twice, creating PHP fatal errors
- Menu Limitations
- Removing “wpautop” (auto tags) only on certain pages?
- selected option if current category is the value
- Alert Bar section within WP loop is displaying even though there are no posts
- Load wordpress content in other domain
- Search Query: how to construct a search string from two select elements?
- Custom Menus: dynamic highlighting problem with custom home link
- Is it possible to retrieve all posts with a certain value for metadata?
- How to set up a If is_singular statement?
- How to hook code to show after the_content?
- Run a code only on theme activation only during first activation
- How to avoid duplicates when creating recent network posts
- Creating WordPress Shortcode with Variable
- Catchable fatal error: Object of class stdClass could not be converted to string
- Get title attribute from galleries
- variable value disappears in a second loop
- unknown issue in ‘header.php’ preventing theme from displaying fully
- Referencing Images in javascript to display on wordpress page
- Add meta tags to a custom header
- Ajax filter button display all posts
- Check If Post Was Published More Than 6 Months Ago Using get_the_date
- Function sanitize_title() does not appear to be working
- random display categories – change url
- Nav menu from plugin to theme
- Generate responsive post thumbnails of same size
- How to prevent a function from running based on host (ie web vs local)?
- Change out put of the_post_thumbnail in PHP
- Styling an “active” link outside of WordPress default menu
- WordPress permalink issue
- Any way to hide a blog posts text if it’s longer than let’s say 300 characters
- Delete images from media library when user deletes an image from ACF Gallery
- Array data not saving to specified sections. How to make seting independantly?
- How to get woocommerce orders with get_posts method in a shortcode
- Integrate otp in my custom singup form
- Change category thumbnail size
- how to make wordpress user submit form once?
- Update PHP version of WordPress (internal hosting)
- Unable to retrieve get_author_posts_url
- Multiple Tag Filtering
- Polylang and template files
- Need to show 7 posts from actual date
- How to reload a php script, using AJAX and jQuery
- Make wp_editor required
- I need to edit a widget, with no dashboard access
- Add custom ID attribute to all woocommerce products on archive pages
- problem in using wpdb->prepare and a string placeholder
- Custom content using in_category
- Get the total Author Favorited posts
- Need help with PHP functions
- WordPress WPDB::insert 13th param is always blank (only if format)
- When using shortcode, content stops generating after the_content
- MySQL query in WordPress with AJAX
- enumerating custom taxonomies?
- How do you detect if a specific word is at the end of a the_title()
- WordPress styling recent post
- featured post as div background
- Combining fancybox with multiple thumbnail plugin
- How to display thumbnail if post is assigned one otherwise not
- Highlight posts currently being edited on multiple editor site?
- How to check “From Email” via WordPress before an email is sent
- WordPress Plugin Receive a Link
- Php echo into tag
- Add specific phrase after every product title including the discounted price? [closed]
- Remove Unused Menu Locations
- How do I change the Go To Categories link in the term_updated_messages
- How to use url and amin-ajax.php
- Custom plugin doesn’t show in admin menu – when code added, displays an empty page