loadAssets(); $attributes = $this->parseAttributes($atts); $renderFile = GIVE_PLUGIN_DIR . 'src/Campaigns/Blocks/CampaignGrid/render.php'; return ShortcodeRenderController::renderWithBlockContext( $renderFile, 'givewp/campaign-grid-block', $attributes ); } /** * @since 4.3.0 Use info from asset.php file and set script translations * @since 4.2.0 */ public function loadAssets() { give(LoadCampaignPublicOptions::class)(); $handleName = 'givewp-campaign-grid-app'; $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/campaignGridApp.asset.php'); wp_enqueue_script( $handleName, GIVE_PLUGIN_URL . 'build/campaignGridApp.js', $asset['dependencies'], $asset['version'], true ); Language::setScriptTranslations($handleName); wp_enqueue_style( $handleName, GIVE_PLUGIN_URL . 'build/campaignGridApp.css', [], $asset['version'] ); wp_enqueue_style('givewp-design-system-foundation'); } /** * @since 4.18.0 Sanitize string attributes and restrict enumerated values. * @since 4.2.0 */ private function parseAttributes($atts): array { $atts = shortcode_atts([ 'layout' => 'full', 'show_image' => true, 'show_description' => true, 'show_goal' => true, 'sort_by' => 'date', 'order_by' => 'desc', 'per_page' => 6, 'show_pagination' => true, 'filter_by' => null, ], $atts, 'givewp_campaign_grid'); return [ 'layout' => $this->pickAllowed($atts['layout'], ['full', 'double', 'triple'], 'full'), 'showImage' => filter_var($atts['show_image'], FILTER_VALIDATE_BOOLEAN), 'showDescription' => filter_var($atts['show_description'], FILTER_VALIDATE_BOOLEAN), 'showGoal' => filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN), 'sortBy' => $this->pickAllowed($atts['sort_by'], ['date', 'amount', 'donations', 'donors'], 'date'), 'orderBy' => $this->pickAllowed($atts['order_by'], ['asc', 'desc'], 'desc'), 'filterBy' => $atts['filter_by'] ? sanitize_text_field($atts['filter_by']) : $atts['filter_by'], 'perPage' => (int)$atts['per_page'], 'showPagination' => filter_var($atts['show_pagination'], FILTER_VALIDATE_BOOLEAN), ]; } /** * @since 4.18.0 */ private function pickAllowed($value, array $allowed, $default): string { return in_array($value, $allowed, true) ? $value : $default; } }