jquery & ajax getting data to php in wordpress

Assuming that your script localization and other stuff are set up properly, there is an issue in your back-end script. Your data is in the following format: data : { action : ‘renove_vocabulary’, id_vocabulary : vocabulary, id_user : user } But you are trying to get the data as follows: $id_user = $_POST[‘user_id’]; $id_vacabulary = … Read more

Loading jQuery With Two Fallbacks

I use a similar pattern to enqueue jQuery from the Google CDN (as the CSS Tricks example). However in my footer (typically footer.php) I’ll usually hard code the following fallback. <script type=”text/javascript”> if (typeof jQuery === ‘undefined’) { document.write(‘<script src=”https://wordpress.stackexchange.com/questions/78740/<?php echo get_stylesheet_directory_uri(); ?>/js/jquery.min.js” type=”text/javascript”><\/script>’); } </script> Let me explain what this does and why I … Read more

Extend 3.5 media uploader plugin to change button name

Figured it out using a different method. Help from here. $.fn.oeUpload = function(options) { // Set default options var defaults = { ‘preview’ : ‘.preview-upload’, ‘text’ : ‘.text-upload’, ‘button’ : ‘.button-upload’, ‘name’ : ‘Choose Image’ }; var options = $.extend(defaults, options); var uploader; $(options.button).click(function(e) { e.preventDefault(); //If the uploader object has already been created, reopen … Read more

Modify Custom Field in Media Library using JavaScript

One way to do it (which is probably evil) is to select the control by adding a block of javascript using the tr field of $form_fields: function set_image_data( $form_fields, $post ) { $form_fields[‘text_color’] = array( ‘label’ => ‘Text Color’, ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘_text_color’, true ) ); ob_start(); ?> <script type=”text/javascript”> jQuery(‘[name$=”[text_color]”]’).myColorPicker(); … Read more

How to pass both action and formdata in wordpress ajax?

try to add the action in the formdata : var formData=new FormData(document.getElementById(‘landlordregform’)); formData.append(“action”, “custom_landlord_registration_process”); jQuery.ajax({ url: jQuery(“#cusajaxurl”).val(), type: ‘POST’, data: formData, cache: false, processData: false, contentType: false, success: function(data) { console.log(data); } });

Defer Parsing of Scripts

At the first glance, you sure have a lot of Javascript included in your Website. You can take a few steps towards reducing/speeding up this section. Before I start, please let me remind you that the PageSpeed by Google is not an actual tool to keasure how fast a website loads, it is more a … Read more

Force wp_enqueue_scripts to the HEADER?

The normal behavior of wp_enqueue_script is to put the script output into the head section, the parameter $in_footer is optional and defaults to false. So, you can load jQuery with your plugin into the head and, assumed your dealing with well programmed themes/plugins, it won’t load again, because wp_enqueue_script prevents this by default – additional … Read more

Access Customizer’s DOM – jQuery

The customizer preview is in a different window than the window that contains the customizer controls. Specifically, the customizer preview is contained inside of an iframe. So that is why you cannot directly use jQuery to select elements. One way to work around this is to use parent.jQuery from the preview, but this is not … Read more