Code Duplication    Length = 31-32 lines in 2 locations

includes/class-sensei-utils.php 2 locations

@@ 2017-2048 (lines=32) @@
2014
     *
2015
     * @return mixed $user_data_value
2016
     */
2017
    public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
2018
2019
        $user_data_value = true;
2020
2021
        if( ! ( $user_id > 0 ) ){
2022
            $user_id = get_current_user_id();
2023
        }
2024
2025
        $supported_post_types = array( 'course', 'lesson' );
2026
        $post_type = get_post_type( $post_id );
2027
        if( empty( $post_id ) || empty( $data_key )
2028
            || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2029
            || ! get_userdata( $user_id )
2030
            || !in_array( $post_type, $supported_post_types )  ){
2031
2032
            return false;
2033
        }
2034
2035
        // check if there and existing Sensei status on this post type if not create it
2036
        // and get the  activity ID
2037
        $status_function = 'user_'.$post_type.'_status';
2038
        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2039
        if( ! isset( $sensei_user_status->comment_ID ) ){
2040
            return false;
2041
        }
2042
2043
        $sensei_user_activity_id = $sensei_user_status->comment_ID;
2044
        $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
2045
2046
        return $user_data_value;
2047
2048
    }// end get_user_data
2049
2050
    /**
2051
     * Delete the Sensei user data for the given key, Sensei post type and user combination.
@@ 2059-2089 (lines=31) @@
2056
     *
2057
     * @return bool $deleted
2058
     */
2059
    public static function delete_user_data( $data_key, $post_id , $user_id ){
2060
        $deleted = true;
2061
2062
        if( ! ( $user_id > 0 ) ){
2063
            $user_id = get_current_user_id();
2064
        }
2065
2066
        $supported_post_types = array( 'course', 'lesson' );
2067
        $post_type = get_post_type( $post_id );
2068
        if( empty( $post_id ) || empty( $data_key )
2069
            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2070
            || ! get_userdata( $user_id )
2071
            || !in_array( $post_type, $supported_post_types )  ){
2072
2073
            return false;
2074
        }
2075
2076
        // check if there and existing Sensei status on this post type if not create it
2077
        // and get the  activity ID
2078
        $status_function = 'user_'.$post_type.'_status';
2079
        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2080
        if( ! isset( $sensei_user_status->comment_ID ) ){
2081
            return false;
2082
        }
2083
2084
        $sensei_user_activity_id = $sensei_user_status->comment_ID;
2085
        $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
2086
2087
        return $deleted;
2088
2089
    }// end delete_user_data
2090
2091
2092
    /**