I'm a WordPress beginner, and I have tried to develop plugins, but I don't know how to call external functions in a WordPress plugin. For example, I have an external PHP script called download.php in which there are several functions. To include this file, I call require_once (download.php);, but then I don't know how to call functions within download.php. For example, I want to call a function download ($filename, $time, $ban_user), where: $filename is a file path, $time is from 1 to 60 minutes, $ban_user is a user id banned. To do that, I coded
add_shortcode ('dloader', 'download_file'); function download_file ($atts){ // I don't know how to code continued here // } Please guide me the way of coding, I am not a professional programmer.
add_shortcode( 'dloader', 'download_file' ); // generate shortcode [dloader filename="http://google.com"] // the result is <a href="http://myweb.com/123456abc/">Download</a> // where: 123456abc is the crypted parameter for the url http://google.com function download_file( $atts, $content = null ) { require_once ( 'download.php' ); // the original function: download ( $filename, $time, $ban_user ) { } extract( shortcode_atts( array( 'filename' => '', 'time' => '', 'ban_user' => '', ), $atts ) ); if ( empty( $filename ) ) { return 'ERROR'; } if ( empty( $time ) ) { $time = 60; } if ( empty( $ban_user ) ) { $ban_user = 0; } // value 0 is default, not banned $default = '<div class="dloader">'; //execute the function download() in the file download.php $default .= '<a href="' .download( $filename, $time, $ban_user ). '">Download</a>'; return $default; }
download_fileand when do you want to execute it?downloadnotdownload_file.