page $perPage = empty($stdOpts['pagination']['num_items']) ? 0 : $stdOpts['pagination']['num_items']; $numPages = ($perPage > 0) ? ceil($count / $perPage) : 1; $page = empty($stdOpts['pagination']['page']) ? 1 : $stdOpts['pagination']['page']; // Parse the template-type's own options $ttOpts = $this->parseArgsWithSchema($pOpts, $this->getOptions()); // Get all options by merging std options with template type options $allOpts = ( isset($stdOpts['options']) && !empty($stdOpts['options']) ) ? array_merge_recursive($stdOpts['options'], $ttOpts) : $ttOpts; return [ 'items' => $items, 'options' => $allOpts, 'pagination' => [ 'page' => $page, 'total_num_items' => $count, 'items_per_page' => $perPage, 'num_pages' => $numPages, ], 'self' => [ 'slug' => $stdOpts['template'], 'type' => $this->getKey(), 'path' => $this->getTemplatePath(), 'dir' => $this->getTemplateDir(), ], ]; } /** * Retrieves the WPRA-standard template type options. * * @since 4.13 * * @return array */ protected function getStandardOptions() { return [ 'template' => [ 'default' => '', 'filter' => FILTER_DEFAULT, ], 'source' => [ 'key' => 'filters/sources', 'default' => [], 'filter' => function ($value) { return $this->sanitizeIdCommaList($value); }, ], 'feeds' => [ 'key' => 'filters/feeds', 'filter' => function ($value, $args) { return $this->sanitizeCommaList($value); }, ], 'sources' => [ 'key' => 'filters/sources', 'filter' => function ($value, $args) { return $this->sanitizeIdCommaList($value); }, ], 'exclude' => [ 'key' => 'filters/exclude', 'default' => [], 'filter' => function ($value) { return $this->sanitizeIdCommaList($value); }, ], 'limit' => [ 'key' => 'pagination/num_items', 'default' => 15, 'filter' => FILTER_VALIDATE_INT, 'options' => ['min_range' => 1], ], 'page' => [ 'key' => 'pagination/page', 'default' => 1, 'filter' => FILTER_VALIDATE_INT, 'options' => ['min_range' => 1], ], 'pagination' => [ 'key' => 'pagination/enabled', 'filter' => FILTER_VALIDATE_BOOLEAN, ], 'links_behavior' => [ 'key' => 'options/links_open_behavior', 'filter' => 'enum', 'options' => ['self', 'blank', 'lightbox'], 'default' => 'blank', ], 'links_nofollow' => [ 'key' => 'options/links_rel_nofollow', 'filter' => function ($val) { return $val === 'no_follow' || filter_var($val, FILTER_VALIDATE_BOOLEAN); }, 'default' => true, ], 'link_to_embed' => [ 'key' => 'options/link_to_embed', 'filter' => FILTER_VALIDATE_BOOLEAN, 'default' => false, ], 'custom_css_classname' => [ 'key' => 'options/custom_css_classname', 'filter' => FILTER_DEFAULT, 'default' => '', ], 'className' => [ 'key' => 'options/className', 'filter' => FILTER_DEFAULT, 'default' => '', ], ]; } /** * Creates the data set instance for a given template render context. * * @since 4.13 * * @param array $ctx The render context. * * @return DataSetInterface The created data set instance. */ protected function createContextDataSet(array $ctx) { return new ArrayDataSet($ctx); } /** * The standard pagination localization. */ protected function localizePaginationJs() { wp_localize_script('wpra-pagination', 'WpraPagination', [ 'baseUri' => rest_url('/wpra/v1/templates/%s/render/'), 'scrollOnPageLoad' => apply_filters('wpra/templates/scroll_on_page_load', true), 'scrollDuration' => apply_filters('wpra/templates/scroll_duration', 500), ]); } } circle — CRYPT.ru

circle