Override class inside $atts shortcode_atts in WordPress

Question

I have a plugin and I need to tweak one function. Specifically the ‘class’ => ”.

This is the code in the plugin:

function message_to( $atts, $content = null, $tag = '' ) {
    $atts = shortcode_atts( array(
        'to'        => '{current-post-author}',
        'subject'   => '{current-post-title}',
        'text'      => __( 'Contact','front-end-pm' ),
        'class'     => 'fep-button',
        'fep_mr_to' => false, // Comma separated list of user ids (used in PRO version)
    ), $atts, $tag );
    if ( '{current-post-author}' == $atts['to'] ) {
        $atts['to'] = get_the_author_meta( 'user_nicename' );
    } elseif ( '{current-author}' == $atts['to'] ) {
        if ( $nicename = fep_get_userdata( get_query_var( 'author_name' ), 'user_nicename' ) ) {
            $atts['to'] = $nicename;
        } elseif ( $nicename = fep_get_userdata( get_query_var( 'author' ), 'user_nicename', 'id' ) ) {
            $atts['to'] = $nicename;
        }
        unset( $nicename );
    } elseif ( '{um-current-author}' == $atts['to'] && function_exists( 'um_profile_id' ) ) {
        $atts['to'] = fep_get_userdata( um_profile_id(), 'user_nicename', 'id' );
    } else {
        $atts['to'] = esc_html( $atts['to'] );
    }
    if ( false !== strpos( $atts['subject'], '{current-post-title}' ) ) {
        $atts['subject'] = rawurlencode( str_replace( '{current-post-title}', get_the_title(), $atts['subject'] ) );
    } elseif ( ! empty( $atts['subject'] ) ) {
        $atts['subject'] = rawurlencode( $atts['subject'] );
    } else {
        $atts['subject'] = false;
    }
    if ( empty( $atts['to'] ) && empty( $atts['fep_mr_to'] ) ) {
        return '';
    }
    return '<a href="' . fep_query_url( 'newmessage', array( 'fep_to' => $atts['to'], 'message_title' => $atts['subject'], 'fep_mr_to' => $atts['fep_mr_to'] ) ) . '" class="' . esc_attr( $atts['class'] ) . '">' . esc_html( $atts['text'] ) . '</a>';
}

The original function specifies the class:

'class'     => 'fep-button',

I need to change it to something else:

'class'     => 'something-else',
0
, jade newport 2 years 2019-10-27T09:11:22-05:00 0 Answers 84 views 0

Leave an answer

Browse
Browse