Support » Plugin: Knews Multilingual Newsletters » %the_excerpt_1% and %the_content_1% not working

  • Resolved asherchayyim

    (@asherchayyim)


    Hi,

    Like the thread title says, %the_excerpt_1% and %the_content_1% are not being replaced with proper text – instead they are replaced with EMPTY content. At the same time, %the_title_1% is working FINE.

    I have an auto-create template and an auto-create job.
    For each test i’m creating a new post, with title and content.

    When manually running the job, all is fine (wp-admin/admin-ajax.php?action=knewsForceAutomated&manual=1):

    “Automated job (auto_newsletter_test_3)
    – posts to send: 1
    – there is a newsletter to build: template newsletter (test) #3
    – including post: Postare de test
    – included: Postare de test
    – saving the created newsletter
    – scheduling the submit
    Batch submit process has been properly scheduled.

    – all done
    let’s iterate, maybe more posts wait for news build
    – posts to send: 0
    0″

    After that, when manually running the submit task, again, all is fine (wp-admin/admin-ajax.php?action=knewsCronDo&js=5):

    “Step #6

    Cron-JS finished, you can close the window”

    The problem is that the email I receive has the %the_excerpt_1% and %the_content_1% replaced with EMPTY text (but %the_title_1% is CORRECTLY replaced).

    I’ve checked everything, even the html source of the template to make sure the keywords are NOT split in 2 html tags. Everyting is fine.

    If needed, I can provide the website URL, user and password for debugging.

    Thank you.

    https://wordpress.org/plugins/knews/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter asherchayyim

    (@asherchayyim)

    It turns out the plugin was using only the first keyword found on the page, so if I had “the_title_1” first on the page, the plugin would ignore any following keywords, for example “the_content_1” or any other.

    But if, instead, the “content” keyword was first on the page, and let’s say, for example’s sake, the “title” keyword – after, it would ignore replacing the title keyword.

    Because the author of the plugin didn’t show any interest in solving this bug, I had to debug the PHP code and solve it myself.

    What I’ve changed was that while the old code was replacing only the first keyword on the page, the new code I’ve wrote is a “for” loop cycle that searches for every keyword on the page.

    If anybody else has the same issue, you need to edit the following file:

    /public_html/wp-content/plugins/knews/includes/automated_jobs.php

    and approx from line 385 – until you reach a line like this

    knews_debug(‘- included: ‘ . $pp->post_title . “\r\n”)

    you need to replace all that existing code with this below:

    $anyfound = false;
    
    for ($s=0; $s < count($news_mod_map); $s++) {
        if ($news_mod_map[$s]==0) { continue; }
    
        $n=1;
        $found=false;
        while (!$found && $n<10) {
            if (strpos($news_mod2[$s], '%the_title_' . $n . '%') !== false || strpos($news_mod2[$s], '%the_excerpt_' . $n . '%') !== false || strpos($news_mod2[$s], '%the_permalink_' . $n . '%') !== false || strpos($news_mod2[$s], '%the_content_' . $n . '%') !== false) {
                $found=true;
                $anyfound = true;
            } else {
                $n++;
            }
        }
    
        if ($found) {
            $news_mod_map[$s]--;
            $news_mod2[$s] = str_replace('%the_permalink_' . $n . '%', $permalink, $news_mod2[$s]);
            $news_mod2[$s] = str_replace('%the_title_' . $n . '%', $title, $news_mod2[$s]);
            $news_mod2[$s] = str_replace('%the_excerpt_' . $n . '%', $excerpt, $news_mod2[$s]);
            $news_mod2[$s] = str_replace('%the_content_' . $n . '%', $content, $news_mod2[$s]);
        }
    }
    
    if ($anyfound) {
        $subject = str_replace('%the_title_1%', $title, $subject);
    
        // replace until here, below is existing code whch you should leave as is
    
        knews_debug('- included: ' . $pp->post_title . "\r\n");
    Thread Starter asherchayyim

    (@asherchayyim)

    in the newest version of the plugin, 1.6.4, the same issue persists, and the same solution can be applied, only that now, the starting line where you replace code is approx 357, and the ending line is approx 377.

    More exactly, starting from this lines, inclusive:

    $s=0;
    while ($news_mod_map[$s]==0 && $s < count($news_mod_map)) { $s++; }

    and until this lines, inclusive:

    $news_mod2[$s] = str_replace('%the_content_' . $n . '%', $content, $news_mod2[$s]);
    $subject = str_replace('%the_title_1%', $title, $subject);

    you need to delete all that and replace it with the code I’ve provided in the previous post above.

    Good luck, write me in case you need any assistance with this bug, as I’ve managed to solve it.

    Plugin Author creverter

    (@creverter)

    Hello. We are so bussy last time, sorry…

    We will check this and include it in the next release.

    Thank you very much,
    Carles Reverter.

    Plugin Author creverter

    (@creverter)

    Hello.

    We’re tested it deeply, and can’t reproduce the issue. After analise your mod, I suspect you’re doing a mistake, can you confirm if the issue occurs only in custom newsletter template?

    Maybe you’ve a module with more than one post, and you set twice %the_title_1% instead of %the_title_1% and %the_title_2% (or similar with the_content, the_excerpt or the_permalik???

    Keep in mind your mod is inside another loop, that runs for every post to include. And the inside code seeks for a hole to insert a post and stop when found it.

    Please, give us feedback about.
    Carles Reverter.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘%the_excerpt_1% and %the_content_1% not working’ is closed to new replies.