×

php up to date

wordpress plugin development tutorial for beginers


wordpress plugin development tutorial for beginers


<?php
/*
Plugin Name: Tutorial
Plugin URI: 
Description: This plugin helps to users to find right products suggestions based on their answers
Version: 0.1
Author: V. manikandan
Author URI: http://www.eightlegbuilders.in/
License: GPL2
Text Domain: 
*/

   function html_form_code() //Name whaterver you want
     {
       echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post" class="frm1">';
  echo '<p>1. Whate state are you in?</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<input type="radio" name="q1" value="">state 3<br/>';
  echo '<p>2. Scale of 1-10 in experience with firearms?</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<p>3. How much are you willing to spend?</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<p>4. Do you live in urban, rural, suburban?</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<p>5. What are your walls made of? (if both, pick which is more prominent)</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<p>6. Are there any other occupants?</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<p>7. Are any under the age of 18?</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<p>8. Do you have long hallways? (click on question mark: to determine the proper caliber of weapon. Would you reasonably say you have long hallways.)</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<p>9. What’s more important for you, more stopping power or more rounds fired?</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<p>10. What state do you reside in?</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  echo '<p>11. Would you be open to weapon attachments?</p>';
  echo '<input type="radio" name="q1" value="">state 1<br/>';
  echo '<input type="radio" name="q1" value="">state 2<br/>';
  
  echo '<input type="submit" name="submit" value="Get Result">';
  
 echo'</form>';
 }

function submit_answer() //name of your function
{
    $page="";
$msg="";
    // if the submit button is clicked, send the email
  if ( isset( $_POST['submit'] ) ) 
  {
    if(isset($_POST['q1'])){$ans1=$_POST['q1'];}
if(isset($_POST['q2'])){$ans2=$_POST['q2'];}
if(isset($_POST['q3'])){$ans3=$_POST['q3'];}
if(isset($_POST['q4'])){$ans4=$_POST['q4'];}
if(isset($_POST['q5'])){$ans5=$_POST['q5'];}
if(isset($_POST['q6'])){$ans6=$_POST['q6'];}
if(isset($_POST['q7'])){$ans7=$_POST['q7'];}
if(isset($_POST['q8'])){$ans8=$_POST['q8'];}
if(isset($_POST['q9'])){$ans9=$_POST['q9'];}
if(isset($_POST['q10'])){$ans10=$_POST['q10'];}

    
if(isset($ans2)and isset($ans7))
{
   if($ans2=='8' and $ans7=='0')
{
     
  $msg='your message';
}
}
if(isset($ans2))
{
 if($ans2=='3')
  {
     $msg='your message';
 }
 else if($ans2=='4')
  {
    $msg='your message';
  }
 else if($ans2=='6')
  {
    $msg='your message';
  }
}

if(isset($ans4) and isset($ans2) and isset($ans8))
{
 if($ans4=='rural' and $ans2=='8' and $ans8=='1')
  {
    $msg='your message';
   }
     }
if(isset($ans7) and isset($ans2))
    {
       if($ans7=='1' and $ans2='8')
   {
    $msg='your message';
   }

    }  
if(isset($ans6))
{
   if($ans6=='1')
{
$msg='your message';
}
}
if(isset($ans7))
    {
  if($ans7=='0')
  {
   $msg='your message';
  }
  else
  {
   $msg='your message';
  }
}
if(isset($ans5))
{
  if($ans5=='drywall')
  {
    $msg='your message';
  }
}

   if(isset($ans9))
    {
  if($ans9=='stop')
  {
    $msg='your message';
  }
 else
 {
   $msg='your message';
 }
     }
 
     
   }

      echo '<div class="msg">';       
      
       if(isset($msg)){echo $msg;}
      echo '</div>';
   }
   
}
function your_shortcode() // main function which combine all the above functions make it functionalbe
{
    ob_start();
    submit_answer();
    html_form_code(); 
    return ob_get_clean();
}
add_shortcode( 'your_question', 'your_shortcode' ); //create shortcode

add_action( 'wp_enqueue_scripts', 'prefix_add_my_stylesheet' ); // safest way to add css for your plugin

/**
 * Enqueue plugin style-file
 */
function prefix_add_my_stylesheet() 
{
    // Respects SSL, Style.css is relative to the current file
    wp_register_style( 'prefix-style', plugins_url('style.css', __FILE__) );
    wp_enqueue_style( 'prefix-style' );
}

?>

SHARE

blogger

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Thanks for your valuable feedback