-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from a8cteam51/feat/add-sibling-pages-list-block
feat(hermann-park): add sibling pages list block
- Loading branch information
Showing
17 changed files
with
18,883 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## 1.0.0 (2024-06-25) | ||
|
||
### New Features | ||
|
||
- Initial version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
80
sibling-pages-list/classes/class-wpsp-blocks-self-update.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
); | ||
} | ||
} |
Oops, something went wrong.