tweaks.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. add_action( 'admin_menu', 'daw_is_online_add_admin_menu' );
  98. add_action( 'admin_init', 'daw_is_online_settings_init' );
  99. function daw_is_online_add_admin_menu( ) {
  100. add_options_page( 'DW Status', 'DAW Online', 'manage_options', 'daw_is_online', 'daw_is_online_options_page' );
  101. }
  102. function daw_is_online_settings_init( ) {
  103. register_setting( 'dwstatus', 'daw_is_online_settings' );
  104. add_settings_section('daw_is_online_pluginPage_section', __( 'DAW Online', 'wordpress' ), 'daw_is_online_settings_section_callback', 'dwstatus');
  105. add_settings_field( 'daw_is_online_select_field_0', __( 'Am I Online ?', 'wordpress' ), 'daw_is_online_select_field_0_render', 'dwstatus', 'daw_is_online_pluginPage_section' );
  106. }
  107. function daw_is_online_select_field_0_render( ) {
  108. $options = get_option( 'daw_is_online_settings' ); ?>
  109. <select name='daw_is_online_settings[daw_is_online_select_field_0]'>
  110. <option value='1' <?php selected( $options['daw_is_online_select_field_0'], 1 ); ?>>Yes</option>
  111. <option value='2' <?php selected( $options['daw_is_online_select_field_0'], 2 ); ?>>No</option>
  112. </select>
  113. <?php }
  114. function daw_is_online_settings_section_callback( ) {
  115. echo __( 'This sets my online status', 'wordpress' );
  116. }
  117. function daw_is_online_options_page( ) { ?>
  118. <form action='options.php' method='post'>
  119. <?php settings_fields( 'dwstatus' );
  120. do_settings_sections( 'dwstatus' );
  121. submit_button(); ?>
  122. </form>
  123. <?php }
  124. function dw_online_get_status() {
  125. $dw_status = get_option('daw_is_online_settings');
  126. if( $dw_status['daw_is_online_select_field_0'] == '1' ) {
  127. wp_enqueue_style( 'message', get_template_directory_uri() . '/css/messenger.css');
  128. ?>
  129. <script type="text/javascript">function txt_dave(){$.ajax({url:"https://davidawindham.com/wha/phony/sms.php",dataType:"json",success:function(){}})}$(function(){var a;a=0,Messenger.options={extraClasses:"messenger-fixed messenger-on-bottom messenger-on-left",theme:"flat"};var b;b=Messenger().post({message:"I'm Currently Online",type:'success',actions:{cancel:{label:"Connect",delay:60,action:function(){txt_dave();var c;c=Messenger().run({errorMessage:"Please wait a moment while I get connected with you.",successMessage:"Connecting",action:function(c){return b.hide(),++a<2?c.error({status:500,readyState:0,responseText:0}):(window.location.href="http://chat.davidawindham.com",b.update({message:"Redirect to Chat",hideAfter:20,type:"success",actions:!1}))}})}}},retry:{label:"No Thanks",action:function(){return b.update({message:"Maybe Next Time",hideAfter:1,type:"error",actions:!1})}}})});</script>
  130. <?php }
  131. }
  132. function dw_online_get_chat() {
  133. $dw_status = get_option('daw_is_online_settings');
  134. if( $dw_status['daw_is_online_select_field_0'] == '1' ) { ?>
  135. <script type="text/javascript">
  136. Messenger.options = {extraClasses: "messenger-fixed messenger-on-bottom messenger-on-left",theme: "flat"};var i;i = 0;
  137. $(function(){
  138. var msg_return;
  139. msg_return = Messenger().run({
  140. id: 'one',
  141. errorMessage: 'Looking for David...',
  142. action: function(opts) {if (++i < 2) {get_dave();return opts.error({status: 500,readyState: 0,responseText: 0});}}});});
  143. function get_dave() {$(function poll() {var x = 0; var countTimer = setInterval(function () {if(x > 5){clearInterval(countTimer)}else if(x == 5){dave_not_available()}else{var URLchatAPI = "http://code.davidawindham.com:8080/status";var request = $.ajax({url: URLchatAPI,dataType: 'json',cache: false, success: function (data) {online = data.online;if(online=='yes') {$('.chat').modal('show');x = x+5;};if (online=='no') {dave_connecting();};},error: function ( xhr, tStatus, err ) {dave_error();x = x+5;}});x++;}}, 5000);});}
  144. function dave_connecting(){var y;y = 0;var msg_waiting; msg_waiting = Messenger().run({id: 'one',hideAfter: 4,errorMessage: 'Waiting on David...',action: function(opts) {if (++y < 2) {get_dave();return opts.error({status: 500,readyState: 0,responseText: 0});}}});}
  145. function dave_not_available(){var msg_error; msg_error = Messenger().post({message: 'Sorry, but I am busy.',type: 'error',id: 'one',showCloseButton: true,actions:{cancel: {label: 'Leave me a message',action: function(){window.location.href = '../';}}}});}
  146. function dave_error(){var msg_error; msg_error = Messenger().post({message: 'Oops. Something has gone wrong.',type: 'error',id: 'one',showCloseButton: true,actions:{cancel: {label: 'Leave me a message',action: function(){window.location.href = '../';}}}});}
  147. $(function() {if (window.location.hash.indexOf("chat") !== -1) {$('.chat').modal('show');}});
  148. </script>
  149. <?php }
  150. }
  151. function dw_deliver_form_mail() {
  152. if ( isset( $_POST['dw-contact'] ) ) {
  153. $fname = sanitize_text_field( $_POST["dw-fname"] );
  154. $lname = sanitize_text_field( $_POST["dw-lname"] );
  155. $email = sanitize_email( $_POST["dw-email"] );
  156. $subject = sanitize_text_field( $_POST["dw-org"] );
  157. $message = esc_textarea( $_POST["dw-message"] );
  158. $to = get_option( 'admin_email' );
  159. $headers = "From: $fname $lname <$email>" . "\r\n";
  160. if ( wp_mail( $to, $subject, $message, $headers ) ) {
  161. echo '<div class="alert alert-success" role="alert">';
  162. echo '<p>Thank you. I will be in touch.</p>';
  163. echo '</div>';
  164. }
  165. else {
  166. echo '<div class="alert alert-danger" role="alert">';
  167. echo '<p>Error, please try again</p>';
  168. echo '</div>';
  169. }
  170. }
  171. }
  172. add_shortcode('dwsearch', 'get_search_form');
  173. function doctype_opengraph($output) {
  174. return $output . '
  175. xmlns:og="http://opengraphprotocol.org/schema/"
  176. xmlns:fb="http://www.facebook.com/2008/fbml"';
  177. }
  178. add_filter('language_attributes', 'doctype_opengraph');
  179. function dw_opengraph() {
  180. global $post;
  181. if (is_single()) {
  182. if (has_post_thumbnail($post->ID)) {
  183. $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'full'); $img_src = $img_src[0];
  184. } elseif ( metadata_exists( 'post', get_the_ID(), 'featured_image_url' ) ){
  185. $img_src = get_post_meta( get_the_ID(), 'featured_image_url', true );
  186. } else {
  187. $img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
  188. }
  189. if($excerpt = $post->post_excerpt) {
  190. $excerpt = strip_tags($post->post_excerpt);
  191. $excerpt = str_replace("", "'", $excerpt);
  192. } else {
  193. $excerpt = get_bloginfo('description');
  194. }
  195. ?>
  196. <meta property="og:title" content="<?php echo the_title(); ?>"/>
  197. <meta property="og:description" content="<?php echo $excerpt; ?>"/>
  198. <meta property="og:type" content="article"/>
  199. <meta property="og:url" content="<?php echo the_permalink(); ?>"/>
  200. <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
  201. <meta property="og:image" content="<?php echo $img_src; ?>"/>
  202. <meta property="fb:app_id" content="203136806559589" />
  203. <meta name="twitter:site" content="@windhamdavid">
  204. <meta name="twitter:creator" content="@windhamdavid">
  205. <meta name="twitter:title" content="<?php echo the_title(); ?>">
  206. <meta name="twitter:description" content="<?php echo $excerpt; ?>">
  207. <meta name="twitter:image" content="<?php echo $img_src; ?>">
  208. <?php
  209. } else {
  210. return;
  211. }
  212. $content = do_shortcode( apply_filters( 'the_content', $post->post_content ) );
  213. $media_url = get_post_meta( get_the_ID(), 'media', true );
  214. $media = get_media_embedded_in_content( $content );
  215. if( !empty($media) ) {
  216. $video_url = $media[0];
  217. ?>
  218. <meta property="og:video" content="<?php echo $media_url; ?>" />
  219. <meta property="og:video:secure_url" content="<?php echo $media_url; ?>" />
  220. <meta property="og:video:width" content="1280" />
  221. <meta property="og:video:height" content="720" />
  222. <meta property="og:video:type" content="video/mp4" />
  223. <meta name="twitter:card" content="player">
  224. <meta name="twitter:player" content="<?php echo get_permalink();?>container/" />
  225. <meta name="twitter:player:width" content="1280" />
  226. <meta name="twitter:player:height" content="720" />
  227. <meta name="twitter:player:stream" content="<?php echo $media_url; ?>" />
  228. <meta name="twitter:player:stream:content_type" content="video/mp4" />
  229. <?php
  230. } else {
  231. ?>
  232. <meta name="twitter:card" content="summary_large_image">
  233. <?php
  234. }
  235. }
  236. add_action('wp_head', 'dw_opengraph', 5);
  237. function dw_read_container_endpoint(){
  238. add_rewrite_endpoint( 'container', EP_PERMALINK);
  239. }
  240. add_action( 'init', 'dw_read_container_endpoint' );
  241. function dw_read_container_template( $template = '' ) {
  242. global $wp_query;
  243. if( ! array_key_exists( 'container', $wp_query->query_vars ) ) return $template;
  244. $template = locate_template( 'single-container.php' );
  245. return $template;
  246. }
  247. add_filter( 'single_template', 'dw_read_container_template' );
  248. function dw_video_embed( $attr, $content='' ) {
  249. if ( ! isset( $attr['poster'] ) && has_post_thumbnail() ) {
  250. $poster = get_post_meta( get_the_ID(), 'media-poster', true );
  251. $attr['poster'] = $poster;
  252. }
  253. return wp_video_shortcode( $attr, $content );
  254. }
  255. add_shortcode( 'video', 'dw_video_embed' );
  256. ?>