Using and saving custom dropdown boxes on user profiles

You are storing the data in the $selected value, while using $topselected in the conditionals to check which value is selected. Either change your value like this: $topselected= get_the_author_meta( ‘user_top’, $user->ID ); OR change your inline conditionals to this: <option value=”MPF Pune West:” <?php echo ($selected== “MPF Pune West:”)? ‘selected=”selected”‘ : ” ?>>MPF Pune West:</option> … Read more

How to make container class in PHP

You can do this using below code. if ($slide_title) { $strret .= ‘<div class=”container”>’; $strret .= ‘<a class=”‘.$slide_linkurl.'”><h2>’.$slide_title.'</h2></a>’; $strret .= ‘<p>’.$str.'</p>’; $strret .= ‘<a href=”‘.$slide_linkurl.'” class=”da-link”>’.$slide_linktext.'</a>’; $strret .= ‘</div>’; }

Blob file download problem

There are some security issues. Please sanitize your input because someone can download from Your database something different than archive, or simply drop Your database. $fid = sanitize_text_field( $_GET[‘fid’] );

add_filter only for front office

Just wrap it all in an ! is_admin() check: add_filter( ‘wp_setup_nav_menu_item’,’decorate_mobile_menu’ ); function decorate_mobile_menu($item) { if ( ! is_admin() ) { if ( strpos($item->title, ‘SHIPPING’) !== false) { $split = explode(” IN “, $item->title); $item->title=”<span class=”shipping-menu-item”>” . $split[0] . ‘ IN </span>’; $item->title .= ‘<br/>’; $item->title .= ‘<span class=”shipping-menu-item”>’ . $split[1] . ‘</span>’; } } … Read more

HTML escaping data with ajax requests

If it is not HTML, it does not need HTML escaping, if it is not JS, it does not need JS escaping. All escaping is context based. In general You should probably just avoid sending “text” in response and focus on sending data which is “converted” into whatever is the relevant DOM structures, either directly … Read more

Can’t save php string to a custom field

For some reason, your $subject variable is empty when you call get_the_content($post_id). When using save_post hook, you can pass additional arguments like $post and $update to your callback. For your case, you could use the second argument $post to grab the post contents. Code: function save_url_link( $post_id, $post ){ $pattern = “/(http|https):\/\/.*\/(.*)\.(mp3|m4a|ogg|wav|wma)/”; $subject = $post->post_content; … Read more

How to check if a PHP string is different than meta field?

I suppose it deleted the value when you had no URL in the content, so $audio_raw was empty. if ($audio_raw && get_post_meta( $post_id, ‘audio_url’, true ) != $audio_raw) { // update the meta field update_post_meta( $post_id, ‘audio_url’, $audio_raw ); } checks that $audio_raw isn’t false/null/empty and that $audio_raw isn’t the same as the string currently … Read more

Display an image if odd number of posts in grid

The common mistake people make in this situation is they start to introduce bunch of custom counters to keep track of state. Really WP_Query just has those already. In your case that would be global $wp_query and $wp_query->post_count and $wp_query->current_post. That should be quite enough to figure out even/odd overall and current iteration in the … Read more