2017-12-27 9 views
0

나는 WordPress 플러그인에 상당히 익숙하다. 그러나 사용자 정의 JavaScript를 내 페이지 헤더에 추가하는 간단한 플러그인을 만들었다.정의되지 않은 함수를 호출 add_action() wp_head

localhost의 내 WordPress 관리 페이지에서 플러그인을 실행하면 완벽하게 작동하지만 (내 기능은 그대로 유지) 내 IDE (phpStorm)의 플러그인에 오류가 있습니다. 나는이 오류의 원인이 될 수 있는지 아무 생각

PHP Fatal error: Uncaught Error: Call to undefined function add_action() in C:\xampp\htdocs\website1\wp-content\plugins\jade-plugin\jade-plugin.php:12 Stack trace: thrown in C:\xampp\htdocs\website1\wp-content\plugins\jade-plugin\jade-plugin.php on line 12

Fatal error: Uncaught Error: Call to undefined function add_action() in C:\xampp\htdocs\website1\wp-content\plugins\jade-plugin\jade-plugin.php:12 Stack trace: thrown in C:\xampp\htdocs\website1\wp-content\plugins\jade-plugin\jade-plugin.php on line 12

Process finished with exit code 255

하지만 난 내 디렉토리에있는 파일과 함께 할 수있는 뭔가가 생각 :

내가 오류입니다.

나는 또한 우리의 가족 사업에 대한 WordPress.org이 플러그인을 업로드하고 싶지만 나는 다음과 같은 오류가 플러그인을 업로드하려고하면 다음

The plugin has no name. Add a Plugin Name: line to your main plugin file and upload the plugin again.

내 플러그인은 지금까지입니다 :

<?php 
    /* 
    * Plugin Name: InSite 
    * Plugin URI: http://localhost 
    * Description: Adds javascript 
    * Version: 1.0 
    * Author: Jade 
    * License: GPL2 
    */ 

    /* This function adds two lines of javascript to the page header */ 

    add_action('wp_head', 'addHeader'); 

    function addHeader() 
    { 
     ?> 
     <script 
    src="http://app.insitesoftware.co.za:8080/socket.io/socket.io.js"> 
    </script> 
     <script src="http://app.insitesoftware.co.za:8080/client.js"> 
    </script> 

<?php 
    } 

    ; 

    ?> 

어떤 도움 너무 감사하겠습니다 :)

답변

0

을 당신은 워드 프레스는 표준과 기능을 코딩 사용해야합니다, 후크는 자바 스크립트를해야합니다 포함 할 wp_enqueue_scripts하지 wp_head. 다음은 스 니펫 함수입니다. 자세한 내용은 this을 참조하십시오.

function slug_cssinvolve() { 

     //for custom script 
     wp_register_script('custom-script', plugins_url('/js/custom-script.js', __FILE__)); 
     //for library 

     wp_register_script('custom-script', plugins_url('/js/custom-script.js', __FILE__), array('jquery')); 

} 
add_action('wp_enqueue_scripts', 'slug_cssinvolve');