Post Export Filters

The post export feature of the Greyd Plugin allows administrators to export posts from any supported post type and later import them into another site. During the export and subsequent import the plugin exposes a series of WordPress filters that enable developers to intervene in the process. These filters let you adjust the query used to fetch posts, transform meta data, decide how conflicts are resolved, customise dynamic content processing, and even modify which admin screens display export options. This document introduces each filter, grouped by category, and explains how you can use them to extend the behaviour of the post export feature.

For examples on how to use some of these filters, see the Post Export Filter Snippets documentation.

Post Export Filters

greyd_export_post_query_args

Use this filter to modify the query arguments used when exporting multiple posts from a post type. It is typically invoked by the export routine before running get_posts() on the selected post type. You can use it to add tax queries, change ordering, or limit the number of posts exported.

Parameters:

  • array $query_args – The arguments passed to get_posts(). These include parameters such as post_type, posts_per_page and any user‑defined filters.
  • int $post_id – The post ID of the post type definition being exported.
  • array $args – An array of export options, for example whether to export the whole post type.

Returns:

An array of query arguments to be used when fetching posts for export.

Source:

PHP
/**
 * Filter to modify the query arguments before exporting posts from a post type.
 * 
 * This filter allows developers to customize the WordPress query arguments used
 * when exporting multiple posts from a custom post type. It's useful for adding
 * custom filters, ordering, or limiting the posts that get exported.
 * 
 * @filter greyd_export_post_query_args
 * 
 * @param array $query_args  The query arguments for get_posts() function.
 * @param int   $post_id     The post ID of the post type definition being exported.
 * @param array $args        The export arguments including options like 'whole_posttype'.
 * 
 * @return array $query_args Modified query arguments for post export.
 */
$query_args = apply_filters( 'greyd_export_post_query_args', $query_args, $post_id, $args );

greyd_export_post_meta-dynamic_meta

This filter modifies dynamic meta values before they are processed for export. It fires for each meta field that is considered “dynamic”, such as file paths, URLs and HTML content. Developers can hook into this filter to restructure meta data, sanitise values or implement custom export logic for specific fields.

Parameters:

  • mixed $meta_value – The meta value being processed for export.
  • int $post_id – The ID of the post being exported.
  • array $args – Additional export options, such as whether nested meta should be appended.

Returns:

The modified meta value ready for export.

Source:

PHP
/**
 * Filter to modify dynamic meta values before export processing.
 * 
 * This filter allows developers to customize how dynamic meta values are processed
 * during post export, particularly for custom post type fields like files, URLs,
 * and HTML content. It's useful for modifying meta data structure or adding
 * custom export logic for specific field types.
 * 
 * @filter greyd_export_post_meta-dynamic_meta
 * 
 * @param mixed $meta_value  The meta value to be processed and exported.
 * @param int   $post_id     The post ID being exported.
 * @param array $args        Export arguments including options like 'append_nested'.
 * 
 * @return mixed $meta_value Modified meta value ready for export.
 */
$meta_value = apply_filters( 'greyd_export_post_meta-dynamic_meta', $meta_value, $post_id, $args );

Post Import Filters

greyd_import_conflict_actions

When importing posts into a site, this filter is applied to the list of conflict actions before the plugin processes them. Conflict actions describe what should happen when a post with the same global ID already exists on the destination site. Hook into this filter to implement custom resolution strategies or alter the default conflict handling.

Parameters:

  • array $conflict_actions – An associative array of existing posts with conflicts, keyed by post ID.
  • array $posts – An array of posts to be imported, keyed by their IDs.

Returns:

A modified array of conflict actions.

Source:

PHP
/**
 * Filter to modify conflict actions before processing post imports.
 * 
 * This filter allows developers to customize how conflicts between existing posts
 * and posts being imported are handled. It's useful for implementing custom
 * conflict resolution logic or modifying the default conflict handling behavior.
 * 
 * @filter greyd_import_conflict_actions
 * 
 * @param array $conflict_actions   Array of existing posts with conflicts, keyed by post ID.
 * @param array $posts              Array of posts to be imported, keyed by post ID.
 * 
 * @return array $conflict_actions  Modified array of conflict actions.
 */
$conflict_actions = apply_filters( 'greyd_import_conflict_actions', $conflict_actions, $posts );

greyd_import_postarr

This filter allows developers to adjust the array of post parameters before a post is imported. The array is passed to wp_insert_post() to create or update the destination post. By hooking this filter you can add or modify values such as post status, slug or custom fields.

Parameters:

  • array $postarr – An array of post parameters used for wp_insert_post().
  • Preparred_Post $post – The preparred post object containing meta, taxonomy terms and other context.
  • bool $is_first_post – Whether this is the first post in the import batch.

Returns:

The modified array of post parameters.

Source:

PHP
/**
 * Filter to modify the post array before importing a post.
 * 
 * This filter allows developers to customize the post data that will be used
 * when creating or updating posts during import. It's useful for modifying
 * post attributes, adding custom fields, or implementing custom import logic.
 * 
 * @filter greyd_import_postarr
 * 
 * @param array $postarr        Array of post parameters used for wp_insert_post().
 * @param Preparred_Post $post  Preparred post object with meta, taxonomy terms, etc.
 * @param bool $is_first_post   Whether this is the first post of the import batch.
 * 
 * @return array $postarr       Modified array of post parameters for import.
 */
$postarr = apply_filters( 'greyd_import_postarr', $postarr, $post, $is_first_post );

greyd_import_action

This filter determines the import action to be performed for a post when a conflict occurs. The action can be insert, draft, trash or delete, allowing granular control over how existing posts are updated or removed. Use this hook to implement business rules or user prompts for conflict resolution.

Parameters:

  • string $import_action – The action to take (insert, draft, trash or delete).
  • Preparred_Post $post – The post object being imported.
  • int $existing_post_id – The ID of the existing post that conflicts.

Returns:

A string representing the import action to be taken.

Source:

PHP
/**
 * Filter to determine the import action for a post.
 * 
 * This filter allows developers to customize how posts are handled during import,
 * including whether to insert, update, set as draft, trash, or delete existing posts.
 * It's useful for implementing custom import strategies or business logic.
 * 
 * @since 1.7.0
 * @filter greyd_import_action
 * 
 * @param string $import_action    The import action to be taken. ('insert'|'draft'|'trash'|'delete')
 *   @default 'insert'  Insert or update the post if it already exists.
 *   @value   'draft'   Set the post to draft status.
 *   @value   'trash'   Move the post to trash.
 *   @value   'delete'  Delete the post permanently.
 * @param Preparred_Post $post     The post object being imported.
 * @param int $existing_post_id    The ID of the existing post if there's a conflict.
 * 
 * @return string                  The import action to be taken.
 */
$import_action = apply_filters( 'greyd_import_action', $import_action, $post, $existing_post_id );

greyd_import_conflict_action

This filter modifies the conflict action for individual posts during import. It allows you to override the default conflict resolution on a per‑post basis, for example to skip a particular post, replace it or keep both versions.

Parameters:

  • string $conflict_action – The conflict action (replace, skip or keep).
  • Preparred_Post $post – The post object being imported.
  • int $existing_post_id – The ID of the existing post in conflict.

Returns:

A string representing the modified conflict action.

Source:

PHP
/**
 * Filter to modify the conflict action for a specific post during import.
 * 
 * This filter allows developers to customize how conflicts are resolved for individual
 * posts during import. It's useful for implementing custom conflict resolution logic
 * or overriding default conflict handling behavior on a per‑post basis.
 * 
 * @since new
 * @filter greyd_import_conflict_action
 * 
 * @param string $conflict_action    The conflict action to be taken ('replace'|'skip'|'keep').
 * @param Preparred_Post $post       The post object being imported.
 * @param int $existing_post_id      The ID of the existing post if there's a conflict.
 * 
 * @return string                    The modified conflict action to be taken.
 */
$conflict_action = apply_filters( 'greyd_import_conflict_action', $conflict_action, $post, $existing_post_id );

greyd_filter_post_content_before_post_import

Use this filter to modify post content before it is imported into the database. It runs after string replacements have been applied and before the content is saved. You can use it to clean HTML, replace placeholders or apply custom formatting.

Parameters:

  • string $content – The post content after string replacements.
  • int $post_id – The ID of the newly created or updated post.
  • object $post – The original Preparred_Post object.

Returns:

A string containing the modified post content.

Source:

PHP
/**
 * Filter to modify post content before it's imported into the database.
 * 
 * This filter allows developers to customize post content during import,
 * such as cleaning up HTML, replacing placeholders, or applying custom
 * formatting before the content is saved to the database.
 * 
 * @filter greyd_filter_post_content_before_post_import
 * 
 * @param string    $content    The post content after string replacements.
 * @param int       $post_id    The ID of the newly created/updated post.
 * @param object    $post       The original Preparred_Post object.
 * 
 * @return string               The modified post content for import.
 */
$content = apply_filters( 'greyd_filter_post_content_before_post_import', $content, $new_post_id, $post );

greyd_import_post_meta-{{meta_key}}

This dynamic filter name lets you customise specific post meta values before they are imported. Replace {{meta_key}} with the actual meta key you wish to intercept. The filter is invoked for each meta value allowing targeted adjustments to individual fields.

Parameters:

  • mixed $meta_value – The meta value being imported.
  • int $post_id – The ID of the post being imported.
  • object $post – The original Preparred_Post object.

Returns:

The modified meta value for import.

Source:

PHP
/**
 * Filter to modify specific post meta values before import.
 * 
 * This filter allows developers to customize individual post meta values
 * during import. The filter name is dynamic based on the meta key,
 * allowing for targeted modifications of specific meta fields.
 * 
 * @filter greyd_import_post_meta-{{meta_key}}
 * 
 * @param mixed $meta_value  The meta value to be imported.
 * @param int   $post_id     The ID of the post being imported.
 * @param object $post       The original Preparred_Post object.
 * 
 * @return mixed             The modified meta value for import.
 */
$meta_value = apply_filters( 'greyd_import_post_meta-' . $meta_key, $meta_value, $post_id, $post );

greyd_import_post_meta-dynamic_meta

This filter modifies dynamic meta values after the initial import processing. It is useful for post‑import transformations, such as resolving placeholders, processing nested structures or applying custom conversion logic.

Parameters:

  • mixed $meta_value – The meta value after initial import processing.
  • int $post_id – The ID of the post that was imported.

Returns:

The modified meta value ready for final storage.

Source:

PHP
/**
 * Filter to modify dynamic meta values after import processing.
 * 
 * This filter allows developers to customize how dynamic meta values are processed
 * after they've been imported. It's useful for implementing custom logic for
 * handling dynamic post type fields, resolving placeholders, or applying
 * post-import transformations.
 * 
 * @filter greyd_import_post_meta-dynamic_meta
 * 
 * @param mixed $meta_value  The meta value after initial import processing.
 * @param int   $post_id     The ID of the post that was imported.
 * 
 * @return mixed $meta_value  The modified meta value ready for final storage.
 */
$meta_value = apply_filters( 'greyd_import_post_meta-dynamic_meta', $meta_value, $post_id );

greyd_import_post_conflicts

This filter is called before returning the list of conflicting posts to the user. It allows developers to add custom conflict detection logic or remove certain conflicts based on custom criteria.

Parameters:

  • array $conflicts – An array of conflicting posts keyed by post ID.
  • array $posts – The array of posts being imported, keyed by post ID.

Returns:

A modified array of conflicting posts.

Source:

PHP
/**
 * Filter to modify the list of conflicting posts before returning them.
 * 
 * This filter allows developers to customize the list of posts that conflict
 * with posts being imported. It's useful for adding custom conflict detection
 * logic or filtering out certain types of conflicts.
 * 
 * @filter greyd_import_post_conflicts
 * 
 * @param array $conflicts  Array of conflicting posts, keyed by post ID.
 * @param array $posts      Array of posts being imported, keyed by post ID.
 * 
 * @return array            Modified array of conflicting posts.
 */
$conflicts = apply_filters( 'greyd_import_post_conflicts', $conflicts, $posts );

Preparred_Post class filters

greyd_export_post_meta-{{meta_key}}

This dynamic filter name allows you to customise specific meta values during export. Replace {{meta_key}} with the actual meta key to intercept. The filter fires for each meta value of the Preparred_Post object.

Parameters:

  • mixed $meta_value – The meta value to be exported.
  • int $post_id – The ID of the post being exported.
  • array $export_arguments – The export arguments passed to the constructor.

Returns:

The modified meta value for export.

Source:

PHP
/**
 * Filter to modify specific post meta values before export.
 * 
 * This filter allows developers to customize individual post meta values
 * during export. The filter name is dynamic based on the meta key,
 * allowing for targeted modifications of specific meta fields.
 * 
 * @filter greyd_export_post_meta-{{meta_key}}
 * 
 * @param mixed $meta_value      The meta value to be exported.
 * @param int   $post_id        The ID of the post being exported.
 * @param array $export_arguments The export arguments passed to the constructor.
 * 
 * @return mixed                The modified meta value for export.
 */
$meta_value = apply_filters( 'greyd_export_post_meta-' . $meta_key, $meta_value, $post_id, $export_arguments );

greyd_post_export_resolve_menus

After resolving navigation menus during export, this filter allows you to modify the resulting post content. It runs once the plugin has converted navigation blocks to static links. Use it to apply additional formatting or make further changes to the content before it is exported.

Parameters:

  • string $subject – The post content after menu resolution.
  • int $post_id – The ID of the post being exported.
  • object $post – The Preparred_Post object.

Returns:

The modified post content for export.

Source:

PHP
/**
 * Filter to modify the post content after resolving navigation menus.
 * 
 * This filter allows developers to customize post content after navigation
 * links have been converted to static links during export. It's useful for
 * applying additional content modifications or custom formatting.
 * 
 * @filter greyd_post_export_resolve_menus
 * 
 * @param string $subject  The post content after menu resolution.
 * @param int    $post_id  The ID of the post being exported.
 * @param object $post     The Preparred_Post object.
 * 
 * @return string          The modified post content for export.
 */
$post_content = apply_filters( 'greyd_post_export_resolve_menus', $subject, $post_id, $post );

Content pattern filters

greyd_regex_nested_posts

Customise the regular expression patterns used to detect nested posts within content. Hook into this filter to add patterns for custom block types or structures so that the plugin can correctly replace nested posts with placeholders during export.

Parameters:

  • array $patterns – An array of regex pattern arguments for post detection.
  • int $post_id – The ID of the post being exported.
  • WP_Post $post – The WP_Post object being exported.

Returns:

An array of modified regex patterns used for nested post detection.

Source:

PHP
/**
 * Filter to customize regex patterns for finding nested posts in post content.
 * 
 * This filter allows developers to add custom regex patterns for detecting
 * and replacing nested post references in post content during export.
 * It's useful for supporting custom block types or content structures.
 * 
 * @filter greyd_regex_nested_posts
 * 
 * @param array   $patterns     Array of regex pattern arguments for post detection.
 * @param int     $post_id      The WP_Post ID being exported.
 * @param WP_Post $post         The WP_Post Object being exported.
 * 
 * @return array                Modified array of regex patterns for post detection.
 */
$patterns = apply_filters( 'greyd_regex_nested_posts', $patterns, $post_id, $post );

greyd_regex_nested_strings

This filter allows you to define strings in post content that should be replaced with placeholders during export. It is useful for handling site‑specific URLs, paths or other dynamic content that should be normalised in the export file.

Parameters:

  • array $strings – An associative array of strings to be replaced, keyed by placeholder name.
  • string $content – The post content being processed.
  • int $post_id – The ID of the post being exported.

Returns:

A modified array of strings to be replaced.

Source:

PHP
/**
 * Filter to customize string replacement patterns for post content export.
 * 
 * This filter allows developers to add custom string patterns that should
 * be replaced with placeholders during export. It's useful for handling
 * site-specific URLs, paths, or other dynamic content.
 * 
 * @filter greyd_regex_nested_strings
 * 
 * @param array     $strings   Array of strings to be replaced, keyed by placeholder name.
 * @param string    $content   The post content being processed.
 * @param int       $post_id   The ID of the post being exported.
 * 
 * @return string[]            Modified array of strings to be replaced.
 */
$strings = apply_filters( 'greyd_regex_nested_strings', $strings, $content, $post_id );

greyd_regex_nested_terms

Use this filter to customise the regex patterns used for finding nested taxonomy terms in post content. It allows the export process to detect and replace term references for custom content structures.

Parameters:

  • array $patterns – An array of regex pattern arguments for term detection.
  • int $post_id – The ID of the post being exported.
  • WP_Post $post – The WP_Post object being exported.

Returns:

A modified array of regex patterns for term detection.

Source:

PHP
/**
 * Filter to customize regex patterns for finding nested terms in post content.
 * 
 * This filter allows developers to add custom regex patterns for detecting
 * and replacing nested taxonomy term references in post content during export.
 * It's useful for supporting custom term-based content structures.
 * 
 * @filter greyd_regex_nested_terms
 * 
 * @param array   $patterns     Array of regex pattern arguments for term detection.
 * @param int     $post_id      The WP_Post ID being exported.
 * @param WP_Post $post         The WP_Post Object being exported.
 * 
 * @return array                Modified array of regex patterns for term detection.
 */
$patterns = apply_filters( 'greyd_regex_nested_terms', $patterns, $post_id, $post );

greyd_regex_nested_menus

This filter lets you define custom regex patterns for finding nested menus in post content. It is particularly useful when working with custom menu structures or shortcodes that the default export logic does not recognise.

Parameters:

  • array $patterns – An array of regex pattern arguments for menu detection.
  • int $post_id – The ID of the post being exported.
  • WP_Post $post – The WP_Post object being exported.

Returns:

An array of modified regex patterns used for menu detection.

Source:

PHP
/**
 * Filter to customize regex patterns for finding nested menus in post content.
 * 
 * This filter allows developers to add custom regex patterns for detecting
 * and replacing nested menu references in post content during export.
 * It's useful for supporting custom menu structures or shortcodes.
 * 
 * @filter greyd_regex_nested_menus
 * 
 * @param array   $patterns     Array of regex pattern arguments for menu detection.
 * @param int     $post_id      The WP_Post ID being exported.
 * @param WP_Post $post         The WP_Post Object being exported.
 * 
 * @return array                Modified array of regex patterns for menu detection.
 */
$patterns = apply_filters( 'greyd_regex_nested_menus', $patterns, $post_id, $post );

Helper class filters

greyd_export_blacklisted_meta

Use this filter to modify the list of meta keys that should be excluded from export. By default the plugin defines a set of sensitive or site‑specific keys; you can add or remove keys to tailor the export to your requirements.

Parameters:

  • array $blacklisted_meta – An array of meta keys that should be excluded from export.

Returns:

A modified array of meta keys to exclude.

Source:

PHP
/**
 * Filter to customize the list of blacklisted meta keys for export.
 * 
 * This filter allows developers to add or remove meta keys that should
 * be excluded from post exports. It's useful for preventing sensitive
 * or site-specific meta data from being exported.
 * 
 * @filter greyd_export_blacklisted_meta
 * 
 * @param array $blacklisted_meta Array of meta keys to exclude from export.
 * 
 * @return array                   Modified array of blacklisted meta keys.
 */
$blacklisted_meta = apply_filters( 'greyd_export_blacklisted_meta', $blacklisted_meta );

greyd_export_maybe_skip_meta_option

This filter decides whether a specific meta key should be skipped during export. It receives the current skip flag, the meta key and the value. Return true to skip exporting the meta entry or false to include it.

Parameters:

  • bool $skip_meta – Whether to skip this meta entry (default false).
  • string $meta_key – The meta key being evaluated.
  • mixed $meta_value – The meta value being evaluated.

Returns:

A boolean indicating whether to skip the meta entry.

Source:

PHP
/**
 * Filter to determine whether a specific meta option should be skipped during export.
 * 
 * This filter allows developers to implement custom logic for determining
 * whether specific meta keys or values should be excluded from export.
 * It's useful for implementing site-specific export rules or business logic.
 * 
 * @filter greyd_export_maybe_skip_meta_option
 * 
 * @param bool   $skip_meta    Whether to skip the meta option (default: false).
 * @param string $meta_key     The meta key being evaluated.
 * @param mixed  $meta_value   The meta value being evaluated.
 * 
 * @return bool                Whether to skip the meta option.
 */
$skip_meta = apply_filters( 'greyd_export_maybe_skip_meta_option', false, $meta_key, $meta_value );

Admin class filters

greyd_post_export_is_current_screen_supported

This filter determines whether the current admin screen should display post export/import options. Hook into it to add support for custom post type screens or change which screens the export feature appears on.

Parameters:

  • bool $supported – Whether the current screen supports export/import.
  • object $screen – The current WP_Screen object.

Returns:

A boolean indicating whether the current screen supports export/import.

Source:

PHP
/**
 * Filter to customize whether the current screen supports post export/import functionality.
 * 
 * This filter allows developers to extend or modify the logic that determines
 * which admin screens should display post export/import options. It's useful
 * for adding support to custom post type screens or implementing custom
 * screen detection logic.
 * 
 * @filter greyd_post_export_is_current_screen_supported
 * 
 * @param bool  $supported Whether the current screen supports export/import.
 * @param object $screen   The current WP_Screen object.
 * 
 * @return bool           Whether the current screen supports export/import.
 */
$supported = apply_filters( 'greyd_post_export_is_current_screen_supported', $supported, $screen );