class twoe_vk_gp_back { function __construct() { add_filter('rest_user_query' , array($this, 'showAllUsersInRestApi')); } #включаем отображение всех пользователей в wp-json public function showAllUsersInRestApi($prepared_args, $request = null) { unset($prepared_args['has_published_posts']); return $prepared_args; } } new twoe_vk_gp_back(); ?> class twoe_vk_gp_wp_cron { public $parserOptions; public function __construct() { $this->parserOptions = get_option(twoe_vk_gp::getPluginDefines('prefix').'_parser_options'); #добавляем расписание для крона (время запуска) if (isset($this->parserOptions['parser_time'])) { add_filter('cron_schedules', array($this, 'addSchedules')); } #добавляем крон задачу if (isset($this->parserOptions['parser_status'])) { $this->addTask(); } else { $this->clearTask(); } } #добавляем расписание для крона (время запуска) public function addSchedules($schedules) { $schedules[twoe_vk_gp::getPluginDefines('prefix').'_parser_schedule'] = array( 'interval' => $this->parserOptions['parser_time'], 'display' => twoe_vk_gp::getPluginDefines('prefix').'_parser_schedule' ); return $schedules; } #добавляем задачу крона public function addTask() { add_action(twoe_vk_gp::getPluginDefines('prefix').'_cron_task_hook', array($this, 'task')); if (!wp_next_scheduled(twoe_vk_gp::getPluginDefines('prefix').'_cron_task_hook')) { wp_schedule_event(time(), twoe_vk_gp::getPluginDefines('prefix').'_parser_schedule', twoe_vk_gp::getPluginDefines('prefix').'_cron_task_hook'); } } #удаляем задачу крона public static function clearTask() { if (wp_next_scheduled(twoe_vk_gp::getPluginDefines('prefix').'_cron_task_hook')) { wp_clear_scheduled_hook(twoe_vk_gp::getPluginDefines('prefix').'_cron_task_hook'); } } #задача крона public function task() { $myCurl = curl_init(); curl_setopt_array($myCurl, array( CURLOPT_URL => twoe_vk_gp::getPluginDefines('url') . 'includes/core.php', CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query(array( 'from' => 'Авто режим', 'pluginPrefix' => twoe_vk_gp::getPluginDefines('prefix') )) )); $response = curl_exec($myCurl); curl_close($myCurl); } } new twoe_vk_gp_wp_cron(); ?> class twoe_vk_gp_front { function __construct() { $this->pluginOptions = get_option(twoe_vk_gp::getPluginDefines('prefix').'_options'); add_filter('the_content', array($this, 'appendPostContent')); } public function appendPostContent($content) { if (is_single()) { $postId = get_the_ID(); $prefix = twoe_vk_gp::getPluginDefines('prefix'); $items = array(); if ((isset($this->pluginOptions['post_add_vk_likes_count']))) { $items['likes'] = (!empty(get_post_meta($postId, $prefix.'_vk_post_likes_count', true))) ? get_post_meta($postId, $prefix.'_vk_post_likes_count', true) : 0; } if ((isset($this->pluginOptions['post_add_vk_reposts_count']))) { $items['reposts'] = (!empty(get_post_meta($postId, $prefix.'_vk_post_reposts_count', true))) ? get_post_meta($postId, $prefix.'_vk_post_reposts_count', true) : 0; } if ((isset($this->pluginOptions['post_add_vk_comments_count']))) { $items['comments'] = (!empty(get_post_meta($postId, $prefix.'_vk_post_comments_count', true))) ? get_post_meta($postId, $prefix.'_vk_post_comments_count', true) : 0; } #ссылка на первоисточник if ((isset($this->pluginOptions['post_add_vk_post_link'])) && ($vkPostLink = get_post_meta($postId, $prefix.'_vk_post_link', true))) { $content.= '
'; } #лайки / репосты / комментарии if ($items) { $content .= '