[http://codex.wordpress.org/Function_Reference/wp_localize_script] [http://stackoverflow.com/questions/6808221/php-within-js-file-wordpress]
<?php wp_localize_script( $handle, $name, $data ); ?> | <?php | |
| add_filter( 'woocommerce_checkout_fields' , 'virtual_products_less_fields' ); | |
| /** | |
| * WooCommerce Remove Address Fields from checkout based on presence of virtual products in cart | |
| * @link https://www.skyverge.com/blog/checking-woocommerce-cart-contains-product-category/ | |
| * @link https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ | |
| * @link https://businessbloomer.com/woocommerce-hide-checkout-billing-fields-if-virtual-product-cart/ | |
| */ | |
| function wpr_snap($atts, $content = null) { | |
| extract(shortcode_atts(array( | |
| "snap" => 'http://s.wordpress.com/mshots/v1/', | |
| "url" => 'http://www.sagive.co.il', | |
| "alt" => 'My image', | |
| "w" => '400', // width | |
| "h" => '300' // height | |
| ), $atts)); | |
| $img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>'; |
| <?php | |
| /* | |
| * Plugin Name: CMB2 Custom Field Type - Address | |
| * Description: Makes available an 'address' CMB2 Custom Field Type. Based on https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types#example-4-multiple-inputs-one-field-lets-create-an-address-field | |
| * Author: jtsternberg | |
| * Author URI: http://dsgnwrks.pro | |
| * Version: 0.1.0 | |
| */ | |
| /** |
| <?php | |
| add_filter( 'user_contactmethods', 'add_new_user_fields' ); | |
| function add_new_user_fields( $user_contact ) { | |
| $user_contact[ 'billing_cel_phone' ] = 'Celular'; | |
| return $user_contact; | |
| } |
| <?php | |
| // Based on <https://github.com/mecha-cms/x.minify> | |
| namespace x\minify\_ { // start namespace | |
| $n = __NAMESPACE__; | |
| \define($n . "\\token_boolean", '\b(?:true|false)\b'); | |
| \define($n . "\\token_number", '-?(?:(?:\d+)?\.)?\d+'); |
[http://codex.wordpress.org/Function_Reference/wp_localize_script] [http://stackoverflow.com/questions/6808221/php-within-js-file-wordpress]
<?php wp_localize_script( $handle, $name, $data ); ?> | <?php | |
| /** | |
| * Insert an attachment from a URL address. | |
| * | |
| * @param string $url The URL address. | |
| * @param int|null $parent_post_id The parent post ID (Optional). | |
| * @return int|false The attachment ID on success. False on failure. | |
| */ | |
| function wp_insert_attachment_from_url( $url, $parent_post_id = null ) { |
Imagine we have .myinput input field, that we should process its value after
text pasted into it. We can't access value in paste directly, so we should
wait some time. For that purpose one can use setTimeout function.
Here is example how to correctly handle paste event.
jQuery(document).ready(function($){| <?php | |
| /** | |
| * WooCommerce Ajax Handlers | |
| * | |
| * Handles AJAX requests via wp_ajax hook (both admin and front-end events) | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | |
| /** Frontend AJAX events **************************************************/ |
| <?php | |
| global $wpdb; | |
| $first_char = esc_attr($_GET[$search_key]); | |
| $postids = $wpdb->get_col($wpdb->prepare(" | |
| SELECT ID | |
| FROM $wpdb->posts | |
| WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s | |
| AND $wpdb->posts.post_type = 'product' |