Hope you all have been doing great...
I am here today to look for an answer to my issue...
I created a plugin and activated it, it does not create a table etc just simple php script.
<?php
/*
Plugin Name: F
Plugin URI: h
Description: T
Author: D
Author URI: h
*/
$server = "localhost";
$user = "admin";
$password = "";
$db = "wordpress";
$con = mysql_connect($server,$user,$password);
if (!$con) {
die("database connection error");
} else
{
mysql_select_db($db, $con);
$results = mysql_query("SELECT ID, post_title FROM wp_posts "
. "WHERE "
. "post_status = 'publish' "
);
while($row = mysql_fetch_array($results))
{
echo $row['post_title'];
}
}
the autocomplete code is as below
$("#imageSearch").autocomplete("<?php echo bloginfo('wpurl')."/wp-content/plugins/foxycomplete/"; ?>foxycomplete开发者_JAVA技巧.php", {
dataType: "json",
parse: function(data) {
return $.map(data, function(row) {
return {
data: row,
value: row.title,
result: $("#imageSearch").val()
}
});
}
}).result(function(e, item) {
location.href = link(item);
});
});
this is working but I am pretty sure that this is not the right way. I am not able to use the wp functions is the plugin script and also this seems unsafe and prone to hacking...
could anyone please help how I can get a php file to feed the autocomplete that can access wop functions and is safe?
Thanks a lot!
There's no such thing as a Plugin Page. The code above should probably be wrapped in a function and called from somewhere in a WordPress context, or it should be used in an action or a filter.
If you are accessing the plugin page directly rather than from within Wordpress, the problem might be that the $wpdb is not being initialized. This is done in the WordPress header, which is normally included on the page if you are inside of a Wordpress template. Try including wp-blog-header.php in your script with something like this:
include_once(‘wp-blog-header.php’);
精彩评论