/var/www/html_it/wp-content/plugins/loco-translate/src/admin/config/SettingsController.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
 *  Site-wide Loco options (plugin settings)
 */
class Loco_admin_config_SettingsController extends Loco_admin_config_BaseController {


    
/**
     * {@inheritdoc}
     */
    
public function init(){
        
parent::init();
        
        
// set current plugin options and defaults for placeholders
        
$opts Loco_data_Settings::get();
        
$this->set'opts'$opts );
        
$this->set'dflt'Loco_data_Settings::create() );
        
        
// roles and capabilities
        
$perms = new Loco_data_Permissions;

        
// handle save action 
        
$nonce $this->setNonce('save-config');
        try {
            if( 
$this->checkNonce($nonce->action) ){
                
$post Loco_mvc_PostParams::get();
                if( 
$post->has('opts') ){
                    
$opts->populate$post->opts )->persist();
                    
$perms->populate$post->has('caps') ? $post->caps : [] );
                    
// done update
                    
Loco_error_AdminNotices::success__('Settings saved','loco-translate') );
                    
// remove saved params from session if persistent options unset
                    
if( ! $opts['fs_persist'] ){
                        
$session Loco_data_Session::get();
                        if( isset(
$session['loco-fs']) ){
                            unset( 
$session['loco-fs'] );
                            
$session->persist();
                        }
                    }
                }
            }
        }
        catch( 
Loco_error_Exception $e ){
            
Loco_error_AdminNotices::add($e);
        }

        
$this->set('caps'$caps = new Loco_mvc_ViewParams );
        
// there is no distinct role for network admin, so we'll fake it for UI
        
if( is_multisite() ){
            
$caps[''] = new Loco_mvc_ViewParams( [
                
'label' => __('Super Admin','loco-translate'),
                
'name' => 'dummy-admin-cap',
                
'attrs' => 'checked disabled'
            
] );
        }
        foreach( 
$perms->getRoles() as $id => $role ){
            
$caps[$id] = new Loco_mvc_ViewParams( [
                
'value' => '1',
                
'label' => $perms->getRoleName($id),
                
'name' => 'caps['.$id.'][loco_admin]',
                
'attrs' => $perms->isProtectedRole($role) ? 'checked disabled ' : ( $role->has_cap('loco_admin') ? 'checked ' '' ),
            ] );
        }
        
// allow/deny warning levels
        
$this->set('verbose', new Loco_mvc_ViewParams( [
            
=> __('Allow','loco-translate'),
            
=> __('Allow (with warning)','loco-translate'),
            
=> __('Disallow','loco-translate'),
        ] ) );
    }



    
/**
     * {@inheritdoc}
     */
    
public function render(){
        
        
$title __('Plugin settings','loco-translate');
        
$breadcrumb = new Loco_admin_Navigation;
        
$breadcrumb->add$title );
        
        return 
$this->view('admin/config/settings'compact('breadcrumb') ); 
    }
    
}