'1', 'saved_value' => '', 'option_key' => $name, 'class' => ''); $options = array_merge($default_options, $options); $out = "\n"; $out .= '
'; $out .= ''; $out .= ''; $out .= '
'; if ($echo) { echo $out; } else { return $out; } } // create_toggle_switch /** * Helper for creating checkboxes. * * @param string $value Checkbox value, in HTML. * @param array $current Current, saved value of checkbox. * @param boolean $echo Default: false. * * @return void|string */ static function checked($value, $current, $echo = false) { $out = ''; if (!is_array($current)) { $current = (array) $current; } if (in_array($value, $current)) { $out = ' checked="checked" '; } if ($echo) { echo $out; } else { return $out; } } // checked /** * Format file size to human readable string * * @param int $bytes Size in bytes to format. * * @return string */ static function format_size($bytes) { if ($bytes > 1073741824) { return number_format_i18n($bytes / 1073741824, 2) . ' GB'; } elseif ($bytes > 1048576) { return number_format_i18n($bytes / 1048576, 1) . ' MB'; } elseif ($bytes > 1024) { return number_format_i18n($bytes / 1024, 1) . ' KB'; } else { return number_format_i18n($bytes, 0) . ' bytes'; } } // format_size /** * Create select options for select * * @param array $options options * @param string $selected selected value * @param bool $output echo, if false return html as string * @return string html with options */ static function create_select_options($options, $selected = null, $output = true) { $out = "\n"; if (is_array($options) && !empty($options) && !isset($options[0]['val'])) { $tmp = array(); foreach ($options as $val => $label) { $tmp[] = array('val' => $val, 'label' => $label); } // foreach $options = $tmp; } foreach ($options as $tmp) { if ($selected == $tmp['val']) { $out .= "\n"; } else { $out .= "\n"; } } if ($output) { echo $out; } else { return $out; } } // create_select_options /** * Get table size and row count as html * * @return string html with table details */ static function get_table_details() { global $wpdb, $wp_reset; $tbl_core = $tbl_custom = $tbl_size = $tbl_rows = 0; $table_status = $wpdb->get_results('SHOW TABLE STATUS'); if (is_array($table_status)) { foreach ($table_status as $index => $table) { if (0 !== stripos($table->Name, $wpdb->prefix)) { continue; } if (empty($table->Engine)) { continue; } $tbl_rows += $table->Rows; $tbl_size += $table->Data_length + $table->Index_length; if (in_array($table->Name, $wp_reset->core_tables)) { $tbl_core++; } else { $tbl_custom++; } } // foreach } else { return ' no tables found.'; } return ' totaling ' . self::format_size($tbl_size) . ' in ' . number_format($tbl_rows) . ' rows.'; } // get_table_details } // WP_Reset_Utility