wordpress moving publish metabox - wordpress

I'm working on a plugin and I'm trying to:
1- move the publish metabox from side to the bottom of the page in the normal section.
2- force 1 column layout for the plugin custom post type edit page.
3- remove the screen options tab for the custom post type.
I'm using the next code block but it dont work:
function sds_do_meta_boxes() {
remove_meta_box( 'submitdiv', 'sliding_panel', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sliding_panel', 'normal', 'core' );
}
add_action('do_meta_boxes', 'sds_do_meta_boxes');
function SDS_init() { //The current user is already authenticated by this time
add_filter( 'screen_layout_columns', 'so_screen_layout_columns' );
add_filter( 'get_user_option_screen_layout_dashboard', 'so_screen_layout_dashboard' );
add_filter( 'screen_options_show_screen', 'SDS_remove_screen_options_tab');
}
add_action( 'init', 'SDS_init' );
function so_screen_layout_columns( $columns ) {
$columns['dashboard'] = 1;
return $columns;
}
function so_screen_layout_dashboard() {
return 1;
}
function SDS_remove_screen_options_tab() {
return false;
}
So, the 'publish' metabox is removed but it is not re-added. Also, the 1 column layout filters don't work. I need help:)

Changing the $priority parameter from core to high and setting priority of add_action to 0 should do the trick. I would also suggest using the dynamic add_meta_boxes_{$post_type} hook:
add_action( 'add_meta_boxes_sliding_panel', 'sds_do_meta_boxes', 0, 1 );
function sds_do_meta_boxes( $post )
{
remove_meta_box( 'submitdiv', 'sliding_panel', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sliding_panel', 'normal', 'high', null );
}

Related

Remove action defined within plugin class

I am developing a ecommerce theme.
I have installed the WooCommerce PayPal Checkout Payment Gateway plugin for payment, and I want to change the location of this checkout button, I tried to remove_action display checkout button but it didn't work, How can I remove action in this case?
Hook in plugin file:
plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-with-spb.php
This is my code in functions.php file, it not works:
function remove_anon_filters( $name, $functionname, $priority ) {
global $wp_filter;
foreach ( $wp_filter[ $name ][ $priority ] as $key => $data ) {
if ( stripos( $key, $functionname ) ) {
remove_action( $name, $key, $priority );
}
}
}
add_action( 'plugins_loaded', 'demo_init', 999 );
function demo_init() {
remove_anon_filters( 'woocommerce_review_order_after_submit', 'display_paypal_button', 10 );
}
// or.
add_action( 'init', 'remove_init', 999 );
function remove_init() {
remove_action( 'woocommerce_review_order_after_submit', array( 'WC_Gateway_PPEC_With_SPB', 'display_paypal_button' ), 10 );
}
Any help is appreciated, thank you.
To remove a non-static method, you should instantiate the class, and remove the action in the wp_head https://developer.wordpress.org/reference/functions/remove_action/
Additionally, the remove_action should be the same priority as the add action, which in this case is not specified.
add_action( 'wp_head', 'remove_ppec_with_spb', 10);
function remove_ppec_with_spb() {
$class = new WC_Gateway_PPEC_With_SPB;
remove_action( 'woocommerce_review_order_after_submit', array( $class , 'display_paypal_button' ) );
}

Woocommerce - Adding Custom Fields to Checkout & Custom Dashboard Tab

I have an Multistep Checkout and for that reason i have created a new custom step called "Card-Data", where i want the customer to fill the inputs. This inputs should also appear on a Tab in My Account. I already created a new custom tab for My Account Dashboard.
Can you tell me please, how i can create Custom Fields in the checkout process and and make them visible in the Custom Dashboard Tab. The customer should has the possibility to change data entries on his own through the dashboard.
Many Thanks
// i use multistep checkout wizzard plugin. here i create a step, where user
enters the card data
add_action('woocommerce_multistep_checkout_before', 'add_visica_step');
function add_visica_step() {
$contents = '<h1>Visica Daten</h1>';
$contents .= '<div class="visica-step"> Please Enter something </div>';
echo $contents;
}
add_filter ( 'woocommerce_account_menu_items', 'one_more_link' );
function one_more_link( $menu_links ){
$new = array( 'carddata' => 'Card Data' );
$menu_links = array_slice( $menu_links, 0, 1, true )
+ $new
+ array_slice( $menu_links, 1, NULL, true );
return $menu_links;
}
/*
* Step 2. Register Permalink Endpoint
*/
add_action( 'init', 'add_endpoint' );
function add_endpoint() {
// WP_Rewrite is my Achilles' heel, so please do not ask me for detailed
explanation
add_rewrite_endpoint( 'visicadata', EP_PAGES );
}
/*
* Step 3. Content for the new page in My Account, woocommerce_account_{ENDPOINT
NAME}_endpoint
*/
add_action( 'woocommerce_account_visicadata_endpoint',
'my_account_endpoint_content' );
function my_account_endpoint_content() {
echo 'Here I want do display custom fields from checkout';
}
add_filter( 'woocommerce_checkout_fields' ,
'woocommerce_checkout_field_editor' );
// Our hooked in function - $fields is passed via the filter!
function woocommerce_checkout_field_editor( $fields ) {
$fields['shipping']['shipping_field_value'] = array(
'label' => __('Field Value', 'woocommerce'),
'placeholder' => _x('Field Value', 'placeholder', 'woocommerce'),
'required' => true
);
return $fields;
}
// Display Field on Order Page, but i would like to display it on custom tab
add_action( 'woocommerce_admin_order_data_after_shipping_address',
'edit_woocommerce_checkout_page', 10, 1 );
function edit_woocommerce_checkout_page($order){
global $post_id;
$order = new WC_Order( $post_id );
echo '<p><strong>'.__('Field Value').':</strong> ' . get_post_meta($order->get_id(), '_shipping_field_value', true ) . '</p>';

Solution to Excerpt Customisation with new Gutenberg Editor

I have made several customisations to the native Wordpress Excerpt metabox which no longer seem to work with the new Gutenberg editor and I can find no documentation online that guides me to a solution.
Does anyone know how the following code snippets can be amended to work with the new Gutenberg Editor?
This snippet removes the native Excerpt and repositions it at the top of the Editor screen below the Title metabox:
function remove_normal_excerpt() {
remove_meta_box( 'postexcerpt' , 'post' , 'normal' );
}
add_action( 'admin_menu' , 'remove_normal_excerpt' );
function add_new_excerpt_meta( $post_type ) {
$post_types = get_post_types( array ( 'public' => true ) );
$excluded_posttypes = array ();
$post_type = array_diff($post_types, $excluded_posttypes);
add_meta_box(
'postexcerpt',
__( 'Excerpt', '' ),
'post_excerpt_meta_box',
$post_type,
'advanced',
'high', 0, 0
);
}
add_action( 'add_meta_boxes', 'add_new_excerpt_meta' );
This snippet adds an information notice to the Excerpt metabox:
function excerpt_add_notice( $translation, $original ) {
if ( 'Excerpt' == $original ) {
return 'Excerpt';
}else{
$pos = strpos($original, 'Excerpts are optional hand-crafted summaries of
your');
if ($pos !== false) {
return '<h5 class="notice notice info">Always complete your excerpt
sections.</h5>';
}
}
return $translation;
}
add_filter( 'gettext', 'excerpt_add_notice', 10, 2 );
This snippet adds a javascript character count limit to the Excerpt:
function excerpt_count_js(){
global $post;
if ( get_post_type($post) != 'storefront' ) {
echo '<script>jQuery(document).ready(function(){
jQuery("#postexcerpt .handlediv").after("<div
style=\"position:absolute;top:12px;right:34px;color:#666;\"><small>Excerpt
length: </small><span id=\"excerpt_counter\"></span><span style=\"font-
weight:bold; padding-left:7px;\">/ 170</span><small><span style=\"font-
weight:bold; padding-left:7px;\">character(s).</span></small></div>");
jQuery("span#excerpt_counter").text(jQuery("#excerpt").val().length);
jQuery("#excerpt").keyup( function() {
if(jQuery(this).val().length > 170){
jQuery(this).val(jQuery(this).val().substr(0, 170));
}
jQuery("span#excerpt_counter").text(jQuery("#excerpt").val().length);
});
});</script>';
}
}
add_action( 'admin_head-post.php', 'excerpt_count_js');
add_action( 'admin_head-post-new.php', 'excerpt_count_js');
Is it just a case of something simple as the Excerpt metabox identifiers having been changed?

Force 1 column and put publish metabox below title

How can I force a 1 column layout and put publish metabox below title before the wysiwyg editor in the wordpress admin?
add_action( 'add_meta_boxes', 'action_add_meta_boxes', 0 );
function action_add_meta_boxes() {
global $_wp_post_type_features;
if (isset($_wp_post_type_features['post']['editor']) && $_wp_post_type_features['post']['editor']) {
unset($_wp_post_type_features['post']['editor']);
add_meta_box(
'description_section',
__('Description'),
'inner_custom_box',
'post', 'normal', 'high'
);
}
if (isset($_wp_post_type_features['page']['editor']) && $_wp_post_type_features['page']['editor']) {
unset($_wp_post_type_features['page']['editor']);
add_meta_box(
'description_sectionid',
__('Description'),
'inner_custom_box',
'page', 'normal', 'high'
);
}
}
function inner_custom_box( $post ) {
the_editor($post->post_content);
}
(from https://wordpress.org/support/topic/move-custom-meta-box-above-editor)

How to get a slug name for a page without creating an admin page menu

I now use the add_submenu_page() function, but I don't want the edit page to appear in the admin menu.
I want to access the edit page from a list (another page) directly. But I need the slug as a hook_suffix.
I have in my-edit.php
/* Set up the administration functionality. */
add_action( 'admin_menu', 'my_edit_setup' );
function my_edit_setup() {
...
/* Add Edit Actionlist page. */
$myplugin->my_edit = add_submenu_page( 'myplugin', esc_attr__( 'Edit', 'myplugin' ), esc_attr__( 'Edit', 'myplugin' ), 7, 'my-edit', 'my_edit' );
...
In admin.php I have:
function my_admin_enqueue_style( $hook_suffix ) {
$pages = array(
'admin_page_projects',
'...my-edit'
);
if ( in_array( $hook_suffix, $pages ) ) {
wp_enqueue_style( 'myplugin-admin', trailingslashit( MYPLUGIN_URI ) . 'css/admin.css', false, '20110525', 'screen' );
You see I need the $hook_suffix, but I can't find out how to get this, without creating the admin menu item.
Example of how to create an invisible sub menu (it gets attached to the Dashboard, index.php) and the correspondent $hook_suffix.
The page can be accessed through http://example.com/wp-admin/index.php?page=sample_page_hidden.
add_action( 'admin_menu', 'admin_menu_so_11593510' );
add_action( 'admin_enqueue_scripts', 'admin_enqueue_scripts_so_11593510' );
function admin_menu_so_11593510()
{
add_submenu_page(
null, // doesn't shows up in the menu, submenu is attached to "index.php"
'Test',
'Test',
'edit_pages',
'sample_page_hidden',
'menu_options_so_11593510'
);
}
function menu_options_so_11593510() { echo 'Hello!'; }
function admin_enqueue_scripts_so_11593510( $hook_suffix )
{
if ( 'dashboard_page_sample_page_hidden' == $hook_suffix ) {
wp_enqueue_script( 'swfobject' );
}
}

Resources