That boilerplate uses autoloading, take advantage of it! I understand it’s a bit overwhelming but with some training you will realize that autoloading and OOP are a superlative productivity boost.
Inside inc/common
create your class (for example, class-commonclass.php
)
<?php
namespace PGC_Signoffs\Inc\Common; \\declare the namespace for autoloading
class CommonClass {
public function commonFunction($a,$b,$c){ //could also be 'public static function'
//do your magic
return $start_date;
}
}
Note: the functions inside CommonClass
could be static, it depends on what you want to do with the class. If it’s just a collection of functions go with static.
Then instance the class inside other classes, for example Admin
:
<?php
namespace PGC_Signoffs\Inc\Rest;
use PGC_Signoffs\Inc\Common\CommonClass; //declare you will be using CommonClass from the Inc\Common namespace
class Rest{
...
public function glider_club_update_signoff( \WP_REST_Request $request) {
$commonClass = new CommonClass();
$date_expire = $commonClass->commonFunction($a,$b,$c);
//or, if you went with a static function:
$date_expire = CommonClass::commonFunction($a,$b,$c);
}
}