PageRenderTime 23ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/extras.php

https://gitlab.com/WPTRT/doingitwrong
PHP | 203 lines | 138 code | 23 blank | 42 comment | 12 complexity | 5174cbccdc993de5be835497cb0766a1 MD5 | raw file
  1. <?php
  2. /**
  3. * Custom functions that act independently of the theme templates
  4. *
  5. * Eventually, some of the functionality here could be replaced by core features
  6. *
  7. * @package nopasare
  8. */
  9. /**
  10. * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
  11. *
  12. * @param array $args Configuration arguments.
  13. * @return array
  14. */
  15. function wrong_page_menu_args( $args ) {
  16. $args['show_home'] = true;
  17. return $args;
  18. }
  19. add_filter( 'wp_page_menu_args', 'wrong_page_menu_args' );
  20. /**
  21. * Adds custom classes to the array of body classes.
  22. *
  23. * @param array $classes Classes for the body element.
  24. * @return array
  25. */
  26. function wrong_body_classes( $classes ) {
  27. // Adds a class of group-blog to blogs with more than 1 published author.
  28. if ( is_multi_author() ) {
  29. $classes[] = 'group-blog';
  30. }
  31. if ( is_front_page() ) {
  32. $classes[] = 'has-slider';
  33. }
  34. return $classes;
  35. }
  36. add_filter( 'body_class', 'wrong_body_classes' );
  37. /**
  38. * Filters wp_title to print a neat <title> tag based on what is being viewed.
  39. *
  40. * @param string $title Default title text for current view.
  41. * @param string $sep Optional separator.
  42. * @return string The filtered title.
  43. */
  44. function wrong_wp_title( $title, $sep ) {
  45. if ( is_feed() ) {
  46. return $title;
  47. }
  48. global $page, $paged;
  49. // Add the blog name
  50. $title .= get_bloginfo( 'name', 'display' );
  51. // Add the blog description for the home/front page.
  52. $site_description = get_bloginfo( 'description', 'display' );
  53. if ( $site_description && ( is_home() || is_front_page() ) ) {
  54. $title .= " $sep $site_description";
  55. }
  56. // Add a page number if necessary:
  57. if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
  58. $title .= " $sep " . sprintf( __( 'Page %s', 'nopasare' ), max( $paged, $page ) );
  59. }
  60. return $title;
  61. }
  62. add_filter( 'wp_title', 'wrong_wp_title', 10, 2 );
  63. /**
  64. * Sets the authordata global when viewing an author archive.
  65. *
  66. * This provides backwards compatibility with
  67. * http://core.trac.wordpress.org/changeset/25574
  68. *
  69. * It removes the need to call the_post() and rewind_posts() in an author
  70. * template to print information about the author.
  71. *
  72. * @global WP_Query $wp_query WordPress Query object.
  73. * @return void
  74. */
  75. function wrong_setup_author() {
  76. global $wp_query;
  77. if ( $wp_query->is_author() && isset( $wp_query->post ) ) {
  78. $GLOBALS['authordata'] = get_userdata( $wp_query->post->post_author );
  79. }
  80. }
  81. add_action( 'wp', 'wrong_setup_author' );
  82. global $wp_embed;
  83. add_filter( 'the_excerpt', array( $wp_embed, 'autoembed' ), 9 );
  84. function add_linkpages_content( $content ) {
  85. $pages = wp_link_pages(
  86. array(
  87. 'before' => '<div>' . __( 'Page: ', 'wrong' ),
  88. 'after' => '</div>',
  89. 'echo' => false,
  90. )
  91. );
  92. if ( ! $pages ) {
  93. return $content . $pages;
  94. }
  95. return $content;
  96. }
  97. add_filter( 'the_content', 'add_linkpages_content' );
  98. add_filter( 'the_password_form', 'my_password_form' );
  99. function my_password_form() {
  100. global $post;
  101. $form = '
  102. <form class="password-form" action="/wp-login.php?action=postpass" method="post">
  103. <p>' . __( 'This post is password protected. To read it please enter the password below.' ) . '</p>
  104. <input type="password" value="" name="post_password" id="password-' . $post->ID . '"/>
  105. </form>';
  106. return $form;
  107. }
  108. add_action( 'widgets_init', 'extended_archive_widget' );
  109. function extended_archive_widget() {
  110. register_widget( 'x_archives' );
  111. }
  112. class x_archives extends WP_Widget
  113. {
  114. function __construct() {
  115. $widget_ops = array(
  116. 'classname' => 'archives_extended',
  117. 'description' => 'Extended archives with additional options.',
  118. );
  119. parent::__construct( 'x_archive_widget', 'Archives', $widget_ops );
  120. } # __construct()
  121. function widget( $args, $instance ) {
  122. extract( $args );
  123. $limit = ( empty( $instance['limit'] ) ) ? '12' : $instance['limit'];
  124. $type = ( empty( $instance['type'] ) ) ? 'monthly' : $instance['type'];
  125. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base );
  126. $content = wp_get_archives( array(
  127. 'type' => $type,
  128. 'limit' => $limit,
  129. 'format' => 'html',
  130. 'before' => '',
  131. 'after' => '',
  132. 'show_post_count' => false,
  133. 'echo' => 0,
  134. 'order' => 'DESC',
  135. ) );
  136. $output = $before_widget . $before_title . $title . $after_title . '<ul class="archive">' . $content .'</ul>' . $after_widget;
  137. echo $output;
  138. } # widget()
  139. function update( $new_instance, $old_instance ) {
  140. $instance = $old_instance;
  141. $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => 'Archives', 'type' => '', 'limit' => '' ) );
  142. $instance['title'] = $new_instance['title'];
  143. $instance['limit'] = $new_instance['limit'];
  144. $instance['type'] = $new_instance['type'];
  145. return $instance;
  146. }
  147. function form( $instance ) {
  148. $instance = wp_parse_args( (array) $instance, array( 'title', 'limit', 'type' ) );
  149. $title = $instance['title'];
  150. $limit = $instance['limit'];
  151. $type = $instance['type'];
  152. $types = array(
  153. 'Post' => 'postbypost',
  154. 'Daily' => 'daily',
  155. 'Weekly' => 'weekly',
  156. 'Monthly' => 'monthly',
  157. ); ?>
  158. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  159. <input id="<?php echo $this->get_field_id( 'title' ); ?>" class="widefat" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
  160. <label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e( 'Limit:' ); ?></label>
  161. <input id="<?php echo $this->get_field_id( 'limit' ); ?>" class="widefat" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo $limit; ?>" />
  162. <label for="<?php echo $this->get_field_id( 'type' ); ?>"><?php _e( 'Type:' ); ?></label>
  163. <select id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>">
  164. <?php foreach ( $types as $key => $typo ) {
  165. echo '<option value=' . $typo;
  166. selected( $type, $typo );
  167. echo ">$key</option>";
  168. } ?>
  169. </select>
  170. <?php
  171. } # form()
  172. } # widget class
  173. add_action( 'theme_footer_section', 'my_theme_extra_footer' );
  174. function my_theme_extra_footer() {
  175. echo get_theme_mod( 'footer_setting', 'Add additional information here' );
  176. }
  177. remove_action( 'wp_head', 'feed_links_extra', 3 );
  178. remove_action( 'wp_head', 'feed_links', 2 );
  179. update_option( 'thumbnail_size_w', 460 );
  180. update_option( 'thumbnail_size_h', 460 );