Skip to content

Commit

Permalink
Merge pull request #7 from a8cteam51/feat/add-sibling-pages-list-block
Browse files Browse the repository at this point in the history
feat(hermann-park): add sibling pages list block
  • Loading branch information
chrisbellboy committed Jun 26, 2024
2 parents bb374cf + 586dd9e commit 0bdeb8a
Show file tree
Hide file tree
Showing 17 changed files with 18,883 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sibling-pages-list/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.{yml,yaml}]
indent_style = space
indent_size = 2
30 changes: 30 additions & 0 deletions sibling-pages-list/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Coverage directory used by tools like istanbul
coverage

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Output of `npm pack`
*.tgz

# Output of `wp-scripts plugin-zip`
*.zip

# dotenv environment variables file
.env
5 changes: 5 additions & 0 deletions sibling-pages-list/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 1.0.0 (2024-06-25)

### New Features

- Initial version.
20 changes: 20 additions & 0 deletions sibling-pages-list/build/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "wpsp/sibling-pages-list",
"version": "0.1.0",
"title": "Sibling Pages List",
"category": "widgets",
"description": "Displays a list of the current page's sibling pages",
"example": {},
"supports": {
"html": false
},
"usesContext": [
"postId",
"postType"
],
"textdomain": "sibling-pages-list",
"editorScript": "file:./index.js",
"render": "file:./render.php"
}
1 change: 1 addition & 0 deletions sibling-pages-list/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => '9db8f06fb59babc96b53');
1 change: 1 addition & 0 deletions sibling-pages-list/build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions sibling-pages-list/build/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Render the block on the frontend.
*
* The following variables are exposed:
* $attributes (array): The block attributes.
* $content (string): The block default content.
* $block (WP_Block): The block instance.
*
* @see https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/block-api/block-metadata.md#render
*/

if ( 'page' !== $block->context['postType'] ) {
return;
}

$parent_page_id = wp_get_post_parent_id( $block->context['postId'] );

if ( false === $parent_page_id ) {
return;
}

$sibling_pages = get_pages(
array(
'parent' => $parent_page_id,
'sort_column' => 'menu_order',
)
);
?>
<div <?php echo wp_kses_post( get_block_wrapper_attributes() ); ?>>
<ul>
<?php foreach ( $sibling_pages as $sibling_page ) { ?>

<?php if ( get_the_ID() === $sibling_page->ID ) { ?>
<li>
<?php echo wp_kses_post( $sibling_page->post_title ); ?>
</li>
<?php } else { ?>
<li>
<a href="<?php echo esc_url( get_permalink( $sibling_page->ID ) ); ?>">
<?php echo wp_kses_post( $sibling_page->post_title ); ?>
</a>
</li>
<?php } ?>

<?php } ?>
</ul>
</div>

80 changes: 80 additions & 0 deletions sibling-pages-list/classes/class-wpsp-blocks-self-update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Plugin Autoupdate Filter Self Update class.
* sets up autoupdates for this GitHub-hosted plugin.
*
* @package wpsp
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

class WPSP_Blocks_Self_Update {

public static $instance;

/**
* Get instance of this class.
*
* @return WPSP_Blocks_Self_Update
*/
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new self();
}

return self::$instance;
}

/**
* Initialize WordPress hooks
*/
public function hooks() {
add_filter( 'update_plugins_opsoasis-develop.mystagingwebsite.com', array( $this, 'self_update' ), 10, 3 );
}

/**
* Check for updates to this plugin
*
* @param array $update Array of update data.
* @param array $plugin_data Array of plugin data.
* @param string $plugin_file Path to plugin file.
*
* @return array|bool Array of update data or false if no update available.
*/
public function self_update( $update, array $plugin_data, string $plugin_file ) {
// Already completed update check elsewhere.
if ( ! empty( $update ) ) {
return $update;
}

$plugin_filename_parts = explode( '/', $plugin_file );

// Ask opsoasis.mystagingwebsite.com if there's an update.
$response = wp_remote_get(
'https://opsoasis-develop.mystagingwebsite.com/wp-json/opsoasis-blocks-version-manager/v1/update-check',
array(
'body' => array(
'plugin' => $plugin_filename_parts[0],
'version' => $plugin_data['Version'],
),
)
);

// Bail if this plugin wasn't found on opsoasis.mystagingwebsite.com.
if ( 404 === wp_remote_retrieve_response_code( $response ) || 202 === wp_remote_retrieve_response_code( $response ) ) {
return $update;
}

$updated_version = wp_remote_retrieve_body( $response );
$updated_array = json_decode( $updated_version, true );

return array(
'slug' => $updated_array['slug'],
'version' => $updated_array['version'],
'url' => $updated_array['package_url'],
'package' => $updated_array['package_url'],
);
}
}
Loading

0 comments on commit 0bdeb8a

Please sign in to comment.