PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 1.0.8
Forumax – AI Powered Advanced Community Forum Plugin v1.0.8
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / includes / functions.php

functions.php in Forumax – AI Powered Advanced Community Forum Plugin 1.0.8, at includes/functions.php

92 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 function bbpc_post_pagination() {
3 if ( is_singular() ) {
4 return;
5 }
6 global $wp_query;
7
8 /** Stop execution if there's only 1 page */
9 if ( $wp_query->max_num_pages <= 1 ) {
10 return;
11 }
12
13 $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
14 $max = intval( $wp_query->max_num_pages );
15
16 /** Add current page to the array */
17 if ( $paged >= 1 ) {
18 $links[] = $paged;
19 }
20
21 /** Add the pages around the current page to the array */
22 if ( $paged >= 3 ) {
23 $links[] = $paged - 1;
24 $links[] = $paged - 2;
25 }
26
27 if ( ( $paged + 2 ) <= $max ) {
28 $links[] = $paged + 2;
29 $links[] = $paged + 1;
30 }
31
32 echo '<ul class="d-flex align-items-center">' . "\n";
33
34 /** Previous Post Link */
35 if ( get_previous_posts_link() ) {
36 printf( '<li>%s</li>' . "\n", get_previous_posts_link( '<i class="fa fa-angle-left" aria-hidden="true"></i>' ) );
37 }
38
39 /** Link to first page, plus ellipses if necessary */
40 if ( ! in_array( 1, $links ) ) {
41 $class = 1 == $paged ? ' class="active"' : ' ';
42
43 printf( '<li><a %s href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
44
45 if ( ! in_array( 2, $links ) ) {
46 echo '<li>&#46;&#46;&#46;</li>';
47 }
48 }
49
50 /** Link to current page, plus 2 pages in either direction if necessary */
51 sort( $links );
52 foreach ( $links as $link ) {
53 $class = $paged == $link ? ' class="active"' : ' ';
54 printf( '<li><a %s href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
55 }
56
57 /** Link to last page, plus ellipses if necessary */
58 if ( ! in_array( $max, $links ) ) {
59 if ( ! in_array( $max - 1, $links ) ) {
60 echo '<li>&#46;&#46;&#46;</li>' . "\n";
61 }
62
63 $class = $paged == $max ? ' class="active"' : '';
64 printf( '<li><a %s href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
65 }
66
67 /** Next Post Link */
68 if ( get_next_posts_link() ) {
69 printf( '<li>%s</li>' . "\n", get_next_posts_link( '<i class="fa fa-angle-right" aria-hidden="true"></i>' ) );
70 }
71
72 echo '</ul>';
73 }
74
75
76
77 add_action(
78 'admin_footer',
79 function() {
80 if ( strstr( $_SERVER['REQUEST_URI'], 'wp-admin/post-new.php' ) || strstr( $_SERVER['REQUEST_URI'], 'wp-admin/post.php' ) ) {
81 $forum_id = sanitize_text_field( wp_unslash( isset( $_GET['forum_id'] ) ) ? $_GET['forum_id'] : '' );
82 if ( $forum_id ) :
83 ?>
84 <script>
85 document.getElementById('parent_id').value = <?php echo esc_js( $forum_id ); ?>;
86 </script>
87 <?php
88 endif;
89 }
90 }
91 );
92