Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
umdevelopera committed Nov 26, 2024
1 parent 2dd66df commit feae346
Show file tree
Hide file tree
Showing 7 changed files with 547 additions and 1 deletion.
91 changes: 90 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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 [email protected]: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)
69 changes: 69 additions & 0 deletions includes/core/class-common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Common functionality.
*/

namespace um_ext\um_cpt\core;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}


/**
* Class Common.
*
* @package um_ext\um_cpt\core
*/
class Common {


/**
* Common constructor.
*/
public function __construct() {
add_filter( 'um_core_pages', array( $this, 'core_pages' ) );
add_filter( 'um_setup_predefined_page_content', array( $this, 'pages_content' ), 10, 2 );
}


/**
* Add pages.
*
* @param array $pages Predefined pages.
*
* @return array Predefined pages.
*/
function core_pages( $pages ) {
if ( defined( 'um_groups_version' ) ) {
$pages['cpt_group'] = array(
'title' => __( '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;
}

}
153 changes: 153 additions & 0 deletions includes/core/class-frontend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php
/**
* Frontend functionality.
*/

namespace um_ext\um_cpt\core;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}


/**
* Class Frontend.
*
* @package um_ext\um_cpt\core
*/
class Frontend {


/**
* Frontend constructor.
*/
public function __construct() {
if ( defined( 'um_groups_version' ) ) {
add_shortcode( 'um_single_group', array( $this, 'single_group' ) );
}
if ( defined( 'JB_VERSION' ) ) {
add_shortcode( 'um_single_job', array( $this, 'single_job' ) );
}
add_action( 'init', array( $this, 'init' ), 20 );
}


/**
* Hooks.
*/
public function init() {
if ( defined( 'um_groups_version' ) ) {
remove_filter( 'the_content', 'groups_single_remove_content', 10 );
add_filter( 'the_content', array( $this, 'single_group_content' ), 20, 1 );
}
if ( defined( 'JB_VERSION' ) ) {
JB()->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( ']]>', ']]&gt;', $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( ']]>', ']]&gt;', $content );
}
}
}
}
return $content;
}

}
80 changes: 80 additions & 0 deletions includes/core/class-um-cpt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Init the extension.
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Class UM_CPT.
*
* @package um_ext\um_cpt\core
*/
class UM_CPT {


/**
* An instance of the class.
*
* @var UM_CPT
*/
private static $instance;


/**
* Creates an instance of the class.
*
* @return UM_CPT
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}


/**
* UM_CPT constructor.
*/
public function __construct() {
$this->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'];
}
}
Loading

0 comments on commit feae346

Please sign in to comment.