JoeSz / Exopite-Simple-Options-Framework

Fast, easy and lightweight admin options/metabox form generator for WordPress Plugins and metaboxes.
GNU General Public License v3.0
78 stars 24 forks source link

Get 'title' values from options and echo in page template #15

Closed justinpicard closed 5 years ago

justinpicard commented 5 years ago

I have text fields for e.g. social media channels. The 'title' field of this option contains the name of a social channel. I want to obtain the value of this 'title'. How can I do that?

'fields'  => array(
    ...
    array(
        'id'            => 'social-facebook',
        'type'        => 'text',
        'title'         => __( 'Facebook', 'textdomain' ), // <-- I want to echo this value 
        'attributes'    => array(
            'data-title'    => 'social-facebook',
            'placeholder'   => __( 'Facebook URL', 'textdomain' ),
        ),
    ),
    ...
),

My loop looks like this (blade templating). The title value goes inside the .social-icon .a

<div class="social-channels">

    @php
        $myplugin_options = get_option('myplugin-options');
        $social_channels = $myplugin_options['social_channels'];
    @endphp

    @if( $social_channels )
        <div class="social-icons-container">

            <ul class="social-icons-list list-unstyled">
                @foreach( $social_channels as $key => $value )

                    @if( !empty( $value ) )
                        <li class="social-icon">
                            {!! '<a class="icon-' . $key . '" href="' . $value . '" target="_blank">' . TITLE VALUE HERE . '</a>' !!}
                        </li>
                    @endif

                @endforeach
            </ul>

        </div>
    @endif

</div>
JoeSz commented 5 years ago

With the newest version, you can use get_exopite_sof_option( $option_slug, $default = false ). The newest version will use the current language sub array to save options, like: $options[language][option]

I think this: $social_channels = $myplugin_options['social_channels']; should be this: $social_channels = $myplugin_options[$current_language]['social_channels'];

you can use var_export too: $myplugin_options = get_option('myplugin-options'); var_export( $myplugin_options );