-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/78-placeholder-record
- Loading branch information
Showing
12 changed files
with
1,199 additions
and
3,318 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v20.11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"$schema": "https://playground.wordpress.net/blueprint-schema.json", | ||
"landingPage": "\/wp-admin\/options-general.php?page=adstxt-settings", | ||
"preferredVersions": { | ||
"php": "7.4", | ||
"wp": "latest" | ||
}, | ||
"phpExtensionBundles": ["kitchen-sink"], | ||
"steps": [ | ||
{ | ||
"step": "login", | ||
"username": "admin", | ||
"password": "password" | ||
}, | ||
{ | ||
"step": "setSiteOptions", | ||
"options": { | ||
"permalink_structure": "\/%25postname%25\/" | ||
} | ||
}, | ||
{ | ||
"step": "installPlugin", | ||
"pluginZipFile": { | ||
"resource": "wordpress.org\/plugins", | ||
"slug": "ads-txt" | ||
}, | ||
"options": { | ||
"activate": true | ||
} | ||
}, | ||
{ | ||
"step": "runPHP", | ||
"code": "<?php require_once 'wordpress\/wp-load.php'; $adstxt_id = wp_insert_post( array( 'post_title' => 'Ads.txt', 'post_content' => '# Example information\n[email protected]\n\n# Example record\ngoogle.com, pub-1234567890, DIRECT, f08c47fec0942fa0', 'post_status' => 'publish', 'post_type' => 'adstxt' ) ); $app_adstxt_id = wp_insert_post( array( 'post_title' => 'App-ads.txt', 'post_content' => '# Example information\n[email protected]\n\n# Example record\ngoogle.com, pub-1234567890, DIRECT, f08c47fec0942fa0', 'post_status' => 'publish', 'post_type' => 'app-adstxt' ) ); if ( ! $adstxt_id instanceof WP_Error ) { update_option( 'adstxt_post', (int) $adstxt_id ); } if ( ! $app_adstxt_id instanceof WP_Error ) { update_option( 'app_adstxt_post', (int) $app_adstxt_id ); }" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
/** | ||
* Helper functions for Ads.txt. | ||
* | ||
* @package Ads_Txt_Manager | ||
*/ | ||
|
||
namespace AdsTxt; | ||
|
||
/** | ||
* Display the contents of /ads.txt when requested. | ||
* | ||
* @return void | ||
*/ | ||
function display_ads_txt() { | ||
$request = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : false; | ||
if ( '/ads.txt' === $request || '/ads.txt?' === substr( $request, 0, 9 ) ) { | ||
$post_id = get_option( ADS_TXT_MANAGER_POST_OPTION ); | ||
|
||
// Set custom header for ads-txt | ||
header( 'X-Ads-Txt-Generator: https://wordpress.org/plugins/ads-txt/' ); | ||
|
||
// Will fall through if no option found, likely to a 404. | ||
if ( ! empty( $post_id ) ) { | ||
$post = get_post( $post_id ); | ||
|
||
if ( ! $post instanceof \WP_Post ) { | ||
return; | ||
} | ||
|
||
header( 'Content-Type: text/plain' ); | ||
$adstxt = $post->post_content; | ||
|
||
/** | ||
* Filter the ads.txt content. | ||
* | ||
* @since 1.2.0 | ||
* | ||
* @param type $adstxt The existing ads.txt content. | ||
*/ | ||
echo esc_html( apply_filters( 'ads_txt_content', $adstxt ) ); | ||
die(); | ||
} | ||
} elseif ( '/app-ads.txt' === $request || '/app-ads.txt?' === substr( $request, 0, 13 ) ) { | ||
$post_id = get_option( APP_ADS_TXT_MANAGER_POST_OPTION ); | ||
|
||
// Set custom header for ads-txt | ||
header( 'X-Ads-Txt-Generator: https://wordpress.org/plugins/ads-txt/' ); | ||
|
||
// Will fall through if no option found, likely to a 404. | ||
if ( ! empty( $post_id ) ) { | ||
$post = get_post( $post_id ); | ||
|
||
if ( ! $post instanceof \WP_Post ) { | ||
return; | ||
} | ||
|
||
header( 'Content-Type: text/plain' ); | ||
$adstxt = $post->post_content; | ||
|
||
/** | ||
* Filter the app-ads.txt content. | ||
* | ||
* @since 1.3.0 | ||
* | ||
* @param type $app_adstxt The existing ads.txt content. | ||
*/ | ||
echo esc_html( apply_filters( 'app_ads_txt_content', $adstxt ) ); | ||
die(); | ||
} | ||
} | ||
} | ||
add_action( 'init', __NAMESPACE__ . '\display_ads_txt' ); | ||
|
||
/** | ||
* Add custom capabilities. | ||
* | ||
* @return void | ||
*/ | ||
function add_capabilities() { | ||
$role = get_role( 'administrator' ); | ||
|
||
// Bail early if the administrator role doesn't exist. | ||
if ( null === $role ) { | ||
return; | ||
} | ||
|
||
if ( ! $role->has_cap( ADS_TXT_MANAGE_CAPABILITY ) ) { | ||
$role->add_cap( ADS_TXT_MANAGE_CAPABILITY ); | ||
} | ||
} | ||
add_action( 'admin_init', __NAMESPACE__ . '\add_capabilities' ); | ||
register_activation_hook( __FILE__, __NAMESPACE__ . '\add_capabilities' ); | ||
|
||
/** | ||
* Remove custom capabilities when deactivating the plugin. | ||
* | ||
* @return void | ||
*/ | ||
function remove_capabilities() { | ||
$role = get_role( 'administrator' ); | ||
|
||
// Bail early if the administrator role doesn't exist. | ||
if ( null === $role ) { | ||
return; | ||
} | ||
|
||
$role->remove_cap( ADS_TXT_MANAGE_CAPABILITY ); | ||
} | ||
register_deactivation_hook( __FILE__, __NAMESPACE__ . '\remove_capabilities' ); | ||
|
||
/** | ||
* Add a query var to detect when ads.txt has been saved. | ||
* | ||
* @param array $qvars Array of query vars. | ||
* | ||
* @return array Array of query vars. | ||
*/ | ||
function add_query_vars( $qvars ) { | ||
$qvars[] = 'ads_txt_saved'; | ||
return $qvars; | ||
} | ||
add_filter( 'query_vars', __NAMESPACE__ . '\add_query_vars' ); |
Oops, something went wrong.