Skip to content

Instantly share code, notes, and snippets.

@smartdeal
smartdeal / Wordpress - add data from Contact form 7 to post with attachments (ACF).php
Last active March 29, 2021 02:00
add data from Contact form 7 to post with attachments (ACF) #Wordpress #WP_CF7 #WP_ACF
add_action('wpcf7_before_send_mail', 'send_mail');
function send_mail($form){
global $wpdb;
$submission = WPCF7_Submission::get_instance();
if ( $submission && 138 == $form->id() ) {
$form->skip_mail = true;
$submited = array();
$submited['title'] = $form->title();
$submited['posted_data'] = $submission->get_posted_data();
$uploadedFiles = $submission->uploaded_files();
@smartdeal
smartdeal / wp_clean.php
Last active June 19, 2020 08:05
Очистить шаблон wordpress #Wordpress
remove_action('wp_head', 'wp_generator'); // Убирает вывод используемого движка и его версии
remove_action('wp_head', 'rel_canonical'); // Убирает канонические линки
remove_action('wp_head', 'wp_shortlink_wp_head'); // Убирает короткую ссылку к текущей странице
remove_action('wp_head', 'wlwmanifest_link'); // Используется блог-клиентами, а вернее лишь одним из них - Windows Live Writer. Не используете WLW - удаляйте.
remove_action('wp_head', 'rsd_link'); // Используется различными блог-клиентами или веб-сервисами для публикации/изменения записей в блоге.
remove_action('wp_head', 'pagenavi_css'); // Убирает вывод лишнего css изи плагина WP-PageNavi
remove_action('wp_head', 'index_rel_link'); // Убирает ссылку на главную страницу
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Убирает ссылку на предыдущую запись
remove_action('wp_head', 'start_post_rel_link', 10, 0); // Убирает ссылку на первую запись
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); // Убирает связь с р
@smartdeal
smartdeal / async-load-js-css.js
Last active February 1, 2018 10:45
[Загрузка скриптов и стилей потом] #Javascript
$(document).ready(function(){
jQuery.loadScript = function (url, callback) {jQuery.ajax({url: url, dataType: 'script', success: callback, async: true }); }
// Usage
// if (typeof someObject == 'undefined') $.loadScript('url_to_someScript.js', function(){
// Stuff to do after someScript has loaded
// });
function loadCSS(url) {$("<link/>", {rel: "stylesheet",type: "text/css",href: url}).appendTo("head");}
// Usage
@smartdeal
smartdeal / woocommerce send custom email.php
Last active February 2, 2018 11:41
[WooCommerce - send custom email on custom order status change] #WooCommerce #Wordpress
<?php
// WooCommerce - send custom email on custom order status change
In WC 2.2+ I believe you can do this via the following:
add_action( 'woocommerce_order_status_wc-order-confirmed', array( WC(), 'send_transactional_email' ), 10, 10 );
// As of WooCommerce 2.3
function so_27112461_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_wc-order-confirmed';
return $actions;
@smartdeal
smartdeal / 'woocommerce_terms_page_id.php
Created February 2, 2018 11:41
[WooCommerce: How To Get WooCommerce Page IDs] #WooCommerce
<?php
// Get The Page ID You Need
get_option( 'woocommerce_shop_page_id' );
get_option( 'woocommerce_cart_page_id' );
get_option( 'woocommerce_checkout_page_id' );
get_option( 'woocommerce_pay_page_id' );
get_option( 'woocommerce_thanks_page_id' );
get_option( 'woocommerce_myaccount_page_id' );
get_option( 'woocommerce_edit_address_page_id' );
@smartdeal
smartdeal / breadcrumb.php
Created February 2, 2018 11:57
[WooCommerce breadcrumb add shop link] #WooCommerce
<?php
/**
* Shop breadcrumb
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.3.0
* @see woocommerce_breadcrumb()
*/
@smartdeal
smartdeal / errors_to_file.php
Last active May 8, 2018 15:00
[PHP errors to file] #PHP-hack
<?php
set_error_handler('err_handler');
function err_handler($errno, $errmsg, $filename, $linenum) {
$date = date('Y-m-d H:i:s (T)');
$f = fopen('errors.log', 'a');
if (!empty($f)) {
$filename =str_replace($_SERVER['DOCUMENT_ROOT'],'',$filename);
$err = "$errmsg = $filename = $linenum\r\n";
fwrite($f, $err);
@smartdeal
smartdeal / cf7.js
Last active May 8, 2018 15:54
[Manually submitting contact form 7 (ajax) and adding extra fields] #WP_CF7 #Wordpress
$(function() {
//get form
var $form = $("#mcp7form");
var id = $form.find('input[name="_wpcf7"]').val();
var unitTag = $form.find('input[name="_wpcf7_unit_tag"]').val();
var url = '#/wpcf7-<?php echo $formId?>-o2';
@smartdeal
smartdeal / debug2.php
Last active May 8, 2018 15:53
[Wordpress debug function] #Wordpress #WP_Debug
function (f_debug) {
if (is_admin()) {
define('WP_DEBUG', true )
} else {
define('WP_DEBUG', false )
}
}
add_action(init,f_debug);
@smartdeal
smartdeal / wp_nav_menu_remove_current_link.php
Created February 17, 2018 12:49
[Remove currenk link from menu] #Wordpress