Forum Replies Created

Viewing 15 replies - 31 through 45 (of 171 total)
  • Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay thank you. Seems the second hook is that I want for now (before you’ll add it as a part of the plugin in next update).

    First piece of code (in the previous post) is not good because we slice array BEFORE removing translations posts – so we can get total amount < 3.

    Ah, also I’ve just donated you some amount.
    Thanks.

    • This reply was modified 4 years, 3 months ago by Nikita_Sp.
    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay ok, let’s say I would donate you some amount to improve the plugin.
    Does it make sense? What amount would be suitable for this fix?

    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay I haven’t got the final code and doesn’t use github repos.
    It should take 30 mins maximum for you to fix this. It’s your plugin, isn’t it?

    Thanks.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay

    In theory I should first create the array of posts that gets passed to the custom template, but this is done on the fly.

    Yeah, this is the mistake. It should not. The thing is your WPML compatibility code should be BEFORE custom template output. Not in the cycle foreach for the default template.

    I have NO custom install. I’m using just a custom template hook.

    I don’t need any freedom. It’s just fine with the custom template, why I need to use global queries, etc? I have the feeling that all the custom functions (like API or get_crp_posts_id) would return the same array as custom template function.

    I’ve reported about the plugin bug, I’ve researched what is causing it.
    You need just rewrite 2 lines (just move the WPML compatibility BEFORE custom template apply_filter).

    You’ll help a lot of developers, who using this awesome plugin. Please.
    Thanks.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay hi!

    Does my previous post make sense? Maybe I could help you more?
    Just let me know.

    Thanks.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay interesting, when I disable the output filter (function for updating the template) add_filter('crp_custom_template', 'custom_crp_template', 10, 3); the issue is disappearing.

    When I add the function and just do print_r() the translated post’s ID is in the array:

    function custom_crp_template($null, $results, $plugin_settings){
    	print_r($results); // there is an ID of the translated post version in array
    }

    Seems you have different ways to create the array. Default template has no this ID, but the custom – has.

    Seems like there is a code that remove the translated version, but when I use custom template – it’s not executing. Why? The thing is the code should create the data first, and than work about the output.

    Now, while writing this answer, I’m looking through your code and see what is causing the issue. File include/main-query.php on line 116 you add custom template support and remove the translated posts on line 155-164 directly in the loop of output.

    You should add this exception BEFORE the custom template filter. And prepare the related posts array before ALL the templates.

    If I put that code 155-164 to the function custom_crp_template($null, $results, $plugin_settings){ it won’t work. I need to add also global $post to the function, and the amount of posts will be different because I need exactly 3 posts and I slice the array to 3 elements. If one of the elements in the loop will be unwanted – I need another one.

    Sorry for my English, I hope you’ll get what I mean.
    I understand you need to change your code to resolve this issue, but it would be correct from a programming point of view and I’ll rate it 5 stars!

    Thanks.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay I’ve just tried to rename all the variables. The result is the same – just translated post got to the list.

    The thing is the function got the list of posts from functions inside the plugin.
    This function is just an output code – it’s not resolving the relation.

    Of course we can exclude it from the list in the cycle, but it’s a dirty solution.

    Thanks.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay seems I’m doing something wrong because the result after adding this code is post from another language only.

    Here is a function code:

    add_filter('crp_custom_template', 'crp_template', 10, 3);
    function crp_template($null, $posts, $plugin_settings){
    	$html = '';
    	$posts = array_slice($posts, 0, 3); 
    	
    	if($posts){
    		$html = "<div class=\"sidebar-block related-posts\">";
    
    		// We need this for WPML support.
    		$processed_results = array();
    
    		foreach ($posts as $post) {
    			/* Support WPML */
    			$resultid = crp_object_id_cur_lang( $post->ID );
    
    			// If this is NULL or already processed ID or matches current post then skip processing this loop.
    			if ( ! $resultid || in_array( $resultid, $processed_results ) || intval( $resultid ) === intval( $post->ID ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
    				continue;
    			}
    
    			// Push the current ID into the array to ensure we're not repeating it.
    			array_push($processed_results, $resultid);
    			
    			
    			$html .= "	<div class=\"related-post\">";
    			$html .= "			<span class=\"post-data post-meta\" >";
    			$html .= "				<a href=\"".get_permalink( $post->ID )."\" class=\"title\" >".get_the_title($post->ID)."</a>";
    			$html .= "				<span class=\"published\">". get_the_date('d.m.Y', $post->ID) ."</span>";
    			$html .= "			</span>";
    			$html .= "	</div>";
    		}
    
    	    $html .= "</div>";
    	}
    
    	return $html;
    }

    I think the error is about using $post variable (but I’m obvious could mistaken).
    Thanks.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay I use echo_crp() function and add_filter('crp_custom_template', 'crp_template', 10, 3); to output the posts.

    The template function is quite simple (taken from documentation):

    function crp_template($null, $posts, $plugin_settings){
    	$html = '';
    	$posts = array_slice($posts, 0, 3);
    
    	foreach($post as $post)
    	...
    	
    	return $html;
    }

    And files of the plugin didn’t change.
    So our code is not impact on the plugin algorithms.

    Thanks.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay it’s placed on the right column on desktop version. It has grey background. We use custom template for that, not just a shortcode.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @ajay well just create some new website with default theme. Add polylang from plugin installer and install your plugin.

    Add two languages for tests. Add a sticky post for each language with similar title.
    It’d takes around 30 minutes.

    Than you can edit your code and debug to find out the error.
    I hope it helps.

    Thread Starter Nikita_Sp

    (@nikitasp)

    I’ve got basic polylang and CRP plugins code – nothing is changed.

    It seems the bug appears when the post is sticked.
    I have 2 sticked posts in two languages and one of them shows translation as a related post.

    Maybe this information could help you to solve the issue?
    Thanks.

    • This reply was modified 4 years, 5 months ago by Nikita_Sp.
    Thread Starter Nikita_Sp

    (@nikitasp)

    @westonruter Thanks.

    • This reply was modified 4 years, 6 months ago by Nikita_Sp.
    Thread Starter Nikita_Sp

    (@nikitasp)

    @westonruter I was talking about (as it seems to me) the right (correct) way of implementation.

    add_filter( 'amp_post_template_analytics', 'my_analytics_function' );

    But it seems this filter adds analytics to the same variable that escapes.
    So the solution you provide is the one. Thanks.

    Thread Starter Nikita_Sp

    (@nikitasp)

    @westonruter Yeah, I understand, a few weeks ago got catch an XSS-attack to one of my websites.

    But should the plugin has reduced functionality because of possible attacks on the website? If website’s owner doesn’t watch and care about his source I think intruders would find a way to make something they want.

    For example if they can access admin previleges, than they could add code to the source code directly from admin editors (theme editor, plugin editor, etc).

    Here is my humble suggestion and idea – what if the code from function.php won’t escape slashes, and if user use admin section – apply filters?

    • This reply was modified 4 years, 6 months ago by Nikita_Sp.
Viewing 15 replies - 31 through 45 (of 171 total)