tweaks.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. remove_action('wp_head', 'index_rel_link' );
  3. remove_action('wp_head', 'rel_canonical');
  4. remove_action('wp_head', 'start_post_rel_link', 10);
  5. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
  6. remove_action('wp_head', 'wp_shortlink_wp_head', 10);
  7. remove_action('wp_head', 'parent_post_rel_link', 10);
  8. remove_action('wp_head', 'rsd_link');
  9. remove_action('wp_head', 'wlwmanifest_link');
  10. remove_action('wp_head', 'wp_generator');
  11. remove_action('wp_head', 'feed_links_extra', 3 );
  12. remove_action('wp_head', 'feed_links', 2 );
  13. remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
  14. remove_action('wp_head', 'wp_oembed_add_host_js', 10);
  15. function dw_remove_wp_ver_css_js( $src ) {
  16. if ( strpos( $src, 'ver=' ) )
  17. $src = remove_query_arg( 'ver', $src );
  18. return $src;
  19. }
  20. add_filter( 'style_loader_src', 'dw_remove_wp_ver_css_js', 9999 );
  21. add_filter( 'script_loader_src', 'dw_remove_wp_ver_css_js', 9999 );
  22. add_filter( 'xmlrpc_enabled', '__return_false' );
  23. add_filter( 'wp_headers', 'disable_x_pingback' );
  24. function disable_x_pingback( $headers ) {
  25. unset( $headers['X-Pingback'] );
  26. return $headers;
  27. }
  28. function disable_emojis_tinymce( $plugins ) {
  29. if ( is_array( $plugins ) ) {
  30. return array_diff( $plugins, array( 'wpemoji' ) );
  31. } else {
  32. return array();
  33. }
  34. }
  35. function disable_emojis() {
  36. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  37. remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  38. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  39. remove_action( 'admin_print_styles', 'print_emoji_styles' );
  40. remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  41. remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  42. remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  43. add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
  44. add_filter( 'emoji_svg_url', '__return_false' );
  45. }
  46. add_action( 'init', 'disable_emojis' );
  47. function custom_excerpt_length( $length ) {
  48. return 20;
  49. }
  50. add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
  51. add_filter('wp_mail_from', 'dw_fromemail');
  52. function dw_fromemail($email) {
  53. $wpfrom = get_option('admin_email');
  54. return $wpfrom;
  55. }
  56. add_filter('wp_mail_from_name', 'dw_fromname');
  57. function dw_fromname($email){
  58. $wpfrom = get_option('blogname');
  59. return $wpfrom;
  60. }
  61. add_filter( 'embed_oembed_html', 'dw_oembed_filter', 10, 4 ) ;
  62. function dw_oembed_filter($html, $url, $attr, $post_ID) {
  63. $return = '<div class="video-container">'.$html.'</div>';
  64. $return = str_replace('frameborder="0" allowfullscreen', 'style="border:none"', $return);
  65. return $return;
  66. }
  67. add_filter( 'embed_oembed_html', 'dw_embed_oembed_html' );
  68. function dw_embed_oembed_html( $html ) {
  69. return preg_replace( '@src="https?:@', 'src="', $html );
  70. }
  71. add_action( 'admin_menu', 'daw_is_online_add_admin_menu' );
  72. add_action( 'admin_init', 'daw_is_online_settings_init' );
  73. function daw_is_online_add_admin_menu( ) {
  74. add_options_page( 'DW Status', 'DAW Online', 'manage_options', 'daw_is_online', 'daw_is_online_options_page' );
  75. }
  76. function daw_is_online_settings_init( ) {
  77. register_setting( 'dwstatus', 'daw_is_online_settings' );
  78. add_settings_section('daw_is_online_pluginPage_section', __( 'DAW Online', 'wordpress' ), 'daw_is_online_settings_section_callback', 'dwstatus');
  79. 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' );
  80. }
  81. function daw_is_online_select_field_0_render( ) {
  82. $options = get_option( 'daw_is_online_settings' ); ?>
  83. <select name='daw_is_online_settings[daw_is_online_select_field_0]'>
  84. <option value='1' <?php selected( $options['daw_is_online_select_field_0'], 1 ); ?>>Yes</option>
  85. <option value='2' <?php selected( $options['daw_is_online_select_field_0'], 2 ); ?>>No</option>
  86. </select>
  87. <?php }
  88. function daw_is_online_settings_section_callback( ) {
  89. echo __( 'This sets my online status', 'wordpress' );
  90. }
  91. function daw_is_online_options_page( ) { ?>
  92. <form action='options.php' method='post'>
  93. <?php settings_fields( 'dwstatus' );
  94. do_settings_sections( 'dwstatus' );
  95. submit_button(); ?>
  96. </form>
  97. <?php }
  98. function dw_online_get_status() {
  99. $dw_status = get_option('daw_is_online_settings');
  100. if( $dw_status['daw_is_online_select_field_0'] == '1' ) {
  101. wp_enqueue_style( 'message', get_template_directory_uri() . '/css/messenger.css');
  102. ?>
  103. <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>
  104. <?php }
  105. }
  106. function dw_online_get_chat() {
  107. $dw_status = get_option('daw_is_online_settings');
  108. if( $dw_status['daw_is_online_select_field_0'] == '1' ) { ?>
  109. <script type="text/javascript">
  110. Messenger.options = {extraClasses: "messenger-fixed messenger-on-bottom messenger-on-left",theme: "flat"};var i;i = 0;
  111. $(function(){
  112. var msg_return;
  113. msg_return = Messenger().run({
  114. id: 'one',
  115. errorMessage: 'Looking for David...',
  116. action: function(opts) {if (++i < 2) {get_dave();return opts.error({status: 500,readyState: 0,responseText: 0});}}});});
  117. 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);});}
  118. 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});}}});}
  119. 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 = '../';}}}});}
  120. 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 = '../';}}}});}
  121. $(function() {if (window.location.hash.indexOf("chat") !== -1) {$('.chat').modal('show');}});
  122. </script>
  123. <?php }
  124. }
  125. function dw_deliver_form_mail() {
  126. if ( isset( $_POST['dw-contact'] ) ) {
  127. $fname = sanitize_text_field( $_POST["dw-fname"] );
  128. $lname = sanitize_text_field( $_POST["dw-lname"] );
  129. $email = sanitize_email( $_POST["dw-email"] );
  130. $subject = sanitize_text_field( $_POST["dw-org"] );
  131. $message = esc_textarea( $_POST["dw-message"] );
  132. $to = get_option( 'admin_email' );
  133. $headers = "From: $fname $lname <$email>" . "\r\n";
  134. if ( wp_mail( $to, $subject, $message, $headers ) ) {
  135. echo '<div class="alert alert-success" role="alert">';
  136. echo '<p>Thank you. I will be in touch.</p>';
  137. echo '</div>';
  138. }
  139. else {
  140. echo '<div class="alert alert-danger" role="alert">';
  141. echo '<p>Error, please try again</p>';
  142. echo '</div>';
  143. }
  144. }
  145. }
  146. add_shortcode('dwsearch', 'get_search_form');
  147. function doctype_opengraph($output) {
  148. return $output . '
  149. xmlns:og="http://opengraphprotocol.org/schema/"
  150. xmlns:fb="http://www.facebook.com/2008/fbml"';
  151. }
  152. add_filter('language_attributes', 'doctype_opengraph');
  153. function dw_opengraph() {
  154. global $post;
  155. if (is_single()) {
  156. if (has_post_thumbnail($post->ID)) {
  157. $img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'full'); $img_src = $img_src[0];
  158. } elseif ( metadata_exists( 'post', get_the_ID(), 'featured_image_url' ) ){
  159. $img_src = get_post_meta( get_the_ID(), 'featured_image_url', true );
  160. } else {
  161. $img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
  162. }
  163. if($excerpt = $post->post_excerpt) {
  164. $excerpt = strip_tags($post->post_excerpt);
  165. $excerpt = str_replace("", "'", $excerpt);
  166. } else {
  167. $excerpt = get_bloginfo('description');
  168. }
  169. ?>
  170. <meta property="og:title" content="<?php echo the_title(); ?>"/>
  171. <meta property="og:description" content="<?php echo $excerpt; ?>"/>
  172. <meta property="og:type" content="article"/>
  173. <meta property="og:url" content="<?php echo the_permalink(); ?>"/>
  174. <meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
  175. <meta property="og:image" content="<?php echo $img_src; ?>"/>
  176. <meta property="fb:app_id" content="203136806559589" />
  177. <meta name="twitter:site" content="@windhamdavid">
  178. <meta name="twitter:creator" content="@windhamdavid">
  179. <meta name="twitter:title" content="<?php echo the_title(); ?>">
  180. <meta name="twitter:description" content="<?php echo $excerpt; ?>">
  181. <meta name="twitter:image" content="<?php echo $img_src; ?>">
  182. <?php
  183. } else {
  184. return;
  185. }
  186. $content = do_shortcode( apply_filters( 'the_content', $post->post_content ) );
  187. $media_url = get_post_meta( get_the_ID(), 'media', true );
  188. $media = get_media_embedded_in_content( $content );
  189. if( !empty($media) ) {
  190. $video_url = $media[0];
  191. ?>
  192. <meta property="og:video" content="<?php echo $media_url; ?>" />
  193. <meta property="og:video:secure_url" content="<?php echo $media_url; ?>" />
  194. <meta property="og:video:width" content="1280" />
  195. <meta property="og:video:height" content="720" />
  196. <meta property="og:video:type" content="video/mp4" />
  197. <meta name="twitter:card" content="player">
  198. <meta name="twitter:player" content="<?php echo get_permalink();?>container/" />
  199. <meta name="twitter:player:width" content="1280" />
  200. <meta name="twitter:player:height" content="720" />
  201. <meta name="twitter:player:stream" content="<?php echo $media_url; ?>" />
  202. <meta name="twitter:player:stream:content_type" content="video/mp4" />
  203. <?php
  204. } else {
  205. ?>
  206. <meta name="twitter:card" content="summary_large_image">
  207. <?php
  208. }
  209. }
  210. add_action('wp_head', 'dw_opengraph', 5);
  211. function dw_read_container_endpoint(){
  212. add_rewrite_endpoint( 'container', EP_PERMALINK);
  213. }
  214. add_action( 'init', 'dw_read_container_endpoint' );
  215. function dw_read_container_template( $template = '' ) {
  216. global $wp_query;
  217. if( ! array_key_exists( 'container', $wp_query->query_vars ) ) return $template;
  218. $template = locate_template( 'single-container.php' );
  219. return $template;
  220. }
  221. add_filter( 'single_template', 'dw_read_container_template' );
  222. function dw_video_embed( $attr, $content='' ) {
  223. if ( ! isset( $attr['poster'] ) && has_post_thumbnail() ) {
  224. $poster = get_post_meta( get_the_ID(), 'media-poster', true );
  225. $attr['poster'] = $poster;
  226. }
  227. return wp_video_shortcode( $attr, $content );
  228. }
  229. add_shortcode( 'video', 'dw_video_embed' );
  230. ?>