object-sync-for-salesforce icon indicating copy to clipboard operation
object-sync-for-salesforce copied to clipboard

Create a hook to push a WordPress record by type, ID

Open jonathanstegall opened this issue 7 years ago • 1 comments

Expected behavior

Users should be able to use an action or filter to push an object by code using an ID and object type.

Actual behavior

There is not a filter for this. It does manually happen on the admin UI for users, which calls this function via Ajax:

/**
* Manually push the WordPress object to Salesforce
* This takes either the $_POST array via ajax, or can be directly called with $wordpress_object and $wordpress_id fields
*
* @param string $wordpress_object
* @param int $wordpress_id
*/
public function push_to_salesforce( $wordpress_object = '', $wordpress_id = '' ) {
	$post_data = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING );
	if ( empty( $wordpress_object ) && empty( $wordpress_id ) ) {
		$wordpress_object = isset( $post_data['wordpress_object'] ) ? sanitize_text_field( wp_unslash( $post_data['wordpress_object'] ) ) : '';
		$wordpress_id     = isset( $post_data['wordpress_id'] ) ? absint( $post_data['wordpress_id'] ) : '';
	}
	$data   = $this->wordpress->get_wordpress_object_data( $wordpress_object, $wordpress_id );
	$result = $this->push->manual_object_update( $data, $wordpress_object );

	if ( ! empty( $post_data['wordpress_object'] ) && ! empty( $post_data['wordpress_id'] ) ) {
		wp_send_json_success( $result );
	} else {
		return $result;
	}

}

I think it would be worthwhile to make a hook for that so developers can manually push things.

jonathanstegall avatar Sep 18 '18 15:09 jonathanstegall

Interestingly, this can be done via the REST API in #217. Users could POST to the /wp-json/object-sync-for-salesforce/push/ URL the following parameters in the body: wordpress_id and wordpress_object_type

jonathanstegall avatar Dec 05 '18 20:12 jonathanstegall