有人可以在这里解释语法吗

时间:2020-08-12 23:59:26

标签: php wordpress

这是WP插件中的一些代码。我对OOP还是很陌生,实际上我对函数参数中的\并不熟悉,它看起来像是在实例化一个类。有人愿意澄清一下吗?

 public function customize_membership_plan_row_actions( $actions, \WP_Post $post ) {
        global $typenow;

这是完整的功能参考。

    /**
     * Customizes membership plan row actions.
     *
     * @since 1.0.0
     *
     * @param array $actions array of post actions
     * @param \WP_Post $post post object
     * @return array
     */
    public function customize_membership_plan_row_actions( $actions, \WP_Post $post ) {
        global $typenow;

        if ( 'wc_membership_plan' !== $typenow ) {
            return $actions;
        }

        // add view as member action
        $actions['view_as_member'] = '<a href="' . wp_nonce_url( admin_url( 'edit.php?post_type=wc_membership_plan&action=view_as_member&amp;post=' . $post->ID ), 'wc-memberships-view-as-member-of_' . $post->ID ) . '" title="' . __( 'View site as a member of this plan', 'woocommerce-memberships' ) . '" rel="permalink">' .
                                     __( 'View site as member', 'woocommerce-memberships' ) .
                                     '</a>';

        return $actions;
    }

1 个答案:

答案 0 :(得分:0)

开头的反斜杠字符()表示类型WP_Post位于global namespace中。您可以了解有关PHP名称空间here

的更多信息