Ejemplo n.º 1
0
 function test_insert_at_position()
 {
     $test_source = array();
     for ($i = 0; $i < 100; ++$i) {
         $test_source["item_{$i}"] = $i;
     }
     $test_to_insert = array('insert_first' => 1042, 'insert_last' => 1043);
     // Inserting at specified index
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, 0);
     $this->insert_at_position_check($result, 0, 1, array('item_0' => 2, 'item_99' => 101));
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, 5);
     $this->insert_at_position_check($result, 5, 6, array('item_0' => 0, 'item_4' => 4, 'item_5' => 7, 'item_99' => 101));
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, count($test_source));
     $this->insert_at_position_check($result, 100, 101, array('item_0' => 0, 'item_99' => 99));
     // Negative numeric index
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, -1);
     $this->insert_at_position_check($result, 100, 101, array('item_0' => 0, 'item_99' => 99));
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, -1000);
     $this->insert_at_position_check($result, 0, 1, array('item_0' => 2, 'item_99' => 101));
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, -3);
     $this->insert_at_position_check($result, 98, 99, array('item_0' => 0, 'item_97' => 97, 'item_98' => 100, 'item_99' => 101));
     // Inserting by element key
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, array('key' => 'item_4', 'where' => 'after'));
     $this->insert_at_position_check($result, 5, 6, array('item_0' => 0, 'item_4' => 4, 'item_5' => 7, 'item_99' => 101));
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, array('key' => 'item_5', 'where' => 'before'));
     $this->insert_at_position_check($result, 5, 6, array('item_0' => 0, 'item_4' => 4, 'item_5' => 7, 'item_99' => 101));
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, array('where' => 'before'));
     $this->insert_at_position_check($result, 0, 1, array('item_0' => 2, 'item_99' => 101));
     $result = WPCF_Utils::insert_at_position($test_source, $test_to_insert, array('where' => 'after'));
     $this->insert_at_position_check($result, 100, 101, array('item_0' => 0, 'item_99' => 99));
     $this->expectOutputString('');
 }
Ejemplo n.º 2
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 = WPCF_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;
 }
    function wpcf_clear_option_is_client()
    {
        $option_is_client = get_option('wpcf-is-client');
        if ($option_is_client == 'no') {
            delete_option('wpcf-is-client');
        }
    }
}
add_action('activated_plugin', 'wpcf_clear_option_is_client');
/**
 * Make sure in built taxonomies are stored
 */
$stored_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
if (empty($stored_taxonomies) || !isset($stored_taxonomies['category']) || !isset($stored_taxonomies['post_tag'])) {
    require_once WPCF_ABSPATH . '/embedded/classes/utils.php';
    $taxonomies = WPCF_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);
}
Ejemplo n.º 4
0
 /**
  * @param $item WPCF_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[] = WPCF_Utils::taxonomy_slug_to_label($taxonomy_slug);
         }
         $output = implode(', ', $taxonomy_labels);
     }
     return $output;
 }
Ejemplo n.º 5
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'])) {
        require_once WPCF_ABSPATH . '/embedded/classes/utils.php';
        $taxonomies = WPCF_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);
    }
}
Ejemplo n.º 6
0
 /**
  * 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 = WPCF_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-prefix' => 'taxonomy-'));
             }
             $form['ul-end'] = array('#type' => 'markup', '#markup' => '</ul><br class="clear" />');
             break;
     }
 }
Ejemplo n.º 7
0
 /**
  * Check if a string is contained within the field group definition.
  *
  * Searches in ID, slug, title and description. Case insensitive.
  *
  * @param string $search_string String to look for.
  * @return bool True if found.
  */
 public function is_match($search_string)
 {
     return WPCF_Utils::is_string_match($search_string, $this->get_id()) || WPCF_Utils::is_string_match($search_string, $this->get_slug()) || WPCF_Utils::is_string_match($search_string, $this->get_name()) || WPCF_Utils::is_string_match($search_string, $this->get_display_name()) || WPCF_Utils::is_string_match($search_string, $this->get_description());
 }
Ejemplo n.º 8
0
 /**
  * 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)
 {
     $taxonomy_slug = wpcf_getget('taxonomy');
     $groups = WPCF_Field_Group_Term_Factory::get_instance()->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();
         }
     }
     // 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).
     $columns = WPCF_Utils::insert_at_position($columns, $columns_to_insert, array('key' => 'posts', 'where' => 'before'));
     return $columns;
 }
Ejemplo n.º 9
0
 /**
  * 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 WPCF_Utils::is_string_match($search_string, $this->get_name()) || WPCF_Utils::is_string_match($search_string, $this->get_slug());
 }