PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.0.3
Post Grid Gutenberg Blocks – PostX v4.0.3
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / addons / builder / blocks / Author_Box.php

Author_Box.php in Post Grid Gutenberg Blocks – PostX 4.0.3, at addons/builder/blocks/Author_Box.php

147 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP\blocks;
3
4 defined('ABSPATH') || exit;
5
6 class Author_Box{
7 public function __construct() {
8 add_action('init', array($this, 'register'));
9 }
10 public function register() {
11 register_block_type( 'ultimate-post/author-box',
12 array(
13 'editor_script' => 'ultp-blocks-editor-script',
14 'editor_style' => 'ultp-blocks-editor-css',
15 'render_callback' => array($this, 'content')
16 )
17 );
18 }
19 public function get_attributes() {
20 return array(
21 'blockId' => '',
22 'layout' => 'layout1',
23
24 /*============================
25 Author Box Settings
26 ============================*/
27 'imgShow' => true,
28 'writtenByShow' => true,
29 'authorBioShow' => true,
30 'metaShow' => true,
31 'allPostLinkShow' => true,
32 'authorBoxAlign' => 'center',
33
34
35
36 /*============================
37 Author Image Settings
38 ============================*/
39 'imgSize' => (object)['lg' =>'100'],
40 'imgRatio' => '100',
41
42 /*============================
43 Written by Settings
44 ============================*/
45 'writtenByText' => 'Written by',
46
47 /*============================
48 Author Name Settings
49 ============================*/
50 'authorNameTag' => 'h4',
51
52 /*============================
53 Meta Setting/Style Settings
54 ============================*/
55 'metaPosition' => 'bottom',
56
57 /*============================
58 View all Post Button Settings
59 ============================*/
60 'viewAllPostText' => 'View All Posts',
61
62 /*============================
63 Advanced Settings
64 ============================*/
65 'advanceId' => '',
66 'advanceZindex' => '',
67 'hideExtraLarge' => false,
68 'hideDesktop' => false,
69 'hideTablet' => false,
70 'hideMobile' => false,
71 'advanceCss' => '',
72 );
73 }
74
75 public function content($attr, $noAjax) {
76 $attr = wp_parse_args($attr, $this->get_attributes());
77
78 $block_name = 'author_box';
79 $author_bio = $wrapper_before = $wrapper_after = $content = '';
80
81 $page_post_id = get_the_ID(); // ultimate_post()->get_ID();
82
83 if($page_post_id){
84
85 $attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : '';
86 $attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : '';
87 $attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : '';
88 $attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : '';
89 $attr['authorNameTag'] = in_array( $attr['authorNameTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['authorNameTag'] : 'h4';
90 $attr['layout'] = sanitize_html_class( $attr['layout'] );
91 $attr['writtenByText'] = wp_kses($attr['writtenByText'], ultimate_post()->ultp_allowed_html_tags());
92
93 $_post = get_post( $page_post_id );
94 $post_author = get_userdata( $_post->post_author );
95
96 // Author Image
97 $author_image = '<div class="ultp-post-author-image-section">';
98 $author_image .= get_avatar($post_author->ID, $attr['imgRatio']);
99 $author_image .= '</div>';
100
101 // Author Meta
102 $author_meta = '<div class="ultp-post-author-meta">';
103 $author_meta .= '<span class="ultp-total-post">' . count_user_posts($_post->post_author, $post_type = 'post') . ' Posts</span>';
104 $author_meta .= '<span class="ultp-total-comment">' . get_comments_number($page_post_id) . ' Comments</span>';
105 $author_meta .= '</div>';
106
107 // Author Description
108 if ($post_author->description) {
109 $author_bio .= '<div class="ultp-post-author-bio">';
110 $author_bio .= '<span class="ultp-post-author-bio-meta">' . $post_author->description . '</span>';
111 $author_bio .= '</div>';
112 }
113
114 // Author Url
115 if (get_author_posts_url($_post->post_author)) {
116 $all_post_link = '<div class="ultp-author-post-link">';
117 $all_post_link .= '<a class="ultp-author-post-link-text" href="'.get_author_posts_url( $_post->post_author ).'">'.$attr['viewAllPostText'].'</a>';
118 $all_post_link .= '</div>';
119 }
120
121 $wrapper_before .= '<div '.( $attr['advanceId'] ? 'id="'.$attr['advanceId'].'" ':'' ).' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].( $attr["className"] ?' '.$attr["className"]:'' ).''.( $attr["align"] ? ' align' .$attr["align"]:'' ).'">';
122 $wrapper_before .= '<div class="ultp-block-wrapper">';
123 $content .= '<div class="ultp-author-box ultp-author-box-'.$attr["layout"].'-content">';
124 $content .= ($attr['imgShow'] && $attr['layout'] !== 'layout4' ? $author_image : '');
125 $content .= '<div class="ultp-post-author-details">';
126 $content .= '<div class="ultp-post-author-title">';
127 $content .= $attr["writtenByShow"] ? '<span class="ultp-post-author-written-by">'.$attr["writtenByText"].'</span>' : '';
128 $content .= '<'.$attr['authorNameTag'].' class="ultp-post-author-name"><a href="'.get_author_posts_url( $_post->post_author ).'">'.$post_author->display_name.'</a></'.$attr['authorNameTag'].'>';
129 $content .= '</div>';
130
131
132 $content .= ($attr["metaShow"] && $attr["metaPosition"] == 'top' ? $author_meta : '');
133
134
135 $content .= ($attr["authorBioShow"] && $author_bio ? $author_bio : '');
136 $content .= ($attr["metaShow"] && $attr["metaPosition"] == 'bottom' ? $author_meta : '');
137 $content .= ($attr["allPostLinkShow"] ? $all_post_link : '');
138 $content .= '</div>';
139 $content .= ($attr['imgShow'] && $attr['layout'] === 'layout4' ? $author_image : '');
140 $content .= '</div>';
141 $wrapper_after .= '</div>';
142 $wrapper_after .= '</div>';
143 }
144
145 return $wrapper_before.$content.$wrapper_after;
146 }
147 }