slug = 'ultimatemember'; $this->in_edit = false; $this->edit_mode_value = null; add_action('admin_head', array(&$this, 'admin_head'), 9); add_action('admin_footer', array(&$this, 'load_modal_content'), 9); add_action( 'load-post.php', array(&$this, 'add_metabox'), 9 ); add_action( 'load-post-new.php', array(&$this, 'add_metabox'), 9 ); add_action( 'save_post', array(&$this, 'remove_rewrite_rules_option'), 10, 2 ); } /*** *** @unset rewrite rules if the slug was changed ***/ function remove_rewrite_rules_option( $post_id ) { if ( ! wp_is_post_revision( $post_id ) ) { if ( get_post_meta($post_id, '_um_core', true) ) { delete_option('um_flush_rules'); // so they reset rewrite rules } } } /*** *** @Boolean check if we're viewing UM backend ***/ function is_UM_admin(){ global $current_screen; $screen_id = $current_screen->id; if ( is_admin() && ( strstr( $screen_id, 'ultimatemember') || strstr( $screen_id, 'um_') || strstr($screen_id, 'user') || strstr($screen_id, 'profile') ) ) return true; return false; } /*** *** @check that we're on a custom post type supported by UM ***/ function is_plugin_post_type(){ if (isset($_REQUEST['post_type'])){ $post_type = $_REQUEST['post_type']; if ( in_array($post_type, array('um_form','um_role','um_directory'))){ return true; } } else if ( isset($_REQUEST['action'] ) && $_REQUEST['action'] == 'edit') { $post_type = get_post_type(); if ( in_array($post_type, array('um_form','um_role','um_directory'))){ return true; } } return false; } /*** *** @Gets the role meta ***/ function get_custom_post_meta($id){ $all_meta = get_post_custom($id); foreach($all_meta as $k=>$v){ if (strstr($k, '_um_')){ $um_meta[$k] = $v; } } if (isset($um_meta)) return $um_meta; } /*** *** @Runs on admin head ***/ function admin_head(){ global $post; if ( $this->is_plugin_post_type() && isset($post->ID) ){ $this->postmeta = $this->get_custom_post_meta($post->ID); } } /*** *** @add a helper tooltip ***/ function _tooltip( $text ){ $output = ''; $output .= ''; $output .= ''; return $output; } /*** *** @add a helper tooltip ***/ function tooltip( $text, $e = false ){ ?> postmeta[$id][0]) || $meta ) { $active = ( isset( $this->postmeta[$id][0] ) ) ? $this->postmeta[$id][0] : $meta; } else { $active = $default; } if ($is_conditional == true) { $is_conditional = ' class="um-adm-conditional" data-cond1="'.$cond1.'" data-cond1-show="'.$cond1_show.'" data-cond1-hide="'.$cond1_hide.'"'; } ?> /> id == 'um_form'){ add_action( 'add_meta_boxes', array(&$this, 'add_metabox_form'), 1 ); add_action( 'save_post', array(&$this, 'save_metabox_form'), 10, 2 ); } if( $current_screen->id == 'um_role'){ add_action( 'add_meta_boxes', array(&$this, 'add_metabox_role'), 1 ); add_action( 'save_post', array(&$this, 'save_metabox_role'), 10, 2 ); } if( $current_screen->id == 'um_directory'){ add_action( 'add_meta_boxes', array(&$this, 'add_metabox_directory'), 1 ); add_action( 'save_post', array(&$this, 'save_metabox_directory'), 10, 2 ); } } /*** *** @load a directory metabox ***/ function load_metabox_directory( $object, $box ) { global $ultimatemember; $box['id'] = str_replace('um-admin-form-','', $box['id']); include_once um_path . 'admin/templates/directory/'. $box['id'] . '.php'; wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_directory_nonce' ); } /*** *** @load a role metabox ***/ function load_metabox_role( $object, $box ) { global $ultimatemember, $post; $box['id'] = str_replace('um-admin-form-','', $box['id']); if ( $box['id'] == 'builder' ) { $UM_Builder = new UM_Admin_Builder(); $UM_Builder->form_id = get_the_ID(); } preg_match('#\{.*?\}#s', $box['id'], $matches); if ( isset($matches[0]) ){ $path = $matches[0]; $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] ); } else { $path = um_path; } $path = str_replace('{','', $path ); $path = str_replace('}','', $path ); include_once $path . 'admin/templates/role/'. $box['id'] . '.php'; wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_role_nonce' ); } /*** *** @load a form metabox ***/ function load_metabox_form( $object, $box ) { global $ultimatemember, $post; $box['id'] = str_replace('um-admin-form-','', $box['id']); if ( $box['id'] == 'builder' ) { $UM_Builder = new UM_Admin_Builder(); $UM_Builder->form_id = get_the_ID(); } preg_match('#\{.*?\}#s', $box['id'], $matches); if ( isset($matches[0]) ){ $path = $matches[0]; $box['id'] = preg_replace('~(\\{[^}]+\\})~','', $box['id'] ); } else { $path = um_path; } $path = str_replace('{','', $path ); $path = str_replace('}','', $path ); include_once $path . 'admin/templates/form/'. $box['id'] . '.php'; wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_form_nonce' ); } /*** *** @add directory metabox ***/ function add_metabox_directory() { add_meta_box('um-admin-form-general', __('General Options'), array(&$this, 'load_metabox_directory'), 'um_directory', 'normal', 'default'); add_meta_box('um-admin-form-profile', __('Profile Card'), array(&$this, 'load_metabox_directory'), 'um_directory', 'normal', 'default'); add_meta_box('um-admin-form-search', __('Search Options'), array(&$this, 'load_metabox_directory'), 'um_directory', 'normal', 'default'); add_meta_box('um-admin-form-pagination', __('Results & Pagination'), array(&$this, 'load_metabox_directory'), 'um_directory', 'normal', 'default'); add_meta_box('um-admin-form-shortcode', __('Shortcode'), array(&$this, 'load_metabox_directory'), 'um_directory', 'side', 'default'); add_meta_box('um-admin-form-appearance', __('Styling: General'), array(&$this, 'load_metabox_directory'), 'um_directory', 'side', 'default'); add_meta_box('um-admin-form-profile_card', __('Styling: Profile Card'), array(&$this, 'load_metabox_directory'), 'um_directory', 'side', 'default'); } /*** *** @add role metabox ***/ function add_metabox_role() { add_meta_box('um-admin-form-admin', __('Administrative Permissions'), array(&$this, 'load_metabox_role'), 'um_role', 'normal', 'default'); add_meta_box('um-admin-form-general', __('General Permissions'), array(&$this, 'load_metabox_role'), 'um_role', 'normal', 'default'); add_meta_box('um-admin-form-profile', __('Profile Access'), array(&$this, 'load_metabox_role'), 'um_role', 'normal', 'default'); add_meta_box('um-admin-form-home', __('Homepage Options'), array(&$this, 'load_metabox_role'), 'um_role', 'normal', 'default'); add_meta_box('um-admin-form-register', __('Registration Options'), array(&$this, 'load_metabox_role'), 'um_role', 'normal', 'default'); add_meta_box('um-admin-form-login', __('Login Options'), array(&$this, 'load_metabox_role'), 'um_role', 'normal', 'default'); add_meta_box('um-admin-form-logout', __('Logout Options'), array(&$this, 'load_metabox_role'), 'um_role', 'normal', 'default'); add_meta_box('um-admin-form-delete', __('Delete Options'), array(&$this, 'load_metabox_role'), 'um_role', 'normal', 'default'); do_action('um_admin_custom_role_metaboxes'); } /*** *** @add form metabox ***/ function add_metabox_form() { add_meta_box('um-admin-form-mode', __('Select Form Type'), array(&$this, 'load_metabox_form'), 'um_form', 'normal', 'default'); add_meta_box('um-admin-form-builder', __('Form Builder'), array(&$this, 'load_metabox_form'), 'um_form', 'normal', 'default'); add_meta_box('um-admin-form-shortcode', __('Shortcode'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default'); add_meta_box('um-admin-form-register_customize', __('Customize this form'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default'); add_meta_box('um-admin-form-register_css', __('Custom CSS'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default'); do_action('um_admin_custom_register_metaboxes'); add_meta_box('um-admin-form-profile_customize', __('Customize this form'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default'); add_meta_box('um-admin-form-profile_settings', __('User Meta'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default'); add_meta_box('um-admin-form-profile_css', __('Custom CSS'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default'); do_action('um_admin_custom_profile_metaboxes'); add_meta_box('um-admin-form-login_customize', __('Customize this form'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default'); add_meta_box('um-admin-form-login_settings', __('Options'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default'); add_meta_box('um-admin-form-login_css', __('Custom CSS'), array(&$this, 'load_metabox_form'), 'um_form', 'side', 'default'); do_action('um_admin_custom_login_metaboxes'); } /*** *** @save directory metabox ***/ function save_metabox_directory( $post_id, $post ) { global $wpdb; // validate nonce if ( !isset( $_POST['um_admin_save_metabox_directory_nonce'] ) || !wp_verify_nonce( $_POST['um_admin_save_metabox_directory_nonce'], basename( __FILE__ ) ) ) return $post_id; // validate post type if ( $post->post_type != 'um_directory' ) return $post_id; // validate user $post_type = get_post_type_object( $post->post_type ); if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; $where = array( 'ID' => $post_id ); if (empty($_POST['post_title'])) $_POST['post_title'] = 'Directory #'.$post_id; $wpdb->update( $wpdb->posts, array( 'post_title' => $_POST['post_title'] ), $where ); // save delete_post_meta( $post_id, '_um_roles' ); delete_post_meta( $post_id, '_um_tagline_fields' ); delete_post_meta( $post_id, '_um_reveal_fields' ); delete_post_meta( $post_id, '_um_search_fields' ); delete_post_meta( $post_id, '_um_roles_can_search' ); foreach( $_POST as $k => $v ) { if (strstr($k, '_um_')){ update_post_meta( $post_id, $k, $v); } } } /*** *** @save role metabox ***/ function save_metabox_role( $post_id, $post ) { global $wpdb; // validate nonce if ( !isset( $_POST['um_admin_save_metabox_role_nonce'] ) || !wp_verify_nonce( $_POST['um_admin_save_metabox_role_nonce'], basename( __FILE__ ) ) ) return $post_id; // validate post type if ( $post->post_type != 'um_role' ) return $post_id; // validate user $post_type = get_post_type_object( $post->post_type ); if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; $where = array( 'ID' => $post_id ); if (empty($_POST['post_title'])) $_POST['post_title'] = 'Role #'.$post_id; $wpdb->update( $wpdb->posts, array( 'post_title' => $_POST['post_title'], 'post_name' => sanitize_title( $_POST['post_title'] ) ), $where ); // save delete_post_meta( $post_id, '_um_can_view_roles' ); delete_post_meta( $post_id, '_um_can_edit_roles' ); delete_post_meta( $post_id, '_um_can_delete_roles' ); foreach( $_POST as $k => $v ) { if (strstr($k, '_um_')){ update_post_meta( $post_id, $k, $v); } } } /*** *** @save form metabox ***/ function save_metabox_form( $post_id, $post ) { global $wpdb; // validate nonce if ( !isset( $_POST['um_admin_save_metabox_form_nonce'] ) || !wp_verify_nonce( $_POST['um_admin_save_metabox_form_nonce'], basename( __FILE__ ) ) ) return $post_id; // validate post type if ( $post->post_type != 'um_form' ) return $post_id; // validate user $post_type = get_post_type_object( $post->post_type ); if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; $where = array( 'ID' => $post_id ); if (empty($_POST['post_title'])) $_POST['post_title'] = 'Form #'.$post_id; $wpdb->update( $wpdb->posts, array( 'post_title' => $_POST['post_title'] ), $where ); // save delete_post_meta( $post_id, '_um_profile_metafields' ); foreach( $_POST as $k => $v ) { if (strstr($k, '_um_')){ update_post_meta( $post_id, $k, $v); } } } /*** *** @Load modal content ***/ function load_modal_content(){ global $ultimatemember; $screen = get_current_screen(); if ( $this->is_UM_admin() ) { foreach( glob( um_path . 'admin/templates/modal/*.php' ) as $modal_content) { include_once $modal_content; } } // needed on forms only if ( isset( $screen->id ) && strstr( $screen->id, 'um_form' ) ) { $settings['textarea_rows'] = 8; echo '
'; echo ''; } } /*** *** @Show field input for edit ***/ function field_input ( $attribute, $form_id=null ) { global $ultimatemember; if ( $this->in_edit == true ) { // we're editing a field $real_attr = substr($attribute, 1); $this->edit_mode_value = (isset( $this->edit_array[ $real_attr ] ) ) ? $this->edit_array[ $real_attr ] : null; } switch($attribute) { default: do_action("um_admin_field_edit_hook__{$attribute}", $attribute); break; case '_visibility': ?>
set_field_type == 'row' ) { $back = 'UM_edit_row'; ?>
Choose Icon edit_mode_value ) { ?>
in_edit ) { $back = 'UM_edit_field'; } else { $back = 'UM_add_field'; } ?>Choose Icon edit_mode_value ) { ?>
edit_mode_value ) ) $this->ui_on_off('_heading', $this->edit_mode_value, true, 1, '_heading_text', 'xxx' ); else $this->ui_on_off('_heading', 0, true, 1, '_heading_text', 'xxx'); ?>
edit_mode_value ) ) $this->ui_on_off('_force_good_pass', $this->edit_mode_value ); else $this->ui_on_off('_force_good_pass', 0 ); ?>
edit_mode_value ) ) $this->ui_on_off('_force_confirm_pass', $this->edit_mode_value ); else $this->ui_on_off('_force_confirm_pass', 1 ); ?>
set_field_type == 'date' ) { ?>
edit_mode_value ) && is_array( $this->edit_mode_value ) ) { $values = $this->edit_mode_value; } else { $values = array(''); } ?>
set_field_type == 'shortcode' ) { ?>
set_field_type == 'image' ) { if ( isset( $this->edit_mode_value ) && is_array( $this->edit_mode_value ) ) { $values = $this->edit_mode_value; } else { $values = array('png','jpeg','jpg','gif'); } ?>
edit_mode_value ) && is_array( $this->edit_mode_value ) ) { $values = $this->edit_mode_value; } else { $values = array('pdf','txt'); } ?>
set_field_type == 'image' ) $value = 'Drag & Drop Photo'; if ( $this->set_field_type == 'file' ) $value = 'Drag & Drop File'; ?>
edit_mode_value ) ) { $this->ui_on_off('_is_multi', $this->edit_mode_value, true, 1, '_max_selections', 'xxx'); } else { $this->ui_on_off('_is_multi', 0, true, 1, '_max_selections', 'xxx'); } ?>
edit_mode_value ) ) $this->ui_on_off('_html', $this->edit_mode_value ); else $this->ui_on_off('_html', 0); ?>
edit_mode_value ) && is_array( $this->edit_mode_value ) ) { $values = implode("\n", $this->edit_mode_value); } else if ( $this->edit_mode_value ) { $values = $this->edit_mode_value; } else { $values = ''; } ?>
in_edit ) { ?>
set_field_type == 'textarea' ) { ?>
set_field_type == 'rating' ) { ?>
edit_mode_value ) && is_array( $this->edit_mode_value ) ) { $values = $this->edit_mode_value; } else { $values = array(''); } ?>
set_field_type == 'password' ) $def_required = 1; else $def_required = 0; ?>
edit_mode_value ) ) $this->ui_on_off('_required', $this->edit_mode_value ); else $this->ui_on_off('_required', $def_required); ?>
edit_mode_value ) ) $this->ui_on_off('_editable', $this->edit_mode_value ); else $this->ui_on_off('_editable', 1); ?>