0

hey guys i wanna call my function inside class A than call it inside class B within anonymous function how to do that ? here my sample code.

<?php

     class A extends Z{
        public function sampleFunction($post){
           // code here
        }

     }

     class B extends A{
       public __construct(){
         $this->anotherClass();
       }
    // add_action() and update_meta_box() is function from wordpress

       public function anotherClass(){
         $post = $_POST['test'];
         add_action('save_post',function($id){
           if(isset($post)){
    // here i dont know how to call it inside anonymous function
             $this->sampleFunction($post); 
             update_meta_box(
               $id,
               'key',
               strip_tags($post)
             );
           }
         });
       }

     }

    ?>
  • Solved link – user3073032 Dec 7 '13 at 6:36
  • Please do not duplicate questions across the network. – s_ha_dum Dec 7 '13 at 15:27
0

You need to specify which variables you want your closure to have access to, using the use part of the closure -- see manual.

add_action('save_post', function($id) use ($this, $post) {
    // ....
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.