Plugin Directory

Changeset 3443140


Ignore:
Timestamp:
01/20/2026 10:36:16 AM (2 months ago)
Author:
Molongui
Message:

5.2.7 (2026-01-20)

  • Fixed: Related posts in the author box now respect the configured ordering settings.
  • Fixed: Related posts in the author box no longer include drafts or future posts.
  • Fixed: Post count updates now work correctly in edge cases.
  • Fixed: Post count filtering now ignores empty or invalid author IDs to prevent unexpected behavior.
  • Fixed: Compatibility issue with BetterDocs where enabling Guest Author or Co-Authors could cause single doc posts to render as an archive list.
Location:
molongui-authorship/trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • molongui-authorship/trunk/README.txt

    r3439873 r3443140  
    254254<strong>Important</strong>: If you use a caching plugin, please clear your cache after updating any plugins.
    255255
     256= 5.2.7 (2026-01-20) =
     257
     258* **Fixed**: Related posts in the author box now respect the configured ordering settings.
     259* **Fixed**: Related posts in the author box no longer include drafts or future posts.
     260* **Fixed**: Post count updates now work correctly in edge cases.
     261* **Fixed**: Post count filtering now ignores empty or invalid author IDs to prevent unexpected behavior.
     262* **Fixed**: Compatibility issue with BetterDocs where enabling Guest Author or Co-Authors could cause single doc posts to render as an archive list.
     263
    256264= 5.2.6 (2026-01-14) =
    257265
    258 * **Fixed**: Missing author description in author boxes.
     266* **Fixed**: Author description now correctly appears in author boxes.
    259267
    260268= 5.2.5 (2026-01-14) =
  • molongui-authorship/trunk/changelog.txt

    r3439873 r3443140  
    33== Changelog ==
    44
     5= 5.2.7 (2026-01-20) =
     6
     7* **Fixed**: Related posts in the author box now respect the configured ordering settings.
     8* **Fixed**: Related posts in the author box no longer include drafts or future posts.
     9* **Fixed**: Post count updates now work correctly in edge cases.
     10* **Fixed**: Post count filtering now ignores empty or invalid author IDs to prevent unexpected behavior.
     11* **Fixed**: Compatibility issue with BetterDocs where enabling Guest Author or Co-Authors could cause single doc posts to render as an archive list.
     12
    513= 5.2.6 (2026-01-14) =
    614
    7 * **Fixed**: Missing author description in author boxes.
     15* **Fixed**: Author description now correctly appears in author boxes.
    816
    917= 5.2.5 (2026-01-14) =
  • molongui-authorship/trunk/common/utils/post.php

    r3222089 r3443140  
    282282        }
    283283    }
     284    public static function sanitize_post_status_arg( $post_status, $fallback = 'publish' )
     285    {
     286        $valid_statuses = array_keys( get_post_stati() );
     287
     288        /*!
     289         * FILTER HOOK
     290         * Filters the default fallback value used when sanitizing a "post_status" query argument.
     291         *
     292         * The fallback is used only when the incoming post_status value is empty/invalid and a safe default must be
     293         * applied. The default fallback is an empty string, which causes WP_Query to apply its own context-aware
     294         * defaults:
     295         *
     296         * - On the front end, the default status is "publish".
     297         * - When the user is logged in, "private" may also be included (subject to capabilities and post type).
     298         * - Public custom post statuses may be included by default.
     299         * - In admin/AJAX contexts, protected statuses may be added as well (by default: "future", "draft", "pending").
     300         *
     301         * Return a string status (e.g. "publish"), "any", an array of statuses, or an empty string to defer
     302         * to WordPress defaults.
     303         *
     304         * @param  string|array $fallback Default fallback value. Empty string defers to WordPress defaults.
     305         * @return string|array           Filtered fallback value.
     306         */
     307        $fallback = apply_filters( 'authorship/post_status_fallback', '' );
     308        if ( is_string( $post_status ) )
     309        {
     310            $raw = trim( $post_status );
     311
     312            if ( $raw === '' )
     313            {
     314                return $fallback;
     315            }
     316
     317            if ( strtolower( $raw ) === 'any' )
     318            {
     319                return 'any';
     320            }
     321
     322            if ( is_numeric( $raw ) )
     323            {
     324                return $fallback;
     325            }
     326
     327            $key = sanitize_key( $raw );
     328            return ( $key !== '' && in_array( $key, $valid_statuses, true ) )
     329                ? array( $key )
     330                : $fallback;
     331        }
     332        if ( is_array( $post_status ) )
     333        {
     334            $out = array();
     335
     336            foreach ( $post_status as $st )
     337            {
     338                if ( ! is_string( $st ) )
     339                {
     340                    continue;
     341                }
     342
     343                $raw = trim( $st );
     344                if ( $raw === '' || is_numeric( $raw ) )
     345                {
     346                    continue;
     347                }
     348
     349                $key = sanitize_key( $raw );
     350                if ( $key !== '' && in_array( $key, $valid_statuses, true ) )
     351                {
     352                    $out[] = $key;
     353                }
     354            }
     355
     356            $out = array_values( array_unique( $out ) );
     357            return ! empty( $out ) ? $out : $fallback;
     358        }
     359        return $fallback;
     360    }
    284361
    285362} // class
  • molongui-authorship/trunk/includes/admin/admin-post.php

    r3439281 r3443140  
    12311231         * @since 4.9.0
    12321232         */
    1233         return apply_filters( 'molongui_authorship/countable_post_statuses', array
     1233        $countable_post_status = apply_filters( 'molongui_authorship/countable_post_statuses', array
    12341234        (
    12351235            'publish',
    12361236            'private',
    12371237        ));
     1238
     1239        return Post::sanitize_post_status_arg( $countable_post_status );
    12381240    }
    12391241    public static function update_authors( $post_authors, $post_id, $post_type, $post_author )
  • molongui-authorship/trunk/includes/admin/post-count-updater.php

    r3439281 r3443140  
    1616use Molongui\Authorship\Author;
    1717use Molongui\Authorship\Authors;
     18use Molongui\Authorship\Common\Utils\Debug;
    1819use Molongui\Authorship\Common\Utils\Singleton;
    1920use Molongui\Authorship\Guest_Author;
     
    282283            foreach( $ids as $id )
    283284            {
    284                 $authors[] = array( 'id' => $id, 'type' => $type, 'ref' => $type.'-'.$id, 'name' => '' );
     285                $authors[] = new Author( $id, $type );
    285286            }
    286287        }
     
    331332        if ( !isset( $count ) )
    332333        {
    333             $count = $_author->get_post_count( $post_type, false );
     334            $count = $_author->get_post_count( $post_type, 'live' );
    334335        }
    335336        $_author->persist_post_count( $count, $post_type );
     
    341342            return;
    342343        }
    343         if ( is_string( $post_authors ) )
    344         {
    345             $parts = explode( '-', $post_authors );
    346 
    347             if ( isset( $parts[0] ) and $parts[0] === $post_authors )
    348             {
    349                 return;
    350             }
    351 
    352             $post_authors          = array();
    353             $post_authors[0]       = new \stdClass();
    354             $post_authors[0]->id   = $parts[1];
    355             $post_authors[0]->type = $parts[0];
    356         }
    357 
    358         foreach ( $post_authors as $post_author )
    359         {
    360             $author = new Author( $post_author->id, $post_author->type );
    361             $count  = $author->get_post_count( $post_type );
    362             self::update_author_post_counter( array( 'id' => $post_author->id, 'type' => $post_author->type ), $post_type, $count + 1 );
     344
     345        foreach ( (array) $post_authors as $post_author )
     346        {
     347            $author_id   = null;
     348            $author_type = null;
     349
     350            if ( is_object( $post_author ) && isset( $post_author->id, $post_author->type ) )
     351            {
     352                $author_id   = (int) $post_author->id;
     353                $author_type = (string) $post_author->type;
     354
     355            }
     356            elseif ( is_string( $post_author ) )
     357            {
     358                $parts = explode( '-', $post_author, 2 );
     359                if ( count( $parts ) !== 2 )
     360                {
     361                    continue;
     362                }
     363                $author_type = $parts[0];
     364                $author_id   = (int) $parts[1];
     365
     366            }
     367            else
     368            {
     369                continue;
     370            }
     371
     372            if ( ! in_array( $author_type, array( 'user', 'guest' ), true ) || $author_id <= 0 )
     373            {
     374                continue;
     375            }
     376
     377            $author = new Author( $author_id, $author_type );
     378            $count  = (int) $author->get_post_count( $post_type );
     379
     380            self::update_author_post_counter(
     381                array( 'id' => $author_id, 'type' => $author_type ),
     382                $post_type,
     383                max( 0, $count + 1 )
     384            );
    363385        }
    364386    }
     
    369391            return;
    370392        }
    371         if ( is_string( $post_authors ) )
    372         {
    373             $parts = explode( '-', $post_authors );
    374 
    375             if ( isset( $parts[0] ) and $parts[0] === $post_authors )
    376             {
    377                 return;
    378             }
    379 
    380             $post_authors          = array();
    381             $post_authors[0]       = new \stdClass();
    382             $post_authors[0]->id   = $parts[1];
    383             $post_authors[0]->type = $parts[0];
    384         }
    385 
    386         foreach ( $post_authors as $post_author )
    387         {
    388             $author = new Author( $post_author->id, $post_author->type );
    389             $count  = $author->get_post_count( $post_type );
    390             self::update_author_post_counter( array( 'id' => $post_author->id, 'type' => $post_author->type ), $post_type, $count - 1 );
     393
     394        foreach ( (array) $post_authors as $post_author )
     395        {
     396            $author_id   = null;
     397            $author_type = null;
     398
     399            if ( is_object( $post_author ) && isset( $post_author->id, $post_author->type ) )
     400            {
     401                $author_id   = (int) $post_author->id;
     402                $author_type = (string) $post_author->type;
     403
     404            }
     405            elseif ( is_string( $post_author ) )
     406            {
     407                $parts = explode( '-', $post_author, 2 );
     408                if ( count( $parts ) !== 2 )
     409                {
     410                    continue;
     411                }
     412                $author_type = $parts[0];
     413                $author_id   = (int) $parts[1];
     414
     415            }
     416            else
     417            {
     418                continue;
     419            }
     420
     421            if ( ! in_array( $author_type, array( 'user', 'guest' ), true ) || $author_id <= 0 )
     422            {
     423                continue;
     424            }
     425
     426            $author = new Author( $author_id, $author_type );
     427            $count  = (int) $author->get_post_count( $post_type );
     428
     429            self::update_author_post_counter(
     430                array( 'id' => $author_id, 'type' => $author_type ),
     431                $post_type,
     432                max( 0, $count - 1 )
     433            );
    391434        }
    392435    }
  • molongui-authorship/trunk/includes/author.php

    r3439873 r3443140  
    304304        return self::GUEST_META_PREFIX . $short_key;
    305305    }
     306    private function get_all_plugin_meta()
     307    {
     308        $prefix = $this->is_user ? self::USER_META_PREFIX : self::GUEST_META_PREFIX;
     309
     310        return $this->cache_remember( 'meta:all_plugin', function () use ( $prefix )
     311        {
     312            $all_meta = $this->is_user ? get_user_meta( $this->id ) : get_post_meta( $this->id );
     313
     314            if ( ! is_array( $all_meta ) || empty( $all_meta ) )
     315            {
     316                return array();
     317            }
     318
     319            $plugin_meta = array();
     320
     321            foreach ( $all_meta as $meta_key => $values )
     322            {
     323                if ( ! is_string( $meta_key ) || strpos( $meta_key, $prefix ) !== 0 )
     324                {
     325                    continue;
     326                }
     327                if ( ! is_array( $values ) )
     328                {
     329                    $values = array( $values );
     330                }
     331
     332                $plugin_meta[ $meta_key ] = $values;
     333                if ( ! array_key_exists( $meta_key, $this->prefetched_meta ) )
     334                {
     335                    $first = isset( $values[0] ) ? $values[0] : '';
     336                    $this->prefetched_meta[ $meta_key ] = ( $first === null ) ? '' : $first;
     337                }
     338            }
     339
     340            return $plugin_meta;
     341        } );
     342    }
    306343    final public function get_id()
    307344    {
     
    731768
    732769        $key = (string) $key;
     770        if ( $key === 'all' )
     771        {
     772            return $this->get_all_plugin_meta();
     773        }
    733774        $label = 'meta:' . $key;
    734775        if ( $this->type === 'user' )
     
    753794                         * @deprecated 5.2.0 Use "molongui_authorship/author/{$key}" instead
    754795                         */
    755                         if ( has_filter( "molongui_authorship/get_author_meta_{$key}" ) && apply_filters( 'molongui_authorship/apply_filters_deprecated', true ) )
     796                        if ( has_filter( "molongui_authorship/get_author_meta_{$key}" ) && apply_filters( 'molongui_authorship/apply_filters_deprecated', true, __FUNCTION__ ) )
    756797                        {
    757798                            $value = apply_filters_deprecated(
     
    863904         * @deprecated 5.2.0 Use 'molongui_authorship/author/user_roles' instead
    864905         */
    865         if ( has_filter( 'molongui_authorship/get_author_user_roles' ) and apply_filters( 'molongui_authorship/apply_filters_deprecated', false ) )
     906        if ( has_filter( 'molongui_authorship/get_author_user_roles' ) and apply_filters( 'molongui_authorship/apply_filters_deprecated', false, __FUNCTION__ ) )
    866907        {
    867908            $user_roles = apply_filters_deprecated( 'molongui_authorship/get_author_user_roles', array( $user_roles, $this->id, $this->type, $this ), '5.2.0', 'molongui_authorship/author/user_roles' );
     
    11881229    public function get_posts( $args = null )
    11891230    {
     1231
    11901232        $defaults = array
    11911233        (
    1192             'cat'                 => '',
     1234            'cat'                 => 0,
    11931235            'fields'              => 'all',
    11941236            'ignore_sticky_posts' => true,
     
    12011243            'post__not_in'        => array(),
    12021244            'post_type'           => 'post',
    1203             'post_status'         => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ), // all WP default post_status //Admin_Post::get_countable_post_statuses(),
     1245            'post_status'         => '',
    12041246            'posts_per_page'      => -1,
    1205             'author_id'           => $this->id,
    1206             'author_type'         => $this->type,
    1207             'site_id'             => apply_filters( 'authorship/get_posts/blog_id', get_current_blog_id() ),
    1208             'language'            => apply_filters( 'authorship/get_posts/language', Helpers::get_language() ),
     1247'author_id'           => $this->id,
     1248'author_type'         => $this->type,
     1249'site_id'             => apply_filters( 'authorship/get_posts/blog_id', get_current_blog_id() ),
     1250'language'            => apply_filters( 'authorship/get_posts/language', Helpers::get_language() ),
    12091251
    12101252        );
     
    12121254
    12131255        $fields = is_string( $a['fields'] ) ? strtolower( $a['fields'] ) : 'all';
    1214         if ( ! in_array( $fields, array( '', 'all', 'ids', 'id=>parent' ), true ) )
     1256        if ( ! in_array( $fields, array( 'all', 'ids', 'id=>parent' ), true ) )
    12151257        {
    12161258            $fields = 'all';
     
    12221264            $order = 'DESC';
    12231265        }
     1266
     1267        $orderby = is_string( $a['orderby'] ) ? strtolower( trim( $a['orderby'] ) ) : 'date';
     1268        $allowed_orderby = array
     1269        (
     1270            'none',
     1271            'id',
     1272            'author',
     1273            'title',
     1274            'name',
     1275            'date',
     1276            'modified',
     1277            'parent',
     1278            'rand',
     1279            'comment_count',
     1280            'menu_order',
     1281            'meta_value',
     1282            'meta_value_num',
     1283            'post__in',
     1284        );
     1285        if ( ! in_array( $orderby, $allowed_orderby, true ) )
     1286        {
     1287            $orderby = 'date';
     1288        }
     1289
     1290        $posts_per_page = (int) $a['posts_per_page'];
     1291        if ( $posts_per_page < -1 )
     1292        {
     1293            $posts_per_page = -1;
     1294        }
     1295
     1296        $offset = (int) $a['offset'];
     1297        if ( $offset < 0 )
     1298        {
     1299            $offset = 0;
     1300        }
     1301
     1302        $cat = $a['cat'];
     1303        if ( $cat === '' || $cat === null )
     1304        {
     1305            $cat = 0;
     1306        }
     1307        else
     1308        {
     1309            $cat = absint( $cat );
     1310        }
     1311
     1312        $post__in = $a['post__in']; // accept array|string|int.
     1313        if ( is_string( $post__in ) )
     1314        {
     1315            $post__in = array_filter( array_map( 'absint', explode( ',', $post__in ) ) );
     1316        }
     1317        elseif ( is_numeric( $post__in ) )
     1318        {
     1319            $post__in = array( absint( $post__in ) );
     1320        }
     1321        else
     1322        {
     1323            $post__in = array_filter( array_map( 'absint', (array) $post__in ) );
     1324        }
     1325        $post__in = array_values( array_unique( $post__in ) );
     1326
     1327        $post__not_in = $a['post__not_in']; // accept array|string|int.
     1328        if ( is_string( $post__not_in ) )
     1329        {
     1330            $post__not_in = array_filter( array_map( 'absint', explode( ',', $post__not_in ) ) );
     1331        }
     1332        elseif ( is_numeric( $post__not_in ) )
     1333        {
     1334            $post__not_in = array( absint( $post__not_in ) );
     1335        }
     1336        else
     1337        {
     1338            $post__not_in = array_filter( array_map( 'absint', (array) $post__not_in ) );
     1339        }
     1340        $post__not_in = array_values( array_unique( $post__not_in ) );
     1341
     1342        $meta_query = is_array( $a['meta_query'] ) ? $a['meta_query'] : array();
     1343
     1344        $ignore_sticky_posts = (bool) $a['ignore_sticky_posts'];
     1345        $no_found_rows_raw   = (bool) $a['no_found_rows'];
     1346
    12241347        if ( is_string( $a['post_type'] ) && $a['post_type'] !== '' )
    12251348        {
     
    12351358
    12361359                case 'related':
    1237                     $post_types          = explode( ",", Settings::get( 'author_box_related_posts_post_types' ) );
    1238                     $a['posts_per_page'] = Settings::get( 'author_box_related_posts_count' );
    1239                     $a['orderby']        = Settings::get( 'author_box_related_orderby' );
    1240                     $order               = Settings::get( 'author_box_related_order' );
    12411360                    break;
    12421361
    12431362                default:
    12441363                    $post_types = array( sanitize_key( $a['post_type'] ) );
     1364                    break;
    12451365            }
    12461366        }
     
    12561376                }
    12571377            }
    1258             if ( empty( $post_types ) )
    1259             {
    1260                 $post_types = array( 'post' );
    1261             }
     1378            $post_types = array_values( array_unique( $post_types ) );
    12621379        }
    12631380        else
     
    12651382            $post_types = array( 'post' );
    12661383        }
    1267         if ( is_string( $a['post_status'] ) && $a['post_status'] !== '' )
    1268         {
    1269             $post_status = ( $a['post_status'] === 'any' ) ? 'any' : array( sanitize_key( $a['post_status'] ) );
    1270         }
    1271         elseif ( is_array( $a['post_status'] ) )
    1272         {
    1273             $post_status = array();
    1274             foreach ( $a['post_status'] as $st )
    1275             {
    1276                 $st = sanitize_key( $st );
    1277                 if ( $st !== '' )
    1278                 {
    1279                     $post_status[] = $st;
    1280                 }
    1281             }
    1282             if ( empty( $post_status ) )
    1283             {
    1284                 $post_status = Admin_Post::get_countable_post_statuses();
    1285             }
    1286         }
    1287         else
    1288         {
    1289             $post_status = Admin_Post::get_countable_post_statuses();
    1290         }
    1291         $no_found_rows = ( $a['posts_per_page'] > 0 ) ? false : (bool) $a['no_found_rows'];
    1292 
    1293         /*!
    1294          * FILTER HOOK
    1295          * Allows filtering returned posts list before it is generated.
    1296          *
    1297          * Passing a non-null value will effectively short-circuit the generation, returning that value instead.
    1298          *
    1299          * @param array  $posts  The posts list. Default null.
    1300          * @param array  $args   Array of function arguments.
    1301          * @param Author $author The current author instance.
    1302          * @since 5.2.0
    1303          */
    1304         $posts = apply_filters( 'molongui_authorship/author/pre_get_posts', null, $args, $this );
    1305         if ( null !== $posts )
    1306         {
    1307             return $posts;
    1308         }
     1384
     1385        $post_status = Post::sanitize_post_status_arg( $a['post_status'] );
     1386        $no_found_rows = ( $posts_per_page > 0 ) ? false : $no_found_rows_raw;
     1387        $raw_args = wp_parse_args( $args, array() );
     1388
     1389        $caller_set_order          = array_key_exists( 'order', $raw_args );
     1390        $caller_set_orderby        = array_key_exists( 'orderby', $raw_args );
     1391        $caller_set_posts_per_page = array_key_exists( 'posts_per_page', $raw_args );
     1392        if ( is_string( $a['post_type'] ) && $a['post_type'] === 'related' )
     1393        {
     1394            $related_post_types = array_filter(
     1395                array_map(
     1396                    'sanitize_key',
     1397                    array_map( 'trim', explode( ',', (string) Settings::get( 'author_box_related_posts_post_types' ) ) )
     1398                )
     1399            );
     1400            if ( ! empty( $related_post_types ) )
     1401            {
     1402                $post_types = array_values( array_unique( $related_post_types ) );
     1403            }
     1404            if ( ! $caller_set_posts_per_page )
     1405            {
     1406                $related_count = (int) Settings::get( 'author_box_related_posts_count' );
     1407                $posts_per_page = ( $related_count > 0 ) ? $related_count : -1;
     1408            }
     1409            if ( ! $caller_set_orderby )
     1410            {
     1411                $settings_orderby = is_string( Settings::get( 'author_box_related_posts_orderby' ) )
     1412                    ? strtolower( trim( (string) Settings::get( 'author_box_related_posts_orderby' ) ) )
     1413                    : 'date';
     1414                if ( ! in_array( $settings_orderby, $allowed_orderby, true ) )
     1415                {
     1416                    $settings_orderby = 'date';
     1417                }
     1418
     1419                $orderby = $settings_orderby;
     1420            }
     1421            if ( ! $caller_set_order )
     1422            {
     1423                $settings_order = strtoupper( (string) Settings::get( 'author_box_related_posts_order' ) );
     1424                if ( $settings_order !== 'ASC' && $settings_order !== 'DESC' )
     1425                {
     1426                    $settings_order = 'DESC';
     1427                }
     1428
     1429                $order = $settings_order;
     1430            }
     1431        }
     1432        $no_found_rows = ( $posts_per_page > 0 ) ? false : $no_found_rows_raw;
    13091433        $ref = ( $this->type === 'user' ) ? ( 'user-' . $this->id ) : ( 'guest-' . $this->id );
    1310 
    1311         $meta_query = is_array( $a['meta_query'] ) ? $a['meta_query'] : array();
    13121434        $meta_query[] = array
    13131435        (
     
    13161438            'compare' => '==',
    13171439        );
     1440        if ( is_string( $a['post_type'] ) && $a['post_type'] === 'related' )
     1441        {
     1442            $current_post_id = (int) get_queried_object_id();
     1443            if ( $current_post_id > 0 )
     1444            {
     1445                $post__not_in[] = $current_post_id;
     1446                $post__not_in   = array_values( array_unique( array_filter( array_map( 'absint', $post__not_in ) ) ) );
     1447            }
     1448        }
     1449        if ( $orderby === 'post__in' && empty( $post__in ) )
     1450        {
     1451            $orderby = 'date';
     1452        }
    13181453        $q_args = array
    13191454        (
    13201455            'post_type'              => $post_types,
    13211456            'post_status'            => $post_status,
    1322             'fields'                 => $fields,            // 'all' | 'ids' | 'id=>parent'
    1323             'orderby'                => $a['orderby'],
     1457            'fields'                 => $fields, // 'all' | 'ids' | 'id=>parent'
     1458            'orderby'                => $orderby,
    13241459            'order'                  => $order,
    1325             'posts_per_page'         => (int) $a['posts_per_page'],
    1326             'offset'                 => (int) $a['offset'],
    1327             'ignore_sticky_posts'    => (bool) $a['ignore_sticky_posts'],
     1460            'posts_per_page'         => $posts_per_page,
     1461            'offset'                 => $offset,
     1462            'ignore_sticky_posts'    => (bool) $ignore_sticky_posts,
    13281463            'no_found_rows'          => (bool) $no_found_rows,
    13291464            'meta_query'             => $meta_query,
    1330             'post__in'               => (array) $a['post__in'],
    1331             'post__not_in'           => (array) $a['post__not_in'],
    1332             'cat'                    => $a['cat'],          // pass-through
    1333             'suppress_filters'       => false,              // let multilingual/plugins scope by language if needed
     1465            'post__in'               => $post__in,
     1466            'post__not_in'           => $post__not_in,
     1467            'cat'                    => $cat,
     1468            'suppress_filters'       => false,
    13341469            'update_post_term_cache' => ( $fields === 'all' ), // if only IDs, don't waste time filling term cache
    13351470            'update_post_meta_cache' => ( $fields === 'all' ), // if only IDs, skip meta cache
    13361471        );
     1472
     1473        /*!
     1474         * FILTER HOOK
     1475         * Allow last-second customization of the query args.
     1476         *
     1477         * @param array  $q_args WP_Query args that will be used to fetch authored posts.
     1478         * @param Author $this   The current author instance.
     1479         * @since 5.2.0
     1480         */
    13371481        $q_args = apply_filters( 'molongui_authorship/author/get_posts/query_args', $q_args, $this );
     1482
     1483        $resolved = array
     1484        (
     1485            'cat'                 => $cat,
     1486            'fields'              => $fields,
     1487            'ignore_sticky_posts' => $ignore_sticky_posts,
     1488            'meta_query'          => $meta_query,
     1489            'no_found_rows'       => $no_found_rows,
     1490            'offset'              => $offset,
     1491            'order'               => $order,
     1492            'orderby'             => $orderby,
     1493            'post__in'            => $post__in,
     1494            'post__not_in'        => $post__not_in,
     1495            'post_type'           => $a['post_type'],
     1496            'post_types'          => $post_types,
     1497
     1498            'post_status'         => $post_status,
     1499            'posts_per_page'      => $posts_per_page,
     1500            'author_id'           => $a['author_id'],
     1501            'author_type'         => $a['author_type'],
     1502            'site_id'             => $a['site_id'],
     1503            'language'            => $a['language'],
     1504        );
     1505
     1506        /*!
     1507         * FILTER HOOK
     1508         * Allows filtering returned posts list before it is generated.
     1509         *
     1510         * Returning a non-null value will effectively short-circuit WP_Query execution, returning that value instead.
     1511         *
     1512         * @param mixed  $posts    The posts list. Default null.
     1513         * @param mixed  $args     Raw method input (array|string|null).
     1514         * @param Author $author   The current author instance.
     1515         * @param array  $parsed   Parsed args after defaults are applied (wp_parse_args()).
     1516         * @param array  $resolved Sanitized/normalized args as they will be used.
     1517         * @param array  $q_args   Prepared WP_Query args that would be executed.
     1518         * @since 5.2.0
     1519         */
     1520        $posts = apply_filters( 'molongui_authorship/author/pre_get_posts', null, $args, $this, $a, $resolved, $q_args );
     1521        if ( null !== $posts )
     1522        {
     1523            return $posts;
     1524        }
    13381525        $q = new \WP_Query( $q_args );
    13391526        $posts = $q->posts;
  • molongui-authorship/trunk/includes/authors.php

    r3439281 r3443140  
    7070            $authors = Post::get_authors( $post_id );
    7171        }
    72         if ( empty( $authors ) or $authors[0]->id == 0 )
     72        if ( empty( $authors ) || !is_array( $authors ) || !isset( $authors[0] ) || empty( $authors[0]->id ) )
    7373        {
    7474            return false;
     
    297297            $core_wishlist = array( 'display_name','user_nicename','user_email','user_url','post_title','post_name','post_content' );
    298298            $meta_wishlist_users = array(
    299                 'first_name','last_name','description',                  // native usermeta
     299                'first_name','last_name','description',
    300300                'molongui_author_phone','molongui_author_custom_link',
    301301                'molongui_author_position','molongui_author_company','molongui_author_company_link',
    302                 'molongui_author_archived',                              // archived flag
     302                'molongui_author_archived',
    303303            );
    304304            $meta_wishlist_guests = array(
     
    307307                '_molongui_guest_author_web','_molongui_guest_author_custom_link',
    308308                '_molongui_guest_author_job','_molongui_guest_author_company','_molongui_guest_author_company_link',
    309                 '_molongui_guest_author_archived',                       // archived flag
     309                '_molongui_guest_author_archived',
    310310            );
    311311            $need_post_counts = in_array( 'post_count', $fields, true ) || (int) $args['min_post_count'] > 0;
  • molongui-authorship/trunk/includes/post.php

    r3439281 r3443140  
    7575        {
    7676            $author_type = 'guest';
    77             $author_id   = $the_query->guest_author_id;
     77            $author_id   = absint( $the_query->guest_author_id );
    7878        }
    7979        else
    8080        {
    8181            $author_type = 'user';
    82             $author_id   = $userid;
     82            $author_id   = absint( $userid );
    8383        }
    8484
     
    8989         */
    9090        list( $author_id, $author_type ) = apply_filters( '_authorship/post_count/author', array( $author_id, $author_type ), $count, $userid, $post_type, $public_only );
     91        if ( empty( $author_id ) || absint( $author_id ) === 0 )
     92        {
     93            return apply_filters( 'molongui_authorship/post_count', $count, $count, $userid, $post_type, $public_only );
     94        }
    9195        $author     = new Author( $author_id, $author_type );
    9296        $post_count = $author->get_post_count( $post_type, true );
    93         return apply_filters( 'authorship/post_count', $post_count, $count, $userid, $post_type, $public_only );
     97
     98        /*!
     99         * DEPRECATED
     100         * This filter hook is scheduled for removal in version 5.4.0. Update any dependencies accordingly.
     101         *
     102         * @since      4.6.18
     103         * @deprecated 5.2.7 Use 'molongui_authorship/post_count' instead
     104         */
     105        if ( has_filter( 'authorship/post_count' ) and apply_filters( 'molongui_authorship/apply_filters_deprecated', true, __FUNCTION__ ) )
     106        {
     107            $post_count = apply_filters_deprecated( 'authorship/post_count', array( $post_count, $count, $userid, $post_type, $public_only ), '5.2.7', 'molongui_authorship/post_count' );
     108        }
     109
     110        /*!
     111         * FILTER HOOK
     112         * Allows filtering the post count before it is returned.
     113         *
     114         * @param int          $post_count  The filtered user's post count.
     115         * @param int          $count       The original user's post count.
     116         * @param int          $userid      User ID.
     117         * @param string|array $post_type   Single post type or array of post types to count the number of posts for.
     118         * @param bool         $public_only Whether to limit counted posts to public posts.
     119         * @since 5.2.7
     120         */
     121        return apply_filters( 'molongui_authorship/post_count', $post_count, $count, $userid, $post_type, $public_only );
    94122    }
    95123    public function filter_user_posts( $wp_query )
  • molongui-authorship/trunk/includes/settings.php

    r3421622 r3443140  
    41114111            $wpdb->query( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE '{$like}';" );
    41124112        }
     4113
     4114        do_action( 'molongui_authorship/delete_job_flags' );
    41134115    }
    41144116    public function stylesheet( $file )
     
    44454447         * @deprecated 5.0.8
    44464448         */
    4447         if ( has_filter( 'authorship/user/roles' ) and apply_filters( 'molongui_authorship/apply_filters_deprecated', true ) )
     4449        if ( has_filter( 'authorship/user/roles' ) and apply_filters( 'molongui_authorship/apply_filters_deprecated', true, __FUNCTION__ ) )
    44484450        {
    44494451            $user_roles = apply_filters_deprecated( 'authorship/user/roles', array( $user_roles ), '5.0.8' );
  • molongui-authorship/trunk/molongui-authorship.php

    r3439873 r3443140  
    1313 * Plugin URI:        https://www.molongui.com/wordpress-plugin-post-authors
    1414 * Description:       All-in-One Authorship Solution: Seamless Author Box, Guest Authors, and Co-Authors to enhance your site's authority, credibility, engagement, and SEO.
    15  * Version:           5.2.6
     15 * Version:           5.2.7
    1616 * Requires at least: 5.2
    1717 * Tested up to:      6.9
     
    4444final class MolonguiAuthorship
    4545{
    46     const VERSION = '5.2.6';
     46    const VERSION = '5.2.7';
    4747    use Singleton;
    4848    function __construct()
  • molongui-authorship/trunk/views/author-box/related/html-layout-1.php

    r3415065 r3443140  
    33defined( 'ABSPATH' ) or exit; // Exit if accessed directly
    44
    5 foreach( $profile->get_posts_ids( array( 'post_type' => 'related' ) ) as $related_id )
     5$related_posts_ids = $profile->get_posts_ids( array
     6(
     7    'post_type'    => 'related',
     8    'post__not_in' => get_the_ID(),
     9) );
     10
     11if ( empty( $related_posts_ids ) )
     12{
     13    return;
     14}
     15
     16foreach( $related_posts_ids as $related_id )
    617{
    718    ?>
  • molongui-authorship/trunk/views/author-box/related/html-layout-2.php

    r3415065 r3443140  
    33defined( 'ABSPATH' ) or exit; // Exit if accessed directly
    44
    5 foreach( $profile->get_posts_ids( array( 'post_type' => 'related' ) ) as $related_id )
     5$related_posts_ids = $profile->get_posts_ids( array
     6(
     7    'post_type'    => 'related',
     8    'post__not_in' => get_the_ID(),
     9) );
     10
     11if ( empty( $related_posts_ids ) )
     12{
     13    return;
     14}
     15
     16foreach( $related_posts_ids as $related_id )
    617{
    718    ?>
Note: See TracChangeset for help on using the changeset viewer.