| @@ -7,12 +7,8 @@ | ||
| 7 | 7 | * |
| 8 | 8 | * @since 2.2.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | - exit; // Exit if accessed directly. | |
| 13 | -} | |
| 14 | - | |
| 15 | 11 | /** |
| 16 | 12 | * Post views helper method. |
| 17 | 13 | * |
| 18 | 14 | * @since 2.2.0 |
| @@ -19,12 +15,8 @@ | ||
| 19 | 15 | */ |
| 20 | 16 | class SP_PC_Functions { |
| 21 | 17 | /** |
| 22 | 18 | * WP Version compare |
| 23 | - * | |
| 24 | - * @param int $version_to_compare The WP version. | |
| 25 | - * @param string $operator Compare operator. | |
| 26 | - * @return mixed | |
| 27 | 19 | */ |
| 28 | 20 | public static function wp_version_compare( $version_to_compare, $operator = '>=' ) { |
| 29 | 21 | if ( empty( $version_to_compare ) ) { |
| 30 | 22 | return true; |
| @@ -35,18 +27,30 @@ | ||
| 35 | 27 | return version_compare( $wp_version, $version_to_compare, $operator ); |
| 36 | 28 | } |
| 37 | 29 | |
| 38 | 30 | /** |
| 31 | + * Post title character limit. | |
| 32 | + * | |
| 33 | + * @param string $pcp_title The post title. | |
| 34 | + * @param integer $limit_length The length for the title. | |
| 35 | + * @param string $pcp_after_string The string after title. | |
| 36 | + * @return statement | |
| 37 | + */ | |
| 38 | + // public static function limit_post_title( $pcp_title, $limit_length, $pcp_after_string = '...' ) { | |
| 39 | + // return mb_strimwidth( $pcp_title, 0, $limit_length, apply_filters( 'pcp_post_title_ellipsis', $pcp_after_string ) ); | |
| 40 | + // } | |
| 41 | + | |
| 42 | + /** | |
| 39 | 43 | * Tag name to full tag conversion. |
| 40 | 44 | * |
| 41 | - * @param array $meta_tag Tag option. | |
| 42 | - * @return string | |
| 45 | + * @param string $meta_tag Tag option. | |
| 46 | + * @return return | |
| 43 | 47 | */ |
| 44 | 48 | public static function short_tag_to_html( $meta_tag ) { |
| 45 | 49 | $exclude_tag_string = ''; |
| 46 | 50 | foreach ( $meta_tag as $key => $value ) { |
| 47 | 51 | $exclude_tag_string .= '<' . $value . '>,'; |
| 48 | - } | |
| 52 | + }; | |
| 49 | 53 | return $exclude_tag_string; |
| 50 | 54 | } |
| 51 | 55 | |
| 52 | 56 | /** |
| @@ -56,19 +60,18 @@ | ||
| 56 | 60 | * @param string $type Content type. |
| 57 | 61 | * @return return |
| 58 | 62 | */ |
| 59 | 63 | public static function pcp_content( $view_options, $type ) { |
| 60 | - global $wp_embed; | |
| 64 | + // $post_content_length = isset( $view_options['pcp_content_limit'] ) ? $view_options['pcp_content_limit'] : ''; | |
| 61 | 65 | $post_content_ellipsis = isset( $view_options['post_content_ellipsis'] ) ? $view_options['post_content_ellipsis'] : ''; |
| 62 | 66 | $pcp_strip_tags = isset( $view_options['pcp_strip_tags'] ) ? $view_options['pcp_strip_tags'] : ''; |
| 63 | 67 | $pcp_allow_tag_name = isset( $view_options['pcp_allow_tag_name'] ) ? $view_options['pcp_allow_tag_name'] : ''; |
| 64 | 68 | $allowed_tags = explode( ',', $pcp_allow_tag_name ); |
| 65 | - if ( 'full_content' === $type ) { | |
| 69 | + if ( 'excerpt' === $type ) { | |
| 70 | + $pcp_post_content = get_the_excerpt(); | |
| 71 | + } elseif ( 'full_content' === $type ) { | |
| 66 | 72 | $pcp_post_content = get_the_content(); |
| 67 | - } else { | |
| 68 | - $pcp_post_content = get_the_excerpt(); | |
| 69 | 73 | } |
| 70 | - $pcp_post_content = do_shortcode( $wp_embed->autoembed( wpautop( trim( $pcp_post_content ) ) ) ); | |
| 71 | 74 | return $pcp_post_content; |
| 72 | 75 | } |
| 73 | 76 | |
| 74 | 77 | /** |
| @@ -105,11 +108,10 @@ | ||
| 105 | 108 | $thumb_id = attachment_url_to_postid( $placeholder_img ); |
| 106 | 109 | } |
| 107 | 110 | |
| 108 | 111 | if ( ! empty( $thumb_id ) ) { |
| 109 | - $image_sizes = isset( $post_thumb_setting['pcp_thumb_sizes'] ) ? $post_thumb_setting['pcp_thumb_sizes'] : ''; | |
| 110 | - $image_src = wp_get_attachment_image_src( $thumb_id, $image_sizes ); | |
| 111 | - $image_src = is_array( $image_src ) ? $image_src : array( '', '', '' ); | |
| 112 | + $image_sizes = isset( $post_thumb_setting['pcp_thumb_sizes'] ) ? $post_thumb_setting['pcp_thumb_sizes'] : ''; | |
| 113 | + $image_src = wp_get_attachment_image_src( $thumb_id, $image_sizes ); | |
| 112 | 114 | $image = $image_src[0]; |
| 113 | 115 | $image_width = $image_src[1]; |
| 114 | 116 | $image_height = $image_src[2]; |
| 115 | 117 | } elseif ( ! empty( $placeholder_img ) ) { |
| @@ -134,10 +136,10 @@ | ||
| 134 | 136 | */ |
| 135 | 137 | public static function pcp_get_post_meta( $post_meta_fields, $meta_separator ) { |
| 136 | 138 | $i = 0; |
| 137 | 139 | foreach ( $post_meta_fields as $each_meta ) { |
| 138 | - $selected_meta = $each_meta['select_post_meta']; | |
| 139 | - $meta_icon = ! empty( $each_meta['select_meta_icon'] ) ? sprintf( '<i class="' . $each_meta['select_meta_icon'] . '"></i>' ) : ''; | |
| 140 | + $selected_meta = $each_meta['select_post_meta']; | |
| 141 | + $meta_icon = ! empty( $each_meta['select_meta_icon'] ) ? sprintf( '<i class="' . $each_meta['select_meta_icon'] . '"></i>' ) : ''; | |
| 140 | 142 | $meta_tag_start = apply_filters( 'pcp_post_meta_html_tag_start', '<li>' ); |
| 141 | 143 | $meta_tag_end = apply_filters( 'pcp_post_meta_html_tag_end', '</li>' ); |
| 142 | 144 | |
| 143 | 145 | switch ( $selected_meta ) { |
| @@ -142,40 +144,41 @@ | ||
| 142 | 144 | |
| 143 | 145 | switch ( $selected_meta ) { |
| 144 | 146 | case 'author': |
| 145 | 147 | if ( 0 < $i ) { |
| 146 | - echo esc_html( $meta_separator ); | |
| 148 | + echo $meta_separator; | |
| 147 | 149 | } |
| 148 | - echo wp_kses_post( $meta_tag_start ); | |
| 150 | + echo $meta_tag_start; | |
| 149 | 151 | ?> |
| 150 | 152 | <i class="fa fa-user"></i> |
| 151 | - <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" | |
| 152 | - rel="author"><?php echo esc_html( get_the_author() ); ?></a> | |
| 153 | +<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" | |
| 154 | + rel="author"><?php echo esc_html( get_the_author() ); ?></a> | |
| 153 | 155 | <?php |
| 154 | - echo wp_kses_post( $meta_tag_end ); | |
| 156 | + echo $meta_tag_end; | |
| 155 | 157 | break; |
| 156 | 158 | case 'date': |
| 157 | 159 | if ( 0 < $i ) { |
| 158 | - echo esc_html( $meta_separator ); | |
| 160 | + echo $meta_separator; | |
| 159 | 161 | } |
| 160 | - echo wp_kses_post( $meta_tag_start ); | |
| 162 | + echo $meta_tag_start; | |
| 161 | 163 | ?> |
| 162 | 164 | <i class="fa fa-calendar"></i> |
| 163 | - <time class="entry-date published updated"><?php echo esc_html( get_the_date() ); ?></time> | |
| 165 | + | |
| 166 | +<time class="entry-date published updated"><?php echo esc_html( get_the_date() ); ?></time> | |
| 164 | 167 | <?php |
| 165 | - echo wp_kses_post( $meta_tag_end ); | |
| 168 | + echo $meta_tag_end; | |
| 166 | 169 | break; |
| 167 | 170 | case 'comment_count': |
| 168 | 171 | if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) { |
| 169 | 172 | if ( 0 < $i ) { |
| 170 | - echo esc_html( $meta_separator ); | |
| 173 | + echo $meta_separator; | |
| 171 | 174 | } |
| 172 | - echo wp_kses_post( $meta_tag_start ); | |
| 175 | + echo $meta_tag_start; | |
| 173 | 176 | ?> |
| 174 | 177 | <i class="fa fa-comments-o"></i> |
| 175 | 178 | <a href="<?php the_permalink(); ?>"><?php echo esc_html( get_comments_number() ); ?></a> |
| 176 | 179 | <?php |
| 177 | - echo wp_kses_post( $meta_tag_end ); | |
| 180 | + echo $meta_tag_end; | |
| 178 | 181 | } |
| 179 | 182 | break; |
| 180 | 183 | } |
| 181 | 184 | ++$i; |
| @@ -207,9 +210,9 @@ | ||
| 207 | 210 | * |
| 208 | 211 | * @return int |
| 209 | 212 | */ |
| 210 | 213 | public static function pcp_post_per_page( $limit, $post_per_page, $page ) { |
| 211 | - $limit = ( empty( $limit ) || '-1' === $limit ) ? 1000000 : $limit; | |
| 214 | + $limit = ( empty( $limit ) || $limit === '-1' ) ? 10000000 : $limit; | |
| 212 | 215 | $offset = (int) $post_per_page * ( $page - 1 ); |
| 213 | 216 | $final_post_per_page = $post_per_page; |
| 214 | 217 | if ( intval( $post_per_page ) > $limit - $offset ) { |
| 215 | 218 | $final_post_per_page = $limit - $offset; |
| @@ -219,16 +222,16 @@ | ||
| 219 | 222 | |
| 220 | 223 | /** |
| 221 | 224 | * Pagination last page post |
| 222 | 225 | * |
| 223 | - * @param int $limit total post limit. | |
| 224 | - * @param int $post_per_page post per page. | |
| 225 | - * @param int $total_page last post page. | |
| 226 | + * @param [type] $limit total post limit. | |
| 227 | + * @param [type] $post_per_page post per page. | |
| 228 | + * @param [type] $total_page last post page. | |
| 226 | 229 | * |
| 227 | 230 | * @return int. |
| 228 | 231 | */ |
| 229 | 232 | public static function pcp_last_page_post( $limit, $post_per_page, $total_page ) { |
| 230 | - $limit = ( empty( $limit ) || '-1' === $limit ) ? 10000000 : $limit; | |
| 233 | + $limit = ( empty( $limit ) || $limit === '-1' ) ? 10000000 : $limit; | |
| 231 | 234 | $offset = $post_per_page * ( $total_page - 1 ); |
| 232 | 235 | $pcp_last_page_post = $limit - $offset; |
| 233 | 236 | return $pcp_last_page_post; |
| 234 | 237 | } |
| @@ -235,17 +238,17 @@ | ||
| 235 | 238 | |
| 236 | 239 | /** |
| 237 | 240 | * Get view option from view ID |
| 238 | 241 | * |
| 239 | - * @param string $shortcode_id ID of custom field. | |
| 242 | + * @param string $pcp_gl_id ID of custom field. | |
| 240 | 243 | * |
| 241 | 244 | * @return array |
| 242 | 245 | */ |
| 243 | - public static function view_options( $shortcode_id ) { | |
| 244 | - if ( ! $shortcode_id ) { | |
| 246 | + public static function view_options( $pcp_gl_id ) { | |
| 247 | + if ( ! $pcp_gl_id ) { | |
| 245 | 248 | return; |
| 246 | 249 | } |
| 247 | - $view_options = get_post_meta( $shortcode_id, 'sp_pcp_view_options', true ); | |
| 250 | + $view_options = get_post_meta( $pcp_gl_id, 'sp_pcp_view_options', true ); | |
| 248 | 251 | return $view_options; |
| 249 | 252 | } |
| 250 | 253 | |
| 251 | 254 | /** |
| @@ -255,11 +258,12 @@ | ||
| 255 | 258 | * @param array $array_to_get Array to get values of wanted setting. |
| 256 | 259 | * @param mixed|null $assign The value to assign if setting is not found. |
| 257 | 260 | */ |
| 258 | 261 | public static function pcp_metabox_value( $field, $array_to_get = null, $assign = null ) { |
| 259 | - global $shortcode_id; | |
| 262 | + global $pcp_gl_id; | |
| 260 | 263 | if ( empty( $array_to_get ) ) { |
| 261 | - $array_to_get = self::view_options( $shortcode_id ); | |
| 264 | + $array_to_get = self::view_options( $pcp_gl_id ); | |
| 262 | 265 | } |
| 263 | 266 | return isset( $array_to_get[ $field ] ) ? $array_to_get[ $field ] : $assign; |
| 264 | 267 | } |
| 268 | + | |
| 265 | 269 | } |