Skip to content

Instantly share code, notes, and snippets.

add_action( 'wpcf7_before_send_mail', 'my_activtrail_cf7_integration' );
function my_activtrail_cf7_integration( $cf7 ) {
$form_id = $_POST['_wpcf7'];
if ($form_id == XXX || $form_id == YYY):
$first_name = $_POST['first_name']; // get form data
...
// Do Something;
endif;
}
@hannit
hannit / dropzone-integration.js
Created March 22, 2017 07:54
add_dropzone_to_form
Dropzone.options.dropzoneWordpressForm = {
acceptedFiles: "image/*", // all image mime types
maxFiles: 5, // max allowed upload
uploadMultiple: false,
maxFilesize: 5, // 5 MB
//addRemoveLinks: true,
//dictRemoveFile: 'X (remove)',
init: function() {
this.on("sending", function(file, xhr, formData) {
formData.append("name", "value"); // Append all the additional input data of your form here!
@hannit
hannit / import_youtube_playlists
Last active February 28, 2017 07:27
Import youtube playlist and videos as CPT - Needs optimization
// Get all playlists in the channel
function bio_youtube_get_playlists() {
$lists = array();
$key = 'Youtube-API-Key';
$channel = 'Channel-ID';
$url = "https://www.googleapis.com/youtube/v3/playlists?key=$key&channelId=$channel&part=snippet,id&order=date&maxResults=20";
$data = file_get_contents($url);
if (!empty($data)) {
$data_struct = json_decode($data);
if (is_array($data_struct->items)) {
add_action('wp_login','user_last_login', 0, 2);
function user_last_login($login, $user) {
$user = get_user_by('login',$login);
$now = time();
update_usermeta( $user->ID, 'user_last_login', $now );
}
function get_videos_from_youtube_api($num) {
if ( false === ( $data = get_transient( 'grafa-youtube-result' ) ) ) {
$key = 'Youtube-Key';
$channel = 'Channel-ID';
// $url = "https://www.googleapis.com/youtube/v3/playlistItems?key=$key&playlistId=$channel&part=snippet,id&order=date&maxResults=20";
$url = "https://www.googleapis.com/youtube/v3/search?key=$key&channelId=$channel&part=snippet,id&order=date&maxResults=20";
$data = file_get_contents($url);
set_transient( 'grafa-youtube-result', $data, 4 * HOUR_IN_SECONDS );
function get_user_image($user) {
$img = get_field('author_image', 'user_'.$user->id);
if (!empty($img)) {
$img = wp_get_attachment_image($img['ID'], 'user_avatar');
} else {
$img = get_avatar( $user->ID, 130);
}
return $img;
}
@hannit
hannit / add_quickedit_column.php
Created November 16, 2016 04:15
Add meta fields to quick edit
add_action( 'quick_edit_custom_box', 'display_custom_quickedit_featured', 10, 2 );
function display_custom_quickedit_featured( $column_name, $post_type ) {
static $printNonce = TRUE;
if ( $printNonce ) {
$printNonce = FALSE;
wp_nonce_field( plugin_basename( __FILE__ ), 'post_edit_nonce' );
}
?>
@hannit
hannit / add_tax.php
Created October 20, 2016 04:23
Add TAX
if ( ! function_exists( 'nok_area_type' ) ) {
// Register Custom Taxonomy
function nok_area_type() {
$labels = array(
'name' => _x( 'Area Types', 'Taxonomy General Name', 'nok' ),
'singular_name' => _x( 'Area Type', 'Taxonomy Singular Name', 'nok' ),
'menu_name' => __( 'Area Type', 'nok' ),
'all_items' => __( 'All Items', 'nok' ),
@hannit
hannit / add_cpt.php
Created October 20, 2016 04:22
ADD CPT code
function nok_add_attarctions_cpt() {
$labels = array(
'name' => _x( 'Attractions', 'Post Type General Name', 'nok' ),
'singular_name' => _x( 'Attraction', 'Post Type Singular Name', 'nok' ),
'menu_name' => __( 'Attractions', 'nok' ),
'name_admin_bar' => __( 'Attraction', 'nok' ),
'archives' => __( 'Item Archives', 'nok' ),
'parent_item_colon' => __( 'Parent Item:', 'nok' ),
'all_items' => __( 'All Items', 'nok' ),