Skip to content

Commit

Permalink
follow up fixes and minor updates #13
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarczewski committed Dec 24, 2020
1 parent 255993b commit ce9d306
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
18 changes: 1 addition & 17 deletions bip-pages-main-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,11 @@ function main_page_edit_notice() {
if ( is_bip_main_page_edit_screen() ) {
$message = '<p>' . esc_html__( 'You are editing the BIP main page.', 'bip-pages' ) . '</p>' .
'<p>' . esc_html__( 'Parts of this page are automatically generated. The text you enter below will be displayed between the automatic BIP header and footer.', 'bip-pages' ) . '</p>';
echo "<div class='notice notice-info is-dismissible'>{$message}</div>";
echo "<div class='notice is-info is-dismissible'>{$message}</div>";
}
}
add_action( 'admin_notices', __NAMESPACE__ . '\main_page_edit_notice' );

function enqueue_editor_notices() {
// only proceed if user is editing BIP main page
if ( !is_bip_main_page_edit_screen() ) {
return;
}

wp_enqueue_script(
'bip-editor-notices',
plugin_dir_url( __FILE__ ) . '/js/editor_notices.js',
array( 'wp-notices', 'wp-i18n', 'wp-editor' )
);

wp_set_script_translations( 'bip-editor-notices', 'bip-pages' );
}
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_editor_notices' );

function is_bip_main_page_edit_screen() {
return isset( $_GET['action'] ) &&
$_GET['action'] == 'edit' &&
Expand Down
25 changes: 25 additions & 0 deletions bip-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,31 @@ function redirect_to_bip_main_page() {
}
add_action( 'template_redirect', __NAMESPACE__ . '\redirect_to_bip_main_page' );

function enqueue_editor_notices() {
global $post;

// only proceed if user is editing a BIP page
if ( get_post_type( $post ) != 'bip' ) {
return;
}

wp_enqueue_script(
'bip-editor-notices',
plugin_dir_url( __FILE__ ) . '/js/editor_notices.js',
array( 'wp-notices', 'wp-i18n', 'wp-editor', 'jquery' )
);

$vars = array(
'bip_main_page' => get_bip_main_page(),
'bip_current_id' => $post->ID
);

wp_localize_script( 'bip-editor-notices', 'bip_pages_vars', $vars );

wp_set_script_translations( 'bip-editor-notices', 'bip-pages' );
}
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_editor_notices' );

/** main page **/
function get_bip_main_page() {
return Settings\get_option_value( 'id' );
Expand Down
24 changes: 18 additions & 6 deletions js/editor_notices.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
( function( wp ) {
msg = wp.i18n.__( 'You are editing the BIP main page.', 'bip-pages' ) + ' ' +
wp.i18n.__( 'Parts of this page are automatically generated. The text you enter below will be displayed between the automatic BIP header and footer.', 'bip-pages' );
if ( bip_pages_vars['bip_current_id'] == bip_pages_vars['bip_main_page'] ) {
msg = wp.i18n.__( 'You are editing the BIP main page.', 'bip-pages' ) + ' ' +
wp.i18n.__( 'Parts of this page are automatically generated. The text you enter below will be displayed between the automatic BIP header and footer.', 'bip-pages' );

wp.data.dispatch('core/notices').createWarningNotice(
msg,
{ isDismissible: true, }
);
wp.data.dispatch('core/notices').createInfoNotice(
msg,
{ isDismissible: true, }
);
}
} )( window.wp );

window.onload = (event) => {
el = '<div class="bip-footer-container components-notice is-info is-dismissible">' +
wp.i18n.__( 'A footer containing the author and publication date will be added here automatically.', 'bip-pages' ) +
'</div>';
jQuery('.edit-post-visual-editor').append( el );
wf = jQuery('.editor-writing-flow');
pt = jQuery('.editor-post-title');
footer = jQuery('.bip-footer-container');
};

0 comments on commit ce9d306

Please sign in to comment.