I'm using wp-polls and need to limit the number of votes per IP. Although this is usually set at 1 by default, I need to limit the number of votes per IP to 2.
I've been reading documentation, playing with the plugin code, and looking around on google and SO and can't seem to find the proper method.
I've considered using cookies, but these are harder to catch since I could just as well empty my cookies and voilĂ , it's done.
I need a limit because I don't want people to vote endlessly
Looking at the database, I imagine this has something to do with the pollip_ip field (from the (prefix)_pollsip) table, but not being familiar with editing WP Plugins, this is as far I as I got to go.
As a reference, here is some failed code
wp-polls.php, line 1323
// original code
// if($check_voted == 0) {
// proposed by #birgire
if( $check_voted == 0 || ( is_array( $check_voted ) && 2 >= count( $check_voted ) ) ) {
wp-polls.php, line 1323
// original code
// if($check_voted == 0) {
// alternative of code proposed by #birgire
if( ($check_voted == 0) || count($check_voted) <= 2)
I couldn't see any available filters for this, when I skimmed through the plugin source.
I wonder if it would work, if you replace line #1323 of the wp-polls.php file:
if($check_voted == 0) {
with:
if( $check_voted == 0
|| ( is_array( $check_voted ) && 2 >= count( $check_voted ) ) ) {
to limit the number of votes per IP to 2.
Additionally:
Replace line #140 with:
if( !is_array($check_voted) && intval($check_voted) > 0
|| (is_array($check_voted) && sizeof($check_voted) > 1)
|| ($poll_active == 0 && $poll_close == 1)) {
But I don't recommend in general to modify plugin files, since it will be restored in the next plugin update.
Sidenote: The plugin is not using the recommended $wpdb->prepare() when preparing the SQL for $wpdb->query().
Related
I've been using JSONPath in my Codeigniter 3 Project.
I want to find the result of an expression.
Now, coming to the issue. The Same expression works on an online json evaluator. But the same expression used during the code results into false.
Here's the expression
$.slots[?((('2035-05-16 08:00' >= #.slot_datetime_from && '2035-05-16 08:00' < #.slot_datetime_to) || ('2035-05-16 12:30' > #.slot_datetime_from && '2035-05-16 12:30' <= #.slot_datetime_to) ) && #.venue_id == '1' && #.court_id == '1')]
I'm using one JSON. Here's the link
Here's the code which I'm using.
$existingEntries = new JsonObject($existingSlotAndCourtEntries);
$result = $existingEntries->{$exp};
Here's the answer. The author of the library answered it himself.
Github link
I would like to set the disabled state of a form field based on the combination of 4 variables: processed, process started, process ended, user id
If it is not going to be processed, the form field should be disabled
If the process has started OR ended, it should be also disabled, except if the user id == 1. So User 1 can still fill the form field, even if the process has started OR ended. And it should be also disabled for User 1 also if it is not going to be processed.
I was trying this way, but doesn't work as I expect, so there must be a flaw in my logic or understanding how PHP works:
'disabled' => !$proc || (($proc_started || $proc_ended) && !$user_id == 1)
This way other users see the form field also enabled, which I don't want. Is it the hierarchy of the Logical Operators ?
Can you please point me to the right direction? Thanks.
!$user_id == 1 is (!$user_id) == 1
$foo = 42;
!$foo == false;
You want to write !($user_id == 1) or $user_id != 1
Should work.
if($user_id === 1) {
if($state != "processed") {
$state = "Enabled" // or anything else of your choice
}
} else {
$state = "Disabled";
}
I am writing an if else statement in OOP;
The conditions are:
1. Get all requests from BSC from 789789 or 987897
2. If RNB is starting 17 and are 15 characters long
3. Those values with cost as 15 send to URL 1
4. Else send to URL 2
If it matches the statement it is sent to a specific URL, if it does not it sent to another URL. I have rewritten the conditional statement below:
if($request->BSC = 789789 or 987897 && $request->RNB = 17 && $request->BRN strlen = 15 && $request->Cost = 11){
send to URL 1
} else{
..Send to URL 2
}
My question is conditional statement correct?
Your question is a little unclear,
I try to fix your if statement just to show you the correct syntax!:
if( ($request->BSC == 789789 || $request->BSC == 987897) && strpos($request->RNB,'7') == 0 && $request->BRN == 15&& $request->Cost == 11){
//send to URL 1
} else{
//send to URL 2
}
This line :
strpos($request->RNB,'7') == 0
Means: RNB should start with 7, for example : 765433 or 789998 or 712342 . ..
I have been using laravel + mysql for my project but and it was working perfectly fine until now. The records keep on increasing and now they have reached almost a million record. Problem is when i try to fetch sms from my database using this query
$smsHistory = SmsLog::where('created_at', '>=', $startDate)->where('created_at', '<=', $endDate)->whereNotNull('gateway_statuscode')->get();
It gives a 500 error without showing anything in error log. What i assume is that as i decreased the time period it gives me record so the problem is the bulk it can not handle. What could be the possible solution as i have to give it today.
I am not worried about the error log.. i want to get a count of those million record but i want to apply some algorithm on it before doing it
This is the check which i have to perform afterwards to see how many sms are in sms log
foreach ($smsHistory as $sms) {
$sms_content = SmsService::_getSmsContent($sms);
if ($sms_content->business_id && array_key_exists($sms_content->business_id, $smsCredits )) {
if (floor(strlen($sms_content->content) / 160) == 0) {
$smsCredits[$sms_content->business_id]['count'] += 1;
}
if (floor(strlen($sms_content->content) / 160) == 1 && floor(strlen($sms_content->content) / 306) == 0) {
$smsCredits[$sms_content->business_id]['count'] += 2;
}
if (floor(strlen($sms_content->content) / 306) == 1 && floor(strlen($sms_content->content) / 459) == 0) {
$smsCredits[$sms_content->business_id]['count'] += 3;
}
if (floor(strlen($sms_content->content) / 459) == 1 && floor(strlen($sms_content->content) / 621) == 0) {
$smsCredits[$sms_content->business_id]['count'] += 4;
}
if (floor(strlen($sms_content->content) / 621) == 1 && floor(strlen($sms_content->content) / 774) == 0) {
$smsCredits[$sms_content->business_id]['count'] += 5;
}
if (floor(strlen($sms_content->content) / 774) == 1 && floor(strlen($sms_content->content) / 927) == 0) {
$smsCredits[$sms_content->business_id]['count'] += 6;
}
}
this is the database field
content is the sms that i have to get and count
Regarding the 500 error:
If you are getting a 500 error, there should hopefully be some clue in the actual server error log (your laravel application error log may not have caught it depending on the error handlers, etc and what the cause was). php_info() should show you the location of the physical error log with the error_log setting:
<?php phpinfo(); ?>
If I had to guess, possibly something memory related that is causing it to choke. But that is just a guess.
As a side question, why are you trying to retrieve so many at once? Can you split them up somehow?
Edit based on updated question:
You may need to use some raw-expressions here to get what you really want: https://www.laravel.com/docs/4.2/queries#raw-expressions
MySQL for example provides the ability to get a column length:
FLOOR(CHAR_LENGTH(content) / 160) as len1, FLOOR(CHAR_LENGTH(content) / 306) as len2, FLOOR(CHAR_LENGTH(content) / 459) as len3
So probably with some magic we could take your query and let the database system do it all for you. And there are probably more efficient ways to do it, if I knew more about the significance of those numbers, but I am trying to help you at least get on one possible path.
You should setup index for mysql, or implement a search engine like elastic search
I'm refreshing some older code (someone else wrote), and came across this:
if ( empty ( $role_data["role_id" == 1]))
what are the reasons (if any) one would use the above instead of?:
if ( $role_data["role_id"] != 1)
IMO readability is worse and it's more code. Performance isn't a factor here.
--EDIT--
I should mention, that the expected input($role_data["role_id"]) is a number between 0 - 5 (inclusive)
--MORE INFO--
I've missunderstood the code the first time around.
But here's what's happening:
$role_id = htmlspecialchars ( mysql_real_escape_string ( $_GET["role_id"] ) );
$role_data = $db->fctSelectData ( "core_role" , "`role_id` = '" . $role_id . "'" );
This goes to get the permissions for creating the role. But if given an invalid $role_id in the first place (via the $_GET parameter), it returns nothing, hence checking for an empty value in:
if ( empty ( $role_data["role_id" == 1] ) )
I'm still not fully clear of why it's written this way
The line
if (empty($role_data["role_id" == 1]))
Gets translated into...
if (empty($role_data[0]))
...by the PHP interpreter. This code might be a "joke", a funny hack or an error as the line:
if (empty($role_data["role_id"]) == 1)
..sort of makes sense.