I desire to understand how to theme wrapper works. I’m want to reveal that I’m not a master in OOP. I know something, but not enough.
Said that, I have some questions:
In this piece of code add_filter('template_include', array('Roots_Wrapping', 'wrap'), 99); what does 'Roots_Wrapping'? It is not a function like 'wrap'…
The Roots_Wrapping::$main_template; invoke the $main_template that it is inside of the Roots_Wrapping class, but where is the instance that invoke that class and activates the __construct(...)? i know that the __construct(...) works only if there is a new instance created…
Is how you specify a class or an instance to resolve the function name. That’s just translated to Roots_Wrapping::wrap() which calls the static wrap function in the Roots_Wrapping class. Without that array syntax it would just look up wrap which doesn’t exist outside of the class.
The answer to this goes back to #1. The wrap function instantiates Roots_Wrapping here https://github.com/roots/roots/blob/master/lib/wrapper.php#L46. Since the class has been instantiated, Roots_Wrapping::$main_template has already been populated. Although note that $main_template is a static variable, meaning you can reference it directly through the class name without an instance of the class.
@Foxaii: yes, I read, but, like I said, I’m not used with OOP, so I would like to have more details for assimilate the OOP coding.
When and how $main_template is populated?
In the wrap() function, how $main stores the value? When the wrap() function is called, through add_filter(), no argument is passed. So, what $main does it for?
I’ve read enough about add_filter and apply_filters, but I don’t understand what does it for this pieace of code: $this->templates = apply_filters('roots_wrap_' . $this->slug, $this->templates);
Here is where it is created a new filter -> roots_wrap_base, but if I comment this line, the load still happens. Also, this roots_wrap_base filter hook is not belong to any others file.