tweaks.php 12 KB

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