Author Archives: admin_vincent

Add meta box – editor for post custom meta

function wpdocs_register_meta_boxes() { add_meta_box( ‘meta-box-id’, __( ‘Backend Name’, ‘textdomain’ ), ‘wpdocs_my_display_callback’, ‘post_type’ ); } add_action( ‘add_meta_boxes’, ‘wpdocs_register_meta_boxes’ ); function wpdocs_my_display_callback( $post ) { // INPUT FIELDS GO HERE ?> <label>Year: <input type=”text” name=”inputName” value=”<?php echo get_post_meta(get_the_ID(), ‘meta_key’)[0]; ?>” /></label> <?php } /** * Save meta box content. * * @param int $post_id Post ID */ […]

MySQLi connection

$link = mysqli_connect($db_host, $username, $password, $database); if (!$link) { echo “Error: Unable to connect to MySQL.” . PHP_EOL; echo “Debugging errno: ” . mysqli_connect_errno() . PHP_EOL; echo “Debugging error: ” . mysqli_connect_error() . PHP_EOL; exit; } echo “Success: A proper connection to MySQL was made! The my_db database is great.” . PHP_EOL; echo “Host information: […]

Add payment gateway for certain users only

add_filter( ‘woocommerce_available_payment_gateways’, ‘hide_payment_gateway’ ); function hide_payment_gateway( $available_gateways ) { global $woocommerce; if ( isset( $available_gateways[‘cod’] ) && !current_user_can(‘administrator’) && !current_user_can(‘staff’) && !current_user_can(‘editor’) ) { unset( $available_gateways[‘cod’] ); } return $available_gateways; }

Custom columns content

add_action( ‘manage_colourmedia_column’, ‘colourmedia_columns’, 10, 2 ); function manage_colourmedia_columns( $column, $post_id ) { global $post; $terms = get_post_meta( $post_id ); switch( $column ) { case ‘thumbnail’ : $url = get_the_post_thumbnail_url($post_id); printf( ‘<img src=”‘.$url.'” style=”width:100px”/>’ ); break; case ‘city’ : printf($terms[‘City’][0]); break; case ‘category’ : $cat_list = wp_get_post_terms($post->ID, ‘category’, array(“fields” => “names”)); foreach($cat_list as &$category){ echo ‘<a […]