예제 #1
0
 /**
  * For given URL, try to find an attachment with this file and if successful, try finding thumbnail URL.
  *
  * Returns original URL on failure.
  *
  * @param string $url Image URL
  * @return string URl of the thumbnail or original image.
  * @since 1.9.1
  */
 protected function try_finding_attachment($url)
 {
     $attachment_id = Types_Utils::get_attachment_id_by_url($url);
     if (0 == $attachment_id) {
         return $url;
     }
     $attachment_src = wp_get_attachment_image_src($attachment_id, 'thumbnail');
     if (false == $attachment_src) {
         return $url;
     }
     return is_string($attachment_src[0]) ? $attachment_src[0] : $url;
 }
 /**
  * Does the field definition match a certain string?
  *
  * Searches it's name and slug.
  *
  * @param string $search_string
  * @return bool
  */
 public function is_match($search_string)
 {
     return Types_Utils::is_string_match($search_string, $this->get_name()) || Types_Utils::is_string_match($search_string, $this->get_slug());
 }
 /**
  * Add a column for each term field on the term listing page.
  *
  * @param string[string] $columns Column definitions (column name => display name).
  * @return string[string] Updated column definitions.
  * @link https://make.wordpress.org/docs/plugin-developer-handbook/10-plugin-components/custom-list-table-columns/
  * @since 1.9.1
  */
 public function manage_term_listing_columns($columns)
 {
     $factory = Types_Field_Group_Term_Factory::get_instance();
     $taxonomy_slug = sanitize_text_field(wpcf_getget('taxonomy'));
     $groups = $factory->get_groups_by_taxonomy($taxonomy_slug);
     $columns_to_insert = array();
     foreach ($groups as $group) {
         foreach ($group->get_field_definitions() as $field_definition) {
             $columns_to_insert[self::LISTING_COLUMN_PREFIX . $field_definition->get_slug()] = $field_definition->get_display_name();
         }
     }
     $this->added_listing_columns = $columns_to_insert;
     // Insert before the last column, which displays counts of posts using the term (that's probably why column
     // has the label "Count" and name "posts" :-P).
     // If there is no "posts"=>"Count" column, insert at the end.
     if (isset($columns['posts']) && 'Count' == $columns['posts']) {
         $columns = Types_Utils::insert_at_position($columns, $columns_to_insert, array('key' => 'posts', 'where' => 'before'));
     } else {
         $columns = Types_Utils::insert_at_position($columns, $columns_to_insert, -1);
     }
     return $columns;
 }
예제 #4
0
 /**
  * @param $item Types_Field_Group_Term
  *
  * @return string
  */
 function column_taxonomies($item)
 {
     $taxonomies = $item->get_associated_taxonomies();
     if (empty($taxonomies)) {
         $output = __('Any', 'wpcf');
     } else {
         $taxonomy_labels = array();
         foreach ($taxonomies as $taxonomy_slug) {
             $taxonomy_labels[] = Types_Utils::taxonomy_slug_to_label($taxonomy_slug);
         }
         $output = implode(', ', $taxonomy_labels);
     }
     return $output;
 }
 /**
  * Update the "form" data for the filter dialog.
  *
  * @param string $filter Filter name. Only 'taxonomies-for-meta' is supported here.
  * @param array $form Form data that will be modified.
  */
 protected function form_add_filter_dialog($filter, &$form)
 {
     switch ($filter) {
         case 'taxonomies-for-termmeta':
             include_once WPCF_INC_ABSPATH . '/fields.php';
             // Oh dear god, why?
             $taxonomy_slugs = $this->get_relevant_taxonomy_slugs();
             ksort($taxonomy_slugs);
             $field_group = $this->get_field_group();
             // Can be null when creating new field group
             $currently_supported_taxonomy_slugs = null == $field_group ? array() : $field_group->get_associated_taxonomies();
             // Setup the form
             $form += $this->add_description(__('Select ' . 'specific Taxonomies that you want to use with this Field Group:', 'wpcf'));
             $form['ul-begin'] = array('#type' => 'markup', '#markup' => '<ul>');
             // Add a checkbox for each taxonomy
             foreach ($taxonomy_slugs as $taxonomy_slug) {
                 $label = Types_Utils::taxonomy_slug_to_label($taxonomy_slug);
                 $form[$taxonomy_slug] = array('#name' => esc_attr($taxonomy_slug), '#type' => 'checkbox', '#value' => 1, '#default_value' => $this->ajax_filter_default_value($taxonomy_slug, $currently_supported_taxonomy_slugs, 'taxonomies-for-termmeta'), '#inline' => true, '#before' => '<li>', '#after' => '</li>', '#title' => $label, '#attributes' => array('data-wpcf-value' => esc_attr($taxonomy_slug), 'data-wpcf-name' => $label, 'data-wpcf-prefix' => 'taxonomy-'));
             }
             $form['ul-end'] = array('#type' => 'markup', '#markup' => '</ul><br class="clear" />');
             break;
     }
 }
예제 #6
0
/**
 * Make sure in built taxonomies are stored.
 *
 * This is an upgrade routine for Types older than 1.9. The code will run only once.
 *
 * @since 1.9
 */
function wpcf_upgrade_stored_taxonomies_with_builtin()
{
    $stored_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
    if (empty($stored_taxonomies) || !isset($stored_taxonomies['category']) || !isset($stored_taxonomies['post_tag'])) {
        $taxonomies = Types_Utils::object_to_array_deep(get_taxonomies(array('public' => true, '_builtin' => true), 'objects'));
        if (isset($taxonomies['post_format'])) {
            unset($taxonomies['post_format']);
        }
        foreach ($taxonomies as $slug => $settings) {
            if (isset($stored_taxonomies[$slug])) {
                continue;
            }
            $taxonomies[$slug]['slug'] = $slug;
            foreach ($settings['object_type'] as $support) {
                $taxonomies[$slug]['supports'][$support] = 1;
            }
            $stored_taxonomies[$slug] = $taxonomies[$slug];
        }
        update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $stored_taxonomies);
    }
}