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();