Protect.php / change username & password

Hi guys,

I tried to change the label username & password into “Mitgliedsname” and “Mitgliedsnummer” but it didn’t work out well:

<?php

// Protect
// =============================================================================

function x_shortcode_protect( $atts, $content = null ) {
  extract( shortcode_atts( array(
    'heading' => '',
    'id'      => '',
    'class'   => '',
    'style'   => ''
  ), $atts, 'x_protect' ) );

  GLOBAL $user_login;

  $id    = ( $id    != '' ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class = ( $class != '' ) ? 'x-protect ' . esc_attr( $class ) : 'x-protect';
  $style = ( $style != '' ) ? 'style="' . $style . '"' : '';

  if ( is_user_logged_in() ) {
    $output = do_shortcode( $content );
  } else {
	$heading = ( $heading != '' ) ?  $heading : csi18n('shortcodes.protect-heading');
    $output = "<div {$id} class=\"{$class}\" {$style}>"
              . '<form action="' . esc_url( site_url( 'wp-login.php' ) ) . '" method="post" class="mbn">'
                . '<h3 class="h-protect man">' . $heading . '</h3>'
                . '<div><label>' . csi18n('Mitgliedsname') . '</label><input type="text" name="log" id="log" value="' . esc_attr( $user_login ) . '" /></div>'
                . '<div><label>' . csi18n('Mitgliedsnummer') . '</label><input type="password" name="pwd" id="pwd" /></div>'
                . '<div><input type="submit" name="submit" value="' . csi18n('shortcodes.protect-login') . '" class="x-btn x-btn-protect" /></div>'
                . '<input type="hidden" name="redirect_to" value="' . esc_url( get_permalink() ) . '">'
              . '</form>'
            . '</div>';
  }

  return $output;
}

add_shortcode( 'x_protect', 'x_shortcode_protect' );

What’s wrong with the edit/code?

Best regards,
Christopher

Hello There,

Thanks for writing in! Your code is missing something. You can make use of this code instead:

// Protect
// =============================================================================

function custom_x_shortcode_protect( $atts, $content = null ) {
  extract( shortcode_atts( array(
    'heading' => '',
    'id'      => '',
    'class'   => '',
    'style'   => ''
  ), $atts, 'x_protect' ) );

  GLOBAL $user_login;

  $id    = ( $id    != '' ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class = ( $class != '' ) ? 'x-protect ' . esc_attr( $class ) : 'x-protect';
  $style = ( $style != '' ) ? 'style="' . $style . '"' : '';

  if ( is_user_logged_in() ) {
    $output = do_shortcode( $content );
  } else {
  $heading = ( $heading != '' ) ?  $heading : csi18n('shortcodes.protect-heading');
    $output = "<div {$id} class=\"{$class}\" {$style}>"
              . '<form action="' . esc_url( site_url( 'wp-login.php' ) ) . '" method="post" class="mbn">'
                . '<h3 class="h-protect man">' . $heading . '</h3>'
                . '<div><label>' . csi18n('Mitgliedsname') . '</label><input type="text" name="log" id="log" value="' . esc_attr( $user_login ) . '" /></div>'
                . '<div><label>' . csi18n('Mitgliedsnummer') . '</label><input type="password" name="pwd" id="pwd" /></div>'
                . '<div><input type="submit" name="submit" value="' . csi18n('shortcodes.protect-login') . '" class="x-btn x-btn-protect" /></div>'
                . '<input type="hidden" name="redirect_to" value="' . esc_url( get_permalink() ) . '">'
              . '</form>'
            . '</div>';
  }

  return $output;
}


function change_x_protect() {
  remove_shortcode( 'x_protect' );
  add_shortcode( 'x_protect', 'custom_x_shortcode_protect' );
}
add_action('wp_head', 'change_x_protect');
// =============================================================================

Please let us know how it goes.

Hi RueNel,

thanks for your reply. I’ve added the code in the protect.php file in ‘wp-content/plugins/cornerstone/includes/shortcodes’ and uploaded it again.

Unfortunately there is still no description on the two data fields: http://bvmw-mitgliederversammlung.de/satzungsaenderung/

Best regards,
Christopher

Hi Christopher,

Unfortunately, it will not work that way.

Please do setup a child theme first.

The code should be added on your child theme functions.php file.

To understand the code better, see this: https://theme.co/apex/forum/t/customizations-actions-and-filters-in-x/208

Hope this helps.

Hi Lely,

I get an ‘HTTP ERROR 500’ error if I add the code to the child theme functions.php.

<?php

// =============================================================================
// FUNCTIONS.PHP
// -----------------------------------------------------------------------------
// Overwrite or add your own custom functions to X in this file.
// =============================================================================

// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
//   01. Enqueue Parent Stylesheet
//   02. Additional Functions
// =============================================================================

// Enqueue Parent Stylesheet
// =============================================================================

add_filter( 'x_enqueue_parent_stylesheet', '__return_true' );



// Additional Functions
// =============================================================================

// Protect
// =============================================================================

function custom_x_shortcode_protect( $atts, $content = null ) {
  extract( shortcode_atts( array(
    'heading' => '',
    'id'      => '',
    'class'   => '',
    'style'   => ''
  ), $atts, 'x_protect' ) );

  GLOBAL $user_login;

  $id    = ( $id    != '' ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class = ( $class != '' ) ? 'x-protect ' . esc_attr( $class ) : 'x-protect';
  $style = ( $style != '' ) ? 'style="' . $style . '"' : '';

  if ( is_user_logged_in() ) {
    $output = do_shortcode( $content );
  } else {
  $heading = ( $heading != '' ) ?  $heading : csi18n('shortcodes.protect-heading');
    $output = "<div {$id} class=\"{$class}\" {$style}>"
              . '<form action="' . esc_url( site_url( 'wp-login.php' ) ) . '" method="post" class="mbn">'
                . '<h3 class="h-protect man">' . $heading . '</h3>'
                . '<div><label>' . csi18n('Mitgliedsnummer') . '</label><input type="text" name="log" id="log" value="' . esc_attr( $user_login ) . '" /></div>'
                . '<div><label>' . csi18n('Passwort') . '</label><input type="password" name="pwd" id="pwd" /></div>'
                . '<div><input type="submit" name="submit" value="' . csi18n('shortcodes.protect-login') . '" class="x-btn x-btn-protect" /></div>'
                . '<input type="hidden" name="redirect_to" value="' . esc_url( get_permalink() ) . '">'
              . '</form>'
            . '</div>';
  }

  return $output;
}


function change_x_protect() {
  remove_shortcode( 'x_protect' );
  add_shortcode( 'x_protect', 'custom_x_shortcode_protect' );
}
add_action('wp_head', 'change_x_protect');
// =============================================================================

Best regards,
Christopher

Hello Christopher,

Please make sure that you have inserted the correct code. Invalid quotes could result to a fatal error or http error 500. I have checked the code and it works in my local test server without any errors.

// Protect
// =============================================================================

function custom_x_shortcode_protect( $atts, $content = null ) {
  extract( shortcode_atts( array(
    'heading' => '',
    'id'      => '',
    'class'   => '',
    'style'   => ''
  ), $atts, 'x_protect' ) );

  GLOBAL $user_login;

  $id    = ( $id    != '' ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class = ( $class != '' ) ? 'x-protect ' . esc_attr( $class ) : 'x-protect';
  $style = ( $style != '' ) ? 'style="' . $style . '"' : '';

  if ( is_user_logged_in() ) {
    $output = do_shortcode( $content );
  } else {
  $heading = ( $heading != '' ) ?  $heading : csi18n('shortcodes.protect-heading');
    $output = "<div {$id} class=\"{$class}\" {$style}>"
              . '<form action="' . esc_url( site_url( 'wp-login.php' ) ) . '" method="post" class="mbn">'
                . '<h3 class="h-protect man">' . $heading . '</h3>'
                . '<div><label>Mitgliedsnummer</label><input type="text" name="log" id="log" value="' . esc_attr( $user_login ) . '" /></div>'
                . '<div><label>Passwort</label><input type="password" name="pwd" id="pwd" /></div>'
                . '<div><input type="submit" name="submit" value="' . csi18n('shortcodes.protect-login') . '" class="x-btn x-btn-protect" /></div>'
                . '<input type="hidden" name="redirect_to" value="' . esc_url( get_permalink() ) . '">'
              . '</form>'
            . '</div>';
  }

  return $output;
}


function change_x_protect() {
  remove_shortcode( 'x_protect' );
  add_shortcode( 'x_protect', 'custom_x_shortcode_protect' );
}
add_action('wp_head', 'change_x_protect');
// =============================================================================

And by the way, please make sure that you are using the latest X/Pro version. It might not work or will have some erros if you are using X 4.x.x and below.

If nothing else is working, please provide us access to your site and ftp site if possible to that we can resolve this issue as soon as possible.

Please let us know how it goes.