admin_url( 'admin-ajax.php' ))); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'affinitomics_ajax_script' ); } function custom_restore_function($post_ID) { $the_key = get_option('af_key'); $af_cloud_url = get_option('af_cloud_url', ''); $url = get_permalink($post_ID); $request = curl_request($af_cloud_url . "/api/restore_resource?user_key=" . $the_key . '&uid=' . $post_ID . '&url=' . $url); } add_action('untrash_post', 'custom_restore_function'); /* Page Types to Apply Affinitomics */ $screens = array(); // if (get_option('af_post_type_affinitomics','true') == 'true') $screens[] = 'archetype'; if (get_option('af_post_type_posts','false') == 'true') $screens[] = 'post'; if (get_option('af_post_type_pages','false') == 'true') $screens[] = 'page'; if (get_option('af_post_type_products','false') == 'true') $screens[] = 'product'; if (get_option('af_post_type_projects','false') == 'true') $screens[] = 'project'; if (get_option('af_post_type_listings','false') == 'true') $screens[] = 'listing'; add_action('admin_menu', 'remove_extra_submenu_items'); function remove_extra_submenu_items() { global $submenu; unset($submenu["edit.php?post_type=archetype"][10]); unset($submenu["edit.php?post_type=archetype"][5]); } function af_verify_key(){ $the_key = get_option('af_key'); $af_cloud_url = get_option('af_cloud_url', ''); if (!isset($the_key) || $the_key == ""){ $request = curl_request($af_cloud_url . "/api/anon_key"); $response = json_decode($request, true); update_option( 'af_key' , $response['data']['anon_key'] ); } } function af_check_for_errors(){ $the_key = get_option('af_key'); $af_cloud_url = get_option('af_cloud_url', ''); $request = curl_request($af_cloud_url . "/check_for_errors?user_key=" . $the_key); $response = json_decode($request, true); update_option( 'af_errors' , $response['data']['af_errors'] ); update_option( 'af_error_code' , $response['data']['af_error_code'] ); } function af_verify_provider(){ update_option( 'af_cloud_url' , 'www.affinitomics.com' ); } /* Save Custom DATA */ function afpost_save_postdata() { af_verify_key(); af_verify_provider(); $post_ID = get_the_id(); $post_status = get_post_status($post_ID); // Collect descriptor terms from the post $these_descriptors = wp_get_post_terms( $post_ID, "descriptor" ); $descriptor_terms = array(); foreach ($these_descriptors as $descriptor) { array_push($descriptor_terms, $descriptor->name); } // Collect draw terms from the post $these_draws = wp_get_post_terms( $post_ID, "draw" ); $draw_terms = array(); foreach ($these_draws as $draw) { array_push($draw_terms, $draw->name); } // Collect distance terms from the post $these_distances = wp_get_post_terms( $post_ID, "distance" ); $distance_terms = array(); foreach ($these_distances as $distance) { array_push($distance_terms, $distance->name); } // implode the data $afpost_descriptors = implode(",", $descriptor_terms); $afpost_draw = implode(",", $draw_terms); $afpost_distance = implode(",", $distance_terms); // Save Meta DATA add_post_meta($post_ID, '_afpost_descriptors', $afpost_descriptors, true) or update_post_meta($post_ID, '_afpost_descriptors', $afpost_descriptors); add_post_meta($post_ID, '_afpost_draw', $afpost_draw, true) or update_post_meta($post_ID, '_afpost_draw', $afpost_draw); add_post_meta($post_ID, '_afpost_distance', $afpost_distance, true) or update_post_meta($post_ID, '_afpost_distance', $afpost_distance); // Affinitomic ID $afid = get_post_meta($post_ID, 'afid', true); // Categories String $cat_string = ''; // Save Data To Prefrent Cloud global $af_flag; if ($af_flag == 0) { $cat_string = ''; $categories = get_the_category($id); if ($categories) { $cats = array(); foreach($categories as $cat) { $cats[] = $cat->term_id; } $cat_string = implode(",", $cats); } $affinitomics = array( 'url' => get_permalink($post_ID), 'title' => get_the_title($post_ID), 'descriptors' => $afpost_descriptors, 'draws' => $afpost_draw, 'distances' => $afpost_distance, 'key' => get_option('af_key'), 'uid' => $post_ID, 'category' => $cat_string, 'status' => $post_status ); if ($afid) $affinitomics['afid'] = $afid; $af_cloudify_url = get_option('af_cloud_url') . '/api/affinitomics/cloudify/' . get_option('af_key') . '/'; $request = curl_request($af_cloudify_url, $affinitomics); $af = json_decode($request, true); if (isset($af['data']['objectId'])) { update_post_meta($post_ID, 'afid', $af['data']['objectId']); } } $af_flag = 1; } /* ---------------------------------------------------------------------- CUSTOM TAXONOMY ---------------------------------------------------------------------- */ // Register Custom Taxonomy Descriptor function descriptor_taxonomy() { $labels = array( 'name' => _x( 'Descriptors', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Descriptor', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Descriptor', 'text_domain' ), 'all_items' => __( 'All Descriptors', 'text_domain' ), 'parent_item' => __( 'Parent Descriptor', 'text_domain' ), 'parent_item_colon' => __( 'Parent Descriptor:', 'text_domain' ), 'new_item_name' => __( 'New Descriptor', 'text_domain' ), 'add_new_item' => __( 'Add New Descriptor', 'text_domain' ), 'edit_item' => __( 'Edit Descriptor', 'text_domain' ), 'update_item' => __( 'Update Descriptor', 'text_domain' ), 'separate_items_with_commas' => __( 'Descriptors are similar to Categories in Wordpress. Separate each Descriptor with commas. e.g. Summer Activities, Hobbies', 'text_domain' ), 'search_items' => __( 'Search descriptors', 'affinitomics' ), 'add_or_remove_items' => __( 'Add or remove descriptors', 'text_domain' ), 'choose_from_most_used' => __( 'Choose from the most used Descriptors', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); global $screens; register_taxonomy( 'descriptor', $screens, $args ); } // Hook into the 'init' action add_action( 'init', 'descriptor_taxonomy', 0 ); // Register Custom Taxonomy Draw function draw_taxonomy() { $labels = array( 'name' => _x( 'Positive Relationships (Draws)', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Draw', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Draw', 'text_domain' ), 'all_items' => __( 'All Draws', 'text_domain' ), 'parent_item' => __( 'Parent Draw', 'text_domain' ), 'parent_item_colon' => __( 'Parent Draw:', 'text_domain' ), 'new_item_name' => __( 'New Draw', 'text_domain' ), 'add_new_item' => __( 'Add New Draw', 'text_domain' ), 'edit_item' => __( 'Edit Draw', 'text_domain' ), 'update_item' => __( 'Update Draw', 'text_domain' ), 'separate_items_with_commas' => __( 'Syntax: Draws can have a magnitude from 1 to 5 written as a suffix, with each draw separated by a comma. If a magnitude is not present, a magnitude of one will be assumed. e.g. Cats5, Laser Pointer2', 'text_domain' ), 'search_items' => __( 'Search draws', 'affinitomics' ), 'add_or_remove_items' => __( 'Add or remove draws', 'text_domain' ), 'choose_from_most_used' => __( 'Choose from the most used Draws', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); global $screens; register_taxonomy( 'draw', $screens, $args ); } // Hook into the 'init' action add_action( 'init', 'draw_taxonomy', 0 ); // Register Custom Taxonomy Distance function distance_taxonomy() { $labels = array( 'name' => _x( 'Negative Relationships (Distances)', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Distance', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Distance', 'text_domain' ), 'all_items' => __( 'All Distances', 'text_domain' ), 'parent_item' => __( 'Parent Distance', 'text_domain' ), 'parent_item_colon' => __( 'Parent Distance:', 'text_domain' ), 'new_item_name' => __( 'New Distance', 'text_domain' ), 'add_new_item' => __( 'Add New Distance', 'text_domain' ), 'edit_item' => __( 'Edit Distance', 'text_domain' ), 'update_item' => __( 'Update Distance', 'text_domain' ), 'separate_items_with_commas' => __( 'Syntax: Distances can have a magnitude of 1 to 5, written as a suffix, with each distance separated by a comma. If a magnitude is not present, a magnitude of one will be assumed. e.g. Nickelback5, Canada2', 'text_domain' ), 'search_items' => __( 'Search distances', 'affinitomics' ), 'add_or_remove_items' => __( 'Add or remove Distance', 'text_domain' ), 'choose_from_most_used' => __( 'Choose from the most used Distances', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); global $screens; register_taxonomy( 'distance', $screens, $args ); } // Hook into the 'init' action add_action( 'init', 'distance_taxonomy', 0 ); /* ---------------------------------------------------------------------- Register "Archetype" post type ---------------------------------------------------------------------- */ // Register Custom Post Type function arche_type() { $labels = array( 'name' => __( 'Archetypes', 'Post Type General Name', 'text_domain' ), 'singular_name' => __( 'Archetype', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'Affinitomics™', 'text_domain' ), 'parent_item_colon' => __( 'Parent Archetype:', 'text_domain' ), 'all_items' => __( 'All Archetypes', 'text_domain' ), 'view_item' => __( 'View Archetype', 'text_domain' ), 'add_new_item' => __( 'Add New Archetype', 'text_domain' ), 'add_new' => __( 'New Archetype', 'text_domain' ), 'edit_item' => __( 'Edit Archetype', 'text_domain' ), 'update_item' => __( 'Update Archetype', 'text_domain' ), 'search_items' => __( 'Search Archetypes', 'text_domain' ), 'not_found' => __( 'No archetypes found', 'text_domain' ), 'not_found_in_trash' => __( 'No archetypes found in Trash', 'text_domain' ), ); $args = array( 'label' => __( 'archetype', 'text_domain' ), 'description' => __( 'Archetype information pages', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', 'post-formats', ), 'taxonomies' => array( 'descriptor', 'draw', 'distance' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'menu_icon' => plugins_url( 'affinitomics-favicon.png', __FILE__ ), 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', ); register_post_type( 'archetype', $args ); } // // Hook into the 'init' action add_action( 'init', 'arche_type', 0 ); /* ---------------------------------------------------------------------- RELATED POSTS SHORTCODE Examples: [afview], [afview limit="4"], [afview category_filter="50"] [afview limit=1 display_title="false"] ---------------------------------------------------------------------- */ //register shortcode add_shortcode("afview", "afview_handler"); //handle shortcode function afview_handler( $atts, $content = null ) { $afview_output = afview_function($atts); return $afview_output; } //process shortcode function afview_function($atts) { af_verify_key(); af_verify_provider(); global $screens; extract( shortcode_atts( array( 'affinitomics' => null, 'display_title' => 'true', 'limit' => 10, 'category_filter' => '' ), $atts ) ); // Start output // $afview_output = '