Wordpress: cant derive error - wordpress

I've got a strange one going on here. Tried to implement is_wp_error in multiple situations, but it fails. Here's the thing, illustrated with my last attempt:
I want to login a user by wp_signon(), check if there are errors and if so, display them.
So I wrote the following lines of code:
$user = wp_signon();
if(is_wp_error($user)){
$result = 'Error-' .
$user->get_error_message();
} else {
$result = 'Login succeed';
}
echo $result;
The strange thing is, is_wp_error() doesn't return false (so there is an error). But $user->get_error_message(); is empty.
Tried it in different actions. When debugging, echo is_wp_error(); returns 0.
var_dump(wp_is_error()); returns empty arrays.
Furthermore, even when valid credentials are given, is_wp_error() still returns true. Also when testing in other circumstances (and on a clean WP installation)
Any thoughts?

I took a look through the wp_signon() code (located at http://core.trac.wordpress.org/browser/tags/3.5/wp-includes/user.php#L0 )
Looks like the error is blanked out if a blank username or password is passed in. (lines 56 and 57 of that file.)

Related

Wordpress wp_trash_post hooks not working as expected

This applies to all the hooks associated with wp_trash_post(); pre_trash_post, wp_trash_post, trashed_post and the transition hooks, eg publish_to_trash. All behave in exactly the same way.
I have a piece of code to run on this hook;
function to_fire_on_hook($post_id) {
... do stuff
// Get the slug of the $post_id above - the post being trashed
$slug = $post->post_name;
... more stuff that then
do_something(..., $slug, ...);
// doesn't work unless I put
die; //here
}
}
add_action('wp_trashed_post', 'to_fire_on_hook');
if I put die in the function, it completes OK, if I remove it the function doesn't complete.
I thought it might be to do with the fact that putting the post in the trash appends _trash to its name but appending that to $slug doesn't make any difference (neither does using the post ID).
I have swapped out all variables for static values and the result is the same. If the execution stops with die or wp_die() the last function executes, if not it doesn't.
Using echo statements before the die shows the correct values.
Any light on what could cause this behaviour?

After adding a hook in functions.php, limit login plugin doesn't display value

I am having trouble as I am not able to display counter values of "Limit Login Attempts Reloaded" plugin after adding a hook to change content of error message.
I am using hook below to change eroor content.
add_filter('login_errors', create_function('$a', "return '<b>Error: </b> Wron Username or Password';"));
If I don't use that hook it works well, but template is messed up. Any suggestions?
First, the create_function() function is deprecated. You could try it like this:
function my_login_errors_function(){
return 'Error: Wrong Username or Password';
}
add_filter('login_errors', 'my_login_errors_function');
However, this doesn't fix the main problem, which is that your function will change every login error text to the string we are returning.
Filters are like machines on a conveyor belt, receiving something and passing something along to the next step. But the way your function is written, it's a machine that completely disregards what comes in, and always spits out the same thing.
If you want to only replace a particular login error message, you would first have to check the existing text (the input to your filter machine) to see if it matched the one you want to replace, and then and only then would you return something else (otherwise returning the original argument's value).
function my_login_errors_function( $error ){
if( $error === 'The error message I want to replace' ){
return 'Error: Wrong Username or Password';
}
return $error;
}
add_filter( 'login_errors', 'my_login_errors_function' );
Likely what's happening is that plugin is using a login error to display the count, but since your function is overwriting every error message, that count is getting overwritten.

How can I add server field to post on data in PHP?

Welcome to use the WordPress template developer allows the addition of servers to watch movies I have some problems are when you add a server and update the article is updated but returns the right empty or not added and then when you delete the server is not deleted I checked the error record and this is the result
[21-Sep-2018 10:42:50 UTC] PHP Warning: array_combine() expects parameter 2 to be array, boolean given in /home3/mysite/public_html/wp-content/themes/movie/functions.php on line 154
File functions.php
https://3bdo.info/functions.zip
The linked zip file seams to be broken so I cannot extract the file.
But in general the error message says, that you have to use two arrays to call array_combine. You seam to try to combine an array (which is like a list) and a boolean (which is like yes/no). And that is not possible.
$android_servers_title2 = servers_get_meta( 'android_download_server_title' );
$android_servers_code2 = servers_get_meta( 'android_download_server_link' );
/* foreach($servers_title as $server_title)
{
echo "<label for='servers_server_title'>Server Title</label>";
echo " <br><input type='text' name='servers_server_title[]' id='servers_server_title' value='" . $server_title . "'><br>";
} */
if($android_servers_title2){
$android_arraye2 = array_combine($android_servers_title2, $android_servers_code2);
}else {
$android_arraye2 = false;
}
This is basically your problem. servers_get_meta is returning 'false' I would imagine. Check that 'android_download_server_link' is set. you may wish to change the if statement code to detect a false
if($android_servers_title2 && $android_servers_code2){

simple_html_dom: Call to a member function find() on a non-object in

This code has been working good for months. The output consisted of a few lines containing statistics for a given username. The website from which the html page is taken is not down, and the content of the page in file_get_html hasn't changed.
All of a sudden (I checked and nobody modified it) it stopped working. Here's the relevant part:
[...]if ($FileAge > ($expiretime * 60) || 0 == filesize($cachename))
{
include_once('simple_html_dom.php');
$html = file_get_html('http://www.foo.com/search?what=user%3A'.YOUR_USER.'&search=Search');
var_dump($html); //TEST
$link = $html->find('.likeh4 lightGrey.', 0)->find('a', 0)->href; // Get the last activity link
[...]
The error log says:
[02-Feb-2013 17:02:19 Europe/Berlin] PHP Fatal error: Call to a member function find() on a non-object in /foo.php on line 22 (the line with $link).
var_dump($html) gives bool(false)
I have a similar script which parses an html page from another website. It stopped working as well.
[...]include_once('simple_html_dom.php');
$html = file_get_html('http://my.flightmemory.com/'.FLIGHTMEMORY_USER);
$chilometri_table = $html->find('table', 2); [...]
I tried to save on my webserver one of those html pages and I don't get such error.
Did my host disable some php function for security reasons? (actually, file_get_html comes from simple_html_dom and not from php native functions)
Any hints?
Thanks
It is probably way too late but:
Simple_html_dom has a constant to check given html size - MAX_FILE_SIZE. by default it's 600KB. It's enough for most cases, but if your given html is bigger than that, it will fail and returns false and causes that fatal error.
If you try to get [href]
I had same problem and fixed it.
need valid it's a simple_html_dom_node
if(is_a($html->find('.likeh4 lightGrey. a', 0),'simple_html_dom_node' )
$link = $html->find('.likeh4 lightGrey. a', 0)->href;
OR
foreach ( $$html->find('.likeh4 lightGrey. a') as $links ) {
$link =$links->href;
}

Module field with feeds, module generating data

I have an issue with triming a field before it is saved. I wanted to use substr(), or regex() with preg_match(). I have built a Drupal 7 module, but it can't work at all. I have tried using the trim plugin in feeds tamper module, but it doesn't seem to work. The data I am using is from a feed from Google Alerts. I have posted this issue here.
This is what I have done so far, and I know my regular expression is wrong; I was trying to get it do anything, just to see if I could get it to work, but I am pretty lost on how to add this type of function to a Drupal module.
function sub_node_save() {
$url = $node->field_web_screenhot['und'][0]['url'];
$url = preg_match('~^(http|ftp)(s)?\:\/\/((([a-z0-9\-]*)(\.))+[a-z0-9]*)($|/.*$)~i',$url );
$node->field_web_screenhot['und'][0]['url'] =$url;
return ;
}
I used the Devel module to get the field.
If there's an easy way to use substr(), I would consider that or something else.
Basically, I just want to take the Google redirect off the URL, so it is just the basic URL to the web site.
Depending on your question and later comments, I'd suggesting using node_presave hook (http://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_presave/7) for this.
It's called before both insert (new) and update ops so you will need extra validations to prevent it from executing on node updates if you want.
<?php
function MYMODULE_node_presave($node) {
// check if nodetype is "mytype"
if ($node->type == 'mytype'){
// PHP's parse_url to get params set to an array.
$parts = parse_url($node->field_web_screenhot['und'][0]['url']);
// Now we explode the params by "&" to get the URL.
$queryParts = explode('&', $parts['query']);
$params = array();
foreach ($queryParts as $param) {
$item = explode('=', $param);
$params[$item[0]] = $item[1];
}
//valid_url validates the URL (duh!), urldecode() makes the URL an actual one with fixing "//" in http, q is from the URL you provided.
if (valid_url(urldecode($parms['q']))){
$node->field_web_screenhot['und'][0]['url'] = urldecode($parms['q']);
}
}
}

Resources