From feae346d58f0f04f5b6626d3b6bbbabe3fa91941 Mon Sep 17 00:00:00 2001 From: umdevelopera Date: Tue, 26 Nov 2024 22:41:08 +0200 Subject: [PATCH] version 1.0.0 --- README.md | 91 +++++++++++++++++- includes/core/class-common.php | 69 ++++++++++++++ includes/core/class-frontend.php | 153 +++++++++++++++++++++++++++++++ includes/core/class-um-cpt.php | 80 ++++++++++++++++ languages/um-cpt.pot | 56 +++++++++++ readme.txt | 45 +++++++++ um-cpt.php | 54 +++++++++++ 7 files changed, 547 insertions(+), 1 deletion(-) create mode 100644 includes/core/class-common.php create mode 100644 includes/core/class-frontend.php create mode 100644 includes/core/class-um-cpt.php create mode 100644 languages/um-cpt.pot create mode 100644 readme.txt create mode 100644 um-cpt.php diff --git a/README.md b/README.md index 34f2b52..d96d449 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,91 @@ -# um-cpt +# Ultimate Member - Template pages for CPT + Adds special pages used to customize the single post view for Groups and Jobs. + +Groups and Jobs are custom post type (CPT) with predefined content. +You can edit these views by overridden template files, see “Alternative solution for developers” below. +But this solution requires experience in WEB developing. You should be familiar with PHP to edit template files. +This plugin creates special pages that can be edited with a page builder and places predefined content (a group or a job) inside this page using a shortcode. + +## Key features +- Ability to customize the single group view of the [Groups](https://ultimatemember.com/extensions/groups/) extension with a page builder. +- Ability to customize the single job view of the [JobBoardWP](https://wordpress.org/plugins/jobboardwp/) plugin with a page builder. + +## Installation + +__Note:__ This plugin requires the [Ultimate Member](https://wordpress.org/plugins/ultimate-member/) plugin to be installed first. + +### How to install from GitHub + +Open git bash, navigate to the **plugins** folder and execute this command: + +`git clone --branch=main git@github.com:umdevelopera/um-cpt.git um-cpt` + +Once the plugin is cloned, enter your site admin dashboard and go to _wp-admin > Plugins > Installed Plugins_. Find the **Ultimate Member - Template pages for CPT** plugin and click the **Activate** link. + +### How to install from ZIP archive + +You can install this plugin from the [ZIP file](https://drive.google.com/file/d/14O8yOuJcI9sAhv2sEaM1qi9PRNAFFJfK/view) as any other plugin. Follow [this instruction](https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin). + +## How to use + +### Instruction +1) Install the **Ultimate Member - Template pages for CPT** plugin. +2) Go to _wp-admin > Ultimate Member > Settings > Pages_ and create the **Single Group template** and **Single Job template** pages. +3) Go to _wp-admin > Pages_ and search for the **Single Group template** and **Single Job template** pages. +4) Edit the **Single Group template** and **Single Job template** pages with your page builder. + The **Single Group template** must contain the `[um_single_group]` shortcode. + The **Single Job template** page must contain the `[um_single_job]` shortcode. + You can add any blocks you need above and below the shortcode or wrap the shortcode into a block. +5) Test the group view and the job view + +### Illustrations + +Step 1 - Install the **Ultimate Member - Template pages for CPT** plugin. +![1 - install plugin](https://github.com/user-attachments/assets/09a253df-23be-4d18-98e8-a682b8854f0d) + +Step 2 - Create the **Single Group template** and **Single Job template** pages. +![2 - create pages](https://github.com/user-attachments/assets/ed6be401-254d-40e4-84d5-28b49ae26f00) + +Step 3 - Go to _wp-admin > Pages_. +![3 - pages](https://github.com/user-attachments/assets/75956083-a5c6-425c-8d57-51a7cc8225eb) + +Step 4 - Edit the **Single Group template** and **Single Job template** pages with the page builder. +![4 - group template](https://github.com/user-attachments/assets/9e653d49-5460-441c-894a-00a3f46f3691) + +Step 5 - Test the group view and the job view. +![5 - group test](https://github.com/user-attachments/assets/faa78a55-2d05-4f64-a49e-ff2aef675b61) + +## Alternative solution for developers + +The common layout of the single group view is rendered using the _single.php_ template file in the theme. +You can override and customize the _single.php_ template file in the child theme or create the _single-um_groups.php_ template file for groups. + +The inner layout of the single group view is rendered using the _/wp-content/plugins/um-groups/templates/single.php_ template file. +You can override and customize this template file in the child theme - follow instructions in [this article](https://docs.ultimatemember.com/article/1516-templates-map). + +The common layout of the single job view is rendered using the _single.php_ template file in the theme. +You can override and customize the _single.php_ template file in the child theme or create the _single-jb-job.php_ template file for jobs. + +The inner layout of the single job view is rendered using the _/wp-content/plugins/jobboardwp/templates/single-job.php_ template file. +You can override and customize this template file in the child theme - follow instructions in [this article](https://docs.jobboardwp.com/article/1570-templates-structure). + +See also information about the single post template in [Template Hierarchy](https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post). + +## Support + +This is a free extension created for the community. The Ultimate Member team does not provide support for this extension. + +Open new [issue](https://github.com/umdevelopera/um-account-tabs/issues) if you are facing a problem or have a suggestion. + +### Related links + +Ultimate Member home page: https://ultimatemember.com + +Ultimate Member documentation: https://docs.ultimatemember.com + +Ultimate Member download: https://wordpress.org/plugins/ultimate-member + +--- + +[Free extensions for Ultimate Member](https://docs.google.com/document/d/1wp5oLOyuh5OUtI9ogcPy8NL428rZ8PVTu_0R-BuKKp8/edit?usp=sharing) diff --git a/includes/core/class-common.php b/includes/core/class-common.php new file mode 100644 index 0000000..7adab83 --- /dev/null +++ b/includes/core/class-common.php @@ -0,0 +1,69 @@ + __( 'Single Group template', 'um-cpt' ), + ); + } + if ( defined( 'JB_VERSION' ) ) { + $pages['cpt_job'] = array( + 'title' => __( 'Single Job template', 'um-cpt' ), + ); + } + return $pages; + } + + + /** + * Predefined pages content. + * + * @param string $content Predefined page content. + * @param string $slug Predefined page slug (key). + * + * @return string Predefined page content. + */ + public function pages_content( $content, $slug ) { + if ( 'cpt_group' === $slug ) { + $content = '[um_single_group]'; + } elseif ( 'cpt_job' === $slug ) { + $content = '[um_single_job]'; + } + return $content; + } + +} diff --git a/includes/core/class-frontend.php b/includes/core/class-frontend.php new file mode 100644 index 0000000..cc4f418 --- /dev/null +++ b/includes/core/class-frontend.php @@ -0,0 +1,153 @@ +options()->update( 'job-template', 'default' ); + remove_filter( 'the_content', array( JB()->frontend()->templates(), 'cpt_content' ), 10 ); + add_filter( 'the_content', array( $this, 'single_job_content' ), 20, 1 ); + } + } + + + /** + * Single group shortcode. + * + * @param array $attr { + * Attributes of the shortcode. + * + * @type int group_id The group ID. + * @type string avatar_size Avatar size. Accepts 'small'. Default ''. + * @type int show_actions Show a section with buttons if 1. Default 1. + * @type int show_author Show the group author if 1. Default 1. + * } + * @return string + */ + public function single_group( $attr ) { + if ( 'um_groups' === get_post_type() ) { + $attr['group_id'] = get_the_ID(); + return UM()->Groups()->shortcode()->single( $attr ); + } + } + + + /** + * Render the group view. + * + * Called via the 'the_content' hook with priority 20. + * + * @param string $content The post content. + * + * @return string The post content. + */ + public function single_group_content( $content ) { + if ( is_single() && 'um_groups' === get_post_type() ) { + $page_id = um_get_predefined_page_id( 'cpt_group' ); + if ( $page_id ) { + $page = get_post( $page_id ); + if ( $page && false !== strpos( $page->post_content, '[um_single_group]' ) ) { + $template = wpautop( $page->post_content ); + if ( function_exists( 'um_convert_tags' ) ) { + $template = um_convert_tags( $template, array(), false ); + } + + $content = apply_shortcodes( $template ); + if ( $content ) { + $content = str_replace( ']]>', ']]>', $content ); + } + } + } + } + return $content; + } + + + /** + * Single job shortcode. + * + * @param array $attr { + * Attributes of the shortcode. + * + * @type int id The job ID. + * @type bool ignore_status Internal argument. Default false. + * } + * @return string + */ + public function single_job( $attr ) { + if ( 'jb-job' === get_post_type() ) { + $attr['id'] = get_the_ID(); + $attr['ignore_status'] = true; + return JB()->frontend()->shortcodes()->single_job( $attr ); + } + } + + + /** + * Render the job view. + * + * Called via the 'the_content' hook with priority 20. + * + * @param string $content The post content. + * + * @return string The post content. + */ + public function single_job_content( $content ) { + if ( is_single() && 'jb-job' === get_post_type() ) { + $page_id = um_get_predefined_page_id( 'cpt_job' ); + if ( $page_id ) { + $page = get_post( $page_id ); + if ( $page && false !== strpos( $page->post_content, '[um_single_job]' ) ) { + $template = wpautop( $page->post_content ); + if ( function_exists( 'um_convert_tags' ) ) { + $template = um_convert_tags( $template, array(), false ); + } + + $content = apply_shortcodes( $template ); + if ( $content ) { + $content = str_replace( ']]>', ']]>', $content ); + } + } + } + } + return $content; + } + +} diff --git a/includes/core/class-um-cpt.php b/includes/core/class-um-cpt.php new file mode 100644 index 0000000..dd694cd --- /dev/null +++ b/includes/core/class-um-cpt.php @@ -0,0 +1,80 @@ +common(); + if( UM()->is_ajax() ) { + + } elseif ( UM()->is_request( 'admin' ) ) { + + } elseif ( UM()->is_request( 'frontend' ) ) { + $this->frontend(); + } + } + + + /** + * Common functionality. + * + * @return um_ext\um_cpt\core\Common() + */ + public function common() { + if ( empty( UM()->classes['um_cpt_common'] ) ) { + require_once um_cpt_path . 'includes/core/class-common.php'; + UM()->classes['um_cpt_common'] = new um_ext\um_cpt\core\Common(); + } + return UM()->classes['um_cpt_common']; + } + + + /** + * Frontend functionality. + * + * @return um_ext\um_cpt\core\Frontend() + */ + public function frontend() { + if ( empty( UM()->classes['um_cpt_frontend'] ) ) { + require_once um_cpt_path . 'includes/core/class-frontend.php'; + UM()->classes['um_cpt_frontend'] = new um_ext\um_cpt\core\Frontend(); + } + return UM()->classes['um_cpt_frontend']; + } +} diff --git a/languages/um-cpt.pot b/languages/um-cpt.pot new file mode 100644 index 0000000..7ba2df0 --- /dev/null +++ b/languages/um-cpt.pot @@ -0,0 +1,56 @@ +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: Ultimate Member - Template pages for CPT\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-11-26 19:39+0000\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: \n" +"Language: \n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Loco https://localise.biz/\n" +"X-Loco-Version: 2.6.14; wp-6.7.1\n" +"X-Domain: um-cpt" + +#. Description of the plugin +msgid "" +"Adds special pages used to customize the single post view for Groups and " +"Jobs." +msgstr "" + +#. Author URI of the plugin +msgid "https://github.com/umdevelopera/" +msgstr "" + +#. URI of the plugin +msgid "https://github.com/umdevelopera/um-cpt" +msgstr "" + +#: includes/core/class-common.php:40 +msgid "Single Group template" +msgstr "" + +#: includes/core/class-common.php:45 +msgid "Single Job template" +msgstr "" + +#. %s - plugin name. +#: um-cpt.php:45 +#, php-format +msgid "" +"The %s extension requires the Ultimate Member plugin to be " +"activated to work properly. You can download it here" +msgstr "" + +#. Name of the plugin +msgid "Ultimate Member - Template pages for CPT" +msgstr "" + +#. Author of the plugin +msgid "Ultimate Member support team" +msgstr "" diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..45d1f9d --- /dev/null +++ b/readme.txt @@ -0,0 +1,45 @@ +=== Ultimate Member - Template pages for CPT === + +Author: umdevelopera +Author URI: https://github.com/umdevelopera +Plugin URI: https://github.com/umdevelopera/um-cpt +Tags: ultimate member, groups, jobs, template +License: GNU Version 2 or Any Later Version +License URI: http://www.gnu.org/licenses/gpl-3.0.txt + +Requires at least: 6.5 +Tested up to: 6.7 +Requires UM core at least: 2.6.8 +Tested UM core up to: 2.9.1 +Stable tag: 1.0.0 + +== Description == + +Adds special pages used to customize the single post view for Groups and Jobs. + +Groups and Jobs are custom post type (CPT) with predefined content. You can not edit these post's views with a page builder. +This plugin creates special pages that can be edited with a page builder and places predefined content (a group or a job) inside this page using a shortcode. + += Key Features = + +- Ability to customize the single group view of the "Ultimate Member - Groups" plugin with a page builder. +- Ability to customize the single job view of the "JobBoardWP" plugin with a page builder. + += Documentation & Support = + +This is a free extension created for the community. The Ultimate Member team does not provide support for this extension. +Open new issue in the GitHub repository if you face a problem: https://github.com/umdevelopera/um-cpt/issues + +Documentation is the README section in the GitHub repository: https://github.com/umdevelopera/um-cpt + +== Installation == + +You can install this plugin from the ZIP file as any other plugin. +Download ZIP file from GitHub or Google Drive. +Follow this instruction: https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin + +== Changelog == + += 1.0.0: November 26, 2024 = + + - Initial release. \ No newline at end of file diff --git a/um-cpt.php b/um-cpt.php new file mode 100644 index 0000000..c60952e --- /dev/null +++ b/um-cpt.php @@ -0,0 +1,54 @@ +dependencies()->ultimatemember_active_check() ) { + // Ultimate Member is not active. + add_action( + 'admin_notices', + function () { + // translators: %s - plugin name. + echo '

' . wp_kses_post( sprintf( __( 'The %s extension requires the Ultimate Member plugin to be activated to work properly. You can download it here', 'um-cpt' ), um_cpt_extension ) ) . '

'; + } + ); + } else { + require_once 'includes/core/class-um-cpt.php'; + UM()->set_class( 'CPT', true ); + } + } +} +add_action( 'plugins_loaded', 'um_cpt_check_dependencies', 2 );