Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to add a logout button on the side admin menu (because I disable the admin bar for the users). So I thought add_menu_page() is the way to do it, but how to add the link to the regarded function?

Here is what i did:

add_action( 'admin_menu', 'my_logout_menu' );

function my_logout_menu() {
add_menu_page( 'Logout', 'Logout', 'read', 'logout', 'my_logout' );}

function my_logout() {
echo wp_logout_url( $redirect );}//here is I don't know what to do.

Am I using the correct approach? or there are other easier ways to do it?

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

I'm using this as a custom logout button, it also displays a random quote before logout the user. I think you can adapt it to your needs by removing what you don't need.

Instructions: Copy the code below and save as users-logout.php Create a folder called users-logout, upload the file and the images below to work.

Any problems just let me know

Images: enter image description here enter image description here enter image description here

Code:

 <?php
    /*
    Plugin Name: Users Logout Button
    Plugin URI: http://www.exe.ie
    Description: Logout menu button for users
    Author: Daniel Conde
    Author URI: http://www.exe.ie
    */

    function users_add_login_logout_link() {
            $quotes = array(
    "Commitment leads to action. Action brings your dream closer. 
    </p><font size='4'>Marcia Wieder</font>",

    "Change will not come if we wait for some other person or some other time. We are the ones we've been waiting for. We are the change that we seek. 
    </p><font size='4'>Barack Obama </font>",

    "Nothing can stop the man with the right mental attitude from achieving his goal; nothing on earth can help the man with the wrong mental attitude. 
    </p><font size='4'>Thomas Jefferson</font>",

    "Man, alone, has the power to transform his thoughts into physical reality; man, alone, can dream and make his dreams come true. 
    </p><font size='4'>Napoleon Hill </font>",

    "Try not to become a man of success but a man of value. 
    </p><font size='4'>Albert Einstein</font>",

    "People who don't take risks generally make about two big mistakes a year. People who do take risks generally make about two big mistakes a year. 
    </p><font size='4'>Peter Drucker </font>",

    "Cherish your visions and your dreams as they are the children of your soul, the blueprints of your ultimate achievements. 
    </p><font size='4'>Napoleon Hill </font>",

    "I am careful not to confuse excellence with perfection. Excellence, I can reach for; perfection is God's business. 
    </p><font size='4'>Michael J. Fox</font>",

    "Old friends pass away, new friends appear. It is just like the days. An old day passes, a new day arrives. The important thing is to make it meaningful: a meaningful friend - or a meaningful day. 
    </p><font size='4'>Dalai Lama </font>",

    "When I let go of what I am, I become what I might be
    </p><font size='4'>Lao Tzu </font>",

    "An eye for an eye only ends up making the whole world blind. 
    </p><font size='4'>Mohandas Gandhi </font>",

    "Every artist was first an amateur. 
    </p><font size='4'>Ralph Waldo Emerson</font>",

    "People often say that this or that person has not yet found himself. But the self is not something one finds, it is something one creates.
    </p><font size='4'>Thomas S. Szasz </font>",

    "Unless you try to do something beyond what you have already mastered, you will never grow.
    </p><font size='4'>Ralph Waldo Emerson </font>",

    "There are no such things as limits to growth, because there are no limits to the human capacity for intelligence, imagination, and wonder
    </p><font size='4'>Ronald Reagan </font>",

    "History is a relentless master. It has no present, only the past rushing into the future. To try to hold fast is to be swept aside. 
    </p><font size='4'>John F. Kennedy </font>",

    "Look at everything as though you were seeing it either for the first or last time. Then your time on earth will be filled with glory. 
    </p><font size='4'>Betty Smith</font>",

    "Many of life's failures are people who did not realize how close they were to success when they gave up. 
    </p><font size='4'>Thomas Edison</font>",

    "It doesn't matter where you are coming from. All that matters is where you are going. 
    </p><font size='4'>Brian Tracy</font>",

    "Instead of worrying about what people say of you, why not spend time trying to accomplish something they will admire. 
    </p><font size='4'>Dale Carnegie </font>",

    "All our dreams can come true, if we have the courage to pursue them. 
    </p><font size='4'>Walt Disney </font>",

    "A person who has a cat by the tail knows a whole lot more about cats than someone who has just read about them. 
    </p><font size='4'>Mark Twain</font>",

    "Be Content with what you have; rejoice in the way things are. When you realize there is nothing lacking, the whole world belongs to you.
    </p><font size='4'>Lao Tzu </font>",

    "The future belongs to those who believe in the beauty of their dreams. 
    </p><font size='4'>Eleanor Roosevelt</font>",

    "A dog is not considered a good dog because he is a good barker. A man is not considered a good man because he is a good talker. 
    </p><font size='4'>Buddha </font>",

    "Wealth, like happiness, is never attained when sought after directly. It comes as a by-product of providing a useful service. 
    </p><font size='4'>Henry Ford </font>",

    "Don't judge those who try and fail, judge those who fail to try. 
    </p><font size='4'>Unknown</font>",

    "I can accept failure, everyone fails at something. But I can't accept not trying. 
    </p><font size='4'>Michael Jordan </font>",

    "Every great man, every successful man, no matter what the field of endeavor, has known the magic that lies in these words: every adversity has the seed of an equivalent or greater benefit. 
    </p><font size='4'>W. Clement Stone </font>",

    "Opportunities are like sunrises. If you wait too long, you miss them. 
    </p><font size='4'>Unknown</font>",

    "Once you have mastered time, you will understand how true it is that most people overestimate what they can accomplish in a year - and underestimate what they can achieve in a decade. 
    </p><font size='4'>Tony Robbins </font>",

    "The only thing in life achieved without effort is failure. 
    </p><font size='4'>Unknown</font>",

    "If I'd had some set idea of a finish line, don't you think I would have crossed it years ago? 
    </p><font size='4'>Bill Gates </font>",

    "The truth is that there is nothing noble in being superior to somebody else. The only real nobility is in being superior to your former self. 
    </p><font size='4'>Whitney Young</font>",

    "Success isn't a result of spontaneous combustion. You must set yourself on fire. 
    </p><font size='4'>Arnold H. Glasow </font>",

    "He who is not contented with what he has, would not be contented with what he would like to have. 
    </p><font size='4'>Socrates</font>",

    "The man of wisdom is never of two minds; the man of benevolence never worries; the man of courage is never afraid. 
    </p><font size='4'>Confucius</font>",

    "Most people have no idea of the giant capacity we can immediately command when we focus all of our resources on mastering a single area of our lives. 
    </p><font size='4'>Tony Robbins </font>",

    "A friend is one who knows us, but loves us anyway. 
    </p><font size='4'>Jerome Cummings</font>",

    "Are you bored with life? Then throw yourself into some work you believe in with all your heart, live for it, die for it, and you will find happiness that you had thought could never be yours. 
    </p><font size='4'>Dale Carnegie </font>",

    "Failure is not a single, cataclysmic event. You don't fail overnight. Instead, failure is a few errors in judgement, repeated every day. 
    </p><font size='4'>Jim Rohn </font>",

    "Do not anticipate trouble, or worry about what may never happen. Keep in the sunlight. 
    </p><font size='4'>Benjamin Franklin</font>",

    "Happiness depends more on the inward disposition of mind than on outward circumstances. 
    </p><font size='4'>Benjamin Franklin</font>",

    "Stretching his hand up to reach the stars, too often man forgets the flowers at his feet. 
    </p><font size='4'>Jeremy Bentham </font>",

    "What we plant in the soil of contemplation, we shall reap in the harvest of action. 
    </p><font size='4'>Meister Eckhart </font>",

    "When you see a man of worth, think of how you may emulate him. When you see one who is unworthy, examine yourself. 
    </p><font size='4'>Confucius</font>",

    "Success is getting what you want. Happiness is wanting what you get. 
    </p><font size='4'>Dale Carnegie</font>",

    "Justice consists not in being neutral between right and wrong, but in finding out the right and upholding it, wherever found, against the wrong. 
    </p><font size='4'>Theodore Roosevelt</font>",

    "Don't aim for success if you want it; just do what you love and believe in, and it will come naturally. 
    </p><font size='4'>David Frost </font>",

    "I never think of the future - it comes soon enough. 
    </p><font size='4'>Albert Einstein</font>",

    "A real decision is measured by the fact that you've taken a new action. If there's no action, you haven't truly decided. 
    </p><font size='4'>Tony Robbins </font>",

    "Happy are those who dream dreams and are ready to pay the price to make them come true. 
    </p><font size='4'>Leon J. Suenes</font>",

    "The only way of finding the limits of the possible is by going beyond them into the impossible. 
    </p><font size='4'>Arthur C. Clarke</font>",

    "You cannot dream yourself into a character: you must hammer and forge yourself into one. 
    </p><font size='4'>Henry D. Thoreau</font>",

    "Knowing is not enough; we must apply. Willing is not enough; we must do. 
    </p><font size='4'>Johann Wolfgang von Goethe</font>",

    "Think twice before you speak, because your words and influence will plant the seed of either success or failure in the mind of another. 
    </p><font size='4'>Napoleon Hill </font>",

    "It is better to conquer yourself than to win a thousand battles. Then the victory is yours. It cannot be taken from you, not by angels or by demons, heaven or hell. 
    </p><font size='4'>Buddha </font>",

    "Keep steadily before you the fact that all true success depends at last upon yourself. 
    </p><font size='4'>Theodore T. Hunger</font>",

    "I've learned that people will forget what you said, people will forget what you did, but people will never forget how you made them feel. 
    </p><font size='4'>Maya Angelou</font>",

    "The talent of success is nothing more than doing what you can do, well. 
    </p><font size='4'>Henry W. Longfellow</font>",

    "When you dance, your purpose is not to get to a certain place on the floor. It's to enjoy each step along the way.
    </p><font size='4'>Wayne Dyer </font>",

    "I try to learn from the past, but I plan for the future by focusing exclusively on the present. That's were the fun is. 
    </p><font size='4'>Donald Trump </font>",

    "Whether you think that you can, or that you can't, you are usually right.
    </p><font size='4'>Henry Ford </font>",

    "We are all faced with a series of great opportunities brilliantly disguised as impossible situations.
    </p><font size='4'>Charles R. Swindoll </font>",

    "Don't hold to anger, hurt or pain. They steal your energy and keep you from love. 
    </p><font size='4'>Leo Buscaglia</font>",

    "If you want others to be happy, practice compassion. If you want to be happy, practice compassion. 
    </p><font size='4'>Dalai Lama </font>",

    "Life shrinks or expands in proportion to one's courage. 
    </p><font size='4'>Anais Nin</font>",

    "There is only one person who could ever make you happy, and that person is you. 
    </p><font size='4'>David Burns</font>",

    "Be careful the environment you choose for it will shape you; be careful the friends you choose for you will become like them. 
    </p><font size='4'>W. Clement Stone </font>",

    "Whatever the mind of man can conceive and believe, it can achieve. 
    </p><font size='4'>W. Clement Stone</font>",

    "I've learned that you shouldn't go through life with a catcher's mitt on both hands; you need to be able to throw something back. 
    </p><font size='4'>Maya Angelou </font>",

    "Give me a stock clerk with a goal and I’ll give you a man who will make history. Give me a man with no goals and I’ll give you a stock clerk. 
    </p><font size='4'>J.C. Penney </font>",

    "Sing like no one's listening, love like you've never been hurt, dance like nobody's watching, and live like its heaven on earth.
    </p><font size='4'>Mark Twain </font>",

    "Early to bed, early to rise, makes a man healthy, wealthy and wise
    </p><font size='4'>Benjamin Franklin </font>",

    "Success is not final, failure is not fatal: it is the courage to continue that counts.
    </p><font size='4'>Winston Churchill </font>",

    "Know where to find the information and how to use it - That's the secret of success.
    </p><font size='4'>Albert Einstein </font>",

    "Do not be too moral. You may cheat yourself out of much life. Aim above morality. Be not simply good; be good for something. 
    </p><font size='4'>Henry David Thoreau</font>",

    "I've failed over and over and over again in my life and that is why I succeed. 
    </p><font size='4'>Michael Jordan </font>",

    "Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young. 
    </p><font size='4'>Henry Ford </font>",

    "A successful man is one who can lay a firm foundation with the bricks others have thrown at him. 
    </p><font size='4'>David Brinkley</font>",

    "I don't know the key to success, but the key to failure is trying to please everybody. 
    </p><font size='4'>Bill Cosby </font>",

    "Success is how high you bounce when you hit bottom. 
    </p><font size='4'>George S. Patton</font>",


    "We are all faced with a series of great opportunities brilliantly disguised as impossible situations.
    </p><font size='4'>Charles R. Swindoll </font>",

    "Don't hold to anger, hurt or pain. They steal your energy and keep you from love. 
    </p><font size='4'>Leo Buscaglia</font>",

    "If you want others to be happy, practice compassion. If you want to be happy, practice compassion. 
    </p><font size='4'>Dalai Lama </font>",

    "Life shrinks or expands in proportion to one's courage. 
    </p><font size='4'>Anais Nin</font>",

    "There is only one person who could ever make you happy, and that person is you. 
    </p><font size='4'>David Burns</font>",

    "Be careful the environment you choose for it will shape you; be careful the friends you choose for you will become like them. 
    </p><font size='4'>W. Clement Stone </font>",

    "Whatever the mind of man can conceive and believe, it can achieve. 
    </p><font size='4'>W. Clement Stone</font>",

    "I've learned that you shouldn't go through life with a catcher's mitt on both hands; you need to be able to throw something back. 
    </p><font size='4'>Maya Angelou </font>",

    "Give me a stock clerk with a goal and I’ll give you a man who will make history. Give me a man with no goals and I’ll give you a stock clerk. 
    </p><font size='4'>J.C. Penney </font>",

    "Sing like no one's listening, love like you've never been hurt, dance like nobody's watching, and live like its heaven on earth.
    </p><font size='4'>Mark Twain </font>",

    "Early to bed, early to rise, makes a man healthy, wealthy and wise
    </p><font size='4'>Benjamin Franklin </font>",

    "Success is not final, failure is not fatal: it is the courage to continue that counts.
    </p><font size='4'>Winston Churchill </font>",

    "Know where to find the information and how to use it - That's the secret of success.
    </p><font size='4'>Albert Einstein </font>",

    "Do not be too moral. You may cheat yourself out of much life. Aim above morality. Be not simply good; be good for something. 
    </p><font size='4'>Henry David Thoreau</font>",

    "I've failed over and over and over again in my life and that is why I succeed. 
    </p><font size='4'>Michael Jordan </font>",

    "Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young. 
    </p><font size='4'>Henry Ford </font>",

    "A successful man is one who can lay a firm foundation with the bricks others have thrown at him. 
    </p><font size='4'>David Brinkley</font>",

    "In the absence of clearly-defined goals, we become strangely loyal to performing daily trivia until ultimately we become enslaved by it. 
    </p><font size='4'>Robert Heinlein</font>",

    "A hero is no braver than an ordinary man, but he is braver five minutes longer. 
    </p><font size='4'>Ralph Waldo Emerson</font>",

    "There is no passion to be found playing small - in settling for a life that is less than the one you are capable of living. 
    </p><font size='4'>Nelson Mandela </font>",

    "I know of no more encouraging fact than the unquestionable ability of man to elevate his life by conscious endeavor. 
    </p><font size='4'>Henry David Thoreau </font>",

    "The big secret in life is that there is no big secret. Whatever your goal, you can get there if you're willing to work. 
    </p><font size='4'>Oprah Winfrey</font>",

    "Happiness is not something you postpone for the future; it is something you design for the present. 
    </p><font size='4'>Jim Rohn </font>",

    "For to be free is not merely to cast off one's chains, but to live in a way that respects and enhances the freedom of others. 
    </p><font size='4'>Nelson Mandela </font>",

    "All growth depends upon activity. There is no development physically or intellectually without effort, and effort means work. 
    </p><font size='4'>Calvin Coolidge</font>",

    "It was a high counsel that I once heard given to a young person, \"Always do what you are afraid to do.\" 
    </p><font size='4'>Ralph Waldo Emerson</font>",

    "Being deeply loved by someone gives you strength, while loving someone deeply gives you courage.
    </p><font size='4'>Lao Tzu </font>",

    "Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration. 
    </p><font size='4'>Evan Esar</font>",

    "Success does not consist in never making blunders, but in never making the same one a second time. 
    </p><font size='4'>Josh Billings</font>",

    "The great thing in the world is not so much where we stand as in what direction we are moving. 
    </p><font size='4'>Oliver Wendell Holmes</font>",

    "Thousands of candles can be lit from a single candle, and the life of the candle will not be shortened. Happiness never decreases by being shared.
    </p><font size='4'>Buddha </font>",

    "Only after we can learn to forgive ourselves can we accept others as they are because we don't feel threatened by anything about them which is better than us.
    </p><font size='4'>Stephen Covey </font>",

    "When you judge another, you do not define them, you define yourself.
    </p><font size='4'>Wayne Dyer </font>",

    "After the game, the king and the pawn go into the same box. 
    </p><font size='4'>Italian Proverb</font>",

    "We are the creative force of our life, and through our own decisions rather than our conditions, if we carefully learn to do certain things, we can accomplish those goals. 
    </p><font size='4'>Stephen Covey </font>",

    "Character is like a tree and reputation like a shadow. The shadow is what we think of it; the tree is the real thing. 
    </p><font size='4'>Abraham Lincoln </font>",

    "People who are always making allowances for themselves soon go bankrupt.
    </p><font size='4'>Mary Pettibone Poole </font>"

    );
            $i = 0;
            while ($i < 366) {
                $dates[$i++] = $i++;
            }
            $v = date(z); ?>
            <div id="dashboard" class="wrap">
                <div style="float: left; height: 48px; background: url('/wp-content/plugins/users-logout/keyb.png') no-repeat scroll 0 0 transparent; margin: 7px 8px 0 0; width: 48px;">
                    <br>
                </div>
                <h2>Log Out</h2>
            </div>
            <div style="text-align: center;"><img src="/wp-content/plugins/users-logout/287.gif" width="128px" height="128px" /></div>
            <div style="text-align: center;">Please wait we are logging you out ...</div>
            <br/>
            <br/>
            <div style="padding: 10px 0; font-size: 25px;"><p>
                <?php echo $quotes[$v];?><br/>
            </div>
            <?php 
            $location = '"Location: ' . wp_logout_url() . '"';
            echo '<meta http-equiv="refresh" content="4; url=' . wp_logout_url(home_url()) . '"/>';
            exit;
        }
    add_action('admin_menu', 'register_custom_menu_page');

    function register_custom_menu_page() {
            add_menu_page( 'admin_menu', 'Logout', '0', 'logout', 'users_add_login_logout_link', plugins_url( 'key.png' , __FILE__ )); 
        }
    ?>
share|improve this answer
    
Your solution works. But after some research I do found adminmenu hook can add link below the menu. By some css and jquery hacks, now I can add the link finally. This might not a best solution, but is enough for me. –  dev-jim May 6 '12 at 17:26
1  
Sorry, I don't get what are you saying. If the solution above solves some how your problem please mark the solution to your question. No idea of what jquery and css are you talking about –  user983248 May 6 '12 at 22:43
add comment

Am I using the correct approach? or there are other easier ways to do it?

If you're removing the toolbar, then you're not using the correct approach in the first place. The toolbar is more than just an admin menu for users to log out with ...

As for your code ... no, this won't work.

add_menu_page() adds a link to a specific page represented by a function in WordPress. You're trying to add a page that has nothing on it but a link to log out with.

share|improve this answer
add comment

The add_menu_page() function isn't really meant for adding links to the menu. Check out this answer. Your final code will be something like this (though this snippet is untested):

add_action( 'admin_menu' , 'admin_menu_new_items' );
function admin_menu_new_items() {
    global $submenu;
    $submenu[500] = array( 'Log Out', 'read' , get_site_url() . '/wp-login.php?action=logout&_wpnonce=86c29b634a' ); 
}

+1 to @EAMann's point about not removing the toolbar, though.

share|improve this answer
    
The question states a button, not a sub-menu item. A menu item will be the close thing to a button in this case –  user983248 May 7 '12 at 9:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.