我已经有一个名为People
在我的插件中。
PHP人员类
namespace MyPlugin\\Common;
class People{
public $people_id;
public $first_name;
public $last_name;
public function __construct( $data ){
$this->people_id = $data["people_id"];
$this->first_name = $data["first_name"];
$this->last_name = $data["last_name"];
}
public function save(){
global $wpdb;
$data = array(
"first_name" => $this->first_name,
"last_name" => $this->last_name
);
$wpdb->insert( $wpdb->prefix . PLUGIN_PREFIX . \'people\', $data );
return $wpdb->insert_id;
}
}
我想在激活加载项时,
People
使用属性作为数组进行了改进,以获取/设置更多信息,如以下结果:
带有加载项激活的PHP People类
namespace MyPlugin\\Common;
class People{
public $people_id;
public $first_name;
public $last_name;
public $options = array(); //<-- add an array
public function __construct( $data ){
$this->people_id = $data["people_id"];
$this->first_name = $data["first_name"];
$this->last_name = $data["last_name"];
$this->options = $data[\'options\']; //<-- set more information
}
//Override the save function to save $this->options
/* magic method set */
public function __set($name, $value) {
if (isset($this->data[$name])) $this->data[$name] = $value;
}
/* magic method get */
public function __get($name) {
if (isset($this->data[$name])) return $this->data[$name];
else return false;
}
}
有没有办法用钩子函数或类似的东西来实现这一点?