function enp_btns_HTML($args) { // get the user $enp_user = new Enp_Button_User(); $enp_btn_HTML = ''; // get the button objects $enp_btns = enp_get_all_btns($args); if (empty($enp_btns)) { return false; // quit now if there aren't any buttons } // classes array for outputting in our HTML $classes = array("enp-btns"); if ($args['btn_type'] === 'comment') { $btn_type = 'comment'; } else { $btn_type = 'post'; } $classes[] = 'enp-btns-' . $btn_type . '-' . $args['post_id']; // check if logged in is set $enp_btn_clickable = enp_btn_clickable(); // check if the first one is full of null values if (enp_button_exists($enp_btns[0])) { // check on icon status $enp_btn_icons = get_option('enp_button_icons'); if ($enp_btn_icons === '0') { $enp_btn_icon_class = 'no-enp-icon-state'; $display_enp_btn_icons = false; } else { $enp_btn_icon_class = 'enp-icon-state'; $display_enp_btn_icons = true; } $enp_btn_HTML = '<div id="enp-btns-wrap-' . $btn_type . '-' . $args['post_id'] . '" class="enp-btns-wrap--disabled enp-btns-wrap ' . $enp_btn_icon_class . '" data-btn-type="' . $btn_type . '"> <ul class="'; foreach ($classes as $class) { $enp_btn_HTML .= $class . ' '; } $enp_btn_HTML .= '">'; foreach ($enp_btns as $enp_btn) { if (enp_button_exists($enp_btn)) { $enp_btn_HTML .= enp_btn_append_btn_HTML($enp_btn, $args, $enp_btn_clickable, $enp_user, $display_enp_btn_icons); } // process button names to pass to the Promote option later $enp_btn_names[] = $enp_btn->get_btn_name(); } $enp_btn_HTML .= '</ul>'; $enp_btn_HTML .= enp_user_clicked_buttons_HTML($enp_user, $enp_btns, $btn_type, $args['post_id']); if ($enp_btn_clickable === false) { // append a login link and message // redirect them back to this button section if ($btn_type === 'post') { $redirect = get_permalink() . '/#enp-btns-wrap-' . $btn_type . '-' . $args['post_id']; } elseif ($btn_type === 'comment') { $redirect = get_comment_link($args['post_id']); } else { // hmmm... which type are they on? $redirect = site_url(); } $enp_btn_HTML .= '<p class="enp-btn-hint enp-hint--please-log-in">Please <a href="' . wp_login_url($redirect) . '">Log In</a> to click the buttons</p>'; } if ($btn_type === 'post' && !empty($enp_btn_names)) { $return = true; $enp_btn_HTML .= promote_enp_HTML($enp_btn_names, $return); // true returns instead of echos } // no script reference $enp_btn_HTML .= '<noscript><p class="enp-btn-hint">Enable Javascript to click a button</p></noscript>'; $enp_btn_HTML .= '</div>'; // close enp-btns-wrap } return $enp_btn_HTML; }
public function enp_btn_register_scripts() { $version = '1.0.4'; // 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)); }