如何使用会话/函数或javascript将变量从插件php传递到wordpress中的另一个php文件? [英] how to pass variable from plugin php to another php file in wordpress using session/function or javascript?

查看:65
本文介绍了如何使用会话/函数或javascript将变量从插件php传递到wordpress中的另一个php文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插件文件testplugin.php ..它包含变量$ abc;

I have oneplugin file testplugin.php..It contains variable $abc;

//main plugin.php

//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_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;
 );
}

///正在接收文件

include ('testplugin.php'); 
session_start();
$array1[]=$abc;

现在$ abc来自主插件页面

Now this $abc is from main plugin page

但是我收到此错误

致命错误:在第98行的C:\ wamp \ www \ wordpress \ wp-content \ plugins \ testplugin.php中调用未定义的函数is_admin()

在98行中,我有 if(!is_admin()){

on 98 line i have if(!is_admin()){

推荐答案

使用会话:

//在testplugin.php上

//On testplugin.php

session_start();
$_SESSION['varname'] = $var_value;

//在另一个文件上

session_start();
$var_value = $_SESSION['varname'];

使用Cookie:

//在testplugin.php上

//On testplugin.php

$_COOKIE['varname'] = $var_value;

//第2页

$var_value = $_COOKIE['varname'];

这篇关于如何使用会话/函数或javascript将变量从插件php传递到wordpress中的另一个php文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆