tweaks.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. ###################### Date Modified ######################
  3. function daw_post_columns_data( $column, $post_id ) {
  4. switch ( $column ) {
  5. case 'modified':
  6. $m_orig = get_post_field( 'post_modified', $post_id, 'raw' );
  7. $m_stamp = strtotime( $m_orig );
  8. $modified = date('Y/m/d', $m_stamp );
  9. $modr_id = get_post_meta( $post_id, '_edit_last', true );
  10. echo '<p class="mod-date">';
  11. echo '<em>'.$modified.'</em>';
  12. echo '</p>';
  13. break;
  14. }
  15. }
  16. add_action ( 'manage_posts_custom_column', 'daw_post_columns_data', 10, 2 );
  17. add_filter ( 'manage_edit-post_columns', 'daw_post_columns_display');
  18. function daw_post_columns_display( $columns ) {
  19. $columns['modified'] = 'Last Modified';
  20. return $columns;
  21. }
  22. function daw_last_modified_column_register_sortable( $columns ) {
  23. $columns['modified'] = 'post_modified';
  24. return $columns;
  25. }
  26. add_filter( "manage_edit-post_sortable_columns", "daw_last_modified_column_register_sortable" );
  27. add_filter( "manage_edit-page_sortable_columns", "daw_last_modified_column_register_sortable" );
  28. remove_action('wp_head', 'index_rel_link' );
  29. remove_action('wp_head', 'rel_canonical');
  30. remove_action('wp_head', 'start_post_rel_link', 10);
  31. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
  32. remove_action('wp_head', 'wp_shortlink_wp_head', 10);
  33. remove_action('wp_head', 'parent_post_rel_link', 10);
  34. remove_action('wp_head', 'rsd_link');
  35. remove_action('wp_head', 'wlwmanifest_link');
  36. remove_action('wp_head', 'wp_generator');
  37. remove_action('wp_head', 'feed_links_extra', 3 );
  38. remove_action('wp_head', 'feed_links', 2 );
  39. remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
  40. remove_action('wp_head', 'wp_oembed_add_host_js', 10);
  41. function dw_remove_wp_ver_css_js( $src ) {
  42. if ( strpos( $src, 'ver=' ) )
  43. $src = remove_query_arg( 'ver', $src );
  44. return $src;
  45. }
  46. add_filter( 'style_loader_src', 'dw_remove_wp_ver_css_js', 9999 );
  47. add_filter( 'script_loader_src', 'dw_remove_wp_ver_css_js', 9999 );
  48. add_filter( 'xmlrpc_enabled', '__return_false' );
  49. add_filter( 'wp_headers', 'disable_x_pingback' );
  50. function disable_x_pingback( $headers ) {
  51. unset( $headers['X-Pingback'] );
  52. return $headers;
  53. }
  54. function disable_emojis_tinymce( $plugins ) {
  55. if ( is_array( $plugins ) ) {
  56. return array_diff( $plugins, array( 'wpemoji' ) );
  57. } else {
  58. return array();
  59. }
  60. }
  61. function disable_emojis() {
  62. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  63. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  64. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  65. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  66. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  67. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  68. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  69. add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
  70. add_filter( 'emoji_svg_url', '__return_false' );
  71. }
  72. add_action( 'init', 'disable_emojis' );
  73. function custom_excerpt_length( $length ) {
  74. return 20;
  75. }
  76. add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  77. add_filter('wp_mail_from', 'dw_fromemail');
  78. function dw_fromemail($email) {
  79. $wpfrom = get_option('admin_email');
  80. return $wpfrom;
  81. }
  82. add_filter('wp_mail_from_name', 'dw_fromname');
  83. function dw_fromname($email){
  84. $wpfrom = get_option('blogname');
  85. return $wpfrom;
  86. }
  87. add_filter( 'embed_oembed_html', 'dw_oembed_filter', 10, 4 ) ;
  88. function dw_oembed_filter($html, $url, $attr, $post_ID) {
  89. $return = '<div class="video-container">'.$html.'</div>';
  90. $return = str_replace('frameborder="0" allowfullscreen', 'style="border:none"', $return);
  91. return $return;
  92. }
  93. add_filter( 'embed_oembed_html', 'dw_embed_oembed_html' );
  94. function dw_embed_oembed_html( $html ) {
  95. return preg_replace( '@src="https?:@', 'src="', $html );
  96. }
  97. function dw_deliver_form_mail() {
  98. if ( isset( $_POST['dw-contact'] ) ) {
  99. $fname = sanitize_text_field( $_POST["dw-fname"] );
  100. $lname = sanitize_text_field( $_POST["dw-lname"] );
  101. $email = sanitize_email( $_POST["dw-email"] );
  102. $subject = sanitize_text_field( $_POST["dw-org"] );
  103. $message = esc_textarea( $_POST["dw-message"] );
  104. $to = get_option( 'admin_email' );
  105. $headers = "From: $fname $lname <$email>" . "\r\n";
  106. if ( wp_mail( $to, $subject, $message, $headers ) ) {
  107. echo '<div class="alert alert-success" role="alert">';
  108. echo '<p>Thank you. I will be in touch.</p>';
  109. echo '</div>';
  110. }
  111. else {
  112. echo '<div class="alert alert-danger" role="alert">';
  113. echo '<p>Error, please try again</p>';
  114. echo '</div>';
  115. }
  116. }
  117. }
  118. add_shortcode('dwsearch', 'get_search_form');
  119. function doctype_opengraph($output) {
  120. return $output . '
  121. xmlns:og="http://opengraphprotocol.org/schema/"
  122. xmlns:fb="http://www.facebook.com/2008/fbml"';
  123. }
  124. add_filter('language_attributes', 'doctype_opengraph');
  125. function dw_opengraph() {
  126. global $post;
  127. if (is_single()) {
  128. if (has_post_thumbnail($post->ID)) {
  129. $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'full'); $img_src = $img_src[0];
  130. } elseif ( metadata_exists( 'post', get_the_ID(), 'featured_image_url' ) ){
  131. $img_src = get_post_meta( get_the_ID(), 'featured_image_url', true );
  132. } else {
  133. $img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
  134. }
  135. if($excerpt = $post->post_excerpt) {
  136. $excerpt = strip_tags($post->post_excerpt);
  137. $excerpt = str_replace("", "'", $excerpt);
  138. } else {
  139. $excerpt = get_bloginfo('description');
  140. }
  141. ?>
  142. <meta property="og:title" content="<?php echo the_title(); ?>"/>
  143. <meta property="og:description" content="<?php echo $excerpt; ?>"/>
  144. <meta property="og:type" content="article"/>
  145. <meta property="og:url" content="<?php echo the_permalink(); ?>"/>
  146. <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
  147. <meta property="og:image" content="<?php echo $img_src; ?>"/>
  148. <meta property="fb:app_id" content="203136806559589" />
  149. <meta name="twitter:site" content="@windhamdavid">
  150. <meta name="twitter:creator" content="@windhamdavid">
  151. <meta name="twitter:title" content="<?php echo the_title(); ?>">
  152. <meta name="twitter:description" content="<?php echo $excerpt; ?>">
  153. <meta name="twitter:image" content="<?php echo $img_src; ?>">
  154. <?php
  155. } else {
  156. return;
  157. }
  158. $content = do_shortcode( apply_filters( 'the_content', $post->post_content ) );
  159. $media_url = get_post_meta( get_the_ID(), 'media', true );
  160. $media = get_media_embedded_in_content( $content );
  161. if( !empty($media) ) {
  162. $video_url = $media[0];
  163. ?>
  164. <meta property="og:video" content="<?php echo $media_url; ?>" />
  165. <meta property="og:video:secure_url" content="<?php echo $media_url; ?>" />
  166. <meta property="og:video:width" content="1280" />
  167. <meta property="og:video:height" content="720" />
  168. <meta property="og:video:type" content="video/mp4" />
  169. <meta name="twitter:card" content="player">
  170. <meta name="twitter:player" content="<?php echo get_permalink();?>container/" />
  171. <meta name="twitter:player:width" content="1280" />
  172. <meta name="twitter:player:height" content="720" />
  173. <meta name="twitter:player:stream" content="<?php echo $media_url; ?>" />
  174. <meta name="twitter:player:stream:content_type" content="video/mp4" />
  175. <?php
  176. } else {
  177. ?>
  178. <meta name="twitter:card" content="summary_large_image">
  179. <?php
  180. }
  181. }
  182. add_action('wp_head', 'dw_opengraph', 5);
  183. function dw_read_container_endpoint(){
  184. add_rewrite_endpoint( 'container', EP_PERMALINK);
  185. }
  186. add_action( 'init', 'dw_read_container_endpoint' );
  187. function dw_read_container_template( $template = '' ) {
  188. global $wp_query;
  189. if( ! array_key_exists( 'container', $wp_query->query_vars ) ) return $template;
  190. $template = locate_template( 'single-container.php' );
  191. return $template;
  192. }
  193. add_filter( 'single_template', 'dw_read_container_template' );
  194. function dw_video_embed( $attr, $content='' ) {
  195. if ( ! isset( $attr['poster'] ) && has_post_thumbnail() ) {
  196. $poster = get_post_meta( get_the_ID(), 'media-poster', true );
  197. $attr['poster'] = $poster;
  198. }
  199. return wp_video_shortcode( $attr, $content );
  200. }
  201. add_shortcode( 'video', 'dw_video_embed' );
  202. ?>