'array', 'sanitize_callback' => array( $this, 'sanitize' ), 'default' => addoremo_get_default_settings(), ) ); } /** * Sanitize all values. * * @param mixed $in Raw input. * @return array */ public function sanitize( $in ) { $d = addoremo_get_default_settings(); $in = is_array( $in ) ? $in : array(); $out = array(); // Booleans. $out['enabled'] = empty( $in['enabled'] ) ? 0 : 1; $out['auto_content'] = empty( $in['auto_content'] ) ? 0 : 1; $out['show_arrow'] = empty( $in['show_arrow'] ) ? 0 : 1; $out['fade'] = empty( $in['fade'] ) ? 0 : 1; $out['remember'] = empty( $in['remember'] ) ? 0 : 1; // Text / selector. $selector = isset( $in['selector'] ) ? trim( wp_strip_all_tags( $in['selector'] ) ) : ''; $out['selector'] = '' !== $selector ? $selector : $d['selector']; $out['more_text'] = isset( $in['more_text'] ) ? sanitize_text_field( $in['more_text'] ) : $d['more_text']; $out['less_text'] = isset( $in['less_text'] ) ? sanitize_text_field( $in['less_text'] ) : $d['less_text']; if ( '' === $out['more_text'] ) { $out['more_text'] = $d['more_text']; } if ( '' === $out['less_text'] ) { $out['less_text'] = $d['less_text']; } // Numbers. $out['collapsed_height'] = isset( $in['collapsed_height'] ) ? absint( $in['collapsed_height'] ) : $d['collapsed_height']; $out['collapsed_height'] = max( 1, $out['collapsed_height'] ); $out['mobile_breakpoint'] = isset( $in['mobile_breakpoint'] ) ? absint( $in['mobile_breakpoint'] ) : $d['mobile_breakpoint']; $out['mobile_breakpoint'] = max( 1, $out['mobile_breakpoint'] ); $out['anim_speed'] = isset( $in['anim_speed'] ) ? absint( $in['anim_speed'] ) : $d['anim_speed']; $out['anim_speed'] = min( 2000, max( 0, $out['anim_speed'] ) ); // Enums. $out['device'] = in_array( isset( $in['device'] ) ? $in['device'] : '', array( 'all', 'mobile', 'desktop' ), true ) ? $in['device'] : $d['device']; $out['style'] = in_array( isset( $in['style'] ) ? $in['style'] : '', array( 'link', 'button', 'pill' ), true ) ? $in['style'] : $d['style']; $out['align'] = in_array( isset( $in['align'] ) ? $in['align'] : '', array( 'left', 'center', 'right' ), true ) ? $in['align'] : $d['align']; $out['fade_style'] = in_array( isset( $in['fade_style'] ) ? $in['fade_style'] : '', array( 'solid', 'gradient' ), true ) ? $in['fade_style'] : $d['fade_style']; $out['icon_size'] = isset( $in['icon_size'] ) ? absint( $in['icon_size'] ) : $d['icon_size']; $out['icon_size'] = min( 64, max( 6, $out['icon_size'] ) ); $out['font_weight'] = in_array( isset( $in['font_weight'] ) ? $in['font_weight'] : '', array( '400', '500', '600', '700', '800' ), true ) ? $in['font_weight'] : $d['font_weight']; $out['font_style'] = in_array( isset( $in['font_style'] ) ? $in['font_style'] : '', array( 'normal', 'italic' ), true ) ? $in['font_style'] : $d['font_style']; $family = isset( $in['font_family'] ) ? sanitize_text_field( $in['font_family'] ) : ''; $out['font_family'] = array_key_exists( $family, addoremo_font_stacks() ) ? $family : $d['font_family']; // Colors. $out['text_color'] = $this->hex( isset( $in['text_color'] ) ? $in['text_color'] : '', $d['text_color'] ); $out['button_bg'] = $this->hex( isset( $in['button_bg'] ) ? $in['button_bg'] : '', $d['button_bg'] ); $out['button_hover'] = $this->hex( isset( $in['button_hover'] ) ? $in['button_hover'] : '', $d['button_hover'] ); $out['fade_color'] = $this->hex( isset( $in['fade_color'] ) ? $in['fade_color'] : '', $d['fade_color'] ); $out['fade_color2'] = $this->hex( isset( $in['fade_color2'] ) ? $in['fade_color2'] : '', $d['fade_color2'] ); // URLs. $out['down_arrow'] = isset( $in['down_arrow'] ) ? esc_url_raw( trim( $in['down_arrow'] ) ) : ''; $out['up_arrow'] = isset( $in['up_arrow'] ) ? esc_url_raw( trim( $in['up_arrow'] ) ) : ''; return $out; } /** * Validate a hex color with fallback. * * @param string $val Raw value. * @param string $fallback Default. * @return string */ private function hex( $val, $fallback ) { $c = sanitize_hex_color( $val ); return $c ? $c : $fallback; } /** * Enqueue admin assets on our page only. * * @param string $hook Hook suffix. * @return void */ public function enqueue_admin_assets( $hook ) { if ( 'toplevel_page_' . self::PAGE_SLUG !== $hook ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_media(); wp_enqueue_style( 'addoremo-admin', ADDOREMO_PLUGIN_URL . 'assets/css/addoremo-admin.css', array( 'wp-color-picker' ), addoremo_asset_version( 'assets/css/addoremo-admin.css' ) ); wp_enqueue_script( 'addoremo-admin', ADDOREMO_PLUGIN_URL . 'assets/js/addoremo-admin.js', array( 'jquery', 'wp-color-picker' ), addoremo_asset_version( 'assets/js/addoremo-admin.js' ), true ); } /** * Get a single setting. * * @param string $key Key. * @return mixed */ private function get( $key ) { $s = addoremo_get_settings(); return isset( $s[ $key ] ) ? $s[ $key ] : ''; } /** * Field name attribute. * * @param string $key Key. * @return string */ private function name( $key ) { return self::OPTION_KEY . '[' . $key . ']'; } /** * Toggle-switch field. * * @param string $key Key. * @param string $label Label. * @param string $help Help text. * @param mixed $value Checked value (default 1). * @return void */ private function toggle( $key, $label, $help, $value = 1 ) { ?>

__( 'Normal (400)', 'addoncraft-read-more-show-less' ), '500' => __( 'Medium (500)', 'addoncraft-read-more-show-less' ), '600' => __( 'Semi-bold (600)', 'addoncraft-read-more-show-less' ), '700' => __( 'Bold (700)', 'addoncraft-read-more-show-less' ), '800' => __( 'Extra-bold (800)', 'addoncraft-read-more-show-less' ), ); ?>

v
toggle( 'enabled', __( 'Enable on front end', 'addoncraft-read-more-show-less' ), __( 'Master switch for the whole plugin.', 'addoncraft-read-more-show-less' ) ); ?> toggle( 'auto_content', __( 'Auto-apply to post content', 'addoncraft-read-more-show-less' ), __( 'Collapse long single post/page content automatically — no shortcode or class needed.', 'addoncraft-read-more-show-less' ) ); ?>

toggle( 'remember', __( 'Remember open state', 'addoncraft-read-more-show-less' ), __( 'Keep a block expanded for the visitor after they reload the page.', 'addoncraft-read-more-show-less' ) ); ?>
toggle( 'show_arrow', __( 'Show arrow icon', 'addoncraft-read-more-show-less' ), __( 'Display a chevron next to the label.', 'addoncraft-read-more-show-less' ) ); ?>
get( 'style' ); foreach ( array( 'link' => __( 'Text link', 'addoncraft-read-more-show-less' ), 'button' => __( 'Button', 'addoncraft-read-more-show-less' ), 'pill' => __( 'Pill', 'addoncraft-read-more-show-less' ), ) as $val => $lbl ) { printf( '', esc_attr( $this->name( 'style' ) ), esc_attr( $val ), checked( $style, $val, false ), esc_attr( $style === $val ? 'is-active' : '' ), esc_html( $lbl ) ); } ?>
toggle( 'fade', __( 'Fade overlay', 'addoncraft-read-more-show-less' ), __( 'Fade the bottom of collapsed content so it hints there is more below.', 'addoncraft-read-more-show-less' ) ); ?>

media_field( 'down_arrow', __( 'Custom collapsed (down) icon', 'addoncraft-read-more-show-less' ) ); $this->media_field( 'up_arrow', __( 'Custom expanded (up) icon', 'addoncraft-read-more-show-less' ) ); ?>

  1. :
  2. : [addoremo_read_more height="200" more="Read more" less="Show less"]…your content…[/addoremo_read_more]
  3. : get( 'selector' ) ); ?>
get( $key ); ?>