admin管理员组

文章数量:1279014

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

<?php
/*
Plugin Name: Integração Pagarme Dokan
Description: Integrar os plugins pagarme para woocommerce e pix pagarme com o dokan
Author: Guilherme Marchesan
Version: 1.0.0
Text Domain: integracao-pagarme-dokan
*/

if(!defined('ABSPATH')){
    die('Invalid request.');
}

include "functions.php";
include "pagarme-functions.php";

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();
    }
}

if(class_exists('PagarmeDokan')){ 
    $PagarmeDokanPlugin = new PagarmeDokan(); 
    register_activation_hook(__FILE__, array($PagarmeDokanPlugin, 'activate'));   
}

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.

本文标签: Error using wordpress functions inside a plugin class