is_amp()) { echo "
"; } } /** * Enqueue assets */ public function add_assets() { // Include scripts on front end if (!is_admin() && !$this->is_amp()) { $js = $this->get_asset_vars('assets/js/onyx-poll.min.js'); wp_enqueue_script('acf-onyx-poll', $js->url, array(), $js->ver, false, true); if (!get_field('onyx_poll_css', 'options')) { $css = $this->get_asset_vars('assets/css/onyx-poll.min.css'); wp_enqueue_style('acf-onyx-poll', $css->url, array(), $css->ver); } wp_localize_script('acf-onyx-poll', 'onyxpoll', array( 'apiurl' => rest_url(), 'modaltime' => get_field('onyx_poll_modal_time', 'options'), 'labels' => array( 'vote' => __('Vote', 'acf-onyx-poll'), 'votes' => __('votes', 'acf-onyx-poll'), 'view' => __('Views result', 'acf-onyx-poll'), 'total' => __('Total votes', 'acf-onyx-poll'), 'success' => __('Vote was submitted successfully.', 'acf-onyx-poll'), 'error' => __('Poll vote error, try again.', 'acf-onyx-poll') ) ) ); } } /** * Some admin styles for better view */ public function admin_styles() { global $post_type; if ('onyxpolls' == $post_type) { $css = $this->get_asset_vars('assets/css/admin.min.css'); wp_enqueue_style('acf-onyx-poll-admin', $css->url, array(), $css->ver); } } /** * Get asset variables for enqueue * @param string $path required */ public function get_asset_vars($path = null) { if ($path) { $a = new stdClass(); $a->path = $path; $a->url = plugins_url($path, __FILE__); $a->ver = filemtime(plugin_dir_path(__FILE__) . $path); return $a; } return false; } /** * Extract shortcode * Just a simple shortcode method */ public function shortcode($atts) { extract(shortcode_atts(array( 'id' => '', 'class' => 'left', 'style' => '' ), $atts)); $poll = OnyxPolls::has_poll($id); if ($poll) { $html = ""; } else { $html = ""; } return $html; } /** * initialize * * Sets up the Onyx Poll plugin. * * @param void * @return void */ public function initialize() { // Change ACF Local JSON save location to /acf folder inside this plugin // add_filter('acf/settings/save_json', function() { // return __DIR__ . '/acf'; // }); // Include the /acf folder in the places to look for ACF Local JSON files // add_filter('acf/settings/load_json', function($paths) { // $paths[] = __DIR__ . '/acf'; // return $paths; // }); // Load text domain language load_plugin_textdomain( 'acf-onyx-poll', false, dirname(plugin_basename(__FILE__)) . '/languages' ); // Verify if Advanced Custom Fields PRO is activated add_action('admin_init', function() { if (is_admin() && current_user_can('activate_plugins') && !is_plugin_active('advanced-custom-fields-pro/acf.php')) { add_action('admin_notices', function() { $notice = __('Sorry, but ACF Onyx Poll requires that ACF PRO is installed and active.', 'acf-onyx-poll'); echo "$notice