10up / ads-txt

Ads.txt Manager for WordPress: Manage your ads.txt and app-ads.txt files in the WordPress dashboard
https://wordpress.org/plugins/ads-txt/
GNU General Public License v2.0
57 stars 25 forks source link

Add support for the WordPress.org plugin preview #158

Closed dkotter closed 11 months ago

dkotter commented 11 months ago

Description of the Change

WordPress.org recently launched support for plugin previews utilizing the WordPress Playground feature. Plugins wanting to take advantage of this need to opt in by setting up a blueprint.json file that configures how the preview should load. This PR adds in that file that does the following:

  1. Sets up an environment running PHP 7.4 (our supported minimum) and the latest version of WordPress
  2. Logs into the admin
  3. Sets up pretty permalinks
  4. Installs and activates the plugin
  5. Runs some custom PHP that will add a sample ads.txt file and app-ads.txt file
  6. Sends the user to the ads.txt settings page

Note that this PR is targeted to trunk as the hope is we can take advantage of our Plugin Asset Update Action to deploy these changes without having to push out a new release. This new blueprint file needs to live within the assets directory in the svn repo, which is the same directory that Action will send changes to.

Also note once these changes are on .org, the preview button will need to be enabled in a test state. Once verified as working, we can enable it for all users.

How to test the Change

The WordPress Playground allows you to spin up a new environment directly through the URL, by going to https://playground.wordpress.net/# and pasting your JSON config after the #. In this case, the URL should be: https://playground.wordpress.net/#{%22$schema%22:%22https://playground.wordpress.net/blueprint-schema.json%22,%22landingPage%22:%22/wp-admin/options-general.php?page=adstxt-settings%22,%22preferredVersions%22:{%22php%22:%227.4%22,%22wp%22:%22latest%22},%22phpExtensionBundles%22:[%22kitchen-sink%22],%22steps%22:[{%22step%22:%22login%22,%22username%22:%22admin%22,%22password%22:%22password%22},{%22step%22:%22setSiteOptions%22,%22options%22:{%22permalink_structure%22:%22/%25postname%25/%22}},{%22step%22:%22installPlugin%22,%22pluginZipFile%22:{%22resource%22:%22wordpress.org/plugins%22,%22slug%22:%22ads-txt%22},%22options%22:{%22activate%22:true}},{%22step%22:%22runPHP%22,%22code%22:%22%3C?php%20require_once%20'wordpress/wp-load.php';%20$adstxt_id%20=%20wp_insert_post(%20array(%20'post_title'%20=%3E%20'Ads.txt',%20'post_content'%20=%3E%20'#%20Example%20information\ncontact=test@example.com\n\n#%20Example%20record\ngoogle.com,%20pub-1234567890,%20DIRECT,%20f08c47fec0942fa0',%20'post_status'%20=%3E%20'publish',%20'post_type'%20=%3E%20'adstxt'%20)%20);%20$app_adstxt_id%20=%20wp_insert_post(%20array(%20'post_title'%20=%3E%20'App-ads.txt',%20'post_content'%20=%3E%20'#%20Example%20information\ncontact=test@example.com\n\n#%20Example%20record\ngoogle.com,%20pub-1234567890,%20DIRECT,%20f08c47fec0942fa0',%20'post_status'%20=%3E%20'publish',%20'post_type'%20=%3E%20'app-adstxt'%20)%20);%20if%20(%20!%20$adstxt_id%20instanceof%20WP_Error%20)%20{%20update_option(%20'adstxt_post',%20(int)%20$adstxt_id%20);%20}%20if%20(%20!%20$app_adstxt_id%20instanceof%20WP_Error%20)%20{%20update_option(%20'app_adstxt_post',%20(int)%20$app_adstxt_id%20);%20}%22}]}

Changelog Entry

Added - Support for the WordPress.org plugin preview

Credits

Props @dkotter

Checklist:

dkotter commented 11 months ago

One big thing to note here is that the WP Playground doesn't seem to support pretty permalinks yet (see https://github.com/WordPress/playground-tools/issues/53) which this plugin requires to fully work.

So right now you can see the settings page with sample content and can modify that content. But if you try and view the ads.txt file itself, it won't work. This may be a big enough issue that we don't want to enable previews yet but figured worth capturing the needed code for now.

jeffpaul commented 11 months ago

Perhaps that's still fine @dkotter as folks can at least see the interaction and revisions for ads/app-ads.txt files in the interim?