AV
Size: a a a
AV
AV
AL
class WebacodersServiceLikes
{
private $db;
public function __construct()
{
$this->db = $GLOBALS['wpdb'];
$this->__init();
}
public function __createLikesTable()
{
$db = $this->db;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$table_name = $db->get_blog_prefix() . 'likes';
$charset_collate = "DEFAULT CHARACTER SET {$db->charset} COLLATE {$db->collate}";
$sql = "CREATE TABLE {$table_name} (
id bigint(20) unsigned NOT NULL auto_increment,
post_id INT NOT NULL default '',
ip TEXT NOT NULL default '',
like_count INT NOT NULL default '',
PRIMARY KEY (id),
)
{$charset_collate};";
dbDelta($sql);
}
function __likes_settings_menu_page(){
add_menu_page(
'Настройки Сервиса лайков', // тайтл страницы
'Лайки', // текст ссылки в меню
'manage_options', // права пользователя, необходимые для доступа к странице
'likes_settings', // ярлык страницы
'front_likes_settings', // функция, которая выводит содержимое страницы
'dashicons-heart', // иконка, в данном случае из Dashicons
4 // позиция в меню
);
}
public function __init()
{
try{
$db = $this->db;
$table_name = $db->get_blog_prefix() . 'options';
$data = [
'option_id' => null,
'option_name' => 'active_likes_service',
'option_value' => 0,
'autoload' => 'yes',
];
$query = $db->insert($table_name, $data);
if($query == 1){
return true;
}
}catch (Exception $e){
echo "Ошибка инициализации сервиса".'<br>'.$e->getMessage();
}
}
public function __checkStatusService(){
$val = get_option('active_likes_service');
return $val;
}
public function start(){
$status = boolval($this->__checkStatusService());
if($status){
return "Сервис уже запущен";
}else{
$this->__init();
if($this->__init()){
return "Сервис успешно активирован";
}else{
return $this->__init();
}
}
}
public function activate(){
$status = boolval($this->__checkStatusService());
if($status){
return "Сервис уже активирован";
}else{
try{
$this->__init();
add_action('admin_menu', '__likes_settings_menu_page', 4); //вот тут вопрос... если я вызываю action из своего метода, я могу передать ему $this->____likes_settings_menu_page или нет
}catch (Exception $e){
echo "Ошибка активации сервиса".'<br>'.$e->getMessage();
}
}
}
}
АП
AL
АП
AL
AL
АП
AL
AG
КЗ
КЗ
IO
КЗ
IO
КЗ
ОТ
ОТ