diff --git a/includes/class-main.php b/includes/class-main.php index e16c02b..2fcadfb 100644 --- a/includes/class-main.php +++ b/includes/class-main.php @@ -82,11 +82,57 @@ private function hooks() { add_action( 'template_redirect', array( $this, 'send_headers_for_aio_seo_pack' ), 20 ); add_action( 'pre_get_posts', array( $this, 'alter_query' ) ); add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 ); + add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) ); + add_action( 'save_post', array( $this, 'save_meta_box' ) ); register_activation_hook( MIHDAN_MAILRU_PULSE_FEED_FILE, array( $this, 'on_activate' ) ); register_deactivation_hook( MIHDAN_MAILRU_PULSE_FEED_FILE, array( $this, 'on_deactivate' ) ); } + /** + * Add settings metabox for posts. + */ + public function add_meta_box() { + add_meta_box( + $this->slug, + __( 'Pulse Main.ru', 'mihdan-mailru-pulse-feed' ), + [ $this, 'render_meta_box' ], + $this->post_type, + 'side', + 'high' + ); + } + + /** + * Render settings metabox for posts. + */ + public function render_meta_box() { + $exclude = (bool) get_post_meta( get_the_ID(), $this->slug . '_exclude', true ); + ?> + + slug . '_exclude' ] ) ) { + update_post_meta( $post_id, $this->slug . '_exclude', 1 ); + } else { + delete_post_meta( $post_id, $this->slug . '_exclude' ); + } + } + /** * Add plugin action links * @@ -130,6 +176,17 @@ public function alter_query( \WP_Query $wp_query ) { // Указываем направление сортировки. $wp_query->set( 'order', $this->wposa_obj->get_option( 'order', 'feed', 'DESC' ) ); + + // Получаем текущие мета запросы. + $meta_query = $wp_query->get( 'meta_query', array() ); + + // Добавляем исключения. + $meta_query[] = array( + 'key' => $this->slug . '_exclude', + 'compare' => 'NOT EXISTS', + ); + // Исключаем записи с галочкой в админке + $wp_query->set( 'meta_query', $meta_query ); } } diff --git a/mihdan-mailru-pulse-feed.php b/mihdan-mailru-pulse-feed.php index c356ce6..162edf8 100644 --- a/mihdan-mailru-pulse-feed.php +++ b/mihdan-mailru-pulse-feed.php @@ -9,8 +9,8 @@ * Author URI: https://www.kobzarev.com/ * Requires at least: 4.6 * Tested up to: 5.3 - * Version: 0.1.3 - * Stable tag: 0.1.3 + * Version: 0.1.4 + * Stable tag: 0.1.4 * * Text Domain: mihdan-mailru-pulse-feed * Domain Path: /languages/ @@ -26,7 +26,7 @@ exit; // Exit if accessed directly. } -define( 'MIHDAN_MAILRU_PULSE_FEED_VERSION', '0.1.3' ); +define( 'MIHDAN_MAILRU_PULSE_FEED_VERSION', '0.1.4' ); define( 'MIHDAN_MAILRU_PULSE_FEED_PATH', __DIR__ ); define( 'MIHDAN_MAILRU_PULSE_FEED_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) ); define( 'MIHDAN_MAILRU_PULSE_FEED_FILE', __FILE__ ); diff --git a/readme.txt b/readme.txt index c49bdcc..3da779e 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: mihdan Tags: mailru, pulse, feed, seo, seo-friendly Requires at least: 4.6 Tested up to: 5.3 -Stable tag: 0.1.3 +Stable tag: 0.1.4 Requires PHP: 5.6.20 WordPress плагин, формирующий ленту для новой рекомендательной системы Пульс от компании Mail.ru. @@ -58,6 +58,10 @@ add_filter( == Changelog == += 0.1.4 (27.12.2019) = +* Ability to exclude posts from feed +* Ability to exclude categories and tags from feed + = 0.1.3 (27.12.2019) = * Added settings for feed source * Added new hook `mihdan_mailru_pulse_feed_head`