本文整理汇总了PHP中Plugin::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Plugin::instance方法的具体用法?PHP Plugin::instance怎么用?PHP Plugin::instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Plugin
的用法示例。
在下文中一共展示了Plugin::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_control
public function add_control($id, $args)
{
if (null !== $this->_current_tab) {
$args = array_merge($args, $this->_current_tab);
}
return Plugin::instance()->controls_manager->add_control_to_stack($this, $id, $args);
}
示例2: init
public static function init()
{
// Hotfix for NextGEN Gallery plugin
if (defined('NGG_PLUGIN_VERSION')) {
add_filter('elementor/utils/get_edit_link', function ($edit_link) {
return add_query_arg('display_gallery_iframe', '', $edit_link);
});
}
// Hack for Ninja Forms
if (class_exists('\\Ninja_Forms')) {
add_action('elementor/preview/enqueue_styles', function () {
ob_start();
\NF_Display_Render::localize(0);
ob_clean();
wp_add_inline_script('nf-front-end', 'var nfForms = nfForms || [];');
});
}
// Exclude our Library from sitemap.xml in Yoast SEO plugin
add_filter('wpseo_sitemaps_supported_post_types', function ($post_types) {
unset($post_types[TemplateLibrary\Source_Local::CPT]);
return $post_types;
});
// Disable optimize files in Editor from Autoptimize plugin
add_filter('autoptimize_filter_noptimize', function ($retval) {
if (Plugin::instance()->editor->is_edit_mode()) {
$retval = true;
}
return $retval;
});
}
示例3: pre_set_site_transient
/**
* Add language translations to update_plugins or update_themes transients.
*
* @param $transient
*
* @return mixed
*/
public function pre_set_site_transient($transient)
{
$locales = get_available_languages();
$locales = !empty($locales) ? $locales : array(get_locale());
$repos = array();
if (!isset($transient->translations)) {
return $transient;
}
if ('pre_set_site_transient_update_plugins' === current_filter()) {
$repos = Plugin::instance()->get_plugin_configs();
$translations = wp_get_installed_translations('plugins');
}
if ('pre_set_site_transient_update_themes' === current_filter()) {
$repos = Theme::instance()->get_theme_configs();
$translations = wp_get_installed_translations('themes');
}
$repos = array_filter($repos, function ($e) {
return isset($e->language_packs);
});
foreach ($repos as $repo) {
foreach ($locales as $locale) {
$lang_pack_mod = isset($repo->language_packs->{$locale}) ? strtotime($repo->language_packs->{$locale}->updated) : 0;
$translation_mod = isset($translations[$repo->repo][$locale]) ? strtotime($translations[$repo->repo][$locale]['PO-Revision-Date']) : 0;
if ($lang_pack_mod > $translation_mod) {
$transient->translations[] = (array) $repo->language_packs->{$locale};
}
}
}
$transient->translations = array_unique($transient->translations, SORT_REGULAR);
return $transient;
}
示例4: init
/**
* Initializing plugins
*
* @return Plugin
*/
public static function init()
{
if (!isset(self::$instance)) {
self::$instance = new Plugin();
}
return self::$instance;
}
示例5: __construct
/**
* CONSTRUCTOR - Initialize
*/
public function __construct($start = '')
{
// Managed directives
ini_set('default_charset', $charset = 'UTF-8');
ini_set('display_errors', 1);
// Abort on startup error
// Intercept errors/exceptions; PHP5.3-compatible
error_reporting(E_ALL | E_STRICT);
if (!ini_get('date.timezone')) {
date_default_timezone_set('GMT');
}
// define shorthand paths
if (!defined('BASE')) {
$base = dirname(__FILE__) . '/';
define("BASE", $base);
define("CACHE", $base . 'cache/');
define("ADMIN", $base . 'admin/');
define("INSTALL", $base . 'install/');
define("LIBS", $base . 'libs/');
define("EXTENSIONS", $base . 'libs/extensions/');
define("FRAMEWORKS", $base . 'libs/frameworks/');
define("FUNCTIONS", $base . 'functions/');
define("CONTENT", $base . 'content/');
define("THEMES", $base . 'content/themes/');
define("PLUGINS", $base . 'content/plugins/');
define("ADMIN_THEMES", $base . 'content/admin_themes/');
define("SITEURL", BASEURL);
}
if (!$start) {
// initialize
parent::__construct();
$this->currentUser = UserBase::instance();
// the current user
$this->displayUser = DisplayUser::instance();
$this->plugin = Plugin::instance();
// instantiate Plugin object
$this->post = Post::instance();
// instantiate Post object
$this->comment = Comment::instance();
$this->includes = IncludeCssJs::instance();
// instantiate Includes object
$this->pageHandling = PageHandling::instance();
// instantiate PageHandling object
$this->debug = Debug::instance();
// instantiate Debug object
$this->csrf('set');
// set a csrfToken
$this->db->setHotaru($this);
// pass $h object to EzSQL for error reporting
//$this->mdb->setHotaru($this); // pass $h object to meekroDb for error reporting
//print 'time: ' . timer_stop(4,'hotaru');
//roughly here at 0.0040 Nov 2, 2014 tests
// time: 0.0047 Nov11, 2014 after moving a few more functions to init
}
}
示例6: on_import
/**
* Fetch images and replace to new
*
* @param $settings
*
* @return array|bool
*/
public function on_import($settings)
{
if (empty($settings['url'])) {
return $settings;
}
$settings = Plugin::instance()->templates_manager->get_import_images_instance()->import($settings);
if (!$settings) {
$settings = ['id' => '', 'url' => Utils::get_placeholder_image_src()];
}
return $settings;
}
示例7: on_import
public function on_import($settings)
{
foreach ($settings as &$attachment) {
if (empty($attachment['url'])) {
continue;
}
$attachment = Plugin::instance()->templates_manager->get_import_images_instance()->import($attachment);
}
// Filter out attachments that doesn't exist
$settings = array_filter($settings);
return $settings;
}
示例8: heartbeat_received
/**
* Handle the post lock in the editor.
*
* @since 1.0.0
*
* @param array $response
* @param array $data
*
* @return array
*/
public function heartbeat_received($response, $data)
{
if (isset($data['elementor_post_lock']['post_ID'])) {
$post_id = $data['elementor_post_lock']['post_ID'];
$locked_user = Plugin::instance()->editor->get_locked_user($post_id);
if (!$locked_user || !empty($data['elementor_force_post_lock'])) {
Plugin::instance()->editor->lock_post($post_id);
} else {
$response['locked_user'] = $locked_user->display_name;
}
$response['elementor_nonce'] = wp_create_nonce('elementor-editing');
}
return $response;
}
示例9: get_value
public function get_value($control, $instance)
{
$value = parent::get_value($control, $instance);
if (!empty($value)) {
foreach ($value as &$item) {
foreach ($control['fields'] as $field) {
$control_obj = Plugin::instance()->controls_manager->get_control($field['type']);
if (!$control_obj) {
continue;
}
$item[$field['name']] = $control_obj->get_value($field, $item);
}
}
}
return $value;
}
示例10: wp_update_response
/**
* Shiny updates results in the update transient being reset with only the wp.org data.
* This catches the response and reloads the transients.
*
* @param mixed $response HTTP server response.
* @param array $args HTTP response arguments.
* @param string $url URL of HTTP response.
*
* @return mixed $response Just a pass through, no manipulation.
*/
public static function wp_update_response($response, $args, $url)
{
$parsed_url = parse_url($url);
if ('api.wordpress.org' === $parsed_url['host']) {
if (current_user_can('update_plugins') && isset($args['body']['plugins'])) {
$current = get_site_transient('update_plugins');
Plugin::instance()->forced_meta_update_plugins(true);
$current = Plugin::instance()->pre_set_site_transient_update_plugins($current);
set_site_transient('update_plugins', $current);
}
if (current_user_can('update_themes') && isset($args['body']['themes'])) {
$current = get_site_transient('update_themes');
Theme::instance()->forced_meta_update_themes(true);
$current = Theme::instance()->pre_set_site_transient_update_themes($current);
set_site_transient('update_themes', $current);
}
}
return $response;
}
示例11: _get_info_data
/**
* This function notifies the user of upgrade notices, new templates and contributors
*
* @param bool $force
*
* @return array|bool
*/
private static function _get_info_data($force = false)
{
$cache_key = 'elementor_remote_info_api_data_' . Plugin::instance()->get_version();
$info_data = get_transient($cache_key);
if ($force || false === $info_data) {
$response = wp_remote_post(self::$api_info_url, ['timeout' => 25, 'body' => ['api_version' => ELEMENTOR_VERSION, 'site_lang' => get_bloginfo('language')]]);
if (is_wp_error($response) || 200 !== (int) wp_remote_retrieve_response_code($response)) {
set_transient($cache_key, [], 2 * HOUR_IN_SECONDS);
return false;
}
$info_data = json_decode(wp_remote_retrieve_body($response), true);
if (empty($info_data) || !is_array($info_data)) {
set_transient($cache_key, [], 2 * HOUR_IN_SECONDS);
return false;
}
if (isset($info_data['templates'])) {
update_option('elementor_remote_info_templates_data', $info_data['templates'], 'no');
unset($info_data['templates']);
}
set_transient($cache_key, $info_data, 12 * HOUR_IN_SECONDS);
}
return $info_data;
}
示例12: get_element_stack
public function get_element_stack(Element_Base $element)
{
$stack_id = $element->get_name();
if (!isset($this->_controls_stack[$stack_id])) {
return null;
}
$stack = $this->_controls_stack[$stack_id];
if ('widget' === $element->get_type() && 'common' !== $element->get_name()) {
$common_widget = Plugin::instance()->widgets_manager->get_widget_types('common');
$stack['controls'] = array_merge($stack['controls'], $common_widget->get_controls());
$stack['tabs'] = array_merge($stack['tabs'], $common_widget->get_tabs_controls());
}
return $stack;
}
示例13: ghu_tokens
/**
* Create and return settings fields for private repositories.
*
* @return void
*/
public function ghu_tokens()
{
$ghu_options_keys = array();
$ghu_plugins = Plugin::instance()->get_plugin_configs();
$ghu_themes = Theme::instance()->get_theme_configs();
$ghu_tokens = array_merge($ghu_plugins, $ghu_themes);
foreach ($ghu_tokens as $token) {
$type = '<span class="dashicons dashicons-admin-plugins"></span> ';
$setting_field = array();
$ghu_options_keys[$token->repo] = null;
$token->private = isset($token->private) ? $token->private : true;
/*
* Set boolean for Enterprise headers.
*/
if ($token->enterprise) {
/*
* Set boolean if GitHub Enterprise header found.
*/
if (false !== strpos($token->type, 'github') && !parent::$auth_required['github_enterprise']) {
parent::$auth_required['github_enterprise'] = true;
}
/*
* Set boolean if GitLab CE/Enterprise header found.
*/
if (false !== strpos($token->type, 'gitlab') && !empty($token->enterprise) && !parent::$auth_required['gitlab_enterprise']) {
parent::$auth_required['gitlab_enterprise'] = true;
}
}
/*
* Check to see if it's a private repo and set variables.
*/
if ($token->private) {
if (false !== strpos($token->type, 'github') && !parent::$auth_required['github_private']) {
parent::$auth_required['github_private'] = true;
}
if (false !== strpos($token->type, 'bitbucket') && !parent::$auth_required['bitbucket_private']) {
parent::$auth_required['bitbucket_private'] = true;
}
}
/*
* Set boolean if GitLab header found.
*/
if (false !== strpos($token->type, 'gitlab') && empty($token->enterprise) && !parent::$auth_required['gitlab']) {
parent::$auth_required['gitlab'] = true;
}
/*
* Next if not a private repo or token field not empty.
*/
if (!$token->private && empty(parent::$options[$token->repo])) {
continue;
}
if (false !== strpos($token->type, 'theme')) {
$type = '<span class="dashicons dashicons-admin-appearance"></span> ';
}
$setting_field['id'] = $token->repo;
$setting_field['title'] = $type . $token->name;
$setting_field['page'] = 'github_updater_install_settings';
switch ($token->type) {
case strpos($token->type, 'github'):
$setting_field['section'] = 'github_id';
$setting_field['callback_method'] = array(&$this, 'token_callback_text');
$setting_field['callback'] = $token->repo;
break;
case strpos($token->type, 'bitbucket'):
$setting_field['section'] = 'bitbucket_id';
$setting_field['callback_method'] = array(&$this, 'token_callback_checkbox');
$setting_field['callback'] = $token->repo;
break;
case strpos($token->type, 'gitlab'):
$setting_field['section'] = 'gitlab_id';
$setting_field['callback_method'] = array(&$this, 'token_callback_checkbox');
$setting_field['callback'] = $token->repo;
break;
}
add_settings_field($setting_field['id'], $setting_field['title'], $setting_field['callback_method'], $setting_field['page'], $setting_field['section'], array('id' => $setting_field['callback']));
}
/*
* Unset options that are no longer present and update options.
*/
$ghu_unset_keys = array_diff_key(parent::$options, $ghu_options_keys);
unset($ghu_unset_keys['github_access_token']);
if (parent::$auth_required['github_enterprise']) {
unset($ghu_unset_keys['github_enterprise_token']);
}
unset($ghu_unset_keys['branch_switch']);
unset($ghu_unset_keys['bitbucket_username']);
unset($ghu_unset_keys['bitbucket_password']);
if (parent::$auth_required['gitlab']) {
unset($ghu_unset_keys['gitlab_private_token']);
}
if (parent::$auth_required['gitlab_enterprise']) {
unset($ghu_unset_keys['gitlab_enterprise_token']);
}
if (!empty($ghu_unset_keys)) {
foreach ($ghu_unset_keys as $key => $value) {
//.........这里部分代码省略.........
示例14: _get_child_type
protected function _get_child_type(array $element_data)
{
if ('section' === $element_data['elType']) {
return Plugin::instance()->elements_manager->get_element_types('section');
}
return Plugin::instance()->widgets_manager->get_widget_types($element_data['widgetType']);
}
示例15: show_updates
/**
* Return listing of available updates.
*
* @param $response
*
* @return mixed
*/
public function show_updates($response)
{
$themes = get_site_transient('update_themes');
$plugins = get_site_transient('update_plugins');
$show_plugins = null;
$show_themes = null;
/*
* Ensure update data is up to date.
*/
$this->forced_meta_update_remote_management();
$themes = Theme::instance()->pre_set_site_transient_update_themes($themes);
$plugins = Plugin::instance()->pre_set_site_transient_update_plugins($plugins);
foreach ($plugins->response as $plugin) {
$plugin->plugin = $plugin->slug;
unset($plugin->slug);
unset($plugin->url);
unset($plugin->package);
if (isset($plugin->id, $plugin->tested, $plugin->compatibility)) {
unset($plugin->id);
unset($plugin->tested);
unset($plugin->compatibility);
}
$show_plugins[] = $plugin;
}
foreach ($themes->response as $theme) {
unset($theme['url']);
unset($theme['package']);
$show_themes[] = $theme;
}
$response['messages'] = esc_html__('Available Updates', 'github-updater');
$response['plugins'] = $show_plugins;
$response['themes'] = $show_themes;
return $response;
}