plugin_dir_url( __FILE__ ) . 'src/assets/images/placeholder.svg', ) ); } /** * Calculate Read Time * * @param string $content content string. */ public static function calculate_read_time( $content ) { $word_count = str_word_count( strip_tags( $content ) ); $words_per_minute = 200; $read_time = ceil( $word_count / $words_per_minute ); return $read_time; } /** * Pagination Function * * The pagination function to display pagination on any archive page * * @param number $pages are total number of pages. * @param array $args is a array of pagination settings. * * @return void|string */ public static function pagination( $pages = '', $args = array() ) { $showitems = $args['showitems'] ?? 5; $first_last = $args['first_last'] ?? true; $prev_next = $args['prev_next'] ?? true; $show_range = $args['show_range'] ?? true; $has_dotted = $args['has_dotted'] ?? false; $is_ajax = $args['is_ajax'] ?? false; $class_name = $args['class_name'] ?? ''; $ajax_paged = $args['paged'] ?? 1; $pagination_unique_classes = 'pagination-' . $class_name; if ( true === $is_ajax ) { $paged = $ajax_paged; } else { $paged = $ajax_paged; } if ( '' === $pages ) { global $wp_query; $pages = $wp_query->max_num_pages; if ( ! $pages ) { $pages = 1; } } if ( $is_ajax ) { $html = ''; if ( 1 !== $pages ) { $pagination_unique_classes .= ' ajax-pagination-' . $class_name; $html .= ''; } return $html; } else { if ( 1 !== $pages ) { echo ''; } } } /** * Get current page url */ public static function get_current_page_url() { $protocol = ( ! empty( $_SERVER['HTTPS'] ) && 'off' !== $_SERVER['HTTPS'] ) || ( ! empty( $_SERVER['SERVER_PORT'] ) && 443 === $_SERVER['SERVER_PORT'] ) ? 'https://' : 'http://'; if ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) { $url = esc_url( wp_unslash( $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ); return $url; } return null; } /** * Get page number from url * * @param string $url page url. */ public static function get_page_number_from_url( $url ) { $pattern = '/\/page\/(\d+)\//'; if ( preg_match( $pattern, $url, $matches ) ) { return isset( $matches[1] ) ? (int) $matches[1] : null; } return null; } /** * Shortcode to render Advance Post Grid * * @param array $attributes Attributes array data. * * Usage: [advance_post_grid postGrid="3" postType="post" postPerPage="6" PostOrder="DESC" PostOrderBy="date" showHidePagi="true" showHideLink="true" showHideCat="true" showHideRT="true"] */ public function shortcode_render( $attributes ) { ob_start(); // Remap lowercase attrs back to camelCase. $mapped_attrs = array(); foreach ( $attributes as $key => $value ) { switch ( strtolower( $key ) ) { case 'postgrid': $mapped_attrs['postGrid'] = $value; break; case 'postgridmobile': $mapped_attrs['postGridMobile'] = $value; break; case 'postgridtablet': $mapped_attrs['postGridTablet'] = $value; break; case 'enablepostgridres': $mapped_attrs['enablePostGridRes'] = filter_var( $value, FILTER_VALIDATE_BOOLEAN ); break; case 'posttype': $mapped_attrs['postType'] = $value; break; case 'postperpage': $mapped_attrs['postPerPage'] = $value; break; case 'postorder': $mapped_attrs['PostOrder'] = $value; break; case 'postorderby': $mapped_attrs['PostOrderBy'] = $value; break; case 'showhidepagi': $mapped_attrs['showHidePagi'] = filter_var( $value, FILTER_VALIDATE_BOOLEAN ); break; case 'showhidelink': $mapped_attrs['showHideLink'] = filter_var( $value, FILTER_VALIDATE_BOOLEAN ); break; case 'showhidecat': $mapped_attrs['showHideCat'] = filter_var( $value, FILTER_VALIDATE_BOOLEAN ); break; case 'showhidert': $mapped_attrs['showHideRT'] = filter_var( $value, FILTER_VALIDATE_BOOLEAN ); break; } } // Merge with defaults $attributes = shortcode_atts( array( 'postGrid' => 3, 'enablePostGridRes' => false, 'postGridTablet' => 2, 'postGridMobile' => 1, 'postType' => 'post', 'postPerPage' => 12, 'PostOrder' => 'DESC', 'PostOrderBy' => 'title', 'showHidePagi' => true, 'showHideLink' => true, 'showHideCat' => true, 'showHideRT' => true, ), $mapped_attrs, 'advance_post_grid' ); wp_enqueue_style( 'advance-post-grid-style', plugin_dir_url( __FILE__ ) . 'build/style-index.css', array(), filemtime( plugin_dir_path( __FILE__ ) . 'build/style-index.css' ) ); require_once __DIR__ . '/build/render.php'; return ob_get_clean(); } } new WO_APG_Init();