Skip to content

Instantly share code, notes, and snippets.

@smartdeal
smartdeal / PHPDebug.php
Created November 14, 2016 13:13
PHP debug to js console
<?php
class PHPDebug {
function __construct() {
if (!defined("LOG")) define("LOG",1);
if (!defined("INFO")) define("INFO",2);
if (!defined("WARN")) define("WARN",3);
if (!defined("ERROR")) define("ERROR",4);
@smartdeal
smartdeal / wp-cpt-template.php
Created November 17, 2016 08:30
wordpress Apply template to custom-post-type
<?php
add_action( 'add_meta_boxes', 'add_custom_page_attributes_meta_box' );
function add_custom_page_attributes_meta_box(){
global $post;
if ( 'page' != $post->post_type && post_type_supports($post->post_type, 'page-attributes') ) {
add_meta_box( 'custompageparentdiv', __('Template'), 'custom_page_attributes_meta_box', NULL, 'side', 'core');
}
}
function custom_page_attributes_meta_box($post) {
<?php
// go to wp-config.ini
define('WP_DEBUG', false);
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
?>
<?php
ob_start();
var_dump($someVar);
$result = ob_get_clean();
file_put_contents('file.txt', $result);
?>
@smartdeal
smartdeal / cf7-get-fields.php
Last active May 8, 2018 15:54
Contact form 7 - get fields in function.php #Wordpress #WP_CF7
<?php
$wpcf7 = WPCF7_ContactForm::get_current();
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
$form_type = $data['form-type'];
?>
@smartdeal
smartdeal / cf7-no-validate.php
Created November 21, 2016 12:43
Disabled validate forms
<?php
add_filter( 'wpcf7_validate_configuration', '__return_false' );
?>
@smartdeal
smartdeal / cf7-sendpulse.php
Last active March 1, 2022 07:11
пример интеграции #Wordpress #Sendpulse #WP_CF7
<?php
function add_email_to_sendpulse($contact_form) {
$wpcf7 = WPCF7_ContactForm::get_current();
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
$cur_email = $data['Email'];
if ($cur_email != '') {
define( 'API_USER_ID', '' );
$.when( runGal() ).done(function() {
$('.fotogal').show();
});
@smartdeal
smartdeal / fancybox-no-scrolling.js
Created December 6, 2016 15:52
Disable scrolling on iphone in fancybox
$('.fancybox').fancybox({
scrolling: 'hidden',
helpers: {
overlay: {
locked: true
}
}
});
@smartdeal
smartdeal / сontact-form-7-validate.php
Created December 22, 2016 14:04
Wordpress contact form 7 validation
/*
Validate fields in Contact Form 7
*/
function cf7_validation( $result, $tag ) {
$tag = new WPCF7_FormTag( $tag );
$name = $tag->name;
if ($name == 'inn') {
if( !preg_match( "/(\d{8,12})/", $_POST[$name] ) or strlen( $_POST[$name] ) > 12 ) {
$result->invalidate( $tag, "Проверьте правильность заполнения поля. ИНН должно содержать не более 12 цифр цифр." );