[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-content/add-ons/ -> MailPress_roles_and_capabilities.php (source)

   1  <?php
   2  if (class_exists('MailPress') && !class_exists('MailPress_roles_and_capabilities'))
   3  {
   4  /*
   5  Plugin Name: MailPress_roles_and_capabilities
   6  Plugin URI: http://blog.mailpress.org/tutorials/add-ons/roles_and_capabilities/
   7  Description: Settings : manage roles &amp; capabilities
   8  Version: 5.4.4
   9  */
  10  
  11  class MailPress_roles_and_capabilities
  12  {
  13  	function __construct()
  14      {
  15      // for link on plugin page
  16          add_filter('plugin_action_links',             array(__CLASS__, 'plugin_action_links'), 10, 2 );
  17      // for role & capabilities
  18          add_action('MailPress_roles_and_capabilities',     array(__CLASS__, 'roles_and_capabilities'));
  19      // for settings
  20          add_filter('MailPress_styles',             array(__CLASS__, 'styles'), 8, 2);
  21          add_filter('MailPress_scripts',             array(__CLASS__, 'scripts'), 8, 2);
  22          add_filter('MailPress_settings_tab',         array(__CLASS__, 'settings_tab'), 45, 1);
  23      //for ajax
  24          add_action('mp_action_r_and_c',            array(__CLASS__, 'mp_action_r_and_c'));
  25      }
  26  
  27  ////  ADMIN  ////
  28  ////  ADMIN  ////
  29  ////  ADMIN  ////
  30  ////  ADMIN  ////
  31  
  32  // for link on plugin page
  33  	public static function plugin_action_links($links, $file)
  34      {
  35          return MailPress::plugin_links($links, $file, plugin_basename(__FILE__), 'roles_and_capabilities');
  36      }
  37  
  38  // for role & capabilities
  39  	public static function roles_and_capabilities()
  40      {
  41          global $wp_roles;
  42          $capabilities = MailPress::capabilities();
  43  
  44          foreach($wp_roles->role_names as $role => $name)
  45          {
  46              if ('administrator' == $role) continue;
  47  
  48              $r = get_role($role);
  49              $rcs = get_option('MailPress_r&c_' . $role);
  50  
  51              foreach ($capabilities as $capability => $v)
  52              {
  53                  if (isset($rcs[$capability]))     $r->add_cap($capability);
  54                  else                        $r->remove_cap($capability);
  55              }
  56          }
  57      }
  58  
  59  // for settings
  60  
  61  	public static function styles($styles, $screen) 
  62      {
  63          if ($screen != MailPress_page_settings) return $styles;
  64  
  65          wp_register_style ( 'mp-r-and-c', '/' . MP_PATH . 'mp-admin/css/settings_roles_and_capabilities.css');
  66          $styles[] = 'mp-r-and-c';
  67  
  68          return $styles;
  69      }
  70  
  71  	public static function scripts($scripts, $screen) 
  72      {
  73          if ($screen != MailPress_page_settings) return $scripts;
  74  
  75          wp_register_script( 'mp-r-and-c', '/' . MP_PATH . 'mp-admin/js/settings_roles_and_capabilities.js', array('jquery'), false, 1);
  76  
  77          $scripts[] = 'mp-r-and-c';
  78  
  79          return $scripts;
  80      }
  81  
  82  	public static function settings_tab($tabs)
  83      {
  84          $tabs['roles_and_capabilities'] = __('R&amp;C', MP_TXTDOM);
  85          return $tabs;
  86      }
  87  
  88  	public static function mp_action_r_and_c()
  89      {
  90          $rcs_option = 'MailPress_r&c_' . $_POST['role'];
  91          $r = get_role($_POST['role']);
  92  
  93          $rcs = get_option($rcs_option);
  94          if (empty($rcs)) $rcs = array();
  95  
  96          if ($_POST['add'])
  97          {
  98              $rcs[$_POST['capability']] = 'on';
  99              if ($r) $r->add_cap($_POST['capability']);
 100          }
 101          else
 102          {
 103              unset ($rcs[$_POST['capability']] );
 104              if ($r) $r->remove_cap($_POST['capability']);
 105          }
 106          if (!add_option ($rcs_option, $rcs )) update_option ($rcs_option, $rcs);
 107  
 108          MP_::mp_die(1);
 109      }
 110  }
 111  new MailPress_roles_and_capabilities();
 112  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1