WordPress.org

Ready to get started?Download WordPress

Forums

Custom Author Byline (7 posts)

  1. NelsR
    Member
    Posted 1 year ago #

    So I'm trying to use the plugin custom author byline. However, when I use the plugin suffusion, it doesn't work. According to the person that make suffusion it should be using the filter "get_the_author". However, when I do that it stops working completely. When I leave the plugin with the default following code, it doesn't change on the homepage but only in the wordpress dashboard. Help!

    <?php
    /*
    Plugin Name: Custom Author Byline
    Plugin URI: http://seoserpent.com/wordpress/custom-author-byline
    Version: 1.2
    License: GPL2
    Description: Allows you to add a custom author name to the byline other than the logged in user writing/editing the post/page.
    Usage:  If the author of your post or page entry is different than your logged in user and you don't want to have to create a separate user account, just add the name as you'd like it to appear to the Custom Author Byline panel in the post/page editor.  Easy!
    Author: Marty Martin
    Author URI: http://seoserpent.com/wordpress/
    */
    
    // Replaces the_author() output with your custom entry or return the logged in user if there is no custom entry
    function custom_author_byline( $author ) {
       global $post;
       $custom_author = get_post_meta($post->ID, 'author', TRUE);
       if($custom_author)
          return $custom_author;
       return $author;
    }
    add_filter('get_the_author_','custom_author_byline');
    
    // Replaces the_author_link() output with your custom entry or return the logged in user if there is no custom entry
    function custom_author_uri( $author_uri ) {
       //global $authordata;
       global $post, $authordata;
       $custom_author_uri = get_post_meta($post->ID, 'uri', TRUE);
       if($custom_author_uri)
          return $custom_author_uri;
       return $author_uri;
    }
    add_filter( 'author_link', 'custom_author_uri' );
    
    // Add custom write panel to post editor page (props to Spencer at Function http://wefunction.com/2008/10/tutorial-creating-custom-write-panels-in-wordpress/)
    $cab_new_meta_boxes =
       array(
          "author" => array(
             "name" => "author",
             "std" => "",
             "description" => "Add a custom author name (other than your own) to override giving yourself credit for this post."
          ),
          "author_uri" => array(
             "name" => "uri",
             "std" => "",
             "description" => "Add a link to your author's webpage (internal or external)."
          )
       );
    
    function cab_new_meta_boxes() {
       global $post, $cab_new_meta_boxes;
    
       foreach($cab_new_meta_boxes as $meta_box) {
          $meta_box_value = get_post_meta($post->ID, $meta_box['name'], true);
    
          if($meta_box_value == "") {
             $meta_box_value = $meta_box['std'];
          }
          echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
          echo'<p><input type="text" name="'.$meta_box['name'].'" value="'.$meta_box_value.'" size="55" /><br />';
          echo'<label for="'.$meta_box['name'].'">'.$meta_box['description'].'</label></p>';
       }
    }
    
    function cab_create_meta_box() {
       global $theme_name;
       if ( function_exists('add_meta_box') ) {
          add_meta_box( 'cab-new-meta-boxes', 'Custom Author Byline', 'cab_new_meta_boxes', 'post', 'normal', 'high' );
          add_meta_box( 'cab-new-meta-boxes', 'Custom Author Byline', 'cab_new_meta_boxes', 'page', 'normal', 'high' );
          // You can edit the below to add Custom Post Type support for the plugin.  Uncomment the line and replace 'custom_post_type' with your custom post type slug
          // You can instead add the below line to your theme's functions.php to "future-proof" your changes from being overwritten by upgrades to this plugin
          //add_meta_box( 'cab-new-meta-boxes', 'Custom Author Byline', 'cab_new_meta_boxes', 'custom_post_type', 'normal', 'high' );
       }
    }
    
    function cab_save_postdata( $post_id ) {
       global $post, $cab_new_meta_boxes;
    
       foreach($cab_new_meta_boxes as $meta_box) {
          if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
             return $post_id;
          }
    
          if ( 'page' == $_POST['post_type'] ) {
             if ( !current_user_can( 'edit_page', $post_id ))
             return $post_id;
          } else {
             if ( !current_user_can( 'edit_post', $post_id ))
             return $post_id;
          }
    
          $data = $_POST[$meta_box['name']];
    
          if(get_post_meta($post_id, $meta_box['name']) == "")
             add_post_meta($post_id, $meta_box['name'], $data, true);
          elseif($data != get_post_meta($post_id, $meta_box['name'], true))
             update_post_meta($post_id, $meta_box['name'], $data);
          elseif($data == "")
          delete_post_meta($post_id, $meta_box['name'], get_post_meta($post_id, $meta_box['name'], true));
       }
    }
    add_action('admin_menu', 'cab_create_meta_box');
    add_action('save_post', 'cab_save_postdata');
    
    ?>
  2. Spencer Cameron
    Member
    Posted 1 year ago #

    What do you mean by, "It doesn't work.". Can you be more specific? :)

    Also, if you are in a position to go into debug mode, that could be beneficial. There may be some error messages relating to your issue that could be exposed that way.

    In your wp-config.php:
    define( 'WP_DEBUG', true );

  3. NelsR
    Member
    Posted 1 year ago #

    When you go to the webpage, it shows the original post author associated with the user account. It's supposed to use a custom author name and URL that's defined under the post options. It shows up on the actual dashboard backed but not on the site itself.

  4. Spencer Cameron
    Member
    Posted 1 year ago #

    Just taking a cursory glance through the code, one thing that stands out is add_filter is being used incorrectly.

    The filter should be written like this:
    add_filter( 'the_author', 'custom_author_byline' );

    Not this:
    add_filter( 'get_the_author_', 'custom_author_byline' );

    That's at least one problem that can be corrected. See where that gets you. :)

  5. NelsR
    Member
    Posted 1 year ago #

    I changed that and it still doesn't work

    http://kcstimes.com/wp-content/uploads/2012/09/Untitled-1.png

  6. Spencer Cameron
    Member
    Posted 1 year ago #

    Hm. Works for me. Can you post the code from your single.php? Also, the custom field is named author, right?

  7. Spencer Cameron
    Member
    Posted 1 year ago #

    I should actually be more specific. Not necessarily single.php, as I believe you said it's on the homepage, but rather whatever code is actually attempting to output the author name.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.