Plugin Directory

Changeset 3091546


Ignore:
Timestamp:
05/23/2024 01:54:07 PM (23 months ago)
Author:
skyword
Message:

Coauthors better compatibility, attribute images and posts, both in WP database and Coauthors metadata

Location:
skyword-publishing-api/tags/1.1.2/php/routes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skyword-publishing-api/tags/1.1.2/php/routes/class-skyword-authors.php

    r3090934 r3091546  
    166166                $retval = $coauthors_plus->guest_authors->create( $guest_author );
    167167                if ( is_wp_error( $retval ) ) {
    168                     $author = $coauthors_plus->guest_authors->get_guest_author_by( 'user_login', $data['email'] );
     168                    if ($options['skyword_coauthors_friendly_slugs']) {
     169                        $author = $coauthors_plus->guest_authors->get_guest_author_by( 'user_login', $this->generate_author_slug($data));
     170                    } else {
     171                        $author = $coauthors_plus->guest_authors->get_guest_author_by( 'user_login', $newUsername );
     172                    }
    169173                    if ( null !== $author ) {
    170174                        $userId = $author->ID;
  • skyword-publishing-api/tags/1.1.2/php/routes/class-skyword-images.php

    r3090934 r3091546  
    155155
    156156    function create_image($request) {
     157        global $coauthors_plus;
    157158        $login = $this->authenticate($request);
    158159        if ( 'success' !== $login['status'] ) {
     
    165166        $type        = 'image/' . substr($data['filename'], strpos($data['filename'], '.') + 1);
    166167        // Yoast SEO plugin requires 'image/jpeg' and will not accept 'image/jpg'
     168        if (is_multisite()) {
     169            $activePlugins = (array) get_site_option('active_sitewide_plugins', array());
     170            $activePlugins = array_keys($activePlugins);
     171        } else {
     172            $activePlugins = (array) get_option('active_plugins', array());
     173        }
    167174        if ( in_array( 'wordpress-seo/wp-seo.php', $activePlugins, true ) ) {
    168175            if ($type === 'image/jpg') {
     
    192199        if ( null !== $data['author'] && is_numeric( trim( $data['author'] ) ) ) {
    193200            $attachment['post_author'] = (int)$data['author'];
    194         }
    195 
     201        } else if ( null !== $data['author'] && null !== $coauthors_plus ) {
     202            $data['author'] = str_replace( 'guest-', '', $data['author'] );
     203            $author          = $coauthors_plus->guest_authors->get_guest_author_by( 'ID', $data['author'] );
     204            $authorTerm      = $coauthors_plus->update_author_term( $author );
     205            $attachment['post_author'] = (int)$data['author'];
     206        }
    196207
    197208        $id = wp_insert_attachment( $attachment, $upload['file'], $postId );
     209        if ( null !== $data['author'] && null !== $coauthors_plus ) {
     210            wp_set_object_terms( $id, $authorTerm->slug, $coauthors_plus->coauthor_taxonomy, true );
     211        }
    198212        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
    199213
  • skyword-publishing-api/tags/1.1.2/php/routes/class-skyword-posts.php

    r3079629 r3091546  
    393393        if ( null !== $data['author'] && is_numeric( trim( $data['author'] ) ) ) {
    394394            $newPost['post_author'] = (int)$data['author'];
     395        } else if ( null !== $data['author'] && null !== $coauthors_plus ) {
     396            $data['author'] = str_replace( 'guest-', '', $data['author'] );
     397            $author          = $coauthors_plus->guest_authors->get_guest_author_by( 'ID', $data['author'] );
     398            $authorTerm      = $coauthors_plus->update_author_term( $author );
     399            $newPost['post_author'] = (int)$data['author'];
     400            if ( 'post' === $postType ) {
     401                wp_set_post_terms( $postId, $authorTerm->slug, $coauthors_plus->coauthor_taxonomy, true );
     402            } else {
     403                wp_set_object_terms( $postId, $authorTerm->slug, $coauthors_plus->coauthor_taxonomy, true );
     404            }
    395405        }
    396406
     
    417427
    418428        $this->attachAttachments($postId, $imageIds);
    419 
    420         if ( null !== $coauthors_plus ) {
    421             if ( ! is_numeric( $data['author'] ) ) {
    422                 $data['author'] = str_replace( 'guest-', '', $data['author'] );
    423                 $author          = $coauthors_plus->guest_authors->get_guest_author_by( 'ID', $data['author'] );
    424                 $authorTerm      = $coauthors_plus->update_author_term( $author );
    425                 if ( 'post' === $postType ) {
    426                     wp_set_post_terms( $postId, $authorTerm->slug, $coauthors_plus->coauthor_taxonomy, true );
    427                 } else {
    428                     wp_set_object_terms( $postId, $authorTerm->slug, $coauthors_plus->coauthor_taxonomy, true );
    429                 }
    430             }
    431         }
    432429
    433430        // Provide a hook for customers to do any additional work with the post once it has been handled by us
Note: See TracChangeset for help on using the changeset viewer.