vendredi 19 février 2016

Getting Multiple Select Box Options to Stay Selected Using Chosen Select

I'm trying to get the selected options to stay selected in the following select box. (The select box resides in the Menus page in WordPress admin). I've verified the data is being saved to the database, but I'm having difficulty figuring out to get the data back from the database to mark the options selected for a given select box. There are multiple select boxes on the page.

The select box makes use of the Chosen Select jQuery plugin. Here's a question and answer providing some guidance on marking the options selected with JS: Chosen select an option by default with jQuery. I couldn't get it to work having multiple select boxes on the page.

<script type="text/javascript">
    jQuery(document).ready(function($){ 
        $(".chzn-select").chosen();
    });
</script>

<select name="locations[<?php echo $item_id; ?>]" id="edit-menu-item-visibility-<?php echo $item_id; ?>" class="chzn-select" multiple="true">
    <option value="DZ">Algeria</option>
    <option value="AS">American Samoa</option>
    <option value="AD">Andorra</option>
    ...

This is how the data gets to the database:

function update_option_text( $menu_id, $menu_item_db_id, $args ) {
    $meta_value = get_post_meta( $menu_item_db_id, 'locations', true );
    $new_meta_value = stripcslashes( $_POST['locations'][$menu_item_db_id] );
    if( '' == $new_meta_value ) {
        delete_post_meta( $menu_item_db_id, 'locations', $meta_value );
    }
    elseif( $meta_value !== $new_meta_value ) {
        update_post_meta( $menu_item_db_id, 'locations', $new_meta_value );
    }
}

Below is my non-working attempt. If I understand correctly, the values can be set to selected with JS. But I couldn't get that to work either. Any assistance is greatly appreciated.

<option value="AF" <?php $val = implode(",",get_post_meta( $menu_item_db_id, 'locations', true )); if(in_array("AF", $val)){echo "selected='selected'";}else{echo "";} ?> >Afghanistan</option>

Here is how the original text input worked:

<input
    type="text" 
    class="widefat code" 
    id="edit-menu-item-visibility-<?php echo $item_id; ?>" 
    name="locations[<?php echo $item_id; ?>]" 
    value="<?php echo esc_html( get_post_meta( $item_id, 'locations', true ) ); ?>" />
    <?php echo 'Enter 2-digit country codes separated by commas, e.g. US,CA,SG' ?></br>

The entire file can be found here.



via Chebli Mohamed

making a multi-steps form in wordpress

I am looking for build a form similar like http://ift.tt/1Q5HtNH in this page, mainly there is two issue I am facing problem, to setup the select field with radio buttons field (there is different value for each selection) and a multi-steps for the next form, it will be best if there is any plugin providing such kind of functions, anyone please help me to find out the solution. Thanks in advance.



via Chebli Mohamed

ACF Google Font Select plugin error

I am receiving an array_merge() error. I have just migrate the site to the new server after that its showing me an error.

Could anyone help me out please

Thanks in advance



via Chebli Mohamed

Wordpress get user meta function

I'm using a couple of plugins to integrate with our LDAP/AD server - that plugin adds a bit of user meta when it successfully auths/creates a wp user. I'm also using the Ultimate Members plugin to control roles etc.

What I need to do is ensure anyone that signs in with their ldap creds gets assigned the ldap UM role. So here's the PHP I got thus far.

global $ultimatemember;
global $user_ID;
$key = 'ad_integration_account_suffix';
$single = true;
$ldap_user=get_user_meta( $user_ID, $key, $single ); // core WP coe to get a users meta info - we are assigning it a variable
echo '<p>The '. $key . ' value for user id ' . $user_ID . ' is: ' . $ldap_user . '</p>'; // some debug stuff - take this out
um_fetch_user( $user_ID ); // set UM user id to retrieve
   if($ldap_user !== '')  { // if the ldap user key is not null then its populated and thus this user is a member of AD
 $ultimatemember->user->set_role('ldap_user'); // so set the UM user to be a member of the ldap_user role/group.
    } 

Now, I think there's some issues with the above ie I assume that it also needs to be wrapped in a function? Where do I stick this php snippet so its called upon sign-in? I also probably should first check to see if the user is already in the ldap_user group and if so we don't need to continue with the rest of the checks/set's etc.



via Chebli Mohamed

how wordpress plugin check for new version and updates

i am newbie in wordpress plugin development. just i want to know how i can make my plugin to check for new version or update. so that once i installed if i build a new version. wordpress will automatically findout that an update for this plugin is available. i experience this on almost every plugin will detect new version automatically.

There is a new version of `plugin name` available. View version 1.4.6 details or update now.

what i can do in my plugin so that it will check updates automatically.



via Chebli Mohamed

How to get Advanced Custom Field choice value from another Advance Custom Field?

I have created two custom fields using Advanced Custom Field plugin. I want it to behave like when I insert value in one text field, it should be filled in the another field which is a choice field.

Custom Field 1

This image is an example where I am inserting Name value and slug value. I want it to return this.

enter image description here



via Chebli Mohamed

wordpress custom permissions checking

I want to implement ACL for my wordpress sites based on role. I have a custom post type which contains a custom field. The custom field contains value of wordpress users. Now, The custom post type should be accessible to only those users with value in custom field.



via Chebli Mohamed