芝麻web文件管理V1.00
编辑当前文件:/home/ezdajrnh/public_html/wp-content/plugins/ads-txt/inc/admin.php
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() { ?> 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; } ?> __( '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'] ); ?>
'; // 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 ''; } ?>
'; // 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 ''; } ?>
</textarea> 1 ) { ?>
%s', 'ads-txt' ), number_format_i18n( $revision_count ) ) ); ?>
' . esc_html( $error['value'] ) . '' ); 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', 'ads-txt' ), 'invalid_record' => __( 'Invalid record', 'ads-txt' ), 'invalid_account_type' => __( 'Third field should be RESELLER or DIRECT', 'ads-txt' ), /* translators: %s: Subdomain */ 'invalid_subdomain' => __( '%s does not appear to be a valid subdomain', 'ads-txt' ), /* translators: %s: Exchange domain */ 'invalid_exchange' => __( '%s does not appear to be a valid exchange domain', 'ads-txt' ), /* translators: %s: Alphanumeric TAG-ID */ 'invalid_tagid' => __( '%s does not appear to be a valid TAG-ID', 'ads-txt' ), ); 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. ?>
'ids', // Only get post IDs. 'post_type' => $post_type, ]; $ads_posts = get_posts( $args ); // Remove the active post ID from the array. $ads_posts = array_filter( $ads_posts, function ( $ads_post ) use ( $option ) { return $ads_post !== (int) $option; } ); 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' );