├── .dev-lib ├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .gitmodules ├── .jscsrc ├── .jshintignore ├── .jshintrc ├── .travis.yml ├── Gruntfile.js ├── composer.json ├── core-media-widgets.php ├── package.json ├── php └── class-media-widgets-wp-cli-command.php ├── phpcs.xml.dist ├── phpunit.xml.dist ├── readme.md ├── readme.txt ├── tests ├── phpunit │ ├── data │ │ ├── small-audio.mp3 │ │ └── small-video.mp4 │ ├── test-class-wp-widget-media-audio.php │ ├── test-class-wp-widget-media-gallery.php │ ├── test-class-wp-widget-media-image.php │ ├── test-class-wp-widget-media-video.php │ └── test-class-wp-widget-media.php └── qunit │ ├── index.html │ ├── test-media-gallery-widget.js │ ├── test-media-image-widget.js │ ├── test-media-video-widget.js │ ├── test-media-widgets.js │ └── test-suite.template ├── wp-admin ├── css │ └── widgets │ │ ├── media-gallery-widget.css │ │ └── media-widgets.css └── js │ └── widgets │ ├── media-audio-widget.js │ ├── media-gallery-widget.js │ ├── media-image-widget.js │ ├── media-video-widget.js │ ├── media-widgets.js │ └── text-widgets.js └── wp-includes ├── js └── customize-selective-refresh-extras.js └── widgets ├── class-wp-widget-media-audio.php ├── class-wp-widget-media-gallery.php ├── class-wp-widget-media-image.php ├── class-wp-widget-media-video.php ├── class-wp-widget-media.php └── class-wp-widget-visual-text.php /.dev-lib: -------------------------------------------------------------------------------- 1 | CHECK_SCOPE=changed-files 2 | PHPCS_RULESET_FILE=phpcs.xml.dist 3 | WPCS_BRANCH=develop 4 | PHPCS_PHAR_URL=https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.9.0/phpcs.phar 5 | 6 | if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then 7 | DEV_LIB_SKIP="$DEV_LIB_SKIP,phpcs" 8 | fi 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | dev-lib/.editorconfig -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dev-lib/.eslintignore -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true 4 | }, 5 | "globals": { 6 | "_": false, 7 | "Backbone": false, 8 | "jQuery": false, 9 | "wp": false 10 | }, 11 | "rules": { 12 | "accessor-pairs": [2], 13 | "block-scoped-var": [2], 14 | "callback-return": [2], 15 | "complexity": [2, 8], 16 | "consistent-return": [2], 17 | "consistent-this": [2, "self"], 18 | "constructor-super": [2], 19 | "default-case": [2], 20 | "eqeqeq": [2], 21 | "func-style": [0], 22 | "global-require": [2], 23 | "guard-for-in": [0], 24 | "handle-callback-err": [2, "^err(or)?$"], 25 | "id-length": [0], 26 | "id-match": [0], 27 | "indent": ["error", "tab"], 28 | "init-declarations": [0], 29 | "max-depth": [2, 3], 30 | "max-nested-callbacks": [2, 3], 31 | "max-params": [2, 4], 32 | "max-statements": [0], 33 | "new-parens": [0], 34 | "no-alert": [2], 35 | "no-array-constructor": [0], 36 | "no-bitwise": [0], 37 | "no-caller": [2], 38 | "no-case-declarations": [2], 39 | "no-catch-shadow": [2], 40 | "no-class-assign": [2], 41 | "no-cond-assign": [2], 42 | "no-console": [0], 43 | "no-const-assign": [2], 44 | "no-constant-condition": [0], 45 | "no-continue": [0], 46 | "no-control-regex": [2], 47 | "no-debugger": [2], 48 | "no-delete-var": [2], 49 | "no-div-regex": [0], 50 | "no-dupe-args": [2], 51 | "no-dupe-class-members": [2], 52 | "no-dupe-keys": [2], 53 | "no-duplicate-case": [2], 54 | "no-else-return": [0], 55 | "no-empty-character-class": [2], 56 | "no-empty-pattern": [2], 57 | "no-empty": [2], 58 | "no-eq-null": [2], 59 | "no-eval": [2], 60 | "no-ex-assign": [2], 61 | "no-extend-native": [0], 62 | "no-extra-bind": [2], 63 | "no-extra-boolean-cast": [2], 64 | "no-extra-parens": [2], 65 | "no-extra-semi": [2], 66 | "no-fallthrough": [2], 67 | "no-floating-decimal": [2], 68 | "no-func-assign": [2], 69 | "no-implicit-coercion": [2], 70 | "no-implicit-globals": [0], 71 | "no-implied-eval": [2], 72 | "no-inline-comments": [0], 73 | "no-inner-declarations": [2], 74 | "no-invalid-regexp": [2], 75 | "no-invalid-this": [0], 76 | "no-irregular-whitespace": [2], 77 | "no-iterator": [2], 78 | "no-label-var": [2], 79 | "no-labels": [0], 80 | "no-lone-blocks": [2], 81 | "no-lonely-if": [2], 82 | "no-loop-func": [2], 83 | "no-magic-numbers": [2, { "ignoreArrayIndexes": true, "ignore": [ -1, 0, 1 ] }], 84 | "no-mixed-requires": [0], 85 | "no-multi-str": [2], 86 | "no-native-reassign": [2], 87 | "no-negated-condition": [0], 88 | "no-negated-in-lhs": [2], 89 | "no-nested-ternary": [0], 90 | "no-new-func": [0], 91 | "no-new-object": [2], 92 | "no-new-require": [0], 93 | "no-new-wrappers": [2], 94 | "no-new": [2], 95 | "no-obj-calls": [2], 96 | "no-octal-escape": [2], 97 | "no-octal": [2], 98 | "no-param-reassign": [2], 99 | "no-path-concat": [2], 100 | "no-plusplus": [0], 101 | "no-process-env": [2], 102 | "no-process-exit": [0], 103 | "no-proto": [2], 104 | "no-redeclare": [2], 105 | "no-regex-spaces": [0], 106 | "no-restricted-imports": [0], 107 | "no-restricted-syntax": [0], 108 | "no-return-assign": [2], 109 | "no-script-url": [0], 110 | "no-self-compare": [2], 111 | "no-sequences": [2], 112 | "no-shadow-restricted-names": [2], 113 | "no-shadow": [2], 114 | "no-sparse-arrays": [2], 115 | "no-sync": [0], 116 | "no-ternary": [0], 117 | "no-trailing-spaces": [2], 118 | "no-this-before-super": [2], 119 | "no-throw-literal": [2], 120 | "no-undef-init": [0], 121 | "no-undef": [2], 122 | "no-undefined": [0], 123 | "no-unneeded-ternary": [2], 124 | "no-unreachable": [2], 125 | "no-unused-expressions": [2], 126 | "no-unused-vars": [2], 127 | "no-use-before-define": [0], 128 | "no-useless-call": [2], 129 | "no-useless-concat": [2], 130 | "no-var": [0], 131 | "no-void": [0], 132 | "no-with": [2], 133 | "object-shorthand": [0], 134 | "one-var": [ 2, "always" ], 135 | "operator-assignment": [2, "always"], 136 | "prefer-arrow-callback": [0], 137 | "prefer-const": [0], 138 | "prefer-reflect": [0], 139 | "prefer-rest-params": [0], 140 | "prefer-spread": [0], 141 | "prefer-template": [0], 142 | "quotes": [0], 143 | "radix": [2, "always"], 144 | "require-jsdoc": [2, { 145 | "require": { 146 | "FunctionDeclaration": true, 147 | "MethodDefinition": true, 148 | "ClassDeclaration": true, 149 | "ArrowFunctionExpression": false 150 | } 151 | } ], 152 | "require-yield": [0], 153 | "sort-imports": [0], 154 | "sort-vars": [0], 155 | "strict": [2, "function"], 156 | "use-isnan": [2], 157 | "valid-typeof": [2], 158 | "valid-jsdoc": [2, { 159 | "prefer": { 160 | "arg": "param", 161 | "argument": "param", 162 | "class": "constructor", 163 | "return": "returns", 164 | "virtual": "abstract" 165 | }, 166 | "requireParamDescription": true, 167 | "requireReturnDescription": true, 168 | "requireReturn": true, 169 | "requireReturnType": true, 170 | "preferType": { 171 | "Boolean": "boolean", 172 | "Number": "number", 173 | "object": "Object", 174 | "String": "string" 175 | } 176 | }], 177 | "vars-on-top": [0], 178 | "wrap-iife": [2, "inside"], 179 | "wrap-regex": [0], 180 | "yoda": [0] 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /vendor 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "dev-lib"] 2 | path = dev-lib 3 | url = https://github.com/xwp/wp-dev-lib.git 4 | branch = master 5 | -------------------------------------------------------------------------------- /.jscsrc: -------------------------------------------------------------------------------- 1 | { 2 | "preset": "wordpress", 3 | "jsDoc": { 4 | "checkAnnotations": "jsdoc3", 5 | "checkParamExistence": true, 6 | "checkParamNames": true, 7 | "requireParamTypes": true, 8 | "checkRedundantParams": true, 9 | "checkReturnTypes": true, 10 | "requireReturnTypes": true, 11 | "checkTypes": "strictNativeCase", 12 | "checkRedundantAccess": "enforceLeadingUnderscore", 13 | "leadingUnderscoreAccess": "private", 14 | "requireHyphenBeforeDescription": true, 15 | "requireNewlineAfterDescription": true, 16 | "requireParamDescription": true 17 | }, 18 | "excludeFiles": [ 19 | "**/*.min.js", 20 | "**/*.jsx", 21 | "**/node_modules/**", 22 | "**/vendor/**" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | **/*.min.js 2 | **/node_modules/** 3 | **/vendor/** 4 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | dev-lib/.jshintrc -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | dist: precise 3 | 4 | notifications: 5 | email: 6 | on_success: never 7 | on_failure: change 8 | 9 | cache: 10 | directories: 11 | - node_modules 12 | - vendor 13 | 14 | language: 15 | - php 16 | - node_js 17 | 18 | php: 19 | - 5.2 20 | - 7.0 21 | 22 | env: 23 | - WP_VERSION=trunk WP_MULTISITE=0 24 | - WP_VERSION=trunk WP_MULTISITE=1 25 | 26 | install: 27 | - nvm install 6 && nvm use 6 28 | - export DEV_LIB_PATH=dev-lib 29 | - if [ ! -e "$DEV_LIB_PATH" ] && [ -L .travis.yml ]; then export DEV_LIB_PATH=$( dirname $( readlink .travis.yml ) ); fi 30 | - if [ ! -e "$DEV_LIB_PATH" ]; then git clone https://github.com/xwp/wp-dev-lib.git $DEV_LIB_PATH; fi 31 | - source $DEV_LIB_PATH/travis.install.sh 32 | 33 | script: 34 | - source $DEV_LIB_PATH/travis.script.sh 35 | 36 | after_script: 37 | - source $DEV_LIB_PATH/travis.after_script.sh 38 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* global require */ 2 | 3 | var grunt = require( 'grunt' ); 4 | 5 | grunt.initConfig({ 6 | qunit: { 7 | all: [ 'tests/qunit/**/*.html' ] 8 | } 9 | }); 10 | 11 | grunt.loadNpmTasks( 'grunt-contrib-qunit' ); 12 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "xwp/wp-core-media-widgets", 3 | "version": "0.2.0", 4 | "type": "wordpress-plugin", 5 | "license": "GPL-2.0", 6 | "homepage": "https://github.com/xwp/wp-core-media-widgets", 7 | "repositories": [ 8 | { 9 | "type": "git", 10 | "url": "https://github.com/xwp/wp-core-media-widgets.git" 11 | } 12 | ], 13 | "dist": { 14 | "url": "https://downloads.wordpress.org/plugin/wp-core-media-widgets.zip", 15 | "type": "zip" 16 | }, 17 | "require": { 18 | "php": ">=5.2.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /core-media-widgets.php: -------------------------------------------------------------------------------- 1 | add( 'text-widgets', plugin_dir_url( __FILE__ ) . 'wp-admin/js/widgets/text-widgets.js', array( 'jquery', 'backbone', 'editor', 'wp-util' ) ); 46 | $scripts->add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' ); 47 | } 48 | 49 | $handle = 'media-widgets'; 50 | $src = plugin_dir_url( __FILE__ ) . 'wp-admin/js/widgets/media-widgets.js'; 51 | if ( ! $scripts->query( $handle, 'registered' ) ) { 52 | $scripts->add( $handle, $src, array( 'jquery', 'media-models', 'media-views' ) ); 53 | $scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' ); 54 | } 55 | 56 | $handle = 'media-image-widget'; 57 | $src = plugin_dir_url( __FILE__ ) . 'wp-admin/js/widgets/media-image-widget.js'; 58 | if ( ! $scripts->query( $handle, 'registered' ) ) { 59 | $scripts->add( $handle, $src, array( 'media-widgets' ) ); 60 | } 61 | 62 | $handle = 'media-video-widget'; 63 | $src = plugin_dir_url( __FILE__ ) . 'wp-admin/js/widgets/media-video-widget.js'; 64 | if ( ! $scripts->query( $handle, 'registered' ) ) { 65 | $scripts->add( $handle, $src, array( 'media-widgets', 'media-audiovideo' ) ); 66 | } 67 | 68 | $handle = 'media-audio-widget'; 69 | $src = plugin_dir_url( __FILE__ ) . 'wp-admin/js/widgets/media-audio-widget.js'; 70 | if ( ! $scripts->query( $handle, 'registered' ) ) { 71 | $scripts->add( $handle, $src, array( 'media-widgets', 'media-audiovideo' ) ); 72 | } 73 | 74 | $scripts->add( 'media-gallery-widget', plugin_dir_url( __FILE__ ) . 'wp-admin/js/widgets/media-gallery-widget.js', array( 'media-widgets' ) ); 75 | 76 | if ( ! WP_CORE_MEDIA_WIDGETS_MERGED ) { 77 | $scripts->add_inline_script( 'customize-selective-refresh', file_get_contents( dirname( __FILE__ ) . '/wp-includes/js/customize-selective-refresh-extras.js' ) ); 78 | } 79 | } 80 | add_action( 'wp_default_scripts', 'wp32417_default_scripts' ); 81 | 82 | /** 83 | * Add filters that will eventually reside in default-filters.php 84 | */ 85 | function wp32417_add_default_filters() { 86 | add_filter( 'widget_text_content', 'capital_P_dangit', 11 ); 87 | add_filter( 'widget_text_content', 'wptexturize' ); 88 | add_filter( 'widget_text_content', 'convert_smilies', 20 ); 89 | add_filter( 'widget_text_content', 'wpautop' ); 90 | } 91 | if ( ! WP_CORE_VISUAL_TEXT_WIDGET_MERGED ) { 92 | add_action( 'plugins_loaded', 'wp32417_add_default_filters' ); 93 | } 94 | 95 | /** 96 | * Register widget styles. 97 | * 98 | * @codeCoverageIgnore 99 | * @param WP_Styles $styles Styles. 100 | */ 101 | function wp32417_default_styles( WP_Styles $styles ) { 102 | $handle = 'media-widgets'; 103 | if ( ! WP_CORE_MEDIA_WIDGETS_MERGED ) { 104 | $src = plugin_dir_url( __FILE__ ) . 'wp-admin/css/widgets/media-widgets.css'; 105 | $styles->add( $handle, $src, array( 'media-views' ) ); 106 | } 107 | 108 | $handle = 'media-gallery-widget'; 109 | if ( ! WP_CORE_GALLERY_WIDGET_MERGED ) { 110 | $src = plugin_dir_url( __FILE__ ) . 'wp-admin/css/widgets/media-gallery-widget.css'; 111 | $styles->add( $handle, $src, array( 'media-views' ) ); 112 | } 113 | } 114 | add_action( 'wp_default_styles', 'wp32417_default_styles' ); 115 | 116 | /** 117 | * Style fixes for default themes. 118 | * 119 | * @codeCoverageIgnore 120 | */ 121 | function wp32417_custom_theme_styles() { 122 | if ( 'twentyten' === get_template() ) { 123 | add_action( 'wp_head', 'wp32417_twentyten_styles' ); 124 | } 125 | } 126 | if ( ! WP_CORE_MEDIA_WIDGETS_MERGED ) { 127 | add_action( 'wp_enqueue_scripts', 'wp32417_custom_theme_styles', 11 ); 128 | } 129 | 130 | /** 131 | * Style fixes for Twenty Ten. 132 | * 133 | * @codeCoverageIgnore 134 | */ 135 | function wp32417_twentyten_styles() { 136 | echo ''; 137 | } 138 | 139 | /** 140 | * Register widget. 141 | * 142 | * @codeCoverageIgnore 143 | */ 144 | function wp32417_widgets_init() { 145 | $class_files = array( 146 | 'WP_Widget_Media' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media.php', 147 | 'WP_Widget_Media_Image' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-image.php', 148 | 'WP_Widget_Media_Video' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-video.php', 149 | 'WP_Widget_Media_Audio' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-audio.php', 150 | 'WP_Widget_Media_Gallery' => dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-media-gallery.php', 151 | ); 152 | foreach ( $class_files as $class => $file ) { 153 | if ( ! class_exists( $class ) ) { 154 | require_once( $file ); 155 | 156 | if ( 'WP_Widget_Media' !== $class ) { 157 | register_widget( $class ); 158 | } 159 | } 160 | } 161 | 162 | if ( function_exists( 'wp_enqueue_editor' ) && ! WP_CORE_VISUAL_TEXT_WIDGET_MERGED ) { 163 | require_once( dirname( __FILE__ ) . '/wp-includes/widgets/class-wp-widget-visual-text.php' ); 164 | unregister_widget( 'WP_Widget_Text' ); 165 | register_widget( 'WP_Widget_Visual_Text' ); 166 | } 167 | } 168 | add_action( 'widgets_init', 'wp32417_widgets_init', 0 ); 169 | 170 | /** 171 | * Add align class name to the alignment container in .attachment-display-settings. 172 | * 173 | * @see wp_print_media_templates() 174 | * @todo For Core merge, this should be patched in \wp_print_media_templates(). 175 | */ 176 | function wp32417_add_classname_to_display_settings() { 177 | ?> 178 | 186 | 198 | 209 | query( $script_handle, 'registered' ) ) { 91 | WP_CLI::error( "Script handle not registered: $script_handle" ); 92 | } 93 | } 94 | 95 | add_filter( 'script_loader_tag', array( __CLASS__, 'filter_script_loader_tag' ), 10, 2 ); 96 | wp_enqueue_media(); 97 | 98 | ob_start(); 99 | echo "