diff --git a/Config/Config.php b/Config/Config.php index 7d57010..e8e3430 100644 --- a/Config/Config.php +++ b/Config/Config.php @@ -144,6 +144,6 @@ public function allowedPostTypes() ); } - return $allowedPostTypes; + return \apply_filters('swiftype_allowed_post_types', $allowedPostTypes); } } diff --git a/Document/Indexer.php b/Document/Indexer.php index a2f3789..64026f8 100644 --- a/Document/Indexer.php +++ b/Document/Indexer.php @@ -16,6 +16,11 @@ class Indexer extends AbstractSwiftypeComponent */ private $documentMapper; + /** + * @var string[] + */ + private static $FORBIDDEN_POST_TYPES = ['attachment']; + /** * Constructor. */ @@ -23,9 +28,22 @@ public function __construct() { parent::__construct(); $this->documentMapper = new Mapper(); + \add_filter('swiftype_allowed_post_types', [$this, 'filterAllowedPostType']); \add_action('swiftype_engine_loaded', [$this, 'installHooks']); } + /** + * Filter out forbiden post types fron indexing. + * + * @param string[] $allowedPostTypes + * + * @return string[] + */ + public function filterAllowedPostType($allowedPostTypes) + { + return \array_diff($allowedPostTypes, self::$FORBIDDEN_POST_TYPES); + } + /** * Install hooks only when the engine is created (swiftype_engine_loaded). */ @@ -44,8 +62,8 @@ public function installHooks() \add_action('trashed_post', [$this, 'handleTrashedPost']); - add_action('swiftype_batch_post_index', [$this, 'handlePostBatchIndex']); - add_action('swiftype_batch_post_delete', [$this, 'handlePostBatchDelete']); + \add_action('swiftype_batch_post_index', [$this, 'handlePostBatchIndex']); + \add_action('swiftype_batch_post_delete', [$this, 'handlePostBatchDelete']); } }