Error using wordpress functions inside a plugin class

Question

Hy! In my plugin activation class i used wordpress functions (get_user_meta, update_user_meta)

class PagarmeDokan{

    private $functions;
    
    public function __construct(){
        $this->functions = new PagarmeDokanFunctions();
        $this->functions->check_pagarme_plugins();
        $sellers = $this->functions->get_sellers();
        foreach ($sellers as $sellerObj) {
            if(get_user_meta($sellerObj->ID, 'banco_saldo_disponivel', true) == null){
                update_user_meta($sellerObj->ID, "banco_saldo_disponivel", 0);
            }
            if(get_user_meta($sellerObj->ID, 'banco_saldo_futuro', true) == null){
                update_user_meta($sellerObj->ID, "banco_saldo_futuro", 0);
            } 
        }
        $this->create_options();
        flush_rewrite_rules();
    }

And this error showed up:

Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /home/shotplacecom/public_html/wp-includes/capabilities.php:693 Stack trace: #0 /home/shotplacecom/public_html/wp-content/plugins/integracao-pagarme-dokan/functions.php(12): current_user_can(‘manage_options’) #1 /home/shotplacecom/public_html/wp-content/plugins/integracao-pagarme-dokan/integracao-pagarme-dokan.php(24): PagarmeDokanFunctions->set_users_bank() #2 /home/shotplacecom/public_html/wp-content/plugins/integracao-pagarme-dokan/integracao-pagarme-dokan.php(63): PagarmeDokan->__construct() #3 /home/shotplacecom/public_html/wp-settings.php(409): include_once(‘/home/shotplace…’) #4 /home/shotplacecom/public_html/wp-config.php(81): require_once(‘/home/shotplace…’) #5 /home/shotplacecom/public_html/wp-load.php(50): require_once(‘/home/shotplace…’) #6 /home/shotplacecom/public_html/wp-blog-header.php(13): require_once(‘/home/shotplace…’) #7 /home/shotplacecom/public_html/index.php(17): require(‘/home/shotplace…’) #8 {main} thrown in /home/shotplacecom/public_html/wp-includes/capabilities.php on line 693

I know I can use WordPress base functions in my plugin class functions, as we can see in this question Access wordpress functions inside a plugin class, but for me its not working and I don’t know why.

0
Guilhermezm 1 month 2021-10-26T14:51:20-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse