Forum Replies Created

Viewing 15 replies - 1 through 15 (of 23 total)
  • Thread Starter mlyczko

    (@mlyczko)

    Hi

    Thank you very much.
    There is only one issue: https://github.com/CMB2/CMB2-Snippet-Library/compare/master…mlyczko:patch-1

    Your support is excellent – better than for commercial plugins ??

    Thread Starter mlyczko

    (@mlyczko)

    Hi

    Please take a look for these fields:

    		$cmb->add_field( array(
    			'name'       => __( 'Category *', 'example' ), 
    			'id'   => $prefix . 'category',
    			'type'           => 'taxonomy_radio_hierarchical',
    			'taxonomy'       => 'ad_category', // Enter Taxonomy Slug
    			'render_row_cb' => 'override_category_field_callback'
    		) );
    		$cmb->add_field( array(
    			'name'           => __( 'Location', 'example' ),
    			'id'   => $prefix . 'locations',
    			'taxonomy'       => 'ad_location',
    			'type'           => 'taxonomy_radio_hierarchical',
    			'remove_default' => 'true',
    			'show_option_none' => false,
    		) );
    function override_category_field_callback( $field_args, $field ) {
    
    	// If field is requesting to not be shown on the front-end
    	if ( ! is_admin() && ! $field->args( 'on_front' ) ) {
    		return;
    	}
    
    	// If field is requesting to be conditionally shown
    	if ( ! $field->should_show() ) {
    		return;
    	}
    
    	$field->peform_param_callback( 'before_row' );
    
    	// Remove the cmb-row class
    	printf( '<div class="cmb-row %s">', $field->row_classes() );
    
    	if ( ! $field->args( 'show_names' ) ) {
    	
    		// If the field is NOT going to show a label output this
    		echo '<div class="cmb-td custom-label-class">';
    		$field->peform_param_callback( 'label_cb' );
    	
    	} else {
    
    		// Otherwise output something different
    		if ( $field->get_param_callback_result( 'label_cb', false ) ) {
    			echo '<div class="cmb-th">', esc_attr($field->peform_param_callback( 'label_cb' )), '</div>';
    		}
    		echo '<div class="cmb-td"><span class="tcf-categories-breadcrumb"></span><span class="tcf-add-category-done btn button">'.__( 'Use selected category', 'example' ).'</span><span class="tcf-change-category-button btn button">'.__( 'Change category', 'example' ).'</span><span class="tcf-add-category-button btn button">'.__( 'Choose  category', 'example' ).'</span>';
    	}
    
    	$field->peform_param_callback( 'before' );
    	
    	// The next two lines are key. This is what actually renders the input field
    	$field_type = new CMB2_Types( $field );
    	$field_type->render();
    
    	$field->peform_param_callback( 'after' );
    
    	echo '</div>';
    	echo '</div>';
    
    	$field->peform_param_callback( 'after_row' );
    
        // For chaining
    	return $field;
    }
    • This reply was modified 5 years, 1 month ago by mlyczko.
    Thread Starter mlyczko

    (@mlyczko)

    Hi

    Thank you for a quick response.
    Please see code between tags // DJ – BEGIN and // DJ – END

    File CMB2_Type_Multi_Base.php:

    <?php
    /**
     * CMB Multi base field type
     *
     * @since  2.2.2
     *
     * @category  WordPress_Plugin
     * @package   CMB2
     * @author    CMB2 team
     * @license   GPL-2.0+
     * @link      https://cmb2.io
     */
    abstract class CMB2_Type_Multi_Base extends CMB2_Type_Base {
    
    	/**
    	 * Generates html for an option element
    	 *
    	 * @since  1.1.0
    	 * @param  array $args Arguments array containing value, label, and checked boolean
    	 * @return string       Generated option element html
    	 */
    	public function select_option( $args = array() ) {
    		return sprintf( "\t" . '<option value="%s" %s>%s</option>', $args['value'], selected( isset( $args['checked'] ) && $args['checked'], true, false ), $args['label'] ) . "\n";
    	}
    
    	/**
    	 * Generates html for list item with input
    	 *
    	 * @since  1.1.0
    	 * @param  array $args Override arguments
    	 * @param  int   $i    Iterator value
    	 * @return string       Gnerated list item html
    	 */
    	public function list_input( $args = array(), $i ) {
    		$a = $this->parse_args( 'list_input', array(
    			'type'  => 'radio',
    			'class' => 'cmb2-option',
    			'name'  => $this->_name(),
    			'id'    => $this->_id( $i ),
    			'value' => $this->field->escaped_value(),
    			'label' => '',
    		), $args );
    		// DJ - BEGIN
    		if($a['name'] == '_tc_category'){
    			$taxonomy = 'ad_category';
    			$terms = get_terms($taxonomy, array("hide_empty" => false)); // Get all terms of a taxonomy
    			foreach ( $terms as $term ) {
    				$cat = get_term_by('slug', $a['value'], $taxonomy);
    				$image_url = '';
    				$image = '';
    				$is_parent = '';
    				if(!empty($cat)){
    					$cat_id = $cat->term_id;
    					$level1 = $cat->parent;
    					$image_url = get_term_meta( $cat_id, '_tc_cat_image', true );
    					if(!empty($image_url) && $level1 == 0){
    						$image = '<img src="'.$image_url.'" alt="'.$a['label'].'" />';
    					} else {
    						$image = '';
    					}
    					
    					if(get_term_children( $cat_id, $taxonomy )){
    						$is_parent = 'class="parent"';
    						return sprintf( "\t" . '<li %s><span><input%s/><label for="%s">%s<span>%s</span></label></span>' . "\n", $is_parent, $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $image, $a['label']);
    					} else {
    						return sprintf( "\t" . '<li %s><span><input%s/><label for="%s">%s<span>%s</span></label></span></li>' . "\n", $is_parent, $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $image, $a['label']);
    					}
    				}
    			}
    		} else {
    			return sprintf( "\t" . '<li><input%s/> <label for="%s">%s</label></li>' . "\n", $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $a['label'] );
    		}
    		
    		// DJ - END
    	}
    
    	/**
    	 * Generates html for list item with checkbox input
    	 *
    	 * @since  1.1.0
    	 * @param  array $args Override arguments
    	 * @param  int   $i    Iterator value
    	 * @return string       Gnerated list item html
    	 */
    	public function list_input_checkbox( $args, $i ) {
    		$saved_value = $this->field->escaped_value();
    		if ( is_array( $saved_value ) && in_array( $args['value'], $saved_value ) ) {
    			$args['checked'] = 'checked';
    		}
    		$args['type'] = 'checkbox';
    		return $this->list_input( $args, $i );
    	}
    
    	/**
    	 * Generates html for concatenated items
    	 *
    	 * @since  1.1.0
    	 * @param  array $args Optional arguments
    	 * @return string        Concatenated html items
    	 */
    	public function concat_items( $args = array() ) {
    		$field = $this->field;
    
    		$method = isset( $args['method'] ) ? $args['method'] : 'select_option';
    		unset( $args['method'] );
    
    		$value = null !== $field->escaped_value()
    			? $field->escaped_value()
    			: $field->get_default();
    
    		$value = CMB2_Utils::normalize_if_numeric( $value );
    
    		$concatenated_items = '';
    		$i = 1;
    
    		$options = array();
    		if ( $option_none = $field->args( 'show_option_none' ) ) {
    			$options[''] = $option_none;
    		}
    		$options = $options + (array) $field->options();
    		foreach ( $options as $opt_value => $opt_label ) {
    
    			// Clone args & modify for just this item
    			$a = $args;
    
    			$a['value'] = $opt_value;
    			$a['label'] = $opt_label;
    
    			// Check if this option is the value of the input
    			if ( $value === CMB2_Utils::normalize_if_numeric( $opt_value ) ) {
    				$a['checked'] = 'checked';
    			}
    
    			$concatenated_items .= $this->$method( $a, $i++ );
    		}
    
    		return $concatenated_items;
    	}
    
    }

    File CMB2_Type_Taxonomy_Base.php:

    <?php
    /**
     * CMB Taxonomy base field type
     *
     * @since  2.2.2
     *
     * @category  WordPress_Plugin
     * @package   CMB2
     * @author    CMB2 team
     * @license   GPL-2.0+
     * @link      https://cmb2.io
     */
    abstract class CMB2_Type_Taxonomy_Base extends CMB2_Type_Multi_Base {
    
    	/**
    	 * Checks if we can get a post object, and if so, uses <code>get_the_terms</code> which utilizes caching.
    	 *
    	 * @since  1.0.2
    	 * @return mixed Array of terms on success
    	 */
    	public function get_object_terms() {
    		switch ( $this->field->object_type ) {
    			case 'options-page':
    			case 'term':
    				return $this->options_terms();
    			case 'post':
    				// WP caches internally so it's better to use
    				return get_the_terms( $this->field->object_id, $this->field->args( 'taxonomy' ) );
    
    			default:
    				return $this->non_post_object_terms();
    		}
    	}
    
    	/**
    	 * Gets the term objects for the terms stored via options boxes.
    	 *
    	 * @since  2.2.4
    	 * @return mixed Array of terms on success
    	 */
    	public function options_terms() {
    		if ( empty( $this->field->value ) ) {
    			return array();
    		}
    
    		$terms = (array) $this->field->value;
    
    		foreach ( $terms as $index => $term ) {
    			$terms[ $index ] = get_term_by( 'slug', $term, $this->field->args( 'taxonomy' ) );
    		}
    
    		return $terms;
    	}
    
    	/**
    	 * For non-post objects, wraps the call to wp_get_object_terms with transient caching.
    	 *
    	 * @since  2.2.4
    	 * @return mixed Array of terms on success
    	 */
    	public function non_post_object_terms() {
    		$object_id = $this->field->object_id;
    		$taxonomy = $this->field->args( 'taxonomy' );
    
    		$cache_key = "cmb-cache-{$taxonomy}-{$object_id}";
    
    		// Check cache
    		$cached = get_transient( $cache_key );
    
    		if ( ! $cached ) {
    			$cached = wp_get_object_terms( $object_id, $taxonomy );
    			// Do our own (minimal) caching. Long enough for a page-load.
    			set_transient( $cache_key, $cached, 60 );
    		}
    
    		return $cached;
    	}
    
    	/**
    	 * Wrapper for <code>get_terms</code> to account for changes in WP 4.6 where taxonomy is expected
    	 * as part of the arguments.
    	 *
    	 * @since  2.2.2
    	 * @return mixed Array of terms on success
    	 */
    	public function get_terms() {
    		return CMB2_Utils::wp_at_least( '4.5.0' )
    			? get_terms( wp_parse_args( $this->field->prop( 'query_args', array() ), array(
    				'taxonomy' => $this->field->args( 'taxonomy' ),
    				'hide_empty' => false,
    			) ) )
    			: get_terms( $this->field->args( 'taxonomy' ), 'hide_empty=0' );
    	}
    
    	protected function no_terms_result( $error, $tag = 'li' ) {
    		if ( is_wp_error( $error ) ) {
    			$message = $error->get_error_message();
    			$data = 'data-error="' . esc_attr( $error->get_error_code() ) . '"';
    		} else {
    			$message = $this->_text( 'no_terms_text', esc_html__( 'No terms', 'cmb2' ) );
    			$data = '';
    		}
    
    		$this->field->args['select_all_button'] = false;
    
    		return sprintf( '<%3$s><label %1$s>%2$s</label></%3$s>', $data, esc_html( $message ), $tag );
    	}
    
    	public function get_object_term_or_default() {
    		$saved_terms = $this->get_object_terms();
    
    		return is_wp_error( $saved_terms ) || empty( $saved_terms )
    			? $this->field->get_default()
    			: array_shift( $saved_terms )->slug;
    	}
    
    	/**
    	 * Takes a list of all tax terms and outputs.
    	 *
    	 * @since  2.2.5
    	 *
    	 * @param  array  $all_terms   Array of all terms.
    	 * @param  array|string $saved Array of terms set to the object, or single term slug.
    	 *
    	 * @return string              List of terms.
    	 */
    	protected function loop_terms( $all_terms, $saved_terms ) {
    		return '';
    	}
    
    	/**
    	 * Build children hierarchy.
    	 *
    	 * @param  object       $parent_term The parent term object.
    	 * @param  array|string $saved       Array of terms set to the object, or single term slug.
    	 *
    	 * @return string                    List of terms.
    	 */
    	protected function build_children( $parent_term, $saved ) {
    		if ( empty( $parent_term->term_id ) ) {
    			return '';
    		}
    
    		$this->parent = $parent_term->term_id;
    
    		$terms   = $this->get_terms();
    		$options = '';
    
    		if ( ! empty( $terms ) && is_array( $terms ) ) {
    			// DJ - BEGIN
    			$options = '<ul class="cmb2-indented-hierarchy">';
    			$options .= $this->loop_terms( $terms, $saved );
    			$options .= '</ul>';
    			// DJ - END
    		}
    
    		return $options;
    	}
    
    }
    Thread Starter mlyczko

    (@mlyczko)

    Hi

    Thank you for your answer.
    I didn’t describe my problem precisely.
    I have a custom plugin that uses CMB2 as a part of this plugin because I’ve made some core changes (showing images for radio list).
    When I have my custom plugin and CMB2 plugin enabled my core changes are not visible on the frontend – CMB2 plugin has a higher priority than my custom plugin with overridden CMB2 included.

    Thread Starter mlyczko

    (@mlyczko)

    That’s my custom code in a plugin. There is a more code to analyze:

                    <form method="post" id="edituser" action="<?php the_permalink(); ?>">
                        <p class="form-username">
                            <label for="first_name"><?php _e('First name', 'example'); ?></label>
                            <input class="text-input" name="first_name" type="text" id="first_name" value="<?php the_author_meta( 'first_name', $current_user->ID ); ?>" />
                        </p><!-- .form-username -->
                        <p class="form-username">
                            <label for="last_name"><?php _e('Last name', 'example'); ?></label>
                            <input class="text-input" name="last_name" type="text" id="last_name" value="<?php the_author_meta( 'last_name', $current_user->ID ); ?>" />
                        </p><!-- .form-username -->
                        <p class="form-email">
                            <label for="user_email"><?php _e('E-mail', 'example'); ?></label>
                            <input class="text-input" name="user_email" type="text" id="user_email" value="<?php the_author_meta( 'user_email', $current_user->ID ); ?>" />
                        </p><!-- .form-email -->
                        <p class="form-url">
                            <label for="url"><?php _e('Website', 'example'); ?></label>
                            <input class="text-input" name="url" type="text" id="url" value="<?php the_author_meta( 'user_url', $current_user->ID ); ?>" />
                        </p><!-- .form-url -->
                        <p class="form-phone">
                            <label for="tc_phone"><?php _e('Phone', 'example'); ?></label>
                            <input class="text-input" name="tc_phone" type="text" id="tc_phone" value="<?php echo $phone_meta_value; ?>" />
                        </p><!-- .form-phone -->
                        <p class="form-password">
                            <label for="pass1"><?php _e('Password', 'example'); ?> </label>
                            <input class="text-input" name="pass1" type="password" id="pass1" />
                        </p><!-- .form-password -->
                        <p class="form-password">
                            <label for="pass2"><?php _e('Repeat password', 'example'); ?></label>
                            <input class="text-input" name="pass2" type="password" id="pass2" />
                        </p><!-- .form-password -->
                        <p class="form-textarea">
                            <label for="description"><?php _e('About me', 'example') ?></label>
                            <textarea name="description" id="description" rows="3" cols="50"><?php the_author_meta( 'description', $current_user->ID ); ?></textarea>
                        </p><!-- .form-textarea -->
                        <?php 
                            //action hook for plugin and extra fields
                            do_action('edit_user_profile',$current_user); 
                        ?>
                        <p class="form-submit">
                            <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Update', 'example'); ?>" />
                            <?php wp_nonce_field( 'update-user' ) ?>
                            <input name="action" type="hidden" id="action" value="update-user" />
                        </p>
                    </form>
    Thread Starter mlyczko

    (@mlyczko)

    Hi

    After last update of Orbit Fox this problem disappears. Thank you.

    Best Regards
    ML

    Thread Starter mlyczko

    (@mlyczko)

    Hi

    I’ve tried it. No luck ??

    Best Regards
    ML

    Thread Starter mlyczko

    (@mlyczko)

    Great support.

    Thank you very much ??

    Thread Starter mlyczko

    (@mlyczko)

    Hi

    Thank you.
    I have this code inside plugin:

    		<script>
    			jQuery(document).ready(
    				function($)
    				{
    				    $('#<?php echo $this->id; ?> .pe-recent-posts-outer').carousel({
    				    	interval: <?php echo $interval; ?>,
    						pause: "<?php echo $slider_pause; ?>"
    				    })
    				}
    			);
    		</script>

    I need a some way to get widget ID inside the plugin’s code.

    Thanks.

    Thread Starter mlyczko

    (@mlyczko)

    Hi

    Please take a look here: https://ml.dev.pax1.eu/testy/wordpress/
    There are 3 widgets in content and 3 widgets in sidebar.
    There are wrong IDs in content: https://www.screencast.com/t/FBN5zGQNt8f
    OK in sidebar: https://www.screencast.com/t/ofPp9Tnk

    Thanks

    Forum: Plugins
    In reply to: [CMB2] File List display
    Thread Starter mlyczko

    (@mlyczko)

    Hello

    I have in functions.php

    function cmb2_output_file_list( $file_list_meta_key, $img_size = 'medium' ) {
    
        // Get the list of files
        $files = get_post_meta( get_the_ID(), $file_list_meta_key, 1 );
    
        echo '<div class="file-list-wrap">';
        // Loop through them and output an image
        foreach ( (array) $files as $attachment_id => $attachment_url ) {
            echo '<div class="file-list-image">';
            echo wp_get_attachment_image( $attachment_id, $img_size );
            echo '</div>';
        }
        echo '</div>';
    }

    In my single.php i have:
    <?php cmb2_output_file_list( 'wiki_test_file_list', 'small' ); ?>

    In my CPT that im checking i have loaded images: https://screencast.com/t/xTqWUA4C8

    I still cant get the images, only empty divs. What can be wrong in my code?

    Best Regards
    ML

    Forum: Plugins
    In reply to: [CMB2] File List display
    Thread Starter mlyczko

    (@mlyczko)

    Hello

    I have images in the CPT – room.

    // Images for Slider
        $cmb->add_field( array(
            'name'       => __( 'Images for Slider', 'PixelEmu' ),
            'desc'       => __( 'Add images for slider.', 'PixelEmu' ),
            'id'         => $prefix . 'slider_images',
            'type'       => 'file_list',
            'show_on_cb' => 'cmb2_hide_if_no_cats', // function should return a bool value
            'repeatable'      => true,
        ) );

    Ican display images this way:

    $files = get_post_meta( get_the_ID(), 'pe_slider_images', 1 );
    							$img_size = 'medium';
    						    echo '<div class="file-list-wrap">';
    						    // Loop through them and output an image
    						    foreach ( $files as $key => $value ) {
    						        echo '<div class="file-list-image">';
    						        echo wp_get_attachment_image( key($value), $img_size );
    						        echo '</div>';
    
    						    }
    						    echo '</div>';

    Best Regards
    ML

    Forum: Plugins
    In reply to: [WP-LESS] Sourcemaps

    Hello

    Is there any chance that sourcemaps will be available in the next WP-Less version?

    Best Regards
    ML

    Thread Starter mlyczko

    (@mlyczko)

    Hi

    Thank you for your help.

    Best Regards
    ML

    Thread Starter mlyczko

    (@mlyczko)

    Hi

    Please taka a look: https://ml.dev.pax2.eu/testy/wordpress2/
    Thanks in advance.

    access:
    demo/demo55

    Best Regards
    ML

Viewing 15 replies - 1 through 15 (of 23 total)