'slm_activate', 'secret_key' => twoe_vk_gp::getPluginDefines('act_secret_key'), 'license_key' => $lk, 'registered_domain' => $_SERVER['SERVER_NAME'], 'item_reference' => urlencode(twoe_vk_gp::getPluginDefines('prefix')) ); $query = esc_url_raw(add_query_arg($api_params, twoe_vk_gp::getPluginDefines('act_server_url'))); $response = wp_remote_get($query, array( 'timeout' => 20, 'sslverify' => false )); self::checkAct($lk); } public static function checkAct($lk) { if (!$lk) { self::setLocalAct(0); return false; } $api_params = array( 'slm_action' => 'slm_check', 'secret_key' => twoe_vk_gp::getPluginDefines('act_secret_key'), 'license_key' => $lk, 'item_reference' => urlencode(twoe_vk_gp::getPluginDefines('prefix')) ); $response = wp_remote_get(add_query_arg($api_params, twoe_vk_gp::getPluginDefines('act_server_url')), array( 'timeout' => 20, 'sslverify' => false )); $lkData = json_decode(wp_remote_retrieve_body($response)); if (!$lkData) { self::setLocalAct(0); return false; } if ((!isset($lkData->status)) || $lkData->status != 'active') { self::setLocalAct(0); return false; } if (!$registeredDomains = $lkData->registered_domains) { self::setLocalAct(0); return false; } $registeredDomainsArr = array(); foreach ($registeredDomains as $registeredDomain) { $registeredDomainsArr[] = $registeredDomain->registered_domain; } if (!in_array($_SERVER['SERVER_NAME'], $registeredDomainsArr)) { self::setLocalAct(0); return false; } self::setLocalAct(1); } public static function setLocalAct($status) { $data = array( 'status' => $status, 'domain' => $_SERVER['SERVER_NAME'] ); update_option(twoe_vk_gp::getPluginDefines('prefix').'_activation', $data); } public static function getActStatus() { if (!$actStatus = get_option(twoe_vk_gp::getPluginDefines('prefix').'_activation')) { return false; } if ($actStatus['domain'] != $_SERVER['SERVER_NAME']) { return false; } if ($actStatus['status'] != 1) { return false; } return true; } } new twoe_vk_gp_act(); ?> 'POST', 'callback' => array($this, 'restApiSetGroupStatus'), 'args' => array( 'id' => array( 'validate_callback' => function($param, $request, $key) { return is_numeric($param); } )))); }); } public function addPostTypes() { #events $labels = array( 'name' => 'VK группы', 'singular_name' => 'VK группу', 'add_new' => 'Добавить VK группу', 'add_new_item' => 'Добавить новую VK группу', 'edit_item' => 'Редактировать VK группу', 'new_item' => 'Новая VK группа', 'all_items' => 'Все VK группы', 'view_item' => 'Просмотр VK группы', 'search_items' => 'Поиск VK групп', 'not_found' => 'VK Группы не найдены', 'not_found_in_trash' => 'В корзине нет ни одной VK группы', 'menu_name' => twoe_vk_gp::getPluginDefines('name') ); $args = array( 'labels' => $labels, 'public' => false, 'show_ui' => true, 'has_archive' => false, 'exclude_from_search' => true, 'menu_position' => -1, 'menu_icon' => 'dashicons-format-quote', 'exclude_from_search' => true, 'show_in_rest' => true, 'rest_base' => twoe_vk_gp::getPluginDefines('prefix'), 'rest_controller_class' => 'WP_REST_Posts_Controller', 'supports' => array( 'title', ) ); register_post_type(twoe_vk_gp::getPluginDefines('prefix'), $args); } public function restApiField($data, $post, $request) { $data->data['status'] = $post->status; $data->data['type'] = $post->type; $data->data['vk_group_id'] = $post->vk_group_id; $data->data['to_category'] = $post->to_category; return $data; } #метод rest-api: включение/выключения парсинга группы public function restApiSetGroupStatus($request) { $data = array(); $id = $request->get_param('id'); $value = $request->get_param('value'); if (!isset($id) || !isset($value)) { return new WP_Error('error', 'Missing required parameters', array('status' => 200)); } update_post_meta($id, 'status', $value); $data[] = array( "result" => "ok" ); return new WP_REST_Response($data, 200); } public function hideAddNewMenuItem() { global $submenu; unset($submenu['edit.php?post_type='.twoe_vk_gp::getPluginDefines('prefix')][10]); } } new twoe_vk_gp_post_type(); ?> addColumns(); $this->columnsContent(); } #создаём metabox public function addMetabox() { add_meta_box(twoe_vk_gp::getPluginDefines('prefix').'_metabox', 'Настройки VK группы / сообщества / страницы', array($this, 'addContentToMetabox'), twoe_vk_gp::getPluginDefines('prefix'), 'normal', 'high'); } #html разметка public function addContentToMetabox() { global $post; ?>