Hei everybody. Maybe someone could give me some tips , because I am stuck on this for second day.
function get_url_id() {
$_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_NUMBER_INT);
$data = $_GET['id'];
$final= xss_clean($data); // function to prevent xss, working
return $final;
}
function relax() {
;
}
function show_order_details_created_date() {
if( $user = wp_get_current_user() ){
$order_id= get_url_id();
if(!isset($order_id)) { relax(); } else {
$order = wc_get_order ($order_id);
$date=$order->get_date_created();
$date_mod=explode("T" , $date);
return $date_mod[0];
}
}
}
Wordpress is giving me critical error , that I can not even open to edit page section. If instead of $order_id I insert existing order number ITS WORKS ABSOLUTELY fine. If I print out variable it also shows ID without problem. Why I can not use variable here? Any hints, guys?
Related
The following custom avatar functions works fine, but I get the following notice
"Trying to get property of non-object in..."
The notice says the problem is on the last part of the function I pasted here - I marked it in the code (look for <-- Notice mentions this line)
Any idea how to fix this? I am stuck...
function test_get_avatar($avatar, $id_or_email, $size, $default, $alt) {
if (!is_numeric($id_or_email)) {
if (is_string($id_or_email)) {
$user = get_user_by('email', $id_or_email);
$id_or_email = $user->ID;
} else if (is_object($id_or_email)) {
if (!empty($id_or_email->ID)) {
$id_or_email = $id_or_email->ID;
}
if (!empty( $id_or_email->comment_author_email)) {
$user = get_user_by('email', $id_or_email->comment_author_email);
$id_or_email = $user->ID; <-- Notice mentions this line
}
}
}
$avatar_id = get_user_meta($id_or_email, 'nicobartes_user_avatar', true);
...
Yes, because get_user_by() can fail and return false. At that point you won't have a wp user object. A test around this code would be:
if ($user = get_user_by('email', $id_or_email->comment_author_email)) {
$id_or_email = $user->ID;
} else {
//Whatever you want to do when this lookup fails
$id_or_email = 0;
}
When you run
$user = get_user_by('email', $id_or_email->comment_author_email);
You should check the value of $user before attempting to get the id on the next line. According to the Wordpress docs, it could potentially be false if no user is found.
I have situation where codeigniter shows database Error Number 1048. It seems Values NULL but when I try to check it usign var_dump($_POST) Values are not NULL.
Controller : Jurusan.php
public function simpan()
{
$this->form_validation->set_rules('code','Kode','required|integer');
$this->form_validation->set_rules('jurusan','Jurusan','required');
$this->form_validation->set_rules('singkatan','Singkatan','required');
$this->form_validation->set_rules('ketua','Ketua','required');
$this->form_validation->set_rules('nik','NIK','required|integer');
$this->form_validation->set_rules('akreditasi','Akreditasi','required');
if($this->form_validation->run() == FALSE)
{
$isi['content'] = 'jurusan/form_tambahjurusan';
$isi['judul'] = 'Master';
$isi['sub_judul'] = 'Tambah Jurusan';
$this->load->view('tampilan_home',$isi);
} else {
$this->model_security->getSecurity();
$key = $this->input->post('code');
$data['kd_prodi'] = $this->input->post['code'];
$data['prodi'] = $this->input->post['jurusan'];
$data['singkat'] = $this->input->post['singkatan'];
$data['ketua_prodi'] = $this->input->post['ketua'];
$data['nik'] = $this->input->post['nik'];
$data['akreditasi'] = $this->input->post['akreditasi'];
$this->load->model('model_jurusan');
$query = $this->model_jurusan->getdata($key);
if($query->num_rows()>0)
{
$this->model_jurusan->getupdate($key,$data);
} else {
$this->model_jurusan->getinsert($data);
}
redirect('jurusan');
}
}
Model : model_jurusan.php
class Model_jurusan extends CI_model {
public function getdata($key)
{
$this->db->where('kd_prodi',$key);
$hasil = $this->db->get('prodi');
return $hasil;
}
public function getupdate($key,$data)
{
$this->db->where('kd_prodi',$key);
$this->db->update('prodi',$data);
}
public function getinsert($data)
{
$this->db->insert('prodi',$data);
}
}
Here is the error shown :
Here is the database structure :
You have a wrong syntax in these lines:
$key = $this->input->post('code');
$data['kd_prodi'] = $this->input->post['code']; // <-- use ('code')
$data['prodi'] = $this->input->post['jurusan']; // <-- use ('jurusan')
Change this to
$this->input->post['array_key'];
this
$this->input->post('array_key');
Read : Input Class in Codeigniter
Well the problem lies in your way of accepting input parameters.
$this->input->post
is a method which accepts the variable name, not an array. So all the input parameters need to be passed as a function parameter to post method. These lines need to be altered to.
$data['kd_prodi'] = $this->input->post('code');
$data['prodi'] = $this->input->post('jurusan');
$data['singkat'] = $this->input->post('singkatan');
$data['ketua_prodi'] = $this->input->post('ketua');
$data['nik'] = $this->input->post('nik');
$data['akreditasi'] = $this->input->post('akreditasi');
Hope this solves the problem.
EDIT:
You did a var_dump($_POST) which works as it is supposed to and it will read the values of the post parameters. So either you fetch the parameters from $_POST array, or you use the $this->input->post() method. But I would suggest using the $this->input->post() method as it provides additional sanitization such as xss attack handling etc, which could be turned on an off from the config.
i have tried your code...it works. I think there some mistakes in your <input> tags, You must use <input name=""> not <input id=""> or something else. Hope it can help you out
You are try to get value from post is wrong. You should use at this way
$_POST['array value'];
So the problem is that the keys I want to delete from memcached are actually not being removed. I get no errors. At this point I don't really have a clue what the problem could be. It also shows the correct key it wants to delete so there is nothing wrong with that.
Down below my Class for using memcached, does anybody have any clue on what the problem might be? So far I didn't find any clues on what the problem might be or how to fix the problem.
class MemCacher extends Memcached{
function __construct(){
parent::__construct();
parent::addServer(MEMCACHED_SERVER,11211,1);
}
function add($p_sKey,$p_oData,$p_iTime = 43200){
$t_sKey = CACHE_NAME.$p_sKey;
parent::set($t_sKey,$p_oData,$p_iTime);
}
function get($p_sKey){
$t_sKey = CACHE_NAME.$p_sKey;
return parent::get($t_sKey);
}
function remove($p_sKey){
$t_sKey = CACHE_NAME.$p_sKey;
parent::delete($t_sKey);
debug("Deleted:".$t_sKey);
}
function show_all(){
if( $l_aCacheInfo = parent::getAllKeys() ){
foreach($l_aCacheInfo as $key){
if( strpos($key, CACHE_NAME) !== FALSE ){
debug($key);
}
}
}
}
function clear_all(){
if( $l_aCacheInfo = parent::getAllKeys() ){
foreach($l_aCacheInfo as $key){
if( strpos($key, CACHE_NAME) !== FALSE ){
parent::delete($key);
debug("Deleted:".$key);
}
}
}
}
}
So apparently the delete method requires the expiration time to be 0 in order to remove it else it doesn't work.
doesn't work
parent::delete($t_sKey);
works
parent::delete($t_sKey,0);
I'm trying to create callback script for Coinbase bitcoin payments. Here is the below function from my payment controller. But somehow the key isn't working as it should. I am trying to access it like that: http://www.example.com/payments/callback?key=true but it's not getting affected basically not working. Take a note that the script is working itself but after adding the key function and validating it ... it's not anymore. The issue is caused by that but I don't know what exactly, so what may cause that in the script below?
Thanks for taking the time to check and possibly answer my question.
function is_valid_key($key) {
// logic to check key
$valid = true;
if($valid) {
return true;
}
else {
return false;
}
}
function callback()
{
//Check if key is valid.
$key = $this->input->get('key');
if( ! $this->is_valid_key($key)) {
//If key above is valid order is "completed", please proceed.
$data = json_decode(file_get_contents('php://input'), TRUE);
$status = $data['order']['status'];
$userid = '507';
if (($status === 'completed')) {
$this->db->query( 'update users set user_money=user_money+15, user_credits=user_credits+5 WHERE users_id=' . $userid );
}
}
}
it has to do with your configuration settings. check out this question Enabling $_GET in codeigniter
Also you can use
parse_str($_SERVER['QUERY_STRING'], $_GET);
which would push GET right back on
I have to search for multiple values in a field using mysql in codeigniter. Here follows my code.
In Controller
public function vpsearch()
{
$data['info'] = $this->psearch_m->emp_search_form();
$this->load->view("employer/result",$data);
}
IN Model
public function emp_search_form()
{
$skill = $this->security->xss_clean($this->input->post('ps_skills'));
$jrole = $this->input->post('ps_jobrole'));
if ( $jrole !== NULL)
{
return $this->db->get('js_edu_details');
$this->db->like('js_skills','$skill');
}
}
In view i.e, (../employer/result)
foreach($info->result() as $row)
{
echo $row->js_id."<br/><br/>" ;
}
However I am getting all the records in 'js_edu_details' table instead of fields having searched 'skills'.
Where I am going wrong? Any help wud b appreciated, thanx in advance.
Try:
public function emp_search_form()
{
$skill = $this->security->xss_clean($this->input->post('ps_skills'));
//$skill = $this->input->post('ps_skills', true); other short way of getting the above result with `xss clean`
if ( $jrole !== NULL)
{
$this->db->like('js_skills',$skill); #remove the single quote around the `$skill`
$res = $this->db->get('js_edu_details');
echo $this->db->last_query(); #try to print the query generated
return $res;
}
}
Return statement should be after the like statement
You should arrange the code properly like this
public function emp_search_form()
{
$ps_skills = $this->input->post('ps_skills')
$skill = $this->security->xss_clean($ps_skills);
if ( $jrole !== NULL)
{
$this->db->like('js_skills','$skill');
return $this->db->get('js_edu_details');
}
}
Also you should note the condition will never meet. It will always give error undefined variable $jrole