Advertisement
findingsimple

Gforms Example

Mar 12th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 18.12 KB | None | 0 0
  1. <?php
  2.  
  3. class GF_CampusVue {
  4.  
  5.     static $text_domain;
  6.  
  7.     static $admin_screen_id;
  8.    
  9.     static $defaults;
  10.    
  11.     static $add_scripts;
  12.    
  13.     /**
  14.      * Initialise
  15.      */
  16.     public static function init() {
  17.    
  18.         global $wp_version;
  19.        
  20.         self::$defaults = array(
  21.             'x' => '',
  22.             'y' => array()
  23.         );
  24.        
  25.         self::$text_domain = apply_filters( 'gf_cvue_text_domain', 'gf_cvue' );
  26.  
  27.         self::$admin_screen_id = apply_filters( 'gf_cvue_admin_screen_id', 'gf_cvue' );
  28.  
  29.         self::$defaults = apply_filters( 'gf_cvue_defaults', self::$defaults );
  30.        
  31.         add_action( 'init', array( __CLASS__, 'register' ) );
  32.        
  33.         add_filter( 'gform_add_field_buttons', __CLASS__ . '::gf_cvue_add_group' );
  34.  
  35.         add_filter( 'gform_field_type_title' , __CLASS__ . '::gf_cvue_custom_titles' );
  36.  
  37.         add_action( 'gform_field_input' , __CLASS__ . '::gf_cvue_state_field_input', 10, 5 );
  38.  
  39.         add_action( 'gform_field_input' , __CLASS__ . '::gf_cvue_country_field_input', 10, 5 );
  40.        
  41.         add_action( 'gform_field_input' , __CLASS__ . '::gf_cvue_campus_field_input', 10, 5 );
  42.  
  43.         add_action( 'gform_field_input' , __CLASS__ . '::gf_cvue_program_field_input', 10, 5 );
  44.  
  45.         add_action( 'gform_field_input' , __CLASS__ . '::gf_cvue_background_field_input', 10, 5 );
  46.  
  47.         add_action( 'gform_field_input' , __CLASS__ . '::gf_cvue_referral_field_input', 10, 5 );
  48.  
  49.         add_action( 'gform_editor_js' , __CLASS__ . '::gf_cvue_editor_js' );
  50.  
  51.         add_action( 'gform_advanced_settings' , __CLASS__ . '::gf_cvue_submit_checkbox', 10, 2 );
  52.        
  53.         add_action( 'gform_editor_js' , __CLASS__ . '::gf_cvue_form_script' );
  54.        
  55.         add_filter( 'gform_tooltips', __CLASS__ . '::gf_cvue_add_form_settings_tooltips' );
  56.        
  57.         add_action( 'gform_after_submission', __CLASS__ . '::gf_cvue_submit_to_cvue', 10, 2 );
  58.        
  59.     }
  60.  
  61.     /**
  62.      * Register something
  63.      */
  64.     public static function register() {
  65.  
  66.     }
  67.    
  68.     /**
  69.      * Add Campus View Grouping
  70.      */
  71.     public static function gf_cvue_add_group( $field_groups ){
  72.    
  73.         //var_dump($field_groups);
  74.  
  75.         $campus_vue_fields = array(
  76.             array(
  77.                 "class"=>"button",
  78.                 "value" => __( "State" , "gravityforms" ),
  79.                 "onclick" => "StartAddField('state');"
  80.                 ),
  81.             array(
  82.                 "class"=>"button",
  83.                 "value" => __( "Country" , "gravityforms" ),
  84.                 "onclick" => "StartAddField('country');"
  85.                 ),
  86.             array(
  87.                 "class"=>"button",
  88.                 "value" => __( "Campus" , "gravityforms" ),
  89.                 "onclick" => "StartAddField('campus');"
  90.                 ),
  91.             array(
  92.                 "class"=>"button",
  93.                 "value" => __( "Program" , "gravityforms" ),
  94.                 "onclick" => "StartAddField('program');"
  95.                 ),
  96.             array(
  97.                 "class"=>"button",
  98.                 "value" => __( "Background" , "gravityforms" ),
  99.                 "onclick" => "StartAddField('background');"
  100.                 ),
  101.             array(
  102.                 "class"=>"button",
  103.                 "value" => __( "Referral" , "gravityforms" ),
  104.                 "onclick" => "StartAddField('referral');"
  105.                 )              
  106.             );
  107.    
  108.         $field_groups[] = array(
  109.             "name" => "campus_vue",
  110.             "label"=> __( "Campus Vue" , self::$text_domain ),
  111.             "fields" => $campus_vue_fields
  112.         );
  113.    
  114.         return $field_groups;
  115.        
  116.     }
  117.    
  118.     /**
  119.      * Modify Titles
  120.      */    
  121.     public static function gf_cvue_custom_titles( $type ) {
  122.  
  123.         if ( $type == 'state' )
  124.             return __( 'Select State' , self::$text_domain );
  125.  
  126.         if ( $type == 'country' )
  127.             return __( 'Select Country' , self::$text_domain );
  128.    
  129.         if ( $type == 'campus' )
  130.             return __( 'Select Campus' , self::$text_domain );
  131.  
  132.         if ( $type == 'background' )
  133.             return __( 'Select Background' , self::$text_domain );
  134.            
  135.         if ( $type == 'program' )
  136.             return __( 'Select Program' , self::$text_domain );        
  137.  
  138.         if ( $type == 'referral' )
  139.             return __( 'Select Referral Method' , self::$text_domain );
  140.            
  141.     }
  142.  
  143.     /**
  144.      * State Select Box Field Input
  145.      */
  146.     public static function gf_cvue_state_field_input( $input, $field, $value, $lead_id, $form_id ){
  147.    
  148.         if ( $field["type"] == "state" ) {
  149.        
  150.             $disabled = '';
  151.        
  152.             if ( is_admin() )
  153.                 $disabled = "disabled='disabled'";
  154.            
  155.             $input_name = $form_id .'_' . $field["id"];
  156.            
  157.             $tabindex = GFCommon::get_tabindex();
  158.            
  159.             $css = isset( $field['cssClass'] ) ? $field['cssClass'] : '';
  160.            
  161.             $field_id = $field["id"];
  162.            
  163.             $css_id = 'state-'. $field['id'];
  164.            
  165.             $css_classes = $field["type"] . ' ' . esc_attr( $css ) . ' ' . $field['size'];
  166.            
  167.             $value_esc = esc_html($value);
  168.            
  169.             //Build field
  170.             $input = "<div class='ginput_container'>";
  171.             $input .= "<select name='input_" . $input_name . "' id='input_" . $css_id . "'  class='medium gfield_select " . $css_classes . "' " . $tabindex . " " . $disabled . " >";
  172.             $input .= "<option value='' >Please Select</option>";
  173.  
  174.             if ( !is_admin() ) {
  175.            
  176.                 $cache = get_transient( 'gf_cvue_states' );
  177.                
  178.                 $options = '';
  179.                        
  180.                 if ( false === $cache ) {
  181.  
  182.                     $states = getList( 'State' );
  183.                        
  184.                     foreach( $states['State'] as $state ) {
  185.                                        
  186.                         $options .= "<option value='" . $state->Id . "' >" . $state->Description . "</option>";
  187.                
  188.                     }
  189.                    
  190.                     $input .= $options;
  191.                                        
  192.                     set_transient( 'gf_cvue_states', $options , 60*60*12 );
  193.                                    
  194.                 } else {
  195.            
  196.                     $input .= $cache;
  197.  
  198.                 }
  199.            
  200.             }
  201.            
  202.             $input .= "</select>";
  203.             $input .= "</div>";
  204.                        
  205.         }
  206.    
  207.         return $input;
  208.        
  209.     }
  210.  
  211.     /**
  212.      * Country Select Box Field Input
  213.      */
  214.     public static function gf_cvue_country_field_input( $input, $field, $value, $lead_id, $form_id ){
  215.    
  216.         if ( $field["type"] == "country" ) {
  217.        
  218.             $disabled = '';
  219.        
  220.             if ( is_admin() )
  221.                 $disabled = "disabled='disabled'";
  222.            
  223.             $input_name = $form_id .'_' . $field["id"];
  224.            
  225.             $tabindex = GFCommon::get_tabindex();
  226.            
  227.             $css = isset( $field['cssClass'] ) ? $field['cssClass'] : '';
  228.            
  229.             $field_id = $field["id"];
  230.            
  231.             $css_id = 'country-'. $field['id'];
  232.            
  233.             $css_classes = $field["type"] . ' ' . esc_attr( $css ) . ' ' . $field['size'];
  234.            
  235.             $value_esc = esc_html($value);
  236.            
  237.             //Build field
  238.             $input = "<div class='ginput_container'>";
  239.             $input .= "<select name='input_" . $input_name . "' id='input_" . $css_id . "'  class='medium gfield_select " . $css_classes . "' " . $tabindex . " " . $disabled . " >";
  240.             $input .= "<option value='' >Please Select</option>";
  241.            
  242.             if ( !is_admin() ) {
  243.            
  244.                 $cache = get_transient( 'gf_cvue_countries' );
  245.                
  246.                 $options = '';
  247.                        
  248.                 if ( false === $cache ) {
  249.  
  250.                     $countries = getList( 'Country' );
  251.                            
  252.                     foreach( $countries['Country'] as $country ) {
  253.                                            
  254.                         $options .= "<option value='" . $country->Id . "' >" . $country->Description . "</option>";
  255.                    
  256.                     }
  257.  
  258.                     $input .= $options;
  259.                    
  260.                     set_transient( 'gf_cvue_countries', $options, 60*60*12 );              
  261.                    
  262.                 } else {
  263.  
  264.                     $input .= $cache;
  265.  
  266.                 }
  267.            
  268.             }
  269.  
  270.             $input .= "</select>";
  271.             $input .= "</div>";
  272.                        
  273.         }
  274.    
  275.         return $input;
  276.        
  277.     }  
  278.  
  279.     /**
  280.      * Campus Select Box Field Input
  281.      */
  282.     public static function gf_cvue_campus_field_input( $input, $field, $value, $lead_id, $form_id ){
  283.    
  284.         if ( $field["type"] == "campus" ) {
  285.        
  286.             $disabled = '';
  287.        
  288.             if ( is_admin() )
  289.                 $disabled = "disabled='disabled'";
  290.            
  291.             $input_name = $form_id .'_' . $field["id"];
  292.            
  293.             $tabindex = GFCommon::get_tabindex();
  294.            
  295.             $css = isset( $field['cssClass'] ) ? $field['cssClass'] : '';
  296.            
  297.             $field_id = $field["id"];
  298.            
  299.             $css_id = 'campus-'. $field['id'];
  300.            
  301.             $css_classes = $field["type"] . ' ' . esc_attr( $css ) . ' ' . $field['size'];
  302.            
  303.             $value_esc = esc_html($value);
  304.            
  305.             //Build field
  306.             $input = "<div class='ginput_container'>";
  307.             $input .= "<select name='input_" . $input_name . "' id='input_" . $css_id . "'  class='medium gfield_select " . $css_classes . "' " . $tabindex . " " . $disabled . " >";
  308.             $input .= "<option value='' >Please Select</option>";
  309.  
  310.             if ( !is_admin() ) {
  311.            
  312.                 $cache = get_transient( 'gf_cvue_campuses' );
  313.                        
  314.                 if ( false === $cache ) {
  315.                
  316.                     $campuses = getList( 'Campus' );
  317.                    
  318.                     $options = '';
  319.                            
  320.                     foreach( $campuses['Campus'] as $campus ) {
  321.                                            
  322.                         $options .= "<option value='" . $campus->Id . "' >" . $campus->Description . "</option>";
  323.                    
  324.                     }
  325.  
  326.                     $input .= $options;
  327.                    
  328.                     set_transient( 'gf_cvue_campuses', $options, 60*60*12 );
  329.                    
  330.                 } else {
  331.            
  332.                     $input .= $cache;
  333.  
  334.                 }
  335.            
  336.             }
  337.  
  338.             $input .= "</select>";
  339.             $input .= "</div>";
  340.                        
  341.         }
  342.    
  343.         return $input;
  344.        
  345.     }
  346.    
  347.     /**
  348.      * Program Select Box Field Input
  349.      */
  350.     public static function gf_cvue_program_field_input( $input, $field, $value, $lead_id, $form_id ){
  351.    
  352.         if ( $field["type"] == "program" ) {
  353.        
  354.             $disabled = '';
  355.        
  356.             if ( is_admin() )
  357.                 $disabled = "disabled='disabled'";
  358.            
  359.             $input_name = $form_id .'_' . $field["id"];
  360.            
  361.             $tabindex = GFCommon::get_tabindex();
  362.            
  363.             $css = isset( $field['cssClass'] ) ? $field['cssClass'] : '';
  364.            
  365.             $field_id = $field["id"];
  366.            
  367.             $css_id = 'program-'. $field['id'];
  368.            
  369.             $css_classes = $field["type"] . ' ' . esc_attr( $css ) . ' ' . $field['size'];
  370.            
  371.             $value_esc = esc_html($value);
  372.            
  373.             //Build field
  374.             $input = "<div class='ginput_container'>";
  375.             $input .= "<select name='input_" . $input_name . "' id='input_" . $css_id . "'  class='medium gfield_select " . $css_classes . "' " . $tabindex . " " . $disabled . " >";
  376.             $input .= "<option value='' >Please Select</option>";
  377.  
  378.             if ( !is_admin() ) {
  379.            
  380.                 $cache = get_transient( 'gf_cvue_programs' );
  381.                        
  382.                 if ( false === $cache ) {
  383.                
  384.                     $programs = getList( 'AreaOfInterest' );
  385.                    
  386.                     $options = '';
  387.                        
  388.                     foreach( $programs['AreaOfInterest'] as $program ) {
  389.                                            
  390.                         $options .= "<option value='" . $program->Id . "' >" . $program->Description . "</option>";
  391.                    
  392.                     }
  393.                
  394.                     $input .= $options;
  395.                    
  396.                     set_transient( 'gf_cvue_programs', $options, 60*60*12 );
  397.                    
  398.                 } else {
  399.            
  400.                     $input .= $cache;
  401.  
  402.                 }
  403.            
  404.             }
  405.  
  406.  
  407.             $input .= "</select>";
  408.             $input .= "</div>";
  409.                        
  410.         }
  411.    
  412.         return $input;
  413.        
  414.     }
  415.    
  416.     /**
  417.      * Background Select Box Field Input
  418.      */
  419.     public static function gf_cvue_background_field_input( $input, $field, $value, $lead_id, $form_id ){
  420.    
  421.         if ( $field["type"] == "background" ) {
  422.        
  423.             $disabled = '';
  424.        
  425.             if ( is_admin() )
  426.                 $disabled = "disabled='disabled'";
  427.            
  428.             $input_name = $form_id .'_' . $field["id"];
  429.            
  430.             $tabindex = GFCommon::get_tabindex();
  431.            
  432.             $css = isset( $field['cssClass'] ) ? $field['cssClass'] : '';
  433.            
  434.             $field_id = $field["id"];
  435.            
  436.             $css_id = 'background-'. $field['id'];
  437.            
  438.             $css_classes = $field["type"] . ' ' . esc_attr( $css ) . ' ' . $field['size'];
  439.            
  440.             $value_esc = esc_html($value);
  441.            
  442.             //Build field
  443.             $input = "<div class='ginput_container'>";
  444.             $input .= "<select name='input_" . $input_name . "' id='input_" . $css_id . "'  class='medium gfield_select " . $css_classes . "' " . $tabindex . " " . $disabled . " >";
  445.             $input .= "<option value='' >Choose Educational Background</option>";
  446.  
  447.             if ( !is_admin() ) {
  448.            
  449.                 $cache = get_transient( 'gf_cvue_backgrounds' );
  450.                        
  451.                 if ( false === $cache ) {
  452.  
  453.                     $backgrounds = getList( 'PreviousEducation' );
  454.                    
  455.                     $options = '';
  456.                            
  457.                     foreach( $backgrounds['PreviousEducation'] as $background ) {
  458.                                            
  459.                         $options .= "<option value='" . $background->Id . "' >" . $background->Description . "</option>";
  460.                    
  461.                     }
  462.                
  463.                     $input .= $options;
  464.                    
  465.                     set_transient( 'gf_cvue_backgrounds', $options, 60*60*12 );            
  466.                    
  467.                 } else {
  468.            
  469.                     $input .= $cache;
  470.  
  471.                 }
  472.            
  473.             }
  474.  
  475.             $input .= "</select>";
  476.             $input .= "</div>";
  477.                        
  478.         }
  479.    
  480.         return $input;
  481.        
  482.     }
  483.    
  484.     /**
  485.      * Referral Select Box Field Input
  486.      */
  487.     public static function gf_cvue_referral_field_input( $input, $field, $value, $lead_id, $form_id ){
  488.    
  489.         if ( $field["type"] == "referral" ) {
  490.        
  491.             $disabled = '';
  492.        
  493.             if ( is_admin() )
  494.                 $disabled = "disabled='disabled'";
  495.            
  496.             $input_name = $form_id .'_' . $field["id"];
  497.            
  498.             $tabindex = GFCommon::get_tabindex();
  499.            
  500.             $css = isset( $field['cssClass'] ) ? $field['cssClass'] : '';
  501.            
  502.             $field_id = $field["id"];
  503.            
  504.             $css_id = 'referral-'. $field['id'];
  505.            
  506.             $css_classes = $field["type"] . ' ' . esc_attr( $css ) . ' ' . $field['size'];
  507.            
  508.             $value_esc = esc_html($value);
  509.            
  510.             //Build field
  511.             $input = "<div class='ginput_container'>";
  512.             $input .= "<select name='input_" . $input_name . "' id='input_" . $css_id . "'  class='medium gfield_select " . $css_classes . "' " . $tabindex . " " . $disabled . " >";
  513.             $input .= "<option value='' >Please Select</option>";
  514.  
  515.             if ( !is_admin() ) {
  516.            
  517.                 $cache = get_transient( 'gf_cvue_referrals' );
  518.                        
  519.                 if ( false === $cache ) {
  520.  
  521.                     $sources = getList( 'LeadSource' );
  522.                    
  523.                     $options = '';
  524.                            
  525.                     foreach( $sources['LeadSource'] as $source ) {
  526.                                            
  527.                         $options .= "<option value='" . $source->Id . "' >" . $source->Description . "</option>";
  528.                    
  529.                     }
  530.                
  531.                     $input .= $options;
  532.                    
  533.                     set_transient( 'gf_cvue_referrals', $options, 60*60*12 );
  534.                                    
  535.                 } else {
  536.            
  537.                     $input .= $cache;
  538.  
  539.                 }
  540.            
  541.             }
  542.  
  543.             $input .= "</select>";
  544.             $input .= "</div>";
  545.                        
  546.         }
  547.    
  548.         return $input;
  549.        
  550.     }
  551.    
  552.     /**
  553.      * Custom editor js for Campus View Input Fields
  554.      */
  555.     public static function gf_cvue_editor_js(){
  556.     ?>
  557.    
  558.     <script type='text/javascript'>
  559.    
  560.         jQuery(document).ready(function($) {
  561.                    
  562.             var input_fields = new Array( 'state', 'country', 'campus', 'background', 'program', 'referral' );
  563.            
  564.             var length = input_fields.length;
  565.            
  566.             for ( var i = 0; i < length; i++) {
  567.  
  568.                 var field_name = input_fields[i];
  569.            
  570.                 //set fields to appear
  571.                 fieldSettings[ field_name ] = ".label_setting, .description_setting, .admin_label_setting, .size_setting, .error_message_setting, .css_class_setting, .visibility_setting ";
  572.        
  573.                 //binding to the load field settings event to initialize the checkbox
  574.                 $(document).bind("gform_load_field_settings", function(event, field, form){
  575.                
  576.                     jQuery("#field_"+field_name).attr("checked", field["field_"+field_name] == true);
  577.                    
  578.                     $("#field_"+field_name+"_value").val(field[ field_name ]);
  579.                    
  580.                 });
  581.            
  582.             }
  583.            
  584.         });
  585.    
  586.     </script>
  587.     <?php
  588.     }
  589.    
  590.     /**
  591.      * Add checkbox for selecting whether or not the form should submit to campusvue
  592.      */
  593.     function gf_cvue_submit_checkbox( $position, $form_id ){
  594.                
  595.         //create settings on position 50 (right after Admin Label)
  596.         if( $position == 800 ){
  597.             ?>
  598.             <li class="campusvue_setting field_setting">
  599.                 <input type="checkbox" id="field_campusvue_value" /> <label for="field_campusvue_value">Submit to CampusVue <?php gform_tooltip('form_field_campusvue_value') ?></label>
  600.             </li>
  601.             <?php
  602.         }
  603.     }
  604.    
  605.     /**
  606.      * Inject supporting script to the form editor page
  607.      */    
  608.     function gf_cvue_form_script(){
  609.         ?>
  610.  
  611.         <script type="text/javascript">
  612.        
  613.             jQuery("#field_campusvue_value").attr("checked", form.enableCvueSubmit ? true : false ).change( function() {
  614.            
  615.                 form.enableCvueSubmit = jQuery("#field_campusvue_value").is(":checked");
  616.                
  617.             });
  618.        
  619.             form.enableCvueSubmit = jQuery("#field_campusvue_value").is(":checked");
  620.            
  621.         </script>      
  622.        
  623.         <?php
  624.     }
  625.    
  626.     /**
  627.      * Add a new tooltip
  628.      */    
  629.     function gf_cvue_add_form_settings_tooltips( $tooltips ){
  630.    
  631.        $tooltips['form_field_campusvue_value'] = "<h6>Submit to CampusVue</h6>Check this box to submit this form's data";
  632.        
  633.        return $tooltips;
  634.        
  635.     }
  636.  
  637.     /**
  638.      * Submit form data to Campus Vue
  639.      */    
  640.     function gf_cvue_submit_to_cvue( $entry, $form ) {
  641.        
  642.         if ( ! isset( $form['enableCvueSubmit'] ) || false == $form['enableCvueSubmit'] )
  643.             return;
  644.        
  645.         $lead = new Lead();
  646.  
  647.         foreach ( $form['fields'] as $field ) {
  648.             if ( is_array( $field['inputs'] ) ) {
  649.                 foreach ( $field['inputs'] as $input ) {
  650.                     switch ( strtolower( $input['label'] ) ) {
  651.                         case 'first' :
  652.                             $lead->FirstName = $entry[$input['id']];
  653.                         break 1;
  654.                         case 'last' :
  655.                             $lead->LastName = $entry[$input['id']];
  656.                         break 1;
  657.                     }
  658.                 }
  659.             } else {
  660.                 switch ( $field['type'] ) {
  661.                     case 'state' :
  662.                         $lead->StateId = $_POST['input_' . $field['formId'] . '_' . $field['id']];
  663.                     break 1;
  664.                     case 'country' :
  665.                         $lead->CountryId = $_POST['input_' . $field['formId'] . '_' . $field['id']];
  666.                     break 1;
  667.                     case 'phone' :
  668.                         $lead->Phone = $entry[$field['id']];
  669.                     break 1;
  670.                     case 'email' :
  671.                         $lead->EMail = $entry[$field['id']];
  672.                     break 1;
  673.                     case 'campus' :
  674.                         $lead->CampusId = $_POST['input_3_' . $field['id']];
  675.                     break 1;
  676.                     case 'program' :
  677.                         $lead->AreaOfInterestId = $_POST['input_' . $field['formId'] . '_' . $field['id']];
  678.                     break 1;
  679.                     case 'background' :
  680.                         $lead->PreviousEducationId = $_POST['input_' . $field['formId'] . '_' . $field['id']];
  681.                     break 1;
  682.                     case 'referral' :
  683.                         $lead->LeadSourceId = $_POST['input_' . $field['formId'] . '_' . $field['id']];
  684.                     break 1;
  685.                     case 'text' :
  686.                         switch ( strtolower( $field['label'] ) ) {
  687.                             case 'address' :
  688.                                 $lead->Address = $entry[$field['id']];
  689.                             break 1;
  690.                             case 'city' :
  691.                                 $lead->City = $entry[$field['id']];
  692.                             break 1;
  693.                             case 'postcode' :
  694.                                 $lead->PostalCode = $entry[$field['id']];
  695.                             break 1;
  696.                         }
  697.                     break 1;
  698.                 }
  699.             }
  700.         }
  701.        
  702.         //var_dump( $lead );
  703.         error_log( '$lead = ' . print_r( $lead, true ) );
  704.        
  705.         addNewLead( $lead );
  706.        
  707.         var_dump( $res );
  708.        
  709.     }
  710.    
  711.     /**
  712.      * Helper function to get the URL of a given file.
  713.      *
  714.      * As this plugin may be used as both a stand-alone plugin and as a submodule of
  715.      * a theme, the standard WP API functions, like plugins_url() can not be used.
  716.      *
  717.      * @since 1.0
  718.      * @return array $post_name => $post_content
  719.      */
  720.     public static function get_url( $file ) {
  721.  
  722.         // Get the path of this file after the WP content directory
  723.         $post_content_path = substr( dirname( str_replace('\\','/',__FILE__) ), strpos( __FILE__, basename( WP_CONTENT_DIR ) ) + strlen( basename( WP_CONTENT_DIR ) ) );
  724.  
  725.         // Return a content URL for this path & the specified file
  726.         return content_url( $post_content_path . $file );
  727.     }  
  728.    
  729.    
  730. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement