예제 #1
0
 /**
  * Force Styles for Control - Ajax Function
  *
  * Updates the 'force_styles' meta option for a 
  * particular font control instance. If this is
  * set to true then the !important modifer will
  * be added to the styles upon output. Note: the
  * js plugin passes the boolean true as the string
  * 'true', therefore we need to do a string 
  * comparison to check the users intent.
  *
  * @since 1.2
  * @version 1.3.9
  * 
  */
 public function force_font_control_styles()
 {
     // Check admin nonce for security
     check_ajax_referer('tt_font_edit_control_instance', 'tt_font_edit_control_instance_nonce');
     // Make sure user has the required access level
     if (!current_user_can('edit_theme_options')) {
         wp_die(-1);
     }
     if (isset($_POST['controlId'])) {
         $control_id = esc_attr($_POST['controlId']);
         $switch = isset($_POST['force-styles']) && 'true' == $_POST['force-styles'] ? true : false;
         $control = EGF_Posttype::get_font_control($control_id);
         if ($control) {
             update_post_meta($control->ID, 'force_styles', $switch);
         }
     }
     wp_die();
 }
 /**
  * Set Font Control Variables
  *
  * Sets the font control variables that are used throughout the
  * admin settings page.
  * 
  * @since 1.2
  * @version 1.3.9
  * 
  */
 public function set_font_controls()
 {
     $this->font_controls = EGF_Posttype::get_all_font_controls();
     $this->custom_controls = array();
     // Set no control flag
     $this->no_controls = $this->font_controls ? false : true;
     if (!$this->no_controls) {
         $count = 0;
         while ($this->font_controls->have_posts()) {
             $this->font_controls->the_post();
             // Add this control to the $custom_controls array
             $id = get_post_meta(get_the_ID(), 'control_id', true);
             $this->custom_controls[$id] = get_the_title();
             // Set curent control id to the first control
             if (0 == $count) {
                 $this->current_control_id = $id;
                 $this->first_control = EGF_Posttype::get_font_control($id);
             }
             $count++;
         }
         // Restore original Post Data
         wp_reset_postdata();
     }
     // Determine Screen via $_GET['action']
     $action = isset($_GET['action']) ? esc_attr($_GET['action']) : false;
     // Update current control id if it is passed in the URL
     if (isset($_GET['control'])) {
         $this->current_control_id = esc_attr($_GET['control']);
     }
     // The control id of the current control being edited - Note this is a string representation of '0', not an integer
     $this->control_selected_id = isset($_GET['control']) ? esc_attr($_GET['control']) : '0';
     // Attempt to get a control instance if it exists
     $this->control_instance = EGF_Posttype::get_font_control($this->control_selected_id);
     // Edit and and no control but has first control
     if ('edit' == $action) {
         if (!isset($_GET['control']) && $this->first_control) {
             $this->control_instance = $this->first_control;
         }
     }
     /**
      * Initialise screen action if no action has been set
      * in the parameter.
      */
     if (!$action) {
         if ($this->first_control) {
             $this->control_instance = $this->first_control;
             $this->control_selected_id = get_post_meta($this->control_instance->ID, 'control_id', true);
         }
     } elseif ('create' == $action) {
         $this->control_selected_id = '0';
     }
 }