/**
Runcode online
Ver: 1.1.1
tham khao https://fellowtuts.com/html-css/make-a-html-css-js-try-it-yourself-editor/
**/
add_shortcode('cf-run-code','cf_run_code');
function cf_run_code($args, $content){
//get_stylesheet_directory() . '/inc/shortcodes/cf_blog_posts.php';
//wp_enqueue_script( 'yourtheme-skip-link-focus-fix', get_template_directory_uri() . '/js/bootstrap.min.js', array(), THEME_VERSION, true );
//custom css
wp_register_style( 'cf-run-code-online', get_stylesheet_directory_uri() . '/assets/css/cf-run-code-online.css', 'all' );
wp_enqueue_style( 'cf-run-code-online' );
//custom script
wp_register_script('cf-run-code-online-script', get_stylesheet_directory_uri() . "/assets/js/cf-run-code-online.js", array('jquery'),'1.0.3',true);
wp_enqueue_script('cf-run-code-online-script');
//ajax url
wp_localize_script( 'cf-run-code-online-script', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
$result = '
';
return $result;
}
add_action('wp_ajax_load_code_from_id', 'load_code_from_id');
add_action('wp_ajax_nopriv_load_code_from_id', 'load_code_from_id');
function load_code_from_id() {
$code_id = (isset($_POST['code_id']))?esc_attr($_POST['code_id']) : '';
//echo $code_id;
/* $ids = (isset($_POST['product_ids']))?esc_attr($_POST['product_ids']) : '';
//echo $product_ids;
$product_ids = explode(',', $ids);
foreach ($product_ids as $product_id) {
WC()->cart->add_to_cart( intval($product_id), 1, 0, array(), array() );
// WC()->cart->add_to_cart( $product_id = 0, $quantity = 1, $variation_id = 0, $variation = array(), $cart_item_data = array() );
}
//return cart count
echo WC()->cart->cart_contents_count;*/
echo get_field( "html", $code_id ).'|'.get_field( "css", $code_id ).'|'.get_field( "js", $code_id );
die();
}
// add popup to theme
function add_to_theme(){
echo do_shortcode(
'[lightbox id="cf-save-code" width="600px" padding="20px"]
[block id="cf-save-code"]
[/lightbox]
[lightbox id="cf-email-code" width="600px" padding="20px"]
[block id="cf-email-code"]
[/lightbox]');
}
add_action('wp_footer', 'add_to_theme');
// sau khi người dùng gởi thông tin
add_action("wpcf7_before_send_mail", "wpcf7_do_something");
function wpcf7_do_something($WPCF7_ContactForm){
//Get current form
$wpcf7 = WPCF7_ContactForm::get_current();
// get current SUBMISSION instance
$submission = WPCF7_Submission::get_instance();
// Ok go forward
if ($submission) {
// get submission data
$data = $submission->get_posted_data();
switch ($WPCF7_ContactForm->id()) {
case 5479: // Tạo post luu code
break;
case 5480: // email code
/* $cf_post_id = $data['gs-id'];
write_log('cf_post_id = '.$cf_post_id);
$uploaded_files = $submission->uploaded_files();
if ($uploaded_files) {
foreach ($uploaded_files as $fieldName => $filepath) {
//write_log('fieldName = '.$fieldName);
//cf7 5.4
if (is_array($filepath)) {
//write_log('filepath = '.$filepath);
foreach ($filepath as $key => $value) {
//write_log('key='.$key);
$data = cf_nmr_create_attachment($value, $cf_post_id, $fieldName);
}
} else {
$data = cf_nmr_create_attachment($filepath, $cf_post_id, $fieldName);
}
}
} */
break;
default:
break;
}
}
}
?>
Test code html css javascript Online - Code & Coffe
Skip to content