Define function name with text field

2019-08-02 19:54发布

问题:

I'm only really a novice with PHP (and I know I'm sortof trying to run before I can walk), but I would like to know if it is possible to define a functions name via a textfield.

Currently, I am working with Wordpress so I can use add_option to add something to the database to store data, etc, which is handy. My idea is for a slideshow plugin which allows you to have unlimited slideshows.

It would work by typing the name into the text box then clicking the submit button to store the name. This name would then be given to a function which can be used to display that specific slideshow. Is this possible?

Sorry if this seems confusing. I know what I want to achieve, I just don't have a clue how (but I am willing to learn). Thanks.

回答1:

Why do you need new functions? Sounds more like the same funxtion with different arguments, which can easily be your textfield value



回答2:

1.your plugin admin page allows naming and creating slideshows, like creating a post or a gallery with a title, and adding images.

2.you place a function call in your theme where you want a slideshow to appear:

if(function_exists('display_slideshow')){display_slideshow($slideshow_name)};

3.the function display_slideshow() is included in your plugin file.

function display_slideshow($slideshow_name){
            //get slideshow stuff from the database, 
            //using the name of the show passed as arg
            //write your html and php to show the images the way you design
        }