Conversation
review · 5 starsafter installing when i tried to activate it, it answered with a complex error
Hi aabella, Sorry for the slow reply. WordPress didn’t send me a message about this comment. Could you tell me what the error is (take a screenshot or copy/paste the message) so I could try to track down the issue? Any other details you have such as which version of WordPress you’re using (you can find this in the bottom right corner of your WordPress admin dashboard) and which version of PHP you’re using (you would find this at your web host) would be helpful.
wordpress 4.4 4, 'btn_slug' => 'respect', 'btn_type' => 'post' ); $test_btn = new Enp_Button($args); var_dump($test_btn);*/ //public function __construct($slug = false, $is_comment = false) { public function __construct($args = array()) { // arguments for querying the Enp_Button object $default_args = array( 'post_id' => false, // set to post or comment id 'btn_slug' => false, // set to slug string or array of strings, "respect", "recommend", "important". also accepts array 'btn_type' => false // slug of the post type. post, page, comment, or cpt slug ); $args = array_merge($default_args, $args); if($args['btn_slug'] === false) { // return all buttons if they didn't specify which one // USAGE: $enp_btns = new Enp_Button(); // $enp_btns = $enp_btns->get_btns(); $this->get_btns($args); } else { // get the one they asked for // USAGE: $enp_btn = new Enp_Button('respect'); $enp_btn = $this->set_btn($args); } } /* NOT IN USE public function get_btn($args) { $enp_btn_values = get_option('enp_buttons_'.$slug); return $this->set_btn($enp_btn_values); }*/ protected function set_btn($args) { // try/catch to return exception if no button is found try { // get the data from wp_options if($args['btn_slug'] !== false) { $slug = $args['btn_slug']; $enp_btn = get_option('enp_button_'.$slug); } else { $enp_btn = false; throw new Exception('Enp_Button: No btn_slug set.'); } if($enp_btn !== false) { $this->btn_type = $this->set_btn_type($enp_btn, $args); // check to see if the button types return true if($this->btn_type !== false) { $this->btn_slug = $this->set_btn_slug($enp_btn); // set all the attributes $this->btn_name = $this->set_btn_name($enp_btn); $this->btn_count = $this->set_btn_count($enp_btn['btn_slug'], $args); $this->btn_lock = $this->set_btn_lock(); } else { // throw new Exception('Enp_Button: No button found for that btn_type'); } } else { throw new Exception('Enp_Button: No button found'); } } catch(Exception $e) { // return our exception echo $e->getMessage(); } } /* * set the button slug for the Enp_Button object */ protected function set_btn_slug($enp_btn) { $slug = false; if(isset($enp_btn['btn_slug'])) { $slug = $enp_btn['btn_slug']; } return $slug; } /* * * set the button name for the Enp_Button object * */ protected function set_btn_name($enp_btn) { $name = false; if(isset($enp_btn['btn_name'])) { $name = $enp_btn['btn_name']; } return $name; } /* * * set the button type for the current Enp_Button object * as an array of types - ie - ['btn_type'] => array('comment' => false, 'posts' => true) * */ protected function set_btn_type($enp_btn, $args) { $btn_type = false; if(isset($enp_btn['btn_type'])) { $btn_type = $enp_btn['btn_type']; } // check if our args match at all. If there's a match, then we can return the object if($btn_type !== false && $args['btn_type'] !== false) { $btn_type_match = false; // this is a string, so we can check if that btn_type is set to true // because this will check for $btn_type['comment'] = '1', etc if( $btn_type[$args['btn_type']] !== false ) { $btn_type_match = true; } } else { $btn_type_match = true; // because there's nothing requested (false), // not really a match but we should return the object } if($btn_type_match === true) { return $btn_type; } else { return false; } // TODO? // If a custom post type gets added, this will throw a PHP notice // that $btn_type['custom_post'] is not set // The way to set it would be loop through ALL active post types // with registeredContentTypes() and set any post types that aren't // set as false. It's an extra check for something that's not a big // deal though, so I'm not sure if it's worth the resources or not } /* * * Set the btn count value * */ protected function set_btn_count($btn_slug, $args) { $enp_btn_count = false; if($args['btn_type'] === 'comment') { if($args['post_id'] !== false) { $comment_id = $args['post_id']; } else { global $comment; $comment_id = $comment->comment_ID; } $enp_btn_count = get_comment_meta($comment_id, 'enp_button_'.$btn_slug, true); } elseif(!is_admin()) { $post_id = false; if($args['post_id'] !== false) { $post_id = $args['post_id']; } else { global $post; $post_id = $post->ID; } if($post_id !== false) { // individual post button $enp_btn_count = get_post_meta($post_id,'enp_button_'.$btn_slug, true); } else { // TODO: get a global count? // $enp_btn_count = get_option('enp_button_'.$enp_btn['btn_slug']); } } // default 0 if nothing is found/posted yet $count = 0; if($enp_btn_count !== false) { $count = (int) $enp_btn_count; } return $count; } /* * * Set the btn lock value. if count is 0 or greater, lock it * */ protected function set_btn_lock() { $lock = false; // if btn_count is greater than 0, lock it if($this->btn_count > 0) { $lock = true; } return $lock; } /* * * returns the button slug for the current Enp_Button object * USAGE: $enp_btn = new Enp_Button('respect'); * $enp_btn->get_btn_slug; // 'respect' * */ public function get_btn_slug() { return $this->btn_slug; } /* * * returns the button name for the current Enp_Button object * USAGE: $enp_btn = new Enp_Button('respect'); * $enp_btn->get_btn_name; // 'Respect' * */ public function get_btn_name() { return $this->btn_name; } public function get_btn_types() { return $this->btn_type; } public function get_btn_count() { return $this->btn_count; } public function get_formatted_btn_count() { $formatted_count = $this->btn_count; if(1000 <= $formatted_count ){ if(1000000 <= $formatted_count) { $format_symbol = 'm'; $format_divide = 100000; } else { $format_symbol = 'k'; $format_divide = 1000; } $formatted_count = $formatted_count/$format_divide; $formatted_count = floor($formatted_count * 10) / 10; // get our decimal places (ie 2.5) $formatted_count = number_format($formatted_count, 1); // removes .0 from end of number, if it's a .0 // ex- 12.0 becomes 12 $formatted_count = $formatted_count + 0; $formatted_count_html = $formatted_count.''.$format_symbol.''; } else { $formatted_count_html = number_format($formatted_count); } return apply_filters('enp_formatted_btn_count', $formatted_count_html); } public function get_btn_lock() { return $this->btn_lock; } /* * * get an individual button type * returns array of types - ie - array('comment' => false, 'posts' => true) * */ public function get_btn_type($type = false) { $btn_type = $this->btn_type; $get_btn_type = false; if($type !== false && isset($btn_type[$type])) { $get_btn_type = $btn_type[$type]; } return $get_btn_type; } /* * * Return all button slugs from enp_button_slugs in an array * Used by function get_btns() * */ public function get_btn_slugs() { $enp_button_slugs = get_option('enp_button_slugs'); return $enp_button_slugs; } /* * Return all buttons as an array of individual objects * (ie- $this->get_btns() = array([0]=> object(Enp_Button){[btn_slug]=>'', [btn_name]=>''}, * [1]=> object(Enp_Button){[btn_slug]=>'', [btn_name]=>''}); * * USAGE * $enp_btns = new Enp_Button(); * $enp_btns = $enp_btns->get_btns(); * foreach($enp_btns as $enp_btn) { * echo ' '.$enp_btn->get_btn_name().' '; * // Outputs button name (ie- Recommend, Respect, Important, ...) * } * */ public function get_btns($args = false) { $enp_btns = $this->get_btn_slugs(); if($enp_btns === false) { return false; // no slugs set yet } $enp_btns_obj = array(); foreach($enp_btns as $slug) { $args['btn_slug'] = $slug; $enp_btns_obj[] = new Enp_Button($args); } if($enp_btns_obj !== null) { $i = 0; foreach($enp_btns_obj as $obj) { // remove any null objects if($obj->btn_slug === NULL) { unset($enp_btns_obj[$i]); //removes the array at given index $reindex = array_values($enp_btns_obj); //normalize index $enp_btns_obj = $reindex; //update variable } $i++; } } return $enp_btns_obj; } } ?> '; } /* * * Register and enqueue style sheet & scripts. * */ public function enp_btn_register_scripts() { $version = '1.0.3'; // get our style choice from the database $enp_btn_style = get_option('enp_button_style'); if(!empty($enp_btn_style)) { $style_path = plugins_url( 'engaging-buttons/front-end/css/enp-button-'.$enp_btn_style.'.min.css' ); } else { $style_path = plugins_url( 'engaging-buttons/front-end/css/enp-button-plain-styles.min.css' ); } wp_register_style( 'enp-button-style', $style_path, array(), $version); wp_enqueue_style( 'enp-button-style' ); // add custom button color CSS, if necessary $enp_button_css = get_option('enp_button_color_css'); if($enp_button_css !== false && !empty($enp_button_css) ) { wp_add_inline_style( 'enp-button-style', $enp_button_css ); } $enp_button_font = get_option('enp_button_font'); if($enp_button_font === 'open_sans') { wp_register_style( 'open_sans', 'https://fonts.googleapis.com/css?family=Open+Sans:600'); wp_enqueue_style( 'open_sans' ); // yeah, 14.28px is weird for a font size, but it's what WordPress Admin computes it to // and we want it to match what people see on the admin panel $enp_open_sans_css = ' body .enp-btns-wrap .enp-btn { font-family: "Open Sans", Helvetica Neue, Helvetica, Arial, sans-serif; font-weight: 600; font-size: 14.28px; } body .enp-btns-wrap .enp-btn-wrap { margin-top: 6px; }'; wp_add_inline_style( 'enp-button-style', $enp_open_sans_css ); } wp_register_script( 'enp-button-scripts', plugins_url( 'engaging-buttons/front-end/js/scripts.min.js' ), array( 'jquery' ), $version, true); wp_enqueue_script( 'enp-button-scripts' ); // in JavaScript, object properties are accessed as enp_button_params.ajax_url, enp_button_params.attr_name // This writes the params to the document // Get the protocol of the current page $protocol = isset( $_SERVER['HTTPS'] ) ? 'https://' : 'http://'; $is_enp_btn_clickable = enp_btn_clickable(); if($is_enp_btn_clickable === false) { $is_enp_btn_clickable = 0; } else { $is_enp_btn_clickable = 1; } $user_id = get_current_user_id(); // will return 0 if none found $login_url = wp_login_url( get_permalink() ); wp_localize_script( 'enp-button-scripts', 'enp_button_params', array( 'ajax_url' => admin_url( 'admin-ajax.php', $protocol ), 'enp_btn_clickable'=> $is_enp_btn_clickable, 'enp_login_url'=>$login_url, 'enp_btn_user_id'=> $user_id) ); } } // fire up our styles and scripts $init = new Enp_Button_Loader(); ?> get_current_user_id(), // try to set the current user id 'btn_slug' => false, // set to slug string or array of strings, "respect", "recommend", "important". also accepts array 'btn_type' => false // post or comment. we don't care if it's a page or cpt ); // merge the default_args and args arrays $args = array_merge($default_args, $args); $this->user_id = $args['user_id']; // sets both $this->clicked_posts and $this->clicked_comments $this->set_user_clicks($args); } protected function set_user_clicks($args) { $btn_slugs = $this->set_btn_slugs($args); if($btn_slugs === false) { return false; // no slugs, get outta } $btn_types = $this->set_btn_types($args); $clicked_btns = array(); // if we have a string, lets turn it into an array to keep our processing // code more DRY if(!is_array($btn_slugs)) { $btn_slugs = array($btn_slugs); } if(!is_array($btn_types)) { $btn_types = array($btn_types); } foreach($btn_slugs as $btn_slug) { // create an empty array for this btn_slug ${'clicked_'.$btn_slug} = array(); // loop through the slugs foreach($btn_types as $btn_type) { // for each btn_type, push the user meta for that button to the clicked_btn_slug array as an associative array ${'clicked_'.$btn_slug}[$btn_type] = get_user_meta($this->user_id, 'enp_button_'.$btn_type.'_'.$btn_slug, true); }...
Hi aabella, Sorry for the slow reply. WordPress didn’t send me a message about this comment. Could you tell me what the error is (take a screenshot or copy/paste the message) so I could try to track down the issue? Any other details you have such as which version of WordPress you’re using (you can find this in the bottom right corner of your WordPress admin dashboard) and which version of PHP you’re using (you would find this at your web host) would be helpful.
wordpress 4.4 4, 'btn_slug' => 'respect', 'btn_type' => 'post' ); $test_btn = new Enp_Button($args); var_dump($test_btn);*/ //public function __construct($slug = false, $is_comment = false) { public function __construct($args = array()) { // arguments for querying the Enp_Button object $default_args = array( 'post_id' => false, // set to post or comment id 'btn_slug' => false, // set to slug string or array of strings, "respect", "recommend", "important". also accepts array 'btn_type' => false // slug of the post type. post, page, comment, or cpt slug ); $args = array_merge($default_args, $args); if($args['btn_slug'] === false) { // return all buttons if they didn't specify which one // USAGE: $enp_btns = new Enp_Button(); // $enp_btns = $enp_btns->get_btns(); $this->get_btns($args); } else { // get the one they asked for // USAGE: $enp_btn = new Enp_Button('respect'); $enp_btn = $this->set_btn($args); } } /* NOT IN USE public function get_btn($args) { $enp_btn_values = get_option('enp_buttons_'.$slug); return $this->set_btn($enp_btn_values); }*/ protected function set_btn($args) { // try/catch to return exception if no button is found try { // get the data from wp_options if($args['btn_slug'] !== false) { $slug = $args['btn_slug']; $enp_btn = get_option('enp_button_'.$slug); } else { $enp_btn = false; throw new Exception('Enp_Button: No btn_slug set.'); } if($enp_btn !== false) { $this->btn_type = $this->set_btn_type($enp_btn, $args); // check to see if the button types return true if($this->btn_type !== false) { $this->btn_slug = $this->set_btn_slug($enp_btn); // set all the attributes $this->btn_name = $this->set_btn_name($enp_btn); $this->btn_count = $this->set_btn_count($enp_btn['btn_slug'], $args); $this->btn_lock = $this->set_btn_lock(); } else { // throw new Exception('Enp_Button: No button found for that btn_type'); } } else { throw new Exception('Enp_Button: No button found'); } } catch(Exception $e) { // return our exception echo $e->getMessage(); } } /* * set the button slug for the Enp_Button object */ protected function set_btn_slug($enp_btn) { $slug = false; if(isset($enp_btn['btn_slug'])) { $slug = $enp_btn['btn_slug']; } return $slug; } /* * * set the button name for the Enp_Button object * */ protected function set_btn_name($enp_btn) { $name = false; if(isset($enp_btn['btn_name'])) { $name = $enp_btn['btn_name']; } return $name; } /* * * set the button type for the current Enp_Button object * as an array of types - ie - ['btn_type'] => array('comment' => false, 'posts' => true) * */ protected function set_btn_type($enp_btn, $args) { $btn_type = false; if(isset($enp_btn['btn_type'])) { $btn_type = $enp_btn['btn_type']; } // check if our args match at all. If there's a match, then we can return the object if($btn_type !== false && $args['btn_type'] !== false) { $btn_type_match = false; // this is a string, so we can check if that btn_type is set to true // because this will check for $btn_type['comment'] = '1', etc if( $btn_typ...
Hi aabella, Very strange! It’s outputting all the code instead of RUNNING the code. I installed WordPress 4.4 and installed the Engaging Buttons plugin with success, so I can’t duplicate the error on my end. I’ll need some more information to troubleshoot this. The default first step when troubleshooting plugins is to deactivate all your plugins, then only activate the Engaging Buttons plugin and see if the error still occurs. If everything works well, then it means that there’s some kind of interference between plugins that’s causing the error, not the plugin itself. I’m happy to try to figure this out via email (or on this board if you’re comfortable posting your URLs publicly). Would you mind posting or emailng me the link(s) to your website? You can email me at jerry [at] engagingnewsproject [dot] org.
Hi aabella, The error has been fixed! You can now download v1.0.5 (stable) or update the plugin via WordPress and it should resolve the errors you were experiencing.