forked from nanodesigns/nano-progga
/
functions.php
675 lines (569 loc) · 23.7 KB
/
functions.php
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
<?php
/**
* nano-progga functions and definitions
*
* @package nano-progga
*/
/**
* Set some basic settings
* --------------------------------------------------------------------------
*/
define( 'THEME_VERSION', '3.0');
$project_prefix = 'np_';
/**
* Enable only when developing the site.
* nanodesigns
* @author Mayeenul Islam <wz.islam@gmail.com>
* --------------------------------------------------------------------------
*/
if( WP_DEBUG )
require get_template_directory() .'/__development/__development.php';
/**
* Codestar Admin Framework.
* @since 3.0.0
* --------------------------------------------------------------------------
*/
require_once dirname( __FILE__ ) .'/libs/cs-framework/cs-framework.php';
/**
* Bengali Support to the Theme.
* Controlled from the Theme Options page.
* --------------------------------------------------------------------------
*/
if( cs_get_option( 'bangla' ) )
require get_template_directory() . '/inc/functions-bangla.php';
if ( ! function_exists( 'nano_progga_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
* ------------------------------------------------------------------------------
*/
function nano_progga_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on nano-progga, use a find and replace
* to change 'nano-progga' to the name of your theme in all the template files
*/
load_theme_textdomain( 'nano-progga', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*/
add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array( 'main_menu' => esc_html__( 'Main Menu', 'nano-progga' ) ) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
* See http://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'image',
'gallery',
'video',
'quote',
'link',
'audio'
) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'nano_progga_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
) ) );
// Force the editor styles to match the theme's UI.
add_editor_style( 'editor-style.css' );
}
endif; // nano_progga_setup
add_action( 'after_setup_theme', 'nano_progga_setup' );
/**
* Bootstrap Nav Walker Class
* @author Edward McIntyre
* @link https://github.com/twittem/wp-bootstrap-navwalker
* --------------------------------------------------------------------------
*/
require get_template_directory() .'/libs/wp-bootstrap-navwalker.php';
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
* ------------------------------------------------------------------------------
*/
function nano_progga_content_width() {
$GLOBALS['content_width'] = apply_filters( 'nano_progga_content_width', 700 );
}
add_action( 'after_setup_theme', 'nano_progga_content_width', 0 );
/**
* Register widget area.
* ------------------------------------------------------------------------------
*/
function nano_progga_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Right Sidebar', 'nano-progga' ),
'id' => 'right_sidebar',
'description' => esc_html__( 'Appears on the right portion of the site', 'nano-progga' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Home Widget 1', 'nano-progga' ),
'id' => 'home_widget_1',
'description' => esc_html__( 'Appears on the home page within the grid', 'nano-progga' ),
'before_widget' => '<aside id="%1$s" class="grid-item widget-holder col-sm-4 %2$s"><div class="grid-widget home-widget-1">',
'after_widget' => '</div></aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Home Widget 2', 'nano-progga' ),
'id' => 'home_widget_2',
'description' => esc_html__( 'Appears on the home page within the grid', 'nano-progga' ),
'before_widget' => '<aside id="%1$s" class="grid-item widget-holder col-sm-4 %2$s"><div class="grid-widget home-widget-2">',
'after_widget' => '</div></aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Home Widget 3', 'nano-progga' ),
'id' => 'home_widget_3',
'description' => esc_html__( 'Appears on the home page within the grid', 'nano-progga' ),
'before_widget' => '<aside id="%1$s" class="grid-item widget-holder col-sm-4 %2$s"><div class="grid-widget home-widget-3">',
'after_widget' => '</div></aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Home Widget 4', 'nano-progga' ),
'id' => 'home_widget_4',
'description' => esc_html__( 'Appears on the home page within the grid', 'nano-progga' ),
'before_widget' => '<aside id="%1$s" class="grid-item widget-holder col-sm-4 %2$s"><div class="grid-widget home-widget-4">',
'after_widget' => '</div></aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Home Widget 5', 'nano-progga' ),
'id' => 'home_widget_5',
'description' => esc_html__( 'Appears on the home page within the grid', 'nano-progga' ),
'before_widget' => '<aside id="%1$s" class="grid-item widget-holder col-sm-4 %2$s"><div class="grid-widget home-widget-5">',
'after_widget' => '</div></aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Archive Left Sidebar', 'nano-progga' ),
'id' => 'left_sidebar',
'description' => esc_html__( 'Appears on the left portion of the site only on archive pages', 'nano-progga' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Sidebar', 'nano-progga' ),
'id' => 'footer_sidebar',
'description' => esc_html__( 'Appears on the footer portion of the site', 'nano-progga' ),
'before_widget' => '<div class="col-sm-4"><aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside></div>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
add_action( 'widgets_init', 'nano_progga_widgets_init' );
/**
* Enqueue scripts and styles.
* ------------------------------------------------------------------------------
*/
function nano_progga_scripts() {
wp_enqueue_style( 'bootstrap-styles', get_template_directory_uri() .'/css/bootstrap.min.css' );
wp_enqueue_style( 'nano-progga-style', get_stylesheet_uri() );
wp_enqueue_script( 'modernizr-js', get_template_directory_uri() .'/js/modernizr-2.8.3.min.js', array(), '2.8.3' ); //in head
wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() .'/js/bootstrap.min.js', array('jquery'), '3.3.4', true );
if( is_home() || is_page_template('page-templates/blog.php') ) {
wp_enqueue_script( 'imagesLoaded-js', get_template_directory_uri() .'/js/imagesloaded.pkgd.min.js', array('jquery'), '3.1.8', true );
wp_enqueue_script( 'masonry-grid-js', get_template_directory_uri() .'/js/masonry.pkgd.min.js', array('jquery'), '3.3.1', true );
wp_enqueue_script( 'jQuery-matchHeight-js', get_template_directory_uri() .'/js/jquery.matchHeight.min.js', array('jquery'), '0.6.0', true );
}
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
wp_enqueue_script( 'nano-progga-js', get_template_directory_uri() .'/js/nano-progga.min.js', array('jquery'), THEME_VERSION, true );
//passing PHP var to JS
wp_localize_script(
'nano-progga-js',
'np', //the var key in JS
array(
'url' => site_url('/'),
'theme_path' => get_template_directory_uri()
)
);
}
add_action( 'wp_enqueue_scripts', 'nano_progga_scripts' );
/**
* Require Necessary Functions.
* ------------------------------------------------------------------------------
*/
require get_template_directory() . '/inc/custom-header.php'; //custom header
require get_template_directory() . '/inc/template-tags.php'; //template tags
require get_template_directory() . '/inc/extras.php'; //theme extras
require get_template_directory() . '/inc/customizer.php'; //WP Customizer API
require get_template_directory() . '/inc/functions-series.php'; //Posts Series
require get_template_directory() . '/inc/framework/helpers.php'; //Helper Functions
require get_template_directory() . '/inc/framework/shortcodes.php'; //Shortcodes
// Theme Options Page (Filters on the Codestar Framework)
require get_template_directory() . '/admin/nano-progga-settings.php';
/**
* The excerpt filters.
* @param string $more Default string [...]
* @return string Modified string ...
* --------------------------------------------------------------------------
*/
function nano_progga_excerpt_more( $more ) {
return '...';
}
add_filter( 'excerpt_more', 'nano_progga_excerpt_more' );
/**
* nano progga Breadcrumbs.
* Based on Dimox Breadcrumbs.
* @link http://dimox.net/wordpress-breadcrumbs-without-a-plugin/
*
* @since 3.0.0
* --------------------------------------------------------------------------
*/
function nano_progga_breadcrumbs(){
/* === OPTIONS === */
$text['home'] = __('Home', 'nano-progga'); // text for the 'Home' link
$text['category'] = __('Category: "%s"', 'nano-progga'); // text for a category page
$text['tax'] = __('Archive: "%s"', 'nano-progga'); // text for a taxonomy page
$text['search'] = __('Search Results: "%s"', 'nano-progga'); // text for a search results page
$text['tag'] = __('Tagged: "%s"', 'nano-progga'); // text for a tag page
$text['author'] = __('Author: %s', 'nano-progga'); // text for an author page
$text['404'] = __('Error 404', 'nano-progga'); // text for the 404 page
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
$showOnHome = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
$delimiter = ' » '; // delimiter between crumbs
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
/* === END OF OPTIONS === */
global $post;
$homeLink = home_url() .'/';
$linkBefore = '<span typeof="v:Breadcrumb">';
$linkAfter = '</span>';
$linkAttr = ' rel="v:url" property="v:title"';
$link = $linkBefore . '<a' . $linkAttr . ' href="%1$s">%2$s</a>' . $linkAfter;
if (is_home() || is_front_page()) {
if ($showOnHome == 1) echo '<div id="breadcrumbs" class="hidden-print"><a href="' . $homeLink . '">' . $text['home'] . '</a></div>';
} else {
echo '<div id="breadcrumbs" class="hidden-print" xmlns:v="http://rdf.data-vocabulary.org/#">' . sprintf($link, $homeLink, $text['home']) . $delimiter;
if ( is_category() ) {
$thisCat = get_category(get_query_var('cat'), false);
if ($thisCat->parent != 0) {
$cats = get_category_parents($thisCat->parent, TRUE, $delimiter);
$cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
$cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
echo $cats;
}
echo $before . sprintf($text['category'], single_cat_title('', false)) . $after;
} elseif( is_tax() ){
$thisCat = get_category(get_query_var('cat'), false);
if ($thisCat->parent != 0) {
$cats = get_category_parents($thisCat->parent, TRUE, $delimiter);
$cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
$cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
echo $cats;
}
echo $before . sprintf($text['tax'], single_cat_title('', false)) . $after;
}elseif ( is_search() ) {
echo $before . sprintf($text['search'], get_search_query()) . $after;
} elseif ( is_day() ) {
echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
echo sprintf($link, get_month_link(get_the_time('Y'),get_the_time('m')), get_the_time('F')) . $delimiter;
echo $before . get_the_time('d') . $after;
} elseif ( is_month() ) {
echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
echo $before . get_the_time('F') . $after;
} elseif ( is_year() ) {
echo $before . get_the_time('Y') . $after;
} elseif ( is_single() && !is_attachment() ) {
if ( get_post_type() != 'post' ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
printf($link, $homeLink . '/' . $slug['slug'] . '/', $post_type->labels->singular_name);
if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after;
} else {
//$cat = get_the_category(); $cat = $cat[0];
//$cats = get_category_parents($cat, TRUE, $delimiter);
//if ($showCurrent == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
//$cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
//$cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
//echo $cats;
if ($showCurrent == 1) echo $before . get_the_title() . $after;
}
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
$post_type = get_post_type_object(get_post_type());
echo $before . $post_type->labels->singular_name . $after;
} elseif ( is_attachment() ) {
$parent = get_post($post->post_parent);
printf($link, get_permalink($parent), $parent->post_title);
if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after;
} elseif ( is_page() && !$post->post_parent ) {
if ($showCurrent == 1) echo $before . get_the_title() . $after;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID));
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
echo $breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) echo $delimiter;
}
if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after;
} elseif ( is_tag() ) {
echo $before . sprintf($text['tag'], single_tag_title('', false)) . $after;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $before . sprintf($text['author'], $userdata->display_name) . $after;
} elseif ( is_404() ) {
echo $before . $text['404'] . $after;
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo ' '. __('Page', 'nano-progga') . ' ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
echo '</div> <!-- #breadcrumbs -->';
}
} // end nano_progga_breadcrumbs()
/**
* Show user meta fields.
* @param array $methods default user contact methods.
* @return array nano progga contact methods.
* --------------------------------------------------------------------------
*/
function nano_progga_author_meta_fields( $methods ) {
$methods['nano_facebook'] = __('Facebook Profile URL [np]', 'nano-progga');
$methods['nano_twitter'] = __('Twitter URL [np]', 'nano-progga');
$methods['nano_google_plus'] = __('Google+ Profile URL [np]', 'nano-progga');
$methods['nano_linkedin'] = __('LinkedIn URL [np]', 'nano-progga');
$methods['nano_pinterest'] = __('Pinterest URL [np]', 'nano-progga');
$methods['nano_tumblr'] = __('Tumblr URL [np]', 'nano-progga');
return $methods;
}
if( cs_get_option('author_bio') )
add_filter( 'user_contactmethods', 'nano_progga_author_meta_fields' );
/**
* Get Related Posts.
* Only on single.php.
* @param integer $post_id
* @param integer $numberposts default is set to 3
* --------------------------------------------------------------------------
*/
function nano_progga_get_related_posts( $post_id = null, $numberposts = 3 ) {
if( !is_single() )
return;
$post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
$total_fetched = 0;
echo '<div class="related-posts hidden-print">';
echo '<h3 class="page-title inner-title"><span>'. __( 'Related Posts', 'nano-progga' ) .'</span></h3>';
echo '<div class="row">';
$categories = wp_get_post_categories( $post_id );
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $numberposts, //default 3
'post__not_in' => array( $post_id ),
'orderby' => 'rand',
'category__in' => $categories,
'ignore_sticky_posts' => 1
);
$related_posts_per_categories = new WP_Query( $args );
while( $related_posts_per_categories->have_posts() ) :
$related_posts_per_categories->the_post(); ?>
<div class="col-xs-4 related-post-col">
<div class="related-post related-post-<?php the_ID(); ?>">
<?php if( has_post_thumbnail() ) : ?>
<div class="featured-image">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php else : ?>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<div class="entry-excerpt"><?php echo wp_trim_words(get_the_excerpt(), 10); ?></div>
<?php endif; ?>
</div>
</div> <!-- /.col-xs-4 related-post-col -->
<?php
$total_fetched++; //update total fetched count on each found posts
endwhile;
wp_reset_postdata();
//alternative if necessary
if( $total_fetched < $numberposts ) {
$get_total = $numberposts - $total_fetched;
$tags = wp_get_post_tags( $post_id );
$tag_ids = array();
foreach( $tags as $indv_tag ) :
$tag_ids[] = $indv_tag->term_id;
endforeach;
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $get_total, //only the remaining
'post__not_in' => array( $post_id ),
'orderby' => 'rand',
'tag__in' => $tag_ids,
'ignore_sticky_posts' => 1
);
$related_posts_per_tags = new WP_Query( $args );
while( $related_posts_per_tags->have_posts() ) :
$related_posts_per_tags->the_post(); ?>
<div class="col-xs-4 related-post-col">
<div class="related-post related-post-<?php the_ID(); ?>">
<?php if( has_post_thumbnail() ) : ?>
<div class="featured-image">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
</a>
</div>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php else : ?>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<div class="entry-excerpt"><?php echo wp_trim_words(get_the_excerpt(), 10); ?></div>
<?php endif; ?>
</div>
</div> <!-- /.col-xs-4 related-post-col -->
<?php
$total_fetched++; //update total fetched count on each found posts
endwhile;
wp_reset_postdata();
}
echo '</div> <!-- .row -->';
echo '</div> <!-- .related-posts -->';
}
/**
* Nofollow External Links.
* Modifying post_content where <a rel="nofollow"> is added to all the external links only.
*
* @author Christine Cooper
* @link http://wordpress.stackexchange.com/a/169029
*
* @param string $content post_content.
* @return string post_content modified.
* --------------------------------------------------------------------------
*/
function nano_progga_nofollow_enternal_links( $content ) {
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
if(preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {
if( !empty($matches) ) {
$srcUrl = home_url();
for ($i=0; $i < count($matches); $i++)
{
$tag = $matches[$i][0];
$tag2 = $matches[$i][0];
$url = $matches[$i][0];
$noFollow = '';
$pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if( count($match) < 1 )
$noFollow .= ' rel="nofollow" ';
$pos = strpos($url,$srcUrl);
if ($pos === false) {
$tag = rtrim ($tag,'>');
$tag .= $noFollow.'>';
$content = str_replace($tag2,$tag,$content);
}
}
}
}
$content = str_replace(']]>', ']]>', $content);
return $content;
}
if( cs_get_option('nofollow') )
add_filter( 'the_content', 'nano_progga_nofollow_enternal_links');
/**
* No Self Ping.
* Keeps WordPress from sending pings to your own site.
*
* Adopted from: No Self Pings (v.0.2)
* @author Michael D. Adams
* @link https://wordpress.org/plugins/no-self-ping/
*
* @since 3.0.0
*
* @param string &$links Links.
* --------------------------------------------------------------------------
*/
function nano_progga_no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
if( cs_get_option('noselfping') )
add_action( 'pre_ping', 'nano_progga_no_self_ping' );
/**
* Add Featured Image column to the Post List.
*
* @since 3.0.0
*
* @param array $columns Default columns.
* @return array Modified columns.
* --------------------------------------------------------------------------
*/
function nano_progga_post_thumbnail_columns( $columns ) {
$new_columns = array(
'thumb' => '<span class="dashicons dashicons-format-image" title="Featured Image"></span>'
);
return array_merge( $columns, $new_columns );
}
add_filter( 'manage_post_posts_columns', 'nano_progga_post_thumbnail_columns' );
/**
* Populate the Post Thumbnail column with the respective data.
*
* @since 3.0.0
*
* @param array $column Default columns.
* @param integer $post_id That particular post_ID.
* --------------------------------------------------------------------------
*/
function nano_progga_post_thumbnail_table_columns_data( $column, $post_id ) {
switch ( $column ) {
case 'thumb':
if( has_post_thumbnail( $post_id ) )
the_post_thumbnail( array(70,70), array('class'=>'post-thumb-preview') );
else
echo '...';
break;
}
}
add_action( 'manage_post_posts_custom_column', 'nano_progga_post_thumbnail_table_columns_data', 10, 2 );