Ads.txt Manager - Version 1.3.0

Version Description

  • Added: Support for app-ads.txt filetype (props @helen, @westi, @p0mmy)
  • Removed: Stop attempting to show an error notice about an existing ads.txt file due to too many false positives. We will bring this back later in a better way.
  • Changed: Bump WordPress version support to 5.4 (props @tmoorewp, @jeffpaul)
  • Changed: Switched to using GitHub Actions instead of Travis for Continuous Integration (props @helen)
  • Changed: Updated plugin screenshots and FAQs (props @jeffpaul, @helen)
  • Fixed: Update capability check when saving ads.txt (props @eclev91)
Download this release

Release Info

Developer 10upbot
Plugin Icon 128x128 Ads.txt Manager
Version 1.3.0
Comparing to
See all releases

Code changes from version 1.2.0 to 1.3.0

Files changed (6) hide show
  1. ads-txt.php +32 -2
  2. inc/admin.php +95 -23
  3. inc/post-type.php +46 -27
  4. inc/save.php +9 -3
  5. js/admin.js +0 -25
  6. readme.txt +28 -18
ads-txt.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Ads.txt Manager
4
  * Description: Create, manage, and validate your Ads.txt from within WordPress, just like any other content asset. Requires PHP 5.3+ and WordPress 4.9+.
5
- * Version: 1.2.0
6
  * Author: 10up
7
  * Author URI: https://10up.com
8
  * License: GPLv2 or later
@@ -15,9 +15,10 @@ if ( ! defined( 'ABSPATH' ) ) {
15
  exit; // Exit if accessed directly.
16
  }
17
 
18
- define( 'ADS_TXT_MANAGER_VERSION', '1.2.0' );
19
  define( 'ADS_TXT_MANAGE_CAPABILITY', 'edit_ads_txt' );
20
  define( 'ADS_TXT_MANAGER_POST_OPTION', 'adstxt_post' );
 
21
 
22
  require_once __DIR__ . '/inc/post-type.php';
23
  require_once __DIR__ . '/inc/admin.php';
@@ -36,6 +37,11 @@ function tenup_display_ads_txt() {
36
  // Will fall through if no option found, likely to a 404.
37
  if ( ! empty( $post_id ) ) {
38
  $post = get_post( $post_id );
 
 
 
 
 
39
  header( 'Content-Type: text/plain' );
40
  $adstxt = $post->post_content;
41
 
@@ -49,6 +55,30 @@ function tenup_display_ads_txt() {
49
  echo esc_html( apply_filters( 'ads_txt_content', $adstxt ) );
50
  die();
51
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  }
53
  }
54
  add_action( 'init', 'tenup_display_ads_txt' );
2
  /**
3
  * Plugin Name: Ads.txt Manager
4
  * Description: Create, manage, and validate your Ads.txt from within WordPress, just like any other content asset. Requires PHP 5.3+ and WordPress 4.9+.
5
+ * Version: 1.3.0
6
  * Author: 10up
7
  * Author URI: https://10up.com
8
  * License: GPLv2 or later
15
  exit; // Exit if accessed directly.
16
  }
17
 
18
+ define( 'ADS_TXT_MANAGER_VERSION', '1.3.0' );
19
  define( 'ADS_TXT_MANAGE_CAPABILITY', 'edit_ads_txt' );
20
  define( 'ADS_TXT_MANAGER_POST_OPTION', 'adstxt_post' );
21
+ define( 'APP_ADS_TXT_MANAGER_POST_OPTION', 'app_adstxt_post' );
22
 
23
  require_once __DIR__ . '/inc/post-type.php';
24
  require_once __DIR__ . '/inc/admin.php';
37
  // Will fall through if no option found, likely to a 404.
38
  if ( ! empty( $post_id ) ) {
39
  $post = get_post( $post_id );
40
+
41
+ if ( ! $post instanceof WP_Post ) {
42
+ return;
43
+ }
44
+
45
  header( 'Content-Type: text/plain' );
46
  $adstxt = $post->post_content;
47
 
55
  echo esc_html( apply_filters( 'ads_txt_content', $adstxt ) );
56
  die();
57
  }
58
+ } elseif ( '/app-ads.txt' === $request ) {
59
+ $post_id = get_option( APP_ADS_TXT_MANAGER_POST_OPTION );
60
+
61
+ // Will fall through if no option found, likely to a 404.
62
+ if ( ! empty( $post_id ) ) {
63
+ $post = get_post( $post_id );
64
+
65
+ if ( ! $post instanceof WP_Post ) {
66
+ return;
67
+ }
68
+
69
+ header( 'Content-Type: text/plain' );
70
+ $adstxt = $post->post_content;
71
+
72
+ /**
73
+ * Filter the app-ads.txt content.
74
+ *
75
+ * @since 1.3.0
76
+ *
77
+ * @param type $app_adstxt The existing ads.txt content.
78
+ */
79
+ echo esc_html( apply_filters( 'app_ads_txt_content', $adstxt ) );
80
+ die();
81
+ }
82
  }
83
  }
84
  add_action( 'init', 'tenup_display_ads_txt' );
inc/admin.php CHANGED
@@ -15,7 +15,7 @@ namespace AdsTxt;
15
  * @return void
16
  */
17
  function admin_enqueue_scripts( $hook ) {
18
- if ( 'settings_page_adstxt-settings' !== $hook ) {
19
  return;
20
  }
21
 
@@ -39,6 +39,10 @@ function admin_enqueue_scripts( $hook ) {
39
  'unknown_error' => esc_html__( 'An unknown error occurred.', 'ads-txt' ),
40
  );
41
 
 
 
 
 
42
  wp_localize_script( 'adstxt', 'adstxt', $strings );
43
  }
44
  add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\admin_enqueue_scripts' );
@@ -64,6 +68,7 @@ function admin_head_css() {
64
  <?php
65
  }
66
  add_action( 'admin_head-settings_page_adstxt-settings', __NAMESPACE__ . '\admin_head_css' );
 
67
 
68
  /**
69
  * Appends a query argument to the edit url to make sure it is redirected to
@@ -75,13 +80,19 @@ add_action( 'admin_head-settings_page_adstxt-settings', __NAMESPACE__ . '\admin_
75
  * @return string Edit url.
76
  */
77
  function ads_txt_adjust_revisions_return_to_editor_link( $url ) {
78
- global $pagenow;
79
 
80
  if ( 'revision.php' !== $pagenow || ! isset( $_REQUEST['adstxt'] ) ) { // @codingStandardsIgnoreLine Nonce not required.
81
  return $url;
82
  }
83
 
84
- return admin_url( 'options-general.php?page=adstxt-settings' );
 
 
 
 
 
 
85
  }
86
  add_filter( 'get_edit_post_link', __NAMESPACE__ . '\ads_txt_adjust_revisions_return_to_editor_link' );
87
 
@@ -147,18 +158,81 @@ function admin_menu() {
147
  esc_html__( 'Ads.txt', 'ads-txt' ),
148
  ADS_TXT_MANAGE_CAPABILITY,
149
  'adstxt-settings',
150
- __NAMESPACE__ . '\settings_screen'
 
 
 
 
 
 
 
 
151
  );
152
  }
153
  add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' );
154
 
155
  /**
156
- * Output the settings screen.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  *
158
  * @return void
159
  */
160
- function settings_screen() {
161
- $post_id = get_option( ADS_TXT_MANAGER_POST_OPTION );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  $post = false;
163
  $content = false;
164
  $errors = [];
@@ -182,29 +256,22 @@ function settings_screen() {
182
 
183
  // Create an initial post so the second save creates a comparable revision.
184
  $postarr = array(
185
- 'post_title' => 'Ads.txt',
186
  'post_content' => '',
187
- 'post_type' => 'adstxt',
188
  'post_status' => 'publish',
189
  );
190
 
191
  $post_id = wp_insert_post( $postarr );
192
  if ( $post_id ) {
193
- update_option( ADS_TXT_MANAGER_POST_OPTION, $post_id );
194
  }
195
  }
196
  ?>
197
  <div class="wrap">
198
- <div class="notice notice-error adstxt-notice existing-adstxt" style="display: none;">
199
- <p><strong><?php echo esc_html_e( 'Existing Ads.txt file found', 'ads-txt' ); ?></strong></p>
200
- <p><?php echo esc_html_e( 'An ads.txt file on the server will take precedence over any content entered here. You will need to rename or remove the existing ads.txt file before you will be able to see any changes you make on this screen.', 'ads-txt' ); ?></p>
201
-
202
- <p><?php echo esc_html_e( 'Removed the existing file but are still seeing this warning?', 'ads-txt' ); ?> <a class="ads-txt-rerun-check" href="#"><?php echo esc_html_e( 'Re-run the check now', 'ads-txt' ); ?></a> <span class="spinner" style="float:none;margin:-2px 5px 0"></span></p>
203
- </div>
204
-
205
  <?php if ( ! empty( $errors ) ) : ?>
206
  <div class="notice notice-error adstxt-notice">
207
- <p><strong><?php echo esc_html__( 'Your Ads.txt contains the following issues:', 'ads-txt' ); ?></strong></p>
208
  <ul>
209
  <?php
210
  foreach ( $errors as $error ) {
@@ -232,14 +299,15 @@ function settings_screen() {
232
  </div>
233
  <?php endif; ?>
234
 
235
- <h2><?php echo esc_html__( 'Manage Ads.txt', 'ads-txt' ); ?></h2>
236
 
237
  <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" class="adstxt-settings-form">
238
  <input type="hidden" name="post_id" value="<?php echo esc_attr( $post_id ) ? esc_attr( $post_id ) : ''; ?>" />
239
- <input type="hidden" name="action" value="adstxt-save" />
 
240
  <?php wp_nonce_field( 'adstxt_save' ); ?>
241
 
242
- <label class="screen-reader-text" for="adstxt_content"><?php echo esc_html__( 'Ads.txt content', 'ads-txt' ); ?></label>
243
  <textarea class="widefat code" rows="25" name="adstxt" id="adstxt_content"><?php echo esc_textarea( $content ); ?></textarea>
244
  <?php
245
  if ( $revision_count > 1 ) {
@@ -378,14 +446,18 @@ function get_error_messages() {
378
  * @return void
379
  */
380
  function admin_notices() {
381
- if ( 'settings_page_adstxt-settings' !== get_current_screen()->base ) {
 
 
 
 
382
  return;
383
  }
384
 
385
  if ( isset( $_GET['ads_txt_saved'] ) ) : // @codingStandardsIgnoreLine Nonce not required.
386
  ?>
387
  <div class="notice notice-success adstxt-notice adstxt-saved">
388
- <p><?php echo esc_html__( 'Ads.txt saved', 'ads-txt' ); ?></p>
389
  </div>
390
  <?php
391
  elseif ( isset( $_GET['revision'] ) ) : // @codingStandardsIgnoreLine Nonce not required.
15
  * @return void
16
  */
17
  function admin_enqueue_scripts( $hook ) {
18
+ if ( ! preg_match( '/adstxt-settings$/', $hook ) ) {
19
  return;
20
  }
21
 
39
  'unknown_error' => esc_html__( 'An unknown error occurred.', 'ads-txt' ),
40
  );
41
 
42
+ if ( 'settings_page_app-adstxt-settings' === $hook ) {
43
+ $strings['error_message'] = esc_html__( 'Your app-ads.txt contains the following issues:', 'ads-txt' );
44
+ }
45
+
46
  wp_localize_script( 'adstxt', 'adstxt', $strings );
47
  }
48
  add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\admin_enqueue_scripts' );
68
  <?php
69
  }
70
  add_action( 'admin_head-settings_page_adstxt-settings', __NAMESPACE__ . '\admin_head_css' );
71
+ add_action( 'admin_head-settings_page_app-adstxt-settings', __NAMESPACE__ . '\admin_head_css' );
72
 
73
  /**
74
  * Appends a query argument to the edit url to make sure it is redirected to
80
  * @return string Edit url.
81
  */
82
  function ads_txt_adjust_revisions_return_to_editor_link( $url ) {
83
+ global $pagenow, $post;
84
 
85
  if ( 'revision.php' !== $pagenow || ! isset( $_REQUEST['adstxt'] ) ) { // @codingStandardsIgnoreLine Nonce not required.
86
  return $url;
87
  }
88
 
89
+ $type = 'adstxt';
90
+
91
+ if ( 'app-adstxt' === $post->post_type ) {
92
+ $type = 'app-adstxt';
93
+ }
94
+
95
+ return admin_url( 'options-general.php?page=' . $type . '-settings' );
96
  }
97
  add_filter( 'get_edit_post_link', __NAMESPACE__ . '\ads_txt_adjust_revisions_return_to_editor_link' );
98
 
158
  esc_html__( 'Ads.txt', 'ads-txt' ),
159
  ADS_TXT_MANAGE_CAPABILITY,
160
  'adstxt-settings',
161
+ __NAMESPACE__ . '\adstxt_settings_screen'
162
+ );
163
+
164
+ add_options_page(
165
+ esc_html__( 'App-ads.txt', 'ads-txt' ),
166
+ esc_html__( 'App-ads.txt', 'ads-txt' ),
167
+ ADS_TXT_MANAGE_CAPABILITY,
168
+ 'app-adstxt-settings',
169
+ __NAMESPACE__ . '\app_adstxt_settings_screen'
170
  );
171
  }
172
  add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' );
173
 
174
  /**
175
+ * Set up settings screen for ads.txt.
176
+ *
177
+ * @return void
178
+ */
179
+ function adstxt_settings_screen() {
180
+ $post_id = get_option( ADS_TXT_MANAGER_POST_OPTION );
181
+
182
+ $strings = array(
183
+ 'existing' => __( 'Existing Ads.txt file found', 'ads-txt' ),
184
+ 'precedence' => __( 'An ads.txt file on the server will take precedence over any content entered here. You will need to rename or remove the existing ads.txt file before you will be able to see any changes you make on this screen.', 'ads-txt' ),
185
+ 'errors' => __( 'Your Ads.txt contains the following issues:', 'ads-txt' ),
186
+ 'screen_title' => __( 'Manage Ads.txt', 'ads-txt' ),
187
+ 'content_label' => __( 'Ads.txt content', 'ads-txt' ),
188
+ );
189
+
190
+ $args = array(
191
+ 'post_type' => 'adstxt',
192
+ 'post_title' => 'Ads.txt',
193
+ 'option' => ADS_TXT_MANAGER_POST_OPTION,
194
+ 'action' => 'adstxt-save',
195
+ );
196
+
197
+ settings_screen( $post_id, $strings, $args );
198
+ }
199
+
200
+ /**
201
+ * Set up settings screen for app-ads.txt.
202
  *
203
  * @return void
204
  */
205
+ function app_adstxt_settings_screen() {
206
+ $post_id = get_option( APP_ADS_TXT_MANAGER_POST_OPTION );
207
+
208
+ $strings = array(
209
+ 'existing' => __( 'Existing App-ads.txt file found', 'ads-txt' ),
210
+ 'precedence' => __( 'An app-ads.txt file on the server will take precedence over any content entered here. You will need to rename or remove the existing app-ads.txt file before you will be able to see any changes you make on this screen.', 'ads-txt' ),
211
+ 'errors' => __( 'Your app-ads.txt contains the following issues:', 'ads-txt' ),
212
+ 'screen_title' => __( 'Manage App-ads.txt', 'ads-txt' ),
213
+ 'content_label' => __( 'App-ads.txt content', 'ads-txt' ),
214
+ );
215
+
216
+ $args = array(
217
+ 'post_type' => 'app-adstxt',
218
+ 'post_title' => 'App-ads.txt',
219
+ 'option' => APP_ADS_TXT_MANAGER_POST_OPTION,
220
+ 'action' => 'app-adstxt-save',
221
+ );
222
+
223
+ settings_screen( $post_id, $strings, $args );
224
+ }
225
+
226
+ /**
227
+ * Output the settings screen for both files.
228
+ *
229
+ * @param int $post_id Post ID associated with the file.
230
+ * @param array $strings Translated strings that mention the specific file name.
231
+ * @param array $args Array of other necessary information to appropriately name items.
232
+ *
233
+ * @return void
234
+ */
235
+ function settings_screen( $post_id, $strings, $args ) {
236
  $post = false;
237
  $content = false;
238
  $errors = [];
256
 
257
  // Create an initial post so the second save creates a comparable revision.
258
  $postarr = array(
259
+ 'post_title' => $args['post_title'],
260
  'post_content' => '',
261
+ 'post_type' => $args['post_type'],
262
  'post_status' => 'publish',
263
  );
264
 
265
  $post_id = wp_insert_post( $postarr );
266
  if ( $post_id ) {
267
+ update_option( $args['option'], $post_id );
268
  }
269
  }
270
  ?>
271
  <div class="wrap">
 
 
 
 
 
 
 
272
  <?php if ( ! empty( $errors ) ) : ?>
273
  <div class="notice notice-error adstxt-notice">
274
+ <p><strong><?php echo esc_html( $strings['errors'] ); ?></strong></p>
275
  <ul>
276
  <?php
277
  foreach ( $errors as $error ) {
299
  </div>
300
  <?php endif; ?>
301
 
302
+ <h2><?php echo esc_html( $strings['screen_title'] ); ?></h2>
303
 
304
  <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" class="adstxt-settings-form">
305
  <input type="hidden" name="post_id" value="<?php echo esc_attr( $post_id ) ? esc_attr( $post_id ) : ''; ?>" />
306
+ <input type="hidden" name="adstxt_type" value="<?php echo esc_attr( $args['post_type'] ); ?>" />
307
+ <input type="hidden" name="action" value="<?php echo esc_attr( $args['action'] ); ?>" />
308
  <?php wp_nonce_field( 'adstxt_save' ); ?>
309
 
310
+ <label class="screen-reader-text" for="adstxt_content"><?php echo esc_html( $strings['content_label'] ); ?></label>
311
  <textarea class="widefat code" rows="25" name="adstxt" id="adstxt_content"><?php echo esc_textarea( $content ); ?></textarea>
312
  <?php
313
  if ( $revision_count > 1 ) {
446
  * @return void
447
  */
448
  function admin_notices() {
449
+ if ( 'settings_page_adstxt-settings' === get_current_screen()->base ) {
450
+ $saved = __( 'Ads.txt saved', 'ads-txt' );
451
+ } elseif ( 'settings_page_app-adstxt-settings' === get_current_screen()->base ) {
452
+ $saved = __( 'App-ads.txt saved', 'ads-txt' );
453
+ } else {
454
  return;
455
  }
456
 
457
  if ( isset( $_GET['ads_txt_saved'] ) ) : // @codingStandardsIgnoreLine Nonce not required.
458
  ?>
459
  <div class="notice notice-success adstxt-notice adstxt-saved">
460
+ <p><?php echo esc_html( $saved ); ?></p>
461
  </div>
462
  <?php
463
  elseif ( isset( $_GET['revision'] ) ) : // @codingStandardsIgnoreLine Nonce not required.
inc/post-type.php CHANGED
@@ -13,37 +13,56 @@ namespace Adstxt;
13
  * @return void
14
  */
15
  function register() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  register_post_type(
17
  'adstxt',
18
- array(
19
- 'labels' => array(
20
- 'name' => esc_html_x( 'Ads.txt', 'post type general name', 'ads-txt' ),
21
- 'singular_name' => esc_html_x( 'Ads.txt', 'post type singular name', 'ads-txt' ),
 
 
22
  ),
23
- 'public' => false,
24
- 'hierarchical' => false,
25
- 'rewrite' => false,
26
- 'query_var' => false,
27
- 'delete_with_user' => false,
28
- 'supports' => array( 'revisions' ),
29
- 'map_meta_cap' => true,
30
- 'capabilities' => array(
31
- 'create_posts' => 'customize',
32
- 'delete_others_posts' => 'customize',
33
- 'delete_post' => 'customize',
34
- 'delete_posts' => 'customize',
35
- 'delete_private_posts' => 'customize',
36
- 'delete_published_posts' => 'customize',
37
- 'edit_others_posts' => 'customize',
38
- 'edit_post' => 'customize',
39
- 'edit_posts' => 'customize',
40
- 'edit_private_posts' => 'customize',
41
- 'edit_published_posts' => 'edit_published_posts',
42
- 'publish_posts' => 'customize',
43
- 'read' => 'read',
44
- 'read_post' => 'customize',
45
- 'read_private_posts' => 'customize',
46
  ),
 
47
  )
48
  );
49
  }
13
  * @return void
14
  */
15
  function register() {
16
+ $args = array(
17
+ 'public' => false,
18
+ 'hierarchical' => false,
19
+ 'rewrite' => false,
20
+ 'query_var' => false,
21
+ 'delete_with_user' => false,
22
+ 'supports' => array( 'revisions' ),
23
+ 'map_meta_cap' => true,
24
+ 'capabilities' => array(
25
+ 'create_posts' => 'customize',
26
+ 'delete_others_posts' => 'customize',
27
+ 'delete_post' => 'customize',
28
+ 'delete_posts' => 'customize',
29
+ 'delete_private_posts' => 'customize',
30
+ 'delete_published_posts' => 'customize',
31
+ 'edit_others_posts' => 'customize',
32
+ 'edit_post' => 'customize',
33
+ 'edit_posts' => 'customize',
34
+ 'edit_private_posts' => 'customize',
35
+ 'edit_published_posts' => 'edit_published_posts',
36
+ 'publish_posts' => 'customize',
37
+ 'read' => 'read',
38
+ 'read_post' => 'customize',
39
+ 'read_private_posts' => 'customize',
40
+ ),
41
+ );
42
+
43
  register_post_type(
44
  'adstxt',
45
+ array_merge(
46
+ array(
47
+ 'labels' => array(
48
+ 'name' => esc_html_x( 'Ads.txt', 'post type general name', 'ads-txt' ),
49
+ 'singular_name' => esc_html_x( 'Ads.txt', 'post type singular name', 'ads-txt' ),
50
+ ),
51
  ),
52
+ $args
53
+ )
54
+ );
55
+
56
+ register_post_type(
57
+ 'app-adstxt',
58
+ array_merge(
59
+ array(
60
+ 'labels' => array(
61
+ 'name' => esc_html_x( 'App-ads.txt', 'post type general name', 'ads-txt' ),
62
+ 'singular_name' => esc_html_x( 'App-ads.txt', 'post type singular name', 'ads-txt' ),
63
+ ),
 
 
 
 
 
 
 
 
 
 
 
64
  ),
65
+ $args
66
  )
67
  );
68
  }
inc/save.php CHANGED
@@ -16,7 +16,7 @@ namespace Adstxt;
16
  * @return void
17
  */
18
  function save() {
19
- current_user_can( 'customize' ) || die;
20
  check_admin_referer( 'adstxt_save' );
21
  $_post = stripslashes_deep( $_POST );
22
  $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
@@ -41,8 +41,7 @@ function save() {
41
  }
42
 
43
  $sanitized = implode( PHP_EOL, $sanitized );
44
-
45
- $postarr = array(
46
  'ID' => $post_id,
47
  'post_title' => 'Ads.txt',
48
  'post_content' => $sanitized,
@@ -53,6 +52,11 @@ function save() {
53
  ),
54
  );
55
 
 
 
 
 
 
56
  if ( ! $doing_ajax || empty( $errors ) || 'y' === $ays ) {
57
  $post_id = wp_insert_post( $postarr );
58
 
@@ -76,7 +80,9 @@ function save() {
76
  exit;
77
  }
78
  add_action( 'admin_post_adstxt-save', __NAMESPACE__ . '\save' );
 
79
  add_action( 'wp_ajax_adstxt-save', __NAMESPACE__ . '\save' );
 
80
 
81
  /**
82
  * Validate a single line.
16
  * @return void
17
  */
18
  function save() {
19
+ current_user_can( ADS_TXT_MANAGE_CAPABILITY ) || die;
20
  check_admin_referer( 'adstxt_save' );
21
  $_post = stripslashes_deep( $_POST );
22
  $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
41
  }
42
 
43
  $sanitized = implode( PHP_EOL, $sanitized );
44
+ $postarr = array(
 
45
  'ID' => $post_id,
46
  'post_title' => 'Ads.txt',
47
  'post_content' => $sanitized,
52
  ),
53
  );
54
 
55
+ if ( 'app-adstxt' === $_post['adstxt_type'] ) {
56
+ $postarr['post_title'] = 'App-ads.txt';
57
+ $postarr['post_type'] = 'app-adstxt';
58
+ }
59
+
60
  if ( ! $doing_ajax || empty( $errors ) || 'y' === $ays ) {
61
  $post_id = wp_insert_post( $postarr );
62
 
80
  exit;
81
  }
82
  add_action( 'admin_post_adstxt-save', __NAMESPACE__ . '\save' );
83
+ add_action( 'admin_post_app-adstxt-save', __NAMESPACE__ . '\save' );
84
  add_action( 'wp_ajax_adstxt-save', __NAMESPACE__ . '\save' );
85
+ add_action( 'wp_ajax_app-adstxt-save', __NAMESPACE__ . '\save' );
86
 
87
  /**
88
  * Validate a single line.
js/admin.js CHANGED
@@ -7,31 +7,6 @@
7
  mode: 'shell'
8
  } );
9
 
10
- function checkForAdsFile( e ){
11
- var currentTime = Date.now(),
12
- adstxtUrl = '/ads.txt?currentTime=' + currentTime,
13
- spinner = $( '.existing-adstxt .spinner' );
14
-
15
- if ( false !== e ) {
16
- e.preventDefault();
17
- }
18
-
19
- spinner.addClass( 'is-active' );
20
-
21
- $.get( adstxtUrl, function( data, status ){
22
- spinner.removeClass( 'is-active' );
23
- $( '.existing-adstxt' ).show();
24
- } ).fail( function() {
25
- // Ads.txt not found
26
- $( '.existing-adstxt' ).hide();
27
- });
28
- }
29
-
30
- // Call our check when we first load the page
31
- checkForAdsFile( false );
32
-
33
- $( '.ads-txt-rerun-check' ).on( 'click', checkForAdsFile );
34
-
35
  submit.on( 'click', function( e ){
36
  e.preventDefault();
37
 
7
  mode: 'shell'
8
  } );
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  submit.on( 'click', function( e ){
11
  e.preventDefault();
12
 
readme.txt CHANGED
@@ -4,18 +4,18 @@ Author URI: https://10up.com
4
  Plugin URI: https://github.com/10up/ads-txt
5
  Tags: ads.txt, ads, ad manager, advertising, publishing, publishers
6
  Requires at least: 4.9
7
- Tested up to: 5.3
8
  Requires PHP: 5.3
9
- Stable tag: 1.2.0
10
  License: GPLv2 or later
11
  License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12
  Text Domain: ads-txt
13
 
14
- Create, manage, and validate your ads.txt from within WordPress, just like any other content asset. Requires PHP 5.3+ and WordPress 4.9+.
15
 
16
  == Description ==
17
 
18
- Create, manage, and validate your ads.txt from within WordPress, just like any other content asset. Requires PHP 5.3+ and WordPress 4.9+.
19
 
20
  === What is ads.txt? ===
21
 
@@ -33,34 +33,44 @@ Ads.txt is an initiative by the Interactive Advertising Bureau to enable publish
33
 
34
  We're closely monitoring continued developments in the ad fraud space, and see this plugin as not only a way to create and manage your ads.txt file but also be prepared for future changes and upgrades to specifications. Ads.cert is still in the extremely early stages so we don't see any immediate concerns with implementing ads.txt.
35
 
36
- === What about app-ads.txt? ===
37
 
38
- We plan on adding support for this file in the future! If you'd like to follow along with development or even help us get it done, please see [this GitHub issue](https://github.com/10up/ads-txt/issues/40).
39
 
40
  == Screenshots ==
41
 
42
- 1. Example of editing an ads.txt file with errors
 
 
43
 
44
  == Installation ==
45
  1. Install the plugin via the plugin installer, either by searching for it or uploading a .zip file.
46
  2. Activate the plugin.
47
- 3. Head to Settings → Ads.txt and add the records you need.
48
- 4. Check it out at yoursite.com/ads.txt!
49
 
50
- Note: If you already have an existing ads.txt file in the web root, the plugin will not read in the contents of that file, and changes you make in WordPress admin will not overwrite contents of the physical file.
51
 
52
- You will need to rename or remove the existing ads.txt file (keeping a copy of the records it contains to put into the new settings screen) before you will be able to see any changes you make to ads.txt inside the WordPress admin.
53
 
54
  == Changelog ==
55
 
 
 
 
 
 
 
 
 
56
  = 1.2.0 =
57
- * **Added:** Make revisions accessible in the admin - now you can restore older versions of your ads.txt or view how it's changed over time (props [@adamsilverstein](https://github.com/adamsilverstein), [@helen](https://github.com/helen))
58
- * **Added:** Show a notice on the edit screen if an ads.txt file exists on the server (props [@kkoppenhaver](https://github.com/kkoppenhaver), [@helen](https://github.com/helen), [@tomjn](https://github.com/tomjn), [@adamsilverstein](https://github.com/adamsilverstein))
59
- * **Added:** Add a custom `edit_ads_txt` capability for granular assignment, which is assigned to administrators by default (props [@ethanclevenger91](https://github.com/ethanclevenger91), [@adamsilverstein](https://github.com/adamsilverstein))
60
- * **Added:** Enable filtering of the output using `ads_txt_content` (props [@ethanclevenger91](https://github.com/ethanclevenger91))
61
- * **Changed:** Updated documentation, automation, and coding standards (props [@jeffpaul](https://github.com/jeffpaul), [@adamsilverstein](https://github.com/adamsilverstein), [@helen](https://github.com/helen), [@mmcachran](https://github.com/mmcachran))
62
- * **Fixed:** Early escaping (props [@tomjn](https://github.com/tomjn))
63
- * **Fixed:** PHPCS issues and added PHPCS scanning (props [@adamsilverstein](https://github.com/adamsilverstein))
64
 
65
  = 1.1 =
66
  * Better error message formatting (wraps values in `<code>` tags for better readability)
4
  Plugin URI: https://github.com/10up/ads-txt
5
  Tags: ads.txt, ads, ad manager, advertising, publishing, publishers
6
  Requires at least: 4.9
7
+ Tested up to: 5.4
8
  Requires PHP: 5.3
9
+ Stable tag: 1.3.0
10
  License: GPLv2 or later
11
  License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12
  Text Domain: ads-txt
13
 
14
+ Create, manage, and validate your ads.txt and app-ads.txt from within WordPress, just like any other content asset. Requires PHP 5.3+ and WordPress 4.9+.
15
 
16
  == Description ==
17
 
18
+ Create, manage, and validate your ads.txt and app-ads.txt from within WordPress, just like any other content asset. Requires PHP 5.3+ and WordPress 4.9+.
19
 
20
  === What is ads.txt? ===
21
 
33
 
34
  We're closely monitoring continued developments in the ad fraud space, and see this plugin as not only a way to create and manage your ads.txt file but also be prepared for future changes and upgrades to specifications. Ads.cert is still in the extremely early stages so we don't see any immediate concerns with implementing ads.txt.
35
 
36
+ === Can I use this with multisite? ===
37
 
38
+ Yes! However, if you are using a subfolder installation it will only work for the main site. This is because you can only have one ads.txt for a given domain or subdomain per the [ads.txt spec](https://iabtechlab.com/ads-txt/). Our recommendation is to only activate Ads.txt Manager per-site.
39
 
40
  == Screenshots ==
41
 
42
+ 1. Example of editing an ads.txt file with errors and a link to browse ads.txt file revisions.
43
+ 2. Example of comparing ads.txt file revisions.
44
+ 3. Example of comparing two disparate ads.txt file revisions.
45
 
46
  == Installation ==
47
  1. Install the plugin via the plugin installer, either by searching for it or uploading a .zip file.
48
  2. Activate the plugin.
49
+ 3. Head to Settings → Ads.txt or App-ads.txt and add the records you need.
50
+ 4. Check it out at yoursite.com/ads.txt or yoursite.com/app-ads.txt!
51
 
52
+ Note: If you already have an existing ads.txt or app-ads.txt file in the web root, the plugin will not read in the contents of the respective files, and changes you make in WordPress admin will not overwrite contents of the physical files.
53
 
54
+ You will need to rename or remove the existing (app-)ads.txt file (keeping a copy of the records it contains to put into the new settings screen) before you will be able to see any changes you make to (app-)ads.txt inside the WordPress admin.
55
 
56
  == Changelog ==
57
 
58
+ = 1.3.0 =
59
+ * **Added:** Support for app-ads.txt filetype (props [@helen](https://profiles.wordpress.org/helen/), [@westi](https://profiles.wordpress.org/westi/), [@p0mmy](https://github.com/p0mmy))
60
+ * **Removed:** Stop attempting to show an error notice about an existing `ads.txt` file due to too many false positives. We will bring this back later in a better way.
61
+ * **Changed:** Bump WordPress version support to 5.4 (props [@tmoorewp](https://profiles.wordpress.org/tmoorewp/), [@jeffpaul](https://profiles.wordpress.org/jeffpaul/))
62
+ * **Changed:** Switched to using GitHub Actions instead of Travis for Continuous Integration (props [@helen](https://profiles.wordpress.org/helen/))
63
+ * **Changed:** Updated plugin screenshots and FAQs (props [@jeffpaul](https://profiles.wordpress.org/jeffpaul/), [@helen](https://profiles.wordpress.org/helen/))
64
+ * **Fixed:** Update capability check when saving ads.txt (props [@eclev91](https://profiles.wordpress.org/eclev91/))
65
+
66
  = 1.2.0 =
67
+ * **Added:** Make revisions accessible in the admin - now you can restore older versions of your ads.txt or view how it's changed over time (props [@adamsilverstein](https://profiles.wordpress.org/adamsilverstein/), [@helen](https://profiles.wordpress.org/helen/))
68
+ * **Added:** Show a notice on the edit screen if an ads.txt file exists on the server (props [@kkoppenhaver](https://profiles.wordpress.org/kkoppenhaver/), [@helen](https://profiles.wordpress.org/helen/), [@tjnowell](https://profiles.wordpress.org/tjnowell/), [@adamsilverstein](https://profiles.wordpress.org/adamsilverstein/))
69
+ * **Added:** Add a custom `edit_ads_txt` capability for granular assignment, which is assigned to administrators by default (props [@eclev91](https://profiles.wordpress.org/eclev91/), [@adamsilverstein](https://profiles.wordpress.org/adamsilverstein/))
70
+ * **Added:** Enable filtering of the output using `ads_txt_content` (props [@eclev91](https://profiles.wordpress.org/eclev91/))
71
+ * **Changed:** Updated documentation, automation, and coding standards (props [@jeffpaul](https://profiles.wordpress.org/jeffpaul/), [@adamsilverstein](https://profiles.wordpress.org/adamsilverstein/), [@helen](https://profiles.wordpress.org/helen/), [@mmcachran](https://profiles.wordpress.org/mmcachran/))
72
+ * **Fixed:** Early escaping (props [@tjnowell](https://profiles.wordpress.org/tjnowell/))
73
+ * **Fixed:** PHPCS issues and added PHPCS scanning (props [@adamsilverstein](https://profiles.wordpress.org/adamsilverstein/))
74
 
75
  = 1.1 =
76
  * Better error message formatting (wraps values in `<code>` tags for better readability)