2017-07-04 1 views
-1

Ich kann nicht die wp_verify_nonce Methode im WordPress-Plugin verwenden.Wordpress: Aufruf zu undefinierter Funktion wp_verify_nonce() in benutzerdefinierten Plugin

Ich bekomme den fatalen Fehler: Call to undefined function wp_verify_nonce().

Ich versuchte veröffentlichen die Methode ohne private function submit_form() Erfolg

<?php 

/* 
* Frontend class. 
* 
* Method and property for frontend section. 
* 
* @since 1.0 
* 
*/ 

namespace Simplestform; 

class Frontend extends \Simplestform\Base { 

    /** 
    * Our constructor. 
    * 
    * 
    */ 

    public function __construct($base_dir = null) { 

     parent::__construct(); 

     if (!is_null ($base_dir)) { 

      /* 
      * Call Base function to set the base dir 
      */ 

      $this->set_base_dir($base_dir); 

     } 

     /* 
     * 
     * Register shortcode 
     * 
     */ 
     $this->add_shortcode(); 
     $this->submit_form(); 

    } 

    /** 
    * Register the shortcode 
    * 
    * @since 1.0 
    */ 

    private function add_shortcode() { 

     add_shortcode($this->get_shortcode_tag() , array ($this , 'render_contact_form')); 

    } 

    public function render_contact_form() { 

     include_once ($this->get_base_dir().'/views/frontend/basic-form.php'); 

    } 

    private function submit_form() { 

     if (isset ($_POST['_wpnonce'])) { 

      $nonce = $_POST['_wpnonce']; 

      wp_verify_nonce ($nonce , 'test_nonce_field'); 

      echo '<pre>'; 
      var_dump ($_POST); 
      echo '</pre>'; 

     } 


    } 


} 
+1

Check [diese Antwort] (https://wordpress.stackexchange.com/questions/21014/cant-access-some-worpress-function-from-my- Plugin) – Picard

Antwort

1

wp_verify_nonce() ist eine Kernfunktion Wordpress zu machen. Viele WP-Funktionen sind zu keinem Zeitpunkt verfügbar.

Wenn ich ein wenig darüber nachdenke, wie Wordpress funktioniert, muss ich annehmen, dass Sie Ihre Funktion in die Wordpress-Sequenz einbinden müssen. Versuchen Sie, Ihre Plugin-Funktion in admin_init zu hängen.

add_action ('hook_name', 'your_function_name', [priority], [accepted_args]); 

Einige gute necesary Lesung: Wordpress - Plugin API

Verwandte Themen