_x( 'Forms', 'post type general name'), 'singular_name' => _x( 'Form', 'post type singular name'), 'add_new' => _x( 'Add New', 'form'), 'add_new_item' => __( 'Add New Form'), 'edit_item' => __( 'Edit Form'), 'new_item' => __( 'New Form'), 'view_item' => __( 'View Form'), 'search_items' => __( 'Search Forms'), 'not_found' => __( 'No forms found'), 'not_found_in_trash' => __( 'No forms found in Trash'), 'parent_item_colon' => '', 'menu_name' => 'Contact Forms' ); $args = array( 'labels' => $labels, 'public' => false, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => false, 'capability_type' => 'post', 'has_archive' => false, 'hierarchical' => false, 'menu_position' => 20, 'menu_icon' => plugin_dir_url( __FILE__ ) . 'images/post-type-icon.png', 'supports' => array( 'title' ) ); register_post_type( 'iwacontactform', $args ); wp_register_style( 'ajax-contact-css', plugin_dir_url( __FILE__ ) . 'ajax-contact.css' ); wp_register_script( 'ajax-contact', plugin_dir_url( __FILE__ ) . 'ajax-contact.js', array( 'jquery' ) ); wp_enqueue_style( 'ajax-contact-css' ); wp_enqueue_script( 'ajax-contact' ); } add_action( 'init', 'acontact_init' ); /** * Our admin init functions **/ function acontact_admin_init() { wp_register_style( 'ajax-contact-admin-css', plugin_dir_url( __FILE__ ) . 'ajax-contact-admin.css' ); wp_register_script( 'ajax-contact-admin', plugin_dir_url( __FILE__ ) . 'ajax-contact-admin.js', array( 'jquery' ) ); wp_enqueue_style( 'ajax-contact-admin-css' ); wp_enqueue_script( 'ajax-contact-admin' ); } add_action( 'admin_init', 'acontact_admin_init' ); /** * Custom sorting function that works with usort() * to sort custom field arrays by a child var's value **/ function sort_fields( $a, $b ) { if ( $a[1] == $b[1] ) return 0; return ( $a[1] < $b[1] ) ? -1 : 1; } /** * trim() all values in an array **/ function trim_value( &$value ) { $value = trim( $value ); } /** * Parses the provided string and replaces any tags * wrapped in [[ ]] with relevant post meta * * @param string $string The string to parse **/ function acontact_parse_special( $string ) { // If this is a multi-line string, split on new lines if ( preg_match( '/\r\n|\r|\n/', $string ) && $lines = preg_split( '/\r\n|\r|\n/', $string ) ) { $result = array(); foreach ( $lines as $line ) { // Re-call this function to parse each line array_push( $result, acontact_parse_special( trim( $line ) ) ); } return join( "\n", $result ); } // Split this string in to single words if ( $words = preg_split( '/\ /', $string ) ) { $result = array(); foreach ( $words as $word ) { if ( preg_match( '/^\[\[([a-z0-9-_.]+)\]\]$/i', $word, $matches ) ) { $requested_resource = $matches[1]; switch( strtolower( $requested_resource ) ) { case 'the_id': array_push( $result, get_the_ID() ); break; case 'the_title': array_push( $result, get_the_title() ); break; } } else { array_push( $result, $word ); } } return join( ' ', $result ); } return false; }