INN / umbrella-energynewsnetwork

Umbrella repository for the Energy News Network site, a project of Fresh Energy
https://energynews.us
GNU General Public License v2.0
0 stars 1 forks source link

ENN Mailchimp widget form updates #101

Closed benlk closed 4 years ago

benlk commented 4 years ago

Changes

This pull request makes the following changes:

On the Digest page: Screen Shot 2020-05-13 at 00 04 25

On the homepage, with .rev styles:

Screen Shot 2020-05-13 at 00 10 12

On an article page:

Screen Shot 2020-05-13 at 00 11 17

Why

For #100

Testing/Questions

Features that this PR affects:

Questions that need to be answered before merging:

Steps to test this PR:

  1. Settings > Privacy, set a privacy policy URL. I'm using the 'Privacy Policy' page in testing. https://energynews.us/privacy/
  2. View this widget in the homepage, Digest category sidebar, and other archives. View it in single posts as well.
benlk commented 4 years ago
benlk commented 4 years ago

Ken has disabled GDPR and requested the removal of:

benlk commented 4 years ago

Screen Shot 2020-05-20 at 17 52 31 Screen Shot 2020-05-20 at 17 53 05 Screen Shot 2020-05-20 at 17 53 17

benlk commented 4 years ago

Form for a widget titled "Manage your subscription":

<p>Are you subscribed to one or more daily digests? Add or remove subscriptions by entering the email used to subscribe:</p>
<!-- Begin Mailchimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
<style type="text/css">
    #mc_embed_signup form{padding: 0;}
    /* Add your own Mailchimp form style overrides in your site stylesheet or in this style block.
       We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>
<div id="mc_embed_signup">
<form action="https://midwestenergynews.us7.list-manage.com/subscribe/post?u=ae5d3a0c6088cad29d71bf0d0&amp;id=724b1f01f5" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">

<div class="">
    <label for="mce-EMAIL">Email Address </label>
    <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
    <div id="mce-responses" class="clear">
        <div class="response" id="mce-error-response" style="display:none"></div>
        <div class="response" id="mce-success-response" style="display:none"></div>
    </div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
    <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_ae5d3a0c6088cad29d71bf0d0_724b1f01f5" tabindex="-1" value=""></div>
    <div class="clear"><input type="submit" value="Manage" name="subscribe" id="mc-embedded-subscribe" class="btn btn-primary"></div>
    </div>
</form>
</div>
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';fnames[3]='ADDRESS';ftypes[3]='address';fnames[4]='PHONE';ftypes[4]='phone';fnames[5]='MMERGE5';ftypes[5]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
<!--End mc_embed_signup-->

Updated 2020-05-22

benlk commented 4 years ago

I see what Ken means about search.

https://usenergystage.wpengine.com/digests/court-epa-failed-to-uphold-clean-air-acts-good-neighbor-pollution-rule/ is a digest post that contains the word "Solar" in the post content, but not in the post title.

Searching for a digest by the word "solar" between two dates that this post falls within does not return that post. Additionally, the search results contain posts outside the specified dates.

https://usenergystage.wpengine.com/category/digest/?digest-search=solar&after=2020-05-17&before=2020-05-22&search+submit=

It looks like the "After" parameter isn't working correctly in the query.

benlk commented 4 years ago

https://github.com/INN/umbrella-energynewsnetwork/pull/101/commits/e927f5be3745130981c1973894e689417b05beb4 fixed the "after" search, and also appears to have somehow fixed some of the issues with a search for "solar" on staging.

Testing

Trying to find https://usenergystage.wpengine.com/digests/court-epa-failed-to-uphold-clean-air-acts-good-neighbor-pollution-rule/ : a post with "solar" in the post_content but not in the title, published May 20.

However, a search not constrained by date for "solar" shows items in descending order that all have "solar" in their headlines. https://usenergystage.wpengine.com/category/digest/?digest-search=solar&after=&before=&search+submit=

The reason why appears to be suggested by https://usenergystage.wpengine.com/category/digest/?digest-search=solar&after=2020-05-17&before=&search+submit= , which shows first posts with "solar" in their title and then posts without. So maybe there's something in the orderby params that we can use here.

Next steps

benlk commented 4 years ago

The orderby is by date, desc, but what's happening is that the actual query is first for post title, second for post excerpt, third for post content:

'request' => '
SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID
FROM wp_posts
LEFT JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1
AND ( 
  wp_posts.post_date > \'2020-05-17 23:59:59\'
) AND ( 
  wp_term_relationships.term_taxonomy_id IN (20198,20348,20710,20711,20720,20721)
) AND ((
    (wp_posts.post_title LIKE \'{c573fccdc8da8ca64f5209b77a5c50838319feac11677aba69b682840c09d612}solar{c573fccdc8da8ca64f5209b77a5c50838319feac11677aba69b682840c09d612}\')
    OR (wp_posts.post_excerpt LIKE \'{c573fccdc8da8ca64f5209b77a5c50838319feac11677aba69b682840c09d612}solar{c573fccdc8da8ca64f5209b77a5c50838319feac11677aba69b682840c09d612}\')
    OR (wp_posts.post_content LIKE \'{c573fccdc8da8ca64f5209b77a5c50838319feac11677aba69b682840c09d612}solar{c573fccdc8da8ca64f5209b77a5c50838319feac11677aba69b682840c09d612}\')
))  AND (wp_posts.post_password = \'\')
AND wp_posts.post_type IN (\'post\', \'roundup\')
AND (wp_posts.post_status = \'publish\')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC LIMIT 0, 20',

In a query for 20 posts of descending date, where there are 20 posts with matching post titles, those get priority over any posts with matching post_content even if the post_content ones are newer.

benlk commented 4 years ago

There does not appear to be an easy way to limit this search to just post_content, which would be the action that most-closely matches Ken's goal.

The order that WP_Query::parse_search() generates the statement for the search is set as post_title, post_excerpt, post_content.

https://wordpress.stackexchange.com/a/293220 shows a filter that could be used but I'm not sure of how safe it is to implement, whether it works, or whether it's something we'd want to run it in production.

benlk commented 4 years ago

I think he wants title AND content, as opposed to just title

A shorter-time solution might be to:

  1. over-query for, say, 60 posts
  2. reorder the query results by date
  3. output the first 20.

This would not always be guaranteed to return the desired posts if more than 20 posts have the search term in their post_title.

Why did we remove Load More Posts from this template? That might help solve some of the problem.

benlk commented 4 years ago

Approved by Ken.

benlk commented 4 years ago

:deployed: