Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>$this refers to the current class context. So if you have a class named MyClass, within that class you can access functions and elements using $this. Outside of that class, $this has no context and won't work, but if you have instantiated the class and if the functions or variables are public, then you can access them via a reference to the class. </p> <p>Example:</p> <pre><code>&lt;?php Class MyClass { $class_var = "Class Var Value"; function class_func_1() { print $this-&gt;class_var; $this-&gt;class_func_2(); } function class_func_2() { print "Class Func 2"; } } ?&gt; </code></pre> <p>So the dummy class above uses $this to reference its own elements. But outside the class you cannot reference them with this. But if we instantiate an instance of the class, we can access them by the reference to the instance of the class:</p> <pre><code>&lt;?php print $this-&gt;class_var; // Fails miserably $this-&gt;class_func_1(); // Also fails $class_instance = new MyClass(); print $class_instance-&gt;class_var; // Var access works $class_instance-&gt;class_func_1(); // Call method works ?&gt; </code></pre> <p>Since this is a wordpress function, I'm curious if you are trying to access something in a plugin (which might use a class) or possibly something in a purchased theme. Either way, there should be a reference to the instance of the class somewhere in the file. Once you have this variable, then you can access the actions and contents of the class.</p> <p>With more information, I think we can probably provide better direction...</p> <hr> <p>Update:</p> <p>Ok, it appears you are using the subscribe2 plugin. At the bottom of the plugin file (<code>subscribe2.php</code>) is this line:</p> <pre><code>$mysubscribe2 = new subscribe2(); </code></pre> <p>What this is doing is creating a global variable that points to an instance of the class. So instead of using <code>$this-&gt;method_name()</code> you could use <code>$mysubscribe2-&gt;method_name()</code>.</p> <p>However, looking at the file you posted - it almost looks like you grabbed a portion of the plugin code and just put it into a template. I'm not sure what you are trying to accomplish but from here it appears you are heading down a rough path...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload