/** * Apply configuration. */ protected function configure($config = null) { // gurantee configuration $config !== null or $config = array(); // invoke htmltag instance configuration if (isset($config['attrs'])) { parent::configure($config['attrs']); unset($config['attrs']); } else { // no html attributes set parent::configure(array()); } // setup meta fields $this->meta = pixlikes::instance('PixlikesMeta', $config); }
/** * @return string attributes */ function htmlattributes(array $extra = array()) { $attr_segments = array(); $attributes = pixlikes::merge($this->attrs->metadata_array(), $extra); foreach ($attributes as $key => $value) { if ($value !== false && $value !== null) { if (!empty($value)) { if (is_array($value)) { $htmlvalue = implode(' ', $value); $attr_segments[] = "{$key}=\"{$htmlvalue}\""; } else { // value is not an array $attr_segments[] = "{$key}=\"{$value}\""; } } else { // empty html tag; ie. no value html tag $attr_segments[] = $key; } } } return implode(' ', $attr_segments); }
} ?> <?php if ($processor->performed_update()) { ?> <br/> <p class="update-nag"> Settings have been updated. </p> <?php } ?> <?php echo $f = pixlikes::form($config, $processor); ?> <?php echo $f->field('general')->render(); ?> <?php echo $f->field('show_on')->render(); ?> <?php echo $f->field('cache')->render(); ?> <button type="submit" class="button button-primary">
<?php return array('cleanup' => array('switch' => array('switch_not_available')), 'checks' => array('counter' => array('is_numeric', 'not_empty')), 'processor' => array('preupdate' => array(), 'postupdate' => array()), 'errors' => array('is_numeric' => __('Numberic value required.', pixlikes::textdomain()), 'not_empty' => __('Field is required.', pixlikes::textdomain())), 'callbacks' => array('switch_not_available' => 'pixlikes_cleanup_switch_not_available', 'is_numeric' => 'pixlikes_validate_is_numeric', 'not_empty' => 'pixlikes_validate_not_empty')); # config
/** * @param string rule * @return string error message */ function error_message($rule) { if (self::$error_message_cache === null) { $defaults = pixlikes::defaults(); $default_errors = $defaults['errors']; $plugin_errors = $this->meta->get('errors', array()); self::$error_message_cache = array_merge($default_errors, $plugin_errors); } return self::$error_message_cache[$rule]; }
<?php defined('ABSPATH') or die; // ensure EXT is defined if (!defined('EXT')) { define('EXT', '.php'); } $basepath = dirname(__FILE__) . DIRECTORY_SEPARATOR; require $basepath . 'core' . EXT; // load classes $interfacepath = $basepath . 'interfaces' . DIRECTORY_SEPARATOR; pixlikes::require_all($interfacepath); $classpath = $basepath . 'classes' . DIRECTORY_SEPARATOR; pixlikes::require_all($classpath); // load callbacks $callbackpath = $basepath . 'callbacks' . DIRECTORY_SEPARATOR; pixlikes::require_all($callbackpath);
/** * Sets a custom text domain; if null is passed the text domain will revert * to the default text domain. */ static function settextdomain($textdomain) { if (!empty($textdomain)) { self::$textdomain = $textdomain; } else { // null or otherwise empty value // revert to default self::$textdomain = 'pixlikes_txtd'; } }
function pixlikes_edit_metabox($post) { // Add an nonce field so we can check for it later. wp_nonce_field('pixlikes_inner_custom_box', 'pixlikes_inner_custom_box_nonce'); $value = get_post_meta($post->ID, '_pixlikes', true); echo '<label for="edit_pixlikes">'; _e("Likes number: ", pixlikes::textdomain()); echo '</label> '; echo '<input type="text" id="edit_pixlikes" name="edit_pixlikes" value="' . esc_attr($value) . '" size="20" />'; }
<?php defined('ABSPATH') or die; $basepath = dirname(__FILE__) . DIRECTORY_SEPARATOR; $debug = false; if (isset($_GET['debug']) && $_GET['debug'] == 'true') { $debug = true; } return array('plugin-name' => 'pixlikes', 'settings-key' => 'pixlikes_settings', 'textdomain' => 'pixlikes_txtd', 'template-paths' => array($basepath . 'core/views/form-partials/', $basepath . 'views/form-partials/'), 'fields' => array('general' => include 'settings/general' . EXT, 'show_on' => include 'settings/show_on' . EXT, 'cache' => include 'settings/cache' . EXT), 'processor' => array('preupdate' => array(), 'postupdate' => array('save_settings')), 'cleanup' => array('switch' => array('switch_not_available')), 'checks' => array('counter' => array('is_numeric', 'not_empty')), 'errors' => array('not_empty' => __('Invalid Value.', pixlikes::textdomain())), 'callbacks' => array('save_settings' => 'save_pixlikes_settings'), 'github_updater' => array('slug' => 'pixlikes/pixlikes.php', 'api_url' => 'https://api.github.com/repos/pixelgrade/pixlikes', 'raw_url' => 'https://raw.github.com/pixelgrade/pixlikes/update', 'github_url' => 'https://github.com/pixelgrade/pixlikes/tree/update', 'zip_url' => 'https://github.com/pixelgrade/pixlikes/archive/update.zip', 'sslverify' => false, 'requires' => '3.0', 'tested' => '3.3', 'readme' => 'README.md', 'textdomain' => 'pixlikes', 'debug_mode' => $debug), 'debug' => $debug); # config
/** * @param string template path * @param array configuration * @return string */ function fieldtemplate($templatepath, $conf = array()) { $config = pixlikes::instance('PixlikesMeta', $conf); return $this->fieldtemplate_render($templatepath, $config); }
/** * Execute postupdate hooks on input. */ protected function postupdate($input) { $defaults = pixlikes::defaults(); $plugin_hooks = $this->meta->get('processor', array('preupdate' => array(), 'postupdate' => array())); // Calculate hooks // --------------- $hooks = array(); // check pixlikes defaults if (isset($defaults['processor']['postupdate'])) { $hooks = $defaults['processor']['postupdate']; } // check plugin defaults if (isset($plugin_hooks['postupdate'])) { $hooks = array_merge($hooks, $plugin_hooks['postupdate']); } // Execute hooks // ------------- foreach ($hooks as $rule) { $callback = pixlikes::callback($rule, $this->meta); call_user_func($callback, $input, $this); } }
<?php return array('type' => 'postbox', 'label' => __('Cache Settings', pixlikes::textdomain()), 'options' => array('load_likes_with_ajax' => array('label' => __('Reload likes number on page load', pixlikes::textdomain()), 'default' => false, 'description' > __('This helps you to prevent the likes number to be cached', pixlikes::textdomain()), 'type' => 'switch'))); # config