• Resolved justanothercoder

    (@justanothercoder)


    Hello, I’m hoping for a bit of direction regarding the addobject/addfield hooks in the plugin.

    Right now I have custom table in wordpress. with 2 fields. I have the correspondign object in SF.

    my_table
    field_a | field_b

    I added the object to the wordpress object drop down. Which works fine:

    
    add_filter( 'object_sync_for_salesforce_add_more_wordpress_types', 'add_more_types', 10, 1 );
    function add_more_types( $more_types ) {
    			$more_types = array( 'my_table' );
    			// or $more_types[] = 'foo';
    			return $more_types;
    }
    

    however. I cannot seem to get the field list to filter:

    
    add_filter( 'object_sync_for_salesforce_wordpress_object_fields', 'add_field', 10, 2 );
    function add_field( $object_fields, $wordpress_object ) {
    			$object_fields[] = array(
    				'key' => 'field_a',
    				'table' => 'my_table',
    				'methods' => array (
    					'create' => 'arc_sub_create',
    					'read' => 'arc_sub_read',
    					'update' => 'arc_sub_update',
    					'delete' => 'arc_sub_delete'
    				)
    			);
    			return $object_fields;
    }
    

    Any direction is greatly appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter justanothercoder

    (@justanothercoder)

    Just to clarify, I am not seeing the field (field_a) that I added in the wordpress fields select list when attampting to add a field mapping. Instead I see a bunch of fields for a different object (User I think)

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    @justanothercoder I realize I documented this hook incorrectly and didn’t realize it. Many thanks for helping catch this. I’ll release a fix for this shortly in the plugin, but in the meantime here’s the correct code the hook expects:

    
    function add_field( $object_fields, $wordpress_object ) {
    		$object_fields['data'][] = array(
    			'key' => 'field_a',
    			'table' => 'my_table',
    			'methods' => array(
    				'create' => 'arc_sub_create',
    				'read' => 'arc_sub_read',
    				'update' => 'arc_sub_update',
    				'delete' => 'arc_sub_delete',
    			),
    		);
    		return $object_fields;
    }
    

    So it is really just about having the [‘data’] array as the location of the new field. This is commented correctly in the file classes/wordpress.php (about line 300), but as I say it is documented incorrectly in the plugin’s documentation.

    Oh, and also, by default the plugin assumes that a new object is a custom post type, so it starts with the default fields for a post object.

    Thanks again.

    Thread Starter justanothercoder

    (@justanothercoder)

    excellent! Many thanks for the speedy response.

    Plugin Author Jonathan Stegall

    (@jonathanstegall)

    @justanothercoder great! I’ll mark this as resolved, but you can re-open if that is not the case.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to add a custom wordpress object’ is closed to new replies.