Plugin Directory

Changeset 1600868


Ignore:
Timestamp:
02/21/2017 08:43:25 PM (9 years ago)
Author:
omnileads
Message:

Update to version 2.1.

Location:
tawkto-manager/trunk
Files:
31 added
5 edited

Legend:

Unmodified
Added
Removed
  • tawkto-manager/trunk/readme.txt

    r1575949 r1600868  
    33Tags: tawkto,Chat Widget,live chat,plugin
    44Requires at least: 2.9
    5 Tested up to: 4.7.1
    6 Stable tag: 2.0.6
     5Tested up to: 4.7.2
     6Stable tag: 2.1
    77
    8 Tawk.To Manager adds visibility control for tawk.to chat with a shortcode (posts/pages/front page) and more options to hide & show.
     8Tawk.To Manager adds visibility control for the chat with options for posts and pages, dashboard, WooCommerce & with shortcode.
    99
    1010== Description ==
    11 Tawk.To Manager enables extensive **visibility control for tawk.to chat** with a **shortcode** for post and pages and visibility options.
    12 Show / hide chat for **tag**, **category** and **front pages** and **administrors** and **subscribers**.
     11Control the visibility for the chat window with options for on showing it on the **website** (front-end), in the **dashboard**, for **WooCommerce pages** and with a shortcode.
     12Show / hide chat for **tag**, **category** and **front pages** and for user roles like **administrors**, **subscribers**, **customers** and the **shop manager**.
     13
     14= Simple and advanced mode =
     15By default the plugin is set to the simple mode. Set it to the Advanced mode to enable many extra options for advanced users.
     16
     17= Plugin is faster APC cachable transient =
     18Version 2.1 introduced a transient for storing all options including the TawkTo script. Transients are cachable objects for  APC cache and much faster then WordPress options for this.
     19
     20= WordPress dashboard options =
     21Control the visibility in the WordPress dashboard with options for user roles like administrator, subscribers, customers and the WooCommcerce shop manager.
     22
     23= WooCommerce Page options =
     24Control the visibility for WooCommerce pages like single product pages, the shop page and the checkout page or hide it for the shop manager where you want.
    1325
    1426= Shortcode =
     
    3850Paste your tawk.to script in the text area Your tawk.to script.
    3951
    40 
    4152NB. if you have also installed the Tawk.to Live Chat plugin then deactivate it when wanting to use this plugin.<br />
    4253
     
    5162== Screenshots ==
    52631. Show the tawk.to chat on your website<br />
    53 2. Plugin options page for visibility per post type<br />
    54 3. Shortcode for posts & pages<br />
     642. Advanced mode to enable options for advanced users<br />
     653. WordPress dashboard settings for user roles<br />
     664. WooCommerce Page options are enabled in it's installed and active<br />
     675. Shortcode for posts & pages<br />
    5568
    5669== Changelog ==
     70= 2.1 =
     71* Mayor release update and added functions for **WoooCommerce** and the **WordPress dashboard** amongst others.
     72
    5773= 2.0.6 =
    5874* Update to make version 2.0.5 backward compatible with WordPress 4.6 and lower and compatible with WordPress 4.7 and higher.
  • tawkto-manager/trunk/tawktomanager.php

    r1575949 r1600868  
    11<?php
    2 namespace TTM\Plugin;
    3 defined( 'ABSPATH' ) or die( 'You do not have sufficient permissions to access this page. PS really?' );
    42/*
    53Plugin Name: TawkTo Manager
    64Plugin URI: http://www.tawktomanager.org/
    7 Description: Tawk.To Manager enables extensive visibility control for tawk.to chat with a shortcode for post and pages and extra display options for the front page, category and tag pages and for administrators and subscribers.
     5Description: Tawk.To Manager enables visibility control for tawk.to chat for post and pages and offers display options for the WordPress dashboard, WooCommerce, the front page, category and tag pages etc and via a shortcode.
    86Author: Daniel Mulder
    9 Version: 2.0.6
     7Version: 2.1
    108Author URI: http://www.omnileads.nl/daniel-mulder-all-star/
    119*/
    1210
     11defined( 'ABSPATH' ) or die( 'You do not have sufficient permissions to access this page.' );
     12
     13// load constants and do file inclusions if not defined
     14defined( 'TTM_ABSPATH' ) or require_once 'includes/load.php';
     15
     16global $ttm;
     17$ttm = (object) null;
     18
    1319/*
    14  * Define TTM_Controller base class
     20 * Define TTM_Controller class
    1521 *
    1622*/
    1723
    18 if ( !class_exists('TTM_Controller') ){
     24if ( !class_exists('TTM_Controller') ):
    1925   
     26    require_once( 'controllers/ttm.ctrl.php' );
    2027   
    21     class TTM_Controller{
    22        
    23        
    24         protected static $ttm_tawktoscript;
    25         protected static $ttm_show_always;
    26         protected static $ttm_show_front_page;
    27         protected static $ttm_show_cat_pages;
    28         protected static $ttm_show_tag_pages;
    29         protected static $ttm_hide_admin;
    30         protected static $ttm_hide_subscribers;
    31         protected static $ttm_hide_not_subscriber;
    32         protected static $ajax_nonce;
    33        
    34        
    35         function __construct(){
    36             self::__init_constants();
    37         }
    38        
    39        
    40         protected static function __init_constants(){
    41             define( 'TTM_TEXTDOMAIN', 'tawkto-manager' );
    42             define( 'TTM_SETTINGS_PAGE', 'ttm-tawkto-manager' );
    43             define( 'TTM_ABSPATH', WP_PLUGIN_DIR . '/' . TTM_TEXTDOMAIN );
    44             define( 'TTM_PLUGIN_FILE', 'tawktomanager.php' );
    45             define('TTM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
    46             define( 'TTM_SCRIPT_URL', WP_PLUGIN_URL.'/'.TTM_TEXTDOMAIN );
    47         }
    48        
    49         /*
    50          * Register WordPress settings in admin area
    51         */
    52        
    53         protected static function __register_settings(){
    54             global $wp_version;
    55             // Check wp version to work with WordPress 4.7 and up and 4.6 and lower
    56             if ( $wp_version >= 4.7 ) {
    57                     /** register wp settings WordPress 4.7 and up */
    58                     $args = array('show_in_rest'=> '','type' =>'string','default' =>'',);
    59                     register_setting( 'ttm_tawkto_manager_plugin_options', 'ttm_tawktoscript', $args );
    60                     register_setting( 'ttm_tawkto_manager_plugin_options', 'ttm_show_always', $args );
    61                     register_setting( 'ttm_tawkto_manager_plugin_options', 'ttm_show_front_page', $args );
    62                     register_setting( 'ttm_tawkto_manager_plugin_options', 'ttm_show_cat_pages', $args );
    63                     register_setting( 'ttm_tawkto_manager_plugin_options', 'ttm_show_tag_pages', $args );
    64                     register_setting( 'ttm_tawkto_manager_plugin_options', 'ttm_hide_admin', $args );
    65                     register_setting( 'ttm_tawkto_manager_plugin_options', 'ttm_hide_subscribers', $args );
    66                     register_setting( 'ttm_tawkto_manager_plugin_options', 'ttm_hide_not_subscriber', $args );
    67             }else {
    68                     /** register wp settings WordPress 4.6 and lower */
    69                     register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_tawktoscript' ) );
    70                     register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_show_always' ) );
    71                     register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_show_front_page' ) );
    72                     register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_show_cat_pages' ) );
    73                     register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_show_tag_pages' ) );
    74                     register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_hide_admin' ) );
    75                     register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_hide_subscribers' ) );
    76                     register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_hide_not_subscriber' ) );   
    77             }
    78         }
    79        
    80         /*
    81          * Get values from WordPress options for option values to use
    82         */
    83        
    84         protected static function __ttm_init_options(){       
    85             /* load settings */
    86             self::$ttm_tawktoscript = get_option('ttm_tawktoscript');
    87             self::$ttm_show_always = get_option('ttm_show_always');
    88             self::$ttm_show_front_page = get_option('ttm_show_front_page');
    89             self::$ttm_show_cat_pages = get_option('ttm_show_cat_pages');
    90             self::$ttm_show_tag_pages = get_option('ttm_show_tag_pages');
    91             self::$ttm_hide_admin = get_option('ttm_hide_admin');
    92             self::$ttm_hide_subscribers = get_option('ttm_hide_subscribers');
    93             self::$ttm_hide_not_subscriber = get_option('ttm_hide_not_subscriber');
    94         }
    95        
    96         /*
    97          * Secure callback create nonce for options page in admin area
    98         */
    99        
    100         protected function createNonce(){
    101             if(self::is_admin_logged_in()){
    102                 self::$ajax_nonce = wp_create_nonce( "sec-callback" );
    103             }
    104         }
    105        
    106         /*
    107          * Secure callback get nonce for reading options page in admin area
    108          *
    109         */
    110        
    111         public function getNonce(){
    112             if(self::is_admin_logged_in()){
    113                 return self::$ajax_nonce;
    114             }
    115         }
     28endif;
    11629
    117         /*
    118          * Determine if user is logged in with admin rights
    119          * @bolean
    120          *
    121         */
    122        
    123         protected static function is_admin_logged_in(){
    124             $userInfo = wp_get_current_user();
    125             if (in_array( 'administrator', (array) $userInfo->roles)){
    126                 return true;
    127             }
    128             return false;
    129         }     
    130        
    131         /*
    132          * Determine if user is logged and confirm role or return roles
    133          * @array (count(array) is 0 for false or contains user roles)
    134          *
    135         */
    136        
    137         protected static function role_is_logged_in($role=''){
    138             if( is_user_logged_in() && !self::is_admin_logged_in() ){
    139                 if($role != ''){
    140                     $userInfo = wp_get_current_user();
    141                     if (in_array( $role, (array) $userInfo->roles)){
    142                         return (bool) true;
    143                     }
    144                 }
    145                 else{
    146                     $userInfo = wp_get_current_user();
    147                     return (array) $userInfo->roles;
    148                 }
    149             }
    150             return (array) $null;
    151         }
    152        
    153     } // end ctrl class
    154    
    155 } //endif
     30/**
     31 * If WordPress dashboard / back-end request load back-end controller 
     32*/
    15633
    157 /** admin actions in dashboard */
     34if ( is_admin() && !class_exists('TTM_BackendController') ) {
     35   
     36    $ttm = TTM_Controller::__create_controller('TTM_Backend');
     37}
    15838
    159 if ( is_admin() && !class_exists('TTM_SettingsController') ){
     39/**
     40 * If front-end page request load front-end controller 
     41*/
     42
     43if ( !is_admin() && !class_exists('TTM_FrontendController') ) {
    16044   
    161     /*
    162      *  TawkTo Manager Setttings Controller
    163      *  Creates and manages admin settings page back-end
    164     */
     45    $ttm = TTM_Controller::__create_controller('TTM_Frontend');
     46   
     47}
    16548
    166     class TTM_SettingsController extends TTM_Controller{
    167        
    168         public function __construct() { 
    169             parent::__construct();
    170             add_action( 'admin_menu', array(__CLASS__, 'ttm_tawkto_manager_plugin_menu') ); // wp dash menu
    171             add_action('admin_init', array(__CLASS__, '__ttm_init') ); // options page
    172         }
    173        
    17449
    175         static function __ttm_init(){
    176             self::__register_settings();
    177             self::__ttm_init_options();
    178         }
    17950
    180         /* create admin options menu */
    181        
    182         static function ttm_tawkto_manager_plugin_menu() {
    183             add_options_page('TawkTo Manager Plugin Options',
    184                              'TawkTo settings','manage_options',
    185                              TTM_SETTINGS_PAGE,array( __CLASS__,
    186                              'ttm_tawkto_manager_plugin_options' ) );
    187         }
    188        
    189 
    190         static function ttm_tawkto_manager_plugin_options() {
    191             /** check if admin */
    192             if ( !current_user_can( 'manage_options' ) )  {
    193              wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    194             }
    195            
    196             // process settings form on submit
    197             if($_SERVER['REQUEST_METHOD'] == 'POST'){ 
    198                
    199                 /** Validate secure referrer nonce  */
    200                 $nonce = $_POST['security'];
    201                 if ( ! wp_verify_nonce( $nonce, 'sec-callback' ) ) {
    202                     wp_die(); // nonce not valid so die
    203                     return;
    204                 }
    205                
    206                 /** process user input and update script */
    207                 $replace = "<!--Start of Tawk.to Script-->";
    208                 $_POST['ttm_tawktoscript'] = trim(str_replace($replace, "", $_POST['ttm_tawktoscript']));
    209                 $replace = '<script type=\"text/javascript\">';
    210                 $_POST['ttm_tawktoscript'] = trim(str_replace($replace, "", $_POST['ttm_tawktoscript']));
    211                 $replace = '</script>';
    212                 $_POST['ttm_tawktoscript'] = str_replace($replace, "", $_POST['ttm_tawktoscript']);
    213                 $replace = '<!--End of Tawk.to Script-->';
    214                 $_POST['ttm_tawktoscript'] = str_replace($replace, "", $_POST['ttm_tawktoscript']);
    215 
    216                 /* eval and persist to wordpress options */
    217                 self::$ttm_tawktoscript = $_POST['ttm_tawktoscript'];
    218                 update_option('ttm_tawktoscript', self::$ttm_tawktoscript );
    219                 if(isset($_POST['ttm_show_always']) && $_POST['ttm_show_always'] == "on" ){
    220                     self::$ttm_show_always = "on";
    221                     update_option('ttm_show_always', self::$ttm_show_always);
    222                 }else{
    223                     self::$ttm_show_always = '';
    224                     update_option('ttm_show_always', self::$ttm_show_always);
    225                 }
    226                 if(isset($_POST['ttm_show_front_page']) && $_POST['ttm_show_front_page'] == "on" ){
    227                     self::$ttm_show_front_page = "on";
    228                     update_option('ttm_show_front_page', self::$ttm_show_front_page);
    229                 }else{
    230                     self::$ttm_show_front_page = '';
    231                     update_option('ttm_show_front_page', self::$ttm_show_front_page);
    232                 }
    233                 if(isset($_POST['ttm_show_cat_pages']) && $_POST['ttm_show_cat_pages'] == "on" ){
    234                     self::$ttm_show_cat_pages = "on";
    235                     update_option('ttm_show_cat_pages', self::$ttm_show_cat_pages);
    236                 }else{
    237                     self::$ttm_show_cat_pages = '';
    238                     update_option('ttm_show_cat_pages', self::$ttm_show_cat_pages);
    239                 }
    240                 if(isset($_POST['ttm_show_tag_pages']) && $_POST['ttm_show_tag_pages'] == "on" ){
    241                     self::$ttm_show_tag_pages = "on";
    242                     update_option('ttm_show_tag_pages', self::$ttm_show_tag_pages);
    243                 }else{
    244                     self::$ttm_show_tag_pages = '';
    245                     update_option('ttm_show_tag_pages', self::$ttm_show_tag_pages);
    246                 }
    247                 if(isset($_POST['ttm_hide_admin']) && $_POST['ttm_hide_admin'] == "on" ){
    248                     self::$ttm_hide_admin = "on";
    249                     update_option('ttm_hide_admin', self::$ttm_hide_admin);
    250                 }else{
    251                     self::$ttm_hide_admin = '';
    252                     update_option('ttm_hide_admin', self::$ttm_hide_admin);
    253                 }
    254                 if(isset($_POST['ttm_hide_subscribers']) && $_POST['ttm_hide_subscribers'] == "on" ){
    255                     self::$ttm_hide_subscribers = "on";
    256                     update_option('ttm_hide_subscribers', self::$ttm_hide_subscribers);
    257                 }else{
    258                     self::$ttm_hide_subscribers = '';
    259                     update_option('ttm_hide_subscribers', self::$ttm_hide_subscribers);
    260                 }
    261                 if(isset($_POST['ttm_hide_not_subscriber']) && $_POST['ttm_hide_not_subscriber'] == "on" ){
    262                     self::$ttm_hide_not_subscriber = "on";
    263                     update_option('ttm_hide_not_subscriber', self::$ttm_hide_not_subscriber);
    264                 }else{
    265                     self::$ttm_hide_not_subscriber = '';
    266                     update_option('ttm_hide_not_subscriber', self::$ttm_hide_not_subscriber);
    267                 }
    268 
    269             }
    270            
    271             self::createNonce(); // secure referrer nonce
    272             include( TTM_ABSPATH . '/settings.ctp.php'); // page view file with html form
    273            
    274         }
    275        
    276     } // end class ctrlsettings
    277 
    278    
    279     $ttmSettingsPage = new TTM_SettingsController();
    280    
    281    
    282 /* front-side end of plugin */
    283    
    284    
    285 }elseif( !class_exists('TTM_PluginController') ) { 
    286    
    287     /*
    288      * TawkTo Manager Plugin controller
    289      * Manages tawk.to window front-side
    290      *
    291     */
    292 
    293     class TTM_PluginController extends TTM_Controller{
    294 
    295         public function __construct(){
    296             add_shortcode('tawkto_show', array(__CLASS__, 'ttm_eval_short_code') );
    297             add_action( 'wp_head', array(__CLASS__, 'ttm_add_to_header') ); // add as inline script to header
    298             self::__ttm_init_options();
    299         }
    300        
    301          /* short code eval hide/show chat */
    302        
    303         static function ttm_eval_short_code(){   
    304             if(!is_category() && !is_tag()){
    305                 if(self::ttm_eval_show() != false){
    306                     self::ttm_out_script(); // add inline to body
    307                 }
    308 
    309             }
    310         }
    311 
    312         /* Evaluate show/hide logged in users */
    313        
    314         static  function ttm_eval_show(){
    315             if(is_user_logged_in()){
    316                 // hide if admin and hide on
    317                 if(self::is_admin_logged_in()){
    318                     if(self::$ttm_hide_admin == 'on'){
    319                         return false;
    320                     }
    321                 }else{ // eval for user role
    322                     $roles = self::role_is_logged_in();
    323                     switch ($roles[0]) {
    324                         case 'subscriber':
    325                                 if(self::$ttm_hide_subscribers == 'on'){
    326                                     return false;
    327                                 }
    328                             break;
    329                         default:
    330                                 return true;
    331                             break;
    332                     }
    333                 }
    334             }else{
    335                     // eval for user not logged in
    336                     if(self::$ttm_hide_not_subscriber == 'on'){
    337                         return false;
    338                     }
    339             }
    340             return true;
    341         }
    342 
    343         /* eval show tawkto (hook wp_head action) adds inline */
    344 
    345         static function ttm_add_to_header(){   
    346             if(self::ttm_eval_show() == false){
    347                 return;
    348             }
    349             /* if  show_always */
    350             if(self::$ttm_show_always){
    351                 self::ttm_out_script();
    352                 return;
    353             }
    354             /* front page */
    355             if(is_front_page() || is_home()){
    356                 if(self::$ttm_show_front_page){
    357                     self::ttm_out_script();
    358                     return;
    359                 }
    360             }
    361             /* category pages */
    362             if(is_category()){
    363                 if(self::$ttm_show_cat_pages){
    364                     self::ttm_out_script();
    365                     return;
    366                 }
    367             }
    368             /* tag pages */
    369             if(is_tag()){
    370                 if(self::$ttm_show_tag_pages){
    371                     self::ttm_out_script();
    372                     return;
    373                 }
    374             }
    375         }
    376        
    377         /* outputs inline to html source where called  */
    378 
    379         private static function ttm_out_script(){ 
    380             echo '<script>'.PHP_EOL;
    381             echo wp_unslash(self::$ttm_tawktoscript).PHP_EOL;
    382             echo '</script>'.PHP_EOL;
    383 
    384         }
    385 
    386     } // end class ctrl plugin
    387 
    388    
    389     $ttmPlugin = new TTM_PluginController();
    390    
    391    
    392 } // endif exist ctrl plugin
    393 
Note: See TracChangeset for help on using the changeset viewer.