We help IT Professionals succeed at work.

Convert Wordpress Widget to a function

Medium Priority
375 Views
Last Modified: 2013-11-19
Hey Experts!!

I have a Wordpress site, with BuddyPress installed. I also have CubePoints integration for BuddyPress installed. I needed a way to get a monthly total of each users points. I did ask on the BP forum and they pointed me to the code below.

But what I want to do is just show how many points a user has for the current month. I'm not too good with PHP yet, but I'd really like some help on figuring this out.
Comment
Watch Question

Commented:
Maybe change

month_cp_getAllPoints($amt=0,$filter_users=array(),$month,$year=0)

to

month_cp_getAllPoints($amt=0,$filter_users=array(),$month=0,$year=0)

and then don't pass the $month when you call the function (it will default to 0) since this line

$month = $month <= 0 ? date('n')+$month : $month;

says if month = 0 then month = the current month, otherwise month = the month passed into the function.  (it also says if month is a negative number than month = this month - the number passed, so you can get points for a previous month)

FYI: date('n') is how you get the current month (without leading zeros for months 1-9).  So another way would be to just pass that value into the function for the month, wherever you are calling it.
LZ1
Top Expert 2011

Author

Commented:
>>and then don't pass the $month when you call the function (it will default to 0)

What do you mean by that?

Commented:
Yes, I didn't explain that well if you are unfamiliar with php.

Just make the month (3rd variable) zero and it should use the current month by default.

$points_this_month = month_cp_getAllPoints(0, array('user'), 0, 0);
LZ1
Top Expert 2011

Author

Commented:
I did all that, however I'm getting the same results.  Is there a way to not have this as a widget and just have this as a function where I can call a php variable???
LZ1
Top Expert 2011

Author

Commented:
Will reopen at a later time.
Top Expert 2011
Commented:
Will reopen at a later time.  No correct answer was given.
LZ1
Top Expert 2011

Author

Commented:
No correct answer given. Will reopen at a later time

Explore More ContentExplore courses, solutions, and other research materials related to this topic.