Whatsapper Whatsap Plugin

The are pretty much two major things that I was on the look out for when building this plugin. One was to use the update_options function to store the phone number in the backend. Two was to use the whatsapp api to perform a javascript call and everything would work.

So after enquiring all nessesary scripts I added the admin page as below.


//Admin Pages
function add_admin_pages(){
   add_menu_page( 'Whatsapper Plugin', 'Whatsapper', 'manage_options', 'whatsapper_plugin', 'whatsap_admin_page_block', plugins_url('/img/whats-dash.png', __FILE__), 110 );
}
add_action('admin_menu', 'add_admin_pages');

From then on it was a matter of setting up that field.



function whatsaper_shortcode_function($atts, $content= null){
   $directoryInf = dirname(__FILE__);
   $wNumber = esc_attr(get_option('whatsappnumber'));

    $content = '
'; $content .= '
<button id="whatsnumber" data-whatsnumber="+27'.$wNumber.'" class="lk-whatsapper">'; $content .= ' <img src="'.plugins_url('/img/Whatsapp-Icon-use-original.png', __FILE__).'" class="lk-icon"/> Book Now </button>'; $content .= '
'; $content .= '
'; return $content; }

Once I had completed all the php functionalities duties it as all now depending on javascript to do all the majic.


 document.getElementById("whatsnumber").addEventListener("click", function(){
     window.location = 'https://api.whatsapp.com/send?phone=' + number + '&text=%20'+ message;
  });