0

I have this function in $root/content/plugins/musicplayer/includes/player.php

public function head_script( $id, $playlist_id, $songs, $in_popup, $autoplay = false ) {
        $output   = '';
        $playlist = '';
        $artist   = '';
        $free     = null;
        $external = 0;

        if ( $songs ) {

            $ogg = '';

            foreach ( $songs as $song ) {

                $free = $song->free;

                if ( $song->poster ) {
                    $poster = esc_url( $song->poster );
                } else {
                    $poster = $this->get_default_playlist_poster( $playlist_id );
                }

                $playlist .= '{  title : "' . $song->name . '", mp3:"'. esc_url( $song->mp3 ) .'"';

                if ( $song->artist )
                    $playlist .= ', artist : "' . $song->artist . '" ';


                if ( $free != 'on' ) {

                $playlist .= ',poster : "' . $poster . '" ';


                $playlist .= ' },';
            }

            $playlist = substr( $playlist, 0, -1 );

            $output .= '<script type="text/javascript">//<![CDATA[';

            $output .= "\n";
            $output .= 'jQuery(document).ready(function($) {
                    new jPlayerPlaylist( {
                        jPlayer: "#jquery_jplayer_' . $id . '",
                        cssSelectorAncestor: "#jp_container_' . $id . '" }, 
                        ['.$playlist.'], {
                        swfPath: "' . WOLF_JPLAYER_PLUGIN_URL . '/assets/js/src",
                        wmode: "window", ';

            $output .= '});'; // end playlist

            if ( ! $in_popup )
                $output .= $this->popup();

            $output .= '});'; // end document ready playlist

            $output .= '//]]></script>';
        }

        echo $output;
    }

How can I use it in $root/content/themes/bigwolf/index.php, with it still being able to call all the functions that are originally and normally called in the native directory, without any problem?

1
  • 1
    As an aside, is this function inside a class? Normally you don't put "public" in front of the function declaration if it's procedural code. Commented Jan 30, 2015 at 16:20

2 Answers 2

1

You can include it. That's how you do it.

f1.php

<?php

    function func1()
    {
        echo 'hi';
    }

f2.php

<?php

    require_once('f1.php'); // require
    //include 'f1.php'; // or include

    func1();
Sign up to request clarification or add additional context in comments.

5 Comments

require_once('../../plugins/musicplayer/includes/jplayer-show.php'); can't see why it's not appearing when I do that. the plugins directory is two levels away.
@CodeFreaks please remove public modifier in your function this can cause troubles.
Done that, seems that the area I put your code in, it magically disappears, if that makes sense. pastebin.com/2E7pfHfY can't see what's wrong
@CodeFreaks what error are you getting ? Try to add some function like function hello_world which echo "hello" and see if there is problem with your function or with something else. If will you have problems write me email.
Just did a quick test, tried putting player.php in the same directory as where I am trying to call the function and it worked, that's great, but when I move it to one directory above, and call it in this form '../player.php' it will not work. no error. Anyway I'll try to work my way up with it, you provided me with the core to begin with. So thank you!
0

Obviously musicplayer is a plugin. If it's properly formatted, WordPress will automatically include it. So in the main file of your plugin put

require_once __DIR__ . "/includes/player.php';

That will bring your player.php in and give you access to the functions in it.

HTH,

=C=

3 Comments

Actually I'm doing somewhat of a complicated modification to the plugin so I am trying to include some functions from wp-content/plugins/wolf-jplayer/includes/jplayer-show.php in to wp-content/themes/twentytwelve/header.php, I could not do that with your solution.
If plugins wolf-jplayer is activated and it has the require_once line above, then you will be able to use the functions inside of jplayer-show.php in your theme.
Ye it is activated, but why does not it show up when I put wp-content/plugins/wolf-jplayer/includes/jplayer-show.php I'm confused because it also makes the whole player disappear.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.