| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template hooks Archive Package. |
| 4 |
* |
| 5 |
* @since 4.2.6.4 |
| 6 |
* @version 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace LearnPress\TemplateHooks\Profile; |
| 10 |
|
| 11 |
use LP_Profile; |
| 12 |
use LP_Settings; |
| 13 |
|
| 14 |
class ProfileGeneralInfoTemplate { |
| 15 |
public static function instance() { |
| 16 |
static $instance = null; |
| 17 |
|
| 18 |
if ( is_null( $instance ) ) { |
| 19 |
$instance = new self(); |
| 20 |
} |
| 21 |
|
| 22 |
return $instance; |
| 23 |
} |
| 24 |
|
| 25 |
protected function __construct() { |
| 26 |
//add_action( 'learn-press/profile/layout/general-info', [ $this, 'sections' ], 2 ); |
| 27 |
add_action( 'learn-press/profile/layout/general-info-custom', [ $this, 'info_custom' ] ); |
| 28 |
add_action( 'learn-press/admin/user/layout/general-info-custom', [ $this, 'user_info_custom' ], 10, 2 ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Show custom field in profile. |
| 33 |
* |
| 34 |
* @param LP_Profile $profile |
| 35 |
* |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public function info_custom( $profile ) { |
| 39 |
$user_info_custom = lp_get_user_custom_register_fields( $profile->get_user()->get_id() ); |
| 40 |
$custom_fields = LP_Settings::get_option( 'register_profile_fields', [] ); |
| 41 |
|
| 42 |
if ( $custom_fields ) { |
| 43 |
foreach ( $custom_fields as $field ) { |
| 44 |
?> |
| 45 |
<li class="form-field form-field__<?php echo esc_attr( $field['id'] ); ?> form-field__clear"> |
| 46 |
<?php |
| 47 |
switch ( $field['type'] ) { |
| 48 |
case 'text': |
| 49 |
case 'number': |
| 50 |
case 'email': |
| 51 |
case 'url': |
| 52 |
case 'tel': |
| 53 |
?> |
| 54 |
<label><?php echo esc_html( $field['name'] ); ?></label> |
| 55 |
<input name="_lp_custom_register[<?php echo esc_attr( $field['id'] ); ?>]" |
| 56 |
type="<?php echo esc_attr( $field['type'] ); ?>" class="regular-text" |
| 57 |
value="<?php echo esc_attr( $user_info_custom[ $field['id'] ] ?? '' ); ?>"> |
| 58 |
<?php |
| 59 |
break; |
| 60 |
case 'textarea': |
| 61 |
?> |
| 62 |
<label><?php echo esc_html( $field['name'] ); ?></label> |
| 63 |
<textarea |
| 64 |
name="_lp_custom_register[<?php echo esc_attr( $field['id'] ); ?>]"><?php echo isset( $user_info_custom[ $field['id'] ] ) ? esc_textarea( $user_info_custom[ $field['id'] ] ) : ''; ?></textarea> |
| 65 |
<?php |
| 66 |
break; |
| 67 |
case 'checkbox': |
| 68 |
?> |
| 69 |
<label> |
| 70 |
<input name="_lp_custom_register[<?php echo esc_attr( $field['id'] ); ?>]" |
| 71 |
type="<?php echo esc_attr( $field['type'] ); ?>" |
| 72 |
value="1" <?php echo isset( $user_info_custom[ $field['id'] ] ) ? checked( $user_info_custom[ $field['id'] ], 1 ) : ''; ?>> |
| 73 |
<?php echo esc_html( $field['name'] ); ?> |
| 74 |
</label> |
| 75 |
<?php |
| 76 |
break; |
| 77 |
} |
| 78 |
?> |
| 79 |
</li> |
| 80 |
<?php |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public function user_info_custom( $user, $user_info_custom ) { |
| 86 |
$custom_fields = LP_Settings::get_option( 'register_profile_fields', [] ); |
| 87 |
|
| 88 |
if ( $custom_fields ) { |
| 89 |
foreach ( $custom_fields as $field ) { |
| 90 |
?> |
| 91 |
<tr> |
| 92 |
<th> |
| 93 |
<label |
| 94 |
for="learn-press-custom-register-<?php echo esc_attr( $field['id'] ); ?>"><?php echo esc_html( $field['name'] ); ?></label> |
| 95 |
</th> |
| 96 |
<td> |
| 97 |
<?php |
| 98 |
switch ( $field['type'] ) { |
| 99 |
case 'text': |
| 100 |
case 'number': |
| 101 |
case 'email': |
| 102 |
case 'url': |
| 103 |
case 'tel': |
| 104 |
?> |
| 105 |
<input name="_lp_custom_register[<?php echo esc_attr( $field['id'] ); ?>]" |
| 106 |
type="<?php echo esc_attr( $field['type'] ); ?>" class="regular-text" |
| 107 |
value="<?php echo esc_attr( $user_info_custom[ $field['id'] ] ?? '' ); ?>"> |
| 108 |
<?php |
| 109 |
break; |
| 110 |
case 'textarea': |
| 111 |
?> |
| 112 |
<textarea |
| 113 |
name="_lp_custom_register[<?php echo esc_attr( $field['id'] ); ?>]"><?php echo isset( $user_info_custom[ $field['id'] ] ) ? esc_textarea( $user_info_custom[ $field['id'] ] ) : ''; ?></textarea> |
| 114 |
<?php |
| 115 |
break; |
| 116 |
case 'checkbox': |
| 117 |
?> |
| 118 |
<input name="_lp_custom_register[<?php echo esc_attr( $field['id'] ); ?>]" |
| 119 |
type="<?php echo esc_attr( $field['type'] ); ?>" |
| 120 |
value="1" <?php echo isset( $user_info_custom[ $field['id'] ] ) ? checked( $user_info_custom[ $field['id'] ], 1 ) : ''; ?>> |
| 121 |
<?php |
| 122 |
break; |
| 123 |
} |
| 124 |
?> |
| 125 |
</td> |
| 126 |
</tr> |
| 127 |
<?php |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
public function print_type_field( $field, $user_info_custom = [] ) { |
| 133 |
ob_start(); |
| 134 |
|
| 135 |
//echo sprintf( '<label>%s</label>', esc_html( $field['name'] ?? '' ) ); |
| 136 |
|
| 137 |
switch ( $field['type'] ?? '' ) { |
| 138 |
case 'text': |
| 139 |
case 'number': |
| 140 |
case 'email': |
| 141 |
case 'url': |
| 142 |
case 'tel': |
| 143 |
?> |
| 144 |
<input name="_lp_custom_register[<?php echo esc_attr( $field['id'] ); ?>]" |
| 145 |
type="<?php echo esc_attr( $field['type'] ); ?>" class="regular-text" |
| 146 |
placeholder="<?php echo esc_attr( $field['name'] ?? '' ); ?>" |
| 147 |
value="<?php echo esc_attr( $user_info_custom[ $field['id'] ] ?? '' ); ?>"> |
| 148 |
<?php |
| 149 |
break; |
| 150 |
case 'textarea': |
| 151 |
?> |
| 152 |
<textarea name="_lp_custom_register[<?php echo esc_attr( $field['id'] ); ?>]"> |
| 153 |
<?php echo isset( $user_info_custom[ $field['id'] ] ) ? esc_textarea( $user_info_custom[ $field['id'] ] ) : ''; ?> |
| 154 |
</textarea> |
| 155 |
<?php |
| 156 |
break; |
| 157 |
case 'checkbox': |
| 158 |
?> |
| 159 |
<input name="_lp_custom_register[<?php echo esc_attr( $field['id'] ); ?>]" |
| 160 |
type="<?php echo esc_attr( $field['type'] ); ?>" |
| 161 |
value="1" <?php echo isset( $user_info_custom[ $field['id'] ] ) ? checked( $user_info_custom[ $field['id'] ], 1 ) : ''; ?>> |
| 162 |
<?php |
| 163 |
break; |
| 164 |
} |
| 165 |
|
| 166 |
return '<div>' . ob_get_clean() . '</div>'; |
| 167 |
} |
| 168 |
} |
| 169 |
|