Guest User

stripimages.php

a guest
Jan 4th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Addon Name: Strip Images
  5. Description: Removes all image tags from the post content.
  6. Author: WPMU DEV
  7. Author URI: http://premium.wpmudev.org
  8. */
  9.  
  10. class A_StripImagesAddon extends Autoblog_Addon
  11. {
  12.  
  13. /**
  14. * Constructor.
  15. *
  16. * @since 4.0.0
  17. *
  18. * @access public
  19. */
  20. public function __construct()
  21. {
  22. parent::__construct();
  23.  
  24. $this->_add_filter('autoblog_pre_post_insert', 'filter_post', 11, 2);
  25. $this->_add_action('autoblog_pre_post_update', 'filter_post', 11, 2);
  26.  
  27. $this->_add_action('autoblog_feed_edit_form_end', 'add_feed_option', 12, 2);
  28. }
  29.  
  30. /**
  31. * Filters post content to strip images.
  32. *
  33. * @since 4.0.0
  34. * @filter autoblog_pre_post_insert 11 2
  35. *
  36. * @access public
  37. * @param array $data The post data.
  38. * @param array $details The array of feed details.
  39. * @return array The post data.
  40. */
  41. public function filter_post($data, array $details)
  42. {
  43. if (!is_array($data)) {
  44. return $data;
  45. }
  46. if (!empty($details['stripimgtags']) && addslashes($details['stripimgtags']) == '1') {
  47. $placeholder = isset($details['stripimgtagsreplace']) ? $details['stripimgtagsreplace'] : '';
  48. $data['post_content'] = preg_replace("/(<img[^>]+\>)|(http(?:[^\s]+)\.(?:jpe?g|gif|png))/", $placeholder, $data['post_content']);
  49. }
  50.  
  51. return $data;
  52. }
  53.  
  54. /**
  55. * Renders addon options.
  56. *
  57. * @since 4.0.0
  58. * @action autoblog_feed_edit_form_end 12 2
  59. *
  60. * @param type $key
  61. * @param type $details
  62. */
  63. public function add_feed_option($key, $details)
  64. {
  65. $table = !empty($details->feed_meta) ? maybe_unserialize($details->feed_meta) : array();
  66.  
  67. if (!isset($table['stripimgtagsreplace'])) {
  68. $table['stripimgtagsreplace'] = '';
  69. }
  70.  
  71. // render block header
  72. $this->_render_block_header(esc_html__('Strip Images', 'autoblogtext'));
  73.  
  74. // render block elements
  75. $this->_render_block_element(esc_html__('Strip Image Tags', 'autoblogtext'), sprintf(
  76. '<input type="checkbox" name="abtble[stripimgtags]" value="1"%s>',
  77. checked(isset($table['stripimgtags']) && $table['stripimgtags'] == '1', true, false)
  78. ));
  79.  
  80. $this->_render_block_element(esc_html__('Replace With', 'autoblogtext'), sprintf(
  81. '<input type="text" class="long field" name="abtble[stripimgtagsreplace]" value="%s">',
  82. esc_attr(stripslashes($table['stripimgtagsreplace']))
  83. ));
  84. }
  85.  
  86. }
  87.  
  88. $a_stripimagesaddon = new A_StripImagesAddon();
Add Comment
Please, Sign In to add comment