forked from DevinWalker/custom-functionality-plugin-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappearance-customizations
More file actions
358 lines (280 loc) · 10.4 KB
/
Copy pathappearance-customizations
File metadata and controls
358 lines (280 loc) · 10.4 KB
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
/**
* Appearance Customizations
*
* @description: All functions that customize the appearance go here
*/
/*---------- Images -----------*/
/************ TRY OUT WITH LIGHTBOX CODE****
*
* Add Rel="lightbox" to all images embedded in a post.
* http://wpsnipp.com/index.php/functions-php/add-rel-lightbox-to-all-images-embedded-in-a-post/
*
******************
add_filter('the_content', 'my_addlightboxrel');
function my_addlightboxrel($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="lightbox" title="'.$post->post_title.'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
/*******************
*
* Sharpen thumbnails
* https://managewp.com/enhanced-performance-code-snippets
*
********************
function ajx_sharpen_resized_files( $resized_file ) {
$image = wp_load_image( $resized_file );
if ( !is_resource( $image ) )
return new WP_Error( 'error_loading_image', $image, $file );
$size = @getimagesize( $resized_file );
if ( !$size )
return new WP_Error('invalid_image', __('Could not read image size'), $file);
list($orig_w, $orig_h, $orig_type) = $size;
switch ( $orig_type ) {
case IMAGETYPE_JPEG:
$matrix = array(
array(-1, -1, -1),
array(-1, 16, -1),
array(-1, -1, -1),
);
$divisor = array_sum(array_map('array_sum', $matrix));
$offset = 0;
imageconvolution($image, $matrix, $divisor, $offset);
imagejpeg($image, $resized_file,apply_filters( 'jpeg_quality', 90, 'edit_image' ));
break;
case IMAGETYPE_PNG:
return $resized_file;
case IMAGETYPE_GIF:
return $resized_file;
}
return $resized_file;
}
add_filter('image_make_intermediate_size', 'ajx_sharpen_resized_files',900);
/*---------- Menu -------------*/
/*----------- Media Library -----------*/
/*---------- WIDGETS ---------*/
/********************************************
* Enable shortcodes in text widgets
* http://stephanieleary.com/2010/02/using-shortcodes-everywhere/
********************************************/
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
/**********************
* Enable PHP Scripts in text widgets
* http://andornagy.com/enable-scripts-and-shortcodes-in-wordpress-text-widgets/
***********************/
add_filter('widget_text', 'php_text', 99);
function php_text($text) {
if (strpos($text, '<' . '?') !== false) {
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}
/*------- Avatar --------*/
/****************************************************************
* Add a new custom Gravatar to the bottom of the Settings -> Discussion section
* http://blogtimenow.com/wordpress/create-add-custom-default-avatar-wordpress-gravatar/
*
*********************************************************************/
add_filter( 'avatar_defaults', 'new_custom_default_gravatar' );
function new_custom_default_gravatar ($avatar_defaults) {
$myavatar = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Smiley.svg/800px-Smiley.svg.png';
$avatar_defaults[$myavatar] = "Custom Default Gravatar";
return $avatar_defaults;
}
/**************************************************
* Custom avatar link added to the profile page.
* http://www.billerickson.net/wordpress-custom-avatar/
*
**************************************************
/**
* Add Custom Avatar Field
* @author Bill Erickson
* @link http://www.billerickson.net/wordpress-custom-avatar/
*
* @param object $user
*/
function be_custom_avatar_field( $user ) { ?>
<h3>Custom Avatar</h3>
<table>
<tr>
<th><label for="be_custom_avatar"></label></th>
<td>
<input type="text" style="width: 100%;" name="be_custom_avatar" id="be_custom_avatar" value="<?php echo esc_attr( get_the_author_meta( 'be_custom_avatar', $user->ID ) ); ?>" />
<span> <i>Type in the <b>URL</b> of the image you'd like to use as your avatar. <br /><strong>Image should be 70x70 pixels.</strong> <p>This will override your default Gravatar, or show up if you don't have a Gravatar. <br /></span>
</td>
</tr>
</table>
<?php
}
add_action( 'show_user_profile', 'be_custom_avatar_field' );
add_action( 'edit_user_profile', 'be_custom_avatar_field' );
/**
* Save Custom Avatar Field
* @author Bill Erickson
* @link http://www.billerickson.net/wordpress-custom-avatar/
*
* @param int $user_id
*/
function be_save_custom_avatar_field( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_usermeta( $user_id, 'be_custom_avatar', $_POST['be_custom_avatar'] );
}
add_action( 'personal_options_update', 'be_save_custom_avatar_field' );
add_action( 'edit_user_profile_update', 'be_save_custom_avatar_field' );
function be_gravatar_filter($avatar, $id_or_email, $size, $default, $alt) {
$custom_avatar = get_the_author_meta('be_custom_avatar');
if ($custom_avatar)
$return = '<img src="'.$custom_avatar.'" width="'.$size.'" height="'.$size.'" alt="avatar" class="avatar" />';
elseif ($avatar)
$return = $avatar;
else
$return = '<img src="'.$default.'" width="'.$size.'" height="'.$size.'" alt="'.$alt.'" />';
return $return;
}
add_filter('get_avatar', 'be_gravatar_filter', 10, 5);
/***************************************
*
* Remove default author profile fields
* http://www.wpbeginner.com/wp-tutorials/25-extremely-useful-tricks-for-the-wordpress-functions-file/
*
******************************************/
add_filter('user_contactmethods','hide_profile_fields',10,1);
function hide_profile_fields( $contactmethods ) {
unset($contactmethods['aim']);
unset($contactmethods['jabber']);
unset($contactmethods['yim']);
return $contactmethods;
}
/***********************************************************
*
* Adding additional social media fields in profile settings
* http://andornagy.com/custom-profile-fields-wordpress/
*
*************************************************************/
add_filter('user_contactmethods', 'my_user_contactmethods');
function my_user_contactmethods($user_contactmethods){
$user_contactmethods['facebook'] = 'Facebook URL';
$user_contactmethods['twitter'] = 'Twitter Username';
$user_contactmethods['linked'] = 'Linkedin Username';
$user_contactmethods['google'] = 'Google Profile Link';
$user_contactmethods['youtube'] = 'Youtube Channel Name';
$user_contactmethods['pinterest'] = 'Printerest Username';
return $user_contactmethods;
}
if ( get_the_author_meta( 'twitter' ) ) {
the_author_meta( 'twitter' );
}
// End check for twitter
if ( get_the_author_meta( 'facebook' ) ) {
the_author_meta( 'facebook' );
}
// End check for facebook
/******************************
*
* Open Graph
* http://www.paulund.co.uk/add-facebook-open-graph-tags-to-wordpress
*
* To get the correct title, description and image data to show when
* pasting a link to facebook.
*
* Test to see that it is working:
* http://coveloping.com/tools/open-graph-tag-tester
*
*******************************/
// Facebook Open Graph
add_action('wp_head', 'add_fb_open_graph_tags');
function add_fb_open_graph_tags() {
if (is_single()) {
global $post;
if(get_the_post_thumbnail($post->ID, 'thumbnail')) {
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail_object = get_post($thumbnail_id);
$image = $thumbnail_object->guid;
} else {
$image = ''; // Change this to the URL of the logo you want beside your links shown on Facebook
}
//$description = get_bloginfo('description');
$description = my_excerpt( $post->post_content, $post->post_excerpt );
$description = strip_tags($description);
$description = str_replace("\"", "'", $description);
?>
<meta property="og:title" content="<?php the_title(); ?>" />
<meta property="og:type" content="article" />
<meta property="og:image" content="<?php echo $image; ?>" />
<meta property="og:url" content="<?php the_permalink(); ?>" />
<meta property="og:description" content="<?php echo $description ?>" />
<meta property="og:site_name" content="<?php echo get_bloginfo('name'); ?>" />
<?php }
}
/***********************
*
* Excerpt - belonging to the above code
*
*************************/
function my_excerpt($text, $excerpt){
if ($excerpt) return $excerpt;
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$words = preg_split("/[\n
]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(' ', $words);
$text = $text . $excerpt_more;
} else {
$text = implode(' ', $words);
}
return apply_filters('wp_trim_excerpt', $text, $excerpt);
}
/***********
*
* Share on Facebook and Twitter not sure if it works or not.
*
*************
function share_this($content){
if(!is_feed() && !is_home()) {
$content .= '<div class="share-this">
<a href="http://twitter.com/share"
class="twitter-share-button"
data-count="horizontal">Tweet</a>
<script type="text/javascript"
src="http://platform.twitter.com/widgets.js"></script>
<div class="facebook-share-button">
<iframe
src="http://www.facebook.com/plugins/like.php?href='.
urlencode(get_permalink($post->ID))
.'&layout=button_count&show_faces=false&width=200&action=like&colorscheme=light&height=21"
scrolling="no" frameborder="0" style="border:none;
overflow:hidden; width:200px; height:21px;"
allowTransparency="true"></iframe>
</div>
</div>';
}
return $content;
}
add_action('the_content', 'share_this');
/**********
*
* Google Plus to bottom of page.
*
****************
add_filter('the_content', 'google_plus');
function google_plus($content) {
$content = $content.'<g:plusone size="tall" href="'.get_permalink().'"></g:plusone>';
return $content;
}
add_action ('wp_enqueue_scripts', 'google_plus_script');
function google_plus_script () {
wp_enqueue_script('google-plus', 'http://apis.google.com/js/plusone.js', array(), null);
}