• Hi,

    Not sure if this forum is the right place for it, so if it isn’t, feel free to move it elsewhere, or delete.

    I’m modifiying a custom plugin and I need to be able to pass the user_id and the site_id through the shortcode. Basically what I need to do is to be able to output into a shortcodes that list a user’s favorite posts (one shortcode) and images (another shortcode – pulls images from the parent’s media library) into the network subsite/subdomain.

    These shortcodes are currently set-up to work on my parent site, but I need to know how to get the shortcode to display on a subsite.

    I imagine that I would need to have a global media library plugin to get this set-up of sorts?

    I’m not a programmer by any means, so I need to learn how to do this myself. I would appreciate if any of you could provide any documentation, guidance, or mentoring to help me get this done.

    I wonder if there’s a course on Udemy or something about passing user_id and site_id through shortcode?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    If the shortcode is not designed to accept certain data, you’d need to customize the shortcode handler function itself. It might be a tall order for a non-programmer, though if you at least have coding aptitude you might be able to cobble something together.

    You shouldn’t modify theme or plugin code directly though. Some code has action or filter hooks with which you can extend functionality. Otherwise, copy the function code into your own plugin and assign new names for your version of the handler function.

    Thread Starter haltek18

    (@haltek18)

    I was told I could use switch_to_blog function within my script. I want to switch to blog 5.

    This is the shortcode I use to fetch the user_id, just need to get the site_id passed through it. Would I use switch_to_blog in this case?

    add_shortcode('user_id_favorite_images', 'user_id_favorite_imagesCBF');
    	function user_id_favorite_imagesCBF($atts){
    	    if (is_admin())
    			return;
    					
                extract(
        			shortcode_atts(
        				array(
        					'uid' => ''
        					), 
        					$atts
        			)
    			);
    			
    	    if ( $uid == '' || !($uid > 0) || !($uid >= 1) )
    			return;
    			
    		$curUserID = $uid; 
    		
    		$mam_my_favorite_images_arr = get_metadata('user',$curUserID, 'mam_my_favorite_images_arr', true);
    		
    		$mam_my_favorite_images_arr = $mam_my_favorite_images_arr ? $mam_my_favorite_images_arr : array(); 
    		
    		$media_cats_terms = get_terms( 'media-category');
    	
    		
    		if(count($mam_my_favorite_images_arr) > 0 && !empty( $media_cats_terms ) && !is_wp_error( $media_cats_terms ) ){
    			
    		foreach($media_cats_terms as $media_cat_term){
    				$image_posts = get_posts(
    					array(
    						'posts_per_page' => -1,
    						'post_type' => 'attachment',
    						'tax_query' => array(
    							array(
    								'taxonomy' => 'media-category',
    								'field' => 'term_id',
    								'terms' => $media_cat_term->term_id,
    							)
    						)
    					)
    				); // image_posts
    				//echo '<pre>'; print_r($image_posts); echo '</pre>';
    				if(isset($image_posts[0])){
    				    
    					$gray_counter = 1;
    					foreach($image_posts as $image_post){
    
    					if( false !== array_search($image_post->ID,$mam_my_favorite_images_arr)){
    						$image_id = $image_post->ID;
    						$flag_wrt_img_uid = get_metadata('user',$curUserID, 'favorites_wrt_imageid_'.$image_id.'_uid_'.$curUserID.'_flag', true);
    						$count = get_metadata('post',$image_id, 'simplefavorites_count', true);
    						if($flag_wrt_img_uid && $flag_wrt_img_uid == 'adding_one'){
    							$gray_counter++; 
    							
                                $approveArgs = array('status' => 'approve', 'post_id' => $image_id,'user_id' => $curUserID, 'order'=>'ASC'); 
                                $approveComments = get_comments($approveArgs);
    							//echo '<pre>'; print_r($image_posts); echo '</pre>'
    							 if(isset($category_name) && $category_name == $media_cat_term->name){
    					    } else {
    					        
        					    $category_name = $media_cat_term->name;
        						echo '<h3>'.($media_cat_term->name).'</h3>';
        						echo '<ul class="favorites-list">';
    					    }
    							?>
    					
    						
    						<li class="div_table_li_wrapper" <?php echo ( ($gray_counter % 2 == 0) ? 'style="background-color:#f1f1f1"' : '')?>>
    							<div class="div_table" style="margin-left: 20px;">
    								<div class="table_row">
    									<div class="table_demention_1" valign="top">
    									    <a>" class="mam_mas_fancybox" rel="example_group" href="<?php echo wp_get_attachment_url($image_id)?>"><img />" height="100" width="100" /></a>
    									 </div>
    									<div  class="table_demention_2" valign="top">
    										<div><?php echo get_the_title($image_id) ?></div>
    										<div>&nbsp;</div>
    										<div>
    											<span id="ufi_mam_favorit_wrapper">
    												<span class="sf-icon-spinner-wrapper">
    													<span class="ufi_mam_favorit_count" style="background: #ff7400;color: white;padding: 9px 9px 9px 9px; margin-top: -4px;"><?php echo $count?></span><span style="display:none;" class="sf-icon-spinner"></span></span><span type="button" name="ufi_mam_favorit_clicked" value="<?php echo $image_id?>" class="sf-icon-love ufi_mam_favorit_clicked" style="background: black;padding: 9px 9px 9px 9px;border: none;margin-top: -7px;color: #f87f94;position: absolute"></span>
    											</span>
    										</div>
    									</div>
    								</div>
    							</div>
    				<button style="<?php echo ($approveComments && count($approveComments) > 0 ? '' : 'display:none')?>" class="vc_general vc_btn3 vc_btn3-size-sm vc_btn3-shape-round vc_btn3-style-custom favorites_comments_show_hide">Show/ Hide Comments</button>
                    <div id="comments" class="comments-area favorites_comments_area_block" style="display:none;">								
                        <div class="comment-list">
                    		<?php if(shortcode_exists('sc_divider')) { echo do_shortcode('[sc_divider style="1" color="'.esc_attr(scalia_get_option('divider_default_color') ? scalia_get_option('divider_default_color') : '').'"]'); } ?>
                    		<?php
                    			wp_list_comments( array(
                    				'style'      => 'div',
                    				'short_ping' => true,
                    				'avatar_size'=> 50
                    			),$approveComments );
                    		?>
                    	</div><!-- .comment-list --
                    </div><!-- #comments -->
    						</li>

    Not sure where it’d go.

    • This reply was modified 6 years, 4 months ago by haltek18.
    • This reply was modified 6 years, 4 months ago by haltek18.
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to pass site_id through shortcode?’ is closed to new replies.