php 删除标题中的条目元

functions.php
//* Remove the entry meta in the entry header (requires HTML5 theme support)
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );

php *模块* - 添加到购物车后的消息

m1-module-after-add-to-cart-message

https://inchoo.net/magento/tracking-magento-add-product-to-cart-action-for-analytic-software-purpose/

\!h /app/code/local/Theme/Afteraddtocart/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Theme_Afteraddtocart>
            <version>1.0.0.0</version>
        </Theme_Afteraddtocart>
    </modules>
    <global>
        <models>
            <afteraddtocart>
                <class>Theme_Afteraddtocart_Model</class>
            </afteraddtocart>
        </models>
    </global>
    <frontend>
        <events>
            <controller_action_predispatch_checkout_cart_add>
                <observers>
                    <afteraddtocart_log_cart_add>
                        <class>afteraddtocart/observer</class>
                        <method>logCartAdd</method>
                    </afteraddtocart_log_cart_add>
                </observers>
            </controller_action_predispatch_checkout_cart_add>
        </events>
    </frontend>
</config>

\!h /app/code/local/Theme/Afteraddtocart/Model/Observer.php

<?php
 
class Theme_Afteraddtocart_Model_Observer
{
    public function logCartAdd() {
 
        $product = Mage::getModel('catalog/product')
                        ->load(Mage::app()->getRequest()->getParam('product', 0));
 
        if (!$product->getId()) {
            return;
        }
 
        $categories = $product->getCategoryIds();
 
        Mage::getModel('core/session')->setProductToShoppingCart(
            new Varien_Object(array(
                'id' => $product->getId(),
                'qty' => Mage::app()->getRequest()->getParam('qty', 1),
                'name' => $product->getName(),
                'price' => $product->getPrice(),
                'category_name' => Mage::getModel('catalog/category')->load($categories[0])->getName(),
            ))
        );
    }
}

\!h /app/etc/modules/Theme_Afteraddtocart.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Theme_Afteraddtocart>
            <active>true</active>
            <codePool>local</codePool>
        </Theme_Afteraddtocart>
    </modules>
</config>

\!h local.xml

<reference name="after-header">
    <block type="core/template" name="afteraddtocart-message" template="additional/afteraddtocart-message.phtml"/>
</reference>

\!h /template/additional/afteraddtocart-message.phtml

<?php 
    $_loaded_product = Mage::getModel('core/session')->getProductToShoppingCart();
    if ($_loaded_product && $_loaded_product->getId()){
        print_r($_loaded_product);
    }
    Mage::getModel('core/session')->unsProductToShoppingCart();
?>

php 数组分组

arrGroupBy
<?php

function group_by($key, $data) {
    $result = array();
    
    foreach($data as $val) {
        if(array_key_exists($key, $val)){
            $result[$val[$key]][] = $val;
        }else{
            $result[""][] = $val;
        }
    }
    
    return $result;
}
arrGroupByExample
<?php
// Example Usage fror Select2 dropdown to group by certain field

$ddlArrayTo = array();
$byGroup = $this->group_by('[Property]', $ddlArrayFrom);
foreach ($byGroup as $k => $sublist) {
    $optgroup = $optgroup != null ? ($k != "" ? $k : $optgroup) : $k; // check if there's a group name
    // Checking if there's selected value
    foreach ($sublist as $sk => $list) {
        $sublist[$sk]['selected'] = ($selected == $list['id']) ? true : false;
        
    }
    
    $ddlArray[] = array (
        "text" => $optgroup,
        "children" => $sublist,
    );
    
}

php 将特色图像添加到CPT [联系人]仪表板列表

Add featured image to CPTcontact dashboard list
//You need to replace 'contact' with your custom post type slug in both hook names.

function add_featured_image_column($defaults) {
  $defaults['featured_image'] = 'Featured Image';
  return $defaults;
}
add_filter('manage_contact_posts_columns', 'add_featured_image_column');		//replace 'contact'

function show_featured_image_column($column_name, $post_id) {
  if ($column_name == 'featured_image') {
	echo get_the_post_thumbnail($post_id, 'thumbnail'); 
  }
}
add_action('manage_contact_posts_custom_column', 'show_featured_image_column', 10, 2);		//replace 'contact'

php 仅运往美国大陆航空

functions.php
function only_ship_to_continental_us( $available_methods ) {
	global $woocommerce;
	$excluded_states = array( 'AK','HI','GU','PR' );
	if( in_array( $woocommerce->customer->get_shipping_state(), $excluded_states ) ) {
		// Empty the $available_methods array
		$available_methods = array();
	}
	return $available_methods;
}
add_filter( 'woocommerce_package_rates', 'only_ship_to_continental_us', 10 );

php Шорткодизменю

menu-shortcode.php
<?php

/*
Шорт код меню
[menu name="MAIN EN"]

В name вставляем название меню из админки, дальше шорт код ставим где угодно
*/
function print_menu_shortcode($atts, $content = null) {
	extract(shortcode_atts(array( 'name' => null, 'class' => null ), $atts));
	return wp_nav_menu( array( 'menu' => $name, 'menu_class' => 'myclass', 'echo' => false ) );
}

add_shortcode('menu', 'print_menu_shortcode');

php 渲染表格

FormBuilder:渲染表单

render-form.php
<?php
$form = $forms->render("my_form");
echo $form->styles;
echo $form->scripts;
echo $form;
?>

php discuz中使用的加密解密算法

有时我们需要使用PHP将特定的信息进行加密,也就是通过加密算法生成一个加密字符串,这个加密后的字符串可以通过解密算法进行解密,便于程序对解密后的信息进行处理。最常见的应用在用户登录以及一些API数据交换的场景。最常见的应用在用户登录以及一些API数据交换的场景。加密解密原理一般都是通过一定的加密解密算法,将密钥加入到算法中,最终得到加密解密结果。

authcode.php
<?php  
//非常给力的authcode加密函数,Discuz!经典代码(带详解)  
//函数authcode($string, $operation, $key, $expiry)中的$string:字符串,明文或密文;$operation:DECODE表示解密,其它表示加密;$key:密匙;$expiry:密文有效期。  
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {     
    // 动态密匙长度,相同的明文会生成不同密文就是依靠动态密匙     
    $ckey_length = 4;     
    // 密匙     
    $key = md5($key ? $key : $GLOBALS['discuz_auth_key']);     
    // 密匙a会参与加解密     
    $keya = md5(substr($key, 0, 16));     
    // 密匙b会用来做数据完整性验证     
    $keyb = md5(substr($key, 16, 16));     
    // 密匙c用于变化生成的密文     
    $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';     
    // 参与运算的密匙     
    $cryptkey = $keya.md5($keya.$keyc);     
    $key_length = strlen($cryptkey);     
    // 明文,前10位用来保存时间戳,解密时验证数据有效性,10到26位用来保存$keyb(密匙b),   
    //解密时会通过这个密匙验证数据完整性     
    // 如果是解码的话,会从第$ckey_length位开始,因为密文前$ckey_length位保存 动态密匙,以保证解密正确     
    $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) :  sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;     
    $string_length = strlen($string);     
    $result = '';     
    $box = range(0, 255);     
    $rndkey = array();     
    // 产生密匙簿     
    for($i = 0; $i <= 255; $i++) {     
        $rndkey[$i] = ord($cryptkey[$i % $key_length]);     
    }     
    // 用固定的算法,打乱密匙簿,增加随机性,好像很复杂,实际上对并不会增加密文的强度     
    for($j = $i = 0; $i < 256; $i++) {     
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;     
        $tmp = $box[$i];     
        $box[$i] = $box[$j];     
        $box[$j] = $tmp;     
    }     
    // 核心加解密部分     
    for($a = $j = $i = 0; $i < $string_length; $i++) {     
        $a = ($a + 1) % 256;     
        $j = ($j + $box[$a]) % 256;     
        $tmp = $box[$a];     
        $box[$a] = $box[$j];     
        $box[$j] = $tmp;     
        // 从密匙簿得出密匙进行异或,再转成字符     
        $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));     
    }     
    if($operation == 'DECODE') {    
        // 验证数据有效性,请看未加密明文的格式     
        if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) &&  substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {     
            return substr($result, 26);     
        } else {     
            return '';     
        }     
    } else {     
        // 把动态密匙保存在密文里,这也是为什么同样的明文,生产不同密文后能解密的原因     
        // 因为加密后的密文可能是一些特殊字符,复制过程可能会丢失,所以用base64编码     
        return $keyc.str_replace('=', '', base64_encode($result));     
    }     
}   
$str = 'abcdef';   
$key = 'www.helloweba.com';   
echo authcode($str,'ENCODE',$key,0); //加密   
$str = '56f4yER1DI2WTzWMqsfPpS9hwyoJnFP2MpC8SOhRrxO7BOk';   
echo authcode($str,'DECODE',$key,0); //解密   
?> 

php php在操作断点续传时文件如何分割合并

php实现断点续传,就需要把大文件分割成多个小文件,然后单个上传。传完后在合并。<br/> $ b $b│merge.php - 合并文件脚本\ <br/>│合并.zip - 合并后文件\ $ b $b│socket.zip - 需要分割的文件\ $ b $b│split.php - 分割文件脚本\ $ b $b│\ <br/>└─split - 分割后小文件目录

split.php
<?php
$fp = fopen("socket.zip", "rb");
$filesize = 10;
$i = 0;
$no = 1;
while(!feof($fp))
{
  $file = fread($fp, $filesize);
  $fp2 = fopen("./split/socket.port".sprintf("%04d",$no).".".$i."-".($i+$filesize).".tmp", "wb");
  fwrite($fp2, $file, $filesize);
  fclose($fp2);
  $i+=$filesize+1;
$no++;
}
fclose($fp);
merge.php
<?php
$filelist = glob('./split/*socket*.tmp');
$filesize = 10;
//print_r($filelist);
$mergeFileName = 'merg.zip';
unlink($mergeFileName);
  $fp2 = fopen($mergeFileName,"w+");
foreach($filelist as $k => $v)
{
  $fp = fopen($v, "rb");
   $content = fread($fp, $filesize);

   fwrite($fp2, $content, $filesize);
   unset($content);
   fclose($fp);
   echo $k,"\n";
}
  fclose($fp2);

php WordPress和ACF |如果菜单项具有自定义字段集,则添加类

类被添加到&lt; li&gt;菜单项的父级。

custom-functions.php
// Add class to menu item using the featured image
add_filter('nav_menu_css_class', function( $classes, $items ) {

  // loop
  foreach( $items as $item ) {

    // vars
    $bgImg = get_field('use_featured_image', $item); // name of custom field

    // check for image
    if( $bgImg ) {

      $classes[] = 'featured-img-bg';

    }

  }

  // return
  return $classes;

}, 10, 2);