golden hour
/home/godaofbq/.trash/wp-cloudflare-page-cache/src/views
⬆️ Go Up
Upload
File/Folder
Size
Actions
admin_js_tab.php
2.53 KB
Del
OK
admin_media_tab.php
4.13 KB
Del
OK
excluded_url_params.php
752 B
Del
OK
optimole.php
3.46 KB
Del
OK
sidebar.php
950 B
Del
OK
template_functions.php
6.29 KB
Del
OK
Edit: template_functions.php
<?php namespace SPC\Views\Functions; use SPC\Loader; use SPC\Modules\Settings_Manager; function render_description( $text, $highlighted = false, $hide = false, $ignore_spacing = false ) { if ( $hide ) { return; } $classes = 'description'; if ( $highlighted ) { $classes .= ' highlighted'; } if ( ! $ignore_spacing ) { echo '<br/>'; } echo '<div class="' . esc_attr( $classes ) . '">' . wp_kses_post( $text ) . '</div>'; } function get_header_pill( $type ) { $pills = [ 'update-wp' => '<span class="swcfpc_plugin_inactive">' . __( 'Update WordPress', 'wp-cloudflare-page-cache' ) . '</span>', ]; return array_key_exists( $type, $pills ) ? $pills[ $type ] : ''; } function render_pro_tag( $utm_campaign = 'pro-tag' ) { echo sprintf( '<a href="%s" target="_blank" class="spc-pro-tag"><span class="dashicons dashicons-lock"></span><span>%s</span></a>', esc_url( tsdk_utmify( 'https://themeisle.com/plugins/super-page-cache-pro', $utm_campaign ) ), __( 'Pro', 'wp-cloudflare-page-cache' ) ); } function render_header( $text, $first = false, $pill = '' ) { $classes = 'main_section_header'; if ( $first ) { $classes .= ' first_section'; } echo '<div class="' . esc_attr( $classes ) . '">'; echo '<h3>'; echo esc_html( $text ); if ( ! empty( $pill ) ) { echo wp_kses_post( get_header_pill( $pill ) ); } echo '</h3>'; echo '</div>'; } function render_update_wordpress_notice() { /* translators: %s: link to WordPress update page - 'update now' */ render_description( sprintf( __( 'This feature requires WordPress 6.2 or higher. %s to access all features.', 'wp-cloudflare-page-cache' ), '<a href="' . esc_url( admin_url( 'update-core.php' ) ) . '" target="_blank">' . __( 'Update now', 'wp-cloudflare-page-cache' ) . '</a>', ), true, Loader::can_process_html() ); } function render_switch( $setting_id, $fallback_default = 0, $conditional = '', $disabled = false ) { global $sw_cloudflare_pagecache; $config_value = (int) $sw_cloudflare_pagecache->get_single_config( $setting_id, Settings_Manager::get_default_for_field( $setting_id, $fallback_default ) ); $inputs = [ [ 'label' => __( 'Yes', 'wp-cloudflare-page-cache' ), 'value' => 1, 'suffix' => 'left', ], [ 'label' => __( 'No', 'wp-cloudflare-page-cache' ), 'value' => 0, 'suffix' => 'right', ], ]; echo '<div class="switch-field">'; foreach ( $inputs as $input ) { $id = "{$setting_id}_{$input['suffix']}"; $attrs = [ 'type' => 'radio', 'name' => "swcfpc_{$setting_id}", 'id' => $id, 'value' => $input['value'], 'class' => '', ]; if ( $conditional ) { $attrs['class'] .= ' conditional_item'; $attrs['data-mainoption'] = $conditional; } if ( $disabled ) { $attrs['class'] .= ' disabled'; } echo '<input ' . attributes_array_to_string( $attrs ) . ' ' . checked( $config_value, $input['value'], false ) . ' />'; echo '<label for="' . esc_attr( $id ) . '">' . esc_html( $input['label'] ) . '</label>'; } echo '</div>'; } function render_textarea( $setting_id, $placeholder = '', $fallback_default = [], $disabled = false ) { global $sw_cloudflare_pagecache; $values = $sw_cloudflare_pagecache->get_single_config( $setting_id, Settings_Manager::get_default_for_field( $setting_id, $fallback_default ) ); $value = is_array( $values ) && count( $values ) > 0 ? implode( "\n", $values ) : ''; $attrs = [ 'name' => 'swcfpc_' . $setting_id, 'placeholder' => $placeholder, ]; if ( $disabled ) { $attrs['disabled'] = true; } echo '<textarea ' . attributes_array_to_string( $attrs ) . '>'; echo esc_attr( $value ); echo '</textarea>'; } function render_checkbox( $setting_id, $label = '', $recommended = false, $fallback_default = 0 ) { global $sw_cloudflare_pagecache; $value = $sw_cloudflare_pagecache->get_single_config( $setting_id, Settings_Manager::get_default_for_field( $setting_id, $fallback_default ) ); $attrs = [ 'name' => 'swcfpc_' . $setting_id, 'id' => $setting_id, 'type' => 'checkbox', 'value' => $value, ]; echo '<div>'; // Hack because otherwise when unchecked, value will not exist. echo '<input type="hidden" name="swcfpc_' . $setting_id . '" value="0" />'; echo '<input ' . attributes_array_to_string( $attrs ) . ' ' . checked( 1, $value, false ) . ' />'; if ( ! empty( $label ) ) { echo '<label for="' . esc_attr( $setting_id ) . '">'; echo ' ' . esc_html( $label ); if ( $recommended ) { echo ' - <strong>' . __( '(recommended)', 'wp-cloudflare-page-cache' ) . '</strong>'; } echo '</label>'; } echo '</div>'; } function render_number_field( $setting_id, $fallback_default = 0, $input_attrs = [] ) { global $sw_cloudflare_pagecache; $defaults = [ 'type' => 'number', 'step' => 1, 'min' => 0, 'max' => 100, 'name' => "swcfpc_{$setting_id}", 'value' => (int) $sw_cloudflare_pagecache->get_single_config( $setting_id, Settings_Manager::get_default_for_field( $setting_id, $fallback_default ) ), ]; $attrs = is_array( $input_attrs ) ? wp_parse_args( $input_attrs, $defaults ) : $defaults; echo '<input ' . attributes_array_to_string( $attrs ) . ' />'; } function render_dummy_switch( $id, $default = 0 ) { render_switch( 'dummy_switch_' . $id, $default, false, true ); } function render_dummy_textarea( $id, $placeholder = '' ) { render_textarea( 'dummy_textarea_' . $id, $placeholder, '', true ); } /** * Convert an array of attributes to a string to be used in HTML tags. * * @param array $attrs The attributes to convert to string. * * @return string */ function attributes_array_to_string( $attrs ) { $attributes = array_map( function ( $key, $value ) { return sprintf( '%s="%s"', esc_attr( $key ), esc_attr( $value ) ); }, array_keys( $attrs ), $attrs ); return implode( ' ', $attributes ); } /** * Load a view file. * * @param string $view The view file to load. * @param string $id The view ID to be used if the view is filtered later. */ function load_view( $view, $id = '' ) { if ( empty( $id ) ) { $id = $view; } $default_template = sprintf( '%s/src/views/%s.php', untrailingslashit( SWCFPC_PLUGIN_PATH ), $view ); $template = apply_filters( 'swcfpc_admin_tab_view_path', $default_template, $id ); $template = is_file( $template ) ? $template : $default_template; if ( ! is_file( $template ) ) { return; } include_once $template; }
Save