Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // classe istanziata dal plugin (tolto tutto ciò che non serve)
- class Nda4Axis {
- function __construct() {
- // role: admin
- add_action('edit_user_profile',[self::class, "edit_user_profile"]);
- add_action('edit_user_profile_update',[self::class, "save_user_profile"]);
- // custom role: partner
- add_action('show_user_profile',[self::class, "edit_user_profile"]);
- add_action('personal_options_update',[self::class, "save_user_profile"]);
- }
- static function edit_user_profile(WP_User $user){
- $utente = new NdaUser($user->ID);
- if ( $utente->is_partner() ){
- $utente->show_admin_user_fields();
- }
- }
- static function save_user_profile($user){
- $utente = new NdaUser($user);
- if ($utente->is_partner()){
- $utente->save_admin_user_fields();
- }
- }
- }
- // classe che gestisce l'utente (tolto tutto ciò che non serve)
- class NdaUser extends WP_User {
- /**
- * user meta key / value
- */
- const META_K_NDA_ACCEPTED = '_nda_accepted';
- const META_V_NDA_IS_OK = '1';
- const META_V_NDA_IS_NOT_OK = "0";
- const META_K_NDA_USER_ACTIVE = '_nda_user_active';
- const META_V_NDA_USER_ACTIVE_OK = '1';
- const META_V_NDA_USER_ACTIVE_NOT_OK = '0';
- const META_K_NDA_AZIENDA_NOME = '_nda_azienda_nome';
- const META_K_NDA_AZIENDA_INDIRIZZO = '_nda_azienda_indirizzo';
- public function __construct($id = 0, $name = '', $blog_id = '') {
- parent::__construct($id, $name, $blog_id);
- }
- public function is_partner() {
- if (in_array(NDA_ROLE, $this->roles)) {
- return true;
- }
- return false;
- }
- public function show_admin_user_fields() {
- ?>
- <h2 style='background: #ccc; padding: 5px 10px; border-radius: 2px;'><?php _e("Other Partner Info", NDA_TEXTDOMAIN);?></h2>
- <h3 style='border-bottom: 1px solid gray;'><?php _e("User status", NDA_TEXTDOMAIN);?></h3>
- <table class="form-table">
- <tr>
- <th>
- <label for=""><?php _e("NDA accepted",NDA_TEXTDOMAIN);?></label>
- </th>
- <td>
- <?php echo $this->is_meta_nda_accepted() ? _e("Yes",NDA_TEXTDOMAIN) : _e("No",NDA_TEXTDOMAIN);?>
- </td>
- </tr>
- <tr>
- <th>
- <label for="<?php echo self::META_K_NDA_USER_ACTIVE?>"><?php _e("User status",NDA_TEXTDOMAIN);?></label>
- </th>
- <td>
- <input type="checkbox" name="<?php echo self::META_K_NDA_USER_ACTIVE?>" value="<?php echo self::META_V_NDA_USER_ACTIVE_OK?>" <?php if ($this->is_meta_nda_user_active()){ echo " checked ";}?> <?php if (!is_super_admin()){echo " disabled";}?>> <?php _e("User active",NDA_TEXTDOMAIN)?>
- </td>
- </tr>
- </table>
- <h3 style='border-bottom: 1px solid gray'><?php _e("Company",NDA_TEXTDOMAIN)?></h3>
- <table class="form-table">
- <tr>
- <th>
- <label for="<?php self::META_K_NDA_AZIENDA_NOME?>"><?php _e('Company',NDA_TEXTDOMAIN); ?></label>
- </th>
- <td>
- <input type="text" name="<?php echo self::META_K_NDA_AZIENDA_NOME?>" id="<?php echo self::META_K_NDA_AZIENDA_NOME?>" value="<?php echo esc_attr(get_the_author_meta(self::META_K_NDA_AZIENDA_NOME,$this->ID)); ?>" class="regular-text" />
- <br><span class="description"><?php _e('Your company name.', NDA_TEXTDOMAIN); ?></span>
- </td>
- </tr>
- <tr>
- <th>
- <label for="<?php self::META_K_NDA_AZIENDA_INDIRIZZO?>"><?php _e('Address',NDA_TEXTDOMAIN); ?></label>
- </th>
- <td>
- <input type="text" name="<?php echo self::META_K_NDA_AZIENDA_INDIRIZZO?>" id="<?php echo self::META_K_NDA_AZIENDA_INDIRIZZO?>" value="<?php echo esc_attr(get_the_author_meta(self::META_K_NDA_AZIENDA_INDIRIZZO,$this->ID)); ?>" class="regular-text" />
- <br><span class="description"><?php _e('Complete address.', NDA_TEXTDOMAIN); ?></span>
- </td>
- </tr>
- </table>
- <?php
- }
- public function save_admin_user_fields(){
- $meta_v_nda_user_active_form_value = filter_input(INPUT_POST, self::META_K_NDA_USER_ACTIVE, FILTER_SANITIZE_STRING);
- if (is_super_admin()) {
- update_user_meta($this->ID, self::META_K_NDA_USER_ACTIVE, $meta_v_nda_user_active_form_value);
- }
- update_user_meta($this->ID, self::META_K_NDA_AZIENDA_NOME, filter_input(INPUT_POST, self::META_K_NDA_AZIENDA_NOME, FILTER_SANITIZE_STRING));
- update_user_meta($this->ID, self::META_K_NDA_AZIENDA_INDIRIZZO, filter_input(INPUT_POST, self::META_K_NDA_AZIENDA_INDIRIZZO, FILTER_SANITIZE_STRING));
- }
- }
Add Comment
Please, Sign In to add comment