Last active
September 12, 2019 07:33
-
-
Save campusboy87/56da3cc1caa0dbc7a6281605034c9fda to your computer and use it in GitHub Desktop.
Преобразуент контент записи в plain text
This file contains hidden or 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
| <?php | |
| /** | |
| * Plugin Name: Преобразуент контент записи в plain text | |
| */ | |
| add_action( 'admin_menu', function () { | |
| add_management_page( | |
| 'Форматирование записи', | |
| 'Форматирование записи', | |
| 'manage_options', | |
| 'plain-text', | |
| 'make_plain_text' | |
| ); | |
| } ); | |
| function make_plain_text() { | |
| $post_id = filter_input( INPUT_GET, 'post_id', FILTER_VALIDATE_INT ); | |
| $post = get_post( $post_id ); | |
| ?> | |
| <div class="wrap"> | |
| <h2><?php echo get_admin_page_title() ?></h2> | |
| <form> | |
| <input type="text" name="post_id" value="<?php echo $post_id; ?>"> | |
| <input type="hidden" name="page" value="plain-text"> | |
| <button>Отправить</button> | |
| </form> | |
| <?php if ( $post ): | |
| $content = $post->post_content; | |
| $content = wpautop( $content ); | |
| $content = str_replace( [ "\n", "\r", "\t" ], '', $content ); | |
| ?> | |
| <h3><?php echo esc_html( $post->post_title ); ?></h3> | |
| <textarea style="width: 100%; height: 600px;"><?php echo $content; ?></textarea> | |
| <?php else: ?> | |
| <p>Указанной записи нет!</p> | |
| <?php endif; ?> | |
| </div> | |
| <?php | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment