page . '_' . $section['id'], $section['title'], array( $this, 'section_description' ), $this->page . '_' . $section['id'] ); } } /** * Generic function to add settings fields * * @param $fields * @param array $sections registered sections * * @since 2.4.0 */ protected function add_fields( $fields, $sections ) { foreach ( $fields as $field ) { add_settings_field( '[' . $field['id'] . ']', sprintf( '', $field['id'], $field['title'] ), array( $this, $field['callback'] ), $this->page . '_' . $sections[ $field['section'] ]['id'], $this->page . '_' . $sections[ $field['section'] ]['id'], $field ); } } /** * Set which tab is considered active. * @return string * @since 2.5.0 */ protected function get_active_tab() { $tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING ); return $tab ? $tab : 'main'; } /** * Echoes out the section description. * * @since 2.3.0 * * @param $section */ public function section_description( $section ) { $id = str_replace( "{$this->page}_", '', $section['id'] ); $method = "{$id}_section_description"; if ( method_exists( $this, $method ) ) { echo wp_kses_post( wpautop( $this->$method() ) ); } } /** * Generic callback to create a number field setting. * * @since 2.3.0 * * @param $args */ public function do_number( $args ) { printf( '', (int) $args['min'], (int) $args['max'], esc_attr( $args['id'] ), esc_attr( $this->setting[ $args['id'] ] ), esc_attr( $this->page ), esc_attr( $args['label'] ) ); $this->do_description( $args ); } /** * generic checkbox function (for all checkbox settings) * * @since 2.3.0 * * @param $args */ public function do_checkbox( $args ) { $setting = $this->get_checkbox_setting( $args ); printf( '', esc_attr( $this->page ), esc_attr( $args['id'] ) ); printf( '', esc_attr( $args['id'] ), checked( 1, esc_attr( $setting ), false ), esc_attr( $args['label'] ), esc_attr( $this->page ) ); $this->do_description( $args ); } /** * Get the current value for the checkbox. * * @param $args * * @return int */ protected function get_checkbox_setting( $args ) { $setting = isset( $this->setting[ $args['id'] ] ) ? $this->setting[ $args['id'] ] : 0; if ( isset( $args['setting_name'] ) && isset( $this->setting[ $args['setting_name'] ][ $args['name'] ] ) ) { $setting = $this->setting[ $args['setting_name'] ][ $args['name'] ]; } return $setting; } /** * Build a checkbox array. * * @param $args */ public function do_checkbox_array( $args ) { foreach ( $args['options'] as $key => $value ) { $type_args = array( 'id' => "{$args['id']}][{$key}", 'label' => $value, 'setting_name' => $args['id'], 'name' => $key, ); $this->do_checkbox( $type_args ); } } /** * radio buttons * @since 2.6.0 * * @param $args */ public function do_radio_buttons( $args ) { echo '
'; } /** * Generic callback to display a field description. * * @param $args array * * @since 2.3.0 */ protected function do_description( $args ) { $description = isset( $args['description'] ) ? $args['description'] : false; $function = $args['id'] . '_description'; if ( method_exists( $this, $function ) ) { $description = $this->$function(); } if ( ! $description ) { return; } printf( '%s
', wp_kses_post( $description ) ); } /** * display image preview * * @param int $id featured image ID * @param $alt string description for alt text * * @return string * * @since 2.3.0 */ public function render_image_preview( $id, $alt = '' ) { if ( empty( $id ) ) { return ''; } $id = displayfeaturedimagegenesis_check_image_id( $id ); /* translators: the placeholder refers to which featured image */ $alt_text = sprintf( __( '%s featured image', 'display-featured-image-genesis' ), esc_attr( $alt ) ); $preview = wp_get_attachment_image_src( (int) $id, 'medium' ); return sprintf( '