'add-link', 'description' => __('A Widgets that helps you add links to your site.', 'add-link') ); /* Widget control settings. */ $control_ops = array( 'width' => 400, 'id_base' => 'add-link-widget' ); /* Create the widget. */ $this->WP_Widget( 'add-link-widget', __('Add Link Widget', 'add-link'), $widget_ops, $control_ops ); } /** * How to display the widget on the screen. */ function widget( $args, $instance ) { global $current_user,$wpdb; extract( $args ); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', $instance['title_label'] ); $message = $instance['message']; $link_label = $instance[ 'link_label' ]; $name_check = $instance[ 'name_check' ]; $name_label = $instance[ 'name_label' ]; $description_check = $instance[ 'description_check' ]; $description_label = $instance[ 'description_label' ]; $feed_check = $instance[ 'feed_check' ]; $feed_label = $instance[ 'feed_label' ]; $notes_check = $instance[ 'notes_check' ]; $notes_label = $instance[ 'notes_label' ]; $password_check = $instance[ 'password_check' ] ; $password_label = $instance[ 'password_label' ]; $password = $instance[ 'password' ]; $button_label = $instance[ 'button_label' ]; $link_category = $instance[ 'link_category' ]; $permissions = $instance[ 'permissions' ]; $owner_view_check = $instance[ 'owner_view_check' ]; $owner_view_label = $instance[ 'owner_view_label' ]; $owner_delete_check = $instance[ 'owner_delete_check' ]; $limit = $instance[ 'limit' ]; $form_creator = $instance[ 'form_creator']; // PERMISSIONS if($permissions == "login"): get_currentuserinfo(); if(!$current_user->ID) return; // permission applies only for MU // if you are registed with the blogs endif; if($permissions == "registered") : get_currentuserinfo(); if(!$current_user->ID) return; $user_blogs = get_blogs_of_user($current_user->ID); $user_blogs_ids = array(); foreach($user_blogs as $user_blog): $user_blogs_ids[] = $user_blog->userblog_id; endforeach; if(!is_array($user_blogs_ids)) return; $current_site = wpmu_current_site(); if(!in_array($current_site->blog_id, $user_blogs_ids)) return; endif; // check the password /* * ADD LINK ******************************************************/ // making sure that the form was submited from here... $nonce = $_POST[$widget_id]; if($limit): $query = "SELECT COUNT(*) FROM ". $wpdb->links ." WHERE `link_owner` = ".$current_user->ID; $link_count = $wpdb->get_var($query); if( $limit > $link_count ): $procced = true; endif; else: $procced = true; endif; if(wp_verify_nonce($nonce, $widget_id) ): if($password_check): if( $_POST['add-link-widget-password'] != $password ): echo "
".__('Sorry, your password is wrong try again.', 'add-link')."
"; $procced = false; else: $procced = true; endif; endif; if($procced): /* include wordpress so that it has the wp_insert_link function ) */ $root = preg_replace('/wp-content.*/', '', __FILE__); require_once($root . 'wp-config.php'); require_once($root . 'wp-admin/includes/admin.php'); // store the data into the database $link[ 'link_url' ] = (isset($_POST['add-link-widget-link']) ? esc_url(esc_html($_POST['add-link-widget-link'])) : ""); $link[ 'link_name' ] = (isset($_POST['add-link-widget-name']) ? esc_html($_POST['add-link-widget-name']) : ""); $link[ 'link_description' ] = (isset($_POST['add-link-widget-description']) ? esc_html($_POST['add-link-widget-description']) : ""); $link[ 'link_rss' ] = (isset($_POST['add-link-widget-feed']) ? esc_url(esc_html($_POST['add-link-widget-feed'])) : ""); $link[ 'link_notes' ] = (isset($_POST['add-link-widget-notes']) ? esc_html($_POST['add-link-widget-notes']) : ""); $link[ 'link_owner' ] = (isset($current_user->ID) ? $current_user->ID : $form_creator ); wp_insert_link( $link ); $link_count++; unset($_POST); echo "".__('Thank you for submitting the form', 'add-link')."
"; endif; // don't add the link to the database endif; /* * DELETE LINK ******************************************************/ if($owner_delete_check && $_GET['add-link-action'] == "delete"): if(is_numeric($_GET['id'])): // making sure that you can only delete your own links $link_owner = $wpdb->get_var($wpdb->prepare("SELECT link_owner FROM $wpdb->links WHERE link_id = %s", $_GET['id'])); if($link_owner == $current_user->ID): // last check I primiss if(wp_verify_nonce($_GET['nonce'], "delete_add-link_".$_GET['id'])): // go ahead delete link $root = preg_replace('/wp-content.*/', '', __FILE__); require_once($root . 'wp-config.php'); require_once($root . 'wp-admin/includes/admin.php'); wp_delete_link( $_GET['id'] ); $link_count--; endif; endif; endif; endif; // link was deleted /* Before widget (defined by themes). */ echo $before_widget; if( $limit > $link_count || !$limit): /* Display the widget title if one was input (before and after defined by themes). */ if ( $title ) echo $before_title . $title . $after_title; if($message) echo ""; ?> $owner_view_label"; $query = "SELECT * FROM ". $wpdb->links ." WHERE `link_owner` = ".$current_user->ID; $links = $wpdb->get_results($query); ?>$link->link_description
": ""); ?> link_notes ? "$link->link_notes
": ""); ?>
style="display:none;" >
id="get_field_id( $type.'_check' ); ?>" name="get_field_name( $type.'_check' ); ?>" /> style="display:none;" >