how to pass variable from plugin php to another php file in wordpress using session/function or javascript?

假如想象 提交于 2019-12-12 00:49:34

问题


I have oneplugin file testplugin.php..It contains variable $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_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;
 );
}

///recieving file

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

Now this $abc is from main plugin page

But i am getting this error

Fatal error: Call to undefined function is_admin() in C:\wamp\www\wordpress\wp-content\plugins\testplugin.php on line 98

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


回答1:


Using session :

//On testplugin.php

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

//On another file

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

Using cookies :

//On testplugin.php

$_COOKIE['varname'] = $var_value;

//On page 2

$var_value = $_COOKIE['varname'];


来源:https://stackoverflow.com/questions/15874726/how-to-pass-variable-from-plugin-php-to-another-php-file-in-wordpress-using-sess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!