简体   繁体   中英

Wordpress custom authentication page

I'm building site based on wordpress for my client that requires album/gallery authentication. I've made custom plugin that stores galleries and images in custom tables in the database. Now i want to create a simple page for clients so they can sign in with gallery name and password to it and browse their galleries. I was thinking about making a page in wp admin and custom template for it and then handle authentication in there.

How would you do such authentication?

The basic approach is:

  1. register a function with the admin_menu event
  2. add your pages and sub-pages
  3. verify permissions

Read roles and capabilities in the Codex for details.

add_action('admin_menu', 'pluginprefix_admin_menu'); // 1

function pluginprefix_admin_menu() {
    //2
    $plugurl = plugin_dir_url( __FILE__ );
    /*
    add_menu_page( $page_title, $menu_title, $capability, $menu_slug,
                     $function, $icon_url, $position );

    add_submenu_page( $parent_slug, $page_title, $menu_title, $capability,
                        $menu_slug, $function );

    for example: */

    add_menu_page( 'Statistikk', 'Statistikk', 'edit_plugins',
                   'pluginprefix_main', 'pluginprefix_page_main',
                   "$plugurl/img/stats-menu.png", 25);

    add_submenu_page( 'pluginprefix_main', 'Statistikk - Instillinger',
                      'Instillinger', 'edit_plugins', 'pluginprefix_fields',
                      'pluginprefix_page_fields' );

function pluginprefix_page_main() {
    // 3
    if ( !current_user_can( 'manage_options' ) )  {
    wp_die( __( 'You do not have sufficient permissions to access this page.' ));
    }
    include( MY_TEMPLATES . 'settings_page.tpl.php' );

}

. . .

I see. In that case;

  1. create a form with login / password fields, and post it to "wp-ajax" .
  2. on the other end, compare the login and password with the stored and salted hashes .
  3. and finally set a session variable indicating that the user can browse a certain album.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM