File manager - Edit - /home/dubair8/saluempire.com/inc.tar
Back
post-type.php 0000755 00000003402 15111573732 0007230 0 ustar 00 <?php /** * Post Type functionality for Ads.txt. * * @package Ads_Txt_Manager */ namespace Adstxt; /** * Register the `adstxt` custom post type. * * @return void */ function register() { $args = array( 'public' => false, 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'delete_with_user' => false, 'supports' => array( 'revisions' ), 'map_meta_cap' => true, 'capabilities' => array( 'create_posts' => 'customize', 'delete_others_posts' => 'customize', 'delete_post' => 'customize', 'delete_posts' => 'customize', 'delete_private_posts' => 'customize', 'delete_published_posts' => 'customize', 'edit_others_posts' => 'edit_others_posts', 'edit_post' => 'customize', 'edit_posts' => 'customize', 'edit_private_posts' => 'customize', 'edit_published_posts' => 'edit_published_posts', 'publish_posts' => 'customize', 'read' => 'read', 'read_post' => 'customize', 'read_private_posts' => 'customize', ), ); register_post_type( 'adstxt', array_merge( array( 'labels' => array( 'name' => esc_html_x( 'Ads.txt', 'post type general name', 'ads-txt' ), 'singular_name' => esc_html_x( 'Ads.txt', 'post type singular name', 'ads-txt' ), ), ), $args ) ); register_post_type( 'app-adstxt', array_merge( array( 'labels' => array( 'name' => esc_html_x( 'App-ads.txt', 'post type general name', 'ads-txt' ), 'singular_name' => esc_html_x( 'App-ads.txt', 'post type singular name', 'ads-txt' ), ), ), $args ) ); } add_action( 'init', __NAMESPACE__ . '\register' ); helpers.php 0000755 00000005674 15111573732 0006743 0 ustar 00 <?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' ); save.php 0000755 00000022635 15111573732 0006233 0 ustar 00 <?php /** * Save functionality for Ads.txt. * * @package Ads_Txt_Manager */ namespace Adstxt; /** * Process and save the ads.txt data. * * Handles both AJAX and POST saves via `admin-ajax.php` and `admin-post.php` respectively. * AJAX calls output JSON; POST calls redirect back to the Ads.txt edit screen. * * @return void */ function save() { current_user_can( ADS_TXT_MANAGE_CAPABILITY ) || die; check_admin_referer( 'adstxt_save' ); $_post = stripslashes_deep( $_POST ); $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; $post_id = (int) $_post['post_id']; $ays = isset( $_post['adstxt_ays'] ) ? $_post['adstxt_ays'] : null; // Different browsers use different line endings. $lines = preg_split( '/\r\n|\r|\n/', $_post['adstxt'] ); $sanitized = array(); $errors = array(); $warnings = array(); $response = array(); $has_only_placeholder_records = null; foreach ( $lines as $i => $line ) { $line_number = $i + 1; $result = validate_line( $line, $line_number, $has_only_placeholder_records ); $sanitized[] = $result['sanitized']; if ( ! empty( $result['errors'] ) ) { $errors = array_merge( $errors, $result['errors'] ); } if ( ! empty( $result['warnings'] ) ) { $warnings = array_merge( $warnings, $result['warnings'] ); } if ( ! empty( $result['is_placeholder_record'] ) ) { if ( is_null( $has_only_placeholder_records ) ) { $has_only_placeholder_records = true; } } list( 'errors' => $errors_data, 'warnings' => $warnings_data, 'is_placeholder_record' => $is_placeholder, 'is_empty_record' => $is_empty_line, 'is_comment' => $is_comment ) = $result; // Check if the line is valid, then set $has_only_placeholder_records to false. if ( empty( $is_placeholder ) && empty( $errors_data ) && empty( $warnings_data ) && ( ! $is_comment && ! $is_empty_line ) ) { $has_only_placeholder_records = false; } } // If $has_only_placeholder_records is false, remove no_authorized_seller warning. if ( false === $has_only_placeholder_records ) { $key = array_search( 'no_authorized_seller', array_column( $warnings, 'type' ) ); if ( false !== $key ) { unset( $warnings[ $key ] ); } } $sanitized = implode( PHP_EOL, $sanitized ); $postarr = array( 'ID' => $post_id, 'post_title' => 'Ads.txt', 'post_content' => $sanitized, 'post_type' => 'adstxt', 'post_status' => 'publish', 'meta_input' => array( 'adstxt_errors' => $errors, 'adstxt_warnings' => $warnings, ), ); if ( 'app-adstxt' === $_post['adstxt_type'] ) { $postarr['post_title'] = 'App-ads.txt'; $postarr['post_type'] = 'app-adstxt'; } if ( ! $doing_ajax || empty( $errors ) || 'y' === $ays ) { $post_id = wp_insert_post( $postarr ); if ( $post_id ) { $response['saved'] = true; } } if ( $doing_ajax ) { $response['sanitized'] = $sanitized; if ( ! empty( $errors ) ) { $response['errors'] = $errors; } echo wp_json_encode( $response ); die(); } wp_safe_redirect( esc_url_raw( $_post['_wp_http_referer'] ) . '&updated=true' ); exit; } add_action( 'admin_post_adstxt-save', __NAMESPACE__ . '\save' ); add_action( 'admin_post_app-adstxt-save', __NAMESPACE__ . '\save' ); add_action( 'wp_ajax_adstxt-save', __NAMESPACE__ . '\save' ); add_action( 'wp_ajax_app-adstxt-save', __NAMESPACE__ . '\save' ); /** * Validate a single line. * * @param string $line The line to validate. * @param string $line_number The line number being evaluated. * @param string $has_only_placeholder_records Flag for presence of placeholder record. * * @return array { * @type string $sanitized Sanitized version of the original line. * @type array $errors Array of errors associated with the line. * } */ function validate_line( $line, $line_number, $has_only_placeholder_records = null ) { static $record_lines = 0; $is_placeholder_record = false; $is_empty_record = false; $is_comment = false; // Only to count for records, not comments/variables. $domain_regex = '/^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}$/i'; $errors = array(); $warnings = array(); if ( empty( $line ) ) { $sanitized = ''; $is_empty_record = true; } elseif ( 0 === strpos( $line, '#' ) ) { // This is a full-line comment. $sanitized = wp_strip_all_tags( $line ); $is_comment = true; } elseif ( 1 < strpos( $line, '=' ) ) { // This is a variable declaration. // The spec currently supports CONTACT, INVENTORYPARTNERDOMAIN, SUBDOMAIN, OWNERDOMAIN and MANAGERDOMAIN. if ( ! preg_match( '/^(CONTACT|SUBDOMAIN|INVENTORYPARTNERDOMAIN|OWNERDOMAIN|MANAGERDOMAIN)=/i', $line ) ) { $errors[] = array( 'line' => $line_number, 'type' => 'invalid_variable', ); } elseif ( 0 === stripos( $line, 'subdomain=' ) ) { // Subdomains should be, well, subdomains. // Disregard any comments. $subdomain = explode( '#', $line ); $subdomain = $subdomain[0]; $subdomain = explode( '=', $subdomain ); array_shift( $subdomain ); // If there's anything other than one piece left something's not right. if ( 1 !== count( $subdomain ) || ! preg_match( $domain_regex, $subdomain[0] ) ) { $subdomain = implode( '', $subdomain ); $errors[] = array( 'line' => $line_number, 'type' => 'invalid_subdomain', 'value' => $subdomain, ); } } $sanitized = wp_strip_all_tags( $line ); unset( $subdomain ); } else { // Data records: the most common. // Disregard any comments. $record = explode( '#', $line ); $record = $record[0]; // Record format: example.exchange.com,pub-id123456789,RESELLER|DIRECT,tagidhash123(optional). $fields = explode( ',', $record ); if ( 3 <= count( $fields ) ) { ++$record_lines; $exchange = trim( $fields[0] ); $pub_id = trim( $fields[1] ); $account_type = trim( $fields[2] ); $tag_id = ! empty( $fields[3] ) ? trim( $fields[3] ) : null; $is_placeholder_record = is_placeholder_record( $exchange, $pub_id, $account_type, $tag_id ); // If the file contains placeholder record and no placeholder was already present, set variable. if ( $is_placeholder_record && is_null( $has_only_placeholder_records ) ) { $warnings[] = array( 'type' => 'no_authorized_seller', 'message' => __( 'Your ads.txt indicates no authorized advertising sellers.', 'ads-txt' ), ); } // Process further only if the current record is not placeholder record. if ( ! $is_placeholder_record ) { if ( ! preg_match( $domain_regex, $exchange ) ) { $errors[] = array( 'line' => $line_number, 'type' => 'invalid_exchange', 'value' => $exchange, ); } if ( ! preg_match( '/^(RESELLER|DIRECT)$/i', $account_type ) ) { $errors[] = array( 'line' => $line_number, 'type' => 'invalid_account_type', ); } if ( isset( $fields[3] ) ) { $tag_id = trim( $fields[3] ); // TAG-IDs appear to be 16 character hashes. // TAG-IDs are meant to be checked against their DB - perhaps good for a service or the future. if ( ! empty( $tag_id ) && ! preg_match( '/^[a-f0-9]{16}$/', $tag_id ) ) { $errors[] = array( 'line' => $line_number, 'type' => 'invalid_tagid', 'value' => $fields[3], ); } } } $sanitized = wp_strip_all_tags( $line ); } else { // Not a comment, variable declaration, or data record; therefore, invalid. // Early on we commented the line out for safety but it's kind of a weird thing to do with a JS AYS. $sanitized = wp_strip_all_tags( $line ); $errors[] = array( 'line' => $line_number, 'type' => 'invalid_record', ); } unset( $record, $fields ); } return array( 'sanitized' => $sanitized, 'errors' => $errors, 'warnings' => $warnings, 'is_placeholder_record' => $is_placeholder_record, 'is_empty_record' => $is_empty_record, 'is_comment' => $is_comment, ); } /** * Delete `adstxt_errors` meta when restoring a revision. * * @param int $post_id Post ID, not revision ID. * * @return void */ function clear_error_meta( $post_id ) { delete_post_meta( $post_id, 'adstxt_errors' ); } add_action( 'wp_restore_post_revision', __NAMESPACE__ . '\clear_error_meta', 10, 1 ); /** * Checks if the given record is placeholder record. * Placeholder indicates that no advertising system is authorized to buy and sell ads on the website. * * @see https://iabtechlab.com/wp-content/uploads/2021/03/ads.txt-1.0.3.pdf * * @param string $exchange Domain name of the advertising system. * @param string $pub_id Publisher’s Account ID. * @param string $account_type Type of Account/Relationship. * @param string|null $tag_id Certification Authority ID. * * @return bool */ function is_placeholder_record( $exchange, $pub_id, $account_type, $tag_id = null ) { $result = true; // Check the exchange for placeholder. if ( 'placeholder.example.com' !== $exchange ) { $result = false; } // Check the publisher ID for placeholder. if ( 'placeholder' !== $pub_id ) { $result = false; } // Check the account type for placeholder. if ( 'DIRECT' !== $account_type ) { $result = false; } // Check the tag ID for placeholder. if ( ! empty( $tag_id ) && 'placeholder' !== $tag_id ) { $result = false; } return $result; } admin.php 0000755 00000041632 15111573732 0006363 0 ustar 00 <?php /** * Admin functionality for Ads.txt. * * @package Ads_Txt_Manager */ namespace AdsTxt; /** * Enqueue any necessary scripts. * * @param string $hook Hook name for the current screen. * * @return void */ function admin_enqueue_scripts( $hook ) { if ( ! preg_match( '/adstxt-settings$/', $hook ) ) { return; } wp_enqueue_script( 'adstxt', esc_url( plugins_url( '/js/admin.js', dirname( __FILE__ ) ) ), array( 'jquery', 'wp-backbone', 'wp-codemirror' ), ADS_TXT_MANAGER_VERSION, true ); wp_enqueue_style( 'code-editor' ); wp_enqueue_style( 'adstxt', esc_url( plugins_url( '/css/admin.css', dirname( __FILE__ ) ) ), array(), ADS_TXT_MANAGER_VERSION ); $strings = array( 'error_message' => esc_html__( 'Your Ads.txt contains the following issues:', 'ads-txt' ), 'unknown_error' => esc_html__( 'An unknown error occurred.', 'ads-txt' ), ); if ( 'settings_page_app-adstxt-settings' === $hook ) { $strings['error_message'] = esc_html__( 'Your app-ads.txt contains the following issues:', 'ads-txt' ); } wp_localize_script( 'adstxt', 'adstxt', $strings ); } add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\admin_enqueue_scripts' ); /** * Output some CSS directly in the head of the document. * * Should there ever be more than ~25 lines of CSS, this should become a separate file. * * @return void */ function admin_head_css() { ?> <style> .CodeMirror { width: 100%; min-height: 60vh; height: calc( 100vh - 295px ); border: 1px solid #ddd; box-sizing: border-box; } </style> <?php } add_action( 'admin_head-settings_page_adstxt-settings', __NAMESPACE__ . '\admin_head_css' ); add_action( 'admin_head-settings_page_app-adstxt-settings', __NAMESPACE__ . '\admin_head_css' ); /** * Appends a query argument to the edit url to make sure it is redirected to * the ads.txt screen. * * @since 1.2.0 * * @param string $url Edit url. * @return string Edit url. */ function ads_txt_adjust_revisions_return_to_editor_link( $url ) { global $pagenow, $post; if ( 'revision.php' !== $pagenow || ! isset( $_REQUEST['adstxt'] ) ) { // @codingStandardsIgnoreLine Nonce not required. return $url; } $type = 'adstxt'; if ( 'app-adstxt' === $post->post_type ) { $type = 'app-adstxt'; } return admin_url( 'options-general.php?page=' . $type . '-settings' ); } add_filter( 'get_edit_post_link', __NAMESPACE__ . '\ads_txt_adjust_revisions_return_to_editor_link' ); /** * Modifies revisions data to preserve adstxt argument used in determining * where to redirect user returning to editor. * * @since 1.9.0 * * @param array $revisions_data The bootstrapped data for the revisions screen. * @return array Modified bootstrapped data for the revisions screen. */ function adstxt_revisions_restore( $revisions_data ) { if ( isset( $_REQUEST['adstxt'] ) ) { // @codingStandardsIgnoreLine Nonce not required. $revisions_data['restoreUrl'] = add_query_arg( 'adstxt', 1, $revisions_data['restoreUrl'] ); } return $revisions_data; } add_filter( 'wp_prepare_revision_for_js', __NAMESPACE__ . '\adstxt_revisions_restore' ); /** * Hide the revisions title with CSS, since WordPress always shows the title * field even if unchanged, and the title is not relevant for ads.txt. */ function admin_header_revisions_styles() { $current_screen = get_current_screen(); if ( ! $current_screen || 'revision' !== $current_screen->id ) { return; } if ( ! isset( $_REQUEST['adstxt'] ) ) { // @codingStandardsIgnoreLine Nonce not required. return; } ?> <style> .revisions-diff .diff h3 { display: none; } .revisions-diff .diff table.diff:first-of-type { display: none; } </style> <?php } add_action( 'admin_head', __NAMESPACE__ . '\admin_header_revisions_styles' ); /** * Add admin menu page. * * @return void */ function admin_menu() { add_options_page( esc_html__( 'Ads.txt', 'ads-txt' ), esc_html__( 'Ads.txt', 'ads-txt' ), ADS_TXT_MANAGE_CAPABILITY, 'adstxt-settings', __NAMESPACE__ . '\adstxt_settings_screen' ); add_options_page( esc_html__( 'App-ads.txt', 'ads-txt' ), esc_html__( 'App-ads.txt', 'ads-txt' ), ADS_TXT_MANAGE_CAPABILITY, 'app-adstxt-settings', __NAMESPACE__ . '\app_adstxt_settings_screen' ); } add_action( 'admin_menu', __NAMESPACE__ . '\admin_menu' ); /** * Set up settings screen for ads.txt. * * @return void */ function adstxt_settings_screen() { $post_id = get_option( ADS_TXT_MANAGER_POST_OPTION ); $strings = array( 'existing' => __( 'Existing Ads.txt file found', 'ads-txt' ), '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' ), 'errors' => __( 'Your Ads.txt contains the following issues:', 'ads-txt' ), 'screen_title' => __( 'Manage Ads.txt', 'ads-txt' ), 'content_label' => __( 'Ads.txt content', 'ads-txt' ), ); $args = array( 'post_type' => 'adstxt', 'post_title' => 'Ads.txt', 'option' => ADS_TXT_MANAGER_POST_OPTION, 'action' => 'adstxt-save', ); settings_screen( $post_id, $strings, $args ); } /** * Set up settings screen for app-ads.txt. * * @return void */ function app_adstxt_settings_screen() { $post_id = get_option( APP_ADS_TXT_MANAGER_POST_OPTION ); $strings = array( 'existing' => __( 'Existing App-ads.txt file found', 'ads-txt' ), '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' ), 'errors' => __( 'Your app-ads.txt contains the following issues:', 'ads-txt' ), 'screen_title' => __( 'Manage App-ads.txt', 'ads-txt' ), 'content_label' => __( 'App-ads.txt content', 'ads-txt' ), ); $args = array( 'post_type' => 'app-adstxt', 'post_title' => 'App-ads.txt', 'option' => APP_ADS_TXT_MANAGER_POST_OPTION, 'action' => 'app-adstxt-save', ); settings_screen( $post_id, $strings, $args ); } /** * Output the settings screen for both files. * * @param int $post_id Post ID associated with the file. * @param array $strings Translated strings that mention the specific file name. * @param array $args Array of other necessary information to appropriately name items. * * @return void */ function settings_screen( $post_id, $strings, $args ) { $post = false; $content = false; $errors = array(); $revision_count = 0; $last_revision_id = false; if ( $post_id ) { $post = get_post( $post_id ); } if ( is_a( $post, 'WP_Post' ) ) { $content = $post->post_content; $revisions = wp_get_post_revisions( $post->ID ); $revision_count = count( $revisions ); $last_revision = array_shift( $revisions ); $last_revision_id = $last_revision ? $last_revision->ID : false; $errors = get_post_meta( $post->ID, 'adstxt_errors', true ); $warnings = get_post_meta( $post->ID, 'adstxt_warnings', true ); $revisions_link = $last_revision_id ? admin_url( 'revision.php?adstxt=1&revision=' . $last_revision_id ) : false; } else { // Create an initial post so the second save creates a comparable revision. $postarr = array( 'post_title' => $args['post_title'], 'post_content' => '', 'post_type' => $args['post_type'], 'post_status' => 'publish', ); $post_id = wp_insert_post( $postarr ); if ( $post_id ) { update_option( $args['option'], $post_id ); } } // Clean orphaned posts. clean_orphaned_posts( $post_id, $args['post_type'] ); ?> <div class="wrap"> <?php if ( ! empty( $warnings ) ) : ?> <div class="notice notice-warning adstxt-notice"> <ul> <?php foreach ( $warnings as $warning ) { echo '<li>'; // Errors were originally stored as an array. // This old style only needs to be accounted for here at runtime display. if ( isset( $warning['message'] ) ) { /* translators: Error message output. 1: Error message */ $message = sprintf( '%1$s', $warning['message'] ); echo esc_html( $message ); } else { display_formatted_error( $warning ); } echo '</li>'; } ?> </ul> </div> <?php endif; ?> <div class="notice notice-error adstxt-notice existing-adstxt" style="display: none;"> <p><strong><?php echo esc_html( $strings['existing'] ); ?></strong></p> <p><?php echo esc_html( $strings['precedence'] ); ?></p> <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> </div> <?php if ( ! empty( $errors ) ) : ?> <div class="notice notice-error adstxt-notice adstxt-notice-save-error"> <p><strong><?php echo esc_html( $strings['errors'] ); ?></strong></p> <ul> <?php foreach ( $errors as $error ) { echo '<li>'; // Errors were originally stored as an array. // This old style only needs to be accounted for here at runtime display. if ( isset( $error['message'] ) ) { $message = sprintf( /* translators: Error message output. 1: Line number, 2: Error message */ __( 'Line %1$s: %2$s', 'ads-txt' ), $error['line'], $error['message'] ); echo esc_html( $message ); } else { display_formatted_error( $error ); } echo '</li>'; } ?> </ul> </div> <?php endif; ?> <h2><?php echo esc_html( $strings['screen_title'] ); ?></h2> <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" class="adstxt-settings-form"> <input type="hidden" name="post_id" value="<?php echo esc_attr( $post_id ) ? esc_attr( $post_id ) : ''; ?>" /> <input type="hidden" name="adstxt_type" value="<?php echo esc_attr( $args['post_type'] ); ?>" /> <input type="hidden" name="action" value="<?php echo esc_attr( $args['action'] ); ?>" /> <?php wp_nonce_field( 'adstxt_save' ); ?> <label class="screen-reader-text" for="adstxt_content"><?php echo esc_html( $strings['content_label'] ); ?></label> <textarea class="widefat code" rows="25" name="adstxt" id="adstxt_content"><?php echo esc_textarea( $content ); ?></textarea> <?php if ( $revision_count > 1 ) { ?> <div class="misc-pub-section misc-pub-revisions"> <?php echo wp_kses_post( sprintf( /* translators: Post revisions heading. 1: The number of available revisions */ __( 'Revisions: <span class="adstxt-revision-count">%s</span>', 'ads-txt' ), number_format_i18n( $revision_count ) ) ); ?> <a class="hide-if-no-js" href="<?php echo esc_url( $revisions_link ); ?>"> <span aria-hidden="true"> <?php echo esc_html( __( 'Browse', 'ads-txt' ) ); ?> </span> <span class="screen-reader-text"> <?php echo esc_html( __( 'Browse revisions', 'ads-txt' ) ); ?> </span> </a> </div> <?php } ?> <div id="adstxt-notification-area"></div> <p class="submit"> <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php echo esc_attr( 'Save Changes' ); ?>"> <span class="spinner" style="float:none;vertical-align:top"></span> </p> </form> <script type="text/template" id="tmpl-adstext-notice"> <# if ( ! _.isUndefined( data.errors ) ) { #> <div class="notice notice-error adstxt-notice adstxt-errors adstxt-notice-save-error"> <p><strong>{{ data.errors.error_message }}</strong></p> <# if ( ! _.isUndefined( data.errors.errors ) ) { #> <ul class="adstxt-errors-items"> <# _.each( data.errors.errors, function( error ) { #> <?php foreach ( array_keys( get_error_messages() ) as $error_type ) : ?> <# if ( "<?php echo esc_html( $error_type ); ?>" === error.type ) { #> <li> <?php display_formatted_error( array( 'line' => '{{error.line}}', 'type' => $error_type, 'value' => '{{error.value}}', ) ); ?> </li> <# } #> <?php endforeach; ?> <# } ); #> </ul> <# } #> </div> <# if ( _.isUndefined( data.saved ) && ! _.isUndefined( data.errors.errors ) ) { #> <p class="adstxt-ays"> <input id="adstxt-ays-checkbox" name="adstxt_ays" type="checkbox" value="y" /> <label for="adstxt-ays-checkbox"> <?php esc_html_e( 'Update anyway, even though it may adversely affect your ads?', 'ads-txt' ); ?> </label> </p> <# } #> <# } #> </script> </div> <?php } /** * Take an error array and output it as a message. * * @param array $error { * Array of error message components. * * @type int $line Line number of the error. * @type string $type Type of error. * @type string $value Optional. Value in question. * } * * @return string|void */ function display_formatted_error( $error ) { $messages = get_error_messages(); if ( ! isset( $messages[ $error['type'] ] ) ) { return __( 'Unknown error', 'adstxt' ); } if ( ! isset( $error['value'] ) ) { $error['value'] = ''; } $message = sprintf( esc_html( $messages[ $error['type'] ] ), '<code>' . esc_html( $error['value'] ) . '</code>' ); printf( /* translators: Error message output. 1: Line number, 2: Error message */ esc_html__( 'Line %1$s: %2$s', 'ads-txt' ), esc_html( $error['line'] ), wp_kses_post( $message ) ); } /** * Get all non-generic error messages, translated and with placeholders intact. * * @return array Associative array of error messages. */ function get_error_messages() { $messages = array( 'invalid_variable' => __( 'Unrecognized variable' ), 'invalid_record' => __( 'Invalid record' ), 'invalid_account_type' => __( 'Third field should be RESELLER or DIRECT' ), /* translators: %s: Subdomain */ 'invalid_subdomain' => __( '%s does not appear to be a valid subdomain' ), /* translators: %s: Exchange domain */ 'invalid_exchange' => __( '%s does not appear to be a valid exchange domain' ), /* translators: %s: Alphanumeric TAG-ID */ 'invalid_tagid' => __( '%s does not appear to be a valid TAG-ID' ), ); return $messages; } /** * Maybe display admin notices on the Ads.txt settings page. * * @return void */ function admin_notices() { if ( 'settings_page_adstxt-settings' === get_current_screen()->base ) { $saved = __( 'Ads.txt saved', 'ads-txt' ); } elseif ( 'settings_page_app-adstxt-settings' === get_current_screen()->base ) { $saved = __( 'App-ads.txt saved', 'ads-txt' ); } else { return; } if ( isset( $_GET['ads_txt_saved'] ) ) : // @codingStandardsIgnoreLine Nonce not required. ?> <div class="notice notice-success adstxt-notice adstxt-saved"> <p><?php echo esc_html( $saved ); ?></p> </div> <?php elseif ( isset( $_GET['revision'] ) ) : // @codingStandardsIgnoreLine Nonce not required. ?> <div class="notice notice-success adstxt-notice adstxt-saved"> <p><?php echo esc_html__( 'Revision restored', 'ads-txt' ); ?></p> </div> <?php endif; } add_action( 'admin_notices', __NAMESPACE__ . '\admin_notices' ); /** * Clean orphaned posts if found. * * @param int $option adstxt | app_adstxt post ID. * @param string $post_type The post type, either 'adstxt' or 'app_adstxt'. * * @return boolean */ function clean_orphaned_posts( $option, $post_type ) { $args = [ 'fields' => 'ids', // Only get post IDs. 'post_type' => $post_type, ]; $ads_posts = get_posts( $args ); if ( 1 === count( $ads_posts ) && [ (int) $option ] === $ads_posts ) { return false; } // Search for the active post ID and remove it from the array. $index = array_search( (int) $option, $ads_posts, true ); if ( false !== $index ) { unset( $ads_posts[ $index ] ); } if ( empty( $ads_posts ) ) { return false; } foreach ( $ads_posts as $post_id ) { wp_delete_post( $post_id, true ); } return true; } /** * Check if ads.txt file already exists in the server * * @return void */ function adstxts_check_for_existing_file() { current_user_can( ADS_TXT_MANAGE_CAPABILITY ) || die; check_admin_referer( 'adstxt_save' ); $home_url_parsed = wp_parse_url( home_url() ); $adstxt_type = sanitize_text_field( $_POST['adstxt_type'] ); if ( 'adstxt' !== $adstxt_type && 'app-adstxt' !== $adstxt_type ) { wp_die(); } $file_name = 'adstxt' === $adstxt_type ? '/ads.txt' : '/app-ads.txt'; if ( empty( $home_url_parsed['path'] ) ) { $response = wp_remote_request( home_url( $file_name ) ); $file_exist = false; if ( ! is_wp_error( $response ) ) { // Check the ads.txt generator header. $headers = wp_remote_retrieve_headers( $response ); $generator = isset( $headers['X-Ads-Txt-Generator'] ) ? $headers['X-Ads-Txt-Generator'] : ''; $file_exist = 'https://wordpress.org/plugins/ads-txt/' !== $generator; } // Return the response wp_send_json( [ 'success' => true, 'file_exist' => $file_exist, ] ); // Make sure to exit wp_die(); } } add_action( 'wp_ajax_adstxts_check_for_existing_file', __NAMESPACE__ . '\adstxts_check_for_existing_file' );
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings