Skip to content

Instantly share code, notes, and snippets.

View stevenroh's full-sized avatar
🇨🇭

Steven Roh stevenroh

🇨🇭
View GitHub Profile
@stevenroh
stevenroh / functions.php
Created May 27, 2020 10:01
Custom slack_wpcf7_submit_message
<?php
/* $message — Default message to send to Slack
$form — Form object
$result — Array of result
*/
function custom_cf_7( $message, $form, $result ) {
return "OK" . json_encode($form) . json_encode($result); // Customize message here
}
add_filter( 'slack_wpcf7_submit_message', 'custom_cf_7', 10, 3 );
@stevenroh
stevenroh / functions.php
Created April 7, 2020 08:40
Display map
<?php /* Template Name: Carte */
function page_content() {
?>
<div class="map">
<?php
$args = array(
'post_type' => 'poi'
);
$the_query = new WP_Query( $args );
@stevenroh
stevenroh / functions.php
Last active November 9, 2021 09:45
Disable gutenberg/new editor for CPT
<?php
add_filter('use_block_editor_for_post_type', 'prefix_disable_gutenberg', 10, 2);
function prefix_disable_gutenberg($current_status, $post_type) {
if ($post_type === 'cpt1') return false;
if ($post_type === 'cpt2') return false;
if ($post_type === 'cpt3') return false;
return $current_status;
}
<?php
/* Template Name: Test */
/**
* Genesis custom loop
*/
function be_custom_loop() {
global $post;
// arguments, adjust as needed
@stevenroh
stevenroh / functions.php
Last active September 11, 2019 15:04
Hide price for product that costs zero
<?php
// Hide price for product that costs zero
function rohs_hide_zero_price($price_html, $product){
if($product->get_price()>0){
return $price_html;
}
return '';
}
add_filter( 'woocommerce_get_price_html','rohs_hide_zero_price',10,2);
?>
@stevenroh
stevenroh / functions.php
Created September 11, 2019 14:59
Disable add to cart for product where price is 0
<?php
/* Disable add to cart for product where price is 0 */
function rohs_is_purchasable( $purchasable, $product ){
if( $product->get_price() == 0 )
$purchasable = false;
return $purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'rohs_is_purchasable', 10, 2 );
?>
@stevenroh
stevenroh / functions.php
Created September 3, 2019 15:05
WordPress import media from wp_content/uploads
/* Import media present on the wp_uploads folder */
// https://codex.wordpress.org/Function_Reference/wp_insert_attachment
if($_GET['rohs_run']) {
echo 'RUN';
// Get WP uploads dir
$wp_upload_dir = wp_upload_dir();
// Init recursive Obj
$di = new RecursiveDirectoryIterator($wp_upload_dir['path'], RecursiveDirectoryIterator::SKIP_DOTS);
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
@stevenroh
stevenroh / string_format_read_stack_hex.md
Created May 11, 2019 16:17
String format read stack in hex

./binary "%08x ...." // ________ ./binary "%#010x..." // 0x________

@stevenroh
stevenroh / buffer_overflow_shell_open.md
Created May 11, 2019 16:15
Buffer overflow + keep shell opened

(python -c "print 'A'*40 + '\xef\xbe\xad\xde'"; cat) | ./bin

@stevenroh
stevenroh / axios-catch-error.js
Created January 28, 2019 10:02 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
axios.put(this.apiBaseEndpoint + '/' + id, input)
.then((response) => {
// Success
})
.catch((error) => {
// Error
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
// console.log(error.response.data);