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( 'admin_init', array( &$this, 'add_taxonomy_metabox' ), 9 ); //roles metaboxes add_action( 'um_roles_add_meta_boxes', array( &$this, 'add_metabox_role' ) ); add_filter( 'um_builtin_validation_types_continue_loop', array( &$this, 'validation_types_continue_loop' ), 1, 4 ); add_filter( 'um_restrict_content_hide_metabox', array( &$this, 'hide_metabox_restrict_content_shop' ), 10, 1 ); add_filter( 'um_member_directory_meta_value_before_save', array( UM()->member_directory(), 'before_save_data' ), 10, 3 ); } /** * Hide Woocommerce Shop page restrict content metabox * @param $hide * * @return bool */ function hide_metabox_restrict_content_shop( $hide ) { if ( function_exists( 'wc_get_page_id' ) && ! empty( $_GET['post'] ) && absint( $_GET['post'] ) == wc_get_page_id( 'shop' ) ) { return true; } return $hide; } /** * Filter validation types on loop * * @param $break * @param $key * @param $form_id * @param $field_array * * @return bool */ function validation_types_continue_loop( $break, $key, $form_id, $field_array ) { // show unique username validation only for user_login field if ( isset( $field_array['metakey'] ) && $field_array['metakey'] == 'user_login' && $key !== 'unique_username' ) { return false; } return $break; } /** * Gets the role meta * * @param $id * * @return mixed */ 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; } return false; } /** * Runs on admin head */ function admin_head(){ global $post; if ( UM()->admin()->is_plugin_post_type() && isset($post->ID) ){ $this->postmeta = $this->get_custom_post_meta($post->ID); } } /** * Init the metaboxes */ function add_metabox() { global $current_screen; if ( $current_screen->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_directory' ) { add_action( 'add_meta_boxes', array(&$this, 'add_metabox_directory'), 1 ); add_action( 'save_post', array(&$this, 'save_metabox_directory'), 10, 2 ); } //restrict content metabox $post_types = UM()->options()->get( 'restricted_access_post_metabox' ); if ( ! empty( $post_types[ $current_screen->id ] ) ) { /** * UM hook * * @type filter * @title um_restrict_content_hide_metabox * @description Show/Hide Restrict content metabox * @input_vars * [{"var":"$show","type":"bool","desc":"Show Metabox"}] * @change_log * ["Since: 2.0"] * @usage add_filter( 'um_restrict_content_hide_metabox', 'function_name', 10, 1 ); * @example * */ $hide_metabox = apply_filters( 'um_restrict_content_hide_metabox', false ); if ( ! $hide_metabox ) { add_action( 'add_meta_boxes', array(&$this, 'add_metabox_restrict_content'), 1 ); add_action( 'save_post', array( &$this, 'save_metabox_restrict_content' ), 10, 2 ); } if ( $current_screen->id == 'attachment' ) { add_action( 'add_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 ); add_action( 'edit_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 ); } } add_action( 'save_post', array( &$this, 'save_metabox_custom' ), 10, 2 ); } /** * @param $post_id * @param $post */ function save_metabox_custom( $post_id, $post ) { // validate nonce if ( ! isset( $_POST['um_admin_save_metabox_custom_nonce'] ) || ! wp_verify_nonce( $_POST['um_admin_save_metabox_custom_nonce'], basename( __FILE__ ) ) ) { return; } /** * UM hook * * @type action * @title um_admin_custom_restrict_content_metaboxes * @description Save metabox custom with restrict content * @input_vars * [{"var":"$post_id","type":"int","desc":"Post ID"}, * {"var":"$post","type":"array","desc":"Post data"}] * @change_log * ["Since: 2.0"] * @usage add_action( 'um_admin_custom_restrict_content_metaboxes', 'function_name', 10, 2 ); * @example * */ do_action( 'um_admin_custom_restrict_content_metaboxes', $post_id, $post ); } /** * */ function add_metabox_restrict_content() { global $current_screen; add_meta_box( 'um-admin-restrict-content', __( 'UM Content Restriction', 'ultimate-member' ), array( &$this, 'restrict_content_cb' ), $current_screen->id, 'normal', 'default' ); /** * UM hook * * @type action * @title um_admin_custom_restrict_content_metaboxes * @description Add restrict content custom metabox * @change_log * ["Since: 2.0"] * @usage add_action( 'um_admin_custom_restrict_content_metaboxes', 'function_name', 10 ); * @example * */ do_action( 'um_admin_custom_restrict_content_metaboxes' ); } /** * Content restriction metabox * * @param $object * @param $box */ function restrict_content_cb( $object, $box ) { include_once UM()->admin()->templates_path . 'access/restrict_content.php'; wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_restrict_content_nonce' ); } /** * Init the metaboxes */ function add_taxonomy_metabox() { //restrict content metabox $all_taxonomies = get_taxonomies( array( 'public' => true ) ); $tax_types = UM()->options()->get( 'restricted_access_taxonomy_metabox' ); $exclude_taxonomies = UM()->excluded_taxonomies(); foreach ( $all_taxonomies as $key => $taxonomy ) { if ( in_array( $key, $exclude_taxonomies ) || empty( $tax_types[$key] ) ) continue; add_action( $taxonomy . '_add_form_fields', array( &$this, 'um_category_access_fields_create' ) ); add_action( $taxonomy . '_edit_form_fields', array( &$this, 'um_category_access_fields_edit' ) ); add_action( 'create_' . $taxonomy, array( &$this, 'um_category_access_fields_save' ) ); add_action( 'edited_' . $taxonomy, array( &$this, 'um_category_access_fields_save' ) ); } } /** * @param $post_id * @param $post */ function save_metabox_restrict_content( $post_id, $post ) { // validate nonce if ( ! isset( $_POST['um_admin_save_metabox_restrict_content_nonce'] ) || ! wp_verify_nonce( $_POST['um_admin_save_metabox_restrict_content_nonce'], basename( __FILE__ ) ) ) { return; } // validate user $post_type = get_post_type_object( $post->post_type ); if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) { return; } if ( ! empty( $_POST['um_content_restriction'] ) && is_array( $_POST['um_content_restriction'] ) ) { update_post_meta( $post_id, 'um_content_restriction', $_POST['um_content_restriction'] ); } else { delete_post_meta( $post_id, 'um_content_restriction' ); } } /** * @param $post_id * */ function save_attachment_metabox_restrict_content( $post_id ) { // validate nonce if ( ! isset( $_POST['um_admin_save_metabox_restrict_content_nonce'] ) || ! wp_verify_nonce( $_POST['um_admin_save_metabox_restrict_content_nonce'], basename( __FILE__ ) ) ) { return; } $post = get_post( $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; } if ( ! empty( $_POST['um_content_restriction'] ) && is_array( $_POST['um_content_restriction'] ) ) { update_post_meta( $post_id, 'um_content_restriction', $_POST['um_content_restriction'] ); } else { delete_post_meta( $post_id, 'um_content_restriction' ); } } /** * */ function um_category_access_fields_create() { $data = array(); /** * UM hook * * @type filter * @title um_admin_category_access_settings_fields * @description Settings fields for terms * @input_vars * [{"var":"$access_settings_fields","type":"array","desc":"Settings Fields"}, * {"var":"$data","type":"array","desc":"Settings Data"}, * {"var":"$screen","type":"string","desc":"Category Screen"}] * @change_log * ["Since: 2.0"] * @usage add_filter( 'um_admin_category_access_settings_fields', 'function_name', 10, 3 ); * @example * 'my-field-key', * 'type' => 'my-field-type', * 'label' => __( 'My field Label', 'ultimate-member' ), * 'description' => __( 'My Field Description', 'ultimate-member' ), * 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0, * ); * return $access_settings_fields; * } * ?> */ $fields = apply_filters( 'um_admin_category_access_settings_fields', array( array( 'id' => '_um_custom_access_settings', 'type' => 'checkbox', 'label' => __( 'Restrict access to this content?', 'ultimate-member' ), 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0, ), array( 'id' => '_um_accessible', 'type' => 'select', 'label' => __( 'Who can access this content?', 'ultimate-member' ), 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), 'value' => ! empty( $data['_um_accessible'] ) ? $data['_um_accessible'] : 0, 'options' => array( '0' => __( 'Everyone', 'ultimate-member' ), '1' => __( 'Logged out users', 'ultimate-member' ), '2' => __( 'Logged in users', 'ultimate-member' ), ), 'conditional' => array( '_um_custom_access_settings', '=', '1' ) ), array( 'id' => '_um_access_roles', 'type' => 'multi_checkbox', 'label' => __( 'Select which roles can access this content', 'ultimate-member' ), 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), 'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ), 'columns' => 3, 'conditional' => array( '_um_accessible', '=', '2' ) ), array( 'id' => '_um_noaccess_action', 'type' => 'select', 'label' => __( 'What happens when users without access tries to view the content?', 'ultimate-member' ), 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), 'value' => ! empty( $data['_um_noaccess_action'] ) ? $data['_um_noaccess_action'] : 0, 'options' => array( '0' => __( 'Show access restricted message', 'ultimate-member' ), '1' => __( 'Redirect user', 'ultimate-member' ), ), 'conditional' => array( '_um_accessible', '!=', '0' ) ), array( 'id' => '_um_restrict_by_custom_message', 'type' => 'select', 'label' => __( 'Would you like to use the global default message or apply a custom message to this content?', 'ultimate-member' ), 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), 'value' => ! empty( $data['_um_restrict_by_custom_message'] ) ? $data['_um_restrict_by_custom_message'] : '0', 'options' => array( '0' => __( 'Global default message (default)', 'ultimate-member' ), '1' => __( 'Custom message', 'ultimate-member' ), ), 'conditional' => array( '_um_noaccess_action', '=', '0' ) ), array( 'id' => '_um_restrict_custom_message', 'type' => 'wp_editor', 'label' => __( 'Custom Restrict Content message', 'ultimate-member' ), 'description' => __( 'Changed global restrict message', 'ultimate-member' ), 'value' => ! empty( $data['_um_restrict_custom_message'] ) ? $data['_um_restrict_custom_message'] : '', 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ) ), array( 'id' => '_um_access_redirect', 'type' => 'select', 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ), 'description' => __( 'Select redirect to page when user hasn\'t access to content', 'ultimate-member' ), 'value' => ! empty( $data['_um_access_redirect'] ) ? $data['_um_access_redirect'] : '0', 'conditional' => array( '_um_noaccess_action', '=', '1' ), 'options' => array( '0' => __( 'Login page', 'ultimate-member' ), '1' => __( 'Custom URL', 'ultimate-member' ), ), ), array( 'id' => '_um_access_redirect_url', 'type' => 'text', 'label' => __( 'Redirect URL', 'ultimate-member' ), 'description' => __( 'Changed global restrict message', 'ultimate-member' ), 'value' => ! empty( $data['_um_access_redirect_url'] ) ? $data['_um_access_redirect_url'] : '', 'conditional' => array( '_um_access_redirect', '=', '1' ) ), array( 'id' => '_um_access_hide_from_queries', 'type' => 'checkbox', 'label' => __( 'Hide from queries', 'ultimate-member' ), 'description' => __( 'Hide this content from archives, RSS feeds etc for users who do not have permission to view this content', 'ultimate-member' ), 'value' => ! empty( $data['_um_access_hide_from_queries'] ) ? $data['_um_access_hide_from_queries'] : '', 'conditional' => array( '_um_accessible', '!=', '0' ) ) ), $data, 'create' ); UM()->admin_forms( array( 'class' => 'um-restrict-content um-third-column', 'prefix_id' => 'um_content_restriction', 'without_wrapper' => true, 'div_line' => true, 'fields' => $fields ) )->render_form(); wp_nonce_field( basename( __FILE__ ), 'um_admin_save_taxonomy_restrict_content_nonce' ); } /** * @param $term */ function um_category_access_fields_edit( $term ) { $termID = $term->term_id; $data = get_term_meta( $termID, 'um_content_restriction', true ); $_um_access_roles_value = array(); if ( ! empty( $data['_um_access_roles'] ) ) { foreach ( $data['_um_access_roles'] as $key => $value ) { if ( $value ) { $_um_access_roles_value[] = $key; } } } /** * UM hook * * @type filter * @title um_admin_category_access_settings_fields * @description Settings fields for terms * @input_vars * [{"var":"$access_settings_fields","type":"array","desc":"Settings Fields"}, * {"var":"$data","type":"array","desc":"Settings Data"}, * {"var":"$screen","type":"string","desc":"Category Screen"}] * @change_log * ["Since: 2.0"] * @usage add_filter( 'um_admin_category_access_settings_fields', 'function_name', 10, 3 ); * @example * 'my-field-key', * 'type' => 'my-field-type', * 'label' => __( 'My field Label', 'ultimate-member' ), * 'description' => __( 'My Field Description', 'ultimate-member' ), * 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0, * ); * return $access_settings_fields; * } * ?> */ $fields = apply_filters( 'um_admin_category_access_settings_fields', array( array( 'id' => '_um_custom_access_settings', 'type' => 'checkbox', 'class' => 'form-field', 'label' => __( 'Restrict access to this content?', 'ultimate-member' ), 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0, ), array( 'id' => '_um_accessible', 'type' => 'select', 'class' => 'form-field', 'label' => __( 'Who can access this content?', 'ultimate-member' ), 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), 'value' => ! empty( $data['_um_accessible'] ) ? $data['_um_accessible'] : 0, 'options' => array( '0' => __( 'Everyone', 'ultimate-member' ), '1' => __( 'Logged out users', 'ultimate-member' ), '2' => __( 'Logged in users', 'ultimate-member' ), ), 'conditional' => array( '_um_custom_access_settings', '=', '1' ) ), array( 'id' => '_um_access_roles', 'type' => 'multi_checkbox', 'class' => 'form-field', 'label' => __( 'Select which roles can access this content', 'ultimate-member' ), 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), 'value' => $_um_access_roles_value, 'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ), 'columns' => 3, 'conditional' => array( '_um_accessible', '=', '2' ) ), array( 'id' => '_um_noaccess_action', 'type' => 'select', 'class' => 'form-field', 'label' => __( 'What happens when users without access tries to view the content?', 'ultimate-member' ), 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), 'value' => ! empty( $data['_um_noaccess_action'] ) ? $data['_um_noaccess_action'] : 0, 'options' => array( '0' => __( 'Show access restricted message', 'ultimate-member' ), '1' => __( 'Redirect user', 'ultimate-member' ), ), 'conditional' => array( '_um_accessible', '!=', '0' ) ), array( 'id' => '_um_restrict_by_custom_message', 'type' => 'select', 'class' => 'form-field', 'label' => __( 'Would you like to use the global default message or apply a custom message to this content?', 'ultimate-member' ), 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), 'value' => ! empty( $data['_um_restrict_by_custom_message'] ) ? $data['_um_restrict_by_custom_message'] : '0', 'options' => array( '0' => __( 'Global default message (default)', 'ultimate-member' ), '1' => __( 'Custom message', 'ultimate-member' ), ), 'conditional' => array( '_um_noaccess_action', '=', '0' ) ), array( 'id' => '_um_restrict_custom_message', 'type' => 'wp_editor', 'class' => 'form-field', 'label' => __( 'Custom Restrict Content message', 'ultimate-member' ), 'description' => __( 'Changed global restrict message', 'ultimate-member' ), 'value' => ! empty( $data['_um_restrict_custom_message'] ) ? $data['_um_restrict_custom_message'] : '', 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ) ), array( 'id' => '_um_access_redirect', 'type' => 'select', 'class' => 'form-field', 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ), 'description' => __( 'Select redirect to page when user hasn\'t access to content', 'ultimate-member' ), 'value' => ! empty( $data['_um_access_redirect'] ) ? $data['_um_access_redirect'] : '0', 'conditional' => array( '_um_noaccess_action', '=', '1' ), 'options' => array( '0' => __( 'Login page', 'ultimate-member' ), '1' => __( 'Custom URL', 'ultimate-member' ), ), ), array( 'id' => '_um_access_redirect_url', 'type' => 'text', 'class' => 'form-field', 'label' => __( 'Redirect URL', 'ultimate-member' ), 'description' => __( 'Changed global restrict message', 'ultimate-member' ), 'value' => ! empty( $data['_um_access_redirect_url'] ) ? $data['_um_access_redirect_url'] : '', 'conditional' => array( '_um_access_redirect', '=', '1' ) ), array( 'id' => '_um_access_hide_from_queries', 'type' => 'checkbox', 'class' => 'form-field', 'label' => __( 'Hide from queries', 'ultimate-member' ), 'description' => __( 'Hide this content from archives, RSS feeds etc for users who do not have permission to view this content', 'ultimate-member' ), 'value' => ! empty( $data['_um_access_hide_from_queries'] ) ? $data['_um_access_hide_from_queries'] : '', 'conditional' => array( '_um_accessible', '!=', '0' ) ) ), $data, 'edit' ); UM()->admin_forms( array( 'class' => 'um-restrict-content um-third-column', 'prefix_id' => 'um_content_restriction', 'without_wrapper' => true, 'fields' => $fields ) )->render_form(); wp_nonce_field( basename( __FILE__ ), 'um_admin_save_taxonomy_restrict_content_nonce' ); } /** * @param $termID * * @return mixed */ function um_category_access_fields_save( $termID ) { // validate nonce if ( ! isset( $_REQUEST['um_admin_save_taxonomy_restrict_content_nonce'] ) || ! wp_verify_nonce( $_REQUEST['um_admin_save_taxonomy_restrict_content_nonce'], basename( __FILE__ ) ) ) { return $termID; } // validate user $term = get_term( $termID ); $taxonomy = get_taxonomy( $term->taxonomy ); if ( ! current_user_can( $taxonomy->cap->edit_terms, $termID ) ) { return $termID; } if ( ! empty( $_REQUEST['um_content_restriction'] ) && is_array( $_REQUEST['um_content_restriction'] ) ) { update_term_meta( $termID, 'um_content_restriction', $_REQUEST['um_content_restriction'] ); } else { delete_term_meta( $termID, 'um_content_restriction' ); } return $termID; } /** * Load a directory metabox * * @param $object * @param $box */ function load_metabox_directory( $object, $box ) { $box['id'] = str_replace( 'um-admin-form-', '', $box['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 . 'includes/admin/templates/directory/'. $box['id'] . '.php'; if ( ! $this->directory_nonce_added ) { $this->directory_nonce_added = true; wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_directory_nonce' ); } } /** * Load a role metabox * * @param $object * @param $box */ function load_metabox_role( $object, $box ) { global $post; $box['id'] = str_replace( 'um-admin-form-', '', $box['id'] ); if ( $box['id'] == '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 . 'includes/admin/templates/role/'. $box['id'] . '.php'; //wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_role_nonce' ); } /** * Load a form metabox * * @param $object * @param $box */ function load_metabox_form( $object, $box ) { global $post; $box['id'] = str_replace( 'um-admin-form-','', $box['id'] ); if ( $box['id'] == '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 . 'includes/admin/templates/form/'. $box['id'] . '.php'; if ( ! $this->form_nonce_added ) { $this->form_nonce_added = true; wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_form_nonce' ); } } /** * Load admin custom metabox * * @param $object * @param $box */ function load_metabox_custom( $object, $box ) { global $post; $box['id'] = str_replace('um-admin-custom-','', $box['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 . 'includes/admin/templates/'. $box['id'] . '.php'; if ( ! $this->custom_nonce_added ) { $this->custom_nonce_added = true; wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_custom_nonce' ); } } /** * Add directory metabox */ function add_metabox_directory() { add_meta_box( 'um-admin-form-general', __( 'General Options', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' ); add_meta_box( 'um-admin-form-sorting', __( 'Sorting', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' ); add_meta_box( 'um-admin-form-profile', __( 'Profile Card', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' ); add_meta_box( 'um-admin-form-search', __( 'Search Options', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' ); add_meta_box( 'um-admin-form-pagination', __( 'Results & Pagination', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'normal', 'default' ); add_meta_box( 'um-admin-form-shortcode', __( 'Shortcode', 'ultimate-member' ), array( &$this, 'load_metabox_directory' ), 'um_directory', 'side', 'default' ); add_meta_box( 'um-admin-form-appearance', __( 'Styling: General', 'ultimate-member' ), array( &$this, 'load_metabox_directory'), 'um_directory', 'side', 'default' ); } /** * Add role metabox */ function add_metabox_role() { $callback = array( &$this, 'load_metabox_role' ); $roles_metaboxes = array( array( 'id' => 'um-admin-form-admin-permissions', 'title' => __( 'Administrative Permissions', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'normal', 'priority' => 'default' ), array( 'id' => 'um-admin-form-general', 'title' => __( 'General Permissions', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'normal', 'priority' => 'default' ), array( 'id' => 'um-admin-form-profile', 'title' => __( 'Profile Access', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'normal', 'priority' => 'default' ) ); if ( ! isset( $_GET['id'] ) || 'administrator' != sanitize_key( $_GET['id'] ) ) { $roles_metaboxes[] = array( 'id' => 'um-admin-form-home', 'title' => __( 'Homepage Options', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'normal', 'priority' => 'default' ); } $roles_metaboxes = array_merge( $roles_metaboxes, array( array( 'id' => 'um-admin-form-register', 'title' => __( 'Registration Options', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'normal', 'priority' => 'default' ), array( 'id' => 'um-admin-form-login', 'title' => __( 'Login Options', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'normal', 'priority' => 'default' ), array( 'id' => 'um-admin-form-logout', 'title' => __( 'Logout Options', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'normal', 'priority' => 'default' ), array( 'id' => 'um-admin-form-delete', 'title' => __( 'Delete Options', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'normal', 'priority' => 'default' ), array( 'id' => 'um-admin-form-publish', 'title' => __( 'Publish', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'side', 'priority' => 'default' ) ) ); /** * UM hook * * @type filter * @title um_admin_role_metaboxes * @description Extend metaboxes at Add/Edit User Role * @input_vars * [{"var":"$roles_metaboxes","type":"array","desc":"Metaboxes at Add/Edit UM Role"}] * @change_log * ["Since: 2.0"] * @usage add_filter( 'um_admin_role_metaboxes', 'function_name', 10, 1 ); * @example * 'um-admin-form-your-custom', * 'title' => __( 'My Roles Metabox', 'ultimate-member' ), * 'callback' => 'my-metabox-callback', * 'screen' => 'um_role_meta', * 'context' => 'side', * 'priority' => 'default' * ); * * return $roles_metaboxes; * } * ?> */ $roles_metaboxes = apply_filters( 'um_admin_role_metaboxes', $roles_metaboxes ); $wp_caps_metabox = false; if ( ! empty( $_GET['id'] ) ) { $data = get_option( 'um_role_' . sanitize_key( $_GET['id'] ) . '_meta' ); if ( ! empty( $data['_um_is_custom'] ) ) { $wp_caps_metabox = true; } } if ( 'add' == sanitize_key( $_GET['tab'] ) || $wp_caps_metabox ) { $roles_metaboxes[] = array( 'id' => 'um-admin-form-wp-capabilities', 'title' => __( 'WP Capabilities', 'ultimate-member' ), 'callback' => $callback, 'screen' => 'um_role_meta', 'context' => 'normal', 'priority' => 'default' ); } foreach ( $roles_metaboxes as $metabox ) { add_meta_box( $metabox['id'], $metabox['title'], $metabox['callback'], $metabox['screen'], $metabox['context'], $metabox['priority'] ); } } /** * Add form metabox */ function add_metabox_form() { add_meta_box( 'um-admin-form-mode', __( 'Select Form Type', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'normal', 'default' ); add_meta_box( 'um-admin-form-builder', __( 'Form Builder', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'normal', 'default' ); add_meta_box( 'um-admin-form-shortcode', __( 'Shortcode', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' ); add_meta_box( 'um-admin-form-register_customize', __( 'Customize this form', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' ); /** * UM hook * * @type action * @title um_admin_custom_register_metaboxes * @description Add custom metaboxes for register form * @change_log * ["Since: 2.0"] * @usage add_action( 'um_admin_custom_register_metaboxes', 'function_name', 10 ); * @example * */ do_action( 'um_admin_custom_register_metaboxes' ); add_meta_box( 'um-admin-form-profile_customize', __( 'Customize this form', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' ); add_meta_box( 'um-admin-form-profile_settings', __( 'User Meta', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' ); /** * UM hook * * @type action * @title um_admin_custom_profile_metaboxes * @description Add custom metaboxes for profile form * @change_log * ["Since: 2.0"] * @usage add_action( 'um_admin_custom_profile_metaboxes', 'function_name', 10 ); * @example * */ do_action( 'um_admin_custom_profile_metaboxes' ); add_meta_box( 'um-admin-form-login_customize', __( 'Customize this form', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' ); add_meta_box( 'um-admin-form-login_settings', __( 'Options', 'ultimate-member' ), array( &$this, 'load_metabox_form' ), 'um_form', 'side', 'default' ); /** * UM hook * * @type action * @title um_admin_custom_login_metaboxes * @description Add custom metaboxes for login form * @change_log * ["Since: 2.0"] * @usage add_action( 'um_admin_custom_login_metaboxes', 'function_name', 10 ); * @example * */ do_action( 'um_admin_custom_login_metaboxes' ); } /** * Save directory metabox * * @param $post_id * @param $post */ 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; } // validate post type if ( $post->post_type != 'um_directory' ) { return; } // validate user $post_type = get_post_type_object( $post->post_type ); if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) { return; } $where = array( 'ID' => $post_id ); if ( empty( $_POST['post_title'] ) ) { $_POST['post_title'] = sprintf( __( 'Directory #%s', 'ultimate-member' ), $post_id ); } $wpdb->update( $wpdb->posts, array( 'post_title' => sanitize_text_field( $_POST['post_title'] ) ), $where ); do_action( 'um_before_member_directory_save', $post_id ); // 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' ); delete_post_meta( $post_id, '_um_roles_can_filter' ); delete_post_meta( $post_id, '_um_show_these_users' ); delete_post_meta( $post_id, '_um_exclude_these_users' ); delete_post_meta( $post_id, '_um_search_filters' ); delete_post_meta( $post_id, '_um_search_filters_gmt' ); //save metadata foreach ( $_POST['um_metadata'] as $k => $v ) { if ( $k == '_um_show_these_users' && trim( $_POST['um_metadata'][ $k ] ) ) { $v = preg_split( '/[\r\n]+/', $v, -1, PREG_SPLIT_NO_EMPTY ); } if ( $k == '_um_exclude_these_users' && trim( $_POST['um_metadata'][ $k ] ) ) { $v = preg_split( '/[\r\n]+/', $v, -1, PREG_SPLIT_NO_EMPTY ); } if ( strstr( $k, '_um_' ) ) { if ( $k === '_um_is_default' ) { $mode = UM()->query()->get_attr( 'mode', $post_id ); if ( ! empty( $mode ) ) { $posts = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_um_mode' AND meta_value = 'directory'" ); foreach ( $posts as $p_id ) { delete_post_meta( $p_id, '_um_is_default' ); } } } $v = apply_filters( 'um_member_directory_meta_value_before_save', $v, $k, $post_id ); update_post_meta( $post_id, $k, $v ); } } update_post_meta( $post_id, '_um_search_filters_gmt', (int) $_POST['um-gmt-offset'] ); } /** * Save form metabox * * @param $post_id * @param $post */ 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; } // validate post type if ( $post->post_type != 'um_form' ) { return; } // validate user $post_type = get_post_type_object( $post->post_type ); if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) { return; } $where = array( 'ID' => $post_id ); if ( empty( $_POST['post_title'] ) ) { $_POST['post_title'] = sprintf( __( 'Form #%s', 'ultimate-member' ), $post_id ); } $wpdb->update( $wpdb->posts, array( 'post_title' => sanitize_text_field( $_POST['post_title'] ) ), $where ); // save delete_post_meta( $post_id, '_um_profile_metafields' ); foreach ( $_POST['form'] as $k => $v ) { if ( strstr( $k, '_um_' ) ) { if ( $k === '_um_is_default' ) { $mode = UM()->query()->get_attr( 'mode', $post_id ); if ( ! empty( $mode ) ) { $posts = $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_um_mode' AND meta_value = %s", $mode ) ); foreach ( $posts as $p_id ) { delete_post_meta( $p_id, '_um_is_default' ); } } } update_post_meta( $post_id, $k, $v ); } } } /** * Load modal content */ function load_modal_content() { $screen = get_current_screen(); if ( UM()->admin()->is_um_screen() ) { foreach ( glob( um_path . 'includes/admin/templates/modal/*.php' ) as $modal_content ) { include_once $modal_content; } } // needed on forms only if ( ! isset( $this->is_loaded ) && isset( $screen->id ) && strstr( $screen->id, 'um_form' ) ) { $settings['textarea_rows'] = 8; echo ''; echo ''; $this->is_loaded = true; } } /** * Show field input for edit at modal field * * @param $attribute * @param null $form_id * @param array $field_args */ function field_input( $attribute, $form_id = null, $field_args = array() ) { 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: /** * UM hook * * @type action * @title um_admin_field_edit_hook{$attribute} * @description Integration for 3-d party fields at wp-admin * @input_vars * [{"var":"$edit_mode_value","type":"string","desc":"Post ID"}] * @change_log * ["Since: 2.0"] * @usage add_action( 'um_admin_field_edit_hook{$attribute}', 'function_name', 10, 1 ); * @example * */ do_action( "um_admin_field_edit_hook{$attribute}", $this->edit_mode_value, $form_id, $this->edit_array ); break; case '_visibility': ?>

  

set_field_type == 'row' ) { $back = 'UM_edit_row'; ?>

edit_mode_value ) { ?> edit_mode_value ) { ?>

in_edit ) { $back = 'UM_edit_field'; } else { $back = 'UM_add_field'; } ?>

edit_mode_value ) { ?> edit_mode_value ) { ?>

edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> class="um-adm-conditional" data-cond1="1" data-cond1-show="_heading_text" data-cond1-hide="xxx" />

edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> />

edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> />

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', 'ultimate-member' ); } if ( $this->set_field_type == 'file' ) { $value = __( 'Drag & Drop File', 'ultimate-member' ); } ?>

edit_mode_value ) ? $this->edit_mode_value : 0 ) ?> class="um-adm-conditional" data-cond1="1" data-cond1-show="_max_selections" data-cond1-hide="xxx" />

edit_mode_value ) ? $this->edit_mode_value : 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 == 'date' ) { ?>

set_field_type == 'time' ) { ?>

set_field_type == 'rating' ) { ?>

__( 'Everyone', 'ultimate-member' ), '2' => __( 'Members', 'ultimate-member' ), '-1' => __( 'Only visible to profile owner and admins', 'ultimate-member' ), '-3' => __( 'Only visible to profile owner and specific roles', 'ultimate-member' ), '-2' => __( 'Only specific member roles', 'ultimate-member' ), ); $privacy_options = apply_filters( 'um_field_privacy_options', $privacy_options ); ?>

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->edit_mode_value : $def_required ) ?> />

edit_mode_value || $this->edit_mode_value ) ?> />