Server IP : 172.67.214.6 / Your IP : 216.73.216.73 Web Server : LiteSpeed System : Linux premium900.web-hosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64 User : redwjova ( 1790) PHP Version : 8.1.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/redwjova/sort.llc/wp-content/plugins/ultimate-post/addons/builder/blocks/ |
Upload File : |
<?php namespace ULTP\blocks; defined('ABSPATH') || exit; class Post_Excerpt { public function __construct() { add_action('init', array($this, 'register')); } public function get_attributes() { return array( 'blockId' => '', /*============================ Post Excerpt Setting ============================*/ 'excerptLimit' => "150", //-------------------------- // Advanced Style //-------------------------- 'advanceId' => '', 'advanceZindex' => '', 'hideExtraLarge' => false, 'hideDesktop' => false, 'hideTablet' => false, 'hideMobile' => false, 'advanceCss' => '', ); } public function register() { register_block_type( 'ultimate-post/post-excerpt', array( 'editor_script' => 'ultp-blocks-editor-script', 'editor_style' => 'ultp-blocks-editor-css', 'render_callback' => array($this, 'content') ) ); } public function content($attr, $noAjax) { $attr = wp_parse_args($attr, $this->get_attributes()); $block_name = 'post-excerpt'; $wrapper_before = $wrapper_after = $content = ''; $attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : ''; $attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : ''; $attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : ''; $attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : ''; $excerpt = $this->excerpt_word($attr['excerptLimit']); if ($excerpt) { $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"]:'' ).'">'; $wrapper_before .= '<div class="ultp-block-wrapper">'; $content .= '<div class="ultp-builder-excerpt">'; $content .= $excerpt; $content .= '</div>'; $wrapper_after .= '</div>'; $wrapper_after .= '</div>'; } return $wrapper_before.$content.$wrapper_after; } public function excerpt_word($charlength = 200) { $html = ''; $charlength++; $excerpt = get_the_excerpt(); if (mb_strlen( $excerpt ) > $charlength ) { $subex = mb_substr( $excerpt, 0, $charlength ); $exwords = explode( ' ', $subex ); $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) ); if ($excut < 0 ) { $html = mb_substr( $subex, 0, $excut ); } else { $html = $subex; } $html .= '...'; } else { $html = $excerpt; } return $html; } }