php 禁用插件更新

禁用插件更新

functions.php
<?php
//* Disable plugin updates
add_filter( 'site_transient_update_plugins', 'nl_disable_plugin_updates' );
function nl_disable_plugin_updates( $value ) {
  unset( $value->response['woocommerce/woocommerce.php'] );
  return $value;
}

php 作曲家PHP

作曲家PHP

composer-php.php
// iniciar composer e criar composer.json
composer init

// instalar dependecias
composer require nomeda/dependencia || composer require-dev nomeda/dependencia
composer install || composer update

// dump dos autoloads
composer dumpautoload

// remover packages
composer remove nomeda/dependencia

// criar novo projeto composer numa pasta definida
composer create-project nomeda/dependencia pasta


// composer autoload
require_once '../vendor/autoload.php';

php 检查对象是否有关系数据

检查对象是否有关系数据

UsersController.php
<?php

class UsersController extends Controller
{
 
    public function deleteUser($id,Request $request)
    {
        try {
            $user = User::findOrFail($id);
            //only allowed delete user that have no evaluation
            if ($user->companies()->count()) {
                return response()->json(['result'=>'error', 'message'=>'not allowed to delete user with evaluation']);
            }
            else{
                $user->delete();
                return response()->json(['result'=>'success']);
            }
        }
        catch (QueryException $e) {
            return $this->response->errorBadRequest('Error while deleting.');
        }
    } 
  
  
  
}

php POST,ПроверкавходныхданныхPOST

POST,ПроверкавходныхданныхPOST

index.php
<?
foreach ($_POST as $key => $value) {
  $data = htmlspecialchars(strip_tags($value));
  $datasec = iconv("UTF-8", "WINDOWS-1251", $data);
  $_SESSION["create".$IBLOCK][$key] = $datasec;
}

php 删除WooCommerce评论标签

删除WooCommerce评论标签

example.php
<?php

add_filter( 'woocommerce_product_tabs', 'lpb_wc_remove_reviews_tab', 98 );
function lpb_wc_remove_reviews_tab ( $tabs ) {
  unset($tabs['reviews']);
  return $tabs;
}

php 从不需要它的页面中删除联系表单7脚本和css

从不需要它的页面中删除联系表单7脚本和css

functions.php
//add this to functions.php
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
 
//add this to template of page with contact form 7 before wp_head() tag

<?php
    if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
        wpcf7_enqueue_scripts();
    }
 
    if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
        wpcf7_enqueue_styles();
    }
?>

php 周六 - 周一价格计算

周六 - 周一价格计算

functions.php
add_filter( 'easy_booking_two_dates_price', 'easy_booking_return_base_price', 8, 5 );
 
function easy_booking_return_base_price( $booking_price, $product, $_product, $data, $price_type ) {
    
    $end_date = strtotime( $data['end'] );
    $end_day = date( 'D', $end_date );

    $prices_include_tax = get_option('woocommerce_prices_include_tax');

    if ( $end_day === 'Sat' ) {

        $price = ( $price_type === 'regular_price' ) ? $_product->get_regular_price() : $_product->get_price();
        $args = array( 'price' => $price );       
        $price = $prices_include_tax === 'yes' ? wc_get_price_including_tax( $_product, $args ) : wc_get_price_excluding_tax( $_product, $args );

        $booking_price += $price;

    }
 
    return $booking_price;
}

php 用于DIOCESI POST的CHECBOX

用于DIOCESI POST的CHECBOX

new_gist_file_0.php
add_action('post_submitbox_misc_actions', createCustomField);
add_action('save_post', saveCustomField);

function createCustomField()
{
    $post_id = get_the_ID();
  
    if (get_post_type($post_id) != 'post') {
        return;
    }
  
    $value = get_post_meta($post_id, '_my_custom_field', true);
    wp_nonce_field('my_custom_nonce_'.$post_id, 'my_custom_nonce');
    ?>
    <div class="misc-pub-section misc-pub-section-last">
        <label><input type="checkbox" value="1" <?php checked($value, true, true); ?> name="_my_custom_field" /><?php _e('My Custom Checkbox Field', 'pmg'); ?></label>
    </div>
    <?php
}

function saveCustomField($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    
    if (
        !isset($_POST['my_custom_nonce']) ||
        !wp_verify_nonce($_POST['my_custom_nonce'], 'my_custom_nonce_'.$post_id)
    ) {
        return;
    }
    
    if (!current_user_can('edit_post', $post_id)) {
        return;
    }
    if (isset($_POST['_my_custom_field'])) {
        update_post_meta($post_id, '_my_custom_field', $_POST['_my_custom_field']);
    } else {
        delete_post_meta($post_id, '_my_custom_field');
    }
}

PAGE TEMPLATE

<?php $args = array(
        'meta_key' => '_my_custom_field', // include underscore prefix in key name
        'meta_value' => 1
    );
    // The number of posts displayed would be determined under Settings->Reading
    query_posts($args);

    if(have_posts()): while(have_posts()): the_post(); ?>
       
        <h1><?php the_title(); ?></h1>
    
    <?php endwhile; else: ?>

    <?php endif;    ?>

php 此代码会删除创建优惠券时所有待售的产品。

此代码会删除创建优惠券时所有待售的产品。

new_gist_file.php
<?php

add_filter('ywrac_coupon_args','ywrac_coupon_args');
function ywrac_coupon_args( $args ){

	$product_on_sale = wc_get_product_ids_on_sale();
	if( is_array( $product_on_sale) && !empty( $product_on_sale ) ){
		$args['exclude_product_ids'] = implode( ',', $product_on_sale );
	}

	return $args;
}

php cargar un plugin cuando no esta cargado

cargar un plugin cuando no esta cargado

new_gist_file.php
$Plugins = new Plugins();
echo $Plugins->tips();