<?php

// Create custom plugin settings menu
add_action('admin_menu', 'custom_create_menu');

function custom_create_menu() {
    //create new top-level menu
    add_menu_page('Custom Plugin Settings', 'Custom Settings', 'administrator', __FILE__, 'custom_settings_page' , plugins_url('/images/icon.png', __FILE__) );

    //call register settings function
    add_action( 'admin_init', 'register_mysettings' );
}


function register_mysettings() {
    //register our settings
    register_setting( 'custom-settings-group', 'logo_url' );
}

function custom_settings_page() {
?>
<div class="wrap">
<h1>Custom Plugin</h1>

<form method="post" action="options.php">
    <?php settings_fields( 'custom-settings-group' ); ?>
    <?php do_settings_sections( 'custom-settings-group' ); ?>
    <table class="form-table">
        <tr valign="top">
        <th scope="row">Logo URL</th>
        <td><input type="text" name="logo_url" value="<?php echo esc_attr( get_option('logo_url') ); ?>" /></td>
        </tr>
    </table>

    <?php submit_button(); ?>

</form>
</div>
<?php }

add_action('admin_bar_menu', 'custom_admin_bar_menu', 999);

function custom_admin_bar_menu($wp_admin_bar) {
    $logo_url = get_option('logo_url');
    if(!empty($logo_url)) {
        $args = array(
            'id' => 'custom-logo',
            'title' => '<img src="' . $logo_url . '" style="height: 32px; width: auto;">',
            'href' => get_option('siteurl'),
            'meta' => array(
                'class' => 'custom-logo',
                'title' => 'Home'
            )
        );
        $wp_admin_bar->add_node($args);
    }
}