Skip to content

Instantly share code, notes, and snippets.

@SyzBeats
Last active February 1, 2022 22:20
Show Gist options
  • Select an option

  • Save SyzBeats/bbe540c14287cfcee7d59406a1c9ab7c to your computer and use it in GitHub Desktop.

Select an option

Save SyzBeats/bbe540c14287cfcee7d59406a1c9ab7c to your computer and use it in GitHub Desktop.
Wordpress & Woocommerce Collection
<?php
/** ___ ADD THIS TO functions.php ____
* ENHANCE THE STANDARD SEARCH
* Join posts and postmeta tables
* and include SKU in standard Search
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
function sku_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
add_filter('posts_join', 'sku_search_join' );
/**
* Modify the search query with posts_where
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where
*/
function sku_search_where( $where ) {
global $pagenow, $wpdb;
if ( is_search() ) {
$where = preg_replace(
"/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
}
return $where;
}
add_filter( 'posts_where', 'sku_search_where' );
/**
* Prevent duplicates
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct
*/
function sku_search_distinct( $where ) {
global $wpdb;
if ( is_search() ) {
return "DISTINCT";
}
return $where;
}
add_filter( 'posts_distinct', 'sku_search_distinct' );
/* END Search includes SKU */
<?php
function wpb_admin_account(){
$user = 'Username';
$pass = 'Password';
$email = 'email@domain.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
}
add_action('init','wpb_admin_account');
<?php
/**
* Plugin Name: Vibrosonic Career
* Description: Carrer Page plugin for vibrosonic.
* Version: 0.1.2
* Requires at least: 5.5
* Requires PHP: 7.2
* Author: Simeon Zimmermann - Allbility
* Author URI: https://sz-development.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: vibrosonic_career
* Domain Path: /languages
*/
// carrer plugin
if (!function_exists('career_post_type')) {
// Register Custom Post Type
function career_post_type()
{
$labels = array(
'name' => _x('Vacancies', 'Post Type General Name', 'vibrosonic_career'),
'singular_name' => _x('Vacancy', 'Post Type Singular Name', 'vibrosonic_career'),
'menu_name' => __('Vacancies', 'vibrosonic_career'),
'name_admin_bar' => __('Post Type', 'vibrosonic_career'),
'archives' => __('Vacancy Archives', 'vibrosonic_career'),
'attributes' => __('Vacancy Attributes', 'vibrosonic_career'),
'parent_item_colon' => __('Parent Item:', 'vibrosonic_career'),
'all_items' => __('All Vacancies', 'vibrosonic_career'),
'add_new_item' => __('Add New Vacancy', 'vibrosonic_career'),
'add_new' => __('Add New', 'vibrosonic_career'),
'new_item' => __('New Vacancy', 'vibrosonic_career'),
'edit_item' => __('Edit Vacancy', 'vibrosonic_career'),
'update_item' => __('Update Vacancy', 'vibrosonic_career'),
'view_item' => __('View Vacancy', 'vibrosonic_career'),
'view_items' => __('View Vacancies', 'vibrosonic_career'),
'search_items' => __('Search Vacancy', 'vibrosonic_career'),
'not_found' => __('Not found', 'vibrosonic_career'),
'not_found_in_trash' => __('Not found in Trash', 'vibrosonic_career'),
'featured_image' => __('Featured Image', 'vibrosonic_career'),
'set_featured_image' => __('Set featured image', 'vibrosonic_career'),
'remove_featured_image' => __('Remove featured image', 'vibrosonic_career'),
'use_featured_image' => __('Use as featured image', 'vibrosonic_career'),
'insert_into_item' => __('Insert into Vacancy', 'vibrosonic_career'),
'uploaded_to_this_item' => __('Uploaded to this Vacancy', 'vibrosonic_career'),
'items_list' => __('Items list', 'vibrosonic_career'),
'items_list_navigation' => __('Items list navigation', 'vibrosonic_career'),
'filter_items_list' => __('Filter items list', 'vibrosonic_career'),
);
$args = array(
'label' => __('Vacancy', 'vibrosonic_career'),
'description' => __('Career Page post types', 'vibrosonic_career'),
'labels' => $labels,
'menu_icon' => 'dashicons-businessman',
'supports' => array('title'),
'taxonomies' => array('category'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 10,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => false,
'has_archive' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type('vacancy', $args);
}
add_action('init', 'career_post_type', 0);
}
if (!function_exists("career_shortcode")) {
function career_shortcode($atts)
{
$atts = shortcode_atts(
array(
'language' => 'german',
),
$atts,
'career_shortcode'
);
$lang = $atts['language'];
$args = array(
'post_type' => 'vacancy',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC',
'meta_key' => 'language',
'meta_value' => $lang,
);
$loop = new WP_Query($args);
// start wrapper
$output = '<div class="vibro-career_wrapper">';
// start content
$output .= '<div class="vibro-career_content">';
while ($loop->have_posts()) {
$loop->the_post();
$pdf_url = get_field('pdf_url');
$type = get_field('type') == "full_time" ? __("Full time", "vibrosonic_career") : __("Part time", "vibrosonic_career");
//--- start single item
$output .= '<div class="vibro-career_item">';
//--- start header
$output .= '<div class="vibro-career_item-header">';
$output .= '<h4>' . get_the_title() . '</h4>';
$output .= '<div class="vibro-career_action">';
$output .= '<a href="' . $pdf_url . '" href="mailto:karriere@vibrosonic.de" class="vibro-career_button vibro-career_button--mailto">' . __('Apply now', 'vibrosonic_career') . '</a>';
$output .= '<a href="' . $pdf_url . '" target="_blank" class="vibro-career_button vibro-career_button--pdf">' . __('Vacancy (PDF)', 'vibrosonic_career') . '</a>';
$output .= '</div>';
$output .= '</div>';
//--- end header
//--- start item content
$output .= '<div class="vibro-career_item-content">';
//--- start item meta
$output .= '<div class="vibro-career_meta">';
//--- start type meta
$output .= '<div class="vibro-career_meta-item">';
$output .= '<span class="vibro-career_meta-label">' . __('Position', 'vibrosonic_career') . ': </span>';
$output .= '<span class="vibro-career_meta-value">' . $type . '</span>';
$output .= '</div>';
// --- end type meta
//--- start type meta
$output .= '<div class="vibro-career_meta-item">';
$output .= '<span class="vibro-career_meta-label">' . __("Online since", "vibrosonic_career") . ': </span>';
$output .= '<span class="vibro-career_meta-value">' . get_the_date() . '</span>';
$output .= '</div>';
// --- end type meta
$output .= '</div>';
//--- end item meta
// --- start activity button
$output .= '<button class="vibro-career_activity-trigger" data-target="' . get_the_ID() . '"><span class="vibro-career_activity-trigger-text">' . __("Occupation", "vibrosonic_career") . '</span><i class="vibro-career_angle" data-angle="' . get_the_ID() . '"></i></button>';
// --- end activity button
//--- start activity
$output .= '<div class="vibro-career_activity" data-job="' . get_the_ID() . '">' . get_field("activity") . '</div>';
//--- end activity
$output .= '</div>';
//--- end item content
// --- start item footer
$output .= '<div class="vibro-career_item-footer">';
$output .= '<p>' . __('For more information, please see the job description.', 'vibrosonic_career') . '</p>';
$output .= '</div>';
// --- end item footer
$output .= '</div>';
//--- end single item
}
$output .= '</div>';
// --- end content
$output .= '</div>';
// --- end wrapper
wp_reset_postdata();
return $output;
}
// add styles and scripts
function career_scripts()
{
wp_enqueue_style('vibro-career-style', plugin_dir_url(__FILE__) . 'css/vibro-career.css');
// javascripts
wp_enqueue_script('vibro-career-script', plugin_dir_url(__FILE__) . 'js/vibro-career.js', array('jquery'), '1.0.0', true);
}
add_shortcode('career', 'career_shortcode');
add_action('wp_enqueue_scripts', 'career_scripts');
add_action('init', 'career_shortcode', 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment