Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <div class="big_content_item">CONTENT</div>
  2.  
  3. <div class="wide_content_item">CONTENT</div>
  4.  
  5. <div class="content_item">CONTENT</div>
  6.  
  7. [big_content] или [wide_content] или [content]
  8.  
  9. add_filter('the_content', 'filter_content');
  10. function filter_content( $content ){
  11. modify_content($content, '[big_content]', '<div class="big_content_item"';
  12. modify_content($content, '[wide_content]', '<div class="wide_content_item"');
  13. modify_content($content, '[content]', '<div class="content_item"');
  14. return $content;
  15. }
  16. function modify_content($content, $code, $wrap) {
  17. if (substr($content, $code) {
  18. $content = str_replace($code, '');
  19. return $wrap . $content . '</div>';
  20. }
  21. }
  22.  
  23. <?php
  24. /*
  25. Plugin Name: Вставка отзывов
  26. Plugin URI:
  27. Description: Создаёт блоки текста . Добавляет кнопку в редактор для вставки кода.
  28. Version: 1.0
  29. Author: SeVlad
  30. Author URI: http://sevladwp.wordpress.com/
  31. */
  32.  
  33.  
  34. //Добавление кнопки в редактор
  35. function true_add_mce_button() {
  36. // проверяем права пользователя - может ли он редактировать посты и страницы
  37. if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
  38. return; // если не может, то и кнопка ему не понадобится, в этом случае выходим из функции
  39. }
  40. // проверяем, включен ли визуальный редактор у пользователя в настройках (если нет, то и кнопку подключать незачем)
  41. if ( 'true' == get_user_option( 'rich_editing' ) ) {
  42. add_filter( 'mce_external_plugins', 'true_add_tinymce_script' );
  43. add_filter( 'mce_buttons', 'true_register_mce_button' );
  44. }
  45. }
  46. add_action('admin_head', 'true_add_mce_button');
  47.  
  48. // В этом функции указываем ссылку на JavaScript-файл кнопки
  49. function true_add_tinymce_script( $plugin_array ) {
  50. $plugin_array['ref_mce_button'] = plugin_dir_url( __FILE__ ).'refbuttons.js'; // ref_mce_button - идентификатор кнопки
  51. return $plugin_array;
  52. }
  53.  
  54. // Регистрируем кнопку в редакторе
  55. function true_register_mce_button( $buttons ) {
  56. array_push( $buttons, 'ref_mce_button' ); // ref_mce_button - идентификатор кнопки
  57. return $buttons;
  58. }
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement