ID ) ) $post_id = absint( $post->ID ); else $post_id = 0; echo '
'; $company_ids = array(); if ( $post_id > 0 ) { $html = ''; $companies = maybe_unserialize( get_post_meta( $post_id, 'angellist-companies', true ) ); if ( ! empty( $companies ) && is_array( $companies ) ) { $num_companies = count( $companies ); for ( $i=0; $i < $num_companies; $i++ ) { $company = $companies[$i]; if ( empty( $company ) || ! array_key_exists( 'id', $company ) || ! array_key_exists( 'name', $company ) ) continue; $company['id'] = absint( $company['id'] ); if ( in_array( $company['id'], $company_ids ) ) continue; $company_ids[] = $company['id']; $html .= '
  • ' . esc_html( $company['name'] ); $html .= ''; $html .= ''; $html .= '
  • '; unset( $company ); } } if ( $html ) echo '
      ' . $html . '
    '; else echo '

    ' . esc_html( _x( 'No companies stored.', 'No AngelList companies associated with this post.', 'angellist' ) ) . '

    '; unset( $companies ); unset( $html ); } if ( $post_id < 1 ) echo ''; echo '
    '; echo ''; } /** * Save companies added and arranged in the AngelList meta box * If AngelList meta box is not present then nonce will not be present and the function will return. * * @since 1.0 * @param int post_id post identifier */ public function process_saved_data( $post_id ) { // do not process on autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; $post_id = absint( $post_id ); if ( $post_id < 1 || wp_is_post_revision( $post_id ) != false ) return; // verify the request came from the meta box by checking for our nonce if ( ! array_key_exists( AngelList_Post_Meta_Box::NONCE, $_POST ) || ! wp_verify_nonce( $_POST[AngelList_Post_Meta_Box::NONCE], plugin_basename(__FILE__) ) ) return; // check permissions if ( ! current_user_can( 'edit_post', $post_id ) ) return; /* Is the post box hidden? * A bit tricky since we might want to populate data so it's visible and not disabled when they remove the post box from their hidden list * If we are able to detect the box was never shown then stop processing. Especially if we were thinking about processing tags separately. */ $hidden_post_boxes = maybe_unserialize( get_user_option( 'metaboxhidden_post' ) ); if ( ! empty( $hidden_post_boxes ) && is_array( $hidden_post_boxes ) && in_array( AngelList_Post_Meta_Box::BASE_ID, $hidden_post_boxes, true ) ) return; unset( $hidden_post_boxes ); $companies = array(); if ( array_key_exists( 'angellist-company', $_POST ) && is_array( $_POST['angellist-company'] ) ) { $processed_company_ids = array(); foreach ( $_POST['angellist-company'] as $company ) { if ( ! isset( $company['id'] ) || ! isset( $company['name'] ) ) continue; $company_id = absint( $company['id'] ); if ( $company_id < 1 || in_array( $company_id, $processed_company_ids, true ) ) continue; $companies[] = array( 'id' => $company_id, 'name' => trim( $company['name'] ) ); $processed_company_ids[] = $company_id; unset( $company_id ); } unset( $processed_company_ids ); } update_post_meta( $post_id, 'angellist-companies', $companies ); } /** * Clear the transient cache when postmeta updated with new values * * @since 1.0 * @see update_metadata() * @param $meta_id meta_id value from database row * @param int $post_id post identifier * @param string $meta_key the key of the updated field * @param string $meta_value the new value */ public function clear_cache( $meta_id, $post_id, $meta_key, $meta_value ) { if ( $meta_key !== 'angellist-companies' ) return; $post_id = absint( $post_id ); if ( $post_id < 1 ) return; if ( ! class_exists( 'AngelList_Content' ) ) include_once( dirname(__FILE__) . '/content.php' ); // key differs based on is_ssl boolean value. trigger both foreach ( array( true, false ) as $ssl ) { delete_transient( AngelList_Content::cache_key( $post_id, $ssl ) ); } } /** * Display help documentation in edit and add post screens * Hide help documentation if user has hidden the referenced metabox at the time of pageload * * @since 1.0 */ public function add_help_tab() { $screen = get_current_screen(); $hidden_post_boxes = maybe_unserialize( get_user_option( 'metaboxhidden_post' ) ); // do not display help tab if meta box hidden if ( ! empty( $hidden_post_boxes ) && is_array( $hidden_post_boxes ) && in_array( AngelList_Post_Meta_Box::BASE_ID, $hidden_post_boxes, true ) ) return; unset( $hidden_post_boxes ); $screen->add_help_tab( array( 'id' => AngelList_Post_Meta_Box::BASE_ID . '-help', 'title' => 'AngelList', 'content' => '

    ' . esc_html( __( 'Search for a company by name.', 'angellist' ) ) . '

    ' . esc_html( __( 'Select a matching company from the result list.', 'angellist' ) ) . '

    ' . esc_html( __( 'Rearrange companies in the order you would like them to appear in your post by dragging a company name to its new position.', 'angellist' ) ) . '

    ' . esc_html( sprintf( __( 'Remove a company from the list by clicking the %s button.', 'angellist' ), 'X' ) ) . '

    ' ) ); } } ?>