Observers - nikonorovsv/wpf GitHub Wiki
Observers is middleware classes to execute your own code before template will be loaded. You can specify your own observers as child for \wpf\app\Observer class. Each of observers needed must to be include in your app.config.json file into observers option. Also you can use the observers included in the framework. They are located in the folder /app/observers. See example:
{
"observers": [
"\\wpf\\app\\observers\\OptionsPagesDefiner",
"\\wpf\\app\\observers\\LocalFieldGroupDefiner",
"\\wpf\\app\\observers\\ConstantsDefiner",
"\\wpf\\app\\observers\\EntityDefiner",
"\\app\\observers\\QuerySetter"
],
}
It's convenient to create observer classes, as in the following example:
namespace app\observers;
use \wpf\app\Observer;
use \wpf\App;
use \WP_Query;
class QuerySetter
extends Observer {
public function doUpdate( App $app ) {
$update = function ( WP_Query $query ) use ( $app ) {
if ( is_admin() || ! $query->is_main_query() ) {
return FALSE;
}
// Your rules...
};
add_action( 'pre_get_posts', $update );
}
}
The code into doUpdate() method will be executed at runtime.