'3', 'per_page' => '12', 'orderby' => 'date', 'order' => 'DESC', 'search' => 'true', ), $atts, 'flipset_library' ); $columns = $this->clamp_int( $atts['columns'], 1, 6, 3 ); $per_page = $this->clamp_int( $atts['per_page'], 1, 48, 12 ); $orderby = $this->sanitize_orderby( $atts['orderby'] ); $order = ( 'ASC' === strtoupper( $atts['order'] ) ) ? 'ASC' : 'DESC'; $search_on = $this->att_flag( $atts['search'] ?? 'true', true ); $uid = ++self::$instance_n; $instance_id = 'flipset-library-' . $uid; $query_var = 'flipset_page_' . $uid; $search_var = 'flipset_q_' . $uid; $paged = 1; if ( isset( $_GET[ $query_var ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- public pagination query var. $paged = max( 1, absint( wp_unslash( $_GET[ $query_var ] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- public pagination query var. } $search = ''; if ( $search_on && isset( $_GET[ $search_var ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- public search query var. $search = sanitize_text_field( wp_unslash( $_GET[ $search_var ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- public search query var. } $query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_mime_type' => 'application/pdf', 'posts_per_page' => $per_page, 'paged' => $paged, 'orderby' => $orderby, 'order' => $order, 's' => $search, 'no_found_rows' => false, 'flipset_content_search' => ( '' !== $search ), ) ); if ( ! $query->have_posts() ) { wp_enqueue_style( 'flipset-library', FLIPSET_URL . 'assets/css/flipset-library.css', array(), FLIPSET_VERSION ); wp_reset_postdata(); $html = '
'; $html .= $this->render_search_form( $search_on, $search, $search_var, $query_var ); $html .= $this->render_empty( $search ); $html .= '
'; return wp_kses( $html, Flipset_Viewer::allowed_html() ); } $this->enqueue_assets(); ob_start(); ?>
render_search_form( $search_on, $search, $search_var, $query_var ), Flipset_Viewer::allowed_html() ); ?> render_pagination( $query, $paged, $query_var, $search_var, $search ), Flipset_Viewer::allowed_html() ); ?>
ID; $url = wp_get_attachment_url( $id ); if ( ! $url ) { return ''; } $title = get_the_title( $attachment ); if ( '' === $title ) { $title = wp_basename( $url ); } $embed_id = 'flipset-library-embed-' . wp_unique_id(); $thumb_id = Flipset_Thumbnails::get_thumbnail_id( $id ); $image = ''; if ( $thumb_id ) { $image = wp_get_attachment_image( $thumb_id, 'medium', false, array( 'class' => 'flipset-library-image', 'loading' => 'lazy', 'alt' => $title, ) ); } if ( ! $image ) { $image = ''; } $viewer = Flipset::instance()->viewer->render_shortcode( array( 'file' => $url, 'width' => '100%', 'hash' => 'false', ) ); $viewer = str_replace( ' class="flipset-viewer"', ' class="flipset-viewer" data-flipset-defer="1"', $viewer ); ob_start(); ?>
  • max_num_pages < 2 ) { return ''; } $add_args = array(); if ( '' !== $search_var && '' !== $search ) { $add_args[ $search_var ] = $search; } $links = paginate_links( array( 'base' => add_query_arg( $query_var, '%#%' ), 'format' => '', 'total' => (int) $query->max_num_pages, 'current' => $paged, 'type' => 'list', 'add_args' => $add_args, 'prev_text' => __( 'Previous', 'flipset' ), 'next_text' => __( 'Next', 'flipset' ), ) ); if ( ! $links ) { return ''; } return ''; } private function render_empty( $search = '' ) { $message = '' !== $search ? __( 'No PDFs matched that search.', 'flipset' ) : __( 'No PDFs found.', 'flipset' ); $html = '

    ' . esc_html( $message ) . '

    '; if ( current_user_can( 'upload_files' ) ) { $html .= '

    ' . esc_html__( 'Upload a PDF', 'flipset' ) . '

    '; } $html .= '
    '; return $html; } private function enqueue_assets() { if ( $this->assets_enqueued ) { return; } $this->assets_enqueued = true; Flipset::instance()->viewer->enqueue_assets(); wp_enqueue_style( 'flipset-library', FLIPSET_URL . 'assets/css/flipset-library.css', array( 'flipset-viewer' ), FLIPSET_VERSION ); wp_enqueue_script( 'flipset-library', FLIPSET_URL . 'assets/js/flipset-library.js', array( 'flipset-viewer' ), FLIPSET_VERSION, true ); } private function placeholder_icon() { return ''; } private function clamp_int( $value, $min, $max, $default ) { $n = absint( $value ); if ( $n < $min || $n > $max ) { return $default; } return $n; } private function sanitize_orderby( $value ) { $value = sanitize_key( $value ); $allowed = array( 'date', 'title', 'modified' ); return in_array( $value, $allowed, true ) ? $value : 'date'; } }