function am2_tv_show_usermeta_fields($user) { ?> <h3>Promotor information</h3> <table class="form-table"> <tr> <th><label for="am2_promotor_type">Type</label></th> <td> <?php $selected_option = get_the_author_meta( 'am2_promotor_type', $user->ID ); ?> <select name="am2_promotor_type" id="am2_promotor_type"> <option selected value="">Please select something...</option> <option value="basic" <?php if($selected_option == 'basic'){ echo 'selected'; } ?> >Basic</option> <option value="featured" <?php if($selected_option == 'featured'){ echo 'selected'; } ?> >Featured</option> <option value="premium" <?php if($selected_option == 'premium'){ echo 'selected'; } ?> >Premium</option> </select> <span class="description">Please select promotor type.</span> </td> </tr> </table> <?php } function am2_tv_update_usermeta_fields( $user_id ) { if ( !current_user_can( 'administrator', $user_id ) ){ return false; } update_usermeta( $user_id, 'am2_promotor_type', $_POST['am2_promotor_type'] ); } add_action( 'show_user_profile', 'am2_tv_show_usermeta_fields', 10, 2 ); add_action( 'personal_options_update', 'am2_tv_update_usermeta_fields', 10, 2 ); add_action( 'edit_user_profile_update', 'am2_tv_update_usermeta_fields', 10, 2 ); add_action( 'edit_user_profile', 'am2_tv_show_usermeta_fields', 10, 2 );
Monthly Archives: July 2014
See all SQL queries
$customPosts = new WP_Query($yourArgs); echo "Last SQL-Query: {$customPosts->request}";
OR
First, put this in wp-config.php:
define( 'SAVEQUERIES', true );
Then in the footer of your theme put this:
<?php if ( current_user_can( 'administrator' ) ) { global $wpdb; echo "<pre>"; print_r( $wpdb->queries ); echo "</pre>"; } ?>
Add new fields to custom taxonomies
function am2_cities_tax_create() { // this will add the custom meta field to the add new term page ?> <div class="form-field"> <label for="term_meta[time_zone]">Time Zone</label> <input type="text" name="term_meta[time_zone]" id="term_meta[time_zone]" value=""> <p class="description">If unusure, please check <a href="http://www.timeanddate.com/worldclock/">here.</a></p> </div> <?php } add_action( 'cities_add_form_fields', 'am2_cities_tax_create', 10, 2 ); function am2_cities_tax_update($term) { // this will add the custom meta field to the update term page // put the term ID into a variable $t_id = $term->term_id; // retrieve the existing value(s) for this meta field. This returns an array $term_meta = get_option( "taxonomy_$t_id" ); ?> <tr class="form-field"> <th scope="row" valign="top"><label for="term_meta[time_zone]">Time Zone</label></th> <td> <input type="text" name="term_meta[time_zone]" id="term_meta[time_zone]" value="<?php echo esc_attr( $term_meta['time_zone'] ) ? esc_attr( $term_meta['time_zone'] ) : ''; ?>"> <p class="description">If unusure, please check <a href="http://www.timeanddate.com/worldclock/">here.</a></p> </td> </tr> <?php } add_action( 'cities_edit_form_fields', 'am2_cities_tax_update', 10, 2 ); function am2_cities_tax_custom_meta_save( $term_id ) { if ( isset( $_POST['term_meta'] ) ) { $t_id = $term_id; $term_meta = get_option( "taxonomy_$t_id" ); $cat_keys = array_keys( $_POST['term_meta'] ); foreach ( $cat_keys as $key ) { if ( isset ( $_POST['term_meta'][$key] ) ) { $term_meta[$key] = $_POST['term_meta'][$key]; } } // Save the option array. update_option( "taxonomy_$t_id", $term_meta ); } } add_action( 'edited_cities', 'am2_cities_tax_custom_meta_save', 10, 2 ); add_action( 'create_cities', 'am2_cities_tax_custom_meta_save', 10, 2 );
Disable revisions
Treba korigirati wp-config.php
define('WP_POST_REVISIONS', false ); // disable post revisions define('WP_POST_REVISIONS', 3); // alter number of post revisions kept.
Javascript, check type
function is(type, obj) { var clas = Object.prototype.toString.call(obj).slice(8, -1); return obj !== undefined && obj !== null && clas === type; }
is('String', 'test'); // true is('String', new String('test')); // true is('Date', new Date()); // true
WordPress, send mail
$from_email = 'mailer@server.com'; $to_email = $seller->user_email; $headers = "From: FROM NAME <$from_email>" . "\r\n"; $msg = "Ovo je poruka sa WP servera"; $subject = "WP mail subject"; $attachments = 'neki_file'; wp_mail($to_email, $subject, $msg, $headers, $attachments);
Intercept FORM submit
Nakaci se na ‘submit’ event, napravi nesto sa vrijednostima i dodaj novi input koji ce se submitati
$(document).on('submit', 'form', function (e) { e.preventDefault(); var form = $(this), elements_to_submit = $('[name]', this), signed_values = nv.crypto.sign({ exclude_elements: ['__RequestVerificationToken'], hash_fn: nv.crypto.hash.simpleHash, elements_to_sign: elements_to_submit }); form.append('<input type="hidden" name="signedValues" value="' + signed_values + '">'); this.submit(); });
is value in array, javascript
PHP run process in background
This launches the command $cmd, redirects the command output to $outputfile, and writes the process id to $pidfile.
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
This lets you easily monitor what the process is doing and if it’s still running.
function isRunning($pid){ try{ $result = shell_exec(sprintf("ps %d", $pid)); if( count(preg_split("/\n/", $result)) > 2){ return true; } }catch(Exception $e){} return false; }
Manual:
wordpress set user_id
$user_id = (is_user_logged_in() && !empty($current_user)) ? $current_user->ID : ''; if(empty($user_id)){ $current_user = wp_get_current_user(); if($current_user instanceof WP_User){ $user_id = $current_user->ID; } }