Skip to content

Instantly share code, notes, and snippets.

@eto4detak
eto4detak / JSON.php
Created December 8, 2018 08:38
wp php JSON
<?php
public function __construct()
{
add_action('print_footer_scripts', array($this,'print_script_addsdgsdgsd'), 99);
}
public function print_script_addsdgsdgsd()
{
if( !empty($this->elements)){
@eto4detak
eto4detak / number.php
Last active August 4, 2019 20:18
php number
<?php
$int_value = ctype_digit($value) ? intval($value) : null;
if ($int_value === null)
{
echo 'null';
}else{
echo 'NUMBER';
}
@eto4detak
eto4detak / geo.php
Last active December 16, 2018 16:08
wp php geo
<?php
if(!is_admin()){
add_action('print_footer_scripts', 'print_script_addsdgsdgsd', 99);
}
function print_script_addsdgsdgsd()
{
if( !empty($_COOKIE['geo'])){
@eto4detak
eto4detak / xml.php
Last active December 3, 2018 15:11
php xml
<?php
$movies = new SimpleXMLElement(file_get_contents('http://www.cbr.ru/scripts/XML_daily.asp?date_req=03/12/2018'));
function get_xml_from_url($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
@eto4detak
eto4detak / email.php
Created November 30, 2018 21:49
wp php email
<?php
function sendEmail($fromEmail,$fromEmailName,$toEmail,$toEmailName,$subject,$message,$extra='') {
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'To: '.$toEmailName.' <'.$toEmail.'>' . "\r\n";
$headers .= 'From: '.$fromEmailName.' <'.$fromEmail.'>' . "\r\n";
if(wp_mail($toEmail,$subject,$message,$headers)) {
}else {
@eto4detak
eto4detak / footer-script.php
Last active August 21, 2019 18:07
wp php js footer script
@eto4detak
eto4detak / prepare_attributes.php
Created November 24, 2018 19:36
woo php prepare_attributes
<?php
$data = [
'attribute_names' => ['pa_article','pa_land'],
'attribute_values' => ['279','222'],
'attribute_position' => ['0','0'],
'attribute_visibility' => ['1','1'],
];
$attributes = WC_Meta_Box_Product_Data::prepare_attributes( $data );
@eto4detak
eto4detak / dowload-file.php
Last active August 30, 2019 21:03
wp php dowload file
<?php
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
$file_array = [];
$tmp = download_url($this->infoProduct[0]['image_src'][0]);
preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png)/i', $this->infoProduct[0]['image_src'][0], $matches );
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
@eto4detak
eto4detak / field-general.php
Last active April 8, 2019 13:01
wp php register_setting field-general
<?php
function divie_add_option_field_to_general_admin_page(){
$option_name = 'divie_company_location';
register_setting( 'general', $option_name );
add_settings_field(
'myprefix_setting-id',
'Локация компании',
'divie_setting_callback_location_gen_opt',
'general',
@eto4detak
eto4detak / rating.php
Last active May 26, 2019 12:16
woo php rating
<?php
// show rating plagin
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_custom_action', 15 );
function bbloomer_custom_action() {
if(function_exists('the_ratings')) { the_ratings(); }
}
//
add_action( 'comment_form_logged_in_after', 'extend_comment_custom_fields' );