array( 'obligatory' => false, 'enabled' => true, 'label' => __( 'First Name', 'affiliates' ), 'required' => true, 'is_default' => true, 'type' => 'text' ), 'last_name' => array( 'obligatory' => false, 'enabled' => true, 'label' => __( 'Last Name', 'affiliates' ), 'required' => true, 'is_default' => true, 'type' => 'text' ), 'user_login' => array( 'obligatory' => false, 'enabled' => true, 'label' => __( 'Username', 'affiliates' ), 'required' => true, 'is_default' => true, 'type' => 'text' ), 'user_email' => array( 'obligatory' => true, 'enabled' => true, 'label' => __( 'Email', 'affiliates' ), 'required' => true, 'is_default' => true, 'type' => 'text' ), 'user_url' => array( 'obligatory' => false, 'enabled' => true, 'label' => __( 'Website', 'affiliates' ), 'required' => false, 'is_default' => true, 'type' => 'text' ), 'password' => array( 'obligatory' => false, 'enabled' => false, 'label' => __( 'Password', 'affiliates' ), 'required' => false, 'is_default' => true, 'type' => 'password' ) ); } /** * Registers an admin_notices action. */ public static function admin_init() { } /** * Registration settings. */ public static function section() { if ( isset( $_POST['submit'] ) ) { if ( wp_verify_nonce( $_POST[AFFILIATES_ADMIN_SETTINGS_NONCE], 'admin' ) ) { delete_option( 'aff_registration' ); add_option( 'aff_registration', !empty( $_POST['registration'] ), '', 'no' ); delete_option( 'aff_status' ); $status = !empty( $_POST['affiliate_status'] ) ? $_POST['affiliate_status'] : 'active'; switch( $status ) { case 'active' : case 'pending' : break; default : $status = 'active'; } add_option( 'aff_status', $status, '', 'no' ); delete_option( 'aff_registration_terms_post_id' ); $terms_post_id = !empty( $_POST['terms_post_id'] ) ? intval( $_POST['terms_post_id'] ) : ''; if ( $terms_post_id && ( get_post( $terms_post_id ) !== null ) ) { add_option( 'aff_registration_terms_post_id', $terms_post_id ); } if ( !get_option( 'aff_registration_fields' ) ) { add_option( 'aff_registration_fields', self::$default_fields, '', 'no' ); } $field_enabled = isset( $_POST['field-enabled'] ) ? $_POST['field-enabled'] : array(); $field_name = isset( $_POST['field-name'] ) ? $_POST['field-name'] : array(); $field_label = isset( $_POST['field-label'] ) ? $_POST['field-label'] : array(); $field_required = isset( $_POST['field-required'] ) ? $_POST['field-required'] : array(); $field_type = isset( $_POST['field-type'] ) ? $_POST['field-type'] : array(); $max_index = max( array( max( array_keys( $field_enabled ) ), max( array_keys( $field_name ) ), max( array_keys( $field_label ) ), max( array_keys( $field_required ) ), max( array_keys( $field_type ) ) ) ); $fields = array(); for( $i = 0; $i <= $max_index; $i++ ) { if ( !empty( $field_name[$i] ) ) { $name = strip_tags( $field_name[$i] ); $name = strtolower( $name ); $name = preg_replace( '/[^a-z0-9_]/', '_', $name ); $name = preg_replace( '/[_]+/', '_', $name ); if ( !empty( $name ) && !isset( $fields[$name] ) ) { $fields[$name] = array( 'obligatory' => false || isset( self::$default_fields[$name] ) && self::$default_fields[$name]['obligatory'], 'enabled' => !empty( $field_enabled[$i] ) || isset( self::$default_fields[$name] ) && self::$default_fields[$name]['obligatory'], 'label' => !empty( $field_label[$i] ) ? strip_tags( $field_label[$i] ) : '', 'required' => !empty( $field_required[$i]), 'is_default' => key_exists( $field_name[$i], self::$default_fields ), 'type' => !empty( $field_type[$i] ) ? $field_type[$i] : 'text' ); } } } update_option( 'aff_registration_fields', $fields ); self::settings_saved_notice(); } } $registration = get_option( 'aff_registration', get_option( 'users_can_register', false ) ); $affiliate_status = get_option( 'aff_status', 'active' ); $terms_post_id = get_option( 'aff_registration_terms_post_id', '' ); echo '
' . '
' . '

' . esc_html__( 'Affiliate Registration', 'affiliates' ) . '

' . '

' . '' . '

'; echo '

' . ''; echo '
'; echo ''; esc_html_e( 'This determines if new affiliate applications require manual approval or whether they are accepted automatically.', 'affiliates' ); echo ' '; echo wp_kses( __( 'Pending will require manual approval of new affiliates. Active will accept new affiliates automatically.', 'affiliates' ), array( 'em' => array() ) ); echo ''; echo '

'; echo '

'; echo ''; echo '
'; echo ''; esc_html_e( 'Terms and conditions', 'affiliates' ); echo ' — '; esc_html_e( 'If chosen, a disclaimer and link to the page will be displayed with the registration form.', 'affiliates' ); echo ''; echo '

'; // registration fields echo '

' . __( 'Affiliate Registration Form', 'affiliates' ) . '

'; echo '

'; esc_html_e( 'The following fields are provided on the affiliate registration form.', 'affiliates' ); echo '

'; $registration_fields = get_option( 'aff_registration_fields', self::$default_fields ); echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $i = 0; echo ''; foreach( $registration_fields as $name => $field ) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $i++; } echo ''; echo '
'; esc_html_e( 'Enabled', 'affiliates' ); echo ''; esc_html_e( 'Field Name', 'affiliates' ); echo ''; esc_html_e( 'Field Label', 'affiliates' ); echo ''; esc_html_e( 'Required', 'affiliates' ); echo '
'; echo '
'; echo sprintf( '', $i, $field['enabled'] ? ' checked="checked" ' : '', $field['obligatory'] ? ' readonly="readonly" disabled="disabled" ' : '' ); echo ''; echo sprintf( '', $i, esc_attr( $name ), $field['is_default'] ? ' readonly="readonly" ' : '' ); echo ''; echo sprintf( '', $i, esc_attr( stripslashes( $field['label'] ) ) ); echo ''; echo sprintf( '', $i, $field['required'] ? ' checked="checked" ' : '' ); echo ''; echo sprintf( '', $i, $field['type'] ); echo sprintf( '', $i, esc_html( __( 'Up', 'affiliates' ) ) ); echo sprintf( '', $i, esc_html( __( 'Down', 'affiliates' ) ) ); if ( !$field['is_default'] ) { echo sprintf( '', $i, esc_html( __( 'Remove', 'affiliates' ) ) ); } echo '
'; echo '

'; echo sprintf( '', $i, esc_html( __( 'Add a field', 'affiliates' ) ) ); echo '

'; echo '
'; // #registration-fields echo '

' . wp_nonce_field( 'admin', AFFILIATES_ADMIN_SETTINGS_NONCE, true, false ) . '' . '

' . '
' . '
'; affiliates_footer(); } } Affiliates_Settings_Registration::init();