Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: Hello VDU
  4. * Author: Arūnas Liuiza [KAYAK]
  5. * Version: 0.1.0
  6. * Text Domain: hello-vdu
  7. */
  8.  
  9. add_action( 'plugins_loaded', 'hello_vdu' );
  10.  
  11. function hello_vdu() {
  12. if ( false === Hello_VDU_Class::$instance ) {
  13. Hello_VDU_Class::$instance = new Hello_VDU_Class();
  14. }
  15. return Hello_VDU_Class::$instance;
  16. }
  17.  
  18. class Hello_VDU_Class {
  19. public static $instance = false;
  20. public function __construct() {
  21. add_filter( 'the_content', array( $this, 'copyright' ), 100 );
  22. // add "updated" info to the title
  23. add_filter( 'the_title', array( $this, 'modified' ), 10, 2 );
  24. // add icons to post title
  25. add_filter( 'the_title', array( $this, 'icons' ), 100 );
  26. add_action( 'wp_enqueue_scripts', array( $this, 'assets') );
  27. }
  28.  
  29. public function copyright( $content ) {
  30. if ( ! is_singular( 'post' ) ) {
  31. return $content;
  32. }
  33. $content .= '<hr />' . PHP_EOL;
  34. $content .= '<p><small>';
  35. $content .= sprintf(
  36. __( 'The conents of this article cannot be republished in any form without a prior written consent of the owners of %s website.', 'hello-vdu' ),
  37. get_bloginfo( 'title' )
  38. );
  39. $content .= '</small></p>';
  40. return $content;
  41. }
  42.  
  43. public function modified( $title, $post_id ) {
  44. if ( is_admin() ) {
  45. return $title;
  46. }
  47. if ( ! in_the_loop() ) {
  48. return $title;
  49. }
  50. $post = get_post( $post_id );
  51. if ( $post->post_date === $post->post_modified ) {
  52. return $title;
  53. }
  54. if ( 3 * HOUR_IN_SECONDS < current_time('timestamp') - strtotime( $post->post_modified ) ) {
  55. return $title;
  56. }
  57. $diff = sprintf(
  58. __( '(updated %s ago)', 'hello-vdu' ),
  59. human_time_diff( strtotime( $post->post_modified ) )
  60. );
  61. $title .= " <small style='color:red;'>{$diff}</small>";
  62. return $title;
  63. }
  64.  
  65. public function icons( $title ) {
  66. if ( is_admin() ) {
  67. return $title;
  68. }
  69. $patterns = array(
  70. '[foto]' => '<span class="dashicons dashicons-camera"></span>',
  71. '[video]' => '<span class="dashicons dashicons-video-alt2"></span>',
  72. '[audio]' => '<span class="dashicons dashicons-format-audio"></span>',
  73. );
  74. $title = str_replace(
  75. array_keys( $patterns ),
  76. array_values( $patterns ),
  77. $title
  78. );
  79. return $title;
  80. }
  81.  
  82. public function assets() {
  83. wp_enqueue_style( 'dashicons' );
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement