-
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.
Add block for display register, login links.
- Loading branch information
Showing
20 changed files
with
18,894 additions
and
21 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,5 @@ | ||
##Blocks | ||
|
||
* Run `npm run start` to start editing blocks. | ||
* Run `npm run build` to build the blocks. | ||
|
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
Use this command: | ||
`wp i18n make-pot . --exclude="assets,languages,*.css,*.js,*.svg,*.eot,*.woff,*.woff2,*.ttf,*.html,*.txt,*.pot"` | ||
And check the result. | ||
Use this command: | ||
`wp i18n make-pot . --exclude="assets,block-src,languages,*.css,*.js,*.svg,*.eot,*.woff,*.woff2,*.ttf,*.html,*.txt,*.pot"` | ||
And check the result. | ||
|
||
Convert to JSON to make block i18n supported with this command: | ||
`wp i18n make-json languages/okv-oauth-th.po --no-purge --pretty-print` | ||
and rename **${domain}-${locale}-${md5}.json** to **${domain}-${locale}-${handle}.json** where `${handle}` is from `wp_set_script_translations()` function in 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,43 @@ | ||
<?php | ||
/** | ||
* Login links block. | ||
* | ||
* @package rundiz-oauth | ||
*/ | ||
|
||
|
||
namespace RundizOauth\App\Controllers\Blocks; | ||
|
||
|
||
if (!class_exists('RundizOauth\App\Controllers\Blocks\\LoginLinks')) { | ||
class LoginLinks implements \RundizOauth\App\Controllers\ControllerInterface | ||
{ | ||
|
||
|
||
/** | ||
* Register block. | ||
*/ | ||
public function registerBlock() | ||
{ | ||
register_block_type( | ||
dirname(RUNDIZOAUTH_FILE) . DIRECTORY_SEPARATOR . 'blocks' . DIRECTORY_SEPARATOR . 'loginlinks' | ||
); | ||
|
||
if (function_exists('wp_set_script_translations')) { | ||
wp_set_script_translations('rd-oauth-loginlinks-block-script', 'okv-oauth', str_replace([DIRECTORY_SEPARATOR], '/', plugin_dir_path(RUNDIZOAUTH_FILE)) . 'languages'); | ||
} | ||
}// registerBlock | ||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function registerHooks() | ||
{ | ||
add_action('init', [$this, 'registerBlock']); | ||
}// registerHooks | ||
|
||
|
||
} | ||
} | ||
|
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,44 @@ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import { | ||
useBlockProps, | ||
InspectorControls | ||
} from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import ServerSideRender from '@wordpress/server-side-render'; | ||
import { ToggleControl } from '@wordpress/components'; | ||
|
||
import metadata from './block.json'; | ||
|
||
// import scss to make script build compile to css otherwise it won't work. | ||
import './style.scss'; | ||
|
||
registerBlockType( metadata.name, { | ||
edit: ({attributes, setAttributes}) => { | ||
const { | ||
displayLinkToAdmin | ||
} = attributes; | ||
|
||
console.log(__('Display link to admin dashboard', 'okv-oauth')); | ||
return <p {...useBlockProps()}> | ||
<ServerSideRender | ||
block="rd-oauth/blocks-loginlinks" | ||
attributes={ attributes.attributes } | ||
label="hello label" | ||
checked="{displayLinkToAdmin}" | ||
/> | ||
<InspectorControls key="setting"> | ||
<div id="rd-oauth-loginlinks-controls" class="components-panel__body is-opened"> | ||
<fieldset> | ||
<ToggleControl | ||
label={__('Display link to admin dashboard', 'okv-oauth')} | ||
checked={ displayLinkToAdmin } | ||
onChange={ () => setAttributes({ | ||
displayLinkToAdmin: !displayLinkToAdmin | ||
}) } | ||
/> | ||
</fieldset> | ||
</div> | ||
</InspectorControls> | ||
</p>; | ||
}, | ||
} ); |
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,22 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"attributes": { | ||
"displayLinkToAdmin": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
}, | ||
"category": "theme", | ||
"description": "Display login, register, logout links.", | ||
"editorScript": "file:./block.js", | ||
"icon": "admin-users", | ||
"name": "rd-oauth/blocks-loginlinks", | ||
"render": "file:./render.php", | ||
"style": ["file:./style-block.css", "rd-oauth-loginlinks-block-style"], | ||
"supports": { | ||
"className": true | ||
}, | ||
"textdomain": "okv-oauth", | ||
"title": "Login links" | ||
} |
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 @@ | ||
<?php | ||
/** | ||
* Render contents for loginlinks block. | ||
* | ||
* @package rundiz-oauth | ||
*/ | ||
|
||
|
||
$currentUrl = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | ||
$isUserLoggedIn = is_user_logged_in(); | ||
$classes = ($isUserLoggedIn ? 'logged-in' : 'logged-out'); | ||
$contents = ''; | ||
|
||
if (!$isUserLoggedIn && get_option('users_can_register')) { | ||
$contents .= '<li><a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a></li>' . PHP_EOL; | ||
} elseif ($isUserLoggedIn && isset($attributes) && is_array($attributes) && array_key_exists('displayLinkToAdmin', $attributes) && $attributes['displayLinkToAdmin'] === true) { | ||
$contents .= '<li><a href="' . admin_url() . '">' . __( 'Site Admin' ) . '</a></li>' . PHP_EOL; | ||
} | ||
unset($isUserLoggedIn); | ||
|
||
$contents .= '<li>' . wp_loginout($currentUrl, false) . '</li>' . PHP_EOL; | ||
unset($currentUrl); | ||
|
||
$wrapperAttributes = get_block_wrapper_attributes(['class' => $classes]); | ||
|
||
unset($classes); | ||
|
||
// must use echo, not return. | ||
echo '<ul ' . $wrapperAttributes . '>' . $contents . '</ul>'; | ||
// that's all. end of file. |
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,15 @@ | ||
/* | ||
@package rundiz-oauth | ||
*/ | ||
|
||
|
||
.wp-block-rd-oauth-blocks-loginlinks { | ||
list-style: disc; | ||
margin: 0; | ||
padding-left: 20px; | ||
|
||
li { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
} |
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-components', 'wp-i18n', 'wp-server-side-render'), 'version' => 'ff70017631adf4144639'); |
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,25 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 3, | ||
"attributes": { | ||
"displayLinkToAdmin": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
}, | ||
"category": "theme", | ||
"description": "Display login, register, logout links.", | ||
"editorScript": "file:./block.js", | ||
"icon": "admin-users", | ||
"name": "rd-oauth/blocks-loginlinks", | ||
"render": "file:./render.php", | ||
"style": [ | ||
"file:./style-block.css", | ||
"rd-oauth-loginlinks-block-style" | ||
], | ||
"supports": { | ||
"className": true | ||
}, | ||
"textdomain": "okv-oauth", | ||
"title": "Login links" | ||
} |
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 @@ | ||
<?php | ||
/** | ||
* Render contents for loginlinks block. | ||
* | ||
* @package rundiz-oauth | ||
*/ | ||
|
||
|
||
$currentUrl = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | ||
$isUserLoggedIn = is_user_logged_in(); | ||
$classes = ($isUserLoggedIn ? 'logged-in' : 'logged-out'); | ||
$contents = ''; | ||
|
||
if (!$isUserLoggedIn && get_option('users_can_register')) { | ||
$contents .= '<li><a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a></li>' . PHP_EOL; | ||
} elseif ($isUserLoggedIn && isset($attributes) && is_array($attributes) && array_key_exists('displayLinkToAdmin', $attributes) && $attributes['displayLinkToAdmin'] === true) { | ||
$contents .= '<li><a href="' . admin_url() . '">' . __( 'Site Admin' ) . '</a></li>' . PHP_EOL; | ||
} | ||
unset($isUserLoggedIn); | ||
|
||
$contents .= '<li>' . wp_loginout($currentUrl, false) . '</li>' . PHP_EOL; | ||
unset($currentUrl); | ||
|
||
$wrapperAttributes = get_block_wrapper_attributes(['class' => $classes]); | ||
|
||
unset($classes); | ||
|
||
// must use echo, not return. | ||
echo '<ul ' . $wrapperAttributes . '>' . $contents . '</ul>'; | ||
// that's all. end of file. |
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 @@ | ||
.wp-block-rd-oauth-blocks-loginlinks{list-style:disc;margin:0;padding-left:20px}.wp-block-rd-oauth-blocks-loginlinks li{margin:0;padding:0} |
18 changes: 18 additions & 0 deletions
18
languages/okv-oauth-th-rd-oauth-loginlinks-block-script.json
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 @@ | ||
{ | ||
"translation-revision-date": "2023-11-24 03:13+0700", | ||
"generator": "WP-CLI\/2.8.0-alpha-9dfa966", | ||
"source": "blocks\/loginlinks\/block.js", | ||
"domain": "okv-oauth", | ||
"locale_data": { | ||
"messages": { | ||
"": { | ||
"domain": "okv-oauth", | ||
"lang": "th", | ||
"plural-forms": "nplurals=1; plural=0;" | ||
}, | ||
"Display link to admin dashboard": [ | ||
"\u0e41\u0e2a\u0e14\u0e07\u0e25\u0e34\u0e49\u0e07\u0e04\u0e4c\u0e44\u0e1b\u0e22\u0e31\u0e07\u0e2b\u0e19\u0e49\u0e32\u0e1c\u0e39\u0e49\u0e14\u0e39\u0e41\u0e25" | ||
] | ||
} | ||
} | ||
} |
Binary file not shown.
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
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
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
Oops, something went wrong.