Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Plugins 调用未定义的函数add_action()_Plugins_Wordpress - Fatal编程技术网

Plugins 调用未定义的函数add_action()

Plugins 调用未定义的函数add_action(),plugins,wordpress,Plugins,Wordpress,我正在开发一个自定义注册表的插件。我有第一个文件customapplicationform.php文件,其他文件在side registration和shortcode文件夹中。 我的插件目录结构如下: --->customapplicationform |--js |--ajax-registration.js |--registration |--registration.php |--regsubmit.php

我正在开发一个自定义注册表的插件。我有第一个文件customapplicationform.php文件,其他文件在side registration和shortcode文件夹中。 我的插件目录结构如下:

  --->customapplicationform 
    |--js
        |--ajax-registration.js
    |--registration  
       |--registration.php
       |--regsubmit.php
       |--scripts.php  
   |--shortcode 
       |--display.php 
       |--shortcodes.php            
--customApplicationForm.php

这是一个错误:

 Fatal error: Call to undefined function add_action() in     E:\xampp\htdocs\aism\wp-content\plugins\customapplicationform\registration\scripts.php on line 17
请告诉我这有什么问题?如果有比建议我更好的方法。提前谢谢

1) 这是我的
customapplicationform.php
文件

require_once(ABSPATH.'wp-admin/includes/plugin.php');


ob_start();

global $app_db_version;
$app_db_version = '1.0';


function app_install() {

global $wpdb;
global $app_db_version;

$table_name = $wpdb->prefix .'registeration';

 $charset_collate = $wpdb->get_charset_collate();

$sql = "CREATE TABLE $table_name (
    regid mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    fname varchar(50) NOT NULL,
            lname varchar(50) NOT NULL,
            email varchar(50) NOT NULL,
            phno  int(12) NOT NULL,
    PRIMARY KEY(regid)
) ";

require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );

add_option( 'app_db_version', $app_db_version );
}
register_activation_hook( __FILE__, 'app_install');
include_once('/shortcode/shortcodes.php');
 function shortcode_function( $atts ) {
    $plugin_dir_path = dirname(__FILE__);
    include_once('display.php');
    $data = ob_get_clean();
    return $data; 
  }
 add_shortcode( 'custom-application', 'shortcode_function' );
    include_once(''.dirname(dirname(__FILE__)).'/registration/registration.php');
require_once('scripts.php');
  // Verify nonce
 if( ! wp_verify_nonce( $_POST['app_new_user_nonce'], 'app_new_user' ) )
 {
  die( 'Ooops, something went wrong, please try again later.' );
 }
else {

if(isset($_POST['appemail'])) {
// Post values
echo $fname = $_POST['appfname'];
echo  $lname = $_POST['applname'];
echo  $email    = $_POST['appemail'];
echo  $phone     = $_POST['appphone'];

$userdata = array(
    'fname' => $fname,
    'lname'  => $lname,
    'email' => $email,
    'phno' => $phone,

 );

$user_id = wp_insert_user( $userdata ) ;

// Return
   if( !is_wp_error($user_id) ) {
         echo '1';
     } else {
        echo $user_id->get_error_message();
     }
  }
 }
2) 这是我的
shortcodes.php
文件

require_once(ABSPATH.'wp-admin/includes/plugin.php');


ob_start();

global $app_db_version;
$app_db_version = '1.0';


function app_install() {

global $wpdb;
global $app_db_version;

$table_name = $wpdb->prefix .'registeration';

 $charset_collate = $wpdb->get_charset_collate();

$sql = "CREATE TABLE $table_name (
    regid mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    fname varchar(50) NOT NULL,
            lname varchar(50) NOT NULL,
            email varchar(50) NOT NULL,
            phno  int(12) NOT NULL,
    PRIMARY KEY(regid)
) ";

require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );

add_option( 'app_db_version', $app_db_version );
}
register_activation_hook( __FILE__, 'app_install');
include_once('/shortcode/shortcodes.php');
 function shortcode_function( $atts ) {
    $plugin_dir_path = dirname(__FILE__);
    include_once('display.php');
    $data = ob_get_clean();
    return $data; 
  }
 add_shortcode( 'custom-application', 'shortcode_function' );
    include_once(''.dirname(dirname(__FILE__)).'/registration/registration.php');
require_once('scripts.php');
  // Verify nonce
 if( ! wp_verify_nonce( $_POST['app_new_user_nonce'], 'app_new_user' ) )
 {
  die( 'Ooops, something went wrong, please try again later.' );
 }
else {

if(isset($_POST['appemail'])) {
// Post values
echo $fname = $_POST['appfname'];
echo  $lname = $_POST['applname'];
echo  $email    = $_POST['appemail'];
echo  $phone     = $_POST['appphone'];

$userdata = array(
    'fname' => $fname,
    'lname'  => $lname,
    'email' => $email,
    'phno' => $phone,

 );

$user_id = wp_insert_user( $userdata ) ;

// Return
   if( !is_wp_error($user_id) ) {
         echo '1';
     } else {
        echo $user_id->get_error_message();
     }
  }
 }
3) 这是我的
display.php
文件

require_once(ABSPATH.'wp-admin/includes/plugin.php');


ob_start();

global $app_db_version;
$app_db_version = '1.0';


function app_install() {

global $wpdb;
global $app_db_version;

$table_name = $wpdb->prefix .'registeration';

 $charset_collate = $wpdb->get_charset_collate();

$sql = "CREATE TABLE $table_name (
    regid mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    fname varchar(50) NOT NULL,
            lname varchar(50) NOT NULL,
            email varchar(50) NOT NULL,
            phno  int(12) NOT NULL,
    PRIMARY KEY(regid)
) ";

require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );

add_option( 'app_db_version', $app_db_version );
}
register_activation_hook( __FILE__, 'app_install');
include_once('/shortcode/shortcodes.php');
 function shortcode_function( $atts ) {
    $plugin_dir_path = dirname(__FILE__);
    include_once('display.php');
    $data = ob_get_clean();
    return $data; 
  }
 add_shortcode( 'custom-application', 'shortcode_function' );
    include_once(''.dirname(dirname(__FILE__)).'/registration/registration.php');
require_once('scripts.php');
  // Verify nonce
 if( ! wp_verify_nonce( $_POST['app_new_user_nonce'], 'app_new_user' ) )
 {
  die( 'Ooops, something went wrong, please try again later.' );
 }
else {

if(isset($_POST['appemail'])) {
// Post values
echo $fname = $_POST['appfname'];
echo  $lname = $_POST['applname'];
echo  $email    = $_POST['appemail'];
echo  $phone     = $_POST['appphone'];

$userdata = array(
    'fname' => $fname,
    'lname'  => $lname,
    'email' => $email,
    'phno' => $phone,

 );

$user_id = wp_insert_user( $userdata ) ;

// Return
   if( !is_wp_error($user_id) ) {
         echo '1';
     } else {
        echo $user_id->get_error_message();
     }
  }
 }
4) 这是我的
registration.php
文件

  <form action="<?php echo plugins_url();>/customapplicationform/registration/regsubmit.php" method="Post">

<label>First Name:</label>
<input type="text" name="appfname" id="appfname" />

<label>Last Name :</label>
<input type="text" name="applname" id="applname" />

<label>Email :</label>
<input type="email" name="appemail" id="appemail" />

<label>Phone :</label>
<input type="tel" name="appphone" id="appphone" />

<?php// wp_nonce_field('app_new_user','app_new_user_nonce', true, true ); ?>

<input type="Submit" value="Submit" id="btn-new-user">


</form>
6) 这是我的
scripts.php
文件

  function app_register_user_scripts() {
    // Enqueue script
       wp_register_script('app_reg_script', dirname(__FILE__). '/js/ajax-          registration.js', array('jquery'), null, false);
    wp_enqueue_script('app_reg_script');

   wp_localize_script( 'app_reg_script', 'app_reg_vars',      array('app_ajax_url' => admin_url( 'admin-ajax.php' )));
     }
  add_action('wp_enqueue_scripts', 'app_register_user_scripts');

这是一个核心功能,如果您的代码通过WordPress激活并通过WordPress访问,则可以使用。如果您试图在WordPress作用域之外调用插件文件(例如,您直接从浏览器访问该文件),则add_操作不可用,除非您需要在WordPress根目录的文件顶部使用wp-load.php。

因为我们在$wp->init之前调用核心函数;我们需要包括pluggable.php

require_once(ABSPATH .'wp-includes/pluggable.php');

add\u action
在哪里定义?@ScottHunter,它是一个核心的WordPressfunction@ScottHunter我在scripts.php文件中使用了add_action函数将脚本排队。正如mevius所说,它是WordPress的核心功能。