Changeset 1421525
- Timestamp:
- 05/21/2016 02:14:20 PM (10 years ago)
- Location:
- tawkto-manager/trunk
- Files:
-
- 3 deleted
- 5 edited
-
. (modified) (2 props)
-
includes (deleted)
-
readme.txt (modified) (5 diffs)
-
screenshot-2.png (modified) (previous)
-
settings.ctp.php (modified) (9 diffs)
-
tawktomanager.php (modified) (1 diff)
-
ttmplugin.ctrl.php (deleted)
-
ttmsettings.ctrl.php (deleted)
Legend:
- Unmodified
- Added
- Removed
-
tawkto-manager/trunk
-
Property
svn:global-ignores
set to
*.php
includes
ttmplugin.ctrl.php
-
Property
svn:ignore
set to
ttmplugin.ctrl.php
-
Property
svn:global-ignores
set to
-
tawkto-manager/trunk/readme.txt
r1405625 r1421525 3 3 Tags: tawkto,Chat Widget,live chat,plugin 4 4 Requires at least: 2.9 5 Tested up to: 4. 5.15 Tested up to: 4.4.2 6 6 Stable tag: 2 7 7 8 Tawk.To Manager adds visibility control for tawk.to chat with a short code (posts/pages/front page) and with visibility options.8 Tawk.To Manager adds visibility control for tawk.to chat with a short code (posts/pages/front page) and more options to hide/show. 9 9 10 10 == Description == 11 Tawk.To Manager enables extensive **visibility control for tawk.to chat** with a **short code** for post and pages and **visibility options**. Show / hide the chat for tag, category and front pages and administrors. 11 Tawk.To Manager enables extensive **visibility control for tawk.to chat** with a **short code** for post and pages and **visibility options**. 12 Show / hide chat for **tag**, **category** and **front pages** and **administrors** and **subscribers**. 12 13 13 14 = Short code = … … 19 20 = Disable chat window for administrators = 20 21 Hide and disable the chat window for administrators. 22 23 = Disable chat window for subscribers = 24 Hide and disable the chat window for loggedin users with the role subscriber. 25 26 = Hide if not logged in as subscriber = 27 Hide the chat window for not logged in users and show only to loggedin users with the role subscriber. This does not effect the admin visibility option. 21 28 22 29 == Installation == … … 34 41 NB. if you have also installed the Tawk.to Live Chat plugin then deactivate it when wanting to use this plugin.<br /> 35 42 43 == Installation == 44 Download the plugin code tawkto-manager.zip.<br /> 45 Upload zip file with the standard WordPress plugin installer.<br /> 46 Activate the TawkTo Manager plugin via the plugins menu.<br /> 47 Go to the settings via Settings and the TawkTo settings sub menu.<br /> 48 Paste your tawk.to script in the text area Your tawk.to script.<br /><br /> 49 NB. if you have also installed the Tawk.to Live Chat plugin then deactivate it when wanting to use this plugin. 50 36 51 == Screenshots == 37 1. Example of tawk.to Live Chat Window on website 38 2. Plugin options page for adding script and visibility options 39 3. Short code for posts, pages and front page 52 1. Plugin options page for visibility per post type<br /> 53 2. Short code for posts & pages<br /> 40 54 41 55 == Changelog == 42 = 2.0. 3=43 * Bug fix for update. Resolved.56 = 2.0.4 = 57 * Mayor update to plugin code and added visibility option to hide the chat window for user with the role subsciber. Code overhaul to take up less memery and faster load times. 44 58 45 59 = 2.0.2 = … … 54 68 = 1.0 = 55 69 * First stable release. 70 56 71 57 72 == Frequently Asked Questions == … … 83 98 Go to the website of (https://www.tawk.to) and subscribe for a free account, configure your chat window and use this plugin to add it to your WordPress website. 84 99 85 -
tawkto-manager/trunk/settings.ctp.php
r1378815 r1421525 1 <?php defined( 'ABSPATH' ) or die( ' This action is not allowed.' ); ?>1 <?php defined( 'ABSPATH' ) or die( 'You do not have sufficient permissions to access this page. PS really?' ); ?> 2 2 <div class="wrap"> 3 <h2> tawk.to Manager Options</h2>3 <h2>Tawk.To Manager Options and Settings</h2> 4 4 <form method="post" action="<?php TTM_SCRIPT_URL.'/'.TTM_PLUGIN_FILE; ?>"> 5 <input type="hidden" name="security" value="<?php echo self::getNonce(); ?>" /> 5 6 <?php settings_fields( 'ttm_tawkto_manager_plugin_options' ); ?> 6 7 <?php do_settings_sections( 'ttm_tawkto_manager_plugin_options' ); ?> 7 8 <table class="form-table"> 8 9 <tr valign="top"> 9 <th scope="row"> Plugin options</th>10 <th scope="row">Visibility options / script</th> 10 11 <tr> 11 12 <td>Always show Tawk.To chat</td> 12 13 <td> 13 14 <?php 14 $checked = ( $this->ttm_show_always ? 'checked' : '' );15 $checked = ( self::$ttm_show_always ? 'checked' : '' ); 15 16 ?> 16 17 <input type="checkbox" name="ttm_show_always" id="ttm_show_always" value="on" <?php echo $checked; ?> /> … … 22 23 <td> 23 24 <?php 24 $checked = ( $this->ttm_show_front_page ? 'checked' : '' );25 $checked = ( self::$ttm_show_front_page ? 'checked' : '' ); 25 26 ?> 26 27 <input type="checkbox" name="ttm_show_front_page" id="ttm_show_front_page" value="on" <?php echo $checked; ?> /> … … 32 33 <td> 33 34 <?php 34 $checked = ( $this->ttm_show_cat_pages ? 'checked' : '' );35 $checked = ( self::$ttm_show_cat_pages ? 'checked' : '' ); 35 36 ?> 36 37 <input type="checkbox" name="ttm_show_cat_pages" id="ttm_show_cat_pages" value="on" <?php echo $checked; ?> /> … … 42 43 <td> 43 44 <?php 44 $checked = ( $this->ttm_show_tag_pages ? 'checked' : '' );45 $checked = ( self::$ttm_show_tag_pages ? 'checked' : '' ); 45 46 ?> 46 47 <input type="checkbox" name="ttm_show_tag_pages" id="ttm_show_tag_pages" value="on" <?php echo $checked; ?> /> … … 52 53 <td> 53 54 <?php 54 $checked = ( $this->ttm_hide_admin ? 'checked' : '' );55 $checked = ( self::$ttm_hide_admin ? 'checked' : '' ); 55 56 ?> 56 57 <input type="checkbox" name="ttm_hide_admin" id="ttm_hide_admin" value="on" <?php echo $checked; ?> /> … … 59 60 </tr> 60 61 <tr> 62 <td>Hide for subscribers</td> 63 <td> 64 <?php 65 $checked = ( self::$ttm_hide_subscribers ? 'checked' : '' ); 66 ?> 67 <input type="checkbox" name="ttm_hide_subscribers" id="ttm_hide_subscribers" value="on" <?php echo $checked; ?> /> 68 69 </td> 70 </tr> 71 <tr> 72 <td>Hide if not logged in</td> 73 <td> 74 <?php 75 $checked = ( self::$ttm_hide_not_subscriber ? 'checked' : '' ); 76 ?> 77 <input type="checkbox" name="ttm_hide_not_subscriber" id="ttm_hide_not_subscriber" value="on" <?php echo $checked; ?> /> 78 <a href="javascript:void(0)" class="ttmtooltip" 79 title="Enable to hide chat for all users not logged in and show only to logged in users having role subscriber">point at me for info</a> 80 81 </td> 82 </tr> 83 <tr> 61 84 <td>Your tawk.to script*</td> 62 85 <td> 63 <textarea name="ttm_tawktoscript" rows="14" cols="80"><?php echo wp_unslash( $this->ttm_tawktoscript); ?></textarea>86 <textarea name="ttm_tawktoscript" rows="14" cols="80"><?php echo wp_unslash(self::$ttm_tawktoscript); ?></textarea> 64 87 </td> 65 88 </tr> … … 68 91 <?php submit_button(); ?> 69 92 </form> 70 71 93 <script> 72 94 // if show always changes to checked/unchecked … … 83 105 jQuery("#ttm_show_tag_pages").prop( "checked",false); 84 106 jQuery("#ttm_show_tag_pages").attr("disabled", true); 107 jQuery("#ttm_hide_admin").prop( "checked",false); 108 jQuery("#ttm_hide_admin").attr("disabled", true); 109 jQuery("#ttm_hide_subscribers").prop( "checked",false); 110 jQuery("#ttm_hide_subscribers").attr("disabled", true); 85 111 }else{ 86 112 jQuery("#ttm_show_front_page").removeAttr("disabled"); 87 113 jQuery("#ttm_show_cat_pages").removeAttr("disabled"); 88 114 jQuery("#ttm_show_tag_pages").removeAttr("disabled"); 115 jQuery("#ttm_hide_admin").removeAttr("disabled"); 116 jQuery("#ttm_hide_subscribers").removeAttr("disabled"); 89 117 } 90 118 }); … … 95 123 jQuery("#ttm_show_cat_pages").attr("disabled", true); 96 124 jQuery("#ttm_show_tag_pages").attr("disabled", true); 125 jQuery("#ttm_hide_admin").attr("disabled", true); 126 jQuery("#ttm_hide_subscribers").attr("disabled", true); 97 127 } 98 128 } 99 } 129 } 100 130 </script> 101 131 <br /> -
tawkto-manager/trunk/tawktomanager.php
r1379391 r1421525 1 1 <?php 2 namespace TTM\Plugin; 2 3 /* 3 4 Plugin Name: TawkTo Manager 4 5 Plugin URI: http://www.tawktomanager.org/ 5 Description: Tawk.To Manager enables extensive visibility control for tawk.to chat with a short code for post and pages and extra display options for the front page and category and tag pages.6 Description: Tawk.To Manager enables extensive visibility control for tawk.to chat with a short code for post and pages and extra display options for the front page, category and tag pages and for administrators and subscribers. 6 7 Author: Daniël Mulder 7 Version: 2.0. 38 Version: 2.0.4 8 9 Author URI: http://www.omnileads.nl/daniel-mulder-all-star/ 9 10 */ 10 11 11 /** load.php loads plugin config and sets constants */12 require_once 'includes/load.php';13 14 12 /* 15 * Create new instance of TTM_PluginController to add plugin behaviour.16 * Create new instance of TTM_SettingsController to create options page.13 * Define TTM_Controller base class 14 * 17 15 */ 18 16 19 if ( is_admin() ){ 20 /** admin actions in dashboard */ 21 require_once 'ttmsettings.ctrl.php'; 22 $ttmSettingsPage = new TTM_SettingsController(); 23 } 24 else { 25 /** business end of plugin */ 26 require_once 'ttmplugin.ctrl.php'; 27 $ttmPlugin = new TTM_PluginController(); 28 } 29 30 17 if ( !class_exists('TTM_Controller') ){ 18 19 20 class TTM_Controller{ 21 22 23 protected static $ttm_tawktoscript; 24 protected static $ttm_show_always; 25 protected static $ttm_show_front_page; 26 protected static $ttm_show_cat_pages; 27 protected static $ttm_show_tag_pages; 28 protected static $ttm_hide_admin; 29 protected static $ttm_hide_subscribers; 30 protected static $ttm_hide_not_subscriber; 31 protected static $ajax_nonce; 32 33 34 function __construct(){ 35 self::__init_constants(); 36 } 37 38 39 protected static function __init_constants(){ 40 define( 'TTM_TEXTDOMAIN', 'tawkto-manager' ); 41 define( 'TTM_SETTINGS_PAGE', 'ttm-tawkto-manager' ); 42 define( 'TTM_ABSPATH', WP_PLUGIN_DIR . '/' . TTM_TEXTDOMAIN ); 43 define( 'TTM_PLUGIN_FILE', 'tawktomanager.php' ); 44 define('TTM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); 45 define( 'TTM_SCRIPT_URL', WP_PLUGIN_URL.'/'.TTM_TEXTDOMAIN ); 46 } 47 48 49 protected static function __register_settings(){ 50 /** register and get settings */ 51 register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_tawktoscript' ) ); 52 register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_show_always' ) ); 53 register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_show_front_page' ) ); 54 register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_show_cat_pages' ) ); 55 register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_show_tag_pages' ) ); 56 register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_hide_admin' ) ); 57 register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_hide_subscribers' ) ); 58 register_setting( 'ttm_tawkto_manager_plugin_options', array(__CLASS__, 'ttm_hide_not_subscriber' ) ); 59 } 60 61 62 protected static function __ttm_init_options(){ 63 /* get and set settings */ 64 self::$ttm_tawktoscript = get_option('ttm_tawktoscript'); 65 self::$ttm_show_always = get_option('ttm_show_always'); 66 self::$ttm_show_front_page = get_option('ttm_show_front_page'); 67 self::$ttm_show_cat_pages = get_option('ttm_show_cat_pages'); 68 self::$ttm_show_tag_pages = get_option('ttm_show_tag_pages'); 69 self::$ttm_hide_admin = get_option('ttm_hide_admin'); 70 self::$ttm_hide_subscribers = get_option('ttm_hide_subscribers'); 71 self::$ttm_hide_not_subscriber = get_option('ttm_hide_not_subscriber'); 72 } 73 74 /* 75 * Secure callback with referer for (api) callbacks options page 76 * @void() 77 */ 78 79 protected function createNonce(){ 80 if(self::is_admin_logged_in()){ 81 self::$ajax_nonce = wp_create_nonce( "sec-callback" ); 82 } 83 } 84 85 86 public function getNonce(){ 87 if(self::is_admin_logged_in()){ 88 return self::$ajax_nonce; 89 } 90 } 91 92 /* 93 * Determine if user is logged in with admin rights 94 * @bolean 95 * 96 */ 97 98 protected static function is_admin_logged_in(){ 99 $userInfo = wp_get_current_user(); 100 if (in_array( 'administrator', (array) $userInfo->roles)){ 101 return true; 102 } 103 return false; 104 } 105 106 /* 107 * Determine if user is logged and confirm role or return roles 108 * @array (count(array) is 0 for false or contains user roles) 109 * 110 */ 111 112 protected static function role_is_logged_in($role=''){ 113 if( is_user_logged_in() && !self::is_admin_logged_in() ){ 114 if($role != ''){ 115 $userInfo = wp_get_current_user(); 116 if (in_array( $role, (array) $userInfo->roles)){ 117 return (bool) true; 118 } 119 } 120 else{ 121 $userInfo = wp_get_current_user(); 122 return (array) $userInfo->roles; 123 } 124 } 125 return (array) $null; 126 } 127 128 } // end ctrl class 129 130 } //endif exist ctrl 131 132 133 /** admin actions in dashboard */ 134 135 136 if ( is_admin() && !class_exists('TTM_SettingsController') ){ 137 138 /* 139 * TawkTo Manager Setttings Controller 140 * Creates and manages admin settings page back-end 141 */ 142 143 class TTM_SettingsController extends TTM_Controller{ 144 145 public function __construct() { 146 parent::__construct(); 147 add_action( 'admin_menu', array(__CLASS__, 'ttm_tawkto_manager_plugin_menu') ); // add menu to wp dash 148 add_action('admin_init', array(__CLASS__, '__ttm_init') ); // load plugin options and settings page 149 } 150 151 152 static function __ttm_init(){ 153 self::__register_settings(); 154 self::__ttm_init_options(); 155 } 156 157 158 static function ttm_tawkto_manager_plugin_menu() { 159 /** create admin options menu */ 160 add_options_page('TawkTo Manager Plugin Options', 161 'TawkTo settings','manage_options', 162 TTM_SETTINGS_PAGE,array( __CLASS__, 163 'ttm_tawkto_manager_plugin_options' ) ); 164 } 165 166 167 static function ttm_tawkto_manager_plugin_options() { 168 169 /** check if admin */ 170 if ( !current_user_can( 'manage_options' ) ) { 171 wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 172 } 173 174 // process settings form on submit 175 if($_SERVER['REQUEST_METHOD'] == 'POST'){ 176 177 /** Validate secure referrer nonce */ 178 $nonce = $_POST['security']; 179 if ( ! wp_verify_nonce( $nonce, 'sec-callback' ) ) { 180 wp_die(); // nonce not valid so die 181 return; 182 } 183 184 /** process user input and update script */ 185 $replace = "<!--Start of Tawk.to Script-->"; 186 $_POST['ttm_tawktoscript'] = trim(str_replace($replace, "", $_POST['ttm_tawktoscript'])); 187 $replace = '<script type=\"text/javascript\">'; 188 $_POST['ttm_tawktoscript'] = trim(str_replace($replace, "", $_POST['ttm_tawktoscript'])); 189 $replace = '</script>'; 190 $_POST['ttm_tawktoscript'] = str_replace($replace, "", $_POST['ttm_tawktoscript']); 191 $replace = '<!--End of Tawk.to Script-->'; 192 $_POST['ttm_tawktoscript'] = str_replace($replace, "", $_POST['ttm_tawktoscript']); 193 194 /* eval and persist to wordpress options */ 195 self::$ttm_tawktoscript = $_POST['ttm_tawktoscript']; 196 update_option('ttm_tawktoscript', self::$ttm_tawktoscript ); 197 if(isset($_POST['ttm_show_always']) && $_POST['ttm_show_always'] == "on" ){ 198 self::$ttm_show_always = "on"; 199 update_option('ttm_show_always', self::$ttm_show_always); 200 }else{ 201 self::$ttm_show_always = ''; 202 update_option('ttm_show_always', self::$ttm_show_always); 203 } 204 if(isset($_POST['ttm_show_front_page']) && $_POST['ttm_show_front_page'] == "on" ){ 205 self::$ttm_show_front_page = "on"; 206 update_option('ttm_show_front_page', self::$ttm_show_front_page); 207 }else{ 208 self::$ttm_show_front_page = ''; 209 update_option('ttm_show_front_page', self::$ttm_show_front_page); 210 } 211 if(isset($_POST['ttm_show_cat_pages']) && $_POST['ttm_show_cat_pages'] == "on" ){ 212 self::$ttm_show_cat_pages = "on"; 213 update_option('ttm_show_cat_pages', self::$ttm_show_cat_pages); 214 }else{ 215 self::$ttm_show_cat_pages = ''; 216 update_option('ttm_show_cat_pages', self::$ttm_show_cat_pages); 217 } 218 if(isset($_POST['ttm_show_tag_pages']) && $_POST['ttm_show_tag_pages'] == "on" ){ 219 self::$ttm_show_tag_pages = "on"; 220 update_option('ttm_show_tag_pages', self::$ttm_show_tag_pages); 221 }else{ 222 self::$ttm_show_tag_pages = ''; 223 update_option('ttm_show_tag_pages', self::$ttm_show_tag_pages); 224 } 225 if(isset($_POST['ttm_hide_admin']) && $_POST['ttm_hide_admin'] == "on" ){ 226 self::$ttm_hide_admin = "on"; 227 update_option('ttm_hide_admin', self::$ttm_hide_admin); 228 }else{ 229 self::$ttm_hide_admin = ''; 230 update_option('ttm_hide_admin', self::$ttm_hide_admin); 231 } 232 if(isset($_POST['ttm_hide_subscribers']) && $_POST['ttm_hide_subscribers'] == "on" ){ 233 self::$ttm_hide_subscribers = "on"; 234 update_option('ttm_hide_subscribers', self::$ttm_hide_subscribers); 235 }else{ 236 self::$ttm_hide_subscribers = ''; 237 update_option('ttm_hide_subscribers', self::$ttm_hide_subscribers); 238 } 239 if(isset($_POST['ttm_hide_not_subscriber']) && $_POST['ttm_hide_not_subscriber'] == "on" ){ 240 self::$ttm_hide_not_subscriber = "on"; 241 update_option('ttm_hide_not_subscriber', self::$ttm_hide_not_subscriber); 242 }else{ 243 self::$ttm_hide_not_subscriber = ''; 244 update_option('ttm_hide_not_subscriber', self::$ttm_hide_not_subscriber); 245 } 246 247 } 248 249 self::createNonce(); // secure referrer nonce 250 include( TTM_ABSPATH . '/settings.ctp.php'); // page view file with html form 251 252 } 253 254 } // end class ctrlsettings 255 256 257 $ttmSettingsPage = new TTM_SettingsController(); 258 259 260 /* front-side end of plugin */ 261 262 263 }elseif( !class_exists('TTM_PluginController') ) { 264 265 /* 266 * TawkTo Manager Plugin controller 267 * Manages tawk.to window front-side 268 * 269 */ 270 271 class TTM_PluginController extends TTM_Controller{ 272 273 public function __construct(){ 274 add_shortcode('tawkto_show', array(__CLASS__, 'ttm_eval_short_code') ); 275 add_action( 'wp_head', array(__CLASS__, 'ttm_add_to_header') ); // add tawkto inline script to header 276 self::__ttm_init_options(); 277 } 278 279 280 static function ttm_eval_short_code(){ 281 /* short code eval hide/show chat */ 282 if(!is_category() && !is_tag()){ 283 /* Call here to add inlinet to body */ 284 if(self::ttm_eval_show() != false){ 285 self::ttm_out_script(); 286 } 287 288 } 289 } 290 291 /* Evaluate show/hide logged in users */ 292 293 static function ttm_eval_show(){ 294 295 if(is_user_logged_in()){ 296 if(self::is_admin_logged_in()){ // hide if admin and hide on 297 if(self::$ttm_hide_admin == 'on'){ 298 return false; 299 } 300 }else{ // eval for user role 301 $roles = self::role_is_logged_in(); 302 switch ($roles[0]) { 303 case 'subscriber': 304 if(self::$ttm_hide_subscribers == 'on'){ 305 return false; 306 } 307 break; 308 default: 309 return true; 310 break; 311 } 312 } 313 }else{ 314 // eval for user not logged in 315 316 if(self::$ttm_hide_not_subscriber == 'on'){ 317 return false; 318 } 319 320 } 321 322 return true; 323 324 } 325 326 327 static function ttm_add_to_header(){ 328 /* eval show tawkto (hook wp_head action) adds inline */ 329 if(self::ttm_eval_show() == false){ 330 return; 331 } 332 /* if show_always */ 333 if(self::$ttm_show_always){ 334 self::ttm_out_script(); 335 return; 336 } 337 /* front page */ 338 if(is_front_page() || is_home()){ 339 if(self::$ttm_show_front_page){ 340 self::ttm_out_script(); 341 return; 342 } 343 } 344 /* category pages */ 345 if(is_category()){ 346 if(self::$ttm_show_cat_pages){ 347 self::ttm_out_script(); 348 return; 349 } 350 } 351 /* tag pages */ 352 if(is_tag()){ 353 if(self::$ttm_show_tag_pages){ 354 self::ttm_out_script(); 355 return; 356 } 357 } 358 } 359 360 private static function ttm_out_script(){ 361 /* outputs inline to html source where called */ 362 echo '<script>'.PHP_EOL; 363 echo wp_unslash(self::$ttm_tawktoscript).PHP_EOL; 364 echo '</script>'.PHP_EOL; 365 366 } 367 368 } // end class ctrl plugin 369 370 371 $ttmPlugin = new TTM_PluginController(); 372 373 374 } // endif exist ctrl plugin 375
Note: See TracChangeset
for help on using the changeset viewer.