Deshabilitar funcions als editors

Functions User Role

Per deixar als editors un panell només amb les opcions que vols que puguin fer…

/** amaga del panell dels editors */ define( 'DISALLOW_FILE_EDIT', true); function remove_menus(){ remove_menu_page( 'edit.php' ); //Posts remove_menu_page( 'upload.php' ); //Media remove_menu_page( 'edit.php?post_type=page' ); //Pages remove_menu_page( 'edit-comments.php' ); //Comments remove_menu_page( 'themes.php' ); //Appearance remove_menu_page( 'plugins.php' ); //Plugins remove_menu_page( 'users.php' ); //Users remove_menu_page( 'tools.php' ); //Tools remove_menu_page( 'options-general.php' ); //Settings } if ( current_user_can( 'editor' ) ){ add_action( 'admin_menu', 'remove_menus' ); }

A vegades només s’han de mostrar aquestes caixes només als administradors.

add_filter( 'rcp_metabox_post_types', function( array $post_types ): array { $user = wp_get_current_user(); if ( ! in_array( 'administrator', $user->roles, true ) ) { $post_types = []; } return $post_types; } );

Primer cal afegir els arguments al function.php,
després les condicions al CSS,
i la classe al bloc que vols mostrar o amagar en dunció de l’estat de l’usuari (.hide-logged-in) o ( hide-logged-out).

// function.php // mostra / amaga element segons logged in / logged out add_filter('body_class','er_logged_in_filter'); function er_logged_in_filter($classes) { if( is_user_logged_in() ) { $classes[] = 'logged-in-condition'; } else { $classes[] = 'logged-out-condition'; } // return the $classes array return $classes; } // CSS /* Logged in & out conditions */ .logged-in-condition .hide-logged-in { display: none!important; } .logged-out-condition .hide-logged-out { display: none!important; }

A vegades necessites que el resum ocupi determinades línies de text…

// css .caixa_text { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }

S’ordenen les entrades del bucle de GeneratePress per un dels camps de tipus data d’Advanced Custom Fields i, a més, es mostren només aquelles entrades actives segons aquest mateix camp i la data d’avui. Perquè aquest codi s’apliqui, s’ha de posar la classe `tallers-actius` a la graella de dins el bucle.

add_filter( ‘generateblocks_query_loop_args’, function( array $query_args, array $attributes ) { if ( ! empty( $attributes[‘className’] ) && strpos( $attributes[‘className’], ‘tallers-actius’ ) !== false ) { $query_args = array_merge( $query_args, [ ‘meta_key’ => ‘data_taller’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘DESC’, ‘meta_query’ => [ [ ‘key’ => ‘data_taller’, ‘value’ => date(‘Ymd’), ‘compare’ => ‘>=’ ], ], ] ); } return $query_args; }, 10, 2 );

If is empty field

ACF Functions

Si el camp està buit, mostra això altre

<?php if ( get_field( 'field_name' ) ): ?> FIELD CODE… <?php else: // field_name returned false ?> OTHER CONTENT IF FIELD IS EMPTY <?php endif; // end of if field_name logic ?>

Canvia text botó “add to cart”

Functions WooCommerce

Personalitza el text dels botons d'”Afegeix a la cistella” de WooCommerce…

// Change add to cart text on single product page add_filter( ‘woocommerce_product_single_add_to_cart_text’, ‘woocommerce_add_to_cart_button_text_single’ ); function woocommerce_add_to_cart_button_text_single() { return __( ‘EL TEU TEXT’, ‘woocommerce’ ); } // Change add to cart text on product archives page add_filter( ‘woocommerce_product_add_to_cart_text’, ‘woocommerce_add_to_cart_button_text_archives’ ); function woocommerce_add_to_cart_button_text_archives() { return __( ‘EL TEU TEXT, ‘woocommerce’ ); }

Disable Cart, Checkout, Add Cart

Functions WooCommerce

Desactiva les funcions de botiga… per exemple per tenir un catàleg o perquè no vols que entrin comandes en algun moment.

// Trigger close Mode add_action (‘init’, ‘tandem_woocommerce_close_mode’); // Disable Cart, Checkout, Add Cart function tandem_woocommerce_close_mode() { remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 ); remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’, 30 ); remove_action( ‘woocommerce_proceed_to_checkout’, ‘woocommerce_button_proceed_to_checkout’, 20 ); remove_action( ‘woocommerce_checkout_order_review’, ‘woocommerce_checkout_payment’, 20 ); add_action( ‘woocommerce_before_main_content’, ‘tandem_wc_shop_disabled’, 5 ); add_action( ‘woocommerce_before_cart’, ‘tandem_wc_shop_disabled’, 5 ); add_action( ‘woocommerce_before_checkout_form’, ‘tandem_wc_shop_disabled’, 5 ); } // Show close Notice function tandem_wc_shop_disabled() { wc_print_notice( ‘Our Online Shop is Closed Today :)’, ‘error’); }

Sticky Menu o Header

CSS GeneratePress

Fixar el menu

/* menu */ .main-navigation { position: sticky; top: 0; z-index: 999; } .admin-bar .main-navigation { top: 32px; } /* header */ .site-header { position: sticky; top: 0; z-index: 999; } .admin-bar .site-header { top: 32px; }

GeneratePress Preferences

Functions GeneratePress

Amaga l’edició de preferències del tema a tots els usuaris

/* treure generatepress del menú per a tots els usuaris */ add_action( 'after_setup_theme','tu_remove_gp_admin_menu' ); function tu_remove_gp_admin_menu() { remove_action('admin_menu', 'generate_create_menu'); }

Desactiva Gutenberg per a les entrades i per exemple amb ACF afegeixes camps personalitzats

/* desactiva gutenberg per a les entrades */ function tandem_gutenberg_filter( $use_block_editor, $post_type ) { if ( 'post' === $post_type ) { return false; } return $use_block_editor; } add_filter( 'use_block_editor_for_post_type', 'tandem_gutenberg_filter', 10, 2 );

Amaga l’editor als tipus d’entrada

add_action('init', 'my_remove_editor_from_post_type'); function my_remove_editor_from_post_type() { remove_post_type_support( 'post', 'editor' ); remove_post_type_support( 'page', 'editor' ); }

Amagar l’editor principal de WooCommerce

/* amaga editor principal de woocommerce */ function reset_editor(){ global $_wp_post_type_features; $post_type="product"; $feature = "editor"; if ( !isset($_wp_post_type_features[$post_type]) ){ } elseif ( isset($_wp_post_type_features[$post_type][$feature]) ) unset($_wp_post_type_features[$post_type][$feature]); } add_action("init","reset_editor"); /* fi amaga editor principal de woocommerce */

Amagar opcions GP

Functions GeneratePress

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Hide GeneratePress Options remove_submenu_page( 'themes.php', 'generate-options' )