Plugin Directory

Changeset 2161303


Ignore:
Timestamp:
09/23/2019 10:38:36 AM (7 years ago)
Author:
thapa.laxman
Message:

added email notification option

Location:
automatic-updates/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • automatic-updates/trunk/Laksh_Automatic_Updates_Core.php

    r2062697 r2161303  
    99class Laksh_Automatic_Updates_Core{
    1010    const OPTION_KEY = 'laksh_automatic_updates_core_type';
     11    const OPTION_NOTIFICATION_KEY = 'laksh_automatic_updates_notification';
    1112    protected $updateTypes = [];
    1213
     
    4041    }
    4142
     43    public function updateNotifications($allowNotification = false)
     44    {
     45        update_option(self::OPTION_NOTIFICATION_KEY, $allowNotification);
     46    }
     47
     48    public function isNotificationEnabled()
     49    {
     50        //return 1 for default
     51        $isNotificationEnabled = get_option(self::OPTION_NOTIFICATION_KEY);
     52        //return 1 if value from db is other than 0,1 or minor
     53        return $isNotificationEnabled;
     54    }
     55
    4256
    4357
  • automatic-updates/trunk/README.txt

    r2062714 r2161303  
    44Tags: automatic-updates, update-plugins
    55Requires at least: 4.0.0
    6 Tested up to: 5.1.1
    7 Stable tag: 1.2
     6Tested up to: 5.2.3
     7Stable tag: 1.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1313== Description ==
    1414<h3>Automatic Updates</h3> allows admin to manage the automatic updates of the core wordpress and the plugins.
     15The plugin will also allow admin to toggle email notifications with wordpress updates.
    1516
    16 = Why use Automatic Updates Plugin =
     17= Do I need to update any config files? =
    1718No, you do not if you can modify the wp-config.php.
    1819
  • automatic-updates/trunk/automatic-updates.php

    r2062714 r2161303  
    1818add_filter( 'allow_major_auto_core_updates', '__return_true' );
    1919
    20 add_action( 'wp_ajax_laksh_automatic_update_core', 'laksh_automatic_udpates_core_handler' );
    21 add_action( 'wp_ajax_nopriv_laksh_automatic_update_core', 'laksh_automatic_udpates_core_handler' );
     20add_action( 'wp_ajax_laksh_automatic_update_core', 'laksh_automatic_updates_core_handler' );
     21//add_action( 'wp_ajax_nopriv_laksh_automatic_update_core', 'laksh_automatic_updates_core_handler' );
    2222
    23 add_action( 'wp_ajax_laksh_automatic_update_plugin', 'laksh_automatic_udpates_plugin_handler' );
    24 add_action( 'wp_ajax_nopriv_laksh_automatic_update_plugin', 'laksh_automatic_udpates_plugin_handler' );
     23add_action( 'wp_ajax_laksh_automatic_update_plugin', 'laksh_automatic_updates_plugin_handler' );
     24//add_action( 'wp_ajax_nopriv_laksh_automatic_update_plugin', 'laksh_automatic_updates_plugin_handler' );
     25
     26
     27add_action( 'wp_ajax_laksh_automatic_update_notification', 'laksh_automatic_updates_notification_handler' );
     28//add_action( 'wp_ajax_nopriv_laksh_automatic_update_notification', 'laksh_automatic_updates_notification_handler' );
    2529
    2630
     
    3034        'manage_options',    //created custom capability for the artist role
    3135        'manage-updates',
    32         'laksh_automatic_udpates_manage_handler',
     36        'laksh_automatic_updates_manage_handler',
    3337        'dashicons-admin-tools');
    3438});
     
    3640
    3741//set updates
    38 function laksh_automatic_udpates_init(){
     42function laksh_automatic_updates_init(){
    3943    $coreUpdateType = (new Laksh_Automatic_Updates_Core())->getCoreUpdateOption();
    4044    $pluginIgnoredList = (new Laksh_Automatic_Updates_Plugin())->getIgnoredPlugins();
     45
     46    $isNotificationEnabled = (new Laksh_Automatic_Updates_Core())->isNotificationEnabled();
     47
     48    if(!$isNotificationEnabled){
     49        var_dump('disable email');
     50        add_filter( 'auto_core_update_send_email', '__return_false' );
     51    }
     52    //var_dump($coreUpdateType,$pluginIgnoredList,$isNotificationEnabled);
    4153
    4254    switch ($coreUpdateType){
     
    6678
    6779
    68     add_filter( 'auto_update_plugin', 'laksh_automatic_udpates_specific_plugin_handler', 10, 2 );
     80    add_filter( 'auto_update_plugin', 'laksh_automatic_updates_specific_plugin_handler', 10, 2 );
    6981}
    7082
    71 laksh_automatic_udpates_init();
     83laksh_automatic_updates_init();
    7284
    73 function laksh_automatic_udpates_specific_plugin_handler ( $update, $item ) {
     85function laksh_automatic_updates_specific_plugin_handler ( $update, $item ) {
    7486    $pluginIgnoredList = (new Laksh_Automatic_Updates_Plugin())->getIgnoredPlugins();
    7587    if(in_array($item->slug, $pluginIgnoredList)){
     
    8092
    8193
    82 function laksh_automatic_udpates_core_handler(){
     94function laksh_automatic_updates_core_handler(){
    8395    $updateType = (isset($_GET['updateType']) && $_GET['updateType']!='') ? $_GET['updateType'] : false;
    8496    if($updateType === false) die('unknown type');
     
    91103}
    92104
    93 function laksh_automatic_udpates_plugin_handler(){
     105function laksh_automatic_updates_plugin_handler(){
    94106    $pluginSlug = (isset($_GET['slug']) && $_GET['slug']!='') ? $_GET['slug'] : null;
    95107    $pluginStatus = (isset($_GET['status']) && $_GET['status']!='') ? filter_var($_GET['status'], FILTER_VALIDATE_INT)  : false;
     
    109121
    110122
    111 function laksh_automatic_udpates_manage_handler(){
     123function laksh_automatic_updates_notification_handler(){
     124    if(!isset($_GET['allow'])){
     125        die();
     126    }
     127
     128    $isNotificationEnabled = (isset($_GET['allow']) && $_GET['allow']!='') ? $_GET['allow'] : false;
     129    (new Laksh_Automatic_Updates_Core())->updateNotifications($isNotificationEnabled);
     130    //echo wp_send_json($autoUpdater->getCoreUpdateOption());
     131    die();
     132}
     133
     134function laksh_automatic_updates_manage_handler(){
    112135    //$activePlugins = get_option( 'active_plugins', [] );
    113136
     
    121144    $coreUpdateTypes = $coreAutoUpdater->getCoreUpdateTypes();
    122145
     146    $isNotificationEnabled = $coreAutoUpdater->isNotificationEnabled();
     147
    123148    //$ignoredPlugins = [];
    124149
  • automatic-updates/trunk/inc/form.php

    r2062697 r2161303  
    1313                    <?php endforeach; ?>
    1414                </select>
     15            </p>
     16            <p><label><input type="checkbox" <?=($isNotificationEnabled==true) ? "checked" : ""?> class="update-notification" >Enable email notifications</label>
    1517            </p>
    1618        </div>
     
    104106        xhr.send();
    105107    }
     108    function laksh_automatic_updates_notification(isnotificationEnabled){
     109        coreUpdateWrapper.classList.add('show');
     110        if(isCoreUpdateBusy) return;
     111        var xhr = new XMLHttpRequest();
     112        xhr.onload = function () {
     113            isCoreUpdateBusy = false;
     114            coreUpdateWrapper.classList.remove('show');
     115        };
     116        xhr.open('GET', ajaxUrl+"?action=laksh_automatic_update_notification&allow="+isnotificationEnabled);
     117        xhr.send();
     118    }
    106119
    107120    document.querySelectorAll('.js-laksh-plugins-auto-update-input').forEach(function(input){
     
    116129    document.getElementById('core-update-type').addEventListener('change', function(event){
    117130        laksh_automatic_updates_core(event.currentTarget.value);
    118     })
     131    });
     132
     133    document.querySelector('.update-notification').addEventListener('change', function(event){
     134        var notificationVal = (event.currentTarget.checked) ? 1 : 0;
     135        laksh_automatic_updates_notification(notificationVal);
     136    });
     137
    119138})();
    120139</script>
Note: See TracChangeset for help on using the changeset viewer.