From b993e20f2c92db5866347edb1e5d5320ba9566b0 Mon Sep 17 00:00:00 2001 From: Max Kieltyka Date: Thu, 16 Jun 2022 09:33:56 +0200 Subject: [PATCH 01/30] add filters --- src/modules/rest-api/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/rest-api/rest-api.php b/src/modules/rest-api/rest-api.php index 8aaa5ea3..88336da0 100644 --- a/src/modules/rest-api/rest-api.php +++ b/src/modules/rest-api/rest-api.php @@ -131,7 +131,7 @@ public function getPostAuthorsCallBack($postData) ]; } - return $authorsData; + return $authorsData = apply_filters('pp_rest_api_authors_data', $authorsData); } } } From e6cab0880051feb992a25f9ee22c0608aff671ab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 17 Jun 2022 03:35:30 +0000 Subject: [PATCH 02/30] Bump jpeg-js from 0.4.3 to 0.4.4 Bumps [jpeg-js](https://github.com/eugeneware/jpeg-js) from 0.4.3 to 0.4.4. - [Release notes](https://github.com/eugeneware/jpeg-js/releases) - [Commits](https://github.com/eugeneware/jpeg-js/compare/v0.4.3...v0.4.4) --- updated-dependencies: - dependency-name: jpeg-js dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index e4bf19ec..9f21c5a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7228,9 +7228,9 @@ } }, "node_modules/jpeg-js": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.4.3.tgz", - "integrity": "sha512-ru1HWKek8octvUHFHvE5ZzQ1yAsJmIvRdGWvSoKV52XKyuyYA437QWDttXT8eZXDSbuMpHlLzPDZUPd6idIz+Q==", + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.4.4.tgz", + "integrity": "sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==", "dev": true }, "node_modules/js-beautify": { @@ -17679,9 +17679,9 @@ } }, "jpeg-js": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.4.3.tgz", - "integrity": "sha512-ru1HWKek8octvUHFHvE5ZzQ1yAsJmIvRdGWvSoKV52XKyuyYA437QWDttXT8eZXDSbuMpHlLzPDZUPd6idIz+Q==", + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.4.4.tgz", + "integrity": "sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==", "dev": true }, "js-beautify": { From 8fe7229e693d16f0bed5d7137c213eb0ff95c85a Mon Sep 17 00:00:00 2001 From: Ojo Paul Date: Fri, 17 Jun 2022 11:56:11 +0100 Subject: [PATCH 03/30] - Build our own Author Profile Pages #417 --- src/assets/css/multiple-authors-page.css | 214 ++++++++++++++++++ src/assets/img/no-image.jpeg | Bin 0 -> 7733 bytes src/core/Classes/Query.php | 35 ++- src/core/Classes/Utils.php | 58 +++++ src/core/Plugin.php | 26 ++- .../multiple-authors/multiple-authors.php | 73 +++++- src/modules/settings/settings.php | 3 + src/templates/taxonomy-author.php | 115 ++++++++++ 8 files changed, 498 insertions(+), 26 deletions(-) create mode 100644 src/assets/css/multiple-authors-page.css create mode 100644 src/assets/img/no-image.jpeg create mode 100644 src/templates/taxonomy-author.php diff --git a/src/assets/css/multiple-authors-page.css b/src/assets/css/multiple-authors-page.css new file mode 100644 index 00000000..2e06aa08 --- /dev/null +++ b/src/assets/css/multiple-authors-page.css @@ -0,0 +1,214 @@ +.site-content, +.content-area, +.site-main, +.ppma-page-header, +.ppma-page-content, +#content, +#primary, +#main, +main { + background-color: #ffffff; +} + +.ppma-page-header { + border-bottom: 3px solid #eeeeee; + padding-bottom: 10px; +} + +.ppma-page-header .ppma-page-title { + margin-top: 5px; + font-size: 3rem; + line-height: 1.2; + color: #111; + margin-bottom: 6px; + font-weight: 700; + font-family: 'sans-serif'; +} + +.ppma-page-content .ppma-article { + word-break: break-word; + position: relative; + margin: 0 0 20px; +} + +.ppma-page-content a { + margin: 0; + padding: 0; + color: #000; + background-color: transparent; + transition: color .3s; + text-decoration: none; + vertical-align: baseline; +} + +.ppma-page-content .article-content { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-box-align: start; + -webkit-align-items: flex-start; + -ms-flex-align: start; + align-items: flex-start; + margin-bottom: 20px; +} + +.ppma-page-content .article-image { + position: relative; + width: 27%; + margin-right: 0; +} + +.ppma-page-content .featured-image-link { + display: block; + position: relative; + width: 100%; + background: #f5f5f5 url('../img/no-image.jpeg'); + vertical-align: top; + background-repeat: no-repeat; + background-position: center center; + background-size: cover; + -webkit-background-size: cover; + -moz-background-size: cover; + -o-background-size: cover; + height: 100%; + transition: transform .3s ease,opacity .3s; + transition-timing-function: cubic-bezier(0.39,0.76,0.51,0.56); +} + +.ppma-page-content .featured-image-link:before { + display: block; + content: ""; + width: 100%; + padding-top: 66.6667%; + background: none!important; + box-shadow: none!important; +} + +.ppma-page-content .featured-image-link:after { + content: ""; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: #000; + opacity: 0; + z-index: 1; + transition: opacity .3s ease; +} +.ppma-page-content .article-image:hover .featured-image-link:after { + opacity: .3; +} + +.ppma-page-content .article-body { + padding-left: 20px; + flex: 1; +} + +.ppma-page-content .category-links { + overflow: hidden; + margin-bottom: 0; + display: inline-block; +} +.ppma-page-content.category-links a, +.ppma-page-content .category-links a { + float: left; + background: #000; + font-size: 10px; + font-size: 1rem; + text-align: left; + transition: all .3s; + color: #fff; + font-weight: 500; + padding: 0 5px; + height: 16px; + line-height: 16px; + margin-right: 5px; + margin-bottom: 3px; +} + +.ppma-page-content .article-title { + font-weight: 400; + font-size: 24px; + line-height: 1.25; + text-align: left; + margin: 0; + margin-bottom: 4px; + clear: both; +} + +.ppma-page-content .article-meta { + color: #999; + font-size: 1.2rem; +} +.ppma-page-content .article-meta-item { + display: inline-block; + margin-right: 10px; +} + +.ppma-page-content .article-meta a { + font-family: inherit; + font-size: inherit; + color: inherit; +} + +.ppma-page-content .article-meta .dashicons { + margin-right: 3px; + vertical-align: middle; +} + +.ppma-page-content .article-entry-excerpt { + margin: 1.5em 0 0; + margin-top: 9px; + line-height: 1.71; + text-align: left; +} + +.ppma-page-content .article-entry-excerpt:after { + content: ""; + display: table; + clear: both; +} + +.ppma-page-content .article-footer .tags-links { + display: inline-block; + margin: 10px -2.5px 5px; + width: 100%; +} + +.ppma-page-content .article-footer .tags-links a { + display: inline-block; + min-height: 24px; + line-height: 24px; + font-size: 10px; + font-size: 1rem; + font-weight: 700; + text-align: left; + color: #888; + background: #ececec; + transition: all .3s; + margin: 0 2.5px 5px; + text-transform: uppercase; + padding-left: 10px; + padding-right: 10px; +} + +.ppma-article-pagination { + display: inline-block; + margin: -5px -5px 0; + vertical-align: top; +} + +.ppma-article-pagination a { + margin-left: 5px; + margin-right: 5px; + margin-top: 5px; + display: inline-block; + background: transparent; + color: #111; + min-width: 32px; + height: 32px; + line-height: 32px; + transition: all .3s; +} \ No newline at end of file diff --git a/src/assets/img/no-image.jpeg b/src/assets/img/no-image.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..78c7ae09a8073631640627abf88f00333943c81c GIT binary patch literal 7733 zcmeHL3sjQn*8aSL<@IPqX-SfmlgLFxB^@gbMaN7sGcAn(6%Fv3Xihd|I#YDRq8Tm9 zQDVrfG^LreOij!o^H!E(DtT$N8WA(oR1P-X{`rS9v;OtZS?8?PyZ9FS+wXp!z2E2E zFMObUsFVSawJcgV01ybD0bt<6P(A}pJQB&#$$$o+t#Z2nfKsNlA~GQ%28Tc};_XNj z=60$bnMp^mNHGYM9TEY!xUphL=a<5c#H8({@~6Os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`qg@ zX*c!o&slN_aS+*;!wuf8m$oI<*l-&FOhD>a=hR3aNy$S|?Tt6GBkrjKPFU@lr7-)nnJf(%1ia{nowhLz*db#}MKi{M3||MBk! zC}dKU`iL`@+L`k0^2^>KL$7nQUoa`(>%U}=SL+PT_H%>UcB{+&v0n`|mU*W^32ff0 z1X?dCfxW9@pdW+&_HEM*+sYU*xbRD`f8B#0bK$328oaSB1Y7ca8QAk@MXzuQT06#Q za;>m#UO%|%*GJ#)+U=8{d+)19WgaglPZHdPT4g)Gc|LB($s~eyJ~x#rwpttJ8$NGe zcD47K_d>6Q(h@&rUBYqP(Un&td0m`=<%!Uwzlm;jUgK*)%fw3SP$ggUYt3$M5G`7Zi+`&^pH{l%&|*Wum2c$e^ncDc1{Hp{?OrjPtN z3`_khzIwS6-9~OlFpl?v8n#@0^3`yE#>Bz-Pq~xw&s`e3{K>9yT|7{2w)voK#Kn-2 zo3BRPzg){6mF#9&E{bISP{jL**`U=^Z!kL7{sDZvJ2g4?#`ofsz6uwke>DbA&>~1B{A2L#j9NOS;xc=!gk*Nje!^O(9i6JU%9vu{ETQ24%athJ=G1d`Qz(zHM6bfFHOj zD$5TnSs;Z?9_6AGsVG^m%<#qUp?`Rf#^og9Ed4iS_fJ%rU5b$L2HPW>gc!2KG3)ge z&st28Zm1h~%0Ts_cPK7qcsIOaz3Su`NQ=MxueXeT+S74yPxU6wV;`GK7j5Kq#FuF` p=`h2v>U3+t)#>$&T<{w6#g*XLRevblC+8;xJ}K~jRRE-H`zNPyZ$JP5 literal 0 HcmV?d00001 diff --git a/src/core/Classes/Query.php b/src/core/Classes/Query.php index fb5f8fd4..f51171a0 100644 --- a/src/core/Classes/Query.php +++ b/src/core/Classes/Query.php @@ -96,7 +96,7 @@ public static function filter_author_posts_where($where, $query) { global $wpdb; - if (!$query->is_author()) { + if (!$query->is_author() && empty($query->query_vars['ppma_author'])) { return $where; } @@ -107,11 +107,11 @@ public static function filter_author_posts_where($where, $query) return $where; } - $author_name = sanitize_title($query->get('author_name')); + $author_name = !empty($query->query_vars['ppma_author']) + ? sanitize_title($query->get('ppma_author')) : sanitize_title($query->get('author_name')); if (empty($author_name)) { $author_id = (int)$query->get('author'); - $author = Author::get_by_id($author_id); if (!$author) { @@ -148,8 +148,7 @@ public static function filter_author_posts_where($where, $query) */ $current_user_id = get_current_user_id(); $current_author = Author::get_by_user_id($current_user_id); - if ( - $current_author + if ($current_author && is_object($current_author) && isset($current_author->term_id) && (int)$current_author->term_id > 0 @@ -192,7 +191,7 @@ public static function filter_posts_join($join, $query) { global $wpdb; - if (!$query->is_author() || empty($query->authors_having_terms)) { + if ((!$query->is_author() && empty($query->query_vars['ppma_author'])) || empty($query->authors_having_terms)) { return $join; } @@ -226,7 +225,7 @@ public static function filter_posts_groupby($groupby, $query) { global $wpdb; - if (!$query->is_author() || empty($query->authors_having_terms)) { + if ((!$query->is_author() && empty($query->query_vars['ppma_author']))|| empty($query->authors_having_terms)) { return $groupby; } @@ -248,7 +247,7 @@ public static function filter_admin_posts_list_where($where, $query) { global $wpdb; - if (!isset($query->query_vars['author'])) { + if (!isset($query->query_vars['author']) && !isset($query->query_vars['ppma_author'])) { return $where; } @@ -259,7 +258,7 @@ public static function filter_admin_posts_list_where($where, $query) return $where; } - $author_id = (int)$query->get('author'); + $author_id = !empty($query->query_vars['ppma_author']) ? (int)$query->queried_object_id : (int)$query->get('author'); if (empty($author_id)) { return $where; @@ -269,8 +268,7 @@ public static function filter_admin_posts_list_where($where, $query) if (is_a($query->queried_object, 'WP_User')) { $author = Author::get_by_user_id($query->queried_object_id); } else { - $author = $query->queried_object; - + $author = !empty($query->query_vars['ppma_author']) ? Author::get_by_term_id($author_id) : $query->queried_object; if (!is_a($author, Author::class)) { return $where; } @@ -287,8 +285,7 @@ public static function filter_admin_posts_list_where($where, $query) */ $current_user_id = get_current_user_id(); $current_author = Author::get_by_user_id($current_user_id); - if ( - $current_author + if ($current_author && is_object($current_author) && isset($current_author->term_id) && (int)$current_author->term_id > 0 @@ -371,7 +368,7 @@ public static function filter_posts_list_join($join, $query) { global $wpdb; - if (!isset($query->query_vars['author'])) { + if (!isset($query->query_vars['author']) && !isset($query->query_vars['ppma_author'])) { return $join; } @@ -382,7 +379,7 @@ public static function filter_posts_list_join($join, $query) return $join; } - $author_id = (int)$query->get('author'); + $author_id = !empty($query->query_vars['ppma_author']) ? (int)$query->queried_object_id : (int)$query->get('author'); if (empty($author_id)) { return $join; @@ -391,7 +388,7 @@ public static function filter_posts_list_join($join, $query) if (is_a($query->queried_object, 'WP_User')) { $author = Author::get_by_user_id($query->queried_object_id); } else { - $author = $query->queried_object; + $author = !empty($query->query_vars['ppma_author']) ? Author::get_by_term_id($author_id) : $query->queried_object; } if (!is_object($author) || is_wp_error($author)) { @@ -429,7 +426,7 @@ public static function filter_posts_list_groupby($groupby, $query) { global $wpdb; - if (!isset($query->query_vars['author'])) { + if (!isset($query->query_vars['author']) && !isset($query->query_vars['ppma_author'])) { return $groupby; } @@ -440,7 +437,7 @@ public static function filter_posts_list_groupby($groupby, $query) return $groupby; } - $author_id = (int)$query->get('author'); + $author_id = !empty($query->query_vars['ppma_author']) ? (int)$query->queried_object_id : (int)$query->get('author'); if (empty($author_id)) { return $groupby; @@ -449,7 +446,7 @@ public static function filter_posts_list_groupby($groupby, $query) if (is_a($query->queried_object, 'WP_User')) { $author = Author::get_by_user_id($query->queried_object_id); } else { - $author = $query->queried_object; + $author = !empty($query->query_vars['ppma_author']) ? Author::get_by_term_id($author_id) : $query->queried_object; } if (!is_object($author) || is_wp_error($author)) { diff --git a/src/core/Classes/Utils.php b/src/core/Classes/Utils.php index f66618db..15503244 100644 --- a/src/core/Classes/Utils.php +++ b/src/core/Classes/Utils.php @@ -814,4 +814,62 @@ public static function sanitizeArray($array) return $sanitizedArray; } + + /** + * Helper function to check if template exist in theme/child theme. + * We couldn't use wordpress locate_template() as it support theme compact which load + * default template for files like sidebar.php even if it doesn't exist in theme + * + * @param array $template + * @return mixed + */ + public static function authors_locate_template($template_names) + { + $template = false; + + foreach ((array) $template_names as $template_name) { + if (!$template_name ) { + continue; + } + if (file_exists(STYLESHEETPATH . '/' . $template_name )) { + $template = STYLESHEETPATH . '/' . $template_name; + break; + } elseif (file_exists( TEMPLATEPATH . '/' . $template_name )) { + $template = TEMPLATEPATH . '/' . $template_name; + break; + } + } + + return $template; + } + + /** + * Get article excerpt + * + * @param integer $limit + * @param string $source + * @param boolean $echo + * @param boolean $read_more_link + * @return string + */ + public static function ppma_article_excerpt($limit, $source = null, $echo = false, $read_more_link = false) { + + $excerpt = $source == "content" ? get_the_content() : get_the_excerpt(); + $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); + $excerpt = strip_shortcodes($excerpt); + $excerpt = wp_strip_all_tags($excerpt); + $excerpt = substr($excerpt, 0, $limit); + $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); + $excerpt = trim(preg_replace('/\s+/', ' ', $excerpt)); + if ($read_more_link && !empty(trim($excerpt))) { + $excerpt = $excerpt.'... '. esc_html__('Read more.', 'publishpress-authors') .''; + } + + if ($echo) { + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo $excerpt; + } else { + return $excerpt; + } + } } diff --git a/src/core/Plugin.php b/src/core/Plugin.php index d9b06983..78b8c61b 100644 --- a/src/core/Plugin.php +++ b/src/core/Plugin.php @@ -54,7 +54,7 @@ public function __construct() { // Register our models add_action('init', [$this, 'action_init']); - add_action('init', [$this, 'action_init_late'], 15); + add_action('init', [$this, 'action_init_late'], 1001); // Installation hooks add_action( @@ -514,6 +514,16 @@ public function filter_author_taxonomy_labels($labels) */ public function action_init_late() { + $legacyPlugin = Factory::getLegacyPlugin(); + if (!empty($legacyPlugin) && isset($legacyPlugin->multiple_authors) + && isset($legacyPlugin->modules->multiple_authors->options->enable_plugin_authors_profile) + && $legacyPlugin->modules->multiple_authors->options->enable_plugin_authors_profile === 'yes' + ) { + $enable_authors_profile = true; + } else { + $enable_authors_profile = false; + } + // Register new taxonomy so that we can store all the relationships $args = [ 'labels' => [ @@ -550,7 +560,7 @@ public function action_init_late() 'menu_name' => __('Author', 'publishpress-authors'), 'back_to_items' => __('Back to Authors', 'publishpress-authors'), ], - 'public' => false, + 'public' => $enable_authors_profile ? true : false, 'hierarchical' => false, 'sort' => true, 'args' => [ @@ -567,7 +577,9 @@ public function action_init_late() 'show_in_quick_edit' => false, 'meta_box_cb' => false, 'query_var' => 'ppma_author', - 'rewrite' => false, + 'show_in_rest' => $enable_authors_profile ? true : false, + 'rest_base' => $enable_authors_profile ? 'ppma_author' : '', + 'rewrite' => $enable_authors_profile ? ['slug' => 'author', 'with_front' => true] : false, ]; // If we use the nasty SQL query, we need our custom callback. Otherwise, we still need to flush cache. @@ -577,6 +589,10 @@ public function action_init_late() $supported_post_types = Utils::get_post_types_that_support_authors(); register_taxonomy($this->coauthor_taxonomy, $supported_post_types, $args); + + if (delete_transient('ppma_flush_rewrite_rules')) { + flush_rewrite_rules(true); + } } /** @@ -1783,13 +1799,13 @@ public function shortcodeAuthorsData($attributes) if (isset($attributes['post_id'])) { $post_id = $attributes['post_id']; } - + if (isset($attributes['separator'])) { $separator = $attributes['separator']; } elseif (isset($attributes['seperator'])) { $separator = $attributes['seperator']; } - + if (isset($attributes['field'])) { $field = $attributes['field']; } diff --git a/src/modules/multiple-authors/multiple-authors.php b/src/modules/multiple-authors/multiple-authors.php index d32916b1..b4205c81 100644 --- a/src/modules/multiple-authors/multiple-authors.php +++ b/src/modules/multiple-authors/multiple-authors.php @@ -92,7 +92,8 @@ public function __construct() 'author_for_new_users' => [], 'layout' => Utils::getDefaultLayout(), 'force_empty_author' => 'no', - 'username_in_search_field' => 'no', + 'username_in_search_field' => 'no', + 'enable_plugin_authors_profile' => 'no', 'default_author_for_new_posts' => null, 'author_page_post_types' => [] ], @@ -185,7 +186,7 @@ public function init() if (!is_admin()) { add_filter('body_class', [$this, 'filter_body_class']); add_filter('comment_class', [$this, 'filterCommentClass'], 10, 5); - }else{ + } else { //author profile edit body class add_filter('admin_body_class', [$this, 'filter_admin_body_class']); } @@ -260,6 +261,9 @@ public function init() // Allow author to edit own author profile. add_filter('map_meta_cap', [$this, 'filter_term_map_meta_cap'], 10, 4); + + //add authors template + add_filter('template_include', [$this, 'authors_taxonomy_template']); } /** @@ -519,6 +523,17 @@ public function register_settings() $this->module->options_group_name . '_general' ); + add_settings_field( + 'enable_plugin_authors_profile', + __( + 'Enable custom authors profile:', + 'publishpress-authors' + ), + [$this, 'settings_enable_plugin_authors_profile'], + $this->module->options_group_name, + $this->module->options_group_name . '_general' + ); + add_settings_field( 'post_types', __('Add to these post types:', 'publishpress-authors'), @@ -1113,6 +1128,30 @@ public function settings_username_in_search_field($args = []) echo ''; } + + /** + * @param array $args + */ + public function settings_enable_plugin_authors_profile($args = []) + { + $id = $this->module->options_group_name . '_enable_plugin_authors_profile'; + $value = isset($this->module->options->enable_plugin_authors_profile) ? $this->module->options->enable_plugin_authors_profile : ''; + + echo ''; + } + /** * Default author for new posts * @@ -1360,6 +1399,10 @@ public function validate_module_settings($new_options, $module_name) $new_options['username_in_search_field'] = 'no'; } + if (!isset($new_options['enable_plugin_authors_profile'])) { + $new_options['enable_plugin_authors_profile'] = 'no'; + } + if (isset($new_options['layout'])) { /** * Filter the list of available layouts. @@ -3179,5 +3222,31 @@ public function filter_admin_body_class($classes) { return $classes; } + + /** + * Add authors template + * + * @param string $taxonomy_template + * @return string + */ + public function authors_taxonomy_template($taxonomy_template) { + + if (is_tax('author')) { + //look for authors template from theme + $taxonomy_template = locate_template( array('taxonomy-author.php') ); + if (!$taxonomy_template ) { + $taxonomy_template = PP_AUTHORS_BASE_PATH . 'src/templates/taxonomy-author.php'; + wp_enqueue_style( + 'multiple-authors-page-css', + PP_AUTHORS_ASSETS_URL . 'css/multiple-authors-page.css', + false, + PP_AUTHORS_VERSION, + 'all' + ); + } + } + + return $taxonomy_template; + } } } \ No newline at end of file diff --git a/src/modules/settings/settings.php b/src/modules/settings/settings.php index c51298f7..29071f53 100644 --- a/src/modules/settings/settings.php +++ b/src/modules/settings/settings.php @@ -326,6 +326,9 @@ public function helper_settings_validate_and_save() if (method_exists($legacyPlugin->$module_name, 'settings_save')) { $legacyPlugin->$module_name->settings_save($new_options); } + + // Flush rewrite rules due to authors page slug + set_transient('ppma_flush_rewrite_rules', true); } // Redirect back to the settings page that was submitted without any previous messages diff --git a/src/templates/taxonomy-author.php b/src/templates/taxonomy-author.php new file mode 100644 index 00000000..4ee37e95 --- /dev/null +++ b/src/templates/taxonomy-author.php @@ -0,0 +1,115 @@ + + +
+ ', ''); ?> +
+ +
+ + + + + + +
+ +
+ +

+ + +
+ + Date: Fri, 17 Jun 2022 12:00:21 +0100 Subject: [PATCH 04/30] - Load author's page asset for template copied inside theme --- src/modules/multiple-authors/multiple-authors.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/modules/multiple-authors/multiple-authors.php b/src/modules/multiple-authors/multiple-authors.php index b4205c81..15bc4b49 100644 --- a/src/modules/multiple-authors/multiple-authors.php +++ b/src/modules/multiple-authors/multiple-authors.php @@ -3236,14 +3236,14 @@ public function authors_taxonomy_template($taxonomy_template) { $taxonomy_template = locate_template( array('taxonomy-author.php') ); if (!$taxonomy_template ) { $taxonomy_template = PP_AUTHORS_BASE_PATH . 'src/templates/taxonomy-author.php'; - wp_enqueue_style( - 'multiple-authors-page-css', - PP_AUTHORS_ASSETS_URL . 'css/multiple-authors-page.css', - false, - PP_AUTHORS_VERSION, - 'all' - ); } + wp_enqueue_style( + 'multiple-authors-page-css', + PP_AUTHORS_ASSETS_URL . 'css/multiple-authors-page.css', + false, + PP_AUTHORS_VERSION, + 'all' + ); } return $taxonomy_template; From b7b6541b7b1ca0095263d61bf6dc01a28b747f1b Mon Sep 17 00:00:00 2001 From: Ojo Paul Date: Mon, 20 Jun 2022 15:16:13 +0100 Subject: [PATCH 05/30] - Fix author's profile slug for authors page --- src/core/Classes/Content_Model.php | 48 +++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/src/core/Classes/Content_Model.php b/src/core/Classes/Content_Model.php index 4b319c67..a9d6bae8 100644 --- a/src/core/Classes/Content_Model.php +++ b/src/core/Classes/Content_Model.php @@ -10,6 +10,7 @@ namespace MultipleAuthors\Classes; use MultipleAuthors\Classes\Objects\Author; +use MultipleAuthors\Factory; /** * Declaration of the content model @@ -51,15 +52,28 @@ public static function filter_term_link($link, $term, $taxonomy) return $link; } - $author = Author::get_by_term_id($term->term_id); - $author_slug = is_object($author) ? $author->slug : ''; - $permastruct = $wp_rewrite->get_author_permastruct(); + $legacyPlugin = Factory::getLegacyPlugin(); - if ($permastruct) { - $link = str_replace('%author%', $author_slug, $permastruct); - $link = home_url(user_trailingslashit($link)); + if (!empty($legacyPlugin) && isset($legacyPlugin->multiple_authors) + && isset($legacyPlugin->modules->multiple_authors->options->enable_plugin_author_pages) + && $legacyPlugin->modules->multiple_authors->options->enable_plugin_author_pages === 'yes' + ) { + $enable_authors_profile = true; } else { - $link = add_query_arg('author_name', rawurlencode($author_slug), home_url() . '/'); + $enable_authors_profile = false; + } + + if (!$enable_authors_profile) { + $author = Author::get_by_term_id($term->term_id); + $author_slug = is_object($author) ? $author->slug : ''; + $permastruct = $wp_rewrite->get_author_permastruct(); + + if ($permastruct) { + $link = str_replace('%author%', $author_slug, $permastruct); + $link = home_url(user_trailingslashit($link)); + } else { + $link = add_query_arg('author_name', rawurlencode($author_slug), home_url() . '/'); + } } return $link; @@ -77,9 +91,20 @@ public static function filter_author_link($link, $author_id) { global $wp_rewrite; + $legacyPlugin = Factory::getLegacyPlugin(); + + if (!empty($legacyPlugin) && isset($legacyPlugin->multiple_authors) + && isset($legacyPlugin->modules->multiple_authors->options->enable_plugin_author_pages) + && $legacyPlugin->modules->multiple_authors->options->enable_plugin_author_pages === 'yes' + ) { + $enable_authors_profile = true; + } else { + $enable_authors_profile = false; + } + $permastruct = $wp_rewrite->get_author_permastruct(); - if (empty($permastruct)) { + if (empty($permastruct) && !$enable_authors_profile) { return $link; } @@ -93,6 +118,13 @@ public static function filter_author_link($link, $author_id) } } + if ($enable_authors_profile) { + $author_data = Author::get_by_user_id($author_id); + if (is_object($author_data)) { + return get_term_link($author_data->term_id); + } + } + $link_path = str_replace(home_url(), '', $link); // Check if the author slug is empty in the link. From 0af9c5f2dcde20f1dec1d84209f53c6085e9d938 Mon Sep 17 00:00:00 2001 From: Ojo Paul Date: Mon, 20 Jun 2022 15:18:09 +0100 Subject: [PATCH 06/30] - Add author pages settings tab and it options --- src/core/Plugin.php | 4 +- .../multiple-authors/multiple-authors.php | 527 +++++++++++++++++- 2 files changed, 509 insertions(+), 22 deletions(-) diff --git a/src/core/Plugin.php b/src/core/Plugin.php index 78b8c61b..371463ff 100644 --- a/src/core/Plugin.php +++ b/src/core/Plugin.php @@ -516,8 +516,8 @@ public function action_init_late() { $legacyPlugin = Factory::getLegacyPlugin(); if (!empty($legacyPlugin) && isset($legacyPlugin->multiple_authors) - && isset($legacyPlugin->modules->multiple_authors->options->enable_plugin_authors_profile) - && $legacyPlugin->modules->multiple_authors->options->enable_plugin_authors_profile === 'yes' + && isset($legacyPlugin->modules->multiple_authors->options->enable_plugin_author_pages) + && $legacyPlugin->modules->multiple_authors->options->enable_plugin_author_pages === 'yes' ) { $enable_authors_profile = true; } else { diff --git a/src/modules/multiple-authors/multiple-authors.php b/src/modules/multiple-authors/multiple-authors.php index 15bc4b49..69970acb 100644 --- a/src/modules/multiple-authors/multiple-authors.php +++ b/src/modules/multiple-authors/multiple-authors.php @@ -93,7 +93,18 @@ public function __construct() 'layout' => Utils::getDefaultLayout(), 'force_empty_author' => 'no', 'username_in_search_field' => 'no', - 'enable_plugin_authors_profile' => 'no', + 'enable_plugin_author_pages' => 'no', + 'author_pages_layout' => 'list', + 'show_author_pages_description' => 'yes', + 'show_author_pages_avatar' => 'yes', + 'show_author_post_featured_image' => 'yes', + 'show_author_post_excerpt' => 'yes', + 'show_author_post_authors' => 'yes', + 'show_author_post_date' => 'yes', + 'show_author_post_comments' => 'yes', + 'show_author_post_category' => 'yes', + 'show_author_post_tags' => 'yes', + 'show_author_post_readmore' => 'yes', 'default_author_for_new_posts' => null, 'author_page_post_types' => [] ], @@ -264,6 +275,9 @@ public function init() //add authors template add_filter('template_include', [$this, 'authors_taxonomy_template']); + + //author redirect + add_action('template_redirect', [$this, 'authors_template_redirect']); } /** @@ -523,17 +537,6 @@ public function register_settings() $this->module->options_group_name . '_general' ); - add_settings_field( - 'enable_plugin_authors_profile', - __( - 'Enable custom authors profile:', - 'publishpress-authors' - ), - [$this, 'settings_enable_plugin_authors_profile'], - $this->module->options_group_name, - $this->module->options_group_name . '_general' - ); - add_settings_field( 'post_types', __('Add to these post types:', 'publishpress-authors'), @@ -653,6 +656,149 @@ public function register_settings() $this->module->options_group_name . '_display' ); + /** + * Author Pages + */ + + add_settings_section( + $this->module->options_group_name . '_author_pages', + __return_false(), + [$this, 'settings_section_author_pages'], + $this->module->options_group_name + ); + + add_settings_field( + 'enable_plugin_author_pages', + __( + 'Enable author pages:', + 'publishpress-authors' + ), + [$this, 'settings_enable_plugin_author_pages'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'author_pages_layout', + __( + 'Author pages layout:', + 'publishpress-authors' + ), + [$this, 'settings_author_pages_layout'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_pages_description', + __( + 'Show author description:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_pages_description'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_pages_avatar', + __( + 'Show author avatar:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_pages_avatar'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_post_featured_image', + __( + 'Show featured image:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_post_featured_image'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_post_excerpt', + __( + 'Show excerpt:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_post_excerpt'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_post_authors', + __( + 'Show authors:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_post_authors'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_post_date', + __( + 'Show post date:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_post_date'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_post_comments', + __( + 'Show comment counts:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_post_comments'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_post_category', + __( + 'Show Category:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_post_category'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_post_tags', + __( + 'Show tags:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_post_tags'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + + add_settings_field( + 'show_author_post_readmore', + __( + 'Show read more link:', + 'publishpress-authors' + ), + [$this, 'settings_show_author_post_readmore'], + $this->module->options_group_name, + $this->module->options_group_name . '_author_pages' + ); + /** * Shortcodes @@ -709,6 +855,11 @@ public function settings_section_display() echo ''; } + public function settings_section_author_pages() + { + echo ''; + } + public function settings_section_shortcodes() { echo ''; @@ -1132,18 +1283,289 @@ public function settings_username_in_search_field($args = []) /** * @param array $args */ - public function settings_enable_plugin_authors_profile($args = []) + public function settings_enable_plugin_author_pages($args = []) + { + $id = $this->module->options_group_name . '_enable_plugin_author_pages'; + $value = isset($this->module->options->enable_plugin_author_pages) ? $this->module->options->enable_plugin_author_pages : ''; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_author_pages_layout($args = []) + { + $id = $this->module->options_group_name . '_author_pages_layout'; + $value = isset($this->module->options->author_pages_layout) ? $this->module->options->author_pages_layout : 'list'; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_pages_description($args = []) + { + $id = $this->module->options_group_name . '_show_author_pages_description'; + $value = isset($this->module->options->show_author_pages_description) ? $this->module->options->show_author_pages_description : ''; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_pages_avatar($args = []) + { + $id = $this->module->options_group_name . '_show_author_pages_avatar'; + $value = isset($this->module->options->show_author_pages_avatar) ? $this->module->options->show_author_pages_avatar : ''; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_post_featured_image($args = []) + { + $id = $this->module->options_group_name . '_show_author_post_featured_image'; + $value = isset($this->module->options->show_author_post_featured_image) ? $this->module->options->show_author_post_featured_image : ''; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_post_excerpt($args = []) { - $id = $this->module->options_group_name . '_enable_plugin_authors_profile'; - $value = isset($this->module->options->enable_plugin_authors_profile) ? $this->module->options->enable_plugin_authors_profile : ''; + $id = $this->module->options_group_name . '_show_author_post_excerpt'; + $value = isset($this->module->options->show_author_post_excerpt) ? $this->module->options->show_author_post_excerpt : ''; echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_post_authors($args = []) + { + $id = $this->module->options_group_name . '_show_author_post_authors'; + $value = isset($this->module->options->show_author_post_authors) ? $this->module->options->show_author_post_authors : ''; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_post_date($args = []) + { + $id = $this->module->options_group_name . '_show_author_post_date'; + $value = isset($this->module->options->show_author_post_date) ? $this->module->options->show_author_post_date : ''; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_post_comments($args = []) + { + $id = $this->module->options_group_name . '_show_author_post_comments'; + $value = isset($this->module->options->show_author_post_comments) ? $this->module->options->show_author_post_comments : ''; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_post_category($args = []) + { + $id = $this->module->options_group_name . '_show_author_post_category'; + $value = isset($this->module->options->show_author_post_category) ? $this->module->options->show_author_post_category : ''; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_post_tags($args = []) + { + $id = $this->module->options_group_name . '_show_author_post_tags'; + $value = isset($this->module->options->show_author_post_tags) ? $this->module->options->show_author_post_tags : ''; + + echo ''; + } + + + /** + * @param array $args + */ + public function settings_show_author_post_readmore($args = []) + { + $id = $this->module->options_group_name . '_show_author_post_readmore'; + $value = isset($this->module->options->show_author_post_readmore) ? $this->module->options->show_author_post_readmore : ''; + + echo '