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
$this
support 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
- Solutions for generating dynamic javascript / CSS
- Custom single template for a specific category
- How to add a checkbox element to attachments editor with example
- Auto get_header and get_footer on every template?
- Nested comments ignored for max per page in wordpress
- wp_nav_menu sort order?
- Theme Check gives: Required: This theme doesn’t seem to display tags?
- Is it possible to use line break in theme description?
- How does WordPress decide what template to use as frontpage
- get_option function
- Twenty Eleven home page show only excerpt
- Snippet: Use classes instead of inline styles for text alignment
- Make a custom theme translate-ready
- Formatting ?
- Is there an error in get_the_tag_list()?
- Use theme folder instead of plugins_url
- Setting hero/splash section as a blog post
- How to call wp_list_comments() with callback outside the loop
- why adds ‘»’ symbol?
- Infinite Scroll not working in own theme
- How can I exclude specific authors from wp_list_authors
- how to wrap tag in tag html to wordpress menu conversion
- Understanding the WordPress template hierarchy
- How to display the content for given page ID withot the wrapper?
- Develop new theme without affecting the active one
- How to add categories to wp_list_pages()
- Move theme templates to subfolder without losing page associations
- Force a specific template based on the URL
- Manage base theme with version control?
- How to add a download link to a movie from WP media library?
- Is it a bad practice to use switch_to_blog in the frontend?
- WordPress custom post type permalink: website.com/post-name/post-id
- Execute upgrade-theme with coding
- buddypress: how do i make the group description excerpt shorter?
- Can´t access child theme´s scripts dependencies found in parent
- Prefix best practice, should we use framework name or theme name?
- Theme Javascript.php Overwritten Nightly [closed]
- How to specify the “Main Sidebar” for a theme
- How to place HTML tags in content from the_content()?
- Can I get the ID of an inserted / linked image?
- 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?
- Custom theme, contact form 7 & fast secure form doesn’t work
- How to develop a menu like wwe.com?
- Add tags to pages
- Why set a second parameter in the translate function?
- do_shortcode() in twentyeleven theme
- Override plugin option by with a custom theme
- Replace site title with logo when logo is uploaded in customizer using
- 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”
- Running a function on post update with new post meta
- Check if( selected() )
- Modify available templates (in dropdown)
- Difference between “comment_form_default_fields” AND “comment_form_fields”
- using custom page
- Extending custom shortcode to also be called directly from theme PHP pages
- How to track a users last visited page?
- Preview returns 404 in theme [closed]
- Change WordPress Resource URL
- Adding content inside the anchor tags within WordPress main nav
- How to get DB options format without saving? [closed]
- Why I obtain different visualization when I run the website on my local machine and on remote server?
- Open portfolio image in light box
- Let visitors show/hide a type of content
- Related Post Category Filter
- how to add a badge on product based on filter?
- style variations hurt the editing performance
- how to create/register menu items that can be added to menus later
- White screen of death on index.php page 3 and above?
- Best way to declare product variables in woocommerce theme development?
- Adding a button to wp/aution plugin
- Theme does not allow shortcodes
- Get_header raises an 500 internal server error
- What is an alternative to not using child theme to customize a WordPress theme?
- One-Page WordPress Template
- double page title [duplicate]
- TinyMCE strips content while pasting. Possibly a bug
- Tags interfering with next_post_link();
- How to check if a certain theme option settings has already been set
- 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
- Theme now uses require.js and enqueue script no longer works
- Getting all months in one year WordPress Archive
- Fatal error: Call to undefined function the_posts_navigation()
- Return the_content() with custom div class for a subset of posts
- Smooth Scrolling Animation of Image Between Two Containers (Elementor) Using JavaScript and GSAP
- WP Update Messages get cut off during Theme update
- How to create a template for a post in Query Loop block?
- Home.php not working with underscores
- Checkboxes on custom `WP_List_Table` also check select all
- Use PHP variable defined in parent file in included pattern (WordPress Block Theme)