public function run($atts)
 {
     extract(shortcode_atts($this->arguments, $atts));
     if ($slug == "") {
         return;
     }
     if (null === $parent) {
         $parent = get_the_ID();
     }
     $post_link_manager = new SP_Post_Link_Manager();
     return $post_link_manager->generate_children_list($slug, $parent, $link, $excerpt, 'b', $image);
 }
 public function widget($args, $instance)
 {
     // Setup widget vars
     $instance = array_merge($this->default_vars, $instance);
     // Don't output anything if there's no postlink
     if ($instance['postlink'] == '') {
         return;
     }
     // Don't output the widget on the frontpage if the frontpage show_on_front is posts
     if (is_front_page() && false === is_page()) {
         return;
     }
     // Use custom post of parent is null
     if (null === $instance['parent']) {
         $instance['parent'] = get_the_ID();
     }
     // Load the PTL
     $post_type_link_manager = new SP_Connection_Manager();
     $connection = $post_type_link_manager->get_connection($instance['postlink']);
     // Return if there is no connection
     if (null == $connection) {
         return;
     }
     // Only display widget on pages where the post type is the $instance['parent'] equals the Connection post type
     if ($connection->get_parent() != get_post_type($instance['parent'])) {
         return;
     }
     // Setup the post link manager
     $post_link_manager = new SP_Post_Link_Manager();
     // Generate the widget content
     $widget_content = $post_link_manager->generate_children_list($connection->get_slug(), $instance['parent'], $instance['link'], $instance['excerpt'], 'b', $instance['thumbnail']);
     // Don't ouput the widget if there is no widget content
     if ('' == $widget_content) {
         return;
     }
     // Output the widget
     echo $args['before_widget'];
     echo $args['before_title'] . $instance['title'] . $args['after_title'] . "\n";
     echo $widget_content;
     echo $args['after_widget'];
 }
 /**
  * the_content filter that will add linked posts to the bottom of the main post content
  *
  * @param $content
  *
  * @return string
  */
 public function run($content)
 {
     /**
      * Wow, what's going on here?! Well, setup_postdata() sets a lot of variables but does not change the $post variable.
      * All checks return the main queried ID but we want to check if this specific filter call is the for the 'main' content.
      * The method setup_postdata() does global and set the $id variable, so we're checking that.
      */
     global $id;
     // Only run on single
     if (!is_singular() || !is_main_query() || $id != get_queried_object_id()) {
         return $content;
     }
     $ptl_manager = new SP_Connection_Manager();
     // Add a meta query so we only get relations that have the PM_PTL_APDC or PM_PTL_APDP set to true (1)
     $args = array('meta_query' => array('relation' => 'OR', array('key' => SP_Constants::PM_PTL_APDC, 'value' => '1'), array('key' => SP_Constants::PM_PTL_APDP, 'value' => '1')));
     // Get the connections
     $relations = $ptl_manager->get_connections($args);
     // Check relations
     if (count($relations) > 0) {
         // Store children and parents
         $children_relations = array();
         $parent_relations = array();
         // Post Link Manager
         $pl_manager = new SP_Post_Link_Manager();
         // Current post ID
         $post_id = get_the_ID();
         // Loop relations
         foreach ($relations as $relation) {
             // Check if this relation allows children links to show
             if ('1' === $relation->get_after_post_display_children()) {
                 $children_relations[] = $relation;
             }
             // Check if this relation allows parents links to show
             if ('1' === $relation->get_after_post_display_parents()) {
                 $parent_relations[] = $relation;
             }
         }
         // Are the relations that want to show linked child posts
         if (count($children_relations) > 0) {
             // Opening the wrapper div
             $content .= "<div class='pc-post-children'>\n";
             foreach ($children_relations as $children_relation) {
                 // Generate list and append is there's content
                 $children_list = $pl_manager->generate_children_list($children_relation->get_slug(), $post_id, true, $children_relation->get_after_post_display_children_excerpt(), 'b', $children_relation->get_after_post_display_children_image());
                 if ('' != $children_list) {
                     $content .= "<h3>" . $children_relation->get_title() . "</h3> \n";
                     $content .= $children_list;
                 }
             }
             // Close the wrapper div
             $content .= "</div>\n";
         }
         // Are the relations that want to show linked parent posts
         if (count($parent_relations) > 0) {
             // Opening the wrapper div
             $content .= "<div class='pc-post-parents'>\n";
             foreach ($parent_relations as $parent_relation) {
                 // Get the linked posts
                 $pc_posts = $pl_manager->get_parents($parent_relation->get_slug(), $post_id);
                 if (count($pc_posts) > 0) {
                     $content .= $this->create_post_list($parent_relation->get_slug(), $parent_relation->get_title(), $pc_posts, false, false);
                 }
             }
             // Close the wrapper div
             $content .= "</div>\n";
         }
     }
     return $content;
 }