Support » Plugin: WPGlobus - Multilingual Everything! » WPGLOBUS ADD NEW FIELD WITH GENERAL SETTINGS PAGE

  • Resolved Cute Selvam

    (@selvambe23)


    Hello Guys,

    I have a solution for adding new custom field for general settings page with wordpress. I am going to explain you here thanks for the reading this post.

    Function.php (theme file)
    First create the which field do you want to add in general settings page by following code.

    ===================================
    $new_general_setting = new new_general_setting();

    class new_general_setting {
    function new_general_setting( ) {
    add_filter( ‘admin_init’ , array( &$this , ‘register_fields’ ) );
    }
    function register_fields() {
    register_setting( ‘general’, ‘favorite_color’, ‘esc_attr’ );
    add_settings_field(‘fav_color’, ‘<label for=”favorite_color”>’.__(‘Favorite Color?’ , ‘favorite_color’ ).'</label>’ , array(&$this, ‘fields_html’) , ‘general’ );
    }
    function fields_html() {
    $value = get_option( ‘favorite_color’, ” );
    echo ‘<input type=”text” id=”favorite_color” name=”favorite_color” value=”‘ . $value . ‘” />’;
    }
    }
    ===================================
    Then You have to add the wpglobus class file with above field name. find the below path and open that file
    plugins/includes/class-wpglobus.php

    add which field do you want transalte option in line number 3177.

    =============================================
    <!—KRDS General Settings WPGLOBUS TRNANSLATE–>
    <div id=”wpglobus-favorite_color” class=”hidden”> <?php
    $favcol = get_option( ‘favorite_color’ );
    foreach ( self::Config()->enabled_languages as $language ) :
    $return =
    $language == self::Config()->default_language ? WPGlobus::RETURN_IN_DEFAULT_LANGUAGE : WPGlobus::RETURN_EMPTY; ?>

    <input type=”text” class=”regular-text wpglobus-favcol wpglobus-translatable”
    value=”<?php echo WPGlobus_Core::text_filter( $favcol, $language, $return ); ?>”
    id=”favorite_color-<?php echo $language; ?>” name=”favorite_color-<?php echo $language; ?>”
    data-language=”<?php echo $language; ?>”
    placeholder=”<?php echo self::Config()->en_language_name[ $language ]; ?>”><br />

    <?php
    endforeach; ?>
    </div>
    =============================================
    Then we should make the jquery for this fields.

    find this location wpglobus/includes/js/wpglobus-admin-47.min.js
    add below code in line number 247 inside the option general function
    =======================================================
    /* KRDS NEW CUSTOM FIELD LANGUAGE TRANSLATE WPGLOBUS*/
    var da = b(“#favorite_color”);
    da.addClass(“hidden”), b(“#wpglobus-favorite_color”).insertAfter(da).removeClass(“hidden”), c.on(“blur”, “.wpglobus-favcol”, function() {
    b(“.wpglobus-favcol”).each(function(a, c) {
    var e = b(c);
    da.val(WPGlobusCore.getString(da.val(), e.val(), e.data(“language”)))
    })
    })
    =======================================================
    pleaes note we should very careful when maintain name and id with same.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WPGLOBUS ADD NEW FIELD WITH GENERAL SETTINGS PAGE’ is closed to new replies.