Snippi
A super awesome snippet tool.
- 1.
<?php
- 2.
@ini_set( 'upload_max_size' , '20M' );
- 3.
@ini_set( 'post_max_size', '20M');
- 4.
@ini_set( 'max_execution_time', '300' );
- 5.
- 6.
- 7.
// remove junk from head
- 8.
remove_action('wp_head', 'rsd_link');
- 9.
remove_action('wp_head', 'wp_generator');
- 10.
remove_action('wp_head', 'feed_links', 2);
- 11.
remove_action('wp_head', 'index_rel_link');
- 12.
remove_action('wp_head', 'wlwmanifest_link');
- 13.
remove_action('wp_head', 'feed_links_extra', 3);
- 14.
remove_action('wp_head', 'start_post_rel_link', 10, 0);
- 15.
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
- 16.
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
- 17.
- 18.
// Add default posts and comments RSS feed links to head
- 19.
add_theme_support( 'automatic-feed-links' );
- 20.
- 21.
- 22.
- 23.
- 24.
if (!class_exists('Timber')){
- 25.
add_action( 'admin_notices', function(){
- 26.
echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . admin_url('plugins.php#timber') . '">' . admin_url('plugins.php') . '</a></p></div>';
- 27.
});
- 28.
return;
- 29.
}
- 30.
- 31.
class StarterSite extends TimberSite {
- 32.
- 33.
function __construct(){
- 34.
add_theme_support('post-formats');
- 35.
add_theme_support('post-thumbnails');
- 36.
add_theme_support('menus');
- 37.
add_filter('timber_context', array($this, 'add_to_context'));
- 38.
add_filter('get_twig', array($this, 'add_to_twig'));
- 39.
add_action('init', array($this, 'register_post_types'));
- 40.
add_action('init', array($this, 'register_taxonomies'));
- 41.
parent::__construct();
- 42.
}
- 43.
- 44.
function register_post_types(){
- 45.
//this is where you can register custom post types
- 46.
}
- 47.
- 48.
function register_taxonomies(){
- 49.
//this is where you can register custom taxonomies
- 50.
}
- 51.
- 52.
function add_to_context($context){
- 53.
$context['menu_main'] = new TimberMenu('main');
- 54.
$context['menu_footer'] = new TimberMenu('footer');
- 55.
$context['site'] = $this;
- 56.
return $context;
- 57.
}
- 58.
- 59.
function add_to_twig($twig){
- 60.
/* this is where you can add your own fuctions to twig */
- 61.
$twig->addExtension(new Twig_Extension_StringLoader());
- 62.
$twig->addFilter('myfoo', new Twig_Filter_Function('myfoo'));
- 63.
return $twig;
- 64.
}
- 65.
- 66.
}
- 67.
- 68.
new StarterSite();
- 69.
- 70.
- 71.
// Options Page
- 72.
if( function_exists('acf_add_options_sub_page') )
- 73.
{
- 74.
- 75.
acf_add_options_page();
- 76.
acf_add_options_sub_page(array(
- 77.
'page_title' => 'Site Options'
- 78.
));
- 79.
}
- 80.
- 81.
- 82.
// ENQUEUE STYLESHEET
- 83.
function mytheme_enqueue_style() {
- 84.
wp_enqueue_style( 'of-fa', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css' );
- 85.
wp_enqueue_style( 'sudo-styles', get_stylesheet_uri(),'', filemtime( get_stylesheet_directory() . '/style.css') );
- 86.
}
- 87.
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_style' );
- 88.
- 89.
- 90.
// ENQUEUE JS STUFF
- 91.
function theme_scripts() {
- 92.
wp_enqueue_script('jquery');
- 93.
wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/libs/modernizr.js' , array( 'jquery' ));
- 94.
wp_enqueue_script('scripts', get_template_directory_uri() . '/js/main.min.js' , array( 'jquery' ) , false, true);
- 95.
wp_enqueue_script('os-main', get_template_directory_uri() . '/js/os-main.js' , array( 'jquery' ) , 2.1, true);
- 96.
}
- 97.
add_action( 'wp_enqueue_scripts', 'theme_scripts' );
- 98.
- 99.
- 100.
- 101.
// Add styles dropdown to TinyMCE for custom styles
- 102.
add_filter( 'mce_buttons_2', 'tuts_mce_editor_buttons' );
- 103.
- 104.
function tuts_mce_editor_buttons( $buttons ) {
- 105.
array_unshift( $buttons, 'styleselect' );
- 106.
return $buttons;
- 107.
}
- 108.
- 109.
add_filter( 'tiny_mce_before_init', 'tuts_mce_before_init' );
- 110.
- 111.
function tuts_mce_before_init( $settings ) {
- 112.
- 113.
$style_formats = array(
- 114.
array(
- 115.
'title' => 'Button',
- 116.
'selector' => 'a',
- 117.
'classes' => 'btn'
- 118.
),
- 119.
array(
- 120.
'title' => 'Styled Link',
- 121.
'selector' => 'a',
- 122.
'classes' => 'link'
- 123.
)
- 124.
);
- 125.
- 126.
$settings['style_formats'] = json_encode( $style_formats );
- 127.
- 128.
return $settings;
- 129.
}
- 130.
- 131.
- 132.
// Allow SVG Uploads
- 133.
function cc_mime_types($mimes) {
- 134.
$mimes['svg'] = 'image/svg+xml';
- 135.
return $mimes;
- 136.
}
- 137.
add_filter('upload_mimes', 'cc_mime_types');
- 138.
- 139.
- 140.
require_once('inc/shortcode-accordion.php');
- 141.
- 142.
- 143.
- 144.
// Move Categories Meta Box on Posts
- 145.
add_action('do_meta_boxes', 'wpse33063_move_meta_box');
- 146.
- 147.
function wpse33063_move_meta_box(){
- 148.
remove_meta_box( 'categorydiv', 'post', 'side' );
- 149.
add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'normal', 'high');
- 150.
}
- 151.
- 152.
- 153.
- 154.
// Rename Posts to News
- 155.
function revcon_change_post_label() {
- 156.
global $menu;
- 157.
global $submenu;
- 158.
$menu[5][0] = 'News';
- 159.
$submenu['edit.php'][5][0] = 'News';
- 160.
$submenu['edit.php'][10][0] = 'Add News';
- 161.
$submenu['edit.php'][16][0] = 'News Tags';
- 162.
echo '';
- 163.
}
- 164.
function revcon_change_post_object() {
- 165.
global $wp_post_types;
- 166.
$labels = &$wp_post_types['post']->labels;
- 167.
$labels->name = 'News';
- 168.
$labels->singular_name = 'News';
- 169.
$labels->add_new = 'Add News';
- 170.
$labels->add_new_item = 'Add News';
- 171.
$labels->edit_item = 'Edit News';
- 172.
$labels->new_item = 'News';
- 173.
$labels->view_item = 'View News';
- 174.
$labels->search_items = 'Search News';
- 175.
$labels->not_found = 'No News Found';
- 176.
$labels->not_found_in_trash = 'No News Found in Trash';
- 177.
$labels->all_items = 'All News';
- 178.
$labels->menu_name = 'News';
- 179.
$labels->name_admin_bar = 'News';
- 180.
}
- 181.
- 182.
add_action( 'admin_menu', 'revcon_change_post_label' );
- 183.
add_action( 'init', 'revcon_change_post_object' );
- 184.
- 185.
// remove wp version param from any enqueued scripts
- 186.
function vc_remove_wp_ver_css_js( $src ) {
- 187.
if ( strpos( $src, 'ver=' . get_bloginfo( 'version' ) ) )
- 188.
$src = remove_query_arg( 'ver', $src );
- 189.
return $src;
- 190.
}
- 191.
add_filter( 'style_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
- 192.
add_filter( 'script_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
- 193.
- 194.
// GravityForms -> ActiveCampaign checkbox values
- 195.
add_filter( 'gform_activecampaign_field_value', 'format_checkbox_value', 10, 4 );
- 196.
function format_checkbox_value( $value, $form, $entry, $field_id ) {
- 197.
$field = GFAPI::get_field( $form, $field_id );
- 198.
- 199.
if ( is_object( $field ) && $field->type == 'checkbox' ) {
- 200.
$value = str_replace( ', ', '||', $value );
- 201.
}
- 202.
- 203.
return $value;
- 204.
}
- 205.
- 206.
- 207.
/**
- 208.
* Gravity Wiz // Gravity Forms // Round Robin
- 209.
*
- 210.
* Cycle through the choices of a designated field assigning the next available choice when an entry is submitted. The
- 211.
* cycle starts with the first choice progressing to the next available choice on each submission. After each choice has
- 212.
* been assigned it will restart from the first choice.
- 213.
*
- 214.
* This functionality is useful when distributing leads evenly to a group of sales reps, scheduling shifts such that
- 215.
* employees are assigned to the next available shift, and/or balancing the responsibility of any task-oriented
- 216.
* submission (e.g. support request, job application, contest entry).
- 217.
*
- 218.
* @version 1.3
- 219.
* @author David Smith <[email protected]>
- 220.
* @license GPL-2.0+
- 221.
* @link http://gravitywiz.com/
- 222.
*/
- 223.
class GW_Round_Robin {
- 224.
- 225.
public function __construct( $args = array() ) {
- 226.
- 227.
// set our default arguments, parse against the provided arguments, and store for use throughout the class
- 228.
$this->_args = wp_parse_args(
- 229.
$args,
- 230.
array(
- 231.
'form_id' => false,
- 232.
'field_id' => false,
- 233.
'hide_field' => true,
- 234.
)
- 235.
);
- 236.
- 237.
// do version check in the init to make sure if GF is going to be loaded, it is already loaded
- 238.
add_action( 'init', array( $this, 'init' ) );
- 239.
- 240.
}
- 241.
- 242.
public function init() {
- 243.
- 244.
add_filter( 'gform_pre_render', array( $this, 'hide_round_robin_field' ) );
- 245.
add_filter( 'gform_entry_post_save', array( $this, 'apply_round_robin' ), 7, 2 );
- 246.
- 247.
add_filter( 'gform_email_fields_notification_admin', array( $this, 'add_round_robin_field_to_notification_email_fields' ), 10, 2 );
- 248.
- 249.
}
- 250.
- 251.
public function hide_round_robin_field( $form ) {
- 252.
- 253.
if ( ! $this->_args['hide_field'] || ! $this->is_applicable_form( $form ) ) {
- 254.
return $form;
- 255.
}
- 256.
- 257.
foreach ( $form['fields'] as &$field ) {
- 258.
if ( $field->id == $this->_args['field_id'] ) {
- 259.
$field->visibility = 'hidden';
- 260.
}
- 261.
}
- 262.
- 263.
return $form;
- 264.
}
- 265.
- 266.
public function apply_round_robin( $entry, $form ) {
- 267.
- 268.
if ( ! $this->is_applicable_form( $entry['form_id'] ) ) {
- 269.
return $entry;
- 270.
}
- 271.
- 272.
$rotation = $this->get_rotation_values( $this->_args['field_id'], $form );
- 273.
- 274.
// Get the last submitted entry.
- 275.
$last_entry = rgar(
- 276.
GFAPI::get_entries(
- 277.
$entry['form_id'],
- 278.
array( 'status' => 'active' ),
- 279.
array( 'direction' => 'desc' ),
- 280.
array(
- 281.
'offset' => 1,
- 282.
'page_size' => 1,
- 283.
)
- 284.
),
- 285.
0
- 286.
);
- 287.
- 288.
// Get the value submitted for our designated field in the last entry.
- 289.
$last_value = rgar( $last_entry, $this->_args['field_id'] );
- 290.
- 291.
// Determine the next index at which to fetch our value.
- 292.
$next_index = empty( $last_value ) ? 0 : array_search( $last_value, $rotation ) + 1;
- 293.
if ( $next_index > count( $rotation ) - 1 ) {
- 294.
$next_index = 0;
- 295.
}
- 296.
- 297.
// Get the next value based on our rotation.
- 298.
$next_value = $rotation[ $next_index ];
- 299.
- 300.
// Update the value of our designated field in the database.
- 301.
GFAPI::update_entry_field( $entry['id'], $this->_args['field_id'], $next_value );
- 302.
- 303.
// Update the value of our designated field in the $entry object that will be used to continuing processing the current submission.
- 304.
$entry[ $this->_args['field_id'] ] = $next_value;
- 305.
- 306.
return $entry;
- 307.
}
- 308.
- 309.
public function add_round_robin_field_to_notification_email_fields( $fields, $form ) {
- 310.
- 311.
if ( ! $this->is_applicable_form( $form ) ) {
- 312.
return $fields;
- 313.
}
- 314.
- 315.
$rotation = $this->get_rotation_values( $this->_args['field_id'], $form );
- 316.
- 317.
if ( filter_var( $rotation[0], FILTER_VALIDATE_EMAIL ) ) {
- 318.
$fields[] = GFAPI::get_field( $form, $this->_args['field_id'] );
- 319.
}
- 320.
- 321.
return $fields;
- 322.
}
- 323.
- 324.
public function get_rotation_values( $field_id, $form ) {
- 325.
- 326.
$field = clone GFAPI::get_field( $form, $field_id );
- 327.
- 328.
// Add support for GP Limit Choices.
- 329.
if ( is_callable( 'gp_limit_choices' ) ) {
- 330.
$field->choices = gp_limit_choices()->apply_choice_limits( $field->choices, $field, $form );
- 331.
}
- 332.
- 333.
$rotation = array_filter( wp_list_pluck( $field->choices, 'value' ) );
- 334.
- 335.
return $rotation;
- 336.
}
- 337.
- 338.
public function is_applicable_form( $form ) {
- 339.
- 340.
$form_id = isset( $form['id'] ) ? $form['id'] : $form;
- 341.
- 342.
return empty( $this->_args['form_id'] ) || (int) $form_id === (int) $this->_args['form_id'];
- 343.
}
- 344.
- 345.
}
- 346.
- 347.
# Configuration
- 348.
- 349.
new GW_Round_Robin( array(
- 350.
'form_id' => 4,
- 351.
'field_id' => 97,
- 352.
) );