php upload.php的

upload.php
<?php

    /**
     * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
     * @param \Doctrine\Common\Persistence\ObjectManager $objectManager
     * @param PropertyDocument $propertyDocument
     * @param boolean $persist
     *
     * @return array
     */
    protected function upload(UploadedFile $file, ObjectManager $objectManager, PropertyDocument $propertyDocument, $persist)
    {
        if (null === $file) {
            return;
        }
        $user = $this->getCurrentUser();
        $webPath = $this->uploadFolder.'/property_document/'.$propertyDocument->getProperty()->getId().'/'.$user->getId().'/';
        $dir = $this->uploadRootDir.$webPath;
        $filename = sprintf('property_document_%s', uniqid());
        $filename = $filename.'.'.$file->guessExtension();
        $fs = new Filesystem();
        if (!$fs->exists($dir)) {
            $fs->mkdir($dir);
        }
        $file->move($dir, $filename);
        $file = [
            'name' => $filename,
            'path' => $webPath.$filename,
        ];
        return $file;
    }

php 添加心脏到页脚(用爱做)ioicons

添加心脏到页脚(用爱做)ioicons

madewithlove.php
//* Enqueue Ionicons
add_action( 'wp_enqueue_scripts', 'bg_enqueue_ionicons' );
function bg_enqueue_ionicons() {
	wp_enqueue_style( 'ionicons', '//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css', array(), CHILD_THEME_VERSION );
}

//* Change the footer text
add_filter('genesis_footer_creds_text', 'sp_footer_creds_filter');
function sp_footer_creds_filter( $creds ) {
	$creds = '[footer_copyright] &middot; <p class="love">Made and Customized with <i class="icon ion-heart"></i> by Robert McMillin</p>
';
	return $creds;
}

php 将Genesis中的“找不到帖子”文本更改为自定义文本

将Genesis中的“找不到帖子”文本更改为自定义文本

no-posts-customtext.php
add_filter('genesis_noposts_text', 'sg_noposts_text');
function sg_noposts_text($text)
{
  $text = '<span class="noposts-text">' . __('Ups, didn´t find any posts.', 'sg') . '</span>';

  return $text;
}  

php 重力形成电话检查

重力形成电话检查

gf_phone_check.php
//////////////////////////////////////////////////////////////
///////// GRAVITY FORMS PHONE VALIDATION
//////////////////////////////////////////////////////////////
add_filter( 'gform_field_validation', 'validate_phone', 10, 10 );
function validate_phone( $result, $value, $form, $field ) {
    $pattern = "/^([+]?\d{1,4}[-\s]?|)\d{3}[-\s]?\d{3}[-\s]?\d{4}$/";
    if ( $field->type == 'tel' || $field->type == 'phone' && !preg_match( $pattern, $value ) ) {
        $result['is_valid'] = false;
        $result['message']  = 'Inserire un numero di telefono valido';
    }
    return $result;
}

php 此代码段将排除您在WooCommerce Shop页面上显示的任何类别的所有产品。

此代码段将排除您在WooCommerce Shop页面上显示的任何类别的所有产品。

wc-exclude-product-category-from-shop-page.php
function custom_pre_get_posts_query( $q ) {

    $tax_query = (array) $q->get( 'tax_query' );

    $tax_query[] = array(
           'taxonomy' => 'product_cat',
           'field' => 'slug',
           'terms' => array( 'clothing' ), // Don't display products in the clothing category on the shop page.
           'operator' => 'NOT IN'
    );


    $q->set( 'tax_query', $tax_query );

}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

php 此代码段将排除您在WooCommerce Shop页面上显示的任何类别的所有产品。

此代码段将排除您在WooCommerce Shop页面上显示的任何类别的所有产品。

wc-exclude-product-category-from-shop-page.php
function custom_pre_get_posts_query( $q ) {

    $tax_query = (array) $q->get( 'tax_query' );

    $tax_query[] = array(
           'taxonomy' => 'product_cat',
           'field' => 'slug',
           'terms' => array( 'clothing' ), // Don't display products in the clothing category on the shop page.
           'operator' => 'NOT IN'
    );


    $q->set( 'tax_query', $tax_query );

}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

php CF7手机现场验证

CF7手机现场验证

cf7_phone.php
//////////////////////////////////////////////////////////////
///////// CF7 FORMS PHONE VALIDATION
//////////////////////////////////////////////////////////////
add_filter( 'wpcf7_validate_email*', 'custom_phone_validation_filter', 20, 2 );
 
function custom_phone_validation_filter( $result, $tag ) {
    $tag = new WPCF7_FormTag( $tag );
    if ( 'phone' == $tag->name ) {
        $phone_num = isset( $_POST['phone'] ) ? trim( $_POST['phone'] ) : '';
        if(!preg_match("/^([+]?\d{1,4}[-\s]?|)\d{3}[-\s]?\d{3}[-\s]?\d{4}$/",$phone_num)) { 
            $result->invalidate( $tag, "Fornire un numero di telefono valido" );
        }
    }
    return $result;
}

php 数据库类

数据库类

database.class.php
<?php
class DB
{
    /*
    * コンストラクタ
    *
    * @var host:ホスト
    * @var user:ユーザー
    * @var pass:パス
    * @var db:データーベース名
    */
    function __construct($dbServer,$dbUser,$dbPass,$dbName){
        $this->host = $dbServer;
        $this->user = $dbUser;
        $this->pass = $dbPass;
        $this->db = $dbName;
        $this->dsn = "mysql:dbname=$dbName;$host=$host";
        $this->option = array(
                            PDO::ATTR_PERSISTENT => true,
                            PDO::MYSQL_ATTR_INIT_COMMAND => "SET CHARACTER SET 'utf8'",
                            PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING
                        );        
    }

    /*
    * データベースへ接続
    *
    * @param String
    * @return array
    */
    public function connect(){
        try{
            $pdo = new PDO ($this->dsn, $this->user,$this->pass,$this->option);
        } catch(PDOException $e) {
            echo "接続できませんでした";
        }
        return $pdo;
    }

    public function select($query,$type = 'object'){
        $pdo = $this->connect();
        $stmt = $pdo->prepare($query);
        $stmt->execute();
        if($type == 'object'){
            $data = $stmt->fetchAll(PDO::FETCH_CLASS);
        } else {
            $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
        }
        $this->close();
        return $data;
    }

    public function insert($table,$col,$val,$last_id_flg = false,$id_name = null){

        try{
            $pdo = $this->connect();
            function semicolon($n){
                return(":$n");
            }
            $_val = array_map("semicolon",$val);
            if(count($col) == count($val)){
                return false;
            }
            $query = 'INSERT INTO '.$table.'('.implode(',',$col).') VALUES (' .implode(',',$col).')';
            $stmt = $pdo->prepare($query);
            for($i=0; $val < count($val); $i++){
                $stmt = $pdo->bindValue($_val[$i],$val[$i]);
            }
            $stmt->execute();
            if($last_id_flg){
                return $pdo->lastInsertId($id_name);
            }
            return true;
            $this->close();
        } catch(PDOException $e) {
            return false;
        }
    }

    public function delete($table,$){

        try{
            $pdo = $this->connect();
            $this->close();
        } catch(PDOException $e) {
            return false;
        }
    }

    /*
    * データベースへの接続解除
    *
    * @param String
    * @return array
    */
    public function close(){
        $pdo = null;
    }
}


$dbServer = 'localhost';
$dbUser = 'root';
$dbPass = 'root';
$dbName = 'invo';
$db_connect = new DB($dbServer,$dbUser,$dbPass,$dbName);
$db_connect->connect();
$sql = "SELECT * FROM users";

$result = $db_connect->get_result($sql);
/*
$result = $db_connect->get_result_array($sql);
var_dump($result);
$result = $db_connect->get_result_object($sql);
var_dump($result);
*/

php aggiungo una custom taxonomy nella vista sommario di un custom type #backend #taxonomy #customtax

aggiungo una custom taxonomy nella vista sommario di un custom type #backend #taxonomy #customtax

addTaxtoBackend.php
<?php
//aggiungo taxonomy tipi a presentazioni
//dove presentazioni è il nome del custom type
//e tag_presentazioni è il nome della custom taxonomy
add_filter( 'manage_taxonomies_for_presentazioni_columns', 'presentazioni_type_columns' );
function presentazioni_type_columns( $taxonomies ) {
    $taxonomies[] = 'tag_presentazioni';
    return $taxonomies;
}
?>

php WordPress - 删除作者链接

WordPress - 删除作者链接

entry-meta.php
// Original author link
<?php the_author_posts_link(); ?>

// Author name without link
<?php the_author(); ?>