ID ) ? $post->ID : (int) $id;
}
return $post_id;
}
/**
* Helper method for retrieving settings values.
*
* @since 2.0.0
*
* @global int $id The current post ID.
* @global object $post The current post object.
* @param string $key The setting key to retrieve.
* @param string $default A default value to use.
* @return string Key value on success, empty string on failure.
*/
public function get_setting( $key, $default = false ) {
// Get config
$settings = get_post_meta( $this->get_id(), 'modula-album-settings', true );
// Check config key exists
if ( isset( $settings[ $key ] ) ) {
$value = $settings[ $key ];
} else {
$value = $default ? $default : '';
}
return apply_filters( 'modula_albums_admin_field_value', $value, $key, $settings );
}
public function render( $metabox, $post = false ) {
switch ( $metabox ) {
case 'gallery':
$this->_render_gallery_metabox();
break;
case 'settings':
$this->_render_settings_metabox();
break;
case 'shortcode':
$this->_render_shortcode_metabox( $post );
break;
default:
do_action( "modula_metabox_fields_{$metabox}" );
break;
}
}
/**
* Create HTML for gallery metabox
*/
private function _render_gallery_metabox() {
$galleries = get_post_meta( $this->get_id(), 'modula-album-galleries', true );
$helper_guidelines = $this->get_setting( 'helpergrid' );
$max_upload_size = wp_max_upload_size();
if ( ! $max_upload_size ) {
$max_upload_size = 0;
}
echo '
%s
%s
';
printf( $html, $tabs_html, $tabs_content_html );
}
/**
* Create HTML for shortcode metabox
*/
private function _render_shortcode_metabox( $post ) {
do_action( 'modula_albums_admin_before_shortcode_metabox', $post );
$shortcode = '[modula-album id="' . $post->ID . '"]';
echo '
';
echo '
';
echo '
';
echo '
' . sprintf( esc_html__( 'You can use this to display your newly created album inside a %s post or a page %s', 'modula-albums'), '', ' ' ) . '
';
echo '
';
do_action( 'modula_albums_admin_after_shortcode_metabox', $post );
}
/**
* Create HTML for a tab
*/
private function _render_tab( $tab, $first = false ) {
$icon = '';
$badge = '';
if ( isset( $tab['icon'] ) ) {
$icon = '
';
}
if ( isset( $tab['badge'] ) ) {
$badge = '
' . esc_html( $tab['badge'] ) . ' ';
}
return '
' . $icon . wp_kses_post( $tab['label'] ) . $badge . '
';
}
/**
* Create HTML for a row
*/
private function _render_row( $field ) {
$child = '';
if(isset($field['is_child']) && $field['is_child'] && is_bool($field['is_child'])){
$child = 'child_setting';
}
if(isset($field['is_child']) && $field['is_child'] && is_string($field['is_child'])){
$child = $field['is_child'].'_child_setting';
}
$format = '
%s %s%s ';
if ( 'textarea' == $field['type'] || 'custom_code' == $field['type'] ) {
$format = '
%s %s%s
';
}
$format = apply_filters( "modula_field_type_{$field['type']}_format", $format, $field );
$default = '';
// Check if our field have a default value
if ( isset( $field['default'] ) ) {
$default = $field['default'];
}
// Generate tooltip
$tooltip = '';
if ( isset( $field['description'] ) && '' != $field['description'] ) {
$tooltip .= '
';
}
// Get the current value of the field
$value = $this->get_setting( $field['id'], $default );
return sprintf( $format, wp_kses_post( $field['name'] ), $tooltip, $this->_render_field( $field, $value ) );
}
/**
* Create HTML for a field
*/
private function _render_field( $field, $value = '' ) {
$html = '';
switch ( $field['type'] ) {
case 'text':
$html = '
';
break;
case 'image-size':
$html = '
';
$html .= ' ';
$html .= 'x ';
$html .= ' ';
$html .= 'px ';
$html .= '
';
break;
case 'select' :
$html = '
';
foreach ( $field['values'] as $key => $option ) {
if ( is_array( $option ) ) {
$html .= '';
foreach ( $option as $key_subvalue => $subvalue ) {
$html .= '' . esc_html( $subvalue ) . ' ';
}
$html .= ' ';
}else{
$html .= '' . esc_html( $option ) . ' ';
}
}
if ( isset( $field['disabled'] ) && is_array( $field['disabled'] ) ) {
$html .= '';
foreach ( $field['disabled']['values'] as $key => $disabled ) {
$html .= '' . esc_html( $disabled ) . ' ';
}
$html .= ' ';
}
$html .= ' ';
break;
case 'dimensions-select' :
$sizes = Modula_Album_Fields_Helper::get_image_sizes();
$html = '
';
$infos = '';
foreach ( $sizes as $key => $size ) {
$html .= '' . esc_html( $size['label'] ) . ' ';
$infos .= '' . esc_html__( 'Image Size', 'modula-albums' ) . ' : ' . $size['dimensions']['width'] . 'x' . $size['dimensions']['height'];
$infos .= '. '.esc_html__('Crop','modula-albums').' : ' . ( boolval( $size['crop'] ) ? 'true' : 'false' ) . '
';
}
$html .= '' . __( 'Full', 'modula-albums' ) . ' ';
$html .= '' . __( 'Custom', 'modula-albums' ) . ' ';
$html .= ' ';
if ( '' != $infos ) {
$html .= '
' . $infos . '
';
}
break;
case 'ui-slider':
$min = isset( $field['min'] ) ? $field['min'] : 0;
$max = isset( $field['max'] ) ? $field['max'] : 100;
$step = isset( $field['step'] ) ? $field['step'] : 1;
if ( '' === $value ) {
if ( isset( $field['default'] ) ) {
$value = $field['default'];
}else{
$value = $min;
}
}
$attributes = 'data-min="' . esc_attr( $min ) . '" data-max="' . esc_attr( $max ) . '" data-step="' . esc_attr( $step ) . '"';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
break;
case 'color' :
$html .= '
';
$html .= ' ';
$html .= '
';
break;
case "toggle":
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
break;
case "custom_code":
$html = '
';
$html .= '';
$html .= '
';
break;
case "hover-effect":
$hovers = Modula_Albums_Hover_Effects::get_hover_effects();
$html .= '
';
foreach ( $hovers as $key => $option ) {
$html .= '' . esc_html( $option ) . ' ';
}
$html .= ' ';
$html .= '
' . esc_html__( 'Select an hover effect', 'modula-albums' ) . '
';
// Creates effects preview
$html .= '
';
foreach ( $hovers as $key => $name ) {
$effect = Modula_Albums_Hover_Effects::get_hover_effect_html( $key );
$effect = apply_filters( 'modula_albums_hover_effect_preview', $effect, $key );
$html .= $effect;
}
$html .= '
';
// Hook to change how hover effects field is rendered
$html = apply_filters( "modula_render_hover_effect_field_type", $html, $field );
break;
case "cursor_upload":
$style = array(
'upload' => '',
'replace' => 'display:none;',
'delete' => 'display:none;',
);
if ( 0 != absint( $value ) ) {
$style['upload'] = 'display:none;';
$style['replace'] = '';
$style['delete'] = '';
}
$html = '
';
$html .= '
';
if ( $value ) {
$image = wp_get_attachment_image_src( $value );
if ( $image ) {
$html .= '
';
}
}
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
break;
case 'textarea-placeholder' :
$html = '
';
$html .= '';
$html .= '
';
$html .= '
';
foreach ( $field['values'] as $key => $value ) {
$html .= "";
$html .= esc_html__( $value, 'modula-albums' );
$html .= ' ';
}
$html .= '
';
break;
case 'placeholder' :
$html = '
';
$html .= '
';
foreach ( $field['values'] as $key => $value ) {
$html .= "";
$html .= esc_html__( $value, 'modula-albums' );
$html .= ' ';
}
$html .= '
';
break;
default:
/* Filter for render custom field types */
$html = apply_filters( "modula_render_{$field['type']}_field_type", $html, $field, $value );
break;
}
return $html;
}
}