Well, in this article, I assume you have read the WP Engineer’s excellent post Add WordPress Dashboard Widgets, because his code will be our start point.
So, we have this code:
// Load up the localization file if we're using WordPress in a different language
// Place it in this plugin's folder and name it "MainFunction-[value in wp-config].mo"
load_plugin_textdomain( 'MainFunction', '/wp-content/plugins/MainFunction' );
/**
* Content of Dashboard-Widget
*/
function MainFunction() {
echo 'Test Add Dashboard-Widget';
}
/**
* add Dashboard Widget via function wp_add_dashboard_widget()
*/
function MainFunction_Init() {
wp_add_dashboard_widget( 'MainFunction', __( 'MainFunction Widget Title' ), 'MainFunction' );
}
/**
* use hook, to integrate new widget
*/
add_action('wp_dashboard_setup', 'MainFunction_Init');
OK, now, remenber the wp_add_dashboard_widget function?
function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null )
The $control_callback parameter (obviously optional) is our main target. It gives the ‘Configure’ option to our spiffy widget.
So, we need to add a 4th parameter to wp_add_dashboard_widget:
wp_add_dashboard_widget( 'MainFunction', __( 'MainFunction Widget Title' ), 'MainFunction', 'MainFunction_Setup');
The MainFunction_Setup function handles two things: the options (set the default options, recolect new values, etc) and the option’s presentation (i.e. the HTML part)
So, here goes the code:
function MainFunction_Options() {
$defaults = array( 'items' => 5, 'boolean' => 1);
if ( ( !$options = get_option( 'MainFunction' ) ) || !is_array($options) )
$options = array();
return array_merge( $defaults, $options );
}
function MainFunction_Setup() {
$options = MainFunction_Options();
if ( 'post' == strtolower($_SERVER['REQUEST_METHOD']) && isset( $_POST['widget_id'] ) && 'MainFunction' == $_POST['widget_id'] ) {
foreach ( array( 'items', 'boolean' ) as $key )
$options[$key] = $_POST[$key];
update_option( 'MainFunction', $options );
}
?>
As you can see, MainFunction_Options puts the default values (if necessary, of course) and MainFunction_Setup show the current values and let change them. You can merge this two, of course...
Now, we have to get the options and use them in our MainFunction function. Change MainFunction like that:
/**
* Content of Dashboard-Widget
*/
function MainFunction() {
$widget_options = MainFunction_Options();
echo 'Test Add Dashboard-Widget
';
echo "You have selected $widget_options['items'] items
";
echo "boolean is $widget_options['boolean']
";
}
The complete code here:
';
echo "You have selected $widget_options['items'] items
";
echo "boolean is $widget_options['boolean']
";
}
/**
* add Dashboard Widget via function wp_add_dashboard_widget()
*/
function MainFunction_Init() {
wp_add_dashboard_widget( 'MainFunction', __( 'MainFunction Widget Title' ), 'MainFunction' , 'MainFunction_Setup' );
}
function MainFunction_Options() {
$defaults = array( 'items' => 5, 'boolean' => 1);
if ( ( !$options = get_option( 'MainFunction' ) ) || !is_array($options) )
$options = array();
return array_merge( $defaults, $options );
}
function MainFunction_Setup() {
$options = MainFunction_Options();
if ( 'post' == strtolower($_SERVER['REQUEST_METHOD']) && isset( $_POST['widget_id'] ) && 'MainFunction' == $_POST['widget_id'] ) {
foreach ( array( 'items', 'boolean' ) as $key )
$options[$key] = $_POST[$key];
update_option( 'MainFunction', $options );
}
?>
You can view a PHPS version (without PHP crippled tags) here.
536 replies on “How add options to your WordPress 2.7 dashboard widgets”
Good site you have got here.. It’s hard to find excellent writing like yours these days.
I seriously appreciate people like you! Take care!!
My web site: https://www.qiurom.com/
Some truly interesting details you have written.Assisted me a lot, just what I was looking for :D.
Feel free to visit my web blog: http://www.theezentrepreneur.com/groups/leather-watch-bands-look-for-that-one-which-fits-your-taste/
My programmer is trying to persuade me to move to .net
from PHP. I have always disliked the idea because of the expenses.
But he’s tryiong none the less. I’ve been using Movable-type on several websites for about a
year and am worried about switching to another platform.
I have heard fantastic things about blogengine.net. Is there a way I can transfer all my wordpress
posts into it? Any kind of help would be greatly appreciated!
Feel free to surf to my blog post :: https://helpus.ai/forum/index.php?action=profile;u=493979
If some one wishes to be updated with hottest technologies after that he
must be pay a visit this site and be up to date everyday.
My blog post – leadclub.net
Some truly fantastic content on this internet site, thank you for contribution.
Also visit my site: ultimatedunitedbrothersclub.com
I’ve been exploring for a little for any high-quality articles or weblog posts on this kind of house .
Exploring in Yahoo I eventually stumbled upon this web site.
Studying this info So i am glad to exhibit
that I’ve an incredibly just right uncanny feeling I found out exactly what I needed.
I such a lot undoubtedly will make certain to do not overlook this site and provides it a glance on a continuing basis.
my web site … https://trainingteachers.org.za/groups/low-libido-in-as-well-as-women-how-enhance-male-sexual-prowess-naturally
When someone writes an paragraph he/she retains
the plan of a user in his/her mind that how a user can be
aware of it. Therefore that’s why this post is outstdanding.
Thanks!
My blog: kafecoin.com
Excellent goods from you, man. I’ve consider your stuff
previous to and you’re just too great. I really like what you have
received here, really like what you are saying and the best way in which
you say it. You’re making it entertaining and you continue to care for to
stay it wise. I can not wait to read much more from you.
That is really a great website.
Feel free to surf to my web page; trainingteachers.org.za
Thanks for any other great article. Where
else may just anyone get that kind of information in such an ideal means
of writing? I’ve a presentation subsequent week, and I am at the look for such
information.
My blog; http://www.freeglobalclassifiedads.com
I really enjoy looking through on this internet site,
it has got good posts.
Here is my web-site 0475.banx.co
I truly enjoy studying on this internet site, it has wonderful content.
Here is my blog … http://www.adsyellowpages.com
Greate article. Keep posting such kind of information on your blog.
Im really impressed by your site.[X-N-E-W-L-I-N-S-P-I-N-X]Hi there, You’ve
performed a fantastic job. I’ll certainly digg it and for my part suggest to my friends.
I’m confident they’ll be benefited from this web site.
Visit my page – http://www.axholmeadvertiser.com
Hmm is anyone else having problems with the images on this
blog loading? I’m trying to find out if its a problem on my end or if it’s the blog.
Any feed-back would be greatly appreciated.
My website qiurom.com
It’s awesome to visit this website and reading the views of all friends about this piece of writing, while I am also zealous of getting familiarity.
Also visit my web blog voipxhub.com
Hi there, I enjoy reading through your post.
I like to write a little comment to support you.
My homepage litdevelopments.com
Hello! I know this is kinda off topic but I’d figured I’d ask.
Would you be interested in exchanging links or maybe guest authoring
a blog post or vice-versa? My website discusses a lot of
the same topics as yours and I think we could
greatly benefit from each other. If you’re interested feel free to shoot me an e-mail.
I look forward to hearing from you! Superb blog by the way!
my web page :: 39.100.90.4
I got what you mean,saved to favorites, very decent internet site.
my blog :: https://bettyjostarke.net
Some genuinely excellent articles on this web site, thank you for contribution.
Here is my web blog :: https://www.groovelineentertainment.com
I don’t create a ton of comments, but i did a few searching and
wound up here How add options to your WordPress 2.7
dashboard widgets – Rick's HideOut. And I do have a couple of questions
for you if you usually do not mind. Could it be just me or does it
give the impression like a few of these responses appear like they are written by brain dead visitors?
😛 And, if you are posting on additional places, I’d like to
keep up with everything new you have to post.
Could you make a list of all of all your social pages
like your linkedin profile, Facebook page
or twitter feed?
Also visit my web site http://www.usafreeclassifieds.org
Many thanks for being my own mentor on this niche. I enjoyed your
current article quite definitely and most of all enjoyed how you really handled the issues I regarded as controversial.
You are always rather kind to readers really like me and assist me in my
everyday living. Thank you.
Stop by my website; http://www.makemoneydonothing.com
I like this weblog it’s a master piece! Glad I detected this on google.
Also visit my web page engage.drd4gaming.com
Some truly good articles on this internet site, thanks for contribution.
My website; https://kebe.top
With havin so much content do you ever run into
any issues of plagorism or copyright violation?
My blog has a lot of unique content I’ve either written myself or
outsourced but it looks like a lot of it is
popping it up all over the web without my authorization. Do you know
any ways to help protect against content from being ripped off?
I’d genuinely appreciate it.
My web page: equipifieds.com
Precisely what I was looking for, thanks for posting.
Also visit my web page http://www.hit-forum.info/
Definitely imagine that that you said. Your favorite reason seemed to be on the internet the easiest thing
to keep in mind of. I say to you, I certainly get annoyed even as other
people think about worries that they plainly do not understand about.
You managed to hit the nail upon the top and also defined out the entire thing without
having side-effects , folks could take a signal. Will probably
be back to get more. Thanks
For newest information you have to visit world-wide-web and on world-wide-web I found this website as a most excellent site for
latest updates.
Also visit my homepage: Lionel
Exactly what I was looking for, appreciate it for posting.
Also visit my homepage – http://www.theezentrepreneur.com
Hi it’s me, I am also visiting this web site on a regular
basis, this website is in fact nice and the viewers are really sharing
nice thoughts.
Have a look at my blog – http://www.groovyfreeads.com
I simply wanted to type a small word to be able to say thanks to you
for these marvelous guides you are giving at this website.
My considerable internet investigation has finally been compensated with wonderful knowledge to write about with my guests.
I ‘d declare that many of us readers are rather lucky to be in a fine network
with many special professionals with helpful tips.
I feel very privileged to have seen your entire website and look forward to
plenty of more fabulous minutes reading here.
Thank you once again for a lot of things.
Also visit my blog Nathan
Whats up very nice site!! Man .. Excellent .. Superb ..
I’ll bookmark your blog and take the feeds also…I am happy to seek out numerous useful information right
here within the put up, we’d like develop more strategies in this regard, thank you for sharing.
My homepage :: https://equipifieds.com/
Hiya! I know this is kinda off topic however I’d figured I’d ask.
Would you be interested in trading links or maybe guest writing a blog post or vice-versa?
My site covers a lot of the same topics as yours and I think
we could greatly benefit from each other. If you happen to be interested feel free to send me an e-mail.
I look forward to hearing from you! Excellent blog by the
way!
Also visit my blog; shaboxes.com
I got what you intend, appreciate it for putting
up. Woh I am pleased to find this website through google.
my webpage … muskiefool.com
Hi, i feel that i saw you visited my site thus i came to ?go back
the choose?.I am attempting to in finding things to improve my web site!I assume its adequate to
use some of your concepts!!
Have a look at my web blog … http://www.gifts.bookmarking.site
Hello, i think that i noticed you visited my web site thus i came to ?go back the want?.I am attempting to find issues to improve my website!I
suppose its ok to use some of your ideas!!
Feel free to visit my blog post; kebe.top
Thanks for another great article. The place
else may just anyone get that type of info in such
a perfect approach of writing? I have a presentation next week, and I’m on the look for such info.
My homepage – http://gamegamma.com.tw/forum.php?mod=viewthread&tid=295738
We’re a group of volunteers and starting a new scheme in our community.
Your web site offered us with valuable info to work on. You
have done a formidable job and our entire community will be grateful to you.
Feel free to visit my web site – Judson
That is very interesting, You are a very professional blogger.
I’ve joined your rss feed and sit up for in the hunt for extra of your
fantastic post. Also, I have shared your website in my social networks!
Feel free to surf to my page – shakimuddin.com
I think that is among the such a lot vital information for me.
And i’m glad studying your article. But wanna remark on few general things, The website style is wonderful, the articles is in reality excellent :
D. Just right job, cheers
Here is my blog ozarkstalk.com
Peculiar article, totally what I needed.
Look at my site forum.yawfle.com
Really informative and fantastic bodily structure of written content, now that’s user friendly (:
.
my site; geegram.net
Aw, this was an exceptionally nice post. Taking the time and actual effort to generate a top notch
article? but what can I say? I hesitate a lot and don’t manage to
get nearly anything done.
Here is my site: kebe.top
Hi there, I believe your blog could possibly be having browser compatibility
issues. Whenever I look at your site in Safari, it looks fine however, if opening
in I.E., it’s got some overlapping issues. I just wanted to provide you with a quick heads up!
Apart from that, wonderful blog!
Also visit my web-site :: http://www.physics-s3.org.uk
My brother recommended I might like this web site.
He was totally right. This post actually made my day. You cann’t imagine just how much time I had spent for this information! Thanks!
Feel free to surf to my blog post store.enviotech.com.bd
hey there and thank you for your information ? I’ve certainly picked up anything new from right here.
I did however expertise several technical points using this website, since I experienced to reload the
site lots of times previous to I could get it to load properly.
I had been wondering if your hosting is OK?
Not that I’m complaining, but sluggish loading instances times will sometimes
affect your placement in google and can damage your high-quality score if advertising and
marketing with Adwords. Well I am adding this RSS
to my e-mail and could look out for much more of your respective interesting content.
Ensure that you update this again very soon.
Visit my web blog – https://store.enviotech.com.bd/Choosing_The_Best_Smoking_Pipe
I believe this web site contains some really superb info for everyone :D.
Here is my web blog :: kebe.top
Hi, i believe that i saw you visited my web site so
i came to ?go back the desire?.I’m trying to find issues to enhance my site!I suppose its
adequate to make use of some of your concepts!!
my page: http://www.affiliateclassifiedads.com/user/profile/313466
What’s up Dear, are you really visiting this site daily,
if so after that you will absolutely obtain pleasant know-how.
my web-site – exterminatorsouthflorida.com
Hi there to every , for the reason that I am really eager of reading this website’s post to be updated
on a regular basis. It contains fastidious data.
Feel free to surf to my webpage theezentrepreneur.com
After looking over a few of the blog articles on your web site, I seriously like your way of writing a blog.
I book marked it to my bookmark website list and will be checking back in the near future.
Please check out my web site as well and tell me
your opinion.
My web site … kebe.top
This post is in fact a good one it assists new web users, who are wishing
in favor of blogging.
Feel free to surf to my web blog http://www.hit-forum.info