WordPress.org

Ready to get started?Download WordPress

Forums

shortcode in plugins (3 posts)

  1. quickasianrecipes
    Member
    Posted 2 years ago #

    Hello, I am using the Visual Form Builder plugin. I wanted to write a function and then display the output using shortcodes. I am new to PHP and wordpress coding. I tried the foobar shortcode example.
    http://codex.wordpress.org/Shortcode_API

    When I inserted that function in functions.php, it worked fine and showed the correct output i.e. foo and bar. But using the same function inside the plugin files does not give any output and [foobar] is displayed. The same plugin class has add_shortcode written in _construct. I followed suit, put add_shortcode for foobar inside the _construct function and I created a public foobar_func outside the _construct function but inside the class, like a regular method. But this does not work. In fact I wanted to use this with a different file that's part of the plugin and gets included in the main plugin PHP file.

    How do I get this to work?

  2. xclamation
    Member
    Posted 2 years ago #

    Hi,

    Can you post your plugin code?

  3. quickasianrecipes
    Member
    Posted 2 years ago #

    Hello I figured out the problem. I had to add an array

    add_shortcode( 'potluck', array( &$this, 'potluck_delegate' ) );

    However, this code can only be put inside the main php file. What do I do if I want to put this code in the _construct method of another file

    public function potluck_delegate($atts) {
    include "class-entries-display.php";
    $entries_list = new VisualFormBuilder_Entries_Display();
    /* return "foo bar"; */
    return $entries_list->potluck($atts);
    }

    Instead of delegating the call I want to use that add_shortcode in the class-entries-display file itself. Is that possible?

    I had one more question - how do I figure out the mime type of a particular URL? I want users to submit a url to their image but before displaying it, I wan to check the mime type. how do I do that in wordpress? My current PHP version is 5.2, I am tryign to upgrade it to 5.3

Topic Closed

This topic has been closed to new replies.

About this Topic