kp4coder / sync-post-with-other-site

WordPress Plugin
1 stars 1 forks source link

Feature Suggestion: Filter to modify arguments in sps_remote_post() #2

Open coaten opened 3 weeks ago

coaten commented 3 weeks ago

The $args variable in sps_remote_post() controls the data being synced between sites.

        function sps_remote_post( $action, $args = array() ) {
            do_action( 'spsp_before_send_data', $args );
            $args['sps_action'] = $action;
            $url = $args['sps']['host_name']."/wp-json/sps/v1/data"; 
            $return = wp_remote_post( $url, array( 'body' => $args ));
            return $return;
        }

By adding "$args = apply_filters( 'spsp_before_send_data_args', $args );" at the beginning of the funciton as follows:

        function sps_remote_post( $action, $args = array() ) {
            do_action( 'spsp_before_send_data', $args );
            $args['sps_action'] = $action;
            $args = apply_filters( 'spsp_before_send_data_args', $args );
            $url = $args['sps']['host_name']."/wp-json/sps/v1/data"; 
            $return = wp_remote_post( $url, array( 'body' => $args ));
            return $return;
        }

We are able to filter the syncing arguments to allow specific post meta values to be included or excluded from post syncing. This is useful in situations like ours, where we want to sync LearnDash course and lesson posts but do NOT want to sync various meta keys that associate lessons to courses by post ID, since those post IDs are different on each sync target.

kp4coder commented 2 weeks ago

Thank you for your additional suggestion regarding the filter to modify arguments in sps_remote_post. I appreciate your attention to detail and your willingness to contribute to the plugin's improvement.

I'll be considering this enhancement for the next update as well. Your input is invaluable in making the plugin more versatile for its users.

If you have any other ideas or feedback, feel free to share them.