Rik
Rik

Reputation: 31

How to insert a php code from another php file?

Im creating a custom function for my wordpress website that will add a review section below the post content and i need to insert this function from another another file into a custom function that i added to my functions.php. I need to get this piece of code $buffy .= $this->get_review(); from a different file to work in this function:

function content_injector($content) { 
    global $wp_query;   
    $postid = $wp_query->post->ID;

    if (is_single((get_post_meta($postid, 'top_ad', true) != 'off' )))  {
        $top_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
    } 

    if (is_single((get_post_meta($postid, 'bottom_ad', true) != 'off' ))) {
        $bottom_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
    }

    if (is_single()) {
        $review = //HOW DO I ADD THAT get_review CODE HERE?
        $custom_share = '<div id="title-deel"><h4 class="block-title"><span>DEEL</span></h4></div>' . do_shortcode('[ssba]');
        $facebook_comments = '<div id="title-reageer"><h4 class="block-title"><span>REAGEER</span></h4></div>' . '<div class="fb-comments" data-href="' . get_permalink() . '" data-colorscheme="light" data-numposts="5" data-mobile="false" data-width="700"></div>';
    }

    $content = $top_ad . $content . $bottom_ad . $custom_share . $facebook_comments;
    return $content; 
}

add_filter('the_content', 'content_injector');

As you can see i need to add the get_review function to $review, but i cant make it work on my own. How to make this work?

Upvotes: 0

Views: 3749

Answers (1)

raj
raj

Reputation: 817

Use include to include the file before using any methods from that file.

include("file_with_functions.php");

OR

Create a class (with filename same as classname).

Include the file.

Create an instance of the class.

Access the method in the class through the object

Upvotes: 2

Related Questions