[], 'roles' => [], 'redirect' => ['default'=>'url'], 'redirect_url' => ['default'=>''], 'redirect_page' => ['default'=>''], ]; if ( $value ) { $default = array_merge($default, $value); } return $default; } /** * Text field * @param underDEV\Utils\Settings\Field $field Field instance * @return void */ public function input( $field ) { $per_role = ( null === $field->addon( 'per_role' ) ? true : $field->addon( 'per_role' ) ); $value = self::_corrected_value( $field->value() ); //var_dump($value['roles']); echo '
'; if ( $per_role ) { $this->_add_new_tpl($field); echo '
'; echo '
'; foreach ($value['redirect'] as $key => $redirect) { if ('default' === $key) { continue; } echo '
'; echo ' '; $this->_roles_tpl($field, $key, $value); $this->_redirects_tpl($field, $key, $value); echo '
'; echo '
'; } echo '
'; echo 'If nothing match, '; } $this->_redirects_tpl( $field, 'default', $value ); echo '
'; if ( $per_role ) { echo ''; } //echo ''; } public function _add_new_tpl( $field ) { echo ''; } public function _roles_tpl( $field, $key = '', $value = null ) { $selected_roles = []; $role_match = 'any_of'; if ( '' !== $key && $value ) { $selected_roles = isset($value['roles'][$key]) ? $value['roles'][$key] : $selected_roles; $role_match = isset($value['role_match'][$key]) ? $value['role_match'][$key] : $role_match; } echo ''; echo 'If role match '; echo ''; echo ''; echo '
'; echo '
'; } public function _redirects_tpl( $field, $key = '', $value = null ) { $redirect = 'url'; $redirect_url = ''; $redirect_page = ''; if ( '' !== $key && $value ) { $redirect = isset($value['redirect'][$key]) ? $value['redirect'][$key] : $redirect; $redirect_url = isset($value['redirect_url'][$key]) ? $value['redirect_url'][$key] : $redirect_url; $redirect_page = isset($value['redirect_page'][$key]) ? $value['redirect_page'][$key] : $redirect_page; } echo ''; echo ' redirect to '; echo ''; echo ''; echo ''; echo ''; } /** * Sanitize input value * @param string $value Saved value * @return string Sanitized text */ public function sanitize( $value ) { return $value; } } //array(4) { // ["roles"]=> // array(2) { // [1]=> // string(6) "editor" // [0]=> // string(8) "customer" // } // ["redirect"]=> // array(3) { // [0]=> // string(3) "url" // [1]=> // string(3) "url" // ["default"]=> // string(3) "url" // } // ["redirect_url"]=> // array(3) { // [0]=> // string(3) "/1/" // [1]=> // string(4) "/2/2" // ["default"]=> // string(5) "/def/" // } // ["redirect_page"]=> // array(3) { // [0]=> // string(0) "" // [1]=> // string(0) "" // ["default"]=> // string(0) "" // } //}