get_comment_type example


    public function update_item( $request ) {
        $comment = $this->get_comment( $request['id'] );
        if ( is_wp_error( $comment ) ) {
            return $comment;
        }

        $id = $comment->comment_ID;

        if ( isset( $request['type'] ) && get_comment_type( $id ) !== $request['type'] ) {
            return new WP_Error(
                'rest_comment_invalid_type',
                __( 'Sorry, you are not allowed to change the comment type.' ),
                array( 'status' => 404 )
            );
        }

        $prepared_args = $this->prepare_item_for_database( $request );

        if ( is_wp_error( $prepared_args ) ) {
            return $prepared_args;
        }
 else {
            // Email address.             $email = $id_or_email;
        }
    } elseif ( $id_or_email instanceof WP_User ) {
        // User object.         $user = $id_or_email;
    } elseif ( $id_or_email instanceof WP_Post ) {
        // Post object.         $user = get_user_by( 'id', (int) $id_or_email->post_author );
    } elseif ( $id_or_email instanceof WP_Comment ) {
        if ( ! is_avatar_comment_type( get_comment_type( $id_or_email ) ) ) {
            $args['url'] = false;
            /** This filter is documented in wp-includes/link-template.php */
            return apply_filters( 'get_avatar_data', $args$id_or_email );
        }

        if ( ! empty( $id_or_email->user_id ) ) {
            $user = get_user_by( 'id', (int) $id_or_email->user_id );
        }
        if ( ( ! $user || is_wp_error( $user ) ) && ! empty( $id_or_email->comment_author_email ) ) {
            $email = $id_or_email->comment_author_email;
        }
    }

function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
    if ( false === $commenttxt ) {
        $commenttxt = _x( 'Comment', 'noun' );
    }
    if ( false === $trackbacktxt ) {
        $trackbacktxt = __( 'Trackback' );
    }
    if ( false === $pingbacktxt ) {
        $pingbacktxt = __( 'Pingback' );
    }
    $type = get_comment_type();
    switch ( $type ) {
        case 'trackback':
            echo $trackbacktxt;
            break;
        case 'pingback':
            echo $pingbacktxt;
            break;
        default:
            echo $commenttxt;
    }
}

Home | Imprint | This part of the site doesn't use cookies.