Plugin Directory

Changeset 1178131


Ignore:
Timestamp:
06/10/2015 10:51:50 AM (11 years ago)
Author:
baseapp
Message:

Added email send as option.

Location:
wpbase-cache/trunk/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wpbase-cache/trunk/trunk/wpbase-cache-admin.php

    r989862 r1178131  
    11<?php
     2
    23class WPBase_Cache_Admin {
    34
    4     public function __construct(){
     5    public function __construct() {
    56        add_action('admin_menu', array($this, 'add_wpbase_cache_page'));
    67        add_action('admin_init', array($this, 'wpbase_cache_page_init'));
     
    1617
    1718    public function create_wpbase_cache_page() {
    18         if( ! current_user_can('manage_options') ) {
    19             wp_die( __('You do not have sufficient permissions to access this page.') );
     19        if (!current_user_can('manage_options')) {
     20            wp_die(__('You do not have sufficient permissions to access this page.'));
    2021        }
    2122        ?>
    2223        <div class="wrap">
    23             <?php screen_icon(); ?>
     24        <?php screen_icon(); ?>
    2425            <h2>WPBase Cache</h2>
    2526            <form method="post" action="options.php">
    2627                <?php
    27                     settings_fields('wpbase_cache_options');
    28                     do_settings_sections('wpbasecache');
     28                settings_fields('wpbase_cache_options');
     29                do_settings_sections('wpbasecache');
    2930                ?>
    30                 <?php submit_button(); ?>
     31        <?php submit_button(); ?>
    3132                <a class="button" id="wpbase_cache_flush_all">Empty All Caches</a>
    3233            </form>
     
    3940
    4041        add_settings_section(
    41             'wpbase_cache_section',
    42             'WPBase Cache Settings',
    43             array($this, 'wpbase_cache_section_desc'),
    44             'wpbasecache'
     42                'wpbase_cache_section', 'WPBase Cache Settings', array($this, 'wpbase_cache_section_desc'), 'wpbasecache'
    4543        );
    4644
    47      
     45
    4846
    4947        add_settings_field(
    50             'wpbase_cache_options_varnish_cache',
    51             'Enable Varnish Cache',
    52             array($this, 'varnish_cache_input'),
    53             'wpbasecache',
    54             'wpbase_cache_section'
     48                'wpbase_cache_options_varnish_cache', 'Enable Varnish Cache', array($this, 'varnish_cache_input'), 'wpbasecache', 'wpbase_cache_section'
    5549        );
    5650
     51        add_settings_field(
     52                'wpbase_cache_options_send_as', 'Send Mail As', array($this, 'send_as_input'), 'wpbasecache', 'wpbase_cache_section'
     53        );
    5754    }
    5855
     
    6158    }
    6259
    63    
    6460    public function varnish_cache_input() {
    6561        $options = get_option('wpbase_cache_options');
    6662
    6763        $checked = checked(1, $options['varnish_cache'], FALSE);
    68         if(!(defined('WPBASE_CACHE_SANDBOX') && WPBASE_CACHE_SANDBOX)) {
     64        if (!(defined('WPBASE_CACHE_SANDBOX') && WPBASE_CACHE_SANDBOX)) {
    6965            echo "<input id='wpbase_cache_varnish_cache' name='wpbase_cache_options[varnish_cache]' type='checkbox' value='1' $checked />";
    7066        } else {
    7167            echo "<input id='wpbase_cache_varnish_cache' disabled='disabled' name='wpbase_cache_options[varnish_cache]' type='checkbox' value='1' $checked />";
     68        }
     69    }
     70
     71    public function send_as_input() {
     72        $options = get_option('wpbase_cache_options');
     73
     74        if($options['send_as']!=''){
     75            $send_as= $options['send_as'];
     76        }
     77        if (!(defined('WPBASE_CACHE_SANDBOX') && WPBASE_CACHE_SANDBOX)) {
     78            echo "<input id='wpbase_cache_send_as' name='wpbase_cache_options[send_as]' type='text' value='$send_as' />@yourdomain.com <br /><font color='gray'> Leave field empty to disable this feature.</font>";
     79        } else {
     80            echo "<input id='wpbase_cache_send_as' disabled='disabled' name='wpbase_cache_options[send_as]' type='checkbox' value='1' />";
    7281        }
    7382    }
     
    7786        ?>
    7887        <script type="text/javascript" >
    79         jQuery(document).ready(function($) {
     88            jQuery(document).ready(function($) {
    8089
    81             $('#wpbase_cache_flush_all').click(function(){
    82                 var element = $(this);
    83                 var data = {
    84                     action: 'wpbase_cache_flush_all',
    85                     _ajax_nonce: '<?php echo $nonce; ?>'
    86                 };
     90                $('#wpbase_cache_flush_all').click(function() {
     91                    var element = $(this);
     92                    var data = {
     93                        action: 'wpbase_cache_flush_all',
     94                        _ajax_nonce: '<?php echo $nonce; ?>'
     95                    };
    8796
    88                 $.post(ajaxurl, data, function(response) {
    89                     if(response == 1) {
    90                         message = 'Sucessfully flushed all caches';
    91                     } else if(response == -1) {
    92                         message = 'Unauthorised request';
    93                     } else {
    94                         message = response;
    95                     }
    96                     element.replaceWith(message);
     97                    $.post(ajaxurl, data, function(response) {
     98                        if (response == 1) {
     99                            message = 'Sucessfully flushed all caches';
     100                        } else if (response == -1) {
     101                            message = 'Unauthorised request';
     102                        } else {
     103                            message = response;
     104                        }
     105                        element.replaceWith(message);
     106                    });
    97107                });
    98108            });
    99         });
    100109        </script>
    101110        <?php
     
    105114        check_ajax_referer('wpbase_cache_flush_all');
    106115
    107         if(!current_user_can('manage_options')) {
    108             wp_die( __('You do not have sufficient permissions to perform this action.') );
     116        if (!current_user_can('manage_options')) {
     117            wp_die(__('You do not have sufficient permissions to perform this action.'));
    109118        }
    110119
     
    118127
    119128    public function update_options($oldvalue, $newvalue) {
    120      
     129       
    121130    }
    122131
  • wpbase-cache/trunk/trunk/wpbase-cache.php

    r1175754 r1178131  
    44Plugin URI: https://github.com/baseapp/wpbase-cache
    55Description: A wordpress plugin for using all caches on varnish, nginx, php-fpm stack with php-apc. This plugin includes db-cache-reloaded-fix for dbcache.
    6 Version: 1.0.7
     6Version: 2.0
    77Author: Vikrant Datta
    88Author URI: http://blog.wpoven.com
     
    3030//$path = dirname(dirname(dirname(__FILE__)));
    3131//if(is_file($path.'/db.php')){
    32   //  rename($path.'/db.php',$path.'/db_old.php');
     32 //   rename($path.'/db.php',$path.'/db_old.php');
    3333//}
    3434function upon_activation(){
     
    6262            'db_cache' => '0',
    6363            'varnish_cache' => '1',
     64            'send_as' => 'noreply'
    6465            //'reject_url' => '',
    6566            //'reject_cookie' => '',
     
    7778            'db_cache' => '0',
    7879            'varnish_cache' => '0',
     80             'send_as' =>'0'
    7981            //'reject_url' => '',
    8082            //'reject_cookie' => '',
     
    183185    }
    184186}
     187
     188add_filter('wp_mail_from', 'mail_from');
     189add_filter('wp_mail_from_name', 'mail_from_name');
     190function mail_from($email){
     191   
     192    $options = get_option('wpbase_cache_options');
     193    $send_as = $options['send_as'];
     194    if($send_as != ''){
     195        $sitename = strtolower($_SERVER['SERVER_NAME']);
     196        $sitename = str_replace('www.','',$sitename);
     197        if($_SERVER['SERVER_PORT'] == '8080'){
     198            $dom = explode('/',$_SERVER['REQUEST_URI']);
     199            return $send_as.'@'.$dom[1];
     200        }
     201        else{
     202            return $send_as.'@'.$sitename;
     203        }
     204           
     205    //$sitename = substr($sitename,0,4)=='www.' ? substr($sitename, 4) : $sitename;
     206    }
     207   
     208}
     209function mail_from_name($name){
     210    $options = get_option('wpbase_cache_options');
     211    $send_as = $options['send_as'];
     212    if($send_as != ''){
     213        return $send_as;
     214    }
     215   
     216}
Note: See TracChangeset for help on using the changeset viewer.