wordpress add_action() issue in ajax call

You’re sending your AJAX request to the wrong place. Of course calling functions.php directly will get you undefined function errors, because the WordPress API isn’t loaded by functions.php ( it’s the other way round ). A car doesn’t make fuel go forward, fuel makes a car go forward, simply getting in the car won’t make … Read more

Ajax button not working

As for your PHP not being executed – the action parameter in your JavaScript AJAX call needs to match the hook name in your add_action call. Take a look at the example below. I haven’t tested it but it should work. I have simplifed the AJAX call, feel free to modify it to suit your … Read more

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