Jestem nowy w tworzeniu wtyczek.Wordpress Plugin Dev: Błąd krytyczny: wywołanie niezdefiniowanej funkcji add_action()
Próbuję utworzyć niestandardową stronę formularza do wydrukowania w wp-admin, aby utworzyć adres pocztowy klienta.
bardzo podobny This plugin
gdy administrator kliknij "druku Adres" link pop-up template.php
strona z adresem klienta i informacje o adresie druku
problem jest:
Występuje błąd krytyczny po kliknięciu na kolejność drukowania tag kotwica i nie mogę uruchomić dowolną wordpress
działania na template.php
:
Fatal error: Zadzwoń do niezdefiniowanej funkcji add_action() w C: \ xampp \ htdocs \ wp-content \ plugins \ generator adresu \ template.php na linii 4
<?php
/**
* Plugin Name: Address Generator
* Plugin URI: http://CGTV.ir
* Description:Generate Postal Label for Parcel
* Version: 1.0 or
* Author: Hamed Mayahian
* Author URI: CGTV.ir
* License: A "Slug" license name e.g. GPL12
*/
// ADDING COLUMN TITLES (Here 2 columns)
/*define('MY_PLUGIN_PATH', plugin_dir_path(__FILE__));
include(MY_PLUGIN_PATH . 'template.php');
*/
require_once(ADDRESS__PLUGIN_DIR .'template.php');
add_filter('manage_edit-shop_order_columns', 'custom_shop_order_column',11);
function custom_shop_order_column($columns)
{
//add columns
$columns['my-column1'] = __('چاپ آدرس','theme_slug');
return $columns;
}
// adding the data for each orders by column (example)
add_action('manage_shop_order_posts_custom_column' , 'cbsp_credit_details', 10, 2);
function cbsp_credit_details($column)
{
global $post, $woocommerce, $the_order;
$order_id = $the_order->id;
switch ($column)
{
case 'my-column1' :
$myVarOne = wc_get_order_item_meta($order_id, '_the_meta_key1', true);
echo $myVarOne;
echo "<a target='_blank' href='".plugins_url('template.php' , __FILE__)."?order=$order_id'>Print Address</a>";
break;
}
}
Template.php
<?php
add_action('init', 'my_init', 1);
function my_init(){
global $post, $woocommerce, $the_order;
$id = $_GET['order'];
$order = new WC_Order($id);
$address = $order->get_billing_address();
$customer_id = get_current_user_id();
if($_GET['order'] == "") {
// no username entered
echo "آدرس پیدا نشد";
} else {
echo "Hello, " . $address;
}
}
?>
Proszę wyjaśnić, co robi plik template.php? Nie jest jasne, co chcesz osiągnąć. Dlaczego nie możesz go mieć w tym samym pliku co plik wtyczki? Radziłbym również załadować całą wtyczkę na hak 'woocommerce_loaded', dzięki czemu będziesz mieć pewność, że wszystkie funkcje WooCommerce są gotowe. – helgatheviking
Możliwy duplikat [this] (http://stackoverflow.com/questions/3947979/fatal-error-call-to-undefined-function-add-action?rq=1) lub [this] (http: // stackoverflow .com/questions/32094471/wordpress-plugin-how-to-resolve-call-to-undefined-function-add-action-as-wel? rq = 1) – helgatheviking
@helgatheviking both not work – Radian