/**
  * Convert keys to machine format
  * @param array $array
  * @param string $separator
  * @return array
  */
 public static function machineKeys($array, $separator = '_')
 {
     $keys = array_keys($array);
     $keys = array_map(function ($el) use($separator) {
         return Str::machine($el, $separator);
     }, $keys);
     return array_combine($keys, $array);
 }
Beispiel #2
0
 /**
  * Get a table
  * @param array $records
  * @return string
  */
 public static function tably($records)
 {
     if (count($records) === 0) {
         return null;
     }
     $htmls = array();
     $htmls[] = '<table>';
     foreach ($records as $record) {
         $htmls[] = '<tr>';
         foreach ($record as $k => $v) {
             $htmls[] = sprintf('<td class="%s">%s</td>', Str::machine($k), $v);
         }
         $htmls[] = '</tr>';
     }
     $htmls[] = '</table>';
     return join("\n", $htmls);
 }
function add_slug_to_body_class($classes = [])
{
    global $post;
    $file_name = basename($_SERVER['SCRIPT_FILENAME'], '.php');
    $queried_object = get_queried_object();
    $is_term = is_object($queried_object) && property_exists($queried_object, 'term_taxonomy_id');
    if (!$is_term && !is_null($post)) {
        $classes[] = $post->post_name;
    } else {
        $classes[] = Str::machine($file_name, '-');
    }
    return $classes;
}
 /**
  * Replace non-breaking spaces with regular spaces
  * @param string $input
  * @return string
  */
 public static function clean($input)
 {
     return Str::machine($input, ' ');
 }
 /**
  * Get terms used within one post type
  * Covers multiple taxonomies if applicable
  * @return array
  */
 public static function getTermsUsed()
 {
     global $wpdb;
     $sql_terms = sprintf("SELECT DISTINCT\n          t.term_id,\n          t.name,\n          t.slug,\n          tt.taxonomy\n        FROM %s AS t\n        INNER JOIN %s AS tt ON tt.term_id = t.term_id\n        INNER JOIN %s AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id\n        INNER JOIN %s AS p ON p.ID = tr.object_id\n        WHERE p.post_type = '%s'\n        AND p.post_status = 'publish'\n        ORDER BY t.name ASC", $wpdb->terms, $wpdb->term_taxonomy, $wpdb->term_relationships, $wpdb->posts, \Str::machine(get_called_class(), '-'));
     return $wpdb->get_results($sql_terms, ARRAY_A);
 }