0

I want to save the time that the user activates a plugin. So I need to set the value within the function that the registration hook fires:

function ucme_reg_func () {
//------------other functions-------------
global $sega; 
$sega = new setTime();
$sega->theTimeis = time();}

setTime is a simple class that should hold the timestamp:

class setTime{
public $theTimeis;
public function settingTime($theTimeis) {
   $this->theTimeis = $theTimeis; 
}
public function getTime() { 
    return $this->theTimeis; 
}
}

I try to access the value $sega from a shortcode function:

function new_func() {
 global $post;
 global $sega;
 $now = $sega->getTime();
 //-------------------------
 var_dump($now);
 }

The error is : FATAL ERROR: CALL TO A MEMBER FUNCTION GETTIME() ON A NON-OBJECT IN ...

The same logic I applied in a pure php environment and it worked. I will welcome any help regarding how to set the timestamp right, as well as somebody to point me out what is my error in understanding the differences between Wordpress and PHP, which I suppose is the actual cause of this issue.

0

You'll have to use get- and add_option inside a register_activation_hook.

<?php
register_activation_hook(__FILE__,'save_activation_timestamp');
function save_activation_timestamp()
{
add_option("myplugin_activation_timestamp",mktime());
}
?>

You can find an entire tutorial on that at CodeYoghurt. It even mentions your case as an example.

  • Answers should be more than just plain links. Please post all relevant info/code from the link and keep the link only as credit – Pieter Goosen Nov 24 '14 at 12:35
  • I am really glad that a proper answer was found, because proper answer was I looking for :) – Dejan Toteff Nov 24 '14 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.