/** * Get the API object * * @param array $keys API keys * * @return bool|WordPress */ function socialink_wordpress_get_api_object($keys) { $result = false; if (!empty($keys) && is_array($keys)) { $url = $keys["url"]; $consumer_key = $keys["consumer_key"]; $consumer_secret = $keys["consumer_secret"]; if (isset($keys["oauth_token"]) && isset($keys["oauth_secret"])) { $oauth_token = $keys["oauth_token"]; $oauth_secret = $keys["oauth_secret"]; } else { $oauth_token = null; $oauth_secret = null; } $result = new WordPress($url, $consumer_key, $consumer_secret, $oauth_token, $oauth_secret); if ($proxy_settings = socialink_get_proxy_settings()) { $result->setProxySettings($proxy_settings); } } return $result; }
public static function init(WordPress\App $app) { // Find the Composer ClassLoader instance foreach (spl_autoload_functions() as $callable) { if (is_array($callable)) { if ($callable[0] instanceof Composer\Autoload\ClassLoader) { $app->setShared('autoloader', $callable[0]); break; } } } $app->setShared('app', $app); self::$app = $app; }
public function testImport() { $migrate = new WordPress(); $migrate->setPasswordKey(new EncryptionKey(\str_repeat("", 32))); list($newHash, $data) = $migrate->getHashWithMetadata('$P$BhLUOfHf5srnKHKWEu19tJSmGKTbgX.'); $this->assertTrue($migrate->validate(new HiddenString('apple'), $newHash, $data)); $this->assertFalse($migrate->validate(new HiddenString('hunter2'), $newHash, $data)); $this->assertFalse($migrate->validate(new HiddenString(''), $newHash, $data)); }
/** * Attempts to locate the storage container via the \WordPress class. * * @return \WordPress\Data\StorageInterface|null */ protected function locateStorage() { if (class_exists('WordPress', false)) { if ($dataManager = \WordPress::get('dataManager')) { if ($type = $dataManager->getModelType($this)) { return $type->getStorage(); } } } }
require __DIR__ . '/src/WordPress.php'; composer_autoloader()->addPsr4('WordPress\\', array(__DIR__ . '/src')); /** * @var \WordPress\Application\Environment $env */ $env = new Application\Environment(dirname(ABSPATH), dirname(dirname(ABSPATH))); /** * Get the app class name */ $class = apply_filters('application_class', 'WordPress\\App'); /** * Application instance. * * @var WordPress\App $app */ \WordPress::init($app = new $class($env)); $app->set('autoloader', function (App $app) { return $app->getGlobal('autoloader'); }); $app->setShared('env', $env); $app->setShared('request', Http\Request::createFromGlobals()); $app->setShared('restManager', new Rest\Manager()); $app->setShared('modelManager', new Model\Manager()); $app->setShared('dataManager', new Data\Manager()); $app->set('post', function () { return Model\Post::instance(); }); $app->set('user', function () { return Model\User::instance(); }); $app->setShared('dbConnection', function (App $app) {
/** * Escapes and wraps a $variable (string|array of strings) * @param array|string $var variable which will be wrapped in double-quotes and escaped * @return array|string */ public static function escapeVar($var) { if (is_array($var)) { foreach ($var as $varKey => $varField) { // recursive escaping $var[$varKey] = self::escapeVar($varField); } } elseif (is_string($var)) { $db = WordPress::getDb(); $var = '"' . $db->_escape($var) . '"'; } else { // what else ?? } return $var; }
/** * Returns a registered data repository. * * @return \WordPress\Data\RepositoryInterface */ function get_repository($name) { return WordPress::get('dataManager')->getRepository($name); }
protected function runScript($path, array $globals = []) { // add script specified global variables $globals = array_merge($globals, WordPress::globals($path) ?: []); foreach ($globals as $global) { global ${$global}; } if (env('APP_ENV') == 'testing1') { ob_start(); // We'll evaluate the contents of the view inside a try/catch block so we can // flush out any stray output that might get out before an error occurs or // an exception is thrown. This prevents any partial views from leaking. try { require wordpress_path($path); } catch (Exception $e) { ob_end_clean(); } return ltrim(ob_get_clean()); } else { require wordpress_path($path); } }
protected function runScript($path, array $globals = []) { // add script specified global variables $globals = array_merge($globals, WordPress::globals($path) ?: []); foreach ($globals as $global) { global ${$global}; } require wordpress_path($path); }