ID ) ) {
$thepostid = absint( $post->ID );
return $thepostid;
}
$resolved_post_id = absint( get_the_ID() );
if ( $resolved_post_id > 0 ) {
$thepostid = $resolved_post_id;
}
return $resolved_post_id;
}
/**
* Output a text input box.
*
* @param array $field
*/
function lp_meta_box_text_input_field( $field ) {
global $thepostid, $post;
$thepostid = lp_meta_box_get_post_id();
$field['placeholder'] = esc_attr( $field['placeholder'] ?? '' );
$field['class'] = esc_attr( $field['class'] ?? '' );
$field['style'] = esc_attr( $field['style'] ?? '' );
$wrapper_class = esc_attr( $field['wrapper_class'] ?? '' );
/**
* If you want to set default value for input text
* You must us hook default_{$meta_type}_metadata | Read more get_metadata_default() function
*/
$value_exists = $thepostid > 0 ? LP_Database::getInstance()->check_key_postmeta_exists( $thepostid, $field['id'] ) : false;
$value = $thepostid > 0 ? get_post_meta( $thepostid, $field['id'], true ) : '';
$field['value'] = $value_exists ? $value : ( $field['default'] ?? '' );
$field['id'] = esc_attr( $field['id'] ?? '' );
$field['type_input'] = esc_attr( $field['type_input'] ?? 'text' );
$field['desc_tip'] = esc_attr( $field['desc_tip'] ?? '' );
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"';
}
}
$custom_attributes_str = implode( ' ', $custom_attributes );
?>
/>
';
echo '' . wp_kses_post( $field['description'] ) . ' ';
if ( ! empty( $field['desc_tip'] ) ) {
learn_press_quick_tip( $field['desc_tip'] );
}
echo '';
}
?>
0 ? LP_Database::getInstance()->check_key_postmeta_exists( $thepostid, $field['id'] ) : false;
$value = $thepostid > 0 ? get_post_meta( $thepostid, $field['id'], true ) : '';
$field['value'] = esc_textarea( $value_exists ? $value : ( $field['default'] ?? '' ) );
$field['desc_tip'] = esc_attr( $field['desc_tip'] ?? '' );
$field['name'] = esc_attr( $field['name'] ?? $field['id'] );
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"';
}
}
$custom_attributes_str = implode( ' ', $custom_attributes );
?>
' . wp_kses_post( $field['description'] ) . '';
if ( ! empty( $field['desc_tip'] ) ) {
learn_press_quick_tip( $field['desc_tip'] );
}
}
?>
$custom_attribute ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"';
}
}
$custom_attributes_str = implode( ' ', $custom_attributes );
?>
/>
' . wp_kses_post( $field['description'] ) . '';
if ( ! empty( $field['desc_tip'] ) ) {
learn_press_quick_tip( $field['desc_tip'] );
}
}
?>
'select',
'style' => '',
'wrapper_class' => '', // Use "lp-select-2" for select2.
'value' => isset( $field['value'] ) ? $field['value'] : $default,
'name' => $field['id'],
'desc_tip' => false,
'multiple' => false,
'custom_attributes' => array(),
)
);
$label_attributes = array(
'for' => $field['id'],
);
$field_attributes = (array) $field['custom_attributes'];
$field_attributes['style'] = $field['style'] ?? '';
$field_attributes['id'] = $field['id'] ?? '';
$field_attributes['name'] = $field['multiple'] ? $field['name'] . '[]' : $field['name'];
$field_attributes['class'] = $field['class'] ?? '';
if ( $field['multiple'] ) {
$field['wrapper_class'] = 'lp-select-2';
$field_attributes['multiple'] = true;
}
$tooltip = ! empty( $field['description'] ) && false !== $field['desc_tip'] ? $field['description'] : '';
$description = ! empty( $field['description'] ) && false === $field['desc_tip'] ? $field['description'] : '';
?>
>
$value ) {
echo '' . esc_html( $value ) . ' ';
}
?>
' . wp_kses_post( $field['description'] ) . '';
if ( ! empty( $field['desc_tip'] ) ) {
learn_press_quick_tip( $field['desc_tip'] );
}
}
?>
' . wp_kses_post( $field['label'] ) . ' ';
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) {
learn_press_quick_tip( $field['description'] );
}
echo '';
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) {
echo '' . wp_kses_post( $field['description'] ) . ' ';
}
echo '';
}
function lp_meta_box_file_input_field( $field ) {
global $thepostid, $post;
$thepostid = lp_meta_box_get_post_id();
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
$field['style'] = isset( $field['style'] ) ? $field['style'] : '';
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
$field['default'] = ( ! get_post_meta(
$thepostid,
$field['id'],
true
) && isset( $field['default'] ) ) ? $field['default'] : get_post_meta(
$thepostid,
$field['id'],
true
);
$field['value'] = isset( $field['value'] ) ? $field['value'] : $field['default'];
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
$field['mime_type'] = isset( $field['mime_type'] ) ? implode( ',', $field['mime_type'] ) : '';
$field['multil'] = ( isset( $field['multil'] ) && $field['multil'] ) ? true : false;
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false;
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"';
}
}
echo '';
}
/**
* Output a duration input box.
*
* @param array $field
*/
function lp_meta_box_duration_field( $field ) {
global $thepostid, $post;
$thepostid = lp_meta_box_get_post_id();
$field['placeholder'] = $field['placeholder'] ?? '';
$field['class'] = $field['class'] ?? 'short';
$field['style'] = $field['style'] ?? '';
$field['wrapper_class'] = $field['wrapper_class'] ?? '';
$field['default'] = ( ! get_post_meta(
$thepostid,
$field['id'],
true
) && isset( $field['default'] ) ) ? $field['default'] : get_post_meta(
$thepostid,
$field['id'],
true
);
$field['value'] = $field['value'] ?? $field['default'];
$field['name'] = $field['name'] ?? $field['id'];
$data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
$duration = learn_press_get_course_duration_support();
$duration_keys = array_keys( $duration );
$default_time = ! empty( $field['default_time'] ) ? $field['default_time'] : end( $duration_keys );
if ( preg_match_all( '!([0-9]+)\s*(' . join( '|', $duration_keys ) . ')?!', $field['value'], $matches ) ) {
$a1 = $matches[1][0];
$a2 = in_array( $matches[2][0], $duration_keys ) ? $matches[2][0] : $default_time;
} else {
$a1 = absint( $field['value'] );
$a2 = $default_time;
}
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"';
}
}
$html_option = '';
foreach ( $duration as $k => $v ) {
$html_option .= sprintf( '%s ', $k, selected( $k, $a2, false ), $v );
}
echo '
' . wp_kses_post( $field['label'] ) . ' ';
echo ' ';
echo '' . $html_option . ' ';
if ( ! empty( $field['description'] ) ) {
echo '' . wp_kses_post( $field['description'] ) . ' ';
if ( ! empty( $field['desc_tip'] ) ) {
learn_press_quick_tip( $field['desc_tip'] );
}
}
echo '
';
}
/**
* Use for Type: custom_fields in LP4.
*
* @param [type] $field get ID, options....
* @param [type] $values get_option() value
* @param [type] $key
*
* @return void
*/
function lp_metabox_custom_fields( $field, $values, $key ) {
?>
$val ) {
$name = $field['id'] . '[' . $key . ']' . '[' . $cfk . ']';
switch ( $val['type'] ) {
case 'text':
case 'password':
case 'datetime':
case 'datetime-local':
case 'date':
case 'month':
case 'time':
case 'week':
case 'number':
case 'email':
case 'url':
case 'tel':
?>
$cfselect ) {
?>
>
>
$value ) {
$attributes[] = esc_attr( $name ) . '="' . esc_attr( $value ) . '"';
}
return implode( ' ', $attributes );
}
function lp_meta_box_output( $metaboxes = array() ) {
if ( ! empty( $metaboxes ) ) {
foreach ( $metaboxes as $id => $field ) {
$field['id'] = $id;
switch ( $field['type'] ) {
case 'text':
case 'number':
case 'url':
lp_meta_box_text_input_field( $field );
break;
case 'textarea':
lp_meta_box_textarea_field( $field );
break;
case 'checkbox':
lp_meta_box_checkbox_field( $field );
break;
case 'duration':
lp_meta_box_duration_field( $field );
break;
case 'select':
lp_meta_box_select_field( $field );
break;
case 'radio':
lp_meta_box_radio_field( $field );
break;
case 'file':
lp_meta_box_file_input_field( $field );
break;
}
}
}
}