Cotswold Photo WordPress functions.php file

Facebooktwittergoogle_plusredditpinterestlinkedintumblrFacebooktwittergoogle_plusredditpinterestlinkedintumblr

A simple post. Some of you have asked me what I have in the Cotswold Photo WordPress functions.php file for our child theme (called Togger). So here it is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php 
$theme = array(
  'theme_name' => 'Togger',
  'theme_slug' => 'togger',
);
 
require_once( get_template_directory() . '/wonderfoundry/wonderworks.php' );
 
add_action( 'wp_enqueue_scripts', 'cp_manage_styles_and_scripts', 99 );
 
function cp_manage_styles_and_scripts() {
// remove PrettyPhoto css from Ultimatum
  wp_deregister_style( 'prettyphoto' );
  wp_dequeue_style( 'prettyphoto' );
  wp_dequeue_style( 'ubermenu-basic' );
  wp_deregister_style( 'ubermenu-basic' );
//ultimatum loads prettyphoto scripts that need to be disabled
  wp_dequeue_script( 'fancybox' );
  wp_deregister_script( 'fancybox' );
  wp_dequeue_script( 'enable-lightbox' );
  wp_deregister_script( 'enable-lightbox' );
  wp_dequeue_script( 'lightbox-script' );
  wp_deregister_script( 'lightbox-script' );
  wp_dequeue_script( 'jquery-prettyphoto' );
  wp_deregister_script( 'jquery-prettyphoto' );
// Add Darkly themed Ubermenu style sheet
  wp_register_style( 'ubermenu_cp', get_stylesheet_directory_uri() . '/css/ubermenu_custom.min.css', false, '1.0.0' );
  wp_enqueue_style( 'ubermenu_cp' );
}
 
if ( function_exists( 'is_woocommerce' ) ) {
  function df_woocommerce_single_product_image_html($html) {
    $html = str_replace('data-rel="prettyPhoto', 'rel="lightbox', $html);
    return $html;
  }
  add_filter('woocommerce_single_product_image_html', 'df_woocommerce_single_product_image_html', 99, 1); // single image
  add_filter('woocommerce_single_product_image_thumbnail_html', 'df_woocommerce_single_product_image_html', 99, 1); // thumbnails
 
  add_action( 'wp_enqueue_scripts', 'manage_woocommerce_styles_and_scripts', 99 );
 
  function manage_woocommerce_styles_and_scripts() {
//dequeue parts of WooCommerce not required in any event
    wp_dequeue_style( 'woocommerce-general' );
    wp_deregister_style( 'woocommerce-general' );
    wp_dequeue_style( 'woocommerce-layout' );
    wp_deregister_style( 'woocommerce-layout' );
    wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
    wp_deregister_style( 'woocommerce_prettyPhoto_css' );
    wp_dequeue_script( 'prettyPhoto' );
    wp_deregister_script( 'prettyPhoto' );
    wp_dequeue_script( 'prettyPhoto-init' );
    wp_deregister_script( 'prettyPhoto-init' );
//dequeue scripts and styles
    if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
//remove generator meta tag
//      remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
//      remove_action( 'wp_enqueue_scripts', array( $GLOBALS['woocommerce'], 'frontend_scripts' ) );
      wp_dequeue_style( 'woocommerce-smallscreen' );
      wp_deregister_style( 'woocommerce-smallscreen' );
      wp_dequeue_style( 'woocommerce-multiple-addresses-plugin-styles' );
      wp_deregister_style( 'woocommerce-multiple-addresses-plugin-styles' );
      wp_dequeue_script( 'wc-add-to-cart' );
      wp_deregister_script( 'wc-add-to-cart' );
      wp_dequeue_script( 'woocommerce' );
      wp_deregister_script( 'woocommerce' );
      wp_dequeue_script( 'wc-cart-fragments' );
      wp_deregister_script( 'wc-cart-fragments' );
      wp_dequeue_script( 'woocommerce-multiple-addresses-plugin-script' );
      wp_deregister_script( 'woocommerce-multiple-addresses-plugin-script' );
    } else {
// Add Darkly themed WooCommerce style sheet
      wp_register_style( 'woocommerce_cp', get_stylesheet_directory_uri() . '/css/woocommerce_custom.css', false, '1.0.0' );
      wp_enqueue_style( 'woocommerce_cp' );
    }
    if ( ! is_bbpress() ) {
//remove bbPress scripts and atyles
      wp_dequeue_style( 'bbp-default' );
      wp_deregister_style( 'bbp-default' );
      wp_dequeue_style( 'bbp-default-bbpress' );
      wp_deregister_style( 'bbp-default-bbpress' );
      wp_dequeue_script( 'bbpress-editor' );
      wp_deregister_script( 'bbpress-editor' );
    }
 
  }
}
 
// Add Product Reviews section to Admin
if ((is_admin() )) {
  add_action('admin_menu', 'add_product_reviews'); 
 
  function add_product_reviews() { 
    global $menu, $product_reviews;
    $post_type = 'product';
    add_menu_page(__('Product Reviews'),__('Product Reviews'), 'manage_woocommerce', "edit-comments.php?post_type={$post_type}",'','',58.5);
  }    
 
  function separate_comments_and_review( $clauses, $wp_comment_query ) {
    global $wpdb;
    if ( ! $clauses['join'] )
      $clauses['join'] = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
    if(!empty($_GET['post_type']) &&$_GET['post_type'] == 'product' )
      {
    if ( ! $wp_comment_query->query_vars['post_type'] ) 
          $clauses['where'] .= $wpdb->prepare( " AND {$wpdb->posts}.post_type = %s", 'product' );
      } else {
    if ( ! $wp_comment_query->query_vars['post_type' ] ) 
          $clauses['where'] .= $wpdb->prepare( " AND {$wpdb->posts}.post_type != %s", 'product' );
      }
      return $clauses;
    }
 
  function change_comment_status_link( $status_links ) {
    if( isset( $_GET['post_type'] ) ) 
    {
      $status_links['all'] = '<a href="edit-comments.php?post_type=product&comment_status=all">All</a>';
      $status_links['moderated'] = '<a href="edit-comments.php?post_type=product&comment_status=moderated">Pending</a>';
      $status_links['approved'] = '<a href="edit-comments.php?post_type=product&comment_status=approved">Approved</a>';
      $status_links['spam'] = '<a href="edit-comments.php?post_type=product&comment_status=spam">Spam</a>';
      $status_links['trash'] = '<a href="edit-comments.php?post_type=product&comment_status=trash">Trash</a>';
    }
    return $status_links;
  }
 
  function check_current_page( $screen ) {
    if ( $screen->id == 'edit-comments' ) // Checking comment page
    {
      add_filter( 'comments_clauses', 'separate_comments_and_review', 10, 2 );
      add_filter( 'comment_status_links', 'change_comment_status_link' );
      if( isset( $_GET['post_type'] ) ) 
      {
        function product__comment_columns( $columns ) {
          $columns['comment'] = __( 'Review' );
          return $columns;
        }
        add_filter( 'manage_edit-comments_columns', 'product__comment_columns' );
      }
    }
  }
 
  add_action( 'current_screen', 'check_current_page', 10, 2 );
  add_filter('menu_order','change_label');
 
  function change_label($stuff) {
    global $menu,$submenu;
    global $wpdb;
    $sql = "SELECT count(*) FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
      WHERE comment_approved = '0' AND comment_type = '' AND post_password = '' AND post_type != 'product' ORDER BY comment_date_gmt DESC";
    $comments = $wpdb->get_col($sql);
    $sql1 = "SELECT count(*) FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
      WHERE comment_approved = '0' AND comment_type = '' AND post_password = '' AND post_type = 'product' ORDER BY comment_date_gmt DESC";
    $reviews = $wpdb->get_col($sql1);
    $menu[25][0]= 'Comments<span class="awaiting-mod count-'.$comments[0].'"><span class="pending-count">'.$comments[0].'</span></span>';
    $menu[58.5][0]= 'Reviews<span class="awaiting-mod count-'.$reviews[0].'"><span class="pending-count">'.$reviews[0].'</span></span>';
    return $stuff;
  }
}
 
// Remove Gravatar (taken from a Buddy Press board, hence bp_ naming
function bp_remove_gravatar ($image, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir) {
  $default = get_stylesheet_directory_uri() .'/_inc/images/bp_default_avatar.jpg';
  if( $image && strpos( $image, "gravatar.com" ) ){
    return 'avatar';
  } else {
    return $image;
  }
}
 
add_filter('bp_core_fetch_avatar', 'bp_remove_gravatar', 1, 9 );
 
function remove_gravatar ($avatar, $id_or_email, $size, $default, $alt) {
  $default = get_stylesheet_directory_uri() .'/_inc/images/bp_default_avatar.jpg';
  return "{$alt}";
}
 
add_filter('get_avatar', 'remove_gravatar', 1, 5);
 
function bp_remove_signup_gravatar ($image) {
  $default = get_stylesheet_directory_uri() .'/_inc/images/bp_default_avatar.jpg';
  if( $image && strpos( $image, "gravatar.com" ) ){
    return 'avatar';
  } else {
    return $image;
  }
}
 
add_filter('bp_get_signup_avatar', 'bp_remove_signup_gravatar', 1, 1 );
 
// Defer jQuery Parsing using HTML5′s defer property
if (! is_admin() ) {
  function defer_parsing_of_js ( $url ) {
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return "$url' defer ";
  }
  add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
}
 
//turn heatbeat api off (speeds up admin-ajax.php)
 
function my_deregister_heartbeat() {
    global $pagenow;
 
    if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
        wp_deregister_script('heartbeat');
        wp_register_script('heartbeat', false);
    }
}
add_action( 'admin_enqueue_scripts', 'my_deregister_heartbeat' );
 
// the next 2 commented out functions (leave commented out on a working site, uncomment it for a test site) will show the hooks being loaded on a page
 
/*function dump_hook( $tag, $hook ) {
    ksort($hook);
 
    echo "<pre>>>>>>\t$tag<br>";
 
    foreach( $hook as $priority => $functions ) {
 
    echo $priority;
 
    foreach( $functions as $function )
        if( $function['function'] != 'list_hook_details' ) {
 
        echo "\t";
 
        if( is_string( $function['function'] ) )
            echo $function['function'];
 
        elseif( is_string( $function['function'][0] ) )
             echo $function['function'][0] . ' -> ' . $function['function'][1];
 
        elseif( is_object( $function['function'][0] ) )
            echo "(object) " . get_class( $function['function'][0] ) . ' -> ' . $function['function'][1];
 
        else
            print_r($function);
 
        echo ' (' . $function['accepted_args'] . ') <br>';
        }
    }
 
    echo '</pre>';
}
 
function list_hooks( $filter = 'wp_footer' ){
    global $wp_filter;
 
    $hooks = $wp_filter;
    ksort( $hooks );
 
    foreach( $hooks as $tag => $hook )
        if ( false === $filter || false !== strpos( $tag, $filter ) )
            dump_hook($tag, $hook);
}*/
 
// The next function (leave commented out on a working site, uncomment it for a test site) will show the assets being loaded on a page (css and js)
 
/*function inspect_scripts_or_styles() {
    echo "<br />JS assets:<br />";
    global $wp_scripts;
    foreach( $wp_scripts->queue as $handle ) :
        echo $handle . '<br />';
    endforeach;
    echo "<br />Style assets:<br />";
    global $wp_styles;
    foreach( $wp_styles->queue as $handle ) :
        echo $handle . '<br />';
    endforeach;
}
 
add_action( 'wp_print_scripts', 'inspect_scripts_or_styles' );*/

Enjoy.

Categories: WordPress.