Part 5 – WordPress Theme Development – Custom Social Media Fields and Sanitize Callbacks

:: Support Me ::
http://www.alecaddd.com/support-me/

How to build a Premium Theme for WordPress – Lesson 5
How to create Custom Social Media Fields and Sanitize Callbacks

GitHub Repo: https://github.com/Alecaddd/Sunset-theme

Download Sunset Theme FREE: https://www.youtube.com/watch?v=ViZLtFIcSfo

:: Tutorial Series ::
WordPress 101 – Create a theme from scratch: https://www.youtube.com/playlist?list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE
Learn SASS from Scratch:
https://www.youtube.com/playlist?list=PLriKzYyLb28nvORWgaD0hAbBcJUcsxy16

:: My Website ::
http://www.alecaddd.com/

:: Follow me on ::
Twitter: https://twitter.com/alecaddd
Google+: https://plus.google.com/u/0/+AlessandroCastellani/posts
Facebook: https://www.facebook.com/alecadddpage

27 Comments on “Part 5 – WordPress Theme Development – Custom Social Media Fields and Sanitize Callbacks”

  1. i'm wondering is it the part of wordpress theme ? why admin page ? there is already a admin page of wordpress

  2. are the inputs supposed to be saved somewhere? cause I checked the database there are no input value thatI typed in.

  3. I noticed you’ve moved the do_action() outside of the sunset_add_admin_page() scope in this video, what’s the reason for this?

  4. I am a wordpress theme developer for over 3 years now, but I always fall back to your videos when I dont know what I am doing haha! Thanks for the awesome tutorials.

  5. I added some functions to don't repeat the code every time ^^, I pass the code if some1 want to re-use it :).

    function register_settings( $group, $options = array() ) {
    foreach ( $options as $option ) {
    register_setting( $group, $option );
    }
    }

    function sunset_custom_settings() {
    $group = 'sunset-settings-group';
    $options = [ 'first_name', 'last_name', 'facebook_handler', 'gplus_handler' ];

    register_settings( $group, $options );

    // To avoid multiple IF's, repeat register_setting with extra option

    register_setting( 'sunset-settings-group', 'twitter_handler', 'sunset_sanitize_twitter_handler' );
    add_settings_section( 'sunset-sidebar-options', 'Sidebar Options', 'sunset_sidebar_options', 'alecadd_sunset' );

    $args = format_myArgs( 'first_name', 'text', 'First Name' );

    add_settings_field( 'sidebar-name', 'First Name', 'sunset_sidebar_addField', 'alecadd_sunset', 'sunset-sidebar-options', $args );

    $args = format_myArgs( 'last_name', 'text', 'Last Name' );

    add_settings_field( 'sidebar-lastname', 'Last Name', 'sunset_sidebar_addField', 'alecadd_sunset', 'sunset-sidebar-options', $args );

    $args = format_myArgs( 'twitter_handler', 'text', 'Twitter handler', 'Input your Twitter username without the @ character.' );

    add_settings_field( 'sidebar-twitter', 'Twitter handler', 'sunset_sidebar_addField', 'alecadd_sunset', 'sunset-sidebar-options', $args );

    $args = format_myArgs( 'facebook_handler', 'text', 'Facebook handler' );

    add_settings_field( 'sidebar-facebook', 'Facebook handler', 'sunset_sidebar_addField', 'alecadd_sunset', 'sunset-sidebar-options', $args );

    $args = format_myArgs( 'gplus_handler', 'text', 'Google+ handler' );

    add_settings_field( 'sidebar-gplus', 'Google+ handler', 'sunset_sidebar_addField', 'alecadd_sunset', 'sunset-sidebar-options', $args );
    }

    function sunset_sidebar_options() {
    echo 'Customize your Sidebar Information';
    }

    function format_myArgs( $name, $type, $placeholder, $desc = false ) {
    return array(
    'name' => $name,
    'type' => $type,
    'placeholder' => $placeholder,
    'desc' => $desc
    );
    }

    function sunset_sidebar_addField( $args ) {
    $value = esc_attr( get_option( $args['name'] ) );
    echo '<input type="' . $args['type'] . '" name="' . $args['name'] . '" value="' . $value . '" placeholder="' . $args['placeholder'] . '" />
    <p class="description">' . $args['desc'] . '</p> ';
    }

    // Sanitization settings

    function sunset_sanitize_twitter_handler( $input ) {
    $output = sanitize_text_field( $input );
    $output = str_replace( '@', '', $output );

    return $output;
    }

    Thanks Alecadd! 🙂 I'm learning a lot!.

  6. Alessandro, excellent tutorial.

    I have a doubt. I need display a data wich I saved in inputs that I created. How I would do? I need to do some select or for each or there is a way easier?

  7. Hi Alex, i can't add section via add_settings_section() in admin profile page, i write add_settings_section('garage-profile-sidebar', 'Sidebar Options', 'garage_profile_sidebar_options', 'profile.php'); maybe you know what i need to write in $page = "???" ?

  8. Alessandro Castellani, you're videos are Top I , i can't find others videos on YouTube that explains " how to …" like the way you do it 🙂

  9. Hey Alessandro, is this method the same to strip specific user input from the customizer api instead? for example a setting to change font size, to remove px or em from the users input?

  10. this si awesome i enjoying my coding with you. learn alot from WP 101 series. you just change one word str_replace('super cooool', 'happy coding', $output) hahahahah
    thank you sooo mcuh for teaching us.

  11. where is the $input came from? we can use html input as variable without specify? I'm kinda confused . BTW thank you so much for good videos.

  12. Hi Alessandro,

    Thanks For the tutorial I learn more about WordPress. 😀 <3

    if someones username like "@n@bila" , how to replace this "@" symbol just first one not the second one ?

    your using str_replace() functions that search all "@" in thel string but the problem is this PHP function it's all replace "@" symbol on the string but .. I just replace the first one .

    I know it can be done by Regular Expression…

    but my real question is there any PHP function or some Technic or WordPress function that can be done more easily ??

    Thank you in advance 😀
    Nobir

  13. Hi Alex, thank you so much for your brilliant work!
    I get stuck with saving the values in the fields. If I fill all fields and click 'Save Changes', it saves only my First Name and the rest of the fields have a placeholder. I've already checked my spelling and all variable names but still do not find a problem. Do you have a clue what I could miss?

  14. Hi, in the previous video add_action('admin_init', sunset_custom_settings) was inside sunset_add_admin_page() function, and you mentioned the benefit of it. However in this video it is outside of the function. Was that intentional?

  15. Hi aless! thank you for the tutorial…. ive learned a lot.. 🙂

    but i have a problem on sanitizing on twitter handler…
    when i saved the twitter handler to the wordpress… the twitter handler textbox gets empty even without a special character.

    Here is my code…
    register_setting('sunset-settings-group', 'twitter_handler', 'sunset_sanitize_twitter_handler' );

    function sunset_sanitize_twitter_handler ( $input) {
    $ouput = sanitize_text_field($input);
    $output = str_replace('@', ' ', $output);
    return $output;
    }

    please help.. thanks alessandro!

Comments are closed.