handle_errors_with_sys_exec_info

https://pythonprogramming.net/headless-error-handling-intermediate-python-tutorial/
import sys

try:
    a+b
except:
    print(sys.exc_info()[0])
    print(sys.exc_info()[1])
    print(sys.exc_info()[2].tb_lineno)
    print('Error: {}. {}, line: {}'.format(sys.exc_info()[0],
                                         sys.exc_info()[1],
                                         sys.exc_info()[2].tb_lineno))

Hook Flow

shows how Hooks flow in React
// Hook flow
// https://github.com/donavon/hook-flow
// http://localhost:3000/isolated/examples/hook-flow.js

// PLEASE NOTE: there was a subtle change in the order of cleanup functions
// getting called in React 17:
// https://github.com/kentcdodds/react-hooks/issues/90

import * as React from 'react'

function Child() {
  console.log('%c    Child: render start', 'color: MediumSpringGreen')

  const [count, setCount] = React.useState(() => {
    console.log('%c    Child: useState(() => 0)', 'co

docker remove all containers

docker rm -f $(docker ps -aq)

Display ACF Link with Shortcode

Display ACF link field with shortcode
add_shortcode('display-acf-link', function($atts){

	global $post;

	$a = shortcode_atts( array(
        'name' => '',
        'id' => $post->ID,
		'class' => 'fl-button',
		'target' => '_self',
		'icon' => ' <span class="dashicons dashicons-arrow-right"></span>',
		'type' => 'button'
    ), $atts );

	$link = get_field($a['name'], $a['id']);

	if($a['type'] == 'button'):

		$output = '<a href="' . $link['url'] . '" target="' . $a['target'] . '" class="' . $a['class'] . '" >' . $link['title'] . 

Include all files in plugin/includes folder

// Include PHP files in /includes folder
foreach(glob(plugin_dir_path(__FILE__) . 'includes/*.php') as $file){
    require $file;
}

Get List of Holidays

Dynamically populate list of holidays
function vi_get_holidays() {

	$today = new DateTime('now', new DateTimeZone('America/Chicago') );
	$year = $today->format('Y');

	// Get list of holidays
	$holidays = array(
		"New Year's Day" => '1/1/' . $year,
		"Martin Luther King, Jr. Day" => date('m/j/Y', strtotime('third Monday of 1/1/' . $year)),
		"President's Day" => date('m/j/Y', strtotime('third Monday of 2/1/' . $year)),
		"Memorial Day" => date('m/j/Y', strtotime('last Monday of 5/1/' . $year)),
		"Independence Day" => '7/4/' . $ye

Enqueue JS File

Enqueue JS file in Wordpress
// Enqueue JS file
function vi_enqueue_scripts() {
    wp_enqueue_script( 'vi-scripts', get_stylesheet_directory_uri() . '/vi-scripts.js', array( 'jquery' ), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'vi_enqueue_scripts' );

Dynamically Populate Gravity Form Fields

Dynamically populate Gravity Forms fields
// Populate Gravity Form Fields
add_filter( 'gform_field_value', 'at_populate_gf_fields', 10, 3 );
function at_populate_gf_fields( $value, $field, $name ) {
 
    $values = array(
        'field_one'   => 'value one',
        'field_two'   => 'value two',
        'field_three' => 'value three',
    );
 
    return isset( $values[ $name ] ) ? $values[ $name ] : $value;
    
}

Display Posts with Shortcode

Display Wordpress posts with shortcode
add_shortcode('shortcode-name', 'at_display_posts');
function at_display_posts() {
  
  $output = '';
  
  $args = array(
    'post_type'       => 'posts',
    'posts_per_page'  => -1,
  );
  
  $posts = get_posts($args);
  
  $output .= '<div class="at-posts-container">';
  
    foreach($posts as $p) {
      
      $output .= '<div class="at-post">';
      $output .= '<h2 class="post-title"><a href="' . get_permalink($p->ID) . '">' . $p->post_title . '</a></h2>';
      $output .= '</div>';
    

Modify WooCommerce Order Number

Modify WooCommerce Order Number
add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number', 1, 2);
function change_woocommerce_order_number( $order_id, $order ) {
    $prefix = 'prefix-';
    $suffix = '-suffix';
    return $prefix . $order->id . $suffix;
}

Add Stylesheet to Admin Page

Add stylesheet to Wordpress admin page
// Add stylesheet to alumni post type edit page
function admin_styles($hook) {
    
    $screen = get_current_screen();
    
    if ( $hook == 'post.php' && $screen->post_type != 'post-type-slug' ) {
        return;
    }
    
    wp_register_style( 'admin_stylesheet', get_stylesheet_directory_uri() . '/admin-styles.css', false, '1.0.0' );
    wp_enqueue_style( 'admin_stylesheet' );
    
}

add_action('admin_enqueue_scripts', 'admin_styles');

Add Read Only Field to ACF

Add Read Only field to ACF field options
// READ ONLY ACF FIELD SETTING
// Set up field setting
add_action('acf/render_field_settings', 'vi_read_only_render_field_settings');

function vi_read_only_render_field_settings( $field ) {
	
	acf_render_field_setting( $field, array(
		'label'			=> __('Read Only?'),
		'instructions'	=> '',
		'name'			=> 'read_only',
		'type'			=> 'true_false',
		'ui'			=> 1,
	), true);
	
}

/* Add Disabled Attribute if Setting is True */
add_filter('acf/prepare_field', 'vi_read_only_prepare_field');

function v

Add Options Page

Add options page to Wordpress dashboard settings
// Add Options Page
class viAddOptionsPage {

    private $options;
    private $opt_group;

    function __construct()
    {

        add_action( 'admin_menu', array( $this, 'register_options_page' ) );
        add_action( 'admin_init', array( $this, 'vi_admin_init') );

    }

    // Register page under settings
    function register_options_page()
    {
        add_options_page(
            __( 'VI Options', 'vi-custom' ), // Page Title
            __( 'VI Options', 'vi-custom' ), // Menu Tit

计算路径和是否存在

class Solution {
    public boolean hasPathSum(TreeNode root, int sum) {
        if (root == null) {
            return false;
        }
        // 注意这里不是sum==0,而是和当前元素值相等,因为如果sum==0的情况是在目标节点的下一层。
        if (root.left == null && root.right == null) {
            return sum == root.val;
        }
        return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);
    }
}

Add Custom Meta Box

Add custom meta box to Wordpress posts
// Add custom meta box to post
add_action( 'add_meta_boxes', 'new_meta_box' );
function new_meta_box() {
    add_meta_box(
        'new-meta-box',
         'New Meta Box',
        'new_meta_box_callback',
        'post' // Post Type Slug
    );
}
function new_meta_box_callback( $post ) {
   echo 'CONTENT HERE'; 
}

remove file from github with .gitignore

Se hizo un **commit y push** un directorio a github. 

Después de eso, modifiqué el archivo .gitignore agregando un directorio que debería ignorarse. 

Todo funciona bien, pero el directorio (ahora ignorado) permanece en github.

```git
git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master
```