Skip to content

Instantly share code, notes, and snippets.

@grola
grola / poslish_postcode_fcf.php
Created Aug 6, 2019
Polish postcode custom validation for Flexible Checkout Field
View poslish_postcode_fcf.php
<?php
/**
* Validate polish postcode.
*
* @param string $field_label .
* @param string $value .
*/
function wpdesk_is_polish_postcode( $field_label, $value ) {
if ( ! ( (bool) preg_match( '/^([0-9]{2})-([0-9]{3})$/', $value ) ) ) {
@grola
grola / functions.php
Created Aug 1, 2019
Validate polish postcode
View functions.php
<?php
/**
* Validate polish postcode. "-" is required.
*
* @param bool $valid .
* @param string $postcode .
* @param string $country .
*
* @return bool
View dismissible-notice.php
<?php
wpdesk_permanent_dismissible_notice( 'Success notice.', 'my-success-notice', 'success' );
View init-ajax-handler.php
<?php
wpdesk_init_notice_ajax_handler();
View display-notices.php
<?php
wpdesk_notice_success( 'Success notice.' );
wpdesk_notice_info( 'Info notice.' );
wpdesk_notice_warning( 'Warning notice.' );
wpdesk_notice_error( 'Error notice.' );
View include-init.php
<?php
require_once 'wp-desk/wp-notice/init.php';
View include-autoloader.php
<?php
require_once 'vendor/autoload.php';
View composer-require.sh
composer require wpdesk/wp-notice
@grola
grola / dismissible-ajax-notice.php
Last active Sep 26, 2019
Dismissible notice with AJAX
View dismissible-ajax-notice.php
<?php
function wpdesk_permanent_dismisible_info_notice_for_administrator() {
$notice name = 'admin_notice';
if ( intval( get_option( 'wpdesk_notice_dismiss_' . $notice_name, 0 ) ) !== 1 ) {
$user = wp_get current_user();
if ( in_array( 'administrator', $user->roles ) ) {
?>
<div class="notice notice-info is-dismissible" data-notice-name="<?php echo $notice_name; ?>">
<p>Info notice for administrator.</p>
View dismissible-notice.php
<?php
function wpdesk_dismisible_info_notice_for_administrator() {
$user = wp_get current_user();
if ( in_array( 'administrator', $user->roles ) ) {
?>
<div class="notice notice-info is-dismissible">
<p>Info notice for administrator.</p>
</div>
<?php
You can’t perform that action at this time.