• anup

    (@anupxentrictechnologiesin)


    i am new in plugin development.i am submitting a form in front end,after submitting i am showing a simple hello message.

    but during form submission below error are showing:

    Fatal error: Call to undefined function get_option() in C:\wamp\www\Anup\dating_world\wp-content\plugins\registration_form\registration_form.php on line 9
    please help me
    here is my plugin code:

    <?php
    /*
    Plugin Name: Registration Form
    Description: WordPress plugin for register user
    Author: Anup
    Version: 3.5.2
    site:http://anupkoldhn.wix.com/anup
    */
    $siteurl=get_option('siteurl');
    
    define('REGISTER_FORM_FOLDER',dirname(plugin_basename(__FILE__)));
    define('REGISTER_FORM_URL',$siteurl.'/wp-content/plugins/'.REGISTER_FORM_FOLDER);
    define('REGISTER_FORM_FILE_PATH',dirname(__FILE__));
    define('REGISTER_FORM_DIR_NAME',basename(REGISTER_FORM_FILE_PATH));
    
    	add_action('front_display','front_display');
    	add_shortcode('register','front_display');
    function front_display()
    {
    	/*$user_data = array('ID' => '','user_pass' =>'anup123','user_login' => 'anup123','display_name' =>'anup123','first_name' =>'anup324','last_name' =>'baba44','role' =>'subscriber');
           echo "sggg".$user_id = wp_insert_user( $user_data );*/
    
    	   if(isset($_REQUEST['submit']))
    	   {
    		   echo "hello";
    	   }
    ?>
    
     	<table>
    <form name="form" id="form" method="post" action="http://localhost/Anup/dating_world/wp-content/plugins/registration_form/registration_form.php" >
        <tr><td colspan="2" align="center"><span id="message"></span></td></tr>
        <tr><td>UserName:</td><td><input type="text" name="name" id="name" /></td></tr>
         <tr><td>Password:</td><td><input type="password" name="password" id="password" /></td></tr>
        <tr><td>Email:</td><td><input type="email" name="email" id="email" /></td></tr>
        <tr><td>Gender:</td><td><select id="gender" name="gender">
        							<option value="men">Men</option>
                               		 <option value="woman">Woman</option>
                                 </select>
        </td></tr>
        <tr><td colspan="2" align="center"><input type="submit" value="Submit" name="submit" /></td></tr>
        </form>
        </table>
    
    <?php
    
    }
    ?>

    [Please post code or markup between backticks or use the code button. Or better still – use a pastebin. Your posted code may now have been permanently damaged/corrupted by the forum’s parser.]

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m not good in coding but try this:

    $siteurl= function get_option('siteurl');

    Moderator bcworkz

    (@bcworkz)

    Anytime a form is submitted, the receiving page needs to load the WordPress environment before it can use any WP functions like get_option(). To do this, include the wp-load.php file near the top of the page or similar. You will often see require_once() used instead of include. And if the user must be logged in, include wp-admin/admin.php instead.

    Moderator bcworkz

    (@bcworkz)

    Follow up: My suggestion to include wp-load.php, while it works, is considered very poor practice because one cannot know the WP file structure for any particular installation so the relative reference could fail. It’s often suggested to use an AJAX technique in order to access WP functions. Such a solution is almost always possible, though not always desirable. As it happens, there is a similar technique to the AJAX approach, except no javascript or jQuery is required, your request handler can be initiated from a simple HTML link or form action. It is suitable for any GET or POST request. The handler can include another PHP file and in the process enable access to WP functions on that file.

    See Plugin_API/Action_Reference/admin_post_(action).

    Better late than never 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wordpress default function is not working in my custom plugin,please help me.’ is closed to new replies.