Home Forums WoodMart support forum 1 Column footer & Instagram

1 Column footer & Instagram

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #34839

    ruandeyzel
    Participant

    Hi there, 2 issues after updating from 1.7 to 1.9

    I have a 1 column footer layout – Does not show the 1 footer widget in Appearance > Widgets when 1 column is activated under Theme settings > Footer. Tested with 2 column layout and it only shows the 2 footer columns widgets then.

    Instagram not loading correctly bottom of homepage.

    Thanks

    #34866

    Eric Watson
    Participant

    Hi,

    1) You can fix it in the file woodmart/inc/theme-setup.php

    change the line

    if( count( $footer_config['cols'] ) > 1 ) {

    to this one

    if( count( $footer_config['cols'] ) > 0 ) {

    2) Try to add the following PHP code snippet to the child theme file functions.php to fix this issue

    function woodmart_scrape_instagram($username, $slice = 9) {
    		$username = strtolower( $username );
    		$by_hashtag = ( substr( $username, 0, 1) == '#' );
    		
    		if ( false === ( $instagram = get_transient( 'instagram-media-new-'.sanitize_title_with_dashes( $username ) ) ) ) {
    			
    			$request_param = ( $by_hashtag ) ? 'explore/tags/' . substr( $username, 1) : trim( $username );
    			$remote = wp_remote_get( 'https://instagram.com/'. $request_param );
    			
    			if ( is_wp_error( $remote ) )
    				return new WP_Error( 'site_down', esc_html__( 'Unable to communicate with Instagram.', 'woodmart' ) );
    				
    			if ( 200 != wp_remote_retrieve_response_code( $remote ) )
    				return new WP_Error( 'invalid_response', esc_html__( 'Instagram did not return a 200.', 'woodmart' ) );
    				
    			$shards = explode( 'window._sharedData = ', $remote['body'] );
    			$insta_json = explode( ';</script>', $shards[1] );
    			$insta_array = json_decode( $insta_json[0], TRUE );
    
    			if ( !$insta_array )
    				return new WP_Error( 'bad_json', esc_html__( 'Instagram has returned invalid data.', 'woodmart' ) );
    				
    			// old style
    			if ( isset( $insta_array['entry_data']['UserProfile'][0]['userMedia'] ) ) {
    				$images = $insta_array['entry_data']['UserProfile'][0]['userMedia'];
    				$type = 'old';
    			// old_2 style
    			} elseif( $by_hashtag && isset( $insta_array['entry_data']['TagPage'][0]['tag']['media']['nodes'] ) ) {
    				$images = $insta_array['entry_data']['TagPage'][0]['tag']['media']['nodes'];
    				$type = 'old_2';
    			}else if ( isset( $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'] ) ) {
    				$images = $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
    				$type = 'old_2';
    			// new style
    			} elseif( $by_hashtag && isset( $insta_array['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'] ) ) {
    				$images = $insta_array['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'];
    				$type = 'new';
    			} else {
    				return new WP_Error( 'bad_json_2', esc_html__( 'Instagram has returned invalid data.', 'woodmart' ) );
    			}
    
    			if ( !is_array( $images ) )
    				return new WP_Error( 'bad_array', esc_html__( 'Instagram has returned invalid data.', 'woodmart' ) );
    				
    			$instagram = array();
    			
    			switch ( $type ) {
    				case 'old':
    					foreach ( $images as $image ) {
    						if ( $image['user']['username'] == $username ) {
    							$image['link']						  = $image['link'];
    							$image['images']['thumbnail']		   = preg_replace( "/^http:/i", "", $image['images']['thumbnail'] );
    							$image['images']['standard_resolution'] = preg_replace( "/^http:/i", "", $image['images']['standard_resolution'] );
    							$image['images']['low_resolution']	  = preg_replace( "/^http:/i", "", $image['images']['low_resolution'] );
    							$instagram[] = array(
    								'description'   => $image['caption']['text'],
    								'link'		  	=> $image['link'],
    								'time'		  	=> $image['created_time'],
    								'comments'	  	=> $image['comments']['count'],
    								'likes'		 	=> $image['likes']['count'],
    								'thumbnail'	 	=> $image['images']['thumbnail'],
    								'large'		 	=> $image['images']['standard_resolution'],
    								'small'		 	=> $image['images']['low_resolution'],
    								'type'		  	=> $image['type']
    							);
    						}
    					}
    				break;
    				case 'old_2':
    					foreach ( $images as $image ) {
    						$image['thumbnail_src'] = preg_replace( "/^https:/i", "", $image['thumbnail_src'] );
    						$image['thumbnail'] = preg_replace( "/^https:/i", "", $image['thumbnail_resources'][0]['src'] );
    						$image['medium'] = preg_replace( "/^https:/i", "", $image['thumbnail_resources'][2]['src'] );
    						$image['large'] = $image['thumbnail_src'];
    						$image['display_src'] = preg_replace( "/^https:/i", "", $image['display_src'] );
    						if ( $image['is_video'] == true ) {
    							$type = 'video';
    						} else {
    							$type = 'image';
    						}
    						$caption = esc_html__( 'Instagram Image', 'woodmart' );
    						if ( ! empty( $image['caption'] ) ) {
    							$caption = $image['caption'];
    						}
    						$instagram[] = array(
    							'description'   => $caption,
    							'link'		  	=> '//instagram.com/p/' . $image['code'],
    							'time'		  	=> $image['date'],
    							'comments'	  	=> $image['comments']['count'],
    							'likes'		 	=> $image['likes']['count'],
    							'thumbnail'	 	=> $image['thumbnail'],
    							'medium'		=> $image['medium'],
    							'large'			=> $image['large'],
    							'original'		=> $image['display_src'],
    							'type'		  	=> $type
    						);
    					}
    				break;
    				default:
    					foreach ( $images as $image ) {
    						$image = $image['node'];
    						$caption = esc_html__( 'Instagram Image', 'woodmart' );
    						if ( ! empty( $image['edge_media_to_caption']['edges'][0]['node']['text'] ) ) $caption = $image['edge_media_to_caption']['edges'][0]['node']['text'];
    						
    						$image['thumbnail_src'] = preg_replace( "/^https:/i", "", $image['thumbnail_src'] );
    						$image['thumbnail'] = preg_replace( "/^https:/i", "", $image['thumbnail_resources'][0]['src'] );
    						$image['medium'] = preg_replace( "/^https:/i", "", $image['thumbnail_resources'][2]['src'] );
    						$image['large'] = $image['thumbnail_src'];
    						
    						$type = ( $image['is_video'] ) ? 'video' : 'image';
    						
    						$instagram[] = array(
    							'description'   => $caption,
    							'link'		  	=> '//instagram.com/p/' . $image['shortcode'],
    							'comments'	  	=> $image['edge_media_to_comment']['count'],
    							'likes'		 	=> $image['edge_liked_by']['count'],
    							'thumbnail'	 	=> $image['thumbnail'],
    							'medium'		=> $image['medium'],
    							'large'			=> $image['large'],
    							'type'		  	=> $type
    						);
    					}
    				break;
    			}
    			// do not set an empty transient - should help catch private or empty accounts
    			if ( ! empty( $instagram ) ) {
    				$instagram = woodmart_compress( maybe_serialize( $instagram ) );
    				set_transient( 'instagram-media-new-'.sanitize_title_with_dashes( $username ), $instagram, apply_filters( 'null_instagram_cache_time', HOUR_IN_SECONDS*2 ) );
    			}
    		}
    		if ( ! empty( $instagram ) ) {
    			$instagram = maybe_unserialize( woodmart_decompress( $instagram ) );
    			return array_slice( $instagram, 0, $slice );
    		} else {
    			return new WP_Error( 'no_images', esc_html__( 'Instagram did not return any images.', 'woodmart' ) );
    		}
    	}

    We will fix this issues in our next theme update.

    Regards

    #34880

    ruandeyzel
    Participant

    Thanks. When is the next update due? I need a date to tell client.

    #34913

    Artem Temos
    Keymaster

    We hope to release the next version in 7-10 days.

    #34988

    ruandeyzel
    Participant

    Thanks for the help – The Instagram fix didn’t work so will have to wait for the update. Single column footer fix works.

    #34990

    Artem Temos
    Keymaster

    You will need to clear your WordPress transients cache or wait for a few hours to see the instagram changes.

Viewing 6 posts - 1 through 6 (of 6 total)