Remove all nav menu classes ( but keep useful ones… )

You could work with a white-list and replace the regular expression with something more readable: add_filter( ‘nav_menu_css_class’, function( $classes ) { $allowed = [ ‘menu-item-has-children’, ‘current-menu-item’ ]; return array_intersect( $classes, $allowed ); }); That would make it easier to maintain the white-list too.

File upload, uploads only file name

The WordPress codex states that “The file MUST be on the uploads directory”. I’ve added a line to move the uploaded file into the uploads directory and changed the guid path. if( isset( $_POST[‘submit’] ) ) { $filename = $_FILES[‘file’][‘name’]; $wp_filetype = wp_check_filetype( basename($filename), null ); $wp_upload_dir = wp_upload_dir(); // Move the uploaded file into … Read more

there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?

The no no about loading wp-* files directly are reasonable when you are developing a WordPress plugin or theme, but if you are developing an external code that require WP (and that seems your case) than you must require that files, there is no alternatives. Consider that including wp-blog-header.php is needed when you need to … Read more

WordPress Ajax Data problem

$.post(ajaxurl,{ action:’master_ajaxurl’, option: $(this).find(“option:selected”).val(), // use option also here }, function(data){ //adds the echoed response to our container // alert(data); $(“#details”).html(data); } ); Move action and functions into function.php file make some changes as commented add_action(‘wp_ajax_master_ajaxurl’, ‘master_ajaxurl’); add_action(‘wp_ajax_nopriv_master_ajaxurl’, ‘master_ajaxurl’); function master_ajaxurl() { $myOpt = $_POST[‘option’]; // use option instead of data echo bringDetails($myOpt); die(); } … Read more

“Notice: Undefined variable: content” is showing [closed]

Although the actual question is off topic, I would make a few alterations to the code to make it more reliable and a bit faster and less resource intensive: Add $content=””; right at the top of the function, this will take care off the Notice: Undefined variable notice Only get the term id’s from wp_get_post_terms(). … Read more

How to make a variable available for the duration of the page request

A class provides structure, and if it’s what you need to do it then do it. The alternative would be a global variable, which is bad practice and should be avoided ( and makes reliable unit testing near impossible ) However, your entire premise is unnecessary. WordPress already stores the option in its caches, so … Read more

Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB

If you’re releasing this as a plugin, you absolutely must use the AJAX API. It’s super easy: /** * Handle the request and return the result. */ function alumni_process_request() { global $wpdb; // All your processing code from your original question, except for loading WordPress! return $data; } /** * AJAX handler for the “alumni” … Read more