As you have noticed already, $this will not work as you expected prior to PHP 5.4. You can read this in the PHP wiki. The reason:
For PHP 5.3
$thissupport for Closures was removed because no consensus could be reached how to implement it in a sane fashion. This RFC describes the possible roads that can be taken to implement it in the next PHP version.
An easy workaround is to simple copy $this up front, then use the new reference/ variable:
$subject = clone $this;
Related Posts:
- Using classes instead of global functions in functions.php
- Using $post->post_name in body id causing error: Trying to get property of non-object
- Getting unexpected warnings from theme options code
- Best way to access variables in template markup
- How to specify the “Main Sidebar” for a theme
- How to i style the elements from the TinyMCE
- Integrate WooCommerce theme with a WordPress theme [closed]
- Automated Footer information
- How do you use WordPress for a website that’s not in a blog format?
- Why wp_nav_menu() doesnt show the proper meny when invoked two consecutive times?
- Change the “Default Avatar” admin option via functions.php
- How to develop a menu like wwe.com?
- Add tags to pages
- Why set a second parameter in the translate function?
- ACF Pro make URL Linked in Custom Template [closed]
- How to escape multiple attribute at once in WordPress?
- Override plugin option by with a custom theme
- Replace site title with logo when logo is uploaded in customizer using
- Can’t use admin_enqueue_scripts or wp_enqueue_script
- How is the `get_sidebar` function meant to be used to call a 2nd sidebar?
- Is WordPress a good option for this…?
- Review site using WordPress
- How to create query to get top 3 sticky/latest posts
- Fatal error: Class ‘ZipArchive’ not found
- Is it possible to determine when user is at “Media > Add New” vs “Post > Add an Image”
- Data Validation in wordpress
- What happens if a theme is no longer supported?
- Running a function on post update with new post meta
- Check if( selected() )
- Localize script not working in ajax
- How to find and remove unnecessary theme scripts? [closed]
- Modify available templates (in dropdown)
- Theme logo metadata into template file
- Is There A WordPress Hook for Accessing Attachments for A Particular Page?
- WP Customazation API doesn’t save the default Value
- Change WordPress Resource URL
- Adding content inside the anchor tags within WordPress main nav
- Setting conditional background image from meta value
- How to Emulate Default Navigation Menu Behaviour in a Custom Theme?
- Sample Theme Options page for Multisite – what to consider
- How to use shortcode inside of shortcode in theme
- Search Form Not Working
- My contact form – I’ve changed the source code but the changes are not being applied
- Theme calling page.php instead of home.php
- Open portfolio image in light box
- Let visitors show/hide a type of content
- WordPress comments title
- How can I run code in functions.php when switch_theme() is called?
- Why do sticky posts show in this menu?
- Dot “.” in option value foobars save options function
- style variations hurt the editing performance
- how to create/register menu items that can be added to menus later
- Strict Folder and File Permissions for WordPress Themes Folder
- WP Gutenberg custom block – generate theme colors from SASS and use them in the inspector and php callback
- How to properly use AWS SES for a contact form?
- No templates for condition page.php Elementor
- Default customizer colors aren’t displayed outside of the preview
- Use instead of for wp_nav_menu()
- Find out the reason that the Styles and scripts in the theme are loading properly in localhost but Not in server after deploying
- Theme does not allow shortcodes
- fetch all post from wp multisite network and sort all the post in descending order on the basis of “Created by ” term
- What is an alternative to not using child theme to customize a WordPress theme?
- More HTML elements variety in visual editor
- How allow users to select the theme color?
- How to generate a rtl.css file for themes?
- change wordpress website logo url [duplicate]
- How can i create my Onepage smoothscrool WordPress theme?
- What is the best practice workflow for new website overhaul and keeping current SEO ranking? [closed]
- hide/show a div in wordpress
- Add a customize control depending wich radio setting is checked
- Providing updates to your WordPress theme
- Create new sidebars trough admin post/page metabox
- How one category can have different fields?
- How to add script properly for certain post?
- How do child themes work?
- Why WordPress gets old templates code instead of the last updated ones
- Mutlisite in wordpress is not working
- How can i create a tag with the template’s name like below, and what is the purpose of using them? [duplicate]
- adding navigation to genesis themes
- Checking conditionals
- add_theme_page is not working
- How to check if a certain theme option settings has already been set
- What causes a theme to be inefficient?
- including post-specific feed without full wp_head()
- Show post thumbnail only if it exists using timthumb
- All post ids are the same after this query but rewind_posts() does not seem to work here?
- How can I tell WP which file to load by default in Appearance > Editor?
- while loop to be continue in next section
- Upgrade to WP 3.2/ and Server to php5 breaks theme? [closed]
- What matters should I care to make my theme SEO friendly? [closed]
- How to resize video lightbox popup in wordpress? [closed]
- How can I get rid of the distance when I’m using list-style-type: none? [closed]
- Extracting Distance from FacetWP Proximity Function to Display in WordPress Template
- Theme now uses require.js and enqueue script no longer works
- Best practice to create required pages
- WP site makes mobile browser crash for high memory usage
- Fatal error: Call to undefined function the_posts_navigation()
- Do core themes normally allow automatic upgrades?
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?
- Full Site Editing, Block Theme, Gutenberg, Site Editor