Skip to content

Conversation

@phschmanau
Copy link
Contributor

What does this Pull Request do?

This Pull Request introduces a new catch-all filter that allows developers to modify or fully replace the resolved table structure for any WordPress object type inside get_wordpress_table_structure().
This makes it possible to support custom taxonomies (and optional custom post types) without modifying the plugin code directly.

Previously, only a hard-coded set of taxonomy slugs (category, tag, post_tag) was supported.
With this PR, developers can hook into the new filter and return their own table structure for any custom taxonomy or object type while maintaining full backward compatibility.
The plugin’s default behavior remains unchanged if no filter is used.

How do I test this Pull Request?

  1. Ensure that at least one custom taxonomy is registered (e.g. via a theme, plugin, or simple test snippet).
    This is required so the filter can override its table structure.
  2. Register a filter for object_sync_for_salesforce_wordpress_table_structure in a theme, plugin, or mu-plugin.
  3. Inside the filter callback, return a custom table structure for the registered taxonomy slug (e.g. region or canton).
  4. Trigger any plugin functionality that calls get_wordpress_table_structure() with that taxonomy.

Example: Overriding table structure for a custom taxonomy

add_filter( 'object_sync_for_salesforce_wordpress_table_structure', function( $structure, $object_type ) {

    // Custom taxonomies we want to treat like WP terms.
    $custom_taxonomies = [ 'region', 'canton', 'district', 'municipality' ];

    if ( ! in_array( $object_type, $custom_taxonomies, true ) ) {
        return $structure;
    }

    global $wpdb;

    return [
        'object_name'     => 'term',
        'content_methods' => [
            'create' => 'wp_insert_term',
            'read'   => 'get_term_by',
            'update' => 'wp_update_term',
            'delete' => 'wp_delete_term',
            'match'  => 'get_term_by',
        ],
        'meta_methods'    => [
            'create' => 'add_term_meta',
            'read'   => 'get_term_meta',
            'update' => 'update_term_meta',
            'delete' => 'delete_metadata',
            'match'  => 'WP_Term_Query',
        ],
        'content_table'   => $wpdb->prefix . 'terms',
        'id_field'        => 'term_id',
        'meta_table'      => [
            $wpdb->prefix . 'termmeta',
            $wpdb->prefix . 'term_taxonomy',
        ],
        'meta_join_field' => 'term_id',
        'where'           => '',
        'ignore_keys'     => [],
    ];
}, 10, 2 );

@jonathanstegall jonathanstegall added feature Pull request that adds a feature patch pull request that requires a patch release, ex v2.1.2. This is the default for new releases. labels Dec 9, 2025
@jonathanstegall jonathanstegall added this to the v2.2.13 milestone Dec 9, 2025
@jonathanstegall jonathanstegall added for developers Pull request for developer functionality fix needs review A fix is in and it needs further testing and removed feature Pull request that adds a feature labels Dec 9, 2025
@jonathanstegall jonathanstegall merged commit ca8936a into MinnPost:master Dec 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix needs review A fix is in and it needs further testing for developers Pull request for developer functionality patch pull request that requires a patch release, ex v2.1.2. This is the default for new releases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants