Author: goodamaze

  • Hello world!

    Welcome to Life is Good, cause You’re Amazing Sites. This is your first post. Edit or delete it, then start writing!

  • N8N Workflow on WordPress site

    function load_n8n_demo_scripts() {
    wp_enqueue_script(
    ‘webcomponents-loader’,
    ‘https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2.0.0/webcomponents-loader.js’,
    array(),
    null,
    true
    );
    wp_enqueue_script(
    ‘lit-polyfill’,
    ‘https://www.unpkg.com/lit@2.0.0-rc.2/polyfill-support.js’,
    array(),
    null,
    true
    );
    wp_enqueue_script(
    ‘n8n-demo’,
    ‘https://cdn.jsdelivr.net/npm/@n8n_io/n8n-demo-component/n8n-demo.bundled.js’,
    array(),
    null,
    true
    );
    }
    add_action(‘wp_enqueue_scripts’, ‘load_n8n_demo_scripts’);

  • “Unlocking the Health Benefits of New Zealand’s Premium Manuka Honey: UMF Certification Explained”

    Title: The Health Benefits of Manuka Honey from New Zealand

    Manuka Honey, produced in New Zealand, is renowned for its unique health benefits. This monofloral honey, derived from the nectar of the mānuka tree (Leptospermum scoparium), boasts potent antimicrobial, anti-inflammatory, and antioxidant properties. Here are some of its key health benefits:

    -Soothes Coughs Naturally:** Manuka Honey’s anti-inflammatory properties help soothe coughs and clear a child’s cough, making it a natural remedy for respiratory issues[1].
    – Boosts Immunity & Fights Infections:** Its antibacterial and antiviral properties make it effective in preventing infections and boosting immunity[1][3].
    – Supports Gut Health & Digestion:** Manuka Honey has been shown to support gut health and digestion, potentially aiding in conditions like irritable bowel syndrome (IBS)[1][3].
    – Soothes Hay Fever Symptoms:** The honey’s anti-inflammatory properties can help regulate the immune system’s overreaction in hay fever, soothing symptoms[1].
    – Heals & Protects Skin:** Topically applied, Manuka Honey calms inflammation and irritation in eczema and other skin disorders, promoting wound healing and tissue regeneration[1][3].
    – Oral Health Benefits:** Manuka Honey inhibits oral bacteria growth, reduces plaque, and eases gingivitis, making it a valuable addition to oral care routines[5].

    New Zealand’s strict regulatory framework ensures the authenticity and quality of Manuka Honey, which is graded using the Unique Manuka Factor (UMF) rating system. This grading system indicates the concentration of methylglyoxal (MGO), directly correlating with the honey’s potency[2][4].

  • Claude Code: Enhancing Coding Efficiency with AI

    Claude Code: Revolutionizing Coding with AI

    Claude, developed by Anthropic, is an advanced AI model designed to assist with coding tasks. With its integration into JetBrains AI Assistant, developers can now leverage Claude’s capabilities to enhance their coding workflows.

    Here are some key features of Claude Code:

    • Code Explanation and Refactoring: Claude can explain code snippets, suggest refactoring, and provide insights into complex programming concepts.
    • Contextual Code Completion: By using Claude models like Claude 3.5 Sonnet and Claude 3.5 Haiku, developers can receive contextually relevant code suggestions.
    • Task Automation: Claude’s ability to interact with external tools makes it ideal for automating repetitive coding tasks, such as generating commit messages or creating documentation.

    ### Why Choose Claude Code?

    Claude Code offers several advantages over traditional coding methods:

    • Improved Accuracy: Claude’s advanced language models provide more accurate and reliable code suggestions, reducing the likelihood of errors.
    • Enhanced Productivity: By automating routine tasks and providing real-time code assistance, developers can focus on more complex and creative aspects of their projects.
    • Customization Options: The ability to tailor Claude’s tone and voice for different types of writing ensures that the AI assistant fits seamlessly into various coding environments.

    ### How to Integrate Claude Code into Your Workflow

    To start using Claude Code, follow these steps:

    1. Choose Your IDE: Ensure you are using a JetBrains IDE that supports the integration of AI assistants.
    2. Select Claude Models: In the chat interface, select the desired Claude model (e.g., Claude 3.5 Sonnet or Claude 3.5 Haiku) for optimal performance.
    3. Utilize AI Assistance: Engage with Claude by asking questions or providing code snippets for assistance. The AI will respond with relevant suggestions and explanations.

    ### Conclusion

    Claude Code represents a significant advancement in AI-assisted coding tools. By leveraging its capabilities, developers can streamline their workflows, improve accuracy, and enhance productivity. Whether you’re working on complex projects or need help with routine tasks, Claude Code is an invaluable addition to any developer’s toolkit.

  • array( $this, ‘process_admin_options’ )처럼 작성해야하는 이유는?

    phpCopyEditarray( $this, 'process_admin_options' )
    

    이렇게 작성해야 하는 이유는 객체 지향 프로그래밍에서 클래스의 메서드를 콜백으로 전달할 때 사용하는 올바른 방식이기 때문입니다. 아래에서 각 부분을 상세히 설명하겠습니다.

    1. array( $this, 'process_admin_options' )의 의미

    • array(...):
      • PHP에서 콜백 함수를 전달할 때, 특정 클래스의 메서드를 호출하려면 이 콜백을 배열로 표현해야 합니다.
    • $this:
      • $this현재 클래스의 인스턴스를 나타냅니다. 즉, 이 클래스에서 정의된 메서드를 호출할 때 현재 인스턴스를 참조해야 합니다.
    • 'process_admin_options':
      • 이 문자열은 호출하려는 클래스의 메서드 이름을 나타냅니다.
      • 여기서 process_admin_optionsWC_Shipping_Method 클래스에서 상속받은 메서드로, WooCommerce 설정 페이지에서 옵션을 저장할 때 호출됩니다.

    2. 왜 이렇게 해야 하는가?

    • 객체의 메서드를 콜백으로 사용:
      • PHP에서는 클래스의 인스턴스 메서드를 콜백으로 전달하려면 array( $object, 'methodName' ) 형식을 사용해야 합니다.
      • $this는 현재 클래스의 인스턴스이며, 'process_admin_options'는 해당 클래스의 메서드 이름입니다.
    • 객체 지향 프로그래밍(OOP)의 특성:
      • OOP에서 메서드는 객체의 맥락에서 호출되어야 합니다. array( $this, 'process_admin_options' )로 지정하면, WooCommerce가 process_admin_options 메서드를 호출할 때 현재 인스턴스를 기준으로 호출합니다.

    3. 대안과 문제점

    • 대안: 단순히 'process_admin_options'로 콜백 전달:
      • 만약 array( $this, 'process_admin_options' ) 대신 'process_admin_options'만 전달한다면, PHP는 이 메서드를 전역 함수로 찾으려고 합니다. 하지만 process_admin_options는 클래스 내부에 정의된 메서드이기 때문에 오류가 발생합니다.
    • 정적 메서드 사용 시:
      • 만약 process_admin_options가 정적 메서드라면 array( 'ClassName', 'process_admin_options' ) 형태로 사용할 수 있습니다.

    4. 결론

    array( $this, 'process_admin_options' )는 현재 클래스의 인스턴스 메서드를 콜백으로 전달할 때 사용하는 표준적인 방법입니다. 이것은 WooCommerce가 해당 메서드를 호출할 때, 현재 인스턴스의 컨텍스트에서 호출하도록 보장합니다. 이 방법을 사용하지 않으면 콜백으로 클래스의 메서드를 올바르게 연결할 수 없습니다.

    array( $object&,; ‘methodName’ )

  • 왜 ‘woocommerce_update_options_shipping_’ . $this->id 이렇게 해야 할까? ‘woocommerce_update_options_shipping_. $this->id’ 로 쓰면 틀리나?

     

    'woocommerce_update_options_shipping_. $this->id' 이렇게 쓰면 문법 오류가 발생합니다. 이 부분은 문자열 연결(string concatenation)과 관련된 것으로, PHP에서 올바른 문법을 사용해야 합니다.

    1. 문법 차이

    • 올바른 방식: 'woocommerce_update_options_shipping_' . $this->id
      • **'.'**는 PHP에서 문자열을 **연결(concatenate)**하는 연산자입니다.
      • 이 방식은 'woocommerce_update_options_shipping_' 문자열과 $this->id 속성 값을 하나의 문자열로 결합합니다.
    • 잘못된 방식: 'woocommerce_update_options_shipping_. $this->id'
      • 여기서 . $this->id 부분은 따옴표 안에 그대로 문자열로 인식됩니다.
      • PHP는 . 연산자를 따옴표 안에서 문자열로 간주하므로, 실제로 문자열을 연결하지 않습니다.
      • 이로 인해 $this->id가 문자열에 포함되지 않고, 전체 문자열이 'woocommerce_update_options_shipping_. $this->id'로 처리됩니다.

    2. 예시 비교

    • 올바른 코드:phpCopyEdit'woocommerce_update_options_shipping_' . $this->id
      • $this->id'custom_shipping'이라면, 이 코드는 **'woocommerce_update_options_shipping_custom_shipping'**이 됩니다.
    • 잘못된 코드:phpCopyEdit'woocommerce_update_options_shipping_. $this->id'
      • PHP는 이 문자열을 그대로 **'woocommerce_update_options_shipping_. $this->id'**로 처리하고, $this->id 변수의 값을 문자열에 포함시키지 않습니다.

    3. 결론

    . 연산자를 따옴표 바깥에 사용해야 $this->id 값을 포함한 동적인 문자열을 생성할 수 있습니다. 그렇지 않으면 PHP는 문자열을 그대로 해석하여, 변수를 포함한 문자열 결합이 이루어지지 않습니다. 따라서 '.' 연산자를 올바르게 사용해야 동적인 훅 이름을 생성할 수 있습니다.

  • WordPress plugin 개발에서 add_filter와 add_action의 차이

    add_filteradd_action은 WordPress에서 플러그인을 개발할 때 사용하는 두 가지 주요 함수입니다. 이 두 함수는 WordPress의 Hook 시스템의 일부로, 플러그인이나 테마가 WordPress의 기본 기능을 확장하거나 수정할 수 있도록 도와줍니다.

    1. Hook 시스템 개요

    • Actions: 특정 시점에 실행되는 함수입니다. 예를 들어, 게시글이 저장될 때 특정 작업을 실행할 수 있습니다.
    • Filters: 특정 데이터를 변경할 수 있는 기회를 제공합니다. 예를 들어, 게시글 제목을 수정할 수 있습니다.

    2. add_action

    add_action 함수는 WordPress가 특정 Action Hook에서 실행될 때 사용자 정의 함수를 호출하도록 등록합니다. 이 함수는 주로 작업을 수행하는 데 사용됩니다.

    사용 예시:

    // 사용자가 로그인할 때 메시지를 로그에 기록하는 작업을 추가
    function log_user_login($user_login) {
        error_log("User logged in: " . $user_login);
    }
    add_action('wp_login', 'log_user_login');
    
    • wp_login: 사용자가 로그인할 때 실행되는 Action Hook.
    • log_user_login: 사용자가 로그인할 때 실행될 사용자 정의 함수.

    주요 특징:

    • 동작을 추가할 때 사용.
    • 기존 기능을 중단하지 않고 추가적인 작업을 수행.

    3. add_filter

    add_filter 함수는 특정 Filter Hook을 통해 전달되는 데이터를 수정할 때 사용됩니다. 이 함수는 주로 특정 데이터를 변경하거나 조작하는 데 사용됩니다.

    사용 예시:

    // 모든 게시글 제목 앞에 "Special: "를 추가
    function modify_post_title($title) {
        return 'Special: ' . $title;
    }
    add_filter('the_title', 'modify_post_title');
    
    • the_title: 게시글 제목을 출력하기 전에 데이터를 수정할 수 있는 Filter Hook.
    • modify_post_title: 제목을 수정하는 사용자 정의 함수.

    주요 특징:

    • 데이터를 변경하거나 조작할 때 사용.
    • 전달된 데이터를 수정하여 반환.

    4. 비교

    기능add_actionadd_filter
    목적특정 시점에 작업을 추가데이터를 수정하거나 필터링
    반환값없음필터링된 데이터를 반환해야 함
    사용 사례사용자가 로그인할 때 이메일을 보내기게시글 제목을 수정
    훅 유형Action HookFilter Hook

    5. 심화 예시

    add_action 심화 예시

    사용자가 로그아웃할 때 로그를 남기고 이메일을 보낼 수 있습니다.

    function notify_user_logout($user_login) {
        error_log("User logged out: " . $user_login);
        wp_mail('admin@example.com', 'User Logout', $user_login . ' has logged out.');
    }
    add_action('wp_logout', 'notify_user_logout');
    

    add_filter 심화 예시

    블로그 게시물 내용에 “이 글은 수정되었습니다.”라는 문구를 추가할 수 있습니다.

    function append_modified_notice($content) {
        return $content . '<p>This post has been modified.</p>';
    }
    add_filter('the_content', 'append_modified_notice');
    

    6. 결론

    • add_action은 WordPress에서 특정 이벤트가 발생할 때 추가 작업을 수행하도록 해줍니다.
    • add_filter는 WordPress에서 특정 데이터를 필터링하거나 변경할 수 있는 기회를 제공합니다.

    이 두 가지를 적절히 사용하면 WordPress의 기본 기능을 훨씬 더 유연하게 확장할 수 있습니다.

  • Docker Compose로 업데이트

    Compose 사용 시: Docker Compose를 사용하는 경우 docker-compose.yml 파일을 업데이트한 후 실행합니다.

    # Pull latest version
    # Stop and remove older version
    # Start the container

    docker-compose down
    docker-compose pull
    docker-compose up -d

     

     

  • 배송방법 추가 코드

    <?php
    /*
    Plugin Name: Custom Shipping Method
    Plugin URI:
    Description: WooCommerce Custom Shipping Method
    Version: 1.0
    Author: Your Name
    */

    if (!defined(‘ABSPATH’)) {
    exit;
    }

    function custom_shipping_method_init() {
    if (!class_exists(‘Custom_Shipping_Method’)) {

    class Custom_Shipping_Method extends WC_Shipping_Method {
    /**
    * Weight unit
    */
    private $weight_unit;

    /**
    * Constructor for shipping class
    */
    public function __construct($instance_id = 0) {
    $this->id = ‘custom_shipping_method’;
    $this->instance_id = absint($instance_id);
    $this->title = ‘사용자 정의 배송’;
    $this->method_title = ‘사용자 정의 배송 방법’;
    $this->method_description = ‘배송 방법 설정을 관리합니다’;
    $this->supports = array(
    ‘shipping-zones’,
    ‘instance-settings’,
    ‘instance-settings-modal’
    );

    $this->weight_unit = get_option(‘woocommerce_weight_unit’);

    $this->init();
    }

    /**
    * Initialize shipping method
    */
    private function init() {
    $this->init_form_fields();
    $this->init_settings();

    $this->enabled = $this->get_option(‘enabled’);
    $this->title = $this->get_option(‘title’);

    add_action(‘woocommerce_update_options_shipping_’ . $this->id,
    array($this, ‘process_admin_options’));
    add_action(‘woocommerce_update_options_shipping_’ . $this->id,
    array($this, ‘clear_transients’));
    }

    /**
    * Initialize form fields
    */
    public function init_form_fields() {
    $this->instance_form_fields = array(
    ‘enabled’ => array(
    ‘title’ => ‘활성화’,
    ‘type’ => ‘checkbox’,
    ‘label’ => ‘이 배송 방법 활성화’,
    ‘default’ => ‘yes’
    ),
    ‘title’ => array(
    ‘title’ => ‘배송방법명’,
    ‘type’ => ‘text’,
    ‘description’ => ‘고객에게 표시될 배송 방법 이름’,
    ‘default’ => $this->method_title,
    ‘desc_tip’ => true
    ),
    ‘cost’ => array(
    ‘title’ => ‘기본 배송비’,
    ‘type’ => ‘number’,
    ‘default’ => ‘0’,
    ‘description’ => ‘기본 배송비를 입력하세요’,
    ‘desc_tip’ => true,
    ‘custom_attributes’ => array(
    ‘step’ => ‘100’,
    ‘min’ => ‘0’
    )
    ),
    ‘cost_per_weight’ => array(
    ‘title’ => $this->weight_unit.’당 추가 배송비’,
    ‘type’ => ‘number’,
    ‘default’ => ‘0’,
    ‘description’ => ‘무게당 추가되는 배송비’,
    ‘desc_tip’ => true,
    ‘custom_attributes’ => array(
    ‘step’ => ‘100’,
    ‘min’ => ‘0’
    )
    ),
    ‘min_weight’ => array(
    ‘title’ => ‘최소 배송 무게 (‘.$this->weight_unit.’)’,
    ‘type’ => ‘number’,
    ‘default’ => ‘0’,
    ‘description’ => ‘이 무게 이상일 때 배송 가능’,
    ‘desc_tip’ => true,
    ‘custom_attributes’ => array(
    ‘step’ => ‘0.1’,
    ‘min’ => ‘0’
    )
    ),
    ‘max_weight’ => array(
    ‘title’ => ‘최대 배송 무게 (‘.$this->weight_unit.’)’,
    ‘type’ => ‘number’,
    ‘default’ => ‘0’,
    ‘description’ => ‘0으로 설정시 무제한’,
    ‘desc_tip’ => true,
    ‘custom_attributes’ => array(
    ‘step’ => ‘0.1’,
    ‘min’ => ‘0’
    )
    ),
    ‘excluded_countries’ => array(
    ‘title’ => ‘제외 국가’,
    ‘type’ => ‘multiselect’,
    ‘class’ => ‘wc-enhanced-select’,
    ‘options’ => WC()->countries->get_shipping_countries()
    )
    );
    }

    /**
    * Calculate shipping cost
    */
    public function calculate_shipping($package = array()) {
    $cost = (float)$this->get_option(‘cost’, 0);
    $has_shipping_items = false;
    $weight = 0;

    // 배송 가능한 상품이 있는지 확인하고 무게 계산
    foreach ($package[‘contents’] as $item) {
    if ($item[‘data’]->needs_shipping()) {
    $has_shipping_items = true;
    $product_weight = (float)$item[‘data’]->get_weight();

    if (!empty($product_weight)) {
    $weight += $product_weight * $item[‘quantity’];
    }
    }
    }

    // 배송 가능 여부 확인
    if (!$has_shipping_items) {
    return;
    }

    // 무게가 있는 경우에만 무게 기반 배송비 계산
    $min_weight = (float)$this->get_option(‘min_weight’, 0);
    $max_weight = (float)$this->get_option(‘max_weight’, 0);

    if (($min_weight > 0 && $weight < $min_weight) ||
    ($max_weight > 0 && $weight > $max_weight)) {
    return;
    }

    $cost_per_weight = (float)$this->get_option(‘cost_per_weight’, 0);
    $cost += $weight * $cost_per_weight;

    // 배송비가 0 이상일 때만 배송 방법 추가
    if ($cost >= 0) {
    $rate = array(
    ‘id’ => $this->id . $this->instance_id,
    ‘label’ => $this->title,
    ‘cost’ => $cost,
    ‘calc_tax’ => ‘per_order’
    );

    $this->add_rate($rate);
    }
    }

    /**
    * Check if shipping method is available
    */
    public function is_available($package) {
    if ($this->enabled === ‘no’) {
    return false;
    }

    // 배송지 검사
    if (isset($package[‘destination’])) {
    $shipping_country = $package[‘destination’][‘country’];
    $shipping_state = $package[‘destination’][‘state’];
    $shipping_postcode = $package[‘destination’][‘postcode’];

    // 제외된 국가 확인
    $excluded_countries = $this->get_option(‘excluded_countries’, array());
    if (!empty($excluded_countries) &&
    in_array($shipping_country, $excluded_countries)) {
    return false;
    }

    // 배송지 주소가 비어있는 경우
    if (empty($shipping_country)) {
    return false;
    }
    }

    return apply_filters(
    ‘woocommerce_shipping_’ . $this->id . ‘_is_available’,
    true,
    $package,
    $this
    );
    }

    /**
    * Clear transients
    */
    public function clear_transients() {
    wc_delete_shipping_transients();
    }

    /**
    * Validate settings fields
    */
    public function validate_settings_fields($form_fields = array()) {
    if (!wp_verify_nonce($_POST[‘_wpnonce’], ‘woocommerce-settings’)) {
    return false;
    }
    return $form_fields;
    }
    }
    }
    }

    /**
    * Add shipping method to WooCommerce
    */
    function add_custom_shipping_method($methods) {
    $methods[‘custom_shipping_method’] = ‘Custom_Shipping_Method’;
    return $methods;
    }

    // 후크 등록
    add_action(‘woocommerce_shipping_init’, ‘custom_shipping_method_init’);
    add_filter(‘woocommerce_shipping_methods’, ‘add_custom_shipping_method’);

    // 관리자 스타일 추가
    add_action(‘admin_enqueue_scripts’, function() {
    wp_enqueue_style(‘custom-shipping-admin-style’,
    plugins_url(‘/assets/css/admin.css’, __FILE__));
    });

  • The 12.3 Emergency Martial Law in South Korea

    Introduction

    In December 2024, South Korea witnessed a significant political crisis with the declaration of emergency martial law by President Yoon Suk Yeol. This move, aimed at addressing perceived threats to the country’s democratic order, was met with widespread opposition and ultimately led to its swift reversal. In this blog post, we will delve into the events leading up to and following the declaration of martial law, providing a detailed timeline of the key developments.

     

    The Background: Political Tensions and Gridlock

    The political landscape in South Korea has been marked by intense conflicts and power struggles between the ruling People’s Power Party (PPP) and the main opposition Democratic Party (DP). The DP, which holds a majority in Parliament, has been critical of President Yoon’s administration, initiating impeachment motions against key government officials and fast-tracking a scaled-back budget bill without support from the PPP.

     

    The Declaration of Martial Law

    On December 3, 2024, President Yoon Suk Yeol declared emergency martial law, citing the need to eradicate pro-North Korean forces and protect the free constitutional order. The declaration was met with immediate rejection from opposition politicians and members of his own party. Yoon accused the opposition of engaging in anti-state activities and controlling Parliament, which he claimed was paralyzing the judiciary and executive branches.

     

    The Martial Law Decree

    The martial law decree, signed by Martial Law Commander General Park An-su, prohibited all political activities, including parliamentary activities, and placed all media and publications under the control of the Martial Law Command. The decree also banned strikes, work stoppages, and rallies inciting social unrest, with violators facing arrest, detention, and search without a warrant.

     

    Opposition Reaction and Parliament’s Response

    The opposition reacted swiftly to Yoon’s announcement. Lee Jae-myung, who narrowly lost to Yoon in the 2022 presidential election, called Yoon’s declaration “illegal and unconstitutional”. Even Yoon’s party leader, Han Dong-hoon, criticized the decision as “wrong” and vowed to “stop it with the people”. In an emergency session convened by Parliament, lawmakers passed a motion demanding the lifting of martial law, with 190 of its 300 members present.

     

    The Military’s Response and Parliament’s Vote

    Despite the vote, the military maintained that martial law would remain in place until formally lifted by President Yoon. However, the Parliament’s resolution was clear: martial law must be lifted. The military eventually retreated from the Assembly building after the lawmakers’ determination to end the emergency rule.

     

    Consequences and Aftermath

    The declaration of martial law sparked widespread protests in front of Parliament, with citizens chanting slogans such as “Immediate withdrawal of martial law!” and “Yoon Suk-yeol, to prison!”. The Korean Confederation of Trade Unions declared an indefinite general strike until the Yoon administration stepped down, invoking past military coups in 1961 and 1979.

     

    International Reactions and Implications

    The international community remained largely noncommittal during the crisis. U.S. State Department officials provided vague responses to questions about the showdown at the National Assembly, reflecting a long history of tolerating authoritarian behavior in South Korea for the sake of cohesion against the North Korean threat.

     

    Conclusion

    The declaration and subsequent lifting of martial law in South Korea serve as a stark reminder of the country’s complex political landscape and the ongoing power struggles between different factions. While the immediate crisis has been resolved, the underlying tensions and potential for future conflicts remain. As South Korea continues to navigate its democratic journey, it is crucial to address these issues through peaceful and constitutional means.