It can be used for pre-filled fields or custom functionality with filterning and updating values.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function wpm_custom_date_shortcode_handler($tag) { if ( ! is_array( $tag ) ) return ''; $name = $tag['name']; if ( empty( $name ) ) return ''; $next_week = date('Y-m-d', time() + (60*60*24*7)); $html = '<input type="text" name="' . $name . '" value="' . $next_week . '" />'; return $html; } wpcf7_add_shortcode( 'custom_date', 'wpm_custom_date_shortcode_handler', true ); |
1 2 3 4 5 |
function wpm_seo_metabox_priority() { //* Accepts 'high', 'default', 'low'. Default is 'high'. return 'low'; } add_filter( 'wpseo_metabox_prio', 'wpm_seo_metabox_priority' ); |
Add filter for Post Type — ‘project’.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// Post Type Project add_filter( 'views_edit-project', 'wpm_add_project_filter' ); function wpm_add_project_filter( $views ) { global $wp_query; $my_cat = 38; // Replace with your category ID $query = array( 'post_type' => 'project', 'post_status' => 'publish', 'cat' => $my_cat ); $cat_object = get_category( $my_cat ); $result = new WP_Query( $query ); $class = ( $wp_query->query_vars['cat'] == $cat_object->slug ) ? ' class="current"' : ''; $views['publish_f'] = sprintf( __( '<a href="%s"' . $class . '>' . $cat_object->name . ' <span class="count">(%d)</span></a>', $cat_object->name ), admin_url( 'edit.php?post_status=publish&post_type=project&cat=' . $my_cat ), $result->found_posts ); return $views; } |
1. Create template.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php /** * Template Name: Flexible */ get_header(); ?> <?php if( have_rows('flexible_content') ): while ( have_rows('flexible_content') ) : the_row(); get_template_part( 'template-parts/block', get_row_layout() ); endwhile; endif; ?> <?php get_footer(); ?> |
2. Install Advanced Custom Fields PRO.
3. Create Field Group for define template.
4. Add layout (e.g., content).
5. Create template for each layouts.
1 2 3 4 5 6 7 8 9 10 |
<?php $width = empty( $class = get_sub_field( 'class' ) ) ? '_s' : $width; $class = empty( $width = get_sub_field( 'width' ) ) ? 'content' : $class; ?> <section class="<?php echo $class; ?>"> <div class="container <?php echo $width; ?>"> <?php echo apply_filters( 'the_content', get_sub_field( 'content' ) ); ?> </div> </section> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function wpm_password_validation_filter( $result, $tag ) { $tag = new WPCF7_Shortcode( $tag ); if ( 'PASSWORD-CONFIRM' == $tag->name ) { $your_password = isset( $_POST['PASSWORD'] ) ? trim( $_POST['PASSWORD'] ) : ''; $your_password_confirm = isset( $_POST['PASSWORD-CONFIRM'] ) ? trim( $_POST['PASSWORD-CONFIRM'] ) : ''; if ( $your_password != $your_password_confirm ) { $result->invalidate( $tag, "Are you sure this is the correct password?" ); } } return $result; } add_filter( 'wpcf7_validate_text*', 'wpm_password_validation_filter', 20, 2 ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
function wpm_email_validation_filter( $result, $tag ) { $tag = new WPCF7_Shortcode( $tag ); if ( 'EMAIL-CONFIRM' == $tag->name ) { $your_email = isset( $_POST['EMAIL'] ) ? trim( $_POST['EMAIL'] ) : ''; $your_email_confirm = isset( $_POST['EMAIL-CONFIRM'] ) ? trim( $_POST['EMAIL-CONFIRM'] ) : ''; if ( $your_email != $your_email_confirm ) { $result->invalidate( $tag, "Are you sure this is the correct address?" ); } } if ( 'EMAIL' == $tag->name ) { $email = isset( $_POST['EMAIL'] ) ? trim( $_POST['EMAIL'] ) : ''; if ( email_exists( $email ) ) { $result->invalidate( $tag, "This email already exists, please choose another." ); } } return $result; } add_filter( 'wpcf7_validate_email*', 'wpm_email_validation_filter', 20, 2 ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
function wpm_create_user_form_registration( $cfdata ) { if ( ! isset( $cfdata->posted_data ) && class_exists( 'WPCF7_Submission' ) ) { // Contact Form 7 version 3.9 removed $cfdata->posted_data and now // we have to retrieve it from an API $submission = WPCF7_Submission::get_instance(); if ( $submission ) { $formdata = $submission->get_posted_data(); } } elseif ( isset( $cfdata->posted_data ) ) { // For pre-3.9 versions of Contact Form 7 $formdata = $cfdata->posted_data; } else { // We can't retrieve the form data return $cfdata; } // Check this is the user registration form if ( $cfdata->title() == 'Registration' ) { $username = $formdata['EMAIL']; $email = $formdata['EMAIL']; $password = $formdata['PASSWORD']; $fname = $formdata['FNAME']; $lname = $formdata['LNAME']; if ( ! email_exists( $email ) ) { // Find an unused username $username_tocheck = $username; $i = 1; while ( username_exists( $username_tocheck ) ) { $username_tocheck = $username . $i ++; } $username = $username_tocheck; // Create the user $userdata = array( 'user_login' => $username, 'user_pass' => $password, 'user_email' => $email, 'nickname' => $fname . ' ' . $lname, 'display_name' => $fname . ' ' . $lname, 'first_name' => $fname, 'last_name' => $lname, 'role' => 'subscriber' ); $user_id = wp_insert_user( $userdata ); if ( ! is_wp_error( $user_id ) ) { wp_set_current_user( $user_id ); wp_set_auth_cookie( $user_id ); do_action( 'woocommerce_created_customer', $user_id ); } } } return $cfdata; } add_action( 'wpcf7_before_send_mail', 'wpm_create_user_form_registration', 1 ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// Enable shortcodes in text widgets add_filter('widget_text', 'do_shortcode'); // Create Shortcode function wpm_shortcode_func( $atts ) { ob_start (); ?> <?php echo $atts['text'] ?> <?php $response = ob_get_contents(); ob_end_clean(); return $response; } add_shortcode( 'wpm_shortcode', 'wpm_shortcode_func' ); |
And past it to Text widget
1 |
[wpm_shortcode text="test"] |
There are a lot of ways to create options page in WordPress. This is one of them:
1 2 3 4 5 6 7 8 9 10 11 |
function wpm_admin_menu() { add_options_page( 'Page Title', 'Menu Element Name', 8, //access right to settings page 'plugin_option_slug', 'wpm_option_page' ); } add_action( 'admin_menu', 'wpm_admin_menu' ); |
In callback function you can include a file with your options fields:
1 2 3 |
function wpm_option_page() { include 'options.php'; } |
1 2 3 4 5 6 7 |
function wpm_admin_menu_items() { global $menu; $menu[10] = $menu[26]; // set position unset( $menu[26] ) // delete old element position } add_action( 'admin_menu', 'wpm_admin_menu_items' ); |