-1

Here is some code from a WP plugin. I'm fairly new to OOP and I'm not actually familiar with the \ in the function parameters which looks like it's instantiating a class. Anybody care to clarify please?

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

Here's the full function for reference.

    /**
     * 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;
    }
dylzee
  • 373
  • 3
  • 8

1 Answers1

0

The backslash character () at the beginning indicates that the type WP_Post is in the global namespace. You can learn more about PHP namespaces here

Joe Santos
  • 28
  • 3
  • 2
    This question already has answers on Stack Overflow. Thank you for contributing and attempting to help the OP, but to combat a lot of redundant pages on Stack Overflow, it is important to close duplicate question versus answering them. – mickmackusa Aug 13 '20 at 00:37
  • 1
    Thanks, I'm new and still trying to figure things out. I'll keep that in mind. – Joe Santos Aug 13 '20 at 00:43