如何使用会话/函数或javascript将变量从插件php传递到wordpress中的另一个php文件?
我有一个插件文件testplugin.php..它包含变量$abc //main plugin.php如何使用会话/函数或javascript将变量从插件php传递到wordpress中的另一个php文件?,php,plugins,wordpress,Php,Plugins,Wordpress,我有一个插件文件testplugin.php..它包含变量$abc //main plugin.php if(!is_admin()){ new Funtion_Button(); } class Function_Button { if(is_single() || is_page() || is_home() ){ global $post; global $wpdb; $query_images_args = array( 'post_typ
if(!is_admin()){
new Funtion_Button();
}
class Function_Button
{
if(is_single() || is_page() || is_home() ){
global $post;
global $wpdb;
$query_images_args = array(
'post_type' => 'attachment' , 'post_mime_type' =>'image','post_status' => 'published', 'posts_per_page' => -1,'numberposts' => 1
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= wp_get_attachment_url( $image->ID );
}
$abc[]=0;
$abc= $abc.http_build_query($images);
$_SESSION['arrayImg']=$abc;
);
}
session_start();
$_SESSION['varname'] = $var_value;
$_COOKIE['varname'] = $var_value;
///接收文件
include ('testplugin.php');
session_start();
$array1[]=$abc;
现在这个$abc来自主插件页面
但我得到了这个错误
致命错误:对未定义函数的调用是第98行C:\wamp\www\wordpress\wp content\plugins\testplugin.php中的\u admin()
在98行中,我有如果(!is_admin()){
使用会话:
//关于testplugin.php
if(!is_admin()){
new Funtion_Button();
}
class Function_Button
{
if(is_single() || is_page() || is_home() ){
global $post;
global $wpdb;
$query_images_args = array(
'post_type' => 'attachment' , 'post_mime_type' =>'image','post_status' => 'published', 'posts_per_page' => -1,'numberposts' => 1
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= wp_get_attachment_url( $image->ID );
}
$abc[]=0;
$abc= $abc.http_build_query($images);
$_SESSION['arrayImg']=$abc;
);
}
session_start();
$_SESSION['varname'] = $var_value;
$_COOKIE['varname'] = $var_value;
//在另一个文件上
session_start();
$var_value = $_SESSION['varname'];
使用cookies:
//关于testplugin.php
if(!is_admin()){
new Funtion_Button();
}
class Function_Button
{
if(is_single() || is_page() || is_home() ){
global $post;
global $wpdb;
$query_images_args = array(
'post_type' => 'attachment' , 'post_mime_type' =>'image','post_status' => 'published', 'posts_per_page' => -1,'numberposts' => 1
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= wp_get_attachment_url( $image->ID );
}
$abc[]=0;
$abc= $abc.http_build_query($images);
$_SESSION['arrayImg']=$abc;
);
}
session_start();
$_SESSION['varname'] = $var_value;
$_COOKIE['varname'] = $var_value;
//第2页
$var_value = $_COOKIE['varname'];
阅读此文,谢谢@pranshu它起作用了。我不需要在第二页包含testplugin.php???@user1145009不,你不需要在下一页包含testplugin.php,因为你正在使用cookies和session,cookies和session的值临时存储在浏览器中。因此,不需要包含用于传递此变量的值。我正在尝试ng在localhost中它工作了..但是现在我已经在wordpress主题上使它联机..sesion变量没有存储。。