Skip to content

Instantly share code, notes, and snippets.

@woodwardtw
Created May 19, 2022 19:35
Show Gist options
  • Save woodwardtw/9f72d75a67107c840c56fd37e360abad to your computer and use it in GitHub Desktop.
Save woodwardtw/9f72d75a67107c840c56fd37e360abad to your computer and use it in GitHub Desktop.
for a gravity form with the ID of 1, adds a URL to feedwordpress assuming the fields are in the order presented
add_action( 'gform_after_submission_1', 'fwp_gf_url_adder', 10, 2 );
function fwp_gf_url_adder($entry, $form){
$url = rgar( $entry, '1' );
$name = rgar( $entry, '2');
$cat = rgar($entry, '3');
$linkdata = array("link_url" => $url,
// varchar, the URL the link points to
"link_name" => $name,
// varchar, a URL of an associated RSS feed
"link_rss" => $url,
// int, the term ID of the link category. if empty, uses default link category
//remember these cat ids are for the link categories NOT post cats, set the id as a value in gf
"link_category" => (int)$cat
);
if (!function_exists('wp_insert_link')) {
include_once (ABSPATH . '/wp-admin/includes/bookmark.php');
}
wp_insert_link($linkdata, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment