how to pass variable from plugin php to another ph

2019-08-17 03:05发布

问题:

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'];