Plugin Directory

Changeset 2017039


Ignore:
Timestamp:
01/22/2019 05:12:28 PM (7 years ago)
Author:
alexmacarthur
Message:

Update to v3.4.1.

Location:
complete-open-graph
Files:
38 added
14 edited

Legend:

Unmodified
Added
Removed
  • complete-open-graph/trunk/complete-open-graph.php

    r2016610 r2017039  
    33 * Plugin Name: Complete Open Graph
    44 * Description: Simple, comprehensive, highly customizable Open Graph management.
    5  * Version: 3.4.0
     5 * Version: 3.4.1
    66 * Author: Alex MacArthur
    77 * Author URI: https://macarthur.me
     
    1414namespace CompleteOpenGraph;
    1515
    16 if ( ! defined( 'WPINC' ) ) {
    17     die;
     16if (! defined('WPINC')) {
     17    die;
    1818}
    1919
    20 require_once( trailingslashit( ABSPATH ) . 'wp-admin/includes/plugin.php' );
     20require_once(trailingslashit(ABSPATH) . 'wp-admin/includes/plugin.php');
    2121
    22 define( 'COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX', 'complete_open_graph' );
    23 define( 'COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX', 'complete_open_graph' );
    24 define( 'COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG', 'complete_open_graph' );
    25 define( 'COMPLETE_OPEN_GRAPH_PLUGIN_DATA', get_plugin_data( __DIR__ . '/complete-open-graph.php' ) );
    26 define( 'COMPLETE_OPEN_GRAPH_REAL_PATH', trailingslashit( realpath( dirname( __FILE__ ) ) ) );
     22define('COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX', 'complete_open_graph');
     23define('COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX', 'complete_open_graph');
     24define('COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG', 'complete_open_graph');
     25define('COMPLETE_OPEN_GRAPH_REAL_PATH', trailingslashit(realpath(dirname(__FILE__))));
    2726
    2827require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/Generator.php';
     
    3332 * Responsible for registering global assets and requiring code.
    3433 */
    35 class App {
     34class App
     35{
    3636
    37     /**
    38      * Initialize the plugin.
    39      *
    40      * @return object App Instance of class.
    41      */
    42     public static function go() {
    43         $GLOBALS[ __CLASS__ ] = new self;
    44         return $GLOBALS[ __CLASS__ ];
    45     }
     37    /**
     38     * Initialize the plugin.
     39     *
     40     * @return object App Instance of class.
     41     */
     42    public static function go()
     43    {
     44        $GLOBALS[ __CLASS__ ] = new self;
     45        return $GLOBALS[ __CLASS__ ];
     46    }
    4647
    47     /**
    48      * Instatiate necessary classes, enqueue admin scripts.
    49      */
    50     public function __construct() {
    51         require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/generate-open-graph-markup.php';
    52         require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/content-filters.php';
    53         require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/settings.php';
    54         require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/metabox.php';
    55         require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/support.php';
    56         add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles_and_scripts' ) );
    57     }
     48    /**
     49     * Retrive array of plugin data.
     50     *
     51     * @return array
     52     */
     53    public static function getPluginData()
     54    {
     55        return get_plugin_data(__DIR__ . '/complete-open-graph.php');
     56    }
    5857
    59     /**
    60      * Delete global and post/page data.
    61      *
    62      * @return void
    63      */
    64     public static function delete_options_and_meta() {
    65         global $wpdb;
    66         delete_option( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX );
    67         $wpdb->delete( $wpdb->prefix . 'postmeta', array( 'meta_key' => COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX ) );
    68     }
     58    /**
     59     * Instatiate necessary classes, enqueue admin scripts.
     60     */
     61    public function __construct()
     62    {
     63        require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/generate-open-graph-markup.php';
     64        require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/content-filters.php';
     65        require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/settings.php';
     66        require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/metabox.php';
     67        require_once COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/hooks/support.php';
     68        add_action('admin_enqueue_scripts', array( $this, 'enqueue_styles_and_scripts' ));
     69    }
    6970
    70     /**
    71      * Enqueue global admin scripts & styles.
    72      *
    73      * @return void
    74      */
    75     public function enqueue_styles_and_scripts() {
    76         wp_enqueue_style( 'complete-open-graph', plugin_dir_url( __FILE__ ) . 'src/assets/css/style.css', array(), COMPLETE_OPEN_GRAPH_PLUGIN_DATA['Version'] );
    77         wp_enqueue_script( 'complete-open-graph', plugin_dir_url( __FILE__ ) . 'src/assets/js/scripts.js', array( 'jquery' ), COMPLETE_OPEN_GRAPH_PLUGIN_DATA['Version'], true );
    78     }
     71    /**
     72     * Delete global and post/page data.
     73     *
     74     * @return void
     75     */
     76    public static function delete_options_and_meta()
     77    {
     78        global $wpdb;
     79        delete_option(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX);
     80        $wpdb->delete($wpdb->prefix . 'postmeta', array( 'meta_key' => COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX ));
     81    }
     82
     83    /**
     84     * Enqueue global admin scripts & styles.
     85     *
     86     * @return void
     87     */
     88    public function enqueue_styles_and_scripts()
     89    {
     90        wp_enqueue_style('complete-open-graph', plugin_dir_url(__FILE__) . 'src/assets/css/style.css', array(), self::getPluginData()['Version']);
     91        wp_enqueue_script('complete-open-graph', plugin_dir_url(__FILE__) . 'src/assets/js/scripts.js', array( 'jquery' ), self::getPluginData()['Version'], true);
     92    }
    7993}
    8094
     
    8296
    8397// -- On uninstallation, delete plugin-related database stuffs.
    84 register_uninstall_hook( __FILE__, array( '\CompleteOG\App', 'delete_options_and_meta' ) );
     98register_uninstall_hook(__FILE__, array( '\CompleteOG\App', 'delete_options_and_meta' ));
  • complete-open-graph/trunk/composer.json

    r2016610 r2017039  
    55  "minimum-stability": "stable",
    66  "license": "GPL-2.0",
    7   "version": "3.4.0",
     7  "version": "3.4.1",
    88  "authors": [
    99    {
  • complete-open-graph/trunk/readme.txt

    r2016610 r2017039  
    77Requires PHP: 5.6
    88Tested up to: 5.0.3
    9 Stable tag: 3.4.0
     9Stable tag: 3.4.1
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    297297* Display "profile:first_name" and "profile:last_name" meta tags on author pages.
    298298
     299= 3.4.1 =
     300* Fix constant-related bug for installations using older versions of PHP.
     301
    299302== Feedback ==
    300303
  • complete-open-graph/trunk/src/Field.php

    r2016610 r2017039  
    66 * A class to help access field configuration data.
    77 */
    8 class Field {
     8class Field
     9{
    910
    10     public function __construct( $key ) {
    11         $this->fields = Utilities::getFields();
    12         $this->key    = $key;
    13         $this->field  = $this->fields[ $key ];
    14     }
     11    public function __construct($key)
     12    {
     13        $this->fields = Utilities::getFields();
     14        $this->key    = $key;
     15        $this->field  = $this->fields[ $key ];
     16    }
    1517
    16     public function __get( $property ) {
     18    public function __get($property)
     19    {
    1720
    18         if ( $property === 'name' ) {
    19             return 'complete_open_graph_' . $this->key;
    20         }
     21        if ($property === 'name') {
     22            return 'complete_open_graph_' . $this->key;
     23        }
    2124
    22         if ( $property === 'id' ) {
    23             $result = preg_split( '/(_|:)/', $this->key );
     25        if ($property === 'id') {
     26            $result = preg_split('/(_|:)/', $this->key);
    2427
    25             $result = array_map(
    26                 function( $item ) {
    27                     return ucfirst( $item );
    28                 },
    29                 $result
    30             );
     28            $result = array_map(
     29                function ($item) {
     30                    return ucfirst($item);
     31                },
     32                $result
     33            );
    3134
    32             return 'cog' . implode( '', $result );
    33         }
     35            return 'cog' . implode('', $result);
     36        }
    3437
    35         if ( isset( $this->field[ $property ] ) ) {
    36             return $this->field[ $property ];
    37         }
     38        if (isset($this->field[ $property ])) {
     39            return $this->field[ $property ];
     40        }
    3841
    39         return '';
    40     }
     42        return '';
     43    }
    4144
    42     /**
    43      * Return only the fields that are configurable within the admin.
    44      */
    45     public static function getConfigurable( $fields = null ) {
     45    /**
     46     * Return only the fields that are configurable within the admin.
     47     */
     48    public static function getConfigurable($fields = null)
     49    {
    4650
    47         $fields = is_null( $fields ) ? Utilities::getFields() : $fields;
     51        $fields = is_null($fields) ? Utilities::getFields() : $fields;
    4852
    49         $configurableFields = array_filter(
    50             $fields,
    51             function ( $item ) {
    52                 return isset( $item['is_configurable'] ) && $item['is_configurable'];
    53             }
    54         );
     53        $configurableFields = array_filter(
     54            $fields,
     55            function ($item) {
     56                return isset($item['is_configurable']) && $item['is_configurable'];
     57            }
     58        );
    5559
    56         $fields = [];
     60        $fields = [];
    5761
    58         foreach ( $configurableFields as $k => $v ) {
    59             $fields[] = new self( $k );
    60         }
     62        foreach ($configurableFields as $k => $v) {
     63            $fields[] = new self($k);
     64        }
    6165
    62         return $fields;
    63     }
     66        return $fields;
     67    }
    6468}
  • complete-open-graph/trunk/src/Generator.php

    r2016610 r2017039  
    33namespace CompleteOpenGraph;
    44
    5 class Generator {
     5class Generator
     6{
    67
    7     /**
    8      * Get the values for each OG attribute, based on priority & existence of values.
    9      *
    10      * @return array Open Graph values
    11      */
    12     public static function getOpenGraphValues() {
    13         $frontPageID = (int) get_option( 'page_on_front' );
    14         $fields      = Utilities::getFields();
     8    /**
     9     * Get the values for each OG attribute, based on priority & existence of values.
     10     *
     11     * @return array Open Graph values
     12     */
     13    public static function getOpenGraphValues()
     14    {
     15        $frontPageID = (int) get_option('page_on_front');
     16        $fields      = Utilities::getFields();
    1517
    16         // -- Filter for filtering specific fields.
    17         foreach ( $fields as $key => $item ) {
    18             $value = isset( $fields[ $key ]['get_value'] ) ? $fields[ $key ]['get_value']() : "";
    19             $fields[ $key ]['value'] = apply_filters( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_' . $key, $value, $key );
    20         }
     18        // -- Filter for filtering specific fields.
     19        foreach ($fields as $key => $item) {
     20            $value = isset($fields[ $key ]['get_value']) ? $fields[ $key ]['get_value']() : "";
     21            $fields[ $key ]['value'] = apply_filters(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_' . $key, $value, $key);
     22        }
    2123
    22         return apply_filters( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_all_data', $fields );
    23     }
     24        return apply_filters(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_all_data', $fields);
     25    }
    2426}
  • complete-open-graph/trunk/src/PostDecorator.php

    r2016610 r2017039  
    33namespace CompleteOpenGraph;
    44
    5 class PostDecorator {
     5class PostDecorator
     6{
    67
    7     /**
    8     * WP_Post object.
    9     *
    10     * @var obj
    11     */
    12     public $post;
     8    /**
     9    * WP_Post object.
     10    *
     11    * @var obj
     12    */
     13    public $post;
    1314
    14     /**
    15      * Constructs decorator based on WP_Post object.
    16      *
    17      * @param WP_Post|null $post
    18      */
    19     public function __construct( $post = null ) {
    20         $this->post = is_null( $post ) ? $GLOBALS['post'] : $post;
    21     }
     15    /**
     16     * Constructs decorator based on WP_Post object.
     17     *
     18     * @param WP_Post|null $post
     19     */
     20    public function __construct($post = null)
     21    {
     22        $this->post = is_null($post) ? $GLOBALS['post'] : $post;
     23    }
    2224
    23     /**
    24      * Returns false if property doesn't exist.
    25      *
    26      * @param  string $key
    27      * @return mixed
    28      */
    29     public function __get( $key ) {
    30         if ( ! isset( $this->post->$key ) ) {
    31             return null;
    32         }
     25    /**
     26     * Returns false if property doesn't exist.
     27     *
     28     * @param  string $key
     29     * @return mixed
     30     */
     31    public function __get($key)
     32    {
     33        if (! isset($this->post->$key)) {
     34            return null;
     35        }
    3336
    34         return $this->post->$key;
    35     }
     37        return $this->post->$key;
     38    }
    3639}
  • complete-open-graph/trunk/src/Utilities.php

    r2016610 r2017039  
    55require_once 'PostDecorator.php';
    66
    7 class Utilities {
    8 
    9     public static function getFields() {
    10         return include 'fields.php';
    11     }
    12 
    13     public static function get_current_post_type() {
    14         global $post, $typenow, $current_screen;
    15 
    16         if ( $post && $post->post_type ) {
    17             return $post->post_type;
    18         } elseif ( $typenow ) {
    19             return $typenow;
    20         } elseif ( $current_screen && $current_screen->post_type ) {
    21             return $current_screen->post_type;
    22         } elseif ( isset( $_REQUEST['post_type'] ) ) {
    23             return sanitize_key( $_REQUEST['post_type'] );
    24         } elseif ( isset( $_REQUEST['post'] ) ) {
    25             return get_post_type( $_REQUEST['post'] );
    26         }
    27 
    28         return null;
    29     }
    30 
    31     /**
    32      * Gets serialized settings in options table.
    33      *
    34      * @return array
    35      */
    36     public static function get_options() {
    37         return get_option( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX );
    38     }
    39 
    40     /**
    41      * Gets specific option value.
    42      *
    43      * @param  string $key Option key
    44      * @return string
    45      */
    46     public static function get_option( $key ) {
    47         if ( isset( self::get_options()[ $key ] ) ) {
    48             return self::get_options()[ $key ];
    49         }
    50 
    51         return false;
    52     }
    53 
    54     /**
    55      * Returns instance of PostDecorator, creates one if not defined.
    56      *
    57      * @return obj
    58      */
    59     public static function get_post_decorator() {
    60         global $post;
    61         return new PostDecorator( $post );
    62     }
    63 
    64     /**
    65      * Gets serialized options for individual post/page.
    66      *
    67      * @return array
    68      */
    69     public static function get_post_options() {
    70         $post_options = get_post_meta( self::get_post_decorator()->ID, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX );
    71 
    72         if ( empty( $post_options ) ) {
    73             return array();
    74         }
    75 
    76         return $post_options[0];
    77     }
    78 
    79     /**
    80      * Gets value for specific post/page option.
    81      *
    82      * @param  string $key Field key
    83      * @return string|bool
    84      */
    85     public static function get_post_option( $key ) {
    86         $post_options = self::get_post_options();
    87         return ! empty( $post_options[ $key ] ) ? $post_options[ $key ] : false;
    88     }
    89 
    90     /**
    91      * Gets full name of particular field, with prefix appended.
    92      *
    93      * @param  string $name Name of field
    94      * @return string
    95      */
    96     public static function get_field_name( $name ) {
    97         return COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '[' . $name . ']';
    98     }
    99 
    100     /**
    101      * Gets the first image that appears on the post/page.
    102      *
    103      * @return string|bool
    104      */
    105     public static function get_first_image() {
    106         $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', self::get_post_decorator()->post_content, $matches );
    107         return ! empty( $matches[1][0] ) ? $matches[1][0] : false;
    108     }
    109 
    110     /**
    111      * Strips all tags from a string of text.
    112      *
    113      * @param  string text
    114      * @return string
    115      */
    116     public static function strip_all_tags( $text ) {
    117         if ( ! $text ) {
    118             return $text;
    119         }
    120 
    121         $text = preg_replace( '#<script(.*?)>(.*?)</script>#is', '', $text );
    122         $text = preg_replace( '#<style(.*?)>(.*?)</style>#is', '', $text );
    123 
    124         return strip_tags( $text );
    125     }
    126 
    127     /**
    128      * Do all the things for formatting a piece of OG content.
    129      *
    130      * @param  string $content
    131      * @return string
    132      */
    133     public static function process_content( $content ) {
    134         $value = strip_shortcodes( $content );
    135         $value = self::strip_all_tags( $value );
    136         $value = trim( $value );
    137         $value = substr( $value, 0, 300 );
    138         return $value;
    139     }
    140 
    141     /**
    142      * Cascades over progression of values and return the first value that isn't empty.
    143      *
    144      * @param [array] $progression
    145      * @return string
    146      */
    147     public static function get_cascaded_value( $progression ) {
    148         if ( empty( $progression ) ) {
    149             return '';
    150         }
    151 
    152         foreach ( $progression as $progressionValue ) {
    153             if ( ! empty( $progressionValue ) ) {
    154                 return self::process_content( $progressionValue );
    155             }
    156         }
    157 
    158         return '';
    159     }
    160 
    161     /**
    162      * Get a specific value for an Open Graph attribute.
    163      * If progression is given, it will assign the first value that exists.
    164      *
    165      * @param  string $field_name  Name of the attribute.
    166      * @param  array  $progression Array of possible values, in order of priority.
    167      * @param  array  $protectedKeys Prevents specified keys from being removed duing useGlobal.
    168      * @return string
    169      */
    170     public static function get_processed_value( $field_name, $progression = array(), $protectedKeys = array() ) {
    171 
    172         // -- Check for explicit option to use global options, or if it's an archive page.
    173         $useGlobal =
    174             (
    175                 self::get_option( 'force_all' ) === 'on' ||
    176                 self::get_option( $field_name . '_force' ) === 'on' ||
    177                 ( is_home() || is_archive() )
    178             );
    179 
    180         if ( $useGlobal ) {
    181             $value = self::process_content( self::get_option( $field_name ) );
    182 
    183             // -- Remove non-protected items before we tack on our global value.
    184             // -- This way, we can have a fallback system in place in case a global value is empty.
    185             $progression = self::get_only_protected_values( $progression, $protectedKeys );
    186 
    187             array_unshift( $progression, $value );
    188 
    189             return apply_filters(
    190                 COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_processed_value',
    191                 self::get_cascaded_value( $progression ),
    192                 $field_name
    193             );
    194         }
    195 
    196         return apply_filters(
    197             COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_processed_value',
    198             self::get_cascaded_value( $progression ),
    199             $field_name
    200         );
    201 
    202     }
    203 
    204     /**
    205      * Ideally, this would be array_filter(), but was causing PHP fallback issues.
    206      *
    207      * @param array $progression
    208      * @param array $protectedKeys
    209      * @return array
    210      */
    211     public static function get_only_protected_values( $progression, $protectedKeys ) {
    212         $protectedValues = array();
    213 
    214         foreach ( $protectedKeys as $key ) {
    215             if ( ! isset( $progression[ $key ] ) ) {
    216                 continue;
    217             }
    218             $protectedValues[] = $progression[ $key ];
    219         }
    220 
    221         return $protectedValues;
    222     }
    223 
     7class Utilities
     8{
     9
     10    public static function getFields()
     11    {
     12        return include 'fields.php';
     13    }
     14
     15    public static function get_current_post_type()
     16    {
     17        global $post, $typenow, $current_screen;
     18
     19        if ($post && $post->post_type) {
     20            return $post->post_type;
     21        } elseif ($typenow) {
     22            return $typenow;
     23        } elseif ($current_screen && $current_screen->post_type) {
     24            return $current_screen->post_type;
     25        } elseif (isset($_REQUEST['post_type'])) {
     26            return sanitize_key($_REQUEST['post_type']);
     27        } elseif (isset($_REQUEST['post'])) {
     28            return get_post_type($_REQUEST['post']);
     29        }
     30
     31        return null;
     32    }
     33
     34    /**
     35     * Gets serialized settings in options table.
     36     *
     37     * @return array
     38     */
     39    public static function get_options()
     40    {
     41        return get_option(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX);
     42    }
     43
     44    /**
     45     * Gets specific option value.
     46     *
     47     * @param  string $key Option key
     48     * @return string
     49     */
     50    public static function get_option($key)
     51    {
     52        if (isset(self::get_options()[ $key ])) {
     53            return self::get_options()[ $key ];
     54        }
     55
     56        return false;
     57    }
     58
     59    /**
     60     * Returns instance of PostDecorator, creates one if not defined.
     61     *
     62     * @return obj
     63     */
     64    public static function get_post_decorator()
     65    {
     66        global $post;
     67        return new PostDecorator($post);
     68    }
     69
     70    /**
     71     * Gets serialized options for individual post/page.
     72     *
     73     * @return array
     74     */
     75    public static function get_post_options()
     76    {
     77        $post_options = get_post_meta(self::get_post_decorator()->ID, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX);
     78
     79        if (empty($post_options)) {
     80            return array();
     81        }
     82
     83        return $post_options[0];
     84    }
     85
     86    /**
     87     * Gets value for specific post/page option.
     88     *
     89     * @param  string $key Field key
     90     * @return string|bool
     91     */
     92    public static function get_post_option($key)
     93    {
     94        $post_options = self::get_post_options();
     95        return ! empty($post_options[ $key ]) ? $post_options[ $key ] : false;
     96    }
     97
     98    /**
     99     * Gets full name of particular field, with prefix appended.
     100     *
     101     * @param  string $name Name of field
     102     * @return string
     103     */
     104    public static function get_field_name($name)
     105    {
     106        return COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '[' . $name . ']';
     107    }
     108
     109    /**
     110     * Gets the first image that appears on the post/page.
     111     *
     112     * @return string|bool
     113     */
     114    public static function get_first_image()
     115    {
     116        $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', self::get_post_decorator()->post_content, $matches);
     117        return ! empty($matches[1][0]) ? $matches[1][0] : false;
     118    }
     119
     120    /**
     121     * Strips all tags from a string of text.
     122     *
     123     * @param  string text
     124     * @return string
     125     */
     126    public static function strip_all_tags($text)
     127    {
     128        if (! $text) {
     129            return $text;
     130        }
     131
     132        $text = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $text);
     133        $text = preg_replace('#<style(.*?)>(.*?)</style>#is', '', $text);
     134
     135        return strip_tags($text);
     136    }
     137
     138    /**
     139     * Do all the things for formatting a piece of OG content.
     140     *
     141     * @param  string $content
     142     * @return string
     143     */
     144    public static function process_content($content)
     145    {
     146        $value = strip_shortcodes($content);
     147        $value = self::strip_all_tags($value);
     148        $value = trim($value);
     149        $value = substr($value, 0, 300);
     150        return $value;
     151    }
     152
     153    /**
     154     * Cascades over progression of values and return the first value that isn't empty.
     155     *
     156     * @param [array] $progression
     157     * @return string
     158     */
     159    public static function get_cascaded_value($progression)
     160    {
     161        if (empty($progression)) {
     162            return '';
     163        }
     164
     165        foreach ($progression as $progressionValue) {
     166            if (! empty($progressionValue)) {
     167                return self::process_content($progressionValue);
     168            }
     169        }
     170
     171        return '';
     172    }
     173
     174    /**
     175     * Get a specific value for an Open Graph attribute.
     176     * If progression is given, it will assign the first value that exists.
     177     *
     178     * @param  string $field_name  Name of the attribute.
     179     * @param  array  $progression Array of possible values, in order of priority.
     180     * @param  array  $protectedKeys Prevents specified keys from being removed duing useGlobal.
     181     * @return string
     182     */
     183    public static function get_processed_value($field_name, $progression = array(), $protectedKeys = array())
     184    {
     185
     186        // -- Check for explicit option to use global options, or if it's an archive page.
     187        $useGlobal =
     188            (
     189                self::get_option('force_all') === 'on' ||
     190                self::get_option($field_name . '_force') === 'on' ||
     191                ( is_home() || is_archive() )
     192            );
     193
     194        if ($useGlobal) {
     195            $value = self::process_content(self::get_option($field_name));
     196
     197            // -- Remove non-protected items before we tack on our global value.
     198            // -- This way, we can have a fallback system in place in case a global value is empty.
     199            $progression = self::get_only_protected_values($progression, $protectedKeys);
     200
     201            array_unshift($progression, $value);
     202
     203            return apply_filters(
     204                COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_processed_value',
     205                self::get_cascaded_value($progression),
     206                $field_name
     207            );
     208        }
     209
     210        return apply_filters(
     211            COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_processed_value',
     212            self::get_cascaded_value($progression),
     213            $field_name
     214        );
     215    }
     216
     217    /**
     218     * Ideally, this would be array_filter(), but was causing PHP fallback issues.
     219     *
     220     * @param array $progression
     221     * @param array $protectedKeys
     222     * @return array
     223     */
     224    public static function get_only_protected_values($progression, $protectedKeys)
     225    {
     226        $protectedValues = array();
     227
     228        foreach ($protectedKeys as $key) {
     229            if (! isset($progression[ $key ])) {
     230                continue;
     231            }
     232            $protectedValues[] = $progression[ $key ];
     233        }
     234
     235        return $protectedValues;
     236    }
    224237}
  • complete-open-graph/trunk/src/assets/js/scripts.js

    r1891298 r2017039  
    1 (function($) {
     1(function ($) {
    22
    3     if (typeof wp === 'undefined' || !wp.hasOwnProperty('media')) return;
    4 
    5   var $imageHolder = $('#cogImageHolder');
    6   var $imageInput = $('#cogImage');
    7   var $COGMetaBox = $('#cogMetaBox');
    8   var $cogSettingsPage = $('#cogSettingsPage');
    9     var $uploadedFileName = $('#cogUploadedFileName');
    10 
    11   var customUploader = wp.media.frames.file_frame = wp.media({
    12       title: 'Choose Open Graph Image',
    13       button: {
    14         text: 'Set As Open Graph Image'
    15       },
    16       multiple: false
    17     });
    18   var thumbURL;
    19   var attachment;
    20 
    21   customUploader.on('select', function(e) {
    22     attachment = customUploader.state().get('selection').first().toJSON();
    23     thumbURL = attachment.sizes['medium'] == undefined ? attachment.url : attachment.sizes['medium'].url;
    24 
    25     if($COGMetaBox) {
    26       $COGMetaBox.removeClass('has-no-image');
     3    if (typeof wp === 'undefined' || !wp.hasOwnProperty('media')) {
     4        return;
    275    }
    286
    29     if($cogSettingsPage) {
    30       $cogSettingsPage.removeClass('has-no-image');
    31     }
     7    var $imageHolder = $('#cogImageHolder');
     8    var $imageInput = $('#cogImage');
     9    var $COGMetaBox = $('#cogMetaBox');
     10    var $cogSettingsPage = $('#cogSettingsPage');
     11    var $uploadedFileName = $('#cogUploadedFileName');
    3212
    33     $imageHolder.css('background-image', 'url(' + thumbURL + ')');
    34     $uploadedFileName.html(attachment.url.split('/').reverse()[0]);
     13    var customUploader = wp.media.frames.file_frame = wp.media({
     14        title: 'Choose Open Graph Image',
     15        button: {
     16            text: 'Set As Open Graph Image'
     17        },
     18        multiple: false
     19    });
     20    var thumbURL;
     21    var attachment;
    3522
    36     //-- Set input values.
    37     $imageInput.val(attachment.id);
    38   });
     23    customUploader.on('select', function (e) {
     24        attachment = customUploader.state().get('selection').first().toJSON();
     25        thumbURL = attachment.sizes['medium'] == undefined ? attachment.url : attachment.sizes['medium'].url;
    3926
    40   $('#cogImageSelectButton').on('click', function(e){
    41     customUploader.open();
    42     return true;
    43   });
     27        if ($COGMetaBox) {
     28            $COGMetaBox.removeClass('has-no-image');
     29        }
    4430
    45   $('#ogRemoveImage').on('click', function() {
    46     if($COGMetaBox) {
    47       $COGMetaBox.addClass('has-no-image');
    48     }
    49     if($cogSettingsPage) {
    50       $cogSettingsPage.addClass('has-no-image');
    51     }
    52     $uploadedFileName.html('');
    53     $imageHolder.css('background-image', 'url("")');
    54     $imageInput.val('');
    55   });
     31        if ($cogSettingsPage) {
     32            $cogSettingsPage.removeClass('has-no-image');
     33        }
    5634
    57   $('#ogForceAll').on('change', function () {
    58     if($(this).is(':checked')) {
    59         $cogSettingsPage.addClass('is-forcing-all');
    60     } else {
    61         $cogSettingsPage.removeClass('is-forcing-all');
    62     }
    63   });
     35        $imageHolder.css('background-image', 'url(' + thumbURL + ')');
     36        $uploadedFileName.html(attachment.url.split('/').reverse()[0]);
     37
     38      //-- Set input values.
     39        $imageInput.val(attachment.id);
     40    });
     41
     42    $('#cogImageSelectButton').on('click', function (e) {
     43        customUploader.open();
     44        return true;
     45    });
     46
     47    $('#ogRemoveImage').on('click', function () {
     48        if ($COGMetaBox) {
     49            $COGMetaBox.addClass('has-no-image');
     50        }
     51        if ($cogSettingsPage) {
     52            $cogSettingsPage.addClass('has-no-image');
     53        }
     54        $uploadedFileName.html('');
     55        $imageHolder.css('background-image', 'url("")');
     56        $imageInput.val('');
     57    });
     58
     59    $('#ogForceAll').on('change', function () {
     60        if ($(this).is(':checked')) {
     61            $cogSettingsPage.addClass('is-forcing-all');
     62        } else {
     63            $cogSettingsPage.removeClass('is-forcing-all');
     64        }
     65    });
    6466})(jQuery);
  • complete-open-graph/trunk/src/fields.php

    r2016610 r2017039  
    33namespace CompleteOpenGraph;
    44
    5 $frontPageID = (int) get_option( 'page_on_front' );
     5$frontPageID = (int) get_option('page_on_front');
    66
    77return [
    8     'og:site_name'        => [
    9         'label'     => 'Site Name',
    10         'attribute' => 'property',
    11         'get_value' => function () {
    12             return get_bloginfo( 'name' );
    13         },
    14     ],
    15     'og:url'              => [
    16         'attribute' => 'property',
    17         'get_value' => function () {
    18             return Utilities::get_processed_value(
    19                 'og:url',
    20                 array(
    21                     get_permalink( Utilities::get_post_decorator()->ID ),
    22                     get_bloginfo( 'url' ),
    23                 ),
    24                 array( 1 )
    25             );
    26         },
    27     ],
    28     'og:locale'           => [
    29         'attribute' => 'property',
    30         'get_value' => function () {
    31             return get_locale();
    32         },
    33     ],
    34     'og:description'      => $description = [
    35         'is_configurable' => true,
    36         'field_type'      => 'text',
    37         'attribute'       => 'property',
    38         'label'           => 'Description',
    39         'description'     => 'If left blank, the excerpt will be used. If no excerpt exists, the site description will be used.',
    40         'get_value'       => function () {
    41             return Utilities::get_processed_value(
    42                 'og:description',
    43                 array(
    44                     Utilities::get_post_option( 'og:description' ),
    45                     Utilities::get_post_decorator()->post_excerpt,
    46                     Utilities::get_post_decorator()->post_content,
    47                     Utilities::get_option( 'og:description' ),
    48                     get_bloginfo( 'description' ),
    49                 ),
    50                 array( 3, 4 )
    51             );
    52         },
    53     ],
    54     'og:title'            => $title       = [
    55         'is_configurable' => true,
    56         'field_type'      => 'text',
    57         'attribute'       => 'property',
    58         'label'           => 'Title',
    59         'description'     => 'If left blank, the post title will be used. If that does not exist, the site title will be used.',
    60         'get_value'       => function () {
    61             return Utilities::get_processed_value(
    62                 'og:title',
    63                 array(
    64                     Utilities::get_post_option( 'og:title' ),
    65                     get_the_title(),
    66                     Utilities::get_option( 'og:title' ),
    67                     get_bloginfo( 'name' ),
    68                 ),
    69                 array( 2, 3 )
    70             );
    71         },
    72     ],
    73     'og:type'             => [
    74         'is_configurable' => true,
    75         'field_type'      => 'text',
    76         'attribute'       => 'property',
    77         'label'           => 'Type',
    78         'description'     => 'If left blank, the global \'type\' will be used. If you choose to override it, make sure it follows the correct <a href="https://developers.facebook.com/docs/reference/opengraph/" target="_blank">object type formatting</a>.',
    79         'get_value'       => function () {
    80             Utilities::get_processed_value(
    81                 'og:type',
    82                 array(
    83                     Utilities::get_post_option( 'og:type' ),
    84                     is_single() ? 'article' : '',
    85                     Utilities::get_option( 'og:type' ),
    86                     'website',
    87                 ),
    88                 array( 2, 3 )
    89             );
    90         },
    91     ],
    92     'og:image'            => $image       = [
    93         'is_configurable' => false,
    94         'attribute'       => 'property',
    95         'label'           => 'Image',
    96         'description'     => 'If left empty, the post\'s featured image will be used. If no featured image exists, the front page featured image will be used.',
    97         'get_value'       => function () use ( $frontPageID ) {
    98             return Utilities::get_processed_value(
    99                 'og:image',
    100                 array(
    101                     Utilities::get_post_option( 'og:image' ),
    102                     get_post_thumbnail_id( Utilities::get_post_decorator()->ID ),
    103                     Utilities::get_first_image(),
    104                     Utilities::get_option( 'og:image' ),
    105                     ! empty( $frontPageID ) && has_post_thumbnail( $frontPageID )
    106                         ? get_post_thumbnail_id( $frontPageID )
    107                         : false,
    108                 ),
    109                 array( 3, 4 )
    110             );
    111         },
    112     ],
    113     'og:image:width'      => [
    114         'attribute' => 'property',
    115     ],
    116     'og:image:height'     => [
    117         'attribute' => 'property',
    118     ],
    119     'twitter:card'        => [
    120         'label'           => 'Twitter Summary Card Type',
    121         'attribute'       => 'name',
    122         'is_configurable' => true,
    123         'field_type'      => 'select',
    124         'field_options'   => [
    125             'Summary'       => 'summary',
    126             'Large Summary' => 'summary_large_image',
    127             'App'           => 'app',
    128             'Player'        => 'player',
    129         ],
    130         'description'     => 'The type of Twitter card that will be generated for Open Graph. To learn about what these types mean, see <a target="_blank" href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards">Twitter\'s documentation</a>.',
    131         'get_value'       => function () {
    132             return Utilities::get_processed_value(
    133                 'twitter:card',
    134                 array(
    135                     Utilities::get_post_option( 'twitter:card' ),
    136                     Utilities::get_option( 'twitter:card' ),
    137                     'summary',
    138                 ),
    139                 array( 2 )
    140             );
    141         },
    142     ],
    143     'twitter:creator'     => [
    144         'label'           => 'Twitter Creator',
    145         'description'     => 'If left blank, the global value will be used. It doesn\'t matter if you include the \'@\' symbol.',
    146         'is_configurable' => true,
    147         'field_type'      => 'text',
    148         'attribute'       => 'name',
    149         'get_value'       => function () {
    150             return Utilities::get_processed_value(
    151                 'twitter:creator',
    152                 array(
    153                     Utilities::get_post_option( 'twitter:creator' ),
    154                     Utilities::get_option( 'twitter:creator' ),
    155                 )
    156             );
    157         },
    158     ],
    159     'twitter:site'        => [
    160         'attribute' => 'name',
    161         'get_value' => function () {
    162             return Utilities::get_option( 'twitter:site' );
    163         },
    164     ],
    165     'twitter:title'       => [
    166         'attribute' => 'name',
    167         'get_value' => $title['get_value'],
    168     ],
    169     'twitter:image'       => [
    170         'attribute' => 'name',
    171         'get_value' => $image['get_value'],
    172     ],
    173     'twitter:description' => [
    174         'is_configurable' => true,
    175         'label'           => 'Twitter Description',
    176         'field_type'      => 'text',
    177         'description'     => 'If left blank, the description will be used.',
    178         'attribute'       => 'property',
    179         'get_value'       => function () use ( $description ) {
    180             return Utilities::get_processed_value(
    181                 'twitter:description',
    182                 array(
    183                     Utilities::get_post_option( 'twitter:description' ),
    184                     Utilities::get_post_decorator()->post_excerpt,
    185                     Utilities::get_post_decorator()->post_content,
    186                     Utilities::get_option( 'twitter:description' ),
    187                     $description['get_value'](),
    188                 )
    189             );
    190         },
    191     ],
    192     'fb:admins'           => [
    193         'attribute' => 'property',
    194         'get_value' => function () {
    195             return Utilities::get_option( 'fb:admins' );
    196         },
    197     ],
    198     'fb:app_id'           => [
    199         'attribute' => 'property',
    200         'get_value' => function () {
    201             return Utilities::get_option( 'fb:app_id' );
    202         },
    203     ],
    204     'profile:first_name' => [
    205         'attribute' => 'property',
    206         'get_value' => function () {
    207             return is_author() ? get_the_author_meta( 'first_name' ) : "";
    208         }
    209     ],
    210     'profile:last_name' => [
    211         'attribute' => 'property',
    212         'get_value' => function () {
    213             return is_author() ? get_the_author_meta( 'last_name' ) : "";
    214         }
    215     ]
     8    'og:site_name'        => [
     9        'label'     => 'Site Name',
     10        'attribute' => 'property',
     11        'get_value' => function () {
     12            return get_bloginfo('name');
     13        },
     14    ],
     15    'og:url'              => [
     16        'attribute' => 'property',
     17        'get_value' => function () {
     18            return Utilities::get_processed_value(
     19                'og:url',
     20                array(
     21                    get_permalink(Utilities::get_post_decorator()->ID),
     22                    get_bloginfo('url'),
     23                ),
     24                array( 1 )
     25            );
     26        },
     27    ],
     28    'og:locale'           => [
     29        'attribute' => 'property',
     30        'get_value' => function () {
     31            return get_locale();
     32        },
     33    ],
     34    'og:description'      => $description = [
     35        'is_configurable' => true,
     36        'field_type'      => 'text',
     37        'attribute'       => 'property',
     38        'label'           => 'Description',
     39        'description'     => 'If left blank, the excerpt will be used. If no excerpt exists, the site description will be used.',
     40        'get_value'       => function () {
     41            return Utilities::get_processed_value(
     42                'og:description',
     43                array(
     44                    Utilities::get_post_option('og:description'),
     45                    Utilities::get_post_decorator()->post_excerpt,
     46                    Utilities::get_post_decorator()->post_content,
     47                    Utilities::get_option('og:description'),
     48                    get_bloginfo('description'),
     49                ),
     50                array( 3, 4 )
     51            );
     52        },
     53    ],
     54    'og:title'            => $title       = [
     55        'is_configurable' => true,
     56        'field_type'      => 'text',
     57        'attribute'       => 'property',
     58        'label'           => 'Title',
     59        'description'     => 'If left blank, the post title will be used. If that does not exist, the site title will be used.',
     60        'get_value'       => function () {
     61            return Utilities::get_processed_value(
     62                'og:title',
     63                array(
     64                    Utilities::get_post_option('og:title'),
     65                    get_the_title(),
     66                    Utilities::get_option('og:title'),
     67                    get_bloginfo('name'),
     68                ),
     69                array( 2, 3 )
     70            );
     71        },
     72    ],
     73    'og:type'             => [
     74        'is_configurable' => true,
     75        'field_type'      => 'text',
     76        'attribute'       => 'property',
     77        'label'           => 'Type',
     78        'description'     => 'If left blank, the global \'type\' will be used. If you choose to override it, make sure it follows the correct <a href="https://developers.facebook.com/docs/reference/opengraph/" target="_blank">object type formatting</a>.',
     79        'get_value'       => function () {
     80            Utilities::get_processed_value(
     81                'og:type',
     82                array(
     83                    Utilities::get_post_option('og:type'),
     84                    is_single() ? 'article' : '',
     85                    Utilities::get_option('og:type'),
     86                    'website',
     87                ),
     88                array( 2, 3 )
     89            );
     90        },
     91    ],
     92    'og:image'            => $image       = [
     93        'is_configurable' => false,
     94        'attribute'       => 'property',
     95        'label'           => 'Image',
     96        'description'     => 'If left empty, the post\'s featured image will be used. If no featured image exists, the front page featured image will be used.',
     97        'get_value'       => function () use ($frontPageID) {
     98            return Utilities::get_processed_value(
     99                'og:image',
     100                array(
     101                    Utilities::get_post_option('og:image'),
     102                    get_post_thumbnail_id(Utilities::get_post_decorator()->ID),
     103                    Utilities::get_first_image(),
     104                    Utilities::get_option('og:image'),
     105                    ! empty($frontPageID) && has_post_thumbnail($frontPageID)
     106                        ? get_post_thumbnail_id($frontPageID)
     107                        : false,
     108                ),
     109                array( 3, 4 )
     110            );
     111        },
     112    ],
     113    'og:image:width'      => [
     114        'attribute' => 'property',
     115    ],
     116    'og:image:height'     => [
     117        'attribute' => 'property',
     118    ],
     119    'twitter:card'        => [
     120        'label'           => 'Twitter Summary Card Type',
     121        'attribute'       => 'name',
     122        'is_configurable' => true,
     123        'field_type'      => 'select',
     124        'field_options'   => [
     125            'Summary'       => 'summary',
     126            'Large Summary' => 'summary_large_image',
     127            'App'           => 'app',
     128            'Player'        => 'player',
     129        ],
     130        'description'     => 'The type of Twitter card that will be generated for Open Graph. To learn about what these types mean, see <a target="_blank" href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards">Twitter\'s documentation</a>.',
     131        'get_value'       => function () {
     132            return Utilities::get_processed_value(
     133                'twitter:card',
     134                array(
     135                    Utilities::get_post_option('twitter:card'),
     136                    Utilities::get_option('twitter:card'),
     137                    'summary',
     138                ),
     139                array( 2 )
     140            );
     141        },
     142    ],
     143    'twitter:creator'     => [
     144        'label'           => 'Twitter Creator',
     145        'description'     => 'If left blank, the global value will be used. It doesn\'t matter if you include the \'@\' symbol.',
     146        'is_configurable' => true,
     147        'field_type'      => 'text',
     148        'attribute'       => 'name',
     149        'get_value'       => function () {
     150            return Utilities::get_processed_value(
     151                'twitter:creator',
     152                array(
     153                    Utilities::get_post_option('twitter:creator'),
     154                    Utilities::get_option('twitter:creator'),
     155                )
     156            );
     157        },
     158    ],
     159    'twitter:site'        => [
     160        'attribute' => 'name',
     161        'get_value' => function () {
     162            return Utilities::get_option('twitter:site');
     163        },
     164    ],
     165    'twitter:title'       => [
     166        'attribute' => 'name',
     167        'get_value' => $title['get_value'],
     168    ],
     169    'twitter:image'       => [
     170        'attribute' => 'name',
     171        'get_value' => $image['get_value'],
     172    ],
     173    'twitter:description' => [
     174        'is_configurable' => true,
     175        'label'           => 'Twitter Description',
     176        'field_type'      => 'text',
     177        'description'     => 'If left blank, the description will be used.',
     178        'attribute'       => 'property',
     179        'get_value'       => function () use ($description) {
     180            return Utilities::get_processed_value(
     181                'twitter:description',
     182                array(
     183                    Utilities::get_post_option('twitter:description'),
     184                    Utilities::get_post_decorator()->post_excerpt,
     185                    Utilities::get_post_decorator()->post_content,
     186                    Utilities::get_option('twitter:description'),
     187                    $description['get_value'](),
     188                )
     189            );
     190        },
     191    ],
     192    'fb:admins'           => [
     193        'attribute' => 'property',
     194        'get_value' => function () {
     195            return Utilities::get_option('fb:admins');
     196        },
     197    ],
     198    'fb:app_id'           => [
     199        'attribute' => 'property',
     200        'get_value' => function () {
     201            return Utilities::get_option('fb:app_id');
     202        },
     203    ],
     204    'profile:first_name' => [
     205        'attribute' => 'property',
     206        'get_value' => function () {
     207            return is_author() ? get_the_author_meta('first_name') : "";
     208        }
     209    ],
     210    'profile:last_name' => [
     211        'attribute' => 'property',
     212        'get_value' => function () {
     213            return is_author() ? get_the_author_meta('last_name') : "";
     214        }
     215    ]
    216216];
  • complete-open-graph/trunk/src/hooks/content-filters.php

    r2016610 r2017039  
    88namespace CompleteOpenGraph;
    99
    10 add_filter( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter:description', 'CompleteOpenGraph\append_space_after_period', 10, 2 );
    11 add_filter( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_og:description', 'CompleteOpenGraph\append_space_after_period', 10, 2 );
    12 add_filter( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter:site', 'CompleteOpenGraph\append_at_symbol', 10, 2 );
    13 add_filter( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter:creator', 'CompleteOpenGraph\append_at_symbol', 10, 2 );
    14 add_filter( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_og:image', 'CompleteOpenGraph\attach_image_dimensions', 10, 2 );
    15 add_filter( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter:image', 'CompleteOpenGraph\attach_image_dimensions', 10, 2 );
     10add_filter(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter:description', 'CompleteOpenGraph\append_space_after_period', 10, 2);
     11add_filter(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_og:description', 'CompleteOpenGraph\append_space_after_period', 10, 2);
     12add_filter(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter:site', 'CompleteOpenGraph\append_at_symbol', 10, 2);
     13add_filter(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter:creator', 'CompleteOpenGraph\append_at_symbol', 10, 2);
     14add_filter(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_og:image', 'CompleteOpenGraph\attach_image_dimensions', 10, 2);
     15add_filter(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter:image', 'CompleteOpenGraph\attach_image_dimensions', 10, 2);
    1616
    1717/**
     
    2222 * @return string
    2323 */
    24 function attach_image_dimensions( $value, $field_name ) {
     24function attach_image_dimensions($value, $field_name)
     25{
    2526
    26     // -- This is probably a URL from an older version of the plugin. Just return it.
    27     if ( ! is_numeric( $value ) ) {
    28         return $value;
    29     }
     27    // -- This is probably a URL from an older version of the plugin. Just return it.
     28    if (! is_numeric($value)) {
     29        return $value;
     30    }
    3031
    31     $image_sizes = array(
    32         'complete_open_graph',
    33         'large',
    34         'medium_large',
    35         'medium',
    36         'full',
    37     );
     32    $image_sizes = array(
     33        'complete_open_graph',
     34        'large',
     35        'medium_large',
     36        'medium',
     37        'full',
     38    );
    3839
    39     $data            = false;
    40     $attachment_meta = wp_get_attachment_metadata( $value );
    41     $sizes           = isset( $attachment_meta['sizes'] ) ? $attachment_meta['sizes'] : array();
     40    $data            = false;
     41    $attachment_meta = wp_get_attachment_metadata($value);
     42    $sizes           = isset($attachment_meta['sizes']) ? $attachment_meta['sizes'] : array();
    4243
    43     // -- The 'full' size isn't included by default.
    44     $sizes['full'] = true;
     44    // -- The 'full' size isn't included by default.
     45    $sizes['full'] = true;
    4546
    46     // -- Loop over each image size. Serves as a fallback mechanism if it doesn't exist at the ideal size.
    47     foreach ( $image_sizes as $size ) {
     47    // -- Loop over each image size. Serves as a fallback mechanism if it doesn't exist at the ideal size.
     48    foreach ($image_sizes as $size) {
     49        // -- We have an image!
     50        if (array_key_exists($size, $sizes)) {
     51            $data = wp_get_attachment_image_src($value, $size);
     52            break;
     53        }
     54    }
    4855
    49         // -- We have an image!
    50         if ( array_key_exists( $size, $sizes ) ) {
    51             $data = wp_get_attachment_image_src( $value, $size );
    52             break;
    53         }
    54     }
     56    // -- If, for some reason, no image is returned, exit. Should NEVER actually happen, but you know... #WordPress.
     57    if (empty($data)) {
     58        return '';
     59    }
    5560
    56     // -- If, for some reason, no image is returned, exit. Should NEVER actually happen, but you know... #WordPress.
    57     if ( empty( $data ) ) {
    58         return '';
    59     }
     61    $value  = $data[0];
     62    $width  = $data[1];
     63    $height = $data[2];
    6064
    61     $value  = $data[0];
    62     $width  = $data[1];
    63     $height = $data[2];
     65    // -- Set image sizes.
     66    add_filter(
     67        COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_og:image:width',
     68        function ($value, $key) use ($width) {
     69            return $width;
     70        },
     71        10,
     72        2
     73    );
    6474
    65     // -- Set image sizes.
    66     add_filter(
    67         COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_og:image:width',
    68         function ( $value, $key ) use ( $width ) {
    69             return $width;
    70         },
    71         10,
    72         2
    73     );
     75    add_filter(
     76        COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_og:image:height',
     77        function ($value, $key) use ($height) {
     78            return $height;
     79        },
     80        10,
     81        2
     82    );
    7483
    75     add_filter(
    76         COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_og:image:height',
    77         function ( $value, $key ) use ( $height ) {
    78             return $height;
    79         },
    80         10,
    81         2
    82     );
    83 
    84     return $value;
     84    return $value;
    8585}
    8686
     
    9292 * @return  array
    9393 */
    94 function append_at_symbol( $value, $field_name = '' ) {
    95     return preg_replace( '/^[^@]/', '@$0', trim( $value ) );
     94function append_at_symbol($value, $field_name = '')
     95{
     96    return preg_replace('/^[^@]/', '@$0', trim($value));
    9697}
    9798
     
    103104 * @return string
    104105 */
    105 function append_space_after_period( $value, $field_name = '' ) {
    106     return preg_replace( '/(\.|\?|\!)$/', '$1 ', $value );
     106function append_space_after_period($value, $field_name = '')
     107{
     108    return preg_replace('/(\.|\?|\!)$/', '$1 ', $value);
    107109}
    108 
  • complete-open-graph/trunk/src/hooks/generate-open-graph-markup.php

    r2016610 r2017039  
    88namespace CompleteOpenGraph;
    99
    10 add_action( 'wp_head', 'CompleteOpenGraph\generate_open_graph_markup' );
    11 add_filter( 'language_attributes', 'CompleteOpenGraph\add_open_graph_prefix', 10, 2 );
     10add_action('wp_head', 'CompleteOpenGraph\generate_open_graph_markup');
     11add_filter('language_attributes', 'CompleteOpenGraph\add_open_graph_prefix', 10, 2);
    1212
    1313/**
     
    1616 * @return void
    1717 */
    18 function generate_open_graph_markup() {
     18function generate_open_graph_markup()
     19{
    1920
    20     if ( ! apply_filters( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_maybe_enable', true ) ) {
    21         return;
    22     }
     21    if (! apply_filters(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_maybe_enable', true)) {
     22        return;
     23    }
    2324
    24     echo "\n\n<!-- Open Graph data is managed by Alex MacArthur's Complete Open Graph plugin. (v" . COMPLETE_OPEN_GRAPH_PLUGIN_DATA['Version'] . ") -->\n";
    25     echo "<!-- https://wordpress.org/plugins/complete-open-graph/ -->\n";
     25    echo "\n\n<!-- Open Graph data is managed by Alex MacArthur's Complete Open Graph plugin. (v" . App::getPluginData()['Version'] . ") -->\n";
     26    echo "<!-- https://wordpress.org/plugins/complete-open-graph/ -->\n";
    2627
    27     $start_time = microtime( true );
     28    $start_time = microtime(true);
    2829
    29     foreach ( Generator::getOpenGraphValues() as $key => $data ) {
     30    foreach (Generator::getOpenGraphValues() as $key => $data) {
     31        if (empty($data['value'])) {
     32            continue;
     33        }
    3034
    31         if ( empty( $data['value'] ) ) {
    32             continue;
    33         }
     35        // -- @todo Move this into process_content?
     36        $content = preg_replace("/\r|\n/", '', $data['value']);
     37        $content = htmlentities($content, ENT_QUOTES, 'UTF-8', false);
    3438
    35         // -- @todo Move this into process_content?
    36         $content = preg_replace( "/\r|\n/", '', $data['value'] );
    37         $content = htmlentities( $content, ENT_QUOTES, 'UTF-8', false );
     39        if ($data['attribute'] === 'property') {
     40            echo "<meta property='$key' content='$content' />\n";
     41            continue;
     42        }
    3843
    39         if ( $data['attribute'] === 'property' ) {
    40             echo "<meta property='$key' content='$content' />\n";
    41             continue;
    42         }
     44        if ($data['attribute'] === 'name') {
     45            echo "<meta name='$key' content='$content' />\n";
     46            continue;
     47        }
     48    }
    4349
    44         if ( $data['attribute'] === 'name' ) {
    45             echo "<meta name='$key' content='$content' />\n";
    46             continue;
    47         }
    48     }
    49 
    50     echo '<!-- End Complete Open Graph. | ' . ( microtime( true ) - $start_time ) . "s -->\n\n";
     50    echo '<!-- End Complete Open Graph. | ' . ( microtime(true) - $start_time ) . "s -->\n\n";
    5151}
    5252
     
    5757 * @param string $doctype The type of html document (xhtml|html).
    5858 */
    59 function add_open_graph_prefix( $output, $doctype ) {
    60     if ( ! apply_filters( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_maybe_enable', true ) ) {
    61         return $output;
    62     }
     59function add_open_graph_prefix($output, $doctype)
     60{
     61    if (! apply_filters(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_maybe_enable', true)) {
     62        return $output;
     63    }
    6364
    64     return $output . ' prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# website: http://ogp.me/ns/website#"';
     65    return $output . ' prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# website: http://ogp.me/ns/website#"';
    6566}
  • complete-open-graph/trunk/src/hooks/metabox.php

    r2016610 r2017039  
    33namespace CompleteOpenGraph;
    44
    5 add_action( 'add_meta_boxes', 'CompleteOpenGraph\register_meta_box' );
    6 add_action( 'save_post', 'CompleteOpenGraph\save' );
     5add_action('add_meta_boxes', 'CompleteOpenGraph\register_meta_box');
     6add_action('save_post', 'CompleteOpenGraph\save');
    77
    88/**
    99 * Add meta box for the post. Only display on post types that are publicly queryable.
    1010 */
    11 function register_meta_box() {
    12     $currentPostType = Utilities::get_current_post_type();
     11function register_meta_box()
     12{
     13    $currentPostType = Utilities::get_current_post_type();
    1314
    14     $queryablePostTypes = get_post_types(
    15         array(
    16             'publicly_queryable' => true,
    17         )
    18     );
     15    $queryablePostTypes = get_post_types(
     16        array(
     17            'publicly_queryable' => true,
     18        )
     19    );
    1920
    20     // -- Oddly enough, pages aren't publicly queryable by default, so this ensures they're counted.
    21     $queryablePostTypes['page'] = 'page';
     21    // -- Oddly enough, pages aren't publicly queryable by default, so this ensures they're counted.
     22    $queryablePostTypes['page'] = 'page';
    2223
    23     if ( ! in_array( $currentPostType, $queryablePostTypes ) ) {
    24         return;
    25     }
     24    if (! in_array($currentPostType, $queryablePostTypes)) {
     25        return;
     26    }
    2627
    27     add_meta_box( 'complete_open_graph_metabox', 'Open Graph Settings', 'CompleteOpenGraph\open_graph_metabox_cb', null, 'normal', 'low' );
     28    add_meta_box('complete_open_graph_metabox', 'Open Graph Settings', 'CompleteOpenGraph\open_graph_metabox_cb', null, 'normal', 'low');
    2829}
    2930
     
    3334 * @return void
    3435 */
    35 function open_graph_metabox_cb() {
    36     $post_type = get_post_type();
    37     wp_nonce_field( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce_verification', COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce' );
     36function open_graph_metabox_cb()
     37{
     38    $post_type = get_post_type();
     39    wp_nonce_field(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce_verification', COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce');
    3840
    39     $imageURL = wp_get_attachment_image_src( Utilities::get_post_option( 'og:image' ), 'medium' )[0];
     41    $imageURL = wp_get_attachment_image_src(Utilities::get_post_option('og:image'), 'medium')[0];
    4042
    41     ?>
    42         <p class="main-description">These fields will allow you to customize the open graph data for the page or post.</p>
     43    ?>
     44        <p class="main-description">These fields will allow you to customize the open graph data for the page or post.</p>
    4345
    44         <div id="cogMetaBox" class="COG-fieldsWrapper
    45         <?php
    46         if ( ! Utilities::get_post_option( 'og:image' ) ) :
    47             ?>
    48             has-no-image<?php endif; ?>">
     46        <div id="cogMetaBox" class="COG-fieldsWrapper
     47        <?php
     48        if (! Utilities::get_post_option('og:image')) :
     49            ?>
     50        <?php endif; ?>">
    4951
    50             <?php foreach ( Field::getConfigurable() as $field ) : ?>
     52            <?php foreach (Field::getConfigurable() as $field) : ?>
     53                <fieldset class="SK_Box">
     54                    <label for="<?php echo $field->id; ?>">
     55                        <?php echo $field->label; ?>
     56                    </label>
     57                    <p>
     58                        <?php echo $field->description; ?>
     59                    </p>
    5160
    52                 <fieldset class="SK_Box">
    53                     <label for="<?php echo $field->id; ?>">
    54                         <?php echo $field->label; ?>
    55                     </label>
    56                     <p>
    57                         <?php echo $field->description; ?>
    58                     </p>
     61                    <?php
    5962
    60                     <?php
     63                    switch ($field->field_type) {
     64                        case 'text':
     65                            ?>
     66                                <input type="text" value="<?php echo Utilities::get_post_option($field->key); ?>" name="<?php echo $field->name; ?>" id="<?php echo $field->id; ?>" />
     67                            <?php
     68                            break;
    6169
    62                     switch ( $field->field_type ) {
    63                         case 'text':
    64                             ?>
    65                                 <input type="text" value="<?php echo Utilities::get_post_option( $field->key ); ?>" name="<?php echo $field->name; ?>" id="<?php echo $field->id; ?>" />
    66                             <?php
    67                             break;
     70                        case 'select':
     71                            $cardValue = Utilities::get_post_option($field->key);
     72                            ?>
     73                                <select name="<?php echo $field->name; ?>" id="<?php echo $field->id; ?>">
     74                                    <?php foreach ($field->field_options as $label => $value) : ?>
     75                                        <option <?php selected($cardValue, $value); ?> value="<?php echo $value; ?>">
     76                                            <?php echo $label; ?>
     77                                        </option>
     78                                    <?php endforeach; ?>
     79                                </select>
     80                            <?php
     81                            break;
     82                    }
     83                    ?>
     84                </fieldset>
    6885
    69                         case 'select':
    70                             $cardValue = Utilities::get_post_option( $field->key );
    71                             ?>
    72                                 <select name="<?php echo $field->name; ?>" id="<?php echo $field->id; ?>">
    73                                     <?php foreach ( $field->field_options as $label => $value ) : ?>
    74                                         <option <?php selected( $cardValue, $value ); ?> value="<?php echo $value; ?>">
    75                                             <?php echo $label; ?>
    76                                         </option>
    77                                     <?php endforeach; ?>
    78                                 </select>
    79                             <?php
    80                             break;
    81                     }
    82                     ?>
    83                 </fieldset>
     86            <?php endforeach; ?>
    8487
    85             <?php endforeach; ?>
     88            <fieldset class="SK_Box">
     89                <span class="SK_Box-label">Image</span>
     90                <p>If left empty, the <?php echo $post_type; ?>'s featured image will be used. If no featured image exists, the front page featured image will be used.</p>
     91                <div class="SK_ImageHolder"
     92                    id="cogImageHolder"
     93                    style="background-image: url('<?php echo $imageURL; ?>')">
     94                    <span class="SK_ImageHolder-remove" id="ogRemoveImage">x</span>
     95                </div>
     96                <span class="howto" id="cogUploadedFileName"><?php echo basename($imageURL); ?></span>
     97                <div class="SK_Box-buttonWrapper">
     98                    <a class="button button-primary button-large" id="cogImageSelectButton">Choose Image</a>
     99                    <span>No image selected.</span>
     100                </div>
     101                <input type="hidden" value="<?php echo Utilities::get_post_option('og:image'); ?>" name="complete_open_graph_og:image" id="cogImage">
     102            </fieldset>
    86103
    87             <fieldset class="SK_Box">
    88                 <span class="SK_Box-label">Image</span>
    89                 <p>If left empty, the <?php echo $post_type; ?>'s featured image will be used. If no featured image exists, the front page featured image will be used.</p>
    90                 <div class="SK_ImageHolder"
    91                     id="cogImageHolder"
    92                     style="background-image: url('<?php echo $imageURL; ?>')">
    93                     <span class="SK_ImageHolder-remove" id="ogRemoveImage">x</span>
    94                 </div>
    95                 <span class="howto" id="cogUploadedFileName"><?php echo basename( $imageURL ); ?></span>
    96                 <div class="SK_Box-buttonWrapper">
    97                     <a class="button button-primary button-large" id="cogImageSelectButton">Choose Image</a>
    98                     <span>No image selected.</span>
    99                 </div>
    100                 <input type="hidden" value="<?php echo Utilities::get_post_option( 'og:image' ); ?>" name="complete_open_graph_og:image" id="cogImage">
    101             </fieldset>
    102 
    103         </div>
    104     <?php
     104        </div>
     105    <?php
    105106}
    106107
     
    111112 * @return mixed ID if the meta didn't exist, true/false if the update failed or succeeded.
    112113 */
    113 function save( $post_id ) {
     114function save($post_id)
     115{
    114116
    115     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
    116         return;
    117     }
     117    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
     118        return;
     119    }
    118120
    119     if (
    120         ! isset( $_POST[ COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce' ] ) ||
    121         ! wp_verify_nonce( $_POST[ COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce' ], COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce_verification' )
    122     ) {
    123         return;
    124     }
     121    if (! isset($_POST[ COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce' ]) ||
     122        ! wp_verify_nonce($_POST[ COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce' ], COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce_verification')
     123    ) {
     124        return;
     125    }
    125126
    126     unset( $_POST[ COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce' ] );
     127    unset($_POST[ COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_nonce' ]);
    127128
    128     if ( ! current_user_can( 'edit_posts' ) ) {
    129         return;
    130     }
     129    if (! current_user_can('edit_posts')) {
     130        return;
     131    }
    131132
    132     // -- Get ony the keys that matter.
    133     $cogFields = array_filter(
    134         $_POST,
    135         function ( $key ) {
    136             return substr( $key, 0, 19 ) === COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX;
    137         },
    138         ARRAY_FILTER_USE_KEY
    139     );
     133    // -- Get ony the keys that matter.
     134    $cogFields = array_filter(
     135        $_POST,
     136        function ($key) {
     137            return substr($key, 0, 19) === COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX;
     138        },
     139        ARRAY_FILTER_USE_KEY
     140    );
    140141
    141     // -- Make sure the image we're saving actually returns a real string.
    142     if ( isset( $_POST['complete_open_graph_image'] ) ) {
    143         $image     = $_POST['complete_open_graph_image'];
    144         $imagePath = get_attached_file( $image );
     142    // -- Make sure the image we're saving actually returns a real string.
     143    if (isset($_POST['complete_open_graph_image'])) {
     144        $image     = $_POST['complete_open_graph_image'];
     145        $imagePath = get_attached_file($image);
    145146
    146         if ( is_numeric( $image ) && ! file_exists( $imagePath ) ) {
    147             $_POST['complete_open_graph_image'] = '';
    148         }
    149     }
     147        if (is_numeric($image) && ! file_exists($imagePath)) {
     148            $_POST['complete_open_graph_image'] = '';
     149        }
     150    }
    150151
    151     // -- Cleanse new post meta.
    152     // -- @todo: Move this to a method & TEST.
    153     $newPostMeta = [];
    154     foreach ( $cogFields as $key => $value ) {
    155         $key                 = str_replace( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_', '', $key );
    156         $value               = esc_attr( $value );
    157         $newPostMeta[ $key ] = $value;
    158     }
     152    // -- Cleanse new post meta.
     153    // -- @todo: Move this to a method & TEST.
     154    $newPostMeta = [];
     155    foreach ($cogFields as $key => $value) {
     156        $key                 = str_replace(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_', '', $key);
     157        $value               = esc_attr($value);
     158        $newPostMeta[ $key ] = $value;
     159    }
    159160
    160     return update_post_meta( $post_id, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX, $newPostMeta );
     161    return update_post_meta($post_id, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX, $newPostMeta);
    161162}
  • complete-open-graph/trunk/src/hooks/settings.php

    r2016610 r2017039  
    33namespace CompleteOpenGraph;
    44
    5 add_action( 'admin_init', 'CompleteOpenGraph\ensure_attachment_exists', 1 );
    6 add_action( 'admin_init', 'CompleteOpenGraph\register_main_setting' );
    7 add_action( 'admin_init', 'CompleteOpenGraph\register_settings' );
    8 add_action( 'admin_init', 'CompleteOpenGraph\register_facebook_settings' );
    9 add_action( 'admin_init', 'CompleteOpenGraph\register_twitter_settings' );
    10 add_action( 'admin_menu', 'CompleteOpenGraph\open_graph_settings_page' );
    11 add_action( 'admin_enqueue_scripts', 'CompleteOpenGraph\enqueue_settings_page_media' );
     5add_action('admin_init', 'CompleteOpenGraph\ensure_attachment_exists', 1);
     6add_action('admin_init', 'CompleteOpenGraph\register_main_setting');
     7add_action('admin_init', 'CompleteOpenGraph\register_settings');
     8add_action('admin_init', 'CompleteOpenGraph\register_facebook_settings');
     9add_action('admin_init', 'CompleteOpenGraph\register_twitter_settings');
     10add_action('admin_menu', 'CompleteOpenGraph\open_graph_settings_page');
     11add_action('admin_enqueue_scripts', 'CompleteOpenGraph\enqueue_settings_page_media');
    1212
    1313/**
     
    1616 * @return void
    1717 */
    18 function enqueue_settings_page_media() {
    19     if ( ! isset( $_REQUEST['page'] ) || $_REQUEST['page'] !== 'complete-open-graph' ) {
    20         return;
    21     }
    22 
    23     wp_enqueue_media();
    24     wp_enqueue_script( 'media-upload' );
    25 }
    26 
    27 function ensure_attachment_exists() {
    28     if ( ! isset( $_POST['complete_open_graph'] ) || ! isset( $_POST['complete_open_graph']['og:image'] ) ) {
    29         return;
    30     }
    31 
    32     $image     = $_POST['complete_open_graph']['og:image'];
    33     $imagePath = get_attached_file( $image );
    34 
    35     if ( is_numeric( $image ) && ! file_exists( $imagePath ) ) {
    36         unset( $_POST['complete_open_graph']['og:image'] );
    37     }
     18function enqueue_settings_page_media()
     19{
     20    if (! isset($_REQUEST['page']) || $_REQUEST['page'] !== 'complete-open-graph') {
     21        return;
     22    }
     23
     24    wp_enqueue_media();
     25    wp_enqueue_script('media-upload');
     26}
     27
     28function ensure_attachment_exists()
     29{
     30    if (! isset($_POST['complete_open_graph']) || ! isset($_POST['complete_open_graph']['og:image'])) {
     31        return;
     32    }
     33
     34    $image     = $_POST['complete_open_graph']['og:image'];
     35    $imagePath = get_attached_file($image);
     36
     37    if (is_numeric($image) && ! file_exists($imagePath)) {
     38        unset($_POST['complete_open_graph']['og:image']);
     39    }
    3840}
    3941
     
    4345 * @return void
    4446 */
    45 function open_graph_settings_page() {
    46     add_submenu_page( 'options-general.php', 'Open Graph Settings', 'Open Graph', 'edit_posts', 'complete-open-graph', 'CompleteOpenGraph\open_graph_settings_page_cb' );
     47function open_graph_settings_page()
     48{
     49    add_submenu_page('options-general.php', 'Open Graph Settings', 'Open Graph', 'edit_posts', 'complete-open-graph', 'CompleteOpenGraph\open_graph_settings_page_cb');
    4750}
    4851
     
    5255 * @return void
    5356 */
    54 function open_graph_settings_page_cb() {
    55 
    56     $github_url    = 'https://github.com/alexmacarthur/wp-complete-open-graph';
    57     $wordpress_url = 'https://wordpress.org/support/plugin/complete-open-graph/reviews/?rate=5#new-post';
    58     $twitter_url   = 'https://twitter.com/intent/tweet?text=I%20highly%20recommend%20the%20Complete%20Open%20Graph%20%23WordPress%20plugin%20from%20%40amacarthur!%20https%3A//wordpress.org/plugins/complete-open-graph/';
    59 
    60     ?>
    61     <div
    62         id="cogSettingsPage"
    63         class="
    64             wrap
    65             <?php echo Utilities::get_option( 'og:image' ) ? '' : 'has-no-image '; ?>
    66             <?php echo Utilities::get_option( 'force_all' ) ? 'is-forcing-all ' : ''; ?>"
    67         >
    68         <h1>Complete Open Graph Settings</h1>
    69 
    70         <div id="poststuff">
    71             <div id="post-body" class="metabox-holder columns-2">
    72                 <div id="post-body-content" class="postbox-container">
    73                     <form method="post" action="options.php">
    74                         <?php wp_nonce_field( 'update-options' ); ?>
    75                         <?php
    76                             settings_fields( 'complete_open_graph_settings' );
    77                             do_settings_sections( COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG );
    78                             submit_button();
    79                         ?>
    80                     </form>
    81                 </div>
    82 
    83                 <div id="postbox-container-1" class="postbox-container">
    84 
    85                     <aside class="SK_SidebarBlock">
    86 
    87                         <h2>Support Complete Open Graph!</h2>
    88 
    89                         <ul class="SK_FeedbackList">
    90                             <li class="SK_FeedbackList-item SK_FeedbackItem">
    91                                 <a class="SK_FeedbackItem-link" title="Review on WordPress" href="<?php echo $wordpress_url; ?>" target="_blank" rel="noopener noreferrer">
    92                                     <?php echo file_get_contents( COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/assets/img/wordpress.svg.php' ); ?>
    93                                 </a>
    94                                 <span class="SK_FeedbackItem-text"><p><a href="<?php echo $wordpress_url; ?>">Leave a 5 Star Review</a></p></span>
    95                             </li>
    96                             <li class="SK_FeedbackList-item SK_FeedbackItem">
    97                                 <a class="SK_FeedbackItem-link SK_FeedbackItem-link--github" title="Star on Github" href="<?php echo $github_url; ?>" target="_blank" rel="noopener noreferrer">
    98                                     <?php echo file_get_contents( COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/assets/img/github.svg.php' ); ?>
    99                                 </a>
    100                                 <span class="SK_FeedbackItem-text"><p><a href="<?php echo $github_url; ?>">Star on GitHub</a></p></span>
    101                             </li>
    102                             <li class="SK_FeedbackList-item SK_FeedbackItem">
    103                                 <a class="SK_FeedbackItem-link" title="Tweet About It" href="<?php echo $twitter_url; ?>" target="_blank" rel="noopener noreferrer">
    104                                     <?php echo file_get_contents( COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/assets/img/twitter.svg.php' ); ?>
    105                                 </a>
    106                                 <span class="SK_FeedbackItem-text"><p><a href="<?php echo $twitter_url; ?>">Tweet About It</a></p></span>
    107                             </li>
    108                         </ul>
    109                     </aside>
    110                 </div>
    111             </div>
    112         </div>
    113     </div>
    114 
    115     <?php
     57function open_graph_settings_page_cb()
     58{
     59
     60    $github_url    = 'https://github.com/alexmacarthur/wp-complete-open-graph';
     61    $wordpress_url = 'https://wordpress.org/support/plugin/complete-open-graph/reviews/?rate=5#new-post';
     62    $twitter_url   = 'https://twitter.com/intent/tweet?text=I%20highly%20recommend%20the%20Complete%20Open%20Graph%20%23WordPress%20plugin%20from%20%40amacarthur!%20https%3A//wordpress.org/plugins/complete-open-graph/';
     63
     64    ?>
     65    <div
     66        id="cogSettingsPage"
     67        class="
     68            wrap
     69            <?php echo Utilities::get_option('og:image') ? '' : 'has-no-image '; ?>
     70            <?php echo Utilities::get_option('force_all') ? 'is-forcing-all ' : ''; ?>"
     71        >
     72        <h1>Complete Open Graph Settings</h1>
     73
     74        <div id="poststuff">
     75            <div id="post-body" class="metabox-holder columns-2">
     76                <div id="post-body-content" class="postbox-container">
     77                    <form method="post" action="options.php">
     78                        <?php wp_nonce_field('update-options'); ?>
     79                        <?php
     80                            settings_fields('complete_open_graph_settings');
     81                            do_settings_sections(COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG);
     82                            submit_button();
     83                        ?>
     84                    </form>
     85                </div>
     86
     87                <div id="postbox-container-1" class="postbox-container">
     88
     89                    <aside class="SK_SidebarBlock">
     90
     91                        <h2>Support Complete Open Graph!</h2>
     92
     93                        <ul class="SK_FeedbackList">
     94                            <li class="SK_FeedbackList-item SK_FeedbackItem">
     95                                <a class="SK_FeedbackItem-link" title="Review on WordPress" href="<?php echo $wordpress_url; ?>" target="_blank" rel="noopener noreferrer">
     96                                    <?php echo file_get_contents(COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/assets/img/wordpress.svg.php'); ?>
     97                                </a>
     98                                <span class="SK_FeedbackItem-text"><p><a href="<?php echo $wordpress_url; ?>">Leave a 5 Star Review</a></p></span>
     99                            </li>
     100                            <li class="SK_FeedbackList-item SK_FeedbackItem">
     101                                <a class="SK_FeedbackItem-link SK_FeedbackItem-link--github" title="Star on Github" href="<?php echo $github_url; ?>" target="_blank" rel="noopener noreferrer">
     102                                    <?php echo file_get_contents(COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/assets/img/github.svg.php'); ?>
     103                                </a>
     104                                <span class="SK_FeedbackItem-text"><p><a href="<?php echo $github_url; ?>">Star on GitHub</a></p></span>
     105                            </li>
     106                            <li class="SK_FeedbackList-item SK_FeedbackItem">
     107                                <a class="SK_FeedbackItem-link" title="Tweet About It" href="<?php echo $twitter_url; ?>" target="_blank" rel="noopener noreferrer">
     108                                    <?php echo file_get_contents(COMPLETE_OPEN_GRAPH_REAL_PATH . 'src/assets/img/twitter.svg.php'); ?>
     109                                </a>
     110                                <span class="SK_FeedbackItem-text"><p><a href="<?php echo $twitter_url; ?>">Tweet About It</a></p></span>
     111                            </li>
     112                        </ul>
     113                    </aside>
     114                </div>
     115            </div>
     116        </div>
     117    </div>
     118
     119    <?php
    116120}
    117121
     
    121125 * @return void
    122126 */
    123 function register_main_setting() {
    124     register_setting( 'complete_open_graph_settings', COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX );
     127function register_main_setting()
     128{
     129    register_setting('complete_open_graph_settings', COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX);
    125130}
    126131
     
    130135 * @return void
    131136 */
    132 function register_facebook_settings() {
    133     add_settings_section( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_facebook_parameters', 'Facebook Parameters', 'CompleteOpenGraph\cb_facebook_parameters_section', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG );
    134     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_facebook_admin_ids', 'Facebook Admin IDs', 'CompleteOpenGraph\cb_field_facebook_admin_ids', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_facebook_parameters' );
    135     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_facebook_app_id', 'Facebook App ID', 'CompleteOpenGraph\cb_field_facebook_app_id', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_facebook_parameters' );
     137function register_facebook_settings()
     138{
     139    add_settings_section(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_facebook_parameters', 'Facebook Parameters', 'CompleteOpenGraph\cb_facebook_parameters_section', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG);
     140    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_facebook_admin_ids', 'Facebook Admin IDs', 'CompleteOpenGraph\cb_field_facebook_admin_ids', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_facebook_parameters');
     141    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_facebook_app_id', 'Facebook App ID', 'CompleteOpenGraph\cb_field_facebook_app_id', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_facebook_parameters');
    136142}
    137143
     
    142148 * @return void
    143149 */
    144 function register_twitter_settings() {
    145     add_settings_section( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters', 'Twitter Parameters', 'CompleteOpenGraph\cb_twitter_parameters_section', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG );
    146     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_twitter_card', 'Default Twitter Card', 'CompleteOpenGraph\cb_field_twitter_card', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters' );
    147     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_twitter_description', 'Default Twitter Description', 'CompleteOpenGraph\cb_field_twitter_description', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters' );
    148     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_twitter_creator', 'Default Twitter Creator', 'CompleteOpenGraph\cb_field_twitter_creator', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters' );
    149     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_twitter_site', 'Default Twitter Site', 'CompleteOpenGraph\cb_field_twitter_site', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters' );
     150function register_twitter_settings()
     151{
     152    add_settings_section(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters', 'Twitter Parameters', 'CompleteOpenGraph\cb_twitter_parameters_section', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG);
     153    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_twitter_card', 'Default Twitter Card', 'CompleteOpenGraph\cb_field_twitter_card', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters');
     154    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_twitter_description', 'Default Twitter Description', 'CompleteOpenGraph\cb_field_twitter_description', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters');
     155    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_twitter_creator', 'Default Twitter Creator', 'CompleteOpenGraph\cb_field_twitter_creator', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters');
     156    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_twitter_site', 'Default Twitter Site', 'CompleteOpenGraph\cb_field_twitter_site', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_twitter_parameters');
    150157}
    151158
     
    155162 * @return void
    156163 */
    157 function register_settings() {
    158     add_settings_section( COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks', 'Default Fallbacks', 'CompleteOpenGraph\cb_fallbacks_section', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG );
    159     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_force_all', 'Force All', 'CompleteOpenGraph\cb_field_force_all', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks' );
    160     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_type', 'Default Type', 'CompleteOpenGraph\cb_field_type', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks' );
    161     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_title', 'Default Title', 'CompleteOpenGraph\cb_field_title', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks' );
    162     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_description', 'Default Description', 'CompleteOpenGraph\cb_field_description', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks' );
    163     add_settings_field( COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_image', 'Default Image', 'CompleteOpenGraph\cb_field_image', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks' );
     164function register_settings()
     165{
     166    add_settings_section(COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks', 'Default Fallbacks', 'CompleteOpenGraph\cb_fallbacks_section', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG);
     167    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_force_all', 'Force All', 'CompleteOpenGraph\cb_field_force_all', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks');
     168    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_type', 'Default Type', 'CompleteOpenGraph\cb_field_type', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks');
     169    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_title', 'Default Title', 'CompleteOpenGraph\cb_field_title', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks');
     170    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_description', 'Default Description', 'CompleteOpenGraph\cb_field_description', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks');
     171    add_settings_field(COMPLETE_OPEN_GRAPH_OPTIONS_SHORT_PREFIX . '_image', 'Default Image', 'CompleteOpenGraph\cb_field_image', COMPLETE_OPEN_GRAPH_ADMIN_SETTINGS_PAGE_SLUG, COMPLETE_OPEN_GRAPH_OPTIONS_PREFIX . '_fallbacks');
    164172}
    165173
     
    170178 * @return string
    171179 */
    172 function checked( $key ) {
    173     return Utilities::get_option( $key ) === 'on' ? 'checked' : '';
     180function checked($key)
     181{
     182    return Utilities::get_option($key) === 'on' ? 'checked' : '';
    174183}
    175184
     
    179188 * @return void
    180189 */
    181 function cb_fallbacks_section() {
    182     echo '<p>These settings will serve as fallbacks in case individual pages/posts do not have information supplied. If you wish to force these values to always override individual posts/pages, check the box under each option.</p>';
     190function cb_fallbacks_section()
     191{
     192    echo '<p>These settings will serve as fallbacks in case individual pages/posts do not have information supplied. If you wish to force these values to always override individual posts/pages, check the box under each option.</p>';
    183193}
    184194
     
    188198 * @return void
    189199 */
    190 function cb_facebook_parameters_section() {
    191     echo '<p>Optionally modify Default / fallback settings for Facebook-related tags, including those that tie your site to a partiular Facebook page or account.</p>';
     200function cb_facebook_parameters_section()
     201{
     202    echo '<p>Optionally modify Default / fallback settings for Facebook-related tags, including those that tie your site to a partiular Facebook page or account.</p>';
    192203}
    193204
     
    197208 * @return void
    198209 */
    199 function cb_twitter_parameters_section() {
    200     echo '<p>Optionally modify global/fallback settings for Twitter-related Open Graph tags.</p>';
    201 }
    202 
    203 /**
    204  * Outputs field markup.
    205  *
    206  * @return void
    207  */
    208 function cb_field_type() {
    209     ?>
    210     <fieldset class="SK_Box SK_Box--standOut">
    211         <p>If left blank, 'website' will be used.</p>
    212         <input type="text" value="<?php echo Utilities::get_option( 'og:type' ); ?>" name="<?php echo Utilities::get_field_name( 'og:type' ); ?>" id="ogType" />
    213 
    214         <div class="SK_Box-checkboxGroup">
    215             <input type="checkbox" <?php echo \CompleteOpenGraph\checked( 'og:type_force' ); ?> name="<?php echo Utilities::get_field_name( 'og:type_force' ); ?>" id="ogTypeForce">
    216             <label for="ogTypeForce">Force Default Type</label>
    217             <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
    218         </div>
    219 
    220     </fieldset>
    221     <?php
    222 }
    223 
    224 /**
    225  * Outputs field markup.
    226  *
    227  * @return void
    228  */
    229 function cb_field_force_all() {
    230     ?>
    231     <fieldset class="SK_Box SK_Box--standOut SK_Box--important">
    232         <p><strong>Pay attention!</strong> Checking this box will force all of the values from the fields here to be applied universally. Only check this if you want your Open Graph data to be completely uniform throughout your site.</p>
    233 
    234         <div class="SK_Box-checkboxGroup is-immune">
    235             <input type="checkbox" <?php echo \CompleteOpenGraph\checked( 'force_all' ); ?> name="<?php echo Utilities::get_field_name( 'force_all' ); ?>" id="ogForceAll">
    236             <label for="ogForceAll"><strong>Force All Fallback Settings</strong></label>
    237             <span class="SK_Box-disclaimer">Checking this will force the values on this page to be used on very page, no matter what.</span>
    238         </div>
    239 
    240     </fieldset>
    241     <?php
    242 }
    243 
    244 /**
    245  * Outputs field markup.
    246  *
    247  * @return void
    248  */
    249 function cb_field_title() {
    250     ?>
    251     <fieldset class="SK_Box SK_Box--standOut">
    252         <p>If left blank, the site title will be used.</p>
    253         <input type="text" value="<?php echo Utilities::get_option( 'og:title' ); ?>" name="<?php echo Utilities::get_field_name( 'og:title' ); ?>" id="ogDescription" />
    254 
    255         <div class="SK_Box-checkboxGroup">
    256             <input type="checkbox" <?php echo \CompleteOpenGraph\checked( 'og:title_force' ); ?> name="<?php echo Utilities::get_field_name( 'og:title_force' ); ?>" id="ogTitleForce">
    257             <label for="ogTitleForce">Force Default Title</label>
    258             <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
    259         </div>
    260     </fieldset>
    261     <?php
    262 }
    263 
    264 /**
    265  * Outputs field markup.
    266  *
    267  * @return void
    268  */
    269 function cb_field_description() {
    270     ?>
    271     <fieldset class="SK_Box SK_Box--standOut">
    272         <p>If left blank, the site description will be used.</p>
    273         <input type="text" value="<?php echo Utilities::get_option( 'og:description' ); ?>" name="<?php echo Utilities::get_field_name( 'og:description' ); ?>" id="ogDescription" />
    274 
    275         <div class="SK_Box-checkboxGroup">
    276             <input type="checkbox" <?php echo \CompleteOpenGraph\checked( 'og:description_force' ); ?> name="<?php echo Utilities::get_field_name( 'og:description_force' ); ?>" id="ogDescriptionForce">
    277             <label for="ogDescriptionForce">Force Default Description</label>
    278             <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
    279         </div>
    280     </fieldset>
    281     <?php
    282 }
    283 
    284 /**
    285  * Outputs field markup.
    286  *
    287  * @return void
    288  */
    289 function cb_field_twitter_card() {
    290     ?>
    291     <fieldset class="SK_Box SK_Box--standOut">
    292         <p>The type of Twitter card that will be generated for Open Graph. To learn about what these types mean, see <a target="_blank" href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards">Twitter's documentation</a>.</p>
    293 
    294         <?php $cardValue = Utilities::get_option( 'twitter:card' ); ?>
    295 
    296         <select name="<?php echo Utilities::get_field_name( 'twitter:card' ); ?>" id="ogTwitterCard">
    297             <option <?php selected( $cardValue, 'summary' ); ?> value="summary">Summary</option>
    298             <option <?php selected( $cardValue, 'summary_large_image' ); ?> value="summary_large_image">Large Summary</option>
    299             <option <?php selected( $cardValue, 'app' ); ?> value="app">App</option>
    300             <option <?php selected( $cardValue, 'player' ); ?> value="player">Player</option>
    301         </select>
    302 
    303         <div class="SK_Box-checkboxGroup">
    304             <input type="checkbox" <?php echo \CompleteOpenGraph\checked( 'twitter:card_force' ); ?> name="<?php echo Utilities::get_field_name( 'twitter:card_force' ); ?>" id="ogTwitterCardForce">
    305             <label for="ogTwitterCardForce">Force Default Twitter Card</label>
    306             <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
    307         </div>
    308     </fieldset>
    309     <?php
    310 }
    311 
    312 /**
    313  * Outputs field markup.
    314  *
    315  * @return void
    316  */
    317 function cb_field_twitter_description() {
    318     ?>
    319     <fieldset class="SK_Box SK_Box--standOut">
    320         <p>If left blank, the description will be used.</p>
    321         <input type="text" value="<?php echo Utilities::get_option( 'twitter:description' ); ?>" name="<?php echo Utilities::get_field_name( 'twitter:description' ); ?>" id="ogTwitterDescription" />
    322 
    323         <div class="SK_Box-checkboxGroup">
    324             <input type="checkbox" <?php echo \CompleteOpenGraph\checked( 'twitter:description_force' ); ?> name="<?php echo Utilities::get_field_name( 'twitter:description_force' ); ?>" id="ogTwitterDescriptionForce">
    325             <label for="ogTwitterDescriptionForce">Force Default Twitter Description
    326             </label>
    327             <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
    328         </div>
    329     </fieldset>
    330     <?php
    331 }
    332 
    333 /**
    334  * Outputs field markup.
    335  *
    336  * @return void
    337  */
    338 function cb_field_twitter_creator() {
    339     ?>
    340     <fieldset class="SK_Box SK_Box--standOut">
    341         <p>Enter the Twitter handle for the primary author. If left blank, the tag will be omitted, unless it's set at the post/page level.</p>
    342         <input type="text" value="<?php echo Utilities::get_option( 'twitter:creator' ); ?>" name="<?php echo Utilities::get_field_name( 'twitter:creator' ); ?>" id="ogTwitterCreator" />
    343 
    344         <div class="SK_Box-checkboxGroup">
    345             <input type="checkbox" <?php echo \CompleteOpenGraph\checked( 'twitter:creator_force' ); ?> name="<?php echo Utilities::get_field_name( 'twitter:creator_force' ); ?>" id="ogTwitterCreatorForce">
    346             <label for="ogTwitterCreatorForce">Force Default Twitter Creator
    347             </label>
    348             <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
    349         </div>
    350     </fieldset>
    351     <?php
    352 }
    353 
    354 /**
    355  * Outputs field markup.
    356  *
    357  * @return void
    358  */
    359 function cb_field_twitter_site() {
    360     ?>
    361     <fieldset class="SK_Box SK_Box--standOut">
    362         <p>Enter the Twitter handle for the site itself. It doesn't matter if the '@' symbol is included. If left blank, the tag will be omitted.</p>
    363         <input type="text" value="<?php echo Utilities::get_option( 'twitter:site' ); ?>" name="<?php echo Utilities::get_field_name( 'twitter:site' ); ?>" id="ogTwitterSite" />
    364     </fieldset>
    365     <?php
    366 }
    367 
    368 /**
    369  * Outputs field markup.
    370  *
    371  * @return void
    372  */
    373 function cb_field_image() {
    374     $imageID = Utilities::get_option( 'og:image' );
    375 
    376     // -- Ensure the image exists before getting the URL.
    377     if ( empty( $imageID ) ) {
    378         $imageURL = '';
    379     } else {
    380         $imageAttachment = wp_get_attachment_image_src( $imageID, 'medium' );
    381         $imageURL        = isset( $imageAttachment[0] ) ? $imageAttachment[0] : '';
    382     }
    383 
    384     ?>
    385     <fieldset class="SK_Box SK_Box--standOut">
    386         <p>If left blank, the featured image on the home page will be used.</p>
    387         <div class="SK_ImageHolder"
    388             id="cogImageHolder"
    389             style="background-image: url('<?php echo $imageURL; ?>')">
    390             <span class="SK_ImageHolder-remove" id="ogRemoveImage">x</span>
    391         </div>
    392         <span class="howto" id="cogUploadedFileName"><?php echo basename( $imageURL ); ?></span>
    393         <div class="SK_Box-buttonWrapper">
    394             <a class="button button-primary button-large" id="cogImageSelectButton">Choose File</a>
    395             <span>No image selected.</span>
    396         </div>
    397         <input id="cogImage" type="hidden" name="<?php echo Utilities::get_field_name( 'og:image' ); ?>" value="<?php echo Utilities::get_option( 'og:image' ); ?>" />
    398 
    399         <div class="SK_Box-checkboxGroup">
    400             <input type="checkbox" <?php echo \CompleteOpenGraph\checked( 'og:image_force' ); ?> name="<?php echo Utilities::get_field_name( 'og:image_force' ); ?>" id="ogImageForce">
    401             <label for="ogImageForce">Force Default Image</label>
    402             <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
    403         </div>
    404     </fieldset>
    405     <?php
    406 }
    407 
    408 /**
    409  * Outputs field markup.
    410  *
    411  * @return void
    412  */
    413 function cb_field_facebook_app_id() {
    414     ?>
    415     <fieldset class="SK_Box SK_Box--standOut">
    416         <p>Enter the ID of the Facebook app you'd like to grant access to this URL.</p>
    417         <input type="text" value="<?php echo Utilities::get_option( 'fb:app_id' ); ?>" name="<?php echo Utilities::get_field_name( 'fb:app_id' ); ?>" id="ogFacebookAppID" />
    418     </fieldset>
    419     <?php
    420 }
    421 
    422 /**
    423  * Outputs field markup.
    424  *
    425  * @return void
    426  */
    427 function cb_field_facebook_admin_ids() {
    428     ?>
    429     <fieldset class="SK_Box SK_Box--standOut">
    430         <p>Enter the user ID of a person you'd like to give admin access to view insights about this URL.</p>
    431         <input type="text" value="<?php echo Utilities::get_option( 'fb:admins' ); ?>" name="<?php echo Utilities::get_field_name( 'fb:admins' ); ?>" id="ogFacebookAdminIDs" />
    432     </fieldset>
    433     <?php
    434 }
     210function cb_twitter_parameters_section()
     211{
     212    echo '<p>Optionally modify global/fallback settings for Twitter-related Open Graph tags.</p>';
     213}
     214
     215/**
     216 * Outputs field markup.
     217 *
     218 * @return void
     219 */
     220function cb_field_type()
     221{
     222    ?>
     223    <fieldset class="SK_Box SK_Box--standOut">
     224        <p>If left blank, 'website' will be used.</p>
     225        <input type="text" value="<?php echo Utilities::get_option('og:type'); ?>" name="<?php echo Utilities::get_field_name('og:type'); ?>" id="ogType" />
     226
     227        <div class="SK_Box-checkboxGroup">
     228            <input type="checkbox" <?php echo \CompleteOpenGraph\checked('og:type_force'); ?> name="<?php echo Utilities::get_field_name('og:type_force'); ?>" id="ogTypeForce">
     229            <label for="ogTypeForce">Force Default Type</label>
     230            <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
     231        </div>
     232
     233    </fieldset>
     234    <?php
     235}
     236
     237/**
     238 * Outputs field markup.
     239 *
     240 * @return void
     241 */
     242function cb_field_force_all()
     243{
     244    ?>
     245    <fieldset class="SK_Box SK_Box--standOut SK_Box--important">
     246        <p><strong>Pay attention!</strong> Checking this box will force all of the values from the fields here to be applied universally. Only check this if you want your Open Graph data to be completely uniform throughout your site.</p>
     247
     248        <div class="SK_Box-checkboxGroup is-immune">
     249            <input type="checkbox" <?php echo \CompleteOpenGraph\checked('force_all'); ?> name="<?php echo Utilities::get_field_name('force_all'); ?>" id="ogForceAll">
     250            <label for="ogForceAll"><strong>Force All Fallback Settings</strong></label>
     251            <span class="SK_Box-disclaimer">Checking this will force the values on this page to be used on very page, no matter what.</span>
     252        </div>
     253
     254    </fieldset>
     255    <?php
     256}
     257
     258/**
     259 * Outputs field markup.
     260 *
     261 * @return void
     262 */
     263function cb_field_title()
     264{
     265    ?>
     266    <fieldset class="SK_Box SK_Box--standOut">
     267        <p>If left blank, the site title will be used.</p>
     268        <input type="text" value="<?php echo Utilities::get_option('og:title'); ?>" name="<?php echo Utilities::get_field_name('og:title'); ?>" id="ogDescription" />
     269
     270        <div class="SK_Box-checkboxGroup">
     271            <input type="checkbox" <?php echo \CompleteOpenGraph\checked('og:title_force'); ?> name="<?php echo Utilities::get_field_name('og:title_force'); ?>" id="ogTitleForce">
     272            <label for="ogTitleForce">Force Default Title</label>
     273            <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
     274        </div>
     275    </fieldset>
     276    <?php
     277}
     278
     279/**
     280 * Outputs field markup.
     281 *
     282 * @return void
     283 */
     284function cb_field_description()
     285{
     286    ?>
     287    <fieldset class="SK_Box SK_Box--standOut">
     288        <p>If left blank, the site description will be used.</p>
     289        <input type="text" value="<?php echo Utilities::get_option('og:description'); ?>" name="<?php echo Utilities::get_field_name('og:description'); ?>" id="ogDescription" />
     290
     291        <div class="SK_Box-checkboxGroup">
     292            <input type="checkbox" <?php echo \CompleteOpenGraph\checked('og:description_force'); ?> name="<?php echo Utilities::get_field_name('og:description_force'); ?>" id="ogDescriptionForce">
     293            <label for="ogDescriptionForce">Force Default Description</label>
     294            <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
     295        </div>
     296    </fieldset>
     297    <?php
     298}
     299
     300/**
     301 * Outputs field markup.
     302 *
     303 * @return void
     304 */
     305function cb_field_twitter_card()
     306{
     307    ?>
     308    <fieldset class="SK_Box SK_Box--standOut">
     309        <p>The type of Twitter card that will be generated for Open Graph. To learn about what these types mean, see <a target="_blank" href="https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards">Twitter's documentation</a>.</p>
     310
     311        <?php $cardValue = Utilities::get_option('twitter:card'); ?>
     312
     313        <select name="<?php echo Utilities::get_field_name('twitter:card'); ?>" id="ogTwitterCard">
     314            <option <?php selected($cardValue, 'summary'); ?> value="summary">Summary</option>
     315            <option <?php selected($cardValue, 'summary_large_image'); ?> value="summary_large_image">Large Summary</option>
     316            <option <?php selected($cardValue, 'app'); ?> value="app">App</option>
     317            <option <?php selected($cardValue, 'player'); ?> value="player">Player</option>
     318        </select>
     319
     320        <div class="SK_Box-checkboxGroup">
     321            <input type="checkbox" <?php echo \CompleteOpenGraph\checked('twitter:card_force'); ?> name="<?php echo Utilities::get_field_name('twitter:card_force'); ?>" id="ogTwitterCardForce">
     322            <label for="ogTwitterCardForce">Force Default Twitter Card</label>
     323            <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
     324        </div>
     325    </fieldset>
     326    <?php
     327}
     328
     329/**
     330 * Outputs field markup.
     331 *
     332 * @return void
     333 */
     334function cb_field_twitter_description()
     335{
     336    ?>
     337    <fieldset class="SK_Box SK_Box--standOut">
     338        <p>If left blank, the description will be used.</p>
     339        <input type="text" value="<?php echo Utilities::get_option('twitter:description'); ?>" name="<?php echo Utilities::get_field_name('twitter:description'); ?>" id="ogTwitterDescription" />
     340
     341        <div class="SK_Box-checkboxGroup">
     342            <input type="checkbox" <?php echo \CompleteOpenGraph\checked('twitter:description_force'); ?> name="<?php echo Utilities::get_field_name('twitter:description_force'); ?>" id="ogTwitterDescriptionForce">
     343            <label for="ogTwitterDescriptionForce">Force Default Twitter Description
     344            </label>
     345            <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
     346        </div>
     347    </fieldset>
     348    <?php
     349}
     350
     351/**
     352 * Outputs field markup.
     353 *
     354 * @return void
     355 */
     356function cb_field_twitter_creator()
     357{
     358    ?>
     359    <fieldset class="SK_Box SK_Box--standOut">
     360        <p>Enter the Twitter handle for the primary author. If left blank, the tag will be omitted, unless it's set at the post/page level.</p>
     361        <input type="text" value="<?php echo Utilities::get_option('twitter:creator'); ?>" name="<?php echo Utilities::get_field_name('twitter:creator'); ?>" id="ogTwitterCreator" />
     362
     363        <div class="SK_Box-checkboxGroup">
     364            <input type="checkbox" <?php echo \CompleteOpenGraph\checked('twitter:creator_force'); ?> name="<?php echo Utilities::get_field_name('twitter:creator_force'); ?>" id="ogTwitterCreatorForce">
     365            <label for="ogTwitterCreatorForce">Force Default Twitter Creator
     366            </label>
     367            <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
     368        </div>
     369    </fieldset>
     370    <?php
     371}
     372
     373/**
     374 * Outputs field markup.
     375 *
     376 * @return void
     377 */
     378function cb_field_twitter_site()
     379{
     380    ?>
     381    <fieldset class="SK_Box SK_Box--standOut">
     382        <p>Enter the Twitter handle for the site itself. It doesn't matter if the '@' symbol is included. If left blank, the tag will be omitted.</p>
     383        <input type="text" value="<?php echo Utilities::get_option('twitter:site'); ?>" name="<?php echo Utilities::get_field_name('twitter:site'); ?>" id="ogTwitterSite" />
     384    </fieldset>
     385    <?php
     386}
     387
     388/**
     389 * Outputs field markup.
     390 *
     391 * @return void
     392 */
     393function cb_field_image()
     394{
     395    $imageID = Utilities::get_option('og:image');
     396
     397    // -- Ensure the image exists before getting the URL.
     398    if (empty($imageID)) {
     399        $imageURL = '';
     400    } else {
     401        $imageAttachment = wp_get_attachment_image_src($imageID, 'medium');
     402        $imageURL        = isset($imageAttachment[0]) ? $imageAttachment[0] : '';
     403    }
     404
     405    ?>
     406    <fieldset class="SK_Box SK_Box--standOut">
     407        <p>If left blank, the featured image on the home page will be used.</p>
     408        <div class="SK_ImageHolder"
     409            id="cogImageHolder"
     410            style="background-image: url('<?php echo $imageURL; ?>')">
     411            <span class="SK_ImageHolder-remove" id="ogRemoveImage">x</span>
     412        </div>
     413        <span class="howto" id="cogUploadedFileName"><?php echo basename($imageURL); ?></span>
     414        <div class="SK_Box-buttonWrapper">
     415            <a class="button button-primary button-large" id="cogImageSelectButton">Choose File</a>
     416            <span>No image selected.</span>
     417        </div>
     418        <input id="cogImage" type="hidden" name="<?php echo Utilities::get_field_name('og:image'); ?>" value="<?php echo Utilities::get_option('og:image'); ?>" />
     419
     420        <div class="SK_Box-checkboxGroup">
     421            <input type="checkbox" <?php echo \CompleteOpenGraph\checked('og:image_force'); ?> name="<?php echo Utilities::get_field_name('og:image_force'); ?>" id="ogImageForce">
     422            <label for="ogImageForce">Force Default Image</label>
     423            <span class="SK_Box-disclaimer">Checking this will force this value, no matter what.</span>
     424        </div>
     425    </fieldset>
     426    <?php
     427}
     428
     429/**
     430 * Outputs field markup.
     431 *
     432 * @return void
     433 */
     434function cb_field_facebook_app_id()
     435{
     436    ?>
     437    <fieldset class="SK_Box SK_Box--standOut">
     438        <p>Enter the ID of the Facebook app you'd like to grant access to this URL.</p>
     439        <input type="text" value="<?php echo Utilities::get_option('fb:app_id'); ?>" name="<?php echo Utilities::get_field_name('fb:app_id'); ?>" id="ogFacebookAppID" />
     440    </fieldset>
     441    <?php
     442}
     443
     444/**
     445 * Outputs field markup.
     446 *
     447 * @return void
     448 */
     449function cb_field_facebook_admin_ids()
     450{
     451    ?>
     452    <fieldset class="SK_Box SK_Box--standOut">
     453        <p>Enter the user ID of a person you'd like to give admin access to view insights about this URL.</p>
     454        <input type="text" value="<?php echo Utilities::get_option('fb:admins'); ?>" name="<?php echo Utilities::get_field_name('fb:admins'); ?>" id="ogFacebookAdminIDs" />
     455    </fieldset>
     456    <?php
     457}
  • complete-open-graph/trunk/src/hooks/support.php

    r2016610 r2017039  
    33namespace CompleteOpenGraph;
    44
    5 add_action( 'plugins_loaded', 'CompleteOpenGraph\add_og_image_size' );
    6 add_filter( 'image_size_names_choose', 'CompleteOpenGraph\add_og_image_size_to_uploader' );
     5add_action('plugins_loaded', 'CompleteOpenGraph\add_og_image_size');
     6add_filter('image_size_names_choose', 'CompleteOpenGraph\add_og_image_size_to_uploader');
    77
    88/**
     
    1111 * @return void
    1212 */
    13 function add_og_image_size() {
    14     add_theme_support( 'post-thumbnails' );
    15     add_image_size( 'complete_open_graph', 1200, 1200, false );
     13function add_og_image_size()
     14{
     15    add_theme_support('post-thumbnails');
     16    add_image_size('complete_open_graph', 1200, 1200, false);
    1617}
    1718
     
    2223 * @return array
    2324 */
    24 function add_og_image_size_to_uploader( $sizes ) {
    25     $sizes['complete_open_graph'] = __( 'Open Graph' );
    26     return $sizes;
     25function add_og_image_size_to_uploader($sizes)
     26{
     27    $sizes['complete_open_graph'] = __('Open Graph');
     28    return $sizes;
    2729}
Note: See TracChangeset for help on using the changeset viewer.