Advertisement
ovizii

functions.php

Feb 26th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.64 KB | None | 0 0
  1. <?php
  2.  
  3. add_action( 'after_setup_theme', 'premaman_theme_setup', 11 );
  4.  
  5. function premaman_theme_setup() {
  6.       //remove the built-in SEO functions
  7.       remove_theme_support('hybrid-core-seo');
  8.       //removing and improving the excerpt
  9.       remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  10.       add_filter('get_the_excerpt', 'improved_trim_excerpt');
  11.       /*modify breadcrumb trail for show pages*/
  12.       add_filter( 'breadcrumb_trail_args', 'my_breadcrumb_trail_args' );
  13.           /*preparing the theme for woocommerce*/
  14.       add_action( 'wp_head', 'mytheme_prepare_woocommerce_wrappers' );
  15.       // Remove WooCommerce sidebar
  16.       remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
  17.       //remove http links in the admin bar
  18.       add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
  19.       /*hide stuff from the profile page*/
  20.       add_action( 'admin_print_scripts-profile.php', 'hideUserChoice' );
  21.       add_filter('user_contactmethods','hide_profile_fields',10,1);
  22.       add_filter( 'hybrid_byline', 'my_byline' );
  23.       add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 12;' ), 20 );
  24.       add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 20 );
  25.       remove_action('woocommerce_pagination', 'woocommerce_catalog_ordering', 20 );
  26.       add_filter( 'woocommerce_states', 'SA_woocommerce_states' );
  27.       add_filter( 'gettext', 'my_gettext', 10, 3 );
  28.       //customizing the PDFs
  29.       add_filter('sod_pdf_header', 'sod_pdf_header_filter', 1, 4);
  30. }
  31.  
  32. /*improve the excerpt, keep HTML in there*/
  33. function improved_trim_excerpt($text) {
  34. global $post;
  35. if ( '' == $text ) {
  36. $text = get_the_content('');
  37. $text = apply_filters('the_content', $text);
  38. $text = str_replace(']]>', ']]&gt;', $text);
  39. /*uncomment the following line to strip javascript*/
  40. $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
  41. /*$text = strip_tags($text, '<p><a><img><ul><ol><li>[php][css][text][perl][shell]');*/
  42. $text = strip_tags($text, '<p><a><ul><ol><li>[php][css][text][perl][shell]');
  43. $excerpt_length = 500;
  44. $words = explode(' ', $text, $excerpt_length + 1);
  45. if (count($words)> $excerpt_length) {
  46. array_pop($words);
  47. array_push($words, '[...]');
  48. $text = implode(' ', $words);
  49. }
  50. }
  51. return $text;
  52. }
  53. function my_breadcrumb_trail_args( $args ) {
  54.  
  55.     $args['singular_product_taxonomy'] = 'product_category';
  56.  
  57.     return $args;
  58. }
  59. /*themeing wocommerce*/
  60. function mytheme_open_woocommerce_content_wrappers()
  61. {
  62.     echo '<div id="content" class="hfeed content">';
  63. }
  64.  
  65. function mytheme_close_woocommerce_content_wrappers()
  66. {
  67.     echo '</div>';
  68. }
  69.  
  70. function mytheme_prepare_woocommerce_wrappers()
  71. {
  72.     remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
  73.     remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
  74.     add_action( 'woocommerce_before_main_content', 'mytheme_open_woocommerce_content_wrappers', 10 );
  75.     add_action( 'woocommerce_after_main_content', 'mytheme_close_woocommerce_content_wrappers', 10 );
  76. }
  77. //removing stuff from the admin bar
  78. function remove_admin_bar_links() {
  79.     global $wp_admin_bar;
  80.     $wp_admin_bar->remove_menu('wp-logo');
  81.     $wp_admin_bar->remove_menu('updates');
  82. }
  83. //don't show the user any choice about the admin bar in the back end   
  84.     function hideUserChoice() { ?>
  85.     <style type="text/css">
  86.     .show-admin-bar { display: none; }
  87.     </style>
  88.     <?php
  89.     }
  90. // remove aim, jabber, yim  from the profile page
  91.     function hide_profile_fields( $contactmethods ) {
  92.     unset($contactmethods['aim']);
  93.     unset($contactmethods['jabber']);
  94.     unset($contactmethods['yim']);
  95.     return $contactmethods;
  96.     }
  97. //custom byline
  98. //my custom byline
  99. function my_byline( $byline ) {
  100.     global $post;
  101.    $byline = '<p class="byline">on the [entry-published] [entry-edit-link before="| "]</p>';
  102.     return $byline;
  103. }
  104. //trying to show 4 related products and only one row of them
  105. // Redefine woocommerce_output_related_products()
  106. function woocommerce_output_related_products() {
  107. woocommerce_related_products(4,1); // Display 3 products in rows of 3
  108. }
  109. //add ZA provinces to woocommerce
  110. function SA_woocommerce_states( $states ) {
  111.  
  112.   $states['ZA'] = array(
  113.                 'EC' => __('Eastern Cape', 'woocommerce') ,
  114.                 'FS' => __('Free State', 'woocommerce') ,
  115.                 'GP' => __('Gauteng', 'woocommerce') ,
  116.                 'KZN' => __('KwaZulu-Natal', 'woocommerce') ,
  117.                 'LP' => __('Limpopo', 'woocommerce') ,
  118.                 'MP' => __('Mpumalanga', 'woocommerce') ,
  119.                 'NC' => __('Northern Cape', 'woocommerce') ,
  120.                 'NW' => __('North West', 'woocommerce') ,
  121.                 'WC' => __('Western Cape', 'woocommerce')
  122.   );
  123.  
  124.   return $states;
  125. }
  126. //change Sort code into Branch code for woocommerce
  127. function my_gettext( $translation, $text, $domain ) {
  128.     if ( 'woocommerce' === $domain ) {
  129.         $translations = &get_translations_for_domain( $domain );
  130.     if ( 'Sort Code' === $text )
  131.         $translation = $translations->translate( 'Branch Code' );
  132.     }
  133.     return $translation;
  134. }
  135.  
  136. //customizing the PDFs
  137. function sod_pdf_header_filter($html, $logo, $woo, $order_num){
  138.    
  139.     $html = '<table class="header">' .
  140.                          '<tr>' .
  141.                             '<td class="logo left half">' . $logo . '</td>' .
  142.                             '<td class="right half">
  143.                                 <h3 class="labels" style="margin-right:73px;">Invoice</h3>
  144.                                 <table>
  145.                                 <tr>
  146.                                     <td class="right">'.__('Date: ', 'sod_wc_pdf_invoices').'</td>
  147.                                     <td><span class="left">' . gmdate( "d.m.Y" , strtotime( $woo->order_date ) ) . '</span></td>
  148.                                 </tr>
  149.                                 <tr>
  150.                                     <td class="right">'.__('Invoice: ', 'sod_wc_pdf_invoices').'</td>
  151.                                     <td>'.$order_num.'</td>
  152.                                 </tr>
  153.                                 </table>
  154.                             </td>
  155.                         </tr>
  156.                 </table>';
  157.         return $html;
  158. }
  159.  
  160. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement