ChiefRed.com Version: 1.0 Author: ChiefRed.com Author URI: https://ChiefRed.com/ */ if ( ! defined( 'ABSPATH' ) ) exit; define( 'CHIEFRED_VERSION', '1.0' ); define( 'CHIEFRED_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'CHIEFRED_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'CHIEFRED_LOCAL_DEBUG', getenv('DEV_LOCAL') ); define( 'CHIEFRED_LOCAL_BASE', 'https://chiefred.dev' ); define('CHIEFRED_LL_OFF', 0); define('CHIEFRED_LL_ERROR', 1); define('CHIEFRED_LL_WARNING', 2); define('CHIEFRED_LL_INFO', 3); define('CHIEFRED_LL_DEBUG', 4); define('CHIEFRED_LOG_LEVEL', CHIEFRED_LL_INFO); if(CHIEFRED_LOG_LEVEL > CHIEFRED_LL_OFF) { define('CHIEFRED_LOG_FILE', fopen(CHIEFRED_PLUGIN_DIR.'/logs/chiefred.log', 'a+')); } define( 'CHIEFRED_MEDIUM_IMG_WIDTH_LIMIT', 400 ); define( 'CHIEFRED_SMALL_IMG_WIDTH_LIMIT', 200 ); register_activation_hook(__FILE__, 'chiefred_plugin_activation'); function chiefred_plugin_activation() { add_option('chiefred_site_id', '', '', 'no'); add_option('chiefred_api_ip', '', '', 'no'); add_option('chiefred_api_port', '', '', 'no'); add_option('chiefred_sync_lock', '0', '', 'no'); add_option('chiefred_article_parent_link', '1', '', 'yes'); add_option('chiefred_article_creators', '1', '', 'yes'); add_option('chiefred_article_childrens', '1', '', 'yes'); add_option('chiefred_article_was_useful', '1', '', 'yes'); add_option('chiefred_illustration_size', 'medium', '', 'yes'); add_option('chiefred_illustration_class', '', '', 'yes'); add_option('chiefred_illustration_link', '1', '', 'yes'); add_option('chiefred_illustration_link_class', 'photo', '', 'yes'); add_option('chiefred_illustration_link_rel', 'lightbox', '', 'yes'); add_option('chiefred_illustration_link_target', '_blank', '', 'yes'); if (! wp_next_scheduled ( 'chiefred_every4hours_synchronize' )) { wp_schedule_event(time(), 'every4hours', 'chiefred_every4hours_synchronize'); } } register_deactivation_hook(__FILE__, 'chiefred_plugin_deactivation'); function chiefred_plugin_deactivation() { wp_clear_scheduled_hook('chiefred_synchronize'); wp_clear_scheduled_hook('chiefred_every4hours_synchronize'); } require_once( CHIEFRED_PLUGIN_DIR . 'class.chiefred.php' ); add_action( 'init', array( 'ChiefRed', 'init' ) ); if ( is_admin() ) { require_once( CHIEFRED_PLUGIN_DIR . 'class.chiefred-admin.php' ); add_action( 'init', array( 'ChiefRed_Admin', 'init' ) ); } function chiefred_log_e($msg=null, $var=null) { if (CHIEFRED_LOG_LEVEL >= CHIEFRED_LL_ERROR) chiefred_logger('ERROR', $msg, $var); } function chiefred_log_w($msg=null, $var=null) { if (CHIEFRED_LOG_LEVEL >= CHIEFRED_LL_WARNING) chiefred_logger('WARNING', $msg, $var); } function chiefred_log_i($msg=null, $var=null) { if (CHIEFRED_LOG_LEVEL >= CHIEFRED_LL_INFO) chiefred_logger('INFO', $msg, $var); } function chiefred_log_d($msg=null, $var=null) { if (CHIEFRED_LOG_LEVEL >= CHIEFRED_LL_DEBUG) chiefred_logger('DEBUG', $msg, $var); } function chiefred_logger($level='debug', $msg=null, $var=null) { if (CHIEFRED_LOG_FILE && $msg) { if ($var !== null) $msg .= ': '.var_export($var, true); $level = str_pad("[{$level}]", 9, ' '); fwrite(CHIEFRED_LOG_FILE, date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) )." {$level} {$msg}\n"); } }