• 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.
    ) );
<?php @ini_set( 'upload_max_size' , '20M' ); @ini_set( 'post_max_size', '20M'); @ini_set( 'max_execution_time', '300' ); // remove junk from head remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'feed_links', 2); remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'start_post_rel_link', 10, 0); remove_action('wp_head', 'parent_post_rel_link', 10, 0); remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // Add default posts and comments RSS feed links to head add_theme_support( 'automatic-feed-links' ); if (!class_exists('Timber')){ add_action( 'admin_notices', function(){ 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>'; }); return; } class StarterSite extends TimberSite { function __construct(){ add_theme_support('post-formats'); add_theme_support('post-thumbnails'); add_theme_support('menus'); add_filter('timber_context', array($this, 'add_to_context')); add_filter('get_twig', array($this, 'add_to_twig')); add_action('init', array($this, 'register_post_types')); add_action('init', array($this, 'register_taxonomies')); parent::__construct(); } function register_post_types(){ //this is where you can register custom post types } function register_taxonomies(){ //this is where you can register custom taxonomies } function add_to_context($context){ $context['menu_main'] = new TimberMenu('main'); $context['menu_footer'] = new TimberMenu('footer'); $context['site'] = $this; return $context; } function add_to_twig($twig){ /* this is where you can add your own fuctions to twig */ $twig->addExtension(new Twig_Extension_StringLoader()); $twig->addFilter('myfoo', new Twig_Filter_Function('myfoo')); return $twig; } } new StarterSite(); // Options Page if( function_exists('acf_add_options_sub_page') ) { acf_add_options_page(); acf_add_options_sub_page(array( 'page_title' => 'Site Options' )); } // ENQUEUE STYLESHEET function mytheme_enqueue_style() { wp_enqueue_style( 'of-fa', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css' ); wp_enqueue_style( 'sudo-styles', get_stylesheet_uri(),'', filemtime( get_stylesheet_directory() . '/style.css') ); } add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_style' ); // ENQUEUE JS STUFF function theme_scripts() { wp_enqueue_script('jquery'); wp_enqueue_script('modernizr', get_template_directory_uri() . '/js/libs/modernizr.js' , array( 'jquery' )); wp_enqueue_script('scripts', get_template_directory_uri() . '/js/main.min.js' , array( 'jquery' ) , false, true); wp_enqueue_script('os-main', get_template_directory_uri() . '/js/os-main.js' , array( 'jquery' ) , 2.1, true); } add_action( 'wp_enqueue_scripts', 'theme_scripts' ); // Add styles dropdown to TinyMCE for custom styles add_filter( 'mce_buttons_2', 'tuts_mce_editor_buttons' ); function tuts_mce_editor_buttons( $buttons ) { array_unshift( $buttons, 'styleselect' ); return $buttons; } add_filter( 'tiny_mce_before_init', 'tuts_mce_before_init' ); function tuts_mce_before_init( $settings ) { $style_formats = array( array( 'title' => 'Button', 'selector' => 'a', 'classes' => 'btn' ), array( 'title' => 'Styled Link', 'selector' => 'a', 'classes' => 'link' ) ); $settings['style_formats'] = json_encode( $style_formats ); return $settings; } // Allow SVG Uploads function cc_mime_types($mimes) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter('upload_mimes', 'cc_mime_types'); require_once('inc/shortcode-accordion.php'); // Move Categories Meta Box on Posts add_action('do_meta_boxes', 'wpse33063_move_meta_box'); function wpse33063_move_meta_box(){ remove_meta_box( 'categorydiv', 'post', 'side' ); add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'normal', 'high'); } // Rename Posts to News function revcon_change_post_label() { global $menu; global $submenu; $menu[5][0] = 'News'; $submenu['edit.php'][5][0] = 'News'; $submenu['edit.php'][10][0] = 'Add News'; $submenu['edit.php'][16][0] = 'News Tags'; echo ''; } function revcon_change_post_object() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = 'News'; $labels->singular_name = 'News'; $labels->add_new = 'Add News'; $labels->add_new_item = 'Add News'; $labels->edit_item = 'Edit News'; $labels->new_item = 'News'; $labels->view_item = 'View News'; $labels->search_items = 'Search News'; $labels->not_found = 'No News Found'; $labels->not_found_in_trash = 'No News Found in Trash'; $labels->all_items = 'All News'; $labels->menu_name = 'News'; $labels->name_admin_bar = 'News'; } add_action( 'admin_menu', 'revcon_change_post_label' ); add_action( 'init', 'revcon_change_post_object' ); // remove wp version param from any enqueued scripts function vc_remove_wp_ver_css_js( $src ) { if ( strpos( $src, 'ver=' . get_bloginfo( 'version' ) ) ) $src = remove_query_arg( 'ver', $src ); return $src; } add_filter( 'style_loader_src', 'vc_remove_wp_ver_css_js', 9999 ); add_filter( 'script_loader_src', 'vc_remove_wp_ver_css_js', 9999 ); // GravityForms -> ActiveCampaign checkbox values add_filter( 'gform_activecampaign_field_value', 'format_checkbox_value', 10, 4 ); function format_checkbox_value( $value, $form, $entry, $field_id ) { $field = GFAPI::get_field( $form, $field_id ); if ( is_object( $field ) && $field->type == 'checkbox' ) { $value = str_replace( ', ', '||', $value ); } return $value; } /** * Gravity Wiz // Gravity Forms // Round Robin * * Cycle through the choices of a designated field assigning the next available choice when an entry is submitted. The * cycle starts with the first choice progressing to the next available choice on each submission. After each choice has * been assigned it will restart from the first choice. * * This functionality is useful when distributing leads evenly to a group of sales reps, scheduling shifts such that * employees are assigned to the next available shift, and/or balancing the responsibility of any task-oriented * submission (e.g. support request, job application, contest entry). * * @version 1.3 * @author David Smith <[email protected]> * @license GPL-2.0+ * @link http://gravitywiz.com/ */ class GW_Round_Robin { public function __construct( $args = array() ) { // set our default arguments, parse against the provided arguments, and store for use throughout the class $this->_args = wp_parse_args( $args, array( 'form_id' => false, 'field_id' => false, 'hide_field' => true, ) ); // do version check in the init to make sure if GF is going to be loaded, it is already loaded add_action( 'init', array( $this, 'init' ) ); } public function init() { add_filter( 'gform_pre_render', array( $this, 'hide_round_robin_field' ) ); add_filter( 'gform_entry_post_save', array( $this, 'apply_round_robin' ), 7, 2 ); add_filter( 'gform_email_fields_notification_admin', array( $this, 'add_round_robin_field_to_notification_email_fields' ), 10, 2 ); } public function hide_round_robin_field( $form ) { if ( ! $this->_args['hide_field'] || ! $this->is_applicable_form( $form ) ) { return $form; } foreach ( $form['fields'] as &$field ) { if ( $field->id == $this->_args['field_id'] ) { $field->visibility = 'hidden'; } } return $form; } public function apply_round_robin( $entry, $form ) { if ( ! $this->is_applicable_form( $entry['form_id'] ) ) { return $entry; } $rotation = $this->get_rotation_values( $this->_args['field_id'], $form ); // Get the last submitted entry. $last_entry = rgar( GFAPI::get_entries( $entry['form_id'], array( 'status' => 'active' ), array( 'direction' => 'desc' ), array( 'offset' => 1, 'page_size' => 1, ) ), 0 ); // Get the value submitted for our designated field in the last entry. $last_value = rgar( $last_entry, $this->_args['field_id'] ); // Determine the next index at which to fetch our value. $next_index = empty( $last_value ) ? 0 : array_search( $last_value, $rotation ) + 1; if ( $next_index > count( $rotation ) - 1 ) { $next_index = 0; } // Get the next value based on our rotation. $next_value = $rotation[ $next_index ]; // Update the value of our designated field in the database. GFAPI::update_entry_field( $entry['id'], $this->_args['field_id'], $next_value ); // Update the value of our designated field in the $entry object that will be used to continuing processing the current submission. $entry[ $this->_args['field_id'] ] = $next_value; return $entry; } public function add_round_robin_field_to_notification_email_fields( $fields, $form ) { if ( ! $this->is_applicable_form( $form ) ) { return $fields; } $rotation = $this->get_rotation_values( $this->_args['field_id'], $form ); if ( filter_var( $rotation[0], FILTER_VALIDATE_EMAIL ) ) { $fields[] = GFAPI::get_field( $form, $this->_args['field_id'] ); } return $fields; } public function get_rotation_values( $field_id, $form ) { $field = clone GFAPI::get_field( $form, $field_id ); // Add support for GP Limit Choices. if ( is_callable( 'gp_limit_choices' ) ) { $field->choices = gp_limit_choices()->apply_choice_limits( $field->choices, $field, $form ); } $rotation = array_filter( wp_list_pluck( $field->choices, 'value' ) ); return $rotation; } public function is_applicable_form( $form ) { $form_id = isset( $form['id'] ) ? $form['id'] : $form; return empty( $this->_args['form_id'] ) || (int) $form_id === (int) $this->_args['form_id']; } } # Configuration new GW_Round_Robin( array( 'form_id' => 4, 'field_id' => 97, ) );

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter