Skip to content

Instantly share code, notes, and snippets.

@grola
grola / poslish_postcode_fcf.php
Created August 6, 2019 09:33
Polish postcode custom validation for Flexible Checkout Field
<?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 August 1, 2019 10:15
Validate polish postcode
<?php
/**
* Validate polish postcode. "-" is required.
*
* @param bool $valid .
* @param string $postcode .
* @param string $country .
*
* @return bool
@grola
grola / dismissible-notice.php
Created January 15, 2019 12:59
Dismissible notice
<?php
wpdesk_permanent_dismissible_notice( 'Success notice.', 'my-success-notice', 'success' );
@grola
grola / init-ajax-handler.php
Created January 15, 2019 12:57
Init AJAX handler
<?php
wpdesk_init_notice_ajax_handler();
@grola
grola / display-notices.php
Created January 15, 2019 12:56
Display notices
<?php
wpdesk_notice_success( 'Success notice.' );
wpdesk_notice_info( 'Info notice.' );
wpdesk_notice_warning( 'Warning notice.' );
wpdesk_notice_error( 'Error notice.' );
@grola
grola / include-init.php
Created January 15, 2019 12:55
Include init
<?php
require_once 'wp-desk/wp-notice/init.php';
@grola
grola / include-autoloader.php
Created January 15, 2019 12:55
Include autoloader
<?php
require_once 'vendor/autoload.php';
@grola
grola / composer-require.sh
Created January 15, 2019 12:53
composer require
composer require wpdesk/wp-notice
@grola
grola / dismissible-ajax-notice.php
Last active September 26, 2019 19:39
Dismissible notice with AJAX
<?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>
@grola
grola / dismissible-notice.php
Created January 15, 2019 12:50
Dismissible notice
<?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