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'] ); ?>