Results 1 to 2 of 2

Thread: Mod to Rename Custom Fields Editor for Fun and Frolic

  1. #1
    Thread Starter
    Veteran vienna's Avatar
    Join Date
    May 2010
    Location
    Vienna, Austria
    Posts
    718
    Thanks
    19
    Thanked 177 Times in 118 Posts

    Lightbulb Mod to Rename Custom Fields Editor for Fun and Frolic

    I have not been in the forum for a few months while working on another project.
    And now that I have stirred things up nicely in Egypt, Tunisia, Libya, Iran, and Topeka, Kansas I am back to take a look at where ClassiPress and me left off.


    So, since 3.1 is not out yet I will raise further mischief again by re-iterating that I think the Custom Field naming strategy needs refinement.

    And here is that refinement:

    At present in ClassiPress 3.0.5.3.91.67980 when you Add a New custom field you might start off with what is called the field name -- you type in "valuable features".

    And no matter if you select for this to be a Text, Text area, Dropdown, Radio button, or Checkbox the actual field name becomes "cp_valuable_features".

    But, here you have the actual field type available while creating the new Custom field--you choose to make this a "checkbox" and dutifully fill in your comma separated options and save and you get back "cp_valuable_features"....no matter what field TYPE you specify.

    But--- if this same procedure returned "cp_checkbox_valuable_features" or "cp_radio_valuable_features" so that the actual field meta names were prefixed with the FIELD TYPE then you could do some more creative things.
    You could create an alternative query that looked for the standard post goodies out of one ad to display in the ad BUT in one case EXCLUDED all the arrays which began metakey "cp_checkbox".
    So that the upper right-hand list of Ad text displaying the usual jazz in comma-separated lists had everything BUT the checkbox arrays.

    Then you have a secondary query that JUST selects the array of values whose metakey begins with "cp_checkbox". Give this string of arrays another name and use that value in your page template to put the Ad information contained in Checkboxes into another area of your ad--even splitting off the checkbox information into your Sidebar!

    And, you could specify throughout your site with a little more coding that all "cp_checkbox_" arrays are put into their own UL-LI lists instead of boring rows of words with commas.

    And, because the html returns like this--
    name="cp_radio_cool_stuff" id="cp_radio_cool_stuff"

    You can use extra CSS rules to further style and postion one FIELD TYPE -- "cp_radio" or "cp_text" or "cp_checkbox" or "cp_textarea" or "cp_dropdown".

    You can make one query that while looking up all the metakeys for an ad splits out each array whose meta_key begins "cp_radio, cp_checkbox" and takes each option and always puts it into an ordered list, for example:

    User selected checkbox options in a list
    <ul>
    <li>the first option from a checkbox array/li>
    <li>the second option from a checkbox array/li>
    <li>the third option from a checkbox array/li>
    </ul>

    User selected Radio button value
    <ul>
    <li>the selected option from a Radio array/li>
    </ul>

    This may sound much ado about nothing but when put into effect it enables some very nice customizations to how ClassiPress displays the information it has according to the ways that you collected that information in the original form.

    If you used some radio checkboxes to collect information now you can separate those values on-the-fly because the checkboy arrays always are stored with a meta key whose name starts with "cp_checkbox"

    Go change this one file and you have made the first step toward new capabilities for Classipress.

    includes/admin/admin-options.php

    go to line 135 in Classipress 3.0.5.3 admin-options.php

    you will see


    /**
    * Take field input label value and make custom name
    * Strip out everything excepts chars & numbers
    * Used for WP custom field name i.e. Middle Name = cp_middle_name
    */
    function cp_make_custom_name($cname) {

    $cname = preg_replace('/[^a-zA-Z0-9\s]/', '', $cname);
    $cname = 'cp_' . str_replace(' ', '_', strtolower(substr(appthemes_clean($cname), 0, 30)));

    return $cname;
    }

    that RED line and just that line is to be replaced with this slight variation--

    PHP Code:
    $cname 'cp_' .$fieldtype.'-' str_replace(' ''_'strtolower(substr(appthemes_clean($cname), 030))); 
    // this now slides in the actual field type name such as "checkbox" when you Add a new Custom field and select the field type.


    now run down to line 1978 in the same file-- do a search for : case 'addfield':

    keep moving down a few lines until you see:

    $insert = "INSERT INTO " . $wpdb->prefix . "cp_ad_fields" .
    " (field_name, field_label, field_desc, field_tooltip, field_type, field_values, field_search, field_owner, field_created) " .
    "VALUES ('" .

    $wpdb->escape(appthemes_clean(cp_make_custom_name($_PO ST['field_label']))) . "','" .

    Yep, right there...just that one red line

    you will replace just that line with this:

    PHP Code:
    $wpdb->escape(appthemes_clean(cp_make_custom_name($_POST['field_label'],$_POST['field_type']))) . "','" 
    make sure it was just that line and that you have that last period...see it? Do NOT miss that PERIOD when you replace with a paste -- that little guy>>> .

    Save the file and upload it back to-- includes/admin/

    This will also work in 3.0.5.2.

    The next time you go into Admin and select Custom Fields and then ADD NEW to create a new custom field you will have a new way of creating Custom fields that now prefixes custom fields with the TYPE .

    It will not hurt any previous custom fields and will play nice.

    Maybe one of you WP geniuses will post some custom queries that can be devised with this new meta key naming for custom fields.

  2. #2
    jomarkosabel's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    40,978
    Thanks
    170
    Thanked 3,407 Times in 3,278 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!
    Please help our moderating team work more efficiently by not sending us support questions via PM. You can read more about how AppThemes support works here. However, you can send a PM to follow up and remind me if I missed your support request/thread.

    Thank you and have a nice day.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Custom Fields in Custom Forms are not working...
    By alexuz0751 in forum Report ClassiPress Bugs
    Replies: 4
    Last Post: December 31st, 2010, 05:15 PM
  2. MODDED for "Custom" Custom Fields output
    By vienna in forum ClassiPress General Discussion
    Replies: 5
    Last Post: November 8th, 2010, 02:08 PM
  3. Custom Fields
    By Skelbimai in forum Help Using ClassiPress
    Replies: 2
    Last Post: April 3rd, 2010, 12:16 PM