-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WP admin bar issue #384
Comments
My colleague and I found a way to solve this so you can update at least Readme file according this. Here we send our link data from php: if (current_user_can('edit_posts')) {
$js_params = [
'edit_link' => [
'is_exist' => false,
]
];
if (!is_archive()) {
$postTypeLabel = get_post_type_object(get_post_type(get_the_ID()))->labels->singular_name;
$js_params['edit_link']['is_exist'] = true;
$js_params['edit_link']['href'] = get_edit_post_link(get_the_ID(), '');
$js_params['edit_link']['title'] = 'Edit ' . $postTypeLabel;
}
echo '<script type="text/javascript">window.post_data = ', json_encode($js_params), ';</script>';
} And here we update/create/remove link according window.post_data on JS: function wpEditLinkRebuild() {
let $wpEditLink = $('#wp-admin-bar-edit a');
let postData = window.post_data;
console.log(postData);
if (postData) {
let linkExist = postData.edit_link['is_exist'];
if (linkExist) {
// Button exists
if (!$wpEditLink.length) {
let $wpAdminBarMenu = $('#wp-admin-bar-root-default');
$wpAdminBarMenu.append(
'<li id="wp-admin-bar-edit">' +
'<a class="ab-item wp-link" href=""></a>' +
'</li>'
);
}
$wpEditLink = $('#wp-admin-bar-edit a');
let newLinkName = postData.edit_link['title'];
let newLinkHref = postData.edit_link['href'];
newLinkName && $wpEditLink.attr('href', newLinkHref);
newLinkHref && $wpEditLink.text(newLinkName);
} else if ($wpEditLink.length){
// Button does not exist
$wpEditLink.remove();
}
}
} Just call this function from your smoothState onAfter function: let $page = $('#main'),
options = {
anchors: 'a',
blacklist: ".wp-link, .post-edit-link, a[href*='.jpg'], a[href*='.png'], a[href*='.jpeg'], a[href*='.pdf']",
onStart: {
duration: 500,
render: function ($container) {
$body.addClass('page-changing');
smoothState.restartCSSAnimations();
closeMenu();
}
},
onReady: {
duration: 0,
render: function ($container, $newContent) {
$container.html($newContent);
}
},
onAfter: function() {
wpEditLinkRebuild();
}
},
smoothState = $page.smoothState(options).data('smoothState'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When pages are changing with smoothState, the WordPress admin bar does not update.
So links to e.g. "Edit Page" don't updates/creates/removes as expected.
There always were only 2 solutions:
but no one of them looks good.
The text was updated successfully, but these errors were encountered: