Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • mdabrowski78

    (@mdabrowski78)

    @rahulbalakrishna Success! We have overcome the Yoast limitations for now.

    You will need to adjust these to your needs and be comfortable with changing the StmListing.php code until the developer can implement Yoast support. Our solution is just a workaround.

    Our solution:

    1. Add 3 Custom Fields to get SEO data in your listing form (users do not fill in the Yoast box):
    – SEO Title
    – SEO Description
    – SEO Image Path
    2. Modify the includes/classes/StmListing.php to make function calls to Yoast to copy the contents of these custom fields to Yoast’s expected Meta fields.

    Make the following changes to the uListing_listing_save() function, and modify these to reflect your preferred defaults and field names:

    FIRST CHUNK – After $options is defined

                    $options = isset($request_data['options']) ? apply_filters('uListing-sanitize-data', $request_data['options']) : [];
                    if ( !empty($options) ) {
    
    					// HACK Yoast SEO integration 
                        //
                        // We must define 3 custom fields which we capture in the edit listing page
                        //
                        //  seo_title               Text field -- Becomes SEO Title
                        //  seo_meta_descirption    Textarea field -- Becomes SEO Title
                        //  seo_image_path          Text field -- Becomes twitter and facebook image. 
    
                        // uListing Options contains arrays of values. We must split into array of Keys and Values
                        // for easy lookup
    
    			        foreach ($options as $key => $value) {
    			            if (is_array($value)) {
    			                foreach ($value as $k => $v) {
    			                    if ($k === 'meta')
    			                        continue;
    			                    if ($k == 'value' AND is_array($v))
    			                    	continue;
    			                    				
    								$variableAccessKeys[$key] = $k;
    								$variableAccessVals[$key] = $v;
    							}
    						}
    					}
    				
                        // Prepopulate SEO Title and SEO Meta Description fields from standard Title, and Description fields
    
    					if (array_key_exists('seo_title', $options) && 
    						array_key_exists('seo_title', $variableAccessKeys) &&
    						$options['seo_title'][$variableAccessKeys['seo_title']] == '') {
    						$options['seo_title'][$variableAccessKeys['seo_title']]	= $request_data['title'];
    					}
    
    					if (array_key_exists('description', $options) && 
    						array_key_exists('seo_meta_description', $variableAccessKeys) &&
    						$options['seo_meta_description'][$variableAccessKeys['seo_meta_description']] == '') {
    						$options['seo_meta_description'][$variableAccessKeys['seo_meta_description']] = $variableAccessVals['description']; 
    					}	
    
    					// End HACK	

    NEXT CHUNK – Look after $listing->save()

    
    $result['redirect_url'] = admin_url("post.php?post=". $listing->ID ."&action=edit");
                    $listing->save();
                    
                    // HACK Yoast SEO integration continued
                    //
                    // Set yoast fields for title and meta description
    	            
    	            if (array_key_exists('title', $request_data)) {    
    					update_post_meta($post_id, '_genesis_title', $request_data['title'] . ' - DayBack Calendar');
    			        update_post_meta($post_id, '_yoast_wpseo_title', $request_data['title'] . ' - DayBack Calendar');
    			    }
    
    				update_post_meta($post_id, '_genesis_description', $variableAccessVals['seo_meta_description']);
    		        update_post_meta($post_id, '_yoast_wpseo_metadesc', $variableAccessVals['seo_meta_description']);
    
    				// If an image has been specified, strip sizing, look up the asset in the database to get
                    // the image ID. Assign the twitter image and image ID
    
    				if ($variableAccessVals['seo_image_path'] != '') {
    					update_post_meta($post_id, '_yoast_wpseo_opengraph-image', $variableAccessVals['seo_image_path']);
    					update_post_meta($post_id, '_yoast_wpseo_twitter-image', $variableAccessVals['seo_image_path']);				
    					
    					$imgUrl = $variableAccessVals['seo_image_path'];
    					$imgUrl = preg_replace("/-(\d+)x(\d+)\.png/", '.png', $variableAccessVals['seo_image_path']);
    					
    					// Grab the Image ID by URL
    				    global $wpdb;
    					$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $imgUrl)); 
    					$imgID = $attachment[0]; 
    					
    					if ($imgID > 0) {
    						update_post_meta($post_id, '_yoast_wpseo_opengraph-image-id', $imgID);
    						update_post_meta($post_id, '_yoast_wpseo_twitter-image-id', $imgID);						
    					}
    				}
    				
    				// End SeedCode
    				
                    $result['status']   = 'success';
                    $result['success']  = true;
                    $result['message']  = __('Listing saved successfully', 'ulisting');
    
    mdabrowski78

    (@mdabrowski78)

    @rahulbalakrishna I’m also very new to hacking this, so I don’t have experience compiling the dist file.

    mdabrowski78

    (@mdabrowski78)

    @rahulbalakrishna we found bugs with our solution. Even though I had success getting Yoast content to save, it ended yup erasing uListing categories and other uListing data elements because those need to be saved through the plugin and not through wordpress’s regular edit page post processing.

    So, back to trying different solution. If we find something that works we will update you.

    mdabrowski78

    (@mdabrowski78)

    You may need to change your version number in the plugin for it to recognize the new code
    edit ulisting.php and change version number, or do a hard refresh, and/or reload the php change manually in the browser to make sure the .js change made it into the file.

    This was very hard to fix for me, and it took many attempts, and I needed to try several times to make sure that the .js file was refreshing my change… but you will succeed in the end, so long as you remove the window.location.refresh() and reload() events and replace with the document.getElementById(‘post’).submit() event and get that .js file to update with your changes.

    Good luck

    mdabrowski78

    (@mdabrowski78)

    Here are the modifications:

    assets/js/admin/src/components/listing-types/tabs/builder/control-panel/textarea-field.js

    Fixed bug in Single Item Display Layout page which caused a HTML code, Text Area input to be displayed as a Checkbox input type. Prevented insertion of custom HTML in layout.

    Replace this:

    <div class="form-group">
    	<label class="ulisting-checkbox">
    		<input type="checkbox"  :true-value="1" :false-value="0" v-model="data[field.name]" />
    		<span></span>
    		{{field.label}}
    	</label>
    </div>

    With this:

    <div class="form-group">
    	<label>{{field.label}}</label>
    	<textarea class="form-control" v-model="data[field.name]"></textarea>
    </div>

    assets/js/admin/dist/app.js

    Replace:

    "textarea-field":{data:function(){return{}},mounted:function(){},methods:{},props:{id:{default:0},data:{default:""},field:{default:""}},watch:{data:function(t){this.$emit("input",t)}},template:'\n\t\t<div class="form-group">\n\t\t\t<label class="ulisting-checkbox">\n\t\t\t\t<input type="checkbox" :true-value="1" :false-value="0" v-model="data[field.name]" />\n\t\t\t\t<span></span>\n\t\t\t\t{{field.label}}\n\t\t\t</label>\n\t\t</div>\n\t'}

    With this:

    "textarea-field":{data:function(){return{}},mounted:function(){},methods:{},props:{id:{default:0},data:{default:""},field:{default:""}},watch:{data:function(t){this.$emit("input",t)}},template:'\n\t\t<div class="form-group">\n\t\t\t<label>{{field.label}}</label>\n\t\t\t\t<textarea class="form-control" v-model="data[field.name]"></textarea>\n\t\t</div>\n\t'}

    mdabrowski78

    (@mdabrowski78)

    Rahul,

    You will also have to make the change in assets/js/admin/dist/app.js
    This is the compiled version of the index.js

    Then clear your cache and changes will take effect

    M

    mdabrowski78

    (@mdabrowski78)

    I just fixed this yesterday. The Edit Listing page in the admin reloads the page after the form is save which is why your Yoast elements aren’t saved. It must be changed to submit the page.

    assets/js/admin/dist/app.js

    Replace:

    ei(this.getAjaxUrl+"?action=uListing_listing_save","POST",n).then((function(t){return t.json()})).then((function(e){if(c(e.message,e.status),t.change_type=!0,t.load=!1,t.status_helper=t.post_status,e.redirect_url&&t.is_create)return window.location.replace(e.redirect_url),!0;window.location.reload()})).catch((function(t){return console.log(t)}))}

    With:

    ei(this.getAjaxUrl+"?action=uListing_listing_save","POST",n).then((function(t){return t.json()})).then((function(e){if(c(e.message,e.status),t.change_type=!0,t.load=!1,t.status_helper=t.post_status,e.redirect_url&&t.is_create)return document.getElementById('post').submit()})).catch((function(t){return console.log(t)}))}

Viewing 7 replies - 1 through 7 (of 7 total)