article

Tuesday, November 29, 2016

Add pagination in wordpress admin in customized plugin

Add pagination in wordpress admin in customized plugin

Create folder name admin_menu path wp-content\plugins\admin_menu

Create php file name admin_menu path wp-content\plugins\admin_menu\admin_menu.php

admin_menu.php source code

<?php
/**
* Plugin Name: Admin Menu
* Plugin URI: https://tutorial101.blogspot.com/
* Description: A custom admin menu.
* Version: 1.0
* Author: Cairocoders
* Author URI: http://tutorial101.blogspot.com/
**/
function theme_options_panel(){
  add_menu_page('Theme page title', 'Theme menu', 'manage_options', 'theme-options', 'wps_theme_func');
  add_submenu_page('theme-options', 'Settings page title', 'Settings menu label', 'manage_options', 'theme-op-settings', 'wps_theme_func_settings');
  add_submenu_page('theme-options', 'FAQ page title', 'FAQ menu label', 'manage_options', 'theme-op-faq', 'wps_theme_func_faq');
  add_submenu_page('theme-options', 'My List Table', 'My List Table', 'manage_options', 'my-list-table', 'wps_theme_list_table');

}
add_action('admin_menu', 'theme_options_panel');

//function
function wps_theme_func(){
    echo '<div class="wrap">
 <div id="icon-users" class="icon32"></div>
 <h2>Theme Options</h2>
 </div>';
}
function wps_theme_func_settings(){
    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div>
    <h2>Settings</h2></div>';
}
function wps_theme_func_faq(){
    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div>
    <h2>FAQ</h2></div>';
}
function wps_theme_list_table(){
    echo '<div class="wrap">
 <div id="icon-users" class="icon32"></div>
 <h2>My List Table Test - Pagination</h2>
 </div>';
 global $wpdb;
 echo '<form method="get" action="" id="posts-filter">
  <table class="wp-list-table widefat fixed pages">
  <tbody id="the-list">
   <thead>
    <tr>
  <th class="manage-column column-cb check-column" id="cb" scope="col"></th>
  <th class="manage-column column-name" scope="col">User ID</th>
  <th class="manage-column column-name" scope="col">Invoice #</th>
  <th class="manage-column column-name" scope="col">Date Order</th>
  <th class="manage-column column-name" scope="col">Paid By</th>
  <th class="manage-column column-name" scope="col">Action</th>
    </tr>
   </thead>
   <tfoot>
    <tr>
  <th class="manage-column column-cb check-column" scope="col"></th>
  <th class="manage-column column-name" scope="col">User ID</th>
  <th class="manage-column column-name" scope="col">Invoice #</th>
  <th class="manage-column column-name" scope="col">Date Order</th>
  <th class="manage-column column-name" scope="col">Paid By</th>
  <th class="manage-column column-name" scope="col">Action</th>
    </tr>
   </tfoot>';
    $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1;
    $limit = 3; // number of rows in page
    $offset = ( $pagenum - 1 ) * $limit;
    $total = $wpdb->get_var( "SELECT COUNT('id') FROM wp_sdn_userorder" );
    $num_of_pages = ceil( $total / $limit );
    $sql_usersorder = $wpdb->get_results( "SELECT * FROM wp_sdn_userorder ORDER BY dateorder DESC LIMIT $offset, $limit");
    $totalrec =  $wpdb->num_rows;
    $isodd=array('','alternate');
    $n=0;
    foreach ($sql_usersorder as $rows_usersorder) 
    {
  $n++;
  $id = $rows_usersorder->id;   
  $user_id = $rows_usersorder->user_id;
  $course_invoice = $rows_usersorder->course_invoice;
  $dateorder = $rows_usersorder->dateorder;
  $paidby = $rows_usersorder->paidby;
  echo '<tr class="type-page '.$isodd[$n%2].'">
  <th class="check-column" scope="row"><center>'.$n.'</center></th> 
  <td class="column-title"><strong><a title="Edit" href="#" class="row-title">'.$user_id.''.rand().'</a></strong>
  <div class="row-actions">
  <span class="edit"><a title="Edit this item" href="#">Edit</a> | </span>
  <span class="trash"><a href="javascript:delusers('.$id.','.$user_id.')" title="Move this item to the Trash" class="submitdelete">Trash</a> | </span>
  </div>
    </td>
    <td>'.$course_invoice.'</td>
    <td>'.$dateorder.'</td>  
    <td>'.$paidby.'</td>
    <td><a href="#">View</a> | <a href="#">Delete</a></td>
  </tr>';
    }
   echo '</tbody>
  </table>
  <div class="tablenav bottom">
   <div class="alignleft actions bulkactions">';
    $page_links = paginate_links( array(
  'base' => add_query_arg( 'pagenum', '%#%' ),
  'format' => '',
  'prev_text' => __( '«', 'text-domain' ),
  'next_text' => __( '»', 'text-domain' ),
  'total' => $num_of_pages,
  'current' => $pagenum
    ) );
    if ( $page_links ) {
  echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>';
    }
   echo '</div>
   <br class="clear">
  </div>
 </form>';
}

Billing Address Same as Shipping Address jQuery

Billing Address Same as Shipping Address jQuery

<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Billing Address Same as Shipping Address jQuery</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript">
   $(document).ready(function(){ 
     $('#check-address').click(function(){ 
     if ($('#check-address').is(":checked")) {
      $('#txtfname_billing').val($('#txtfname').val());
      $('#txtlname_billing').val($('#txtlname').val());
      $('#txtaddress_billing').val($('#txtaddress').val());
      $('#txtcity_billing').val($('#txtcity').val());
      var country = $('#country option:selected').val();
      $('#country_billing option[value=' + country + ']').attr('selected','selected');
     } else { //Clear on uncheck
      $('#txtfname_billing').val("");
      $('#txtlname_billing').val("");
      $('#txtaddress_billing').val("");
      $('#txtcity_billing').val("");
      $('#country_billing option[value=""]').attr('selected','selected');
     };
    });

   });
</script>
</head>
<body>
 <header class="bg-dark" style="height: 60px; padding: 5px;">
  <h3 class="text-light" style="text-align: center;">Billing Address Same as Shipping Address jQuery</h3>
 </header>
 <div class="container bg-dark">
 <div class="row">
  <div class="col-sm-1"></div>
  <div class="col-sm-2"></div>  
  <div class="col-sm-6 bg-light boxStyle">
   <form name="theform" action="" method="post">
   <div class="form-group">
    <div class="width30 floatL"><label>Firstname</label></div>
    <div class="width70 floatR"><input type="text" id="txtfname" name="txtfname" placeholder="First Name" class="form-control"></div><br><br>
   </div>
   <div class="form-group">
    <div class="width30 floatL"><label>Lastname</label></div>
    <div class="width70 floatR"><input type="text" id="txtlname" name="txtlname" placeholder="Last Name" class="form-control"></div>
   </div><br>
   <div class="form-group">
    <div class="width30 floatL"><label>Address</label></div>
    <div class="width70 floatR"><input type="text" id="txtaddress" name="txtaddress" placeholder="Ship to Address" class="form-control"></div>
   </div><br>
   <div class="form-group">
    <div class="width30 floatL"><label>City</label></div>
    <div class="width70 floatR"><input type="text" id="txtcity" name="txtcity" placeholder="Ship to City" class="form-control"></div>
   </div><br>
   <div class="form-group">
    <div class="width30 floatL"><label>Country</label></div>
    <div class="width70 floatR"><select name="country" size="1" id="country" class="form-control">
     <option value="">Select Country..</option>  
     <option value="Philippines">Philippines</option>
     </select></div>
   </div><br>
   <hr/> 
   <p><b>Billing Information <label><input type="checkbox" value="" id="check-address">Same as billing?</label></b></p> 
   <div class="form-group">
    <div class="width30 floatL"><label>Firstname</label></div>
    <div class="width70 floatR"><input type="text" id="txtfname_billing" name="txtfname_billing" placeholder="First Name" class="form-control">
   </div><br><br>
   <div class="form-group">
    <div class="width30 floatL"><label>Lastname</label></div>
    <div class="width70 floatR"><input type="text" id="txtlname_billing" name="txtlname_billing" placeholder="Last Name" class="form-control"></div>
   </div><br>
   <div class="form-group">
    <div class="width30 floatL"><label>Address</label></div>
    <div class="width70 floatR"><input type="text" id="txtaddress_billing" name="txtaddress_billing" placeholder="Ship to Address" class="form-control"></div>
   </div><br>
   <div class="form-group">
    <div class="width30 floatL"><label>City</label></div>
    <div class="width70 floatR"><input type="text" id="txtcity_billing" name="txtcity_billing" placeholder="Ship to City" class="form-control"></div>
   </div><br>
   <div class="form-group">
    <div class="width30 floatL"><label>Country</label></div>
    <div class="width70 floatR"><select name="country_billing" size="1" id="country_billing" class="form-control">
      <option value="">Select Country..</option>  
     <option value="Philippines">Philippines</option>
      </select></div>
   </div><br> 
   

   <div class="form-group">
   <div class="row">
   <div class="floatR"><br/><input class="btn btn-success" type="submit"   value="Submit" style="font-weight: bold"></div> 
   </div>
   </div>
   </form>      
  </div>
  <div class="col-sm-1"></div>
  <div class="col-sm-2"></div>
  </div> 
 </div> 
<style>
.width30 {
  width: 30%;
 }
 .width70 {
  width: 70%; 
 }
 .floatL{
  float: left;
 }
 .floatR{
  float: right;
 }
 .boxStyle{
  padding: 20px; 
  border-radius: 25px; 
  border-top: 6px solid #dc3545;
  border-bottom: 6px solid #28a745;
 }
</style>
</body>
</html>

php Randomize Background Image

php Randomize Background Image
<?php
  $bg = array('bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg', 'bg-04.jpg', 'bg-05.jpg', 'bg-06.jpg', 'bg-07.jpg' ); // array of filenames

  $i = rand(0, count($bg)-1); // generate random number size of the array
  $selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>
<style type="text/css">
body{
background: url(images/<?php echo $selectedBg; ?>) no-repeat;
}
</style>

Saturday, November 26, 2016

Basic Example using SMTP (no authentication) and attachments

Basic Example using SMTP (no authentication) and attachments
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->Subject    = "PHPMailer Test Subject via smtp, basic with no authentication";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

Related Post