tweaks.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. // Strip only the WordPress *core* version from asset URLs (mild version hiding).
  42. // Leave other ?ver values intact so filemtime cache-busters keep working —
  43. // otherwise browsers cache CSS/JS forever and never see a rebuild.
  44. function dw_remove_wp_ver_css_js( $src ) {
  45. if ( strpos( $src, 'ver=' . $GLOBALS['wp_version'] ) !== false )
  46. $src = remove_query_arg( 'ver', $src );
  47. return $src;
  48. }
  49. add_filter( 'style_loader_src', 'dw_remove_wp_ver_css_js', 9999 );
  50. add_filter( 'script_loader_src', 'dw_remove_wp_ver_css_js', 9999 );
  51. add_filter( 'xmlrpc_enabled', '__return_false' );
  52. add_filter( 'wp_headers', 'disable_x_pingback' );
  53. function disable_x_pingback( $headers ) {
  54. unset( $headers['X-Pingback'] );
  55. return $headers;
  56. }
  57. function disable_emojis_tinymce( $plugins ) {
  58. if ( is_array( $plugins ) ) {
  59. return array_diff( $plugins, array( 'wpemoji' ) );
  60. } else {
  61. return array();
  62. }
  63. }
  64. function disable_emojis() {
  65. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  66. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  67. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  68. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  69. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  70. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  71. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  72. add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
  73. add_filter( 'emoji_svg_url', '__return_false' );
  74. }
  75. add_action( 'init', 'disable_emojis' );
  76. function custom_excerpt_length( $length ) {
  77. return 20;
  78. }
  79. add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  80. add_filter('wp_mail_from', 'dw_fromemail');
  81. function dw_fromemail($email) {
  82. $wpfrom = get_option('admin_email');
  83. return $wpfrom;
  84. }
  85. add_filter('wp_mail_from_name', 'dw_fromname');
  86. function dw_fromname($email){
  87. $wpfrom = get_option('blogname');
  88. return $wpfrom;
  89. }
  90. add_filter( 'embed_oembed_html', 'dw_oembed_filter', 10, 4 ) ;
  91. function dw_oembed_filter($html, $url, $attr, $post_ID) {
  92. $return = '<div class="video-container">'.$html.'</div>';
  93. $return = str_replace('frameborder="0" allowfullscreen', 'style="border:none"', $return);
  94. return $return;
  95. }
  96. add_filter( 'embed_oembed_html', 'dw_embed_oembed_html' );
  97. function dw_embed_oembed_html( $html ) {
  98. return preg_replace( '@src="https?:@', 'src="', $html );
  99. }
  100. function dw_deliver_form_mail() {
  101. if ( isset( $_POST['dw-contact'] ) ) {
  102. $fname = sanitize_text_field( $_POST["dw-fname"] );
  103. $lname = sanitize_text_field( $_POST["dw-lname"] );
  104. $email = sanitize_email( $_POST["dw-email"] );
  105. $subject = sanitize_text_field( $_POST["dw-org"] );
  106. $message = esc_textarea( $_POST["dw-message"] );
  107. $to = get_option( 'admin_email' );
  108. $headers = "From: $fname $lname <$email>" . "\r\n";
  109. if ( wp_mail( $to, $subject, $message, $headers ) ) {
  110. echo '<div class="alert alert-success" role="alert">';
  111. echo '<p>Thank you. I will be in touch.</p>';
  112. echo '</div>';
  113. }
  114. else {
  115. echo '<div class="alert alert-danger" role="alert">';
  116. echo '<p>Error, please try again</p>';
  117. echo '</div>';
  118. }
  119. }
  120. }
  121. add_shortcode('dwsearch', 'get_search_form');
  122. function doctype_opengraph($output) {
  123. return $output . '
  124. xmlns:og="http://opengraphprotocol.org/schema/"
  125. xmlns:fb="http://www.facebook.com/2008/fbml"';
  126. }
  127. add_filter('language_attributes', 'doctype_opengraph');
  128. function dw_opengraph() {
  129. global $post;
  130. if (is_single()) {
  131. if (has_post_thumbnail($post->ID)) {
  132. $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'full'); $img_src = $img_src[0];
  133. } elseif ( metadata_exists( 'post', get_the_ID(), 'featured_image_url' ) ){
  134. $img_src = get_post_meta( get_the_ID(), 'featured_image_url', true );
  135. } else {
  136. $img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
  137. }
  138. if($excerpt = $post->post_excerpt) {
  139. $excerpt = strip_tags($post->post_excerpt);
  140. $excerpt = str_replace("", "'", $excerpt);
  141. } else {
  142. $excerpt = get_bloginfo('description');
  143. }
  144. ?>
  145. <meta property="og:title" content="<?php echo the_title(); ?>"/>
  146. <meta property="og:description" content="<?php echo $excerpt; ?>"/>
  147. <meta property="og:type" content="article"/>
  148. <meta property="og:url" content="<?php echo the_permalink(); ?>"/>
  149. <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
  150. <meta property="og:image" content="<?php echo $img_src; ?>"/>
  151. <meta property="fb:app_id" content="203136806559589" />
  152. <meta name="twitter:site" content="@windhamdavid">
  153. <meta name="twitter:creator" content="@windhamdavid">
  154. <meta name="twitter:title" content="<?php echo the_title(); ?>">
  155. <meta name="twitter:description" content="<?php echo $excerpt; ?>">
  156. <meta name="twitter:image" content="<?php echo $img_src; ?>">
  157. <?php
  158. } else {
  159. return;
  160. }
  161. $content = do_shortcode( apply_filters( 'the_content', $post->post_content ) );
  162. $media_url = get_post_meta( get_the_ID(), 'media', true );
  163. $media = get_media_embedded_in_content( $content );
  164. if( !empty($media) ) {
  165. $video_url = $media[0];
  166. ?>
  167. <meta property="og:video" content="<?php echo $media_url; ?>" />
  168. <meta property="og:video:secure_url" content="<?php echo $media_url; ?>" />
  169. <meta property="og:video:width" content="1280" />
  170. <meta property="og:video:height" content="720" />
  171. <meta property="og:video:type" content="video/mp4" />
  172. <meta name="twitter:card" content="player">
  173. <meta name="twitter:player" content="<?php echo get_permalink();?>container/" />
  174. <meta name="twitter:player:width" content="1280" />
  175. <meta name="twitter:player:height" content="720" />
  176. <meta name="twitter:player:stream" content="<?php echo $media_url; ?>" />
  177. <meta name="twitter:player:stream:content_type" content="video/mp4" />
  178. <?php
  179. } else {
  180. ?>
  181. <meta name="twitter:card" content="summary_large_image">
  182. <?php
  183. }
  184. }
  185. add_action('wp_head', 'dw_opengraph', 5);
  186. function dw_read_container_endpoint(){
  187. add_rewrite_endpoint( 'container', EP_PERMALINK);
  188. }
  189. add_action( 'init', 'dw_read_container_endpoint' );
  190. function dw_read_container_template( $template = '' ) {
  191. global $wp_query;
  192. if( ! array_key_exists( 'container', $wp_query->query_vars ) ) return $template;
  193. $template = locate_template( 'single-container.php' );
  194. return $template;
  195. }
  196. add_filter( 'single_template', 'dw_read_container_template' );
  197. function dw_video_embed( $attr, $content='' ) {
  198. if ( ! isset( $attr['poster'] ) && has_post_thumbnail() ) {
  199. $poster = get_post_meta( get_the_ID(), 'media-poster', true );
  200. $attr['poster'] = $poster;
  201. }
  202. return wp_video_shortcode( $attr, $content );
  203. }
  204. add_shortcode( 'video', 'dw_video_embed' );
  205. ?>