PageRenderTime 107ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/functions.php

https://gitlab.com/gpinela/proin-theme
PHP | 437 lines | 213 code | 64 blank | 160 comment | 18 complexity | 39e88188f0b9dba6185acc8125bce732 MD5 | raw file
  1. <?php
  2. /**
  3. * Proin functions and definitions
  4. *
  5. * @package Proin
  6. * @subpackage Proin
  7. * @since Proin 1.0
  8. */
  9. // Hides the admin bar, it shows over the navbar
  10. show_admin_bar( false );
  11. // Register Custom Navigation Walker
  12. require_once('inc/wp_bootstrap_navwalker.php');
  13. // require instagram plugin
  14. require_once('inc/wp-instagram-widget.php');
  15. add_filter( 'wp_generate_tag_cloud_data', 'proin_tag_cloud_data');
  16. function proin_tag_cloud_data( $tags_data ) {
  17. foreach ( $tags_data as $key => $tag ) {
  18. // get tag count
  19. $count = $tag [ 'real_count' ];
  20. // adjust the class based on the size
  21. $tags_data[$key]['class'] .= ' label label-big label-default';
  22. $tags_data[$key]['font_size'] = '';
  23. }
  24. // return adjusted data
  25. return $tags_data;
  26. }
  27. if ( ! function_exists( 'proin_setup' ) ) :
  28. /**
  29. * Proin setup.
  30. *
  31. * Set up theme defaults and registers support for various WordPress features.
  32. *
  33. * @since Proin 1.0
  34. */
  35. function proin_setup() {
  36. // Enable support for Post Thumbnails, and declare two sizes.
  37. add_theme_support( 'post-thumbnails' );
  38. set_post_thumbnail_size( 360, 192, true );
  39. // add_image_size( 'twentyfourteen-full-width', 1038, 576, true );
  40. // This theme uses wp_nav_menu() in two locations.
  41. register_nav_menus( array(
  42. 'primary' => 'Top primary menu'
  43. ) );
  44. /*
  45. * Switch default core markup for search form, comment form, and comments
  46. * to output valid HTML5.
  47. */
  48. add_theme_support( 'html5', array(
  49. 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
  50. ) );
  51. /*
  52. * Enable support for Post Formats.
  53. * See https://codex.wordpress.org/Post_Formats
  54. */
  55. add_theme_support( 'post-formats', array(
  56. 'aside'
  57. ) );
  58. // Add support for featured content.
  59. add_theme_support( 'featured-content', array(
  60. 'featured_content_filter' => 'twentyfourteen_get_featured_posts',
  61. 'max_posts' => 3,
  62. ) );
  63. }
  64. endif; // proin setup
  65. add_action( 'after_setup_theme', 'proin_setup' );
  66. /**
  67. * Getter function for Featured Content Plugin.
  68. *
  69. * @since Proin 1.0
  70. *
  71. * @return array An array of WP_Post objects.
  72. */
  73. function twentyfourteen_get_featured_posts() {
  74. /**
  75. * Filter the featured posts to return in Twenty Fourteen.
  76. *
  77. * @since Twenty Fourteen 1.0
  78. *
  79. * @param array|bool $posts Array of featured posts, otherwise false.
  80. */
  81. return apply_filters( 'twentyfourteen_get_featured_posts', array() );
  82. }
  83. /**
  84. * A helper conditional function that returns a boolean value.
  85. *
  86. * @since Proin 1.0
  87. *
  88. * @return bool Whether there are featured posts.
  89. */
  90. function twentyfourteen_has_featured_posts() {
  91. return ! is_paged() && (bool) twentyfourteen_get_featured_posts();
  92. }
  93. /**
  94. * Register widget areas and register widgets.
  95. * @since Proin 1.0
  96. */
  97. function proin_widgets_init() {
  98. require_once('inc/widget-proin-recent-posts.php');
  99. register_widget('Widget_Proin_Recent_Posts');
  100. register_sidebar( array(
  101. 'name' => 'Primary Sidebar',
  102. 'id' => 'sidebar-1',
  103. 'description' => 'Main sidebar that appears on the left.',
  104. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  105. 'after_widget' => '</aside>',
  106. 'before_title' => '<div class="border-bottom widget-title"><strong class="text-muted">',
  107. 'after_title' => '</strong></div>',
  108. ));
  109. register_sidebar( array(
  110. 'name' => 'Footer Sidebar',
  111. 'id' => 'sidebar-2',
  112. 'description' => 'Appears in the footer section of the site, don\'t put more than 3 widgets here!.',
  113. 'before_widget' => '<div class="col-lg-4">',
  114. 'after_widget' => '</div>',
  115. 'before_title' => '<h5 class="widget-title">',
  116. 'after_title' => '</h5>',
  117. ));
  118. }
  119. add_action( 'widgets_init', 'proin_widgets_init' );
  120. /**
  121. * Register Lato Google font for Twenty Fourteen.
  122. *
  123. * @since Twenty Fourteen 1.0
  124. *
  125. * @return string
  126. */
  127. function twentyfourteen_font_url() {
  128. $font_url = '';
  129. /*
  130. * Translators: If there are characters in your language that are not supported
  131. * by Lato, translate this to 'off'. Do not translate into your own language.
  132. */
  133. if ( 'off' !== _x( 'on', 'Lato font: on or off', 'twentyfourteen' ) ) {
  134. $query_args = array(
  135. 'family' => urlencode( 'Lato:300,400,700,900,300italic,400italic,700italic' ),
  136. 'subset' => urlencode( 'latin,latin-ext' ),
  137. );
  138. $font_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  139. }
  140. return $font_url;
  141. }
  142. /**
  143. * Enqueue scripts and styles for the front end.
  144. *
  145. * @since Proin 1.0
  146. */
  147. function proin_scripts() {
  148. // Add Material Design fonts.
  149. wp_enqueue_style( 'material-design', 'http://fonts.googleapis.com/css?family=Roboto:300,400,500,700');
  150. wp_enqueue_style( 'material-design-icons', 'https://fonts.googleapis.com/icon?family=Material+Icons');
  151. // Add Bootstrap
  152. wp_enqueue_style( 'Bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
  153. // Add Bootstrap Material Design
  154. wp_enqueue_style( 'Bootstrap-Material', 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/0.5.7/css/bootstrap-material-design.min.css');
  155. wp_enqueue_style( 'Bootstrap-Material-Ripples', 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/0.5.7/css/ripples.min.css' );
  156. // Add Font awesome
  157. wp_enqueue_style( 'Font-Awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css');
  158. // Add Owl carrousel
  159. wp_enqueue_style( 'owl.carousel.css', get_template_directory_uri().'/css/owl.carousel.css');
  160. wp_enqueue_style( 'Owl-Carrousel-theme', get_template_directory_uri().'/css/owl.theme.css');
  161. // Load our main stylesheet.
  162. wp_enqueue_style( 'proin-style', get_stylesheet_uri() );
  163. wp_enqueue_script( 'app', get_template_directory_uri() . '/js/app.js', array(), false, true );
  164. if( is_front_page() )
  165. {
  166. wp_enqueue_script( 'chart-js', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js' );
  167. wp_enqueue_script( 'front-page', get_template_directory_uri() . '/js/front-page.js', array(), false, true );
  168. wp_enqueue_style( 'front-page-css', get_template_directory_uri().'/css/front-page.css' );
  169. }
  170. /*
  171. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  172. wp_enqueue_script( 'comment-reply' );
  173. }*/
  174. /*
  175. if ( is_singular() && wp_attachment_is_image() ) {
  176. wp_enqueue_script( 'twentyfourteen-keyboard-image-navigation',wp_enqueue_script( 'comment-reply' );, array( 'jquery' ), '20130402' );
  177. }*/
  178. /*
  179. if ( is_front_page() && 'slider' == get_theme_mod( 'featured_content_layout' ) ) {
  180. wp_enqueue_script( 'twentyfourteen-slider', get_template_directory_uri() . '/js/slider.js', array( 'jquery' ), '20131205', true );
  181. wp_localize_script( 'twentyfourteen-slider', 'featuredSliderDefaults', array(
  182. 'prevText' => __( 'Previous', 'twentyfourteen' ),
  183. 'nextText' => __( 'Next', 'twentyfourteen' )
  184. ) );
  185. }*/
  186. //wp_enqueue_script( 'proin-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150315', true );
  187. }
  188. add_action( 'wp_enqueue_scripts', 'proin_scripts' );
  189. if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) :
  190. /**
  191. * Print the attached image with a link to the next attached image.
  192. *
  193. * @since Twenty Fourteen 1.0
  194. */
  195. function twentyfourteen_the_attached_image() {
  196. $post = get_post();
  197. /**
  198. * Filter the default Twenty Fourteen attachment size.
  199. *
  200. * @since Twenty Fourteen 1.0
  201. *
  202. * @param array $dimensions {
  203. * An array of height and width dimensions.
  204. *
  205. * @type int $height Height of the image in pixels. Default 810.
  206. * @type int $width Width of the image in pixels. Default 810.
  207. * }
  208. */
  209. $attachment_size = apply_filters( 'twentyfourteen_attachment_size', array( 810, 810 ) );
  210. $next_attachment_url = wp_get_attachment_url();
  211. /*
  212. * Grab the IDs of all the image attachments in a gallery so we can get the URL
  213. * of the next adjacent image in a gallery, or the first image (if we're
  214. * looking at the last image in a gallery), or, in a gallery of one, just the
  215. * link to that image file.
  216. */
  217. $attachment_ids = get_posts( array(
  218. 'post_parent' => $post->post_parent,
  219. 'fields' => 'ids',
  220. 'numberposts' => -1,
  221. 'post_status' => 'inherit',
  222. 'post_type' => 'attachment',
  223. 'post_mime_type' => 'image',
  224. 'order' => 'ASC',
  225. 'orderby' => 'menu_order ID',
  226. ) );
  227. // If there is more than 1 attachment in a gallery...
  228. if ( count( $attachment_ids ) > 1 ) {
  229. foreach ( $attachment_ids as $attachment_id ) {
  230. if ( $attachment_id == $post->ID ) {
  231. $next_id = current( $attachment_ids );
  232. break;
  233. }
  234. }
  235. // get the URL of the next image attachment...
  236. if ( $next_id ) {
  237. $next_attachment_url = get_attachment_link( $next_id );
  238. }
  239. // or get the URL of the first image attachment.
  240. else {
  241. $next_attachment_url = get_attachment_link( reset( $attachment_ids ) );
  242. }
  243. }
  244. printf( '<a href="%1$s" rel="attachment">%2$s</a>',
  245. esc_url( $next_attachment_url ),
  246. wp_get_attachment_image( $post->ID, $attachment_size )
  247. );
  248. }
  249. endif;
  250. if ( ! function_exists( 'twentyfourteen_list_authors' ) ) :
  251. /**
  252. * Print a list of all site contributors who published at least one post.
  253. *
  254. * @since Twenty Fourteen 1.0
  255. */
  256. function twentyfourteen_list_authors() {
  257. $contributor_ids = get_users( array(
  258. 'fields' => 'ID',
  259. 'orderby' => 'post_count',
  260. 'order' => 'DESC',
  261. 'who' => 'authors',
  262. ));
  263. foreach ( $contributor_ids as $contributor_id ) :
  264. $post_count = count_user_posts( $contributor_id );
  265. // Move on if user has not published a post (yet).
  266. if ( ! $post_count ) {
  267. continue;
  268. }
  269. ?>
  270. <div class="contributor">
  271. <div class="contributor-info">
  272. <div class="contributor-avatar"><?php echo get_avatar( $contributor_id, 132 ); ?></div>
  273. <div class="contributor-summary">
  274. <h2 class="contributor-name"><?php echo get_the_author_meta( 'display_name', $contributor_id ); ?></h2>
  275. <p class="contributor-bio">
  276. <?php echo get_the_author_meta( 'description', $contributor_id ); ?>
  277. </p>
  278. <a class="button contributor-posts-link" href="<?php echo esc_url( get_author_posts_url( $contributor_id ) ); ?>">
  279. <?php printf( _n( '%d Article', '%d Articles', $post_count, 'twentyfourteen' ), $post_count ); ?>
  280. </a>
  281. </div><!-- .contributor-summary -->
  282. </div><!-- .contributor-info -->
  283. </div><!-- .contributor -->
  284. <?php
  285. endforeach;
  286. }
  287. endif;
  288. // Custom template tags for this theme.
  289. require get_template_directory() . '/inc/template-tags.php';
  290. // Add Customizer functionality.
  291. require get_template_directory() . '/inc/customizer.php';
  292. /*
  293. * Add Featured Content functionality.
  294. *
  295. * To overwrite in a plugin, define your own Featured_Content class on or
  296. * before the 'setup_theme' hook.
  297. */
  298. if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
  299. require get_template_directory() . '/inc/featured-content.php';
  300. }
  301. // Bootstrap pagination function
  302. if ( ! function_exists( 'proin_paging_nav' ) ) :
  303. /**
  304. * Display pagination using bootstrap navigation
  305. *
  306. * @since Proin 1.0
  307. *
  308. */
  309. function proin_paging_nav() {
  310. global $wp_query, $wp_rewrite;
  311. // Don't print empty markup if there's only one page.
  312. if ( $wp_query->max_num_pages < 2 ) {
  313. //return;
  314. }
  315. $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
  316. $pagenum_link = html_entity_decode( get_pagenum_link() );
  317. //$query_args = array();
  318. //$url_parts = explode( '?', $pagenum_link );
  319. //if ( isset( $url_parts[1] ) ) {
  320. // wp_parse_str( $url_parts[1], $query_args );
  321. //}
  322. $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  323. $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
  324. // Set up paginated links.
  325. $links = paginate_links( array(
  326. 'format' => $format,
  327. 'total' => $wp_query->max_num_pages,
  328. 'current' => $paged,
  329. 'mid_size' => 4,
  330. //'add_args' => array_map( 'urlencode', $query_args ),
  331. 'prev_text' => '&larr; Previous',
  332. 'next_text' => 'Next &rarr;',
  333. 'type' => 'array'
  334. ) );
  335. if ( $links ) :
  336. ?>
  337. <div class="text-center" role="navigation">
  338. <ul class="pagination">
  339. <?php foreach($links as $link): ?>
  340. <?php echo "<li>".$link."</li>";?>
  341. <?php endforeach; ?>
  342. </ul>
  343. </div>
  344. <?php
  345. endif;
  346. }
  347. endif;
  348. /*
  349. * Twitter widget filter for overriding date and format
  350. */
  351. add_filter('latest_tweets_render_date', function( $created_at ){
  352. $date = DateTime::createFromFormat('D M d H:i:s O Y', $created_at );
  353. return 'Hace '.human_time_diff($date->getTimestamp());
  354. }, 10 , 1 );
  355. add_filter('latest_tweets_render_tweet', function( $html, $date, $link, array $tweet ){
  356. return "$html<p class='light'><i class='material-icons'>schedule</i>$date</p>";
  357. }, 10, 4 );
  358. add_filter('widget_title_pages', function(){ return "asd"; });
  359. /*
  360. * Instagram widget filter for overriding behaviour
  361. */
  362. add_filter('null_instagram_cache_time', 'my_cache_time');
  363. function my_cache_time() {
  364. return 0;
  365. }
  366. //add_filter( 'wpiw_item_class', 'my_instagram_class' );
  367. add_filter( 'wpiw_a_class', 'my_instagram_class' );
  368. add_filter( 'wpiw_img_class', 'my_instagram_class' );
  369. function my_instagram_class( $classes ) {
  370. $classes = "instagram-image";
  371. return $classes;
  372. }