php CS类(方法)实例源码

下面列出了php CS 类(方法)源码代码实例,从而了解它的用法。

作者:datrack    项目:datalook.i   
public function addMediaButton($editor_id)
 {
     $this->enqueue();
     $title = sprintf(__('Insert Shortcodes', csl18n()));
     $contents = (include CS()->path('includes/builder/svg/nav-elements-solid.php'));
     echo "<button href=\"#\" title=\"{$title}\" id=\"cs-insert-shortcode-button\" class=\"button cs-insert-btn\">{$contents}</button>";
 }

作者:saparhad    项目:morowaliwe   
public static function preInit()
 {
     global $wp_version;
     if (version_compare($wp_version, '4.1', '<')) {
         require_once CS()->path('includes/utility/wp-json.php');
     }
 }

作者:bitflipper    项目:ghcontractin   
public function ajax_handler($data)
 {
     CS_Shortcode_Preserver::init();
     if ($this->sandbox_the_content) {
         CS_Shortcode_Preserver::sandbox('cs_render_the_content');
     }
     add_filter('cs_preserve_shortcodes_no_wrap', '__return_true');
     $this->orchestrator = $this->plugin->component('Element_Orchestrator');
     $this->orchestrator->load_elements();
     $this->mk1 = new Cornerstone_Legacy_Renderer($this->plugin->component('Legacy_Elements'));
     global $post;
     if (!isset($data['post_id']) || !($post = get_post((int) $data['post_id']))) {
         wp_send_json_error(array('message' => 'post_id not set'));
     }
     setup_postdata($post);
     $this->enqueue_extractor = $this->plugin->loadComponent('Enqueue_Extractor');
     $this->enqueue_extractor->start();
     if (isset($data['raw_markup'])) {
         $this->raw_markup = (bool) $data['raw_markup'];
     }
     if (!isset($data['batch'])) {
         wp_send_json_error(array('message' => 'No element data recieved'));
     }
     $jobs = $this->batch($data['batch']);
     $scripts = $this->enqueue_extractor->get_scripts();
     if (is_wp_error($jobs)) {
         wp_send_json_error(array('message' => $jobs->get_error_message()));
     }
     $result = array('jobs' => $jobs, 'scripts' => $scripts);
     //Suppress PHP error output unless debugging
     if (CS()->common()->isDebug()) {
         return wp_send_json_success($result);
     }
     return @wp_send_json_success($result);
 }

作者:saparhad    项目:morowaliwe   
/**
  * Load generated CSS output and place style tag in wp_head
  */
 public function inlineStyles()
 {
     ob_start();
     echo '<style id="cornerstone-generated-preview-css" type="text/css">';
     $settings = CS()->settings();
     $options = CS()->customizer()->optionData();
     extract($settings);
     extract($options);
     include CS()->path() . 'includes/builder/styles.php';
     do_action('cornerstone_generated_preview_css');
     echo '</style>';
     $css = ob_get_contents();
     ob_end_clean();
     //
     // 1. Remove comments.
     // 2. Remove whitespace.
     // 3. Remove starting whitespace.
     //
     $output = preg_replace('#/\\*.*?\\*/#s', '', $css);
     // 1
     $output = preg_replace('/\\s*([{}|:;,])\\s+/', '$1', $output);
     // 2
     $output = preg_replace('/\\s\\s+(.*)/', '$1', $output);
     // 3
     echo $output;
 }

作者:nayabbukhar    项目:circulocristian   
public function __construct()
 {
     /* Get all saved data and put them in self::$settings for later use */
     self::$settings = CS()->settings();
     /* Handles post data */
     if (isset($_POST['cornerstone_options_submitted']) && isset($_POST['cornerstone-fields'])) {
         if (strip_tags($_POST['cornerstone_options_submitted']) == 'submitted' && current_user_can('manage_options')) {
             $fields = $_POST['cornerstone-fields'];
             // Empty checkboxes
             if (isset($_POST['cornerstone-checkboxes'])) {
                 foreach ($_POST['cornerstone-checkboxes'] as $name) {
                     if (!in_array($name, $fields)) {
                         self::$settings[$name] = array();
                     }
                 }
             }
             // Convert checkbox to boolean
             if (isset($_POST['cornerstone-checkbox'])) {
                 foreach ($_POST['cornerstone-checkbox'] as $name) {
                     self::$settings[$name] = in_array($name, $fields);
                 }
             }
             foreach ($fields as $name => $value) {
                 // remove html tags
                 self::$settings[$name] = is_array($value) ? array_map('strip_tags', $value) : strip_tags($value);
             }
             update_option('cornerstone_settings', self::$settings);
         }
     }
 }

作者:bitflipper    项目:ghcontractin   
public function addMediaButton($editor_id)
 {
     $this->enqueue();
     $title = sprintf(__('Insert Shortcodes', csl18n()));
     $contents = CS()->view('svg/nav-elements-solid', false);
     echo "<button href=\"#\" title=\"{$title}\" id=\"cs-insert-shortcode-button\" class=\"button cs-insert-btn\">{$contents}</button>";
 }

作者:elinber    项目:ericlinber   
public function controls()
 {
     global $post;
     $url = add_query_arg(array('url' => CS()->common()->getEditURL(get_the_id())), admin_url('customize.php'));
     $link = '<a href="' . $url . '">' . __('Customizer', csl18n()) . '</a>';
     $html = '<ul class="cs-controls"><li class="cs-control cs-control-info-box"><h4>' . __('Looking for global styling?', csl18n()) . '</h4><p>' . sprintf(__('Sitewide styles outside of the content area are managed via the %s.', csl18n()), $link) . '</p></li></ul>';
     return array('customizer_message' => array('type' => 'custom-markup', 'ui' => array(), 'options' => array('html' => $html)));
 }

作者:GolgoSof    项目:KeenerW   
/**
  * Get an array of post types allowed for Cornerstone.
  * This is based on both user role, and enabled post types
  * @return array
  */
 public function getAllowedPostTypes()
 {
     $settings = CS()->settings();
     $user = wp_get_current_user();
     if (!empty($user) && (user_can($user, 'manage_options') || count(array_intersect($settings['permitted_roles'], (array) $user->roles)) > 0)) {
         return apply_filters('cornerstone_allowed_post_types', $settings['allowed_post_types']);
     }
     return array();
 }

作者:aguidett    项目:Enduri   
public static function preInit()
 {
     // Disable NextGEN Resource Manager
     add_filter('run_ngg_resource_manager', '__return_false');
     global $wp_version;
     if (version_compare($wp_version, '4.1', '<')) {
         require_once CS()->path('includes/utility/wp-json.php');
     }
 }

作者:nayabbukhar    项目:circulocristian   
public function setup()
 {
     // Disable revision through filter
     if (apply_filters('cornerstone_disable_revisions', false) || !CS()->common()->uses_cornerstone()) {
         return;
     }
     // Save cornerstone revision
     add_action('save_post', array($this, 'saveRevision'), 10, 2);
     // Restore cornerstone revision
     add_action('wp_restore_post_revision', array($this, 'restoreRevision'), 10, 2);
 }

作者:nayabbukhar    项目:circulocristian   
public function handler($data)
 {
     global $post;
     $settings = get_post_meta($post->ID, '_cornerstone_settings', true);
     $settings['responsive_text'] = isset($data['elements']) ? $data['elements'] : array();
     update_post_meta($post->ID, '_cornerstone_settings', $settings);
     $save_handler = CS()->component('Save_Handler');
     foreach ($settings['responsive_text'] as $element) {
         $save_handler->append_element($element);
     }
 }

作者:elinber    项目:ericlinber   
/**
  * Instantiate
  */
 public function setup()
 {
     $this->fontIcons = $this->plugin->config('common/font-icons');
     add_action('init', array($this, 'init'));
     $version = CS()->version();
     if (false !== strpos($version, '-alpha')) {
         $this->plugin->loadComponent('Alpha');
     }
     if (false !== strpos($version, '-')) {
         $this->plugin->loadComponent('Prerelease');
     }
 }

作者:nayabbukhar    项目:circulocristian   
public function __construct($data, $parent = null)
 {
     $this->parent = $parent;
     $this->data = $data;
     $type = isset($this->data['_type']) ? $this->data['_type'] : 'undefined';
     $this->definition = CS()->component('Element_Orchestrator')->get($type);
     if (isset($data['elements'])) {
         unset($this->data['elements']);
         foreach ($data['elements'] as $element) {
             $this->elements[] = new self($element, $this);
         }
     }
 }

作者:GolgoSof    项目:KeenerW   
public function ajaxResponseDelete()
 {
     if (!isset($_POST['slug'])) {
         return wp_send_json_error('Invalid request.');
     }
     $query = new WP_Query(array('post_type' => 'cs_user_templates', 'meta_key' => 'cs_template_slug', 'meta_value' => $_POST['slug']));
     if ($query->post && wp_delete_post($query->post->ID, true)) {
         if (CS()->common()->isDebug()) {
             return wp_send_json_success();
         }
         return @wp_send_json_success();
     }
     return wp_send_json_error('Unable to delete template.');
 }

作者:ju4nr3v0    项目:juandavidmarulanda.co   
function x_pairing_notice()
{
    if (x_plugin_cornerstone_exists() && class_exists('CS')) {
        if (!defined('X_CURRENT') || version_compare(CS()->version(), X_CORNERSTONE_CURRENT, '<')) {
            ?>

      <div class="updated x-notice warning">
        <p><strong>IMPORTANT: Please update Cornerstone</strong>. You are using a newer version of X that may not be compatible. After updating, please ensure that you have cleared out your browser cache and any caching plugins you may be using. This message will self destruct upon updating Cornerstone.</p>
      </div>

    <?php 
        }
    }
}

作者:datrack    项目:datalook.i   
public function loadNativePages()
 {
     $path = CS()->path() . 'includes/modules/layout_templates/';
     foreach (glob("{$path}page-*.php") as $filename) {
         if (!file_exists($filename)) {
             continue;
         }
         $data = (include $filename);
         $data['type'] = 'page';
         $data['slug'] = 'themeco-' . trim(str_replace('.php', '', basename($filename)));
         $data['section'] = 'themeco-pages';
         $this->registry[] = $data;
     }
 }

作者:datrack    项目:datalook.i   
/**
  * Load all element classes from the elements folder.
  * Elements are loaded by a convention of lowercase filenames and capitalized class names.
  * Once the classes are loaded, each one is added to the manager library
  * @return none
  */
 public function loadNativeElements()
 {
     $this->elements = array();
     $path = CS()->path() . 'includes/modules/elements/';
     foreach (glob("{$path}*.php") as $filename) {
         if (!file_exists($filename)) {
             continue;
         }
         require_once $filename;
         $words = explode('-', str_replace('.php', '', basename($filename)));
         foreach ($words as $key => $value) {
             $words[$key] = ucfirst($value);
         }
         $class_name = $this->class_prefix . implode('_', $words);
         $this->add($class_name);
     }
 }

作者:nayabbukhar    项目:circulocristian   
public static final function mixinFactory($name, $config = array())
 {
     $mixins = CS()->config('controls/mixins');
     $type = $config['mixin'];
     unset($config['mixin']);
     if (!isset($mixins[$type])) {
         return new WP_Error('cornerstone', "Mixin '{$type}' not found.");
     }
     // Set a maximium merge depth. This allows top level keys to be merged,
     // but allows full arrays to be overriden at the control option level.
     $depth = 3;
     // For groups, we need an additional level of merge depth
     if (isset($config['group']) && $config['group'] === true || isset($mixins[$type]['group']) && $mixins[$type]['group'] === true) {
         $depth = 4;
     }
     return self::factory($name, cs_deep_array_merge($config, $mixins[$type], $depth));
 }

作者:GolgoSof    项目:KeenerW   
/**
  * Register integrations included with Cornerstone
  * @return none
  */
 public function registerNativeIntegrations()
 {
     $this->registry = array();
     $this->themes = array();
     $path = CS()->path() . 'includes/modules/integrations/';
     foreach (glob("{$path}*.php") as $filename) {
         if (!file_exists($filename)) {
             continue;
         }
         require_once $filename;
         $handle = str_replace('.php', '', basename($filename));
         $words = explode('-', $handle);
         foreach ($words as $key => $value) {
             $words[$key] = ucfirst($value);
         }
         $this->registry[$handle] = 'Cornerstone_Integration_' . implode('_', $words);
     }
 }

作者:datrack    项目:datalook.i   
/**
  * Register Customizer Sections, Settings, and Controls.
  */
 public function register($wp_customize)
 {
     $cs = array();
     include CS()->path('includes/customizer/register.php');
     //
     // Output - Sections.
     //
     foreach ($cs['sec'] as $section) {
         $wp_customize->add_section($section[0], array('title' => $section[1], 'priority' => $section[2]));
     }
     //
     // Output - Settings.
     //
     foreach ($cs['set'] as $setting) {
         $wp_customize->add_setting($setting[0], array('type' => 'option', 'default' => $this->defaults[$setting[0]], 'transport' => 'refresh'));
     }
     //
     // Output - Controls.
     //
     foreach ($cs['con'] as $control) {
         static $i = 1;
         if ($control[1] == 'radio') {
             $wp_customize->add_control($control[0], array('type' => $control[1], 'label' => $control[2], 'section' => $control[4], 'priority' => $i, 'choices' => $control[3]));
         } elseif ($control[1] == 'select') {
             $wp_customize->add_control($control[0], array('type' => $control[1], 'label' => $control[2], 'section' => $control[4], 'priority' => $i, 'choices' => $control[3]));
         } elseif ($control[1] == 'slider') {
             $wp_customize->add_control(new X_Customize_Control_Slider($wp_customize, $control[0], array('label' => $control[2], 'section' => $control[4], 'settings' => $control[0], 'priority' => $i, 'choices' => $control[3])));
         } elseif ($control[1] == 'text') {
             $wp_customize->add_control($control[0], array('type' => $control[1], 'label' => $control[2], 'section' => $control[3], 'priority' => $i));
         } elseif ($control[1] == 'textarea') {
             $wp_customize->add_control(new X_Customize_Control_Textarea($wp_customize, $control[0], array('label' => $control[2], 'section' => $control[3], 'settings' => $control[0], 'priority' => $i)));
         } elseif ($control[1] == 'checkbox') {
             $wp_customize->add_control($control[0], array('type' => $control[1], 'label' => $control[2], 'section' => $control[3], 'priority' => $i));
         } elseif ($control[1] == 'color') {
             $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, $control[0], array('label' => $control[2], 'section' => $control[3], 'settings' => $control[0], 'priority' => $i)));
         } elseif ($control[1] == 'image') {
             $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, $control[0], array('label' => $control[2], 'section' => $control[3], 'settings' => $control[0], 'priority' => $i)));
         }
         $i++;
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号