php if username is role

Chris Haugen, You need to check user role who have ‘artist’ role and then you need to act on some video loop stuff. Here’s the solution: $user = get_user_by(‘login’, $username ); if ( !empty( $user->roles ) && is_array( $user->roles ) ) { foreach ( $user->roles as $role ){ if($role == ‘artist’) media files loop } … Read more

zip unzip attachments in wordpress

WordPress provides a function called unzip_file()— easily found by typing “wordpress unzip” into Google. There is sample code in the Codex: WP_Filesystem(); $destination = wp_upload_dir(); $destination_path = $destination[‘path’]; $unzipfile = unzip_file( $destination_path.’/filename.zip’, $destination_path); if ( $unzipfile ) { echo ‘Successfully unzipped the file!’; } else { echo ‘There was an error unzipping the file.’; } … Read more

Get all categories post is not in

Ok. So, the first bit of code is more correct but it has issues nonetheless. Piece by piece… $categories = get_the_category( $post_id ); $post_id is not set in the code you posted. I assume that value is set earlier in the page somewhere, else that is your first problem. $nocats = get_terms(‘category’, array(‘exclude’ => $categories) … Read more

esc_url( ) won’t use https

esc_url never force the URL to protocol it’s only checking and escaping the passed URL from invalid characters, the $protocols variable is an array of acceptable (white list) protocols not for forcing destination URL. // Forcing URL to https instead of http $YOUR_URL = esc_url($YOUR_URL); if( ‘http’ == parse_url($YOUR_URL, PHP_URL_SCHEME) ){ $NEW_URL = str_replace(‘http://’, ‘https://’, … Read more

$wpdb returns duplicate posts

Nevermind, I solved it on my own. While reading on the WordPress Codex for $wpdb, I saw that if I use OBJECT_K it will remove the duplicates and that solved my problem. If it helps anyone, here is my working code: function latest_posts_after_last_login( $atts ) { global $wpdb, $current_user; $atts = shortcode_atts( array( ‘post_type’ => … Read more

Post images are not displayed on the front page

Something that generates the image links is broken. You are not getting a valid src attribute in the title tag. The result is: <p class=”thumb”> <a href=”http://paper-backgrounds.com/red-grunge-concrete-texture-3/” title=”Red Grunge Concrete Texture”> <img src=”undefined” alt=”Red Grunge Concrete Texture” height=”132″ width=”236″> </a> </p> Without that src attribute the image can’t load. As you don’t post the code … Read more

Preg_Match(): compilation failed unknown property name

Xan is a georgian letter as I can find in Google, but it’s not a valid Unicode Script for RegEx, you can find a list of the Unicode Scripts here: http://www.regular-expressions.info/unicode.html Maybe try using another one than Xan, maybe Georgian: preg_match( ‘/[\p{Georgian}]/u’, $content, $results ); Let me know how that goes.