[JavaScript]Promise

getCart(){
    return new Promise((resolve,reject) => {
        const url = 'url';
        fetch(url)
            .then((response)=>{
                if (!response.ok) {
                    throw new Error();
                }
                return response.json();
            })
            .then((json)=>{
                resolve(json);
            })
            .catch((error)=>{
                reject(error);
            });
    });
}

this.getCart()
.then((json)=>{
    
})
.catch((error)=>{

});

[JavaScript]文字列から漢字抽出

文字列から漢字抽出

const str = 'ひらがな小林カタカナ漢字';
const pattern = /(\p{scx=Han}+)/ug;
const matches = str.match(pattern);
console.log(matches);

出力

(2) ['小林', '漢字']

[WordPress]先祖postへのリンクを出力する

function get_parents($post,$parents = array())
{
    if (!empty($post->post_parent)){
        $parent = get_post($post->post_parent);
        array_unshift( $parents, $parent);
        return get_parents( $parent, $parents );
    }
    return $parents;
}
function the_parents($post,$format)
{
    $parents = get_parents($post);
    if(!empty($parents)){
        foreach($parents as $i => $parent){
            $html = $format;
            $html = preg_replace('/%permalink%/',get_permalink($parent->ID),$html);
            $html = preg_replace('/%title%/',esc_html($parent->post_title),$html);
            echo $html;
        }
    }
}

[WordPress]管理画面でjs,cssを読み込む

function add_admin_style()
{
    wp_enqueue_script('admin_script', get_template_directory_uri().'/scripts/admin.js');
    wp_enqueue_style('admin_style', get_template_directory_uri().'/style/admin.css');
}
add_action('admin_enqueue_scripts', 'add_admin_style');

[Shopify][React]カスタムアプリでViewを表示する

import {
    View,
    Text,
    useSettings,
    reactExtension,
} from '@shopify/ui-extensions-react/checkout';

export default reactExtension("purchase.checkout.block.render", () => (
    <Extension />
));

function Extension() {
    const { title,left,border } = useSettings();
    const _title = title ? title : 'タイトル';
    const _left = left ? "start" : "center"
    const _border = border ? "none" : "base"
    return (
        <View display="block" padding="base" border={_border} cornerRadius="base" inlineAlignment={_left}>
            <Text size="base" emphasis="bold">{_title}</Text>
        </View>
    );
}

 
shopify.extension.tomlに追記

[extensions.settings]
[[extensions.settings.fields]]
key = "title"
type = "single_line_text_field"
name = "表示する文言"
description = "表示する文言を入力してください"
[[extensions.settings.fields]]
key = "left"
type = "boolean"
name = "テキストを左寄せにする"
[[extensions.settings.fields]]
key = "border"
type = "boolean"
name = "枠線を表示しない"

[WordPress]不要メニューを非表示

function custom_remove_menus()
{
    global $menu;
    /** 投稿 */
    remove_menu_page('edit.php');
    /** コメント */
    remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'custom_remove_menus');