亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Call variables outside plugin files and inside function files
P粉798343415
P粉798343415 2023-07-17 18:42:42
0
1
555

I use the YITH WooCommerce comparison plugin and I will put the file containing the code relevant to my question:

https://file.io/StHr7KBJBdxF

$current_cat variable has been set equal to: public$current_cat=array() $this->current_cat has been used in some parts of the code, how to call $this-> outside the file and in the function file ;current_cat?

class YITH_Woocompare_Frontend_Premium extends YITH_Woocompare_Frontend {

    …

    /**
     * The list of current cat inside the comparison table
     *
     * @since 1.0.0
     * @var array
     */
    public $current_cat = array();

For example: $this->products_list; is used, if I want to call it outside the file and in the function file, it is like this: $products_list=isset($_COOKIE[get_COOKIE_name()])? json_decode(wp_unslash($_COOKIE[get_COOKIE_name()]): array();

I hope you understand what I mean. If this is a beginner question, please don't diss because not everyone is as professional as you. Furthermore, I spent a lot of time solving this problem. I'm not trying to ask a quick question here to find a quick answer.

P粉798343415
P粉798343415

reply all(1)
P粉262113569

您的current_cat是由您的插件定義的類的公共屬性。

在該類的函數(shù)中,代碼可以使用$this->current_cat來訪問該屬性。為什么?在該類的代碼中,$this是指向該類當(dāng)前實(shí)例的引用。->對象操作符告訴php在$this內(nèi)查找。

在該類的代碼之外,您可以通過以下方式訪問公共屬性。

$my_object = new PluginClass();
$cat = $my_object->current_cat;
您正在嘗試執(zhí)行示例的第二行中顯示的操作。要執(zhí)行此操作,您需要訪問第一行返回的new PluginClass()變量。不同的插件有不同的方法來使這種類型的信息可用于主題代碼(functions.php)。必須查看插件的代碼以確定如何執(zhí)行此操作,或查看文檔,或咨詢插件的支持論壇。

恕我直言,解釋php類的工作原理對于Stack Overflow的答案來說太復(fù)雜了。解釋W(xué)ordPress、插件和主題代碼的交互方式也是如此。我希望這個答案能為您指明一個有用的方向。


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template