Changeset 1756975
- Timestamp:
- 11/01/2017 08:56:24 PM (8 years ago)
- Location:
- stackcommerce-connect/trunk
- Files:
-
- 8 edited
-
dist/scripts/stackcommerce-wp.min.js (modified) (1 diff)
-
dist/scripts/stackcommerce-wp.min.js.map (modified) (1 diff)
-
includes/class-stackcommerce-wp-article.php (modified) (2 diffs)
-
includes/class-stackcommerce-wp-settings.php (modified) (5 diffs)
-
includes/class-stackcommerce-wp.php (modified) (5 diffs)
-
index.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
stackcommerce-connect/trunk/dist/scripts/stackcommerce-wp.min.js
r1752090 r1756975 1 "use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var c=0;c<t.length;c++){var a=t[c];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,c,a){return c&&e(t.prototype,c),a&&e(t,a),t}}();jQuery(document).ready(function(){if(document.querySelector(".stackcommerce-wp-form")){var e=new StackCommerce_WP;e.updateForm(), e.categories(),e.tags(),document.querySelector("#stackcommerce-wp-form-submit").addEventListener("click",e.notify.bind(e)),jQuery("form.stackcommerce-wp-form").keypress(e.performKeycheck.bind(e)),jQuery('input[name="stackcommerce_wp_content_integration[]"]').change(e.updateForm.bind(e))}});var StackCommerce_WP=function(){function e(){_classCallCheck(this,e),this.$endpoint=this.getValue("#stackcommerce_wp_cms_api_endpoint"),this.$form=document.querySelector("#stackcommerce-wp-form"),this.$submit_button=document.querySelector("#stackcommerce-wp-form-submit")}return _createClass(e,[{key:"notify",value:function(){var e=this,t=this.getValue("#stackcommerce_wp_account_id"),c=this.getValue("#stackcommerce_wp_secret");this.setConnectionStatus("connecting"),jQuery.ajax({method:"PUT",url:this.$endpoint+"/api/wordpress/?id="+t+"&secret="+c,processData:!1,contentType:"application/json",dataType:"json",data:JSON.stringify(this.generatePayload())}).done(function(){e.setConnectionStatus("connected"),e.$form.submit()}).fail(function(){e.setConnectionStatus("disconnected")})}},{key:"generatePayload",value:function(){return{data:{type:"partner_wordpress_settings",id:this.getValue("#stackcommerce_wp_account_id"),attributes:{installed:!0,wordpress_url:this.getValue("#stackcommerce_wp_endpoint"),author_id:this.getValue("#stackcommerce_wp_author"),post_status:this.getValue("#stackcommerce_wp_post_status"),categories:this.getSelect2Values("#stackcommerce_wp_categories",[]),tags:this.getSelect2Values("#stackcommerce_wp_tags",[]),featured_image:this.getValue("#stackcommerce_wp_featured_image"),plugin_version:this.getValue("#stackcommerce_wp_plugin_version")}}}}},{key:"setConnectionStatus",value:function(e){this.setValue("#stackcommerce_wp_connection_status",e),this.updateForm()}},{key:"updateForm",value:function(){var e=document.querySelector("#stackcommerce-wp-form"),t=document.querySelector("#stackcommerce-wp-form-submit"),c=this.getValue("#stackcommerce_wp_connection_status"),a=this.getValue('input[name="stackcommerce_wp_content_integration[]"]:checked');e.setAttribute("data-stackcommerce-wp-status",c),e.setAttribute("data-stackcommerce-wp-content-integration","true"==a),"connecting"===c?t.setAttribute("disabled","disabled"):t.removeAttribute("disabled")}},{key:"performKeycheck",value:function(e){if(13==e.which)return this.notify(),!1}},{key:"taxonomySearch",value:function(e){jQuery(e.selector).select2({ajax:{type:"POST",url:window.ajaxurl,dataType:"json",delay:250,data:function(t){return{action:"sc_api_search",taxonomy:e.taxonomy,q:t.term,_wp_nonce:e._wp_nonce}},processResults:function(t){return{results:e.results.split(".").reduce(function(e,t){return e[t]},t)}},cache:!0},escapeMarkup:function(e){return e},minimumInputLength:3})}},{key:"categories",value:function(){var e={selector:"#stackcommerce_wp_categories",taxonomy:"categories",results:"data.categories",_wp_nonce:this.getValue("#stackcommerce_wp_nonce")};this.taxonomySearch(e)}},{key:"tags",value:function(){var e={selector:"#stackcommerce_wp_tags",taxonomy:"tags",results:"data.tags",_wp_nonce:this.getValue("#stackcommerce_wp_nonce")};this.taxonomySearch(e)}},{key:"getValue",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",c=document.querySelector(e).value;return c||t}},{key:"getSelect2Values",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],c=jQuery(e).select2("val");return c||t}},{key:"setValue",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";document.querySelector(e).value=t}}]),e}();1 "use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var c=0;c<t.length;c++){var a=t[c];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,c,a){return c&&e(t.prototype,c),a&&e(t,a),t}}();jQuery(document).ready(function(){if(document.querySelector(".stackcommerce-wp-form")){var e=new StackCommerce_WP;e.updateForm(),jQuery("#stackcommerce_wp_categories").select2({tags:!0,tokenSeparators:[","],minimumInputLength:3}),jQuery("#stackcommerce_wp_tags").select2({tags:!0,tokenSeparators:[","],minimumInputLength:3}),document.querySelector("#stackcommerce-wp-form-submit").addEventListener("click",e.notify.bind(e)),jQuery("form.stackcommerce-wp-form").keypress(e.performKeycheck.bind(e)),jQuery('input[name="stackcommerce_wp_content_integration[]"]').change(e.updateForm.bind(e))}});var StackCommerce_WP=function(){function e(){_classCallCheck(this,e),this.$endpoint=this.getValue("#stackcommerce_wp_cms_api_endpoint"),this.$form=document.querySelector("#stackcommerce-wp-form"),this.$submit_button=document.querySelector("#stackcommerce-wp-form-submit")}return _createClass(e,[{key:"notify",value:function(){var e=this,t=this.getValue("#stackcommerce_wp_account_id"),c=this.getValue("#stackcommerce_wp_secret");this.setConnectionStatus("connecting"),jQuery.ajax({method:"PUT",url:this.$endpoint+"/api/wordpress/?id="+t+"&secret="+c,processData:!1,contentType:"application/json",dataType:"json",data:JSON.stringify(this.generatePayload())}).done(function(){e.setConnectionStatus("connected"),e.$form.submit()}).fail(function(){e.setConnectionStatus("disconnected")})}},{key:"generatePayload",value:function(){return{data:{type:"partner_wordpress_settings",id:this.getValue("#stackcommerce_wp_account_id"),attributes:{installed:!0,wordpress_url:this.getValue("#stackcommerce_wp_endpoint"),author_id:this.getValue("#stackcommerce_wp_author"),post_status:this.getValue("#stackcommerce_wp_post_status"),categories:this.getSelect2Values("#stackcommerce_wp_categories",[]),tags:this.getSelect2Values("#stackcommerce_wp_tags",[]),featured_image:this.getValue("#stackcommerce_wp_featured_image"),plugin_version:this.getValue("#stackcommerce_wp_plugin_version")}}}}},{key:"setConnectionStatus",value:function(e){this.setValue("#stackcommerce_wp_connection_status",e),this.updateForm()}},{key:"updateForm",value:function(){var e=document.querySelector("#stackcommerce-wp-form"),t=document.querySelector("#stackcommerce-wp-form-submit"),c=this.getValue("#stackcommerce_wp_connection_status"),a=this.getValue('input[name="stackcommerce_wp_content_integration[]"]:checked');e.setAttribute("data-stackcommerce-wp-status",c),e.setAttribute("data-stackcommerce-wp-content-integration","true"==a),"connecting"===c?t.setAttribute("disabled","disabled"):t.removeAttribute("disabled")}},{key:"performKeycheck",value:function(e){if(13==e.which)return this.notify(),!1}},{key:"getValue",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",c=document.querySelector(e).value;return c||t}},{key:"getSelect2Values",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],c=jQuery(e).select2("val");return c||t}},{key:"setValue",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";document.querySelector(e).value=t}}]),e}(); 2 2 //# sourceMappingURL=stackcommerce-wp.min.js.map -
stackcommerce-connect/trunk/dist/scripts/stackcommerce-wp.min.js.map
r1752090 r1756975 1 {"version":3,"sources":["stackcommerce-wp.js"],"names":["jQuery","document","ready","querySelector","sc_connect","StackCommerce_WP","updateForm"," categories","tags","addEventListener","notify","bind","keypress","performKeycheck","change","_classCallCheck","this","$endpoint","getValue","$form","$submit_button","_createClass","key","value","_this","$account_id","$secret_key","setConnectionStatus","ajax","method","url","processData","contentType","dataType","data","JSON","stringify","generatePayload","done","submit","fail","type","id","attributes","installed","wordpress_url","author_id","post_status","getSelect2Values","featured_image","plugin_version","status","setValue","$connection_status","$content_integration","setAttribute","removeAttribute","e","which","options","selector","select2","window","ajaxurl","delay","params","action","taxonomy","q","term","_wp_nonce","processResults","results","split","reduce","_data","cache","escapeMarkup","markup","minimumInputLength","taxonomySearch","$selector","default_value","arguments","length","undefined"],"mappings":"6XAAAA,OAAOC,UAAUC,MAAM,WAGrB,GAFmCD,SAASE,cAAc,0BAE3B,CAC7B,IAAIC,EAAa,IAAIC,iBAErBD,EAAWE,aACXF,EAAWG,aACXH,EAAWI,OAEUP,SAASE,cAAc,iCAE7BM,iBAAiB,QAASL,EAAWM,OAAOC,KAAKP,IAEhEJ,OAAO,8BAA8BY,SAASR,EAAWS,gBAAgBF,KAAKP,IAC9EJ,OAAO,wDAAwDc,OAAOV,EAAWE,WAAWK,KAAKP,OAfrG,IAmBMC,iBAAAA,WACJ,SAAAA,IAAcU,gBAAAC,KAAAX,GACZW,KAAKC,UAAiBD,KAAKE,SAAS,sCACpCF,KAAKG,MAAiBlB,SAASE,cAAc,0BAC7Ca,KAAKI,eAAiBnB,SAASE,cAAc,iCA6J9C,OA5JAkB,aAAAhB,IAAAiB,IAAA,SAAAC,MAAA,WAEQ,IAAAC,EAAAR,KACHS,EAAcT,KAAKE,SAAS,gCAC5BQ,EAAcV,KAAKE,SAAS,4BAEhCF,KAAKW,oBAAoB,cAEzB3B,OAAO4B,MACLC,OAAQ,MACRC,IAAKd,KAAKC,UAAY,sBAAwBQ,EAAc,WAAaC,EACzEK,aAAa,EACbC,YAAa,mBACbC,SAAU,OACVC,KAAMC,KAAKC,UAAUpB,KAAKqB,qBAE3BC,KAAK,WACJd,EAAKG,oBAAoB,aACzBH,EAAKL,MAAMoB,WAEZC,KAAK,WACJhB,EAAKG,oBAAoB,qBAE5BL,IAAA,kBAAAC,MAAA,WAYC,OACE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,IAAIoC,GACFC,SAAU,+BACVO,SAAU,aACVK,QAAU,kBACVF,UAAWtD,KAAKE,SAAS,4BAG3BF,KAAKgE,eAAerB,MACrBrC,IAAA,OAAAC,MAAA,WAGC,IAAIoC,GACFC,SAAU,yBACVO,SAAU,OACVK,QAAU,YACVF,UAAWtD,KAAKE,SAAS,4BAG3BF,KAAKgE,eAAerB,MACrBrC,IAAA,WAAAC,MAAA,SAEQ0D,GAA+B,IAApBC,EAAoBC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAJ,GAC9B5D,EAAQtB,SAASE,cAAc8E,GAAW1D,MAE9C,OAAGA,GAGM2D,KAEV5D,IAAA,mBAAAC,MAAA,SAEgB0D,GAA+B,IAApBC,EAAoBC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,MAC1C5D,EAAQvB,OAAOiF,GAAWpB,QAAQ,OAEtC,OAAGtC,GAGM2D,KAEV5D,IAAA,WAAAC,MAAA,SAEQ0D,GAAuB,IAAZ1D,EAAY4D,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAJ,GAC1BlF,SAASE,cAAc8E,GAAW1D,MAAQA,MAC3ClB,EAjKGA","file":"stackcommerce-wp.min.js","sourcesContent":["jQuery(document).ready(function() {\n const isStackCommerceConnectPage = document.querySelector('.stackcommerce-wp-form');\n\n if(isStackCommerceConnectPage) {\n let sc_connect = new StackCommerce_WP();\n\n sc_connect.updateForm();\n sc_connect.categories();\n sc_connect.tags();\n\n let $submit_button = document.querySelector('#stackcommerce-wp-form-submit');\n\n $submit_button.addEventListener('click', sc_connect.notify.bind(sc_connect));\n\n jQuery('form.stackcommerce-wp-form').keypress(sc_connect.performKeycheck.bind(sc_connect));\n jQuery('input[name=\"stackcommerce_wp_content_integration[]\"]').change(sc_connect.updateForm.bind(sc_connect));\n }\n});\n\nclass StackCommerce_WP {\n constructor() {\n this.$endpoint = this.getValue('#stackcommerce_wp_cms_api_endpoint');\n this.$form = document.querySelector('#stackcommerce-wp-form');\n this.$submit_button = document.querySelector('#stackcommerce-wp-form-submit');\n }\n\n notify() {\n let $account_id = this.getValue('#stackcommerce_wp_account_id'),\n $secret_key = this.getValue('#stackcommerce_wp_secret');\n\n this.setConnectionStatus('connecting');\n\n jQuery.ajax({\n method: 'PUT',\n url: this.$endpoint + '/api/wordpress/?id=' + $account_id + '&secret=' + $secret_key,\n processData: false,\n contentType: 'application/json',\n dataType: 'json',\n data: JSON.stringify(this.generatePayload())\n })\n .done(() => {\n this.setConnectionStatus('connected');\n this.$form.submit();\n })\n .fail(() => {\n this.setConnectionStatus('disconnected');\n });\n }\n\n generatePayload() {\n let $account_id = this.getValue('#stackcommerce_wp_account_id'),\n $wordpress_url = this.getValue('#stackcommerce_wp_endpoint'),\n $author_id = this.getValue('#stackcommerce_wp_author'),\n $post_status = this.getValue('#stackcommerce_wp_post_status'),\n $categories = this.getSelect2Values('#stackcommerce_wp_categories', []),\n $tags = this.getSelect2Values('#stackcommerce_wp_tags', []),\n $featured_image = this.getValue('#stackcommerce_wp_featured_image'),\n $plugin_version = this.getValue('#stackcommerce_wp_plugin_version');\n\n return {\n data: {\n type: 'partner_wordpress_settings',\n id: $account_id,\n attributes: {\n installed: true,\n wordpress_url: $wordpress_url,\n author_id: $author_id,\n post_status: $post_status,\n categories: $categories,\n tags: $tags,\n featured_image: $featured_image,\n plugin_version: $plugin_version\n }\n }\n };\n }\n\n setConnectionStatus(status) {\n this.setValue('#stackcommerce_wp_connection_status', status);\n this.updateForm();\n }\n\n updateForm() {\n let $form = document.querySelector('#stackcommerce-wp-form'),\n $submit_button = document.querySelector('#stackcommerce-wp-form-submit'),\n $connection_status = this.getValue('#stackcommerce_wp_connection_status'),\n $content_integration = this.getValue('input[name=\"stackcommerce_wp_content_integration[]\"]:checked');\n\n $form.setAttribute('data-stackcommerce-wp-status', $connection_status);\n $form.setAttribute('data-stackcommerce-wp-content-integration', ($content_integration == 'true' ? true : false));\n\n if($connection_status === 'connecting') {\n $submit_button.setAttribute('disabled', 'disabled');\n } else {\n $submit_button.removeAttribute('disabled');\n }\n }\n\n performKeycheck(e) {\n if(e.which == 13) {\n this.notify();\n return false;\n }\n }\n\n taxonomySearch(options) {\n jQuery(options.selector).select2({\n ajax: {\n type: 'POST',\n url: window.ajaxurl,\n dataType: 'json',\n delay: 250,\n data: function(params) {\n return {\n action: 'sc_api_search',\n taxonomy: options.taxonomy,\n q: params.term,\n _wp_nonce: options._wp_nonce\n }\n },\n processResults: function(data) {\n var results = options.results.split('.').reduce(function(_data, key) {\n return _data[key];\n }, data);\n\n return {\n results: results\n }\n },\n cache: true\n },\n escapeMarkup: function(markup) { return markup; },\n minimumInputLength: 3\n });\n }\n\n categories() {\n var options = {\n selector: '#stackcommerce_wp_categories',\n taxonomy: 'categories',\n results: 'data.categories',\n _wp_nonce: this.getValue('#stackcommerce_wp_nonce')\n }\n\n this.taxonomySearch(options);\n }\n\n tags() {\n var options = {\n selector: '#stackcommerce_wp_tags',\n taxonomy: 'tags',\n results: 'data.tags',\n _wp_nonce: this.getValue('#stackcommerce_wp_nonce')\n }\n\n this.taxonomySearch(options);\n }\n\n getValue($selector, default_value = '') {\n let value = document.querySelector($selector).value;\n\n if(value) {\n return value;\n } else {\n return default_value;\n }\n }\n\n getSelect2Values($selector, default_value = []) {\n let value = jQuery($selector).select2('val');\n\n if(value) {\n return value;\n } else {\n return default_value;\n }\n }\n\n setValue($selector, value = '') {\n document.querySelector($selector).value = value;\n }\n}\n"]}1 {"version":3,"sources":["stackcommerce-wp.js"],"names":["jQuery","document","ready","querySelector","sc_connect","StackCommerce_WP","updateForm","select2","tags","tokenSeparators","minimumInputLength","addEventListener","notify","bind","keypress","performKeycheck","change","_classCallCheck","this","$endpoint","getValue","$form","$submit_button","_createClass","key","value","_this","$account_id","$secret_key","setConnectionStatus","ajax","method","url","processData","contentType","dataType","data","JSON","stringify","generatePayload","done","submit","fail","type","id","attributes","installed","wordpress_url","author_id","post_status","categories","getSelect2Values","featured_image","plugin_version","status","setValue","$connection_status","$content_integration","setAttribute","removeAttribute","e","which","$selector","default_value","arguments","length","undefined"],"mappings":"6XAAAA,OAAOC,UAAUC,MAAM,WAGrB,GAFmCD,SAASE,cAAc,0BAE3B,CAC7B,IAAIC,EAAa,IAAIC,iBAErBD,EAAWE,aAEXN,OAAO,gCAAgCO,SACrCC,MAAM,EACNC,iBAAkB,KAClBC,mBAAoB,IAGtBV,OAAO,0BAA0BO,SAC/BC,MAAM,EACNC,iBAAkB,KAClBC,mBAAoB,IAGDT,SAASE,cAAc,iCAE7BQ,iBAAiB,QAASP,EAAWQ,OAAOC,KAAKT,IAEhEJ,OAAO,8BAA8Bc,SAASV,EAAWW,gBAAgBF,KAAKT,IAC9EJ,OAAO,wDAAwDgB,OAAOZ,EAAWE,WAAWO,KAAKT,OAzBrG,IA6BMC,iBAAAA,WACJ,SAAAA,IAAcY,gBAAAC,KAAAb,GACZa,KAAKC,UAAiBD,KAAKE,SAAS,sCACpCF,KAAKG,MAAiBpB,SAASE,cAAc,0BAC7Ce,KAAKI,eAAiBrB,SAASE,cAAc,iCAwG9C,OAvGAoB,aAAAlB,IAAAmB,IAAA,SAAAC,MAAA,WAEQ,IAAAC,EAAAR,KACHS,EAAcT,KAAKE,SAAS,gCAC5BQ,EAAcV,KAAKE,SAAS,4BAEhCF,KAAKW,oBAAoB,cAEzB7B,OAAO8B,MACLC,OAAQ,MACRC,IAAKd,KAAKC,UAAY,sBAAwBQ,EAAc,WAAaC,EACzEK,aAAa,EACbC,YAAa,mBACbC,SAAU,OACVC,KAAMC,KAAKC,UAAUpB,KAAKqB,qBAE3BC,KAAK,WACJd,EAAKG,oBAAoB,aACzBH,EAAKL,MAAMoB,WAEZC,KAAK,WACJhB,EAAKG,oBAAoB,qBAE5BL,IAAA,kBAAAC,MAAA,WAYC,OACEW,MACEO,KAAM,6BACNC,GAZkB1B,KAAKE,SAAS,gCAahCyB,YACEC,WAAW,EACXC,cAdgB7B,KAAKE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.js","sourcesContent":["jQuery(document).ready(function() {\n const isStackCommerceConnectPage = document.querySelector('.stackcommerce-wp-form');\n\n if(isStackCommerceConnectPage) {\n let sc_connect = new StackCommerce_WP();\n\n sc_connect.updateForm();\n\n jQuery('#stackcommerce_wp_categories').select2({\n tags: true,\n tokenSeparators: [','],\n minimumInputLength: 3\n });\n\n jQuery('#stackcommerce_wp_tags').select2({\n tags: true,\n tokenSeparators: [','],\n minimumInputLength: 3\n });\n\n let $submit_button = document.querySelector('#stackcommerce-wp-form-submit');\n\n $submit_button.addEventListener('click', sc_connect.notify.bind(sc_connect));\n\n jQuery('form.stackcommerce-wp-form').keypress(sc_connect.performKeycheck.bind(sc_connect));\n jQuery('input[name=\"stackcommerce_wp_content_integration[]\"]').change(sc_connect.updateForm.bind(sc_connect));\n }\n});\n\nclass StackCommerce_WP {\n constructor() {\n this.$endpoint = this.getValue('#stackcommerce_wp_cms_api_endpoint');\n this.$form = document.querySelector('#stackcommerce-wp-form');\n this.$submit_button = document.querySelector('#stackcommerce-wp-form-submit');\n }\n\n notify() {\n let $account_id = this.getValue('#stackcommerce_wp_account_id'),\n $secret_key = this.getValue('#stackcommerce_wp_secret');\n\n this.setConnectionStatus('connecting');\n\n jQuery.ajax({\n method: 'PUT',\n url: this.$endpoint + '/api/wordpress/?id=' + $account_id + '&secret=' + $secret_key,\n processData: false,\n contentType: 'application/json',\n dataType: 'json',\n data: JSON.stringify(this.generatePayload())\n })\n .done(() => {\n this.setConnectionStatus('connected');\n this.$form.submit();\n })\n .fail(() => {\n this.setConnectionStatus('disconnected');\n });\n }\n\n generatePayload() {\n let $account_id = this.getValue('#stackcommerce_wp_account_id'),\n $wordpress_url = this.getValue('#stackcommerce_wp_endpoint'),\n $author_id = this.getValue('#stackcommerce_wp_author'),\n $post_status = this.getValue('#stackcommerce_wp_post_status'),\n $categories = this.getSelect2Values('#stackcommerce_wp_categories', []),\n $tags = this.getSelect2Values('#stackcommerce_wp_tags', []),\n $featured_image = this.getValue('#stackcommerce_wp_featured_image'),\n $plugin_version = this.getValue('#stackcommerce_wp_plugin_version');\n\n return {\n data: {\n type: 'partner_wordpress_settings',\n id: $account_id,\n attributes: {\n installed: true,\n wordpress_url: $wordpress_url,\n author_id: $author_id,\n post_status: $post_status,\n categories: $categories,\n tags: $tags,\n featured_image: $featured_image,\n plugin_version: $plugin_version\n }\n }\n };\n }\n\n setConnectionStatus(status) {\n this.setValue('#stackcommerce_wp_connection_status', status);\n this.updateForm();\n }\n\n updateForm() {\n let $form = document.querySelector('#stackcommerce-wp-form'),\n $submit_button = document.querySelector('#stackcommerce-wp-form-submit'),\n $connection_status = this.getValue('#stackcommerce_wp_connection_status'),\n $content_integration = this.getValue('input[name=\"stackcommerce_wp_content_integration[]\"]:checked');\n\n $form.setAttribute('data-stackcommerce-wp-status', $connection_status);\n $form.setAttribute('data-stackcommerce-wp-content-integration', ($content_integration == 'true' ? true : false));\n\n if($connection_status === 'connecting') {\n $submit_button.setAttribute('disabled', 'disabled');\n } else {\n $submit_button.removeAttribute('disabled');\n }\n }\n\n performKeycheck(e) {\n if(e.which == 13) {\n this.notify();\n return false;\n }\n }\n\n getValue($selector, default_value = '') {\n let value = document.querySelector($selector).value;\n\n if(value) {\n return value;\n } else {\n return default_value;\n }\n }\n\n getSelect2Values($selector, default_value = []) {\n let value = jQuery($selector).select2('val');\n\n if(value) {\n return value;\n } else {\n return default_value;\n }\n }\n\n setValue($selector, value = '') {\n document.querySelector($selector).value = value;\n }\n}\n"]} -
stackcommerce-connect/trunk/includes/class-stackcommerce-wp-article.php
r1752090 r1756975 171 171 172 172 /** 173 * Create missing tags and categories 174 * 175 * @since 1.6.0 176 */ 177 protected function register_taxonomy( $taxonomies, $type ) { 178 if ( empty( $taxonomies ) || empty( $type ) ) { 179 return false; 180 } 181 182 if ( is_string( $taxonomies ) ) { 183 $taxonomies = explode( ',', $taxonomies ); 184 } 185 186 $taxonomies_ids = []; 187 188 foreach ( $taxonomies as $tax ) { 189 if ( function_exists( 'wpcom_vip_term_exists' ) ) { 190 $tax_id = wpcom_vip_term_exists( $tax, $type ); 191 } else { 192 // @codingStandardsIgnoreLine 193 $tax_id = term_exists( $tax, $type ); 194 } 195 196 if ( ! $tax_id && 0 !== $tax_id ) { 197 $tax_id = wp_insert_term( $tax, $type ); 198 } 199 200 if ( ! is_wp_error( $tax_id ) ) { 201 $taxonomies_ids[] = (int) $tax_id['term_taxonomy_id']; 202 } 203 } 204 205 return $taxonomies_ids; 206 } 207 208 /** 173 209 * Prepare fields on a $post array 174 210 * 175 * @since 1. 2.0211 * @since 1.6.0 176 212 */ 177 213 protected function prepare_fields( $fields ) { 178 214 $post = array( 179 'post_title' => wp_strip_all_tags( $fields['post_title'] ), 180 'post_content' => $fields['post_content'], 181 'post_type' => 'post', 182 'post_author' => $this->get_admin_fields( 'post_author' ), 183 'post_status' => $this->get_admin_fields( 'post_status' ), 215 'post_title' => wp_strip_all_tags( $fields['post_title'] ), 216 'post_content' => $fields['post_content'], 217 'post_type' => isset( $fields['post_type'] ) ? $fields['post_type'] : 'post', 218 'post_author' => isset( $fields['post_author'] ) ? $fields['post_author'] : $this->get_admin_fields( 'post_author' ), 219 'post_name' => isset( $fields['post_name'] ) ? $fields['post_name'] : '', 220 'post_excerpt' => isset( $fields['post_excerpt'] ) ? $fields['post_excerpt'] : '', 184 221 ); 185 222 186 if ( array_key_exists( 'post_name', $fields ) ) { 187 $post['post_name'] = $fields['post_name']; 188 } 189 190 if ( array_key_exists( 'post_excerpt', $fields ) ) { 191 $post['post_excerpt'] = $fields['post_excerpt']; 192 } 193 194 if ( array_key_exists( 'post_date_gmt', $fields ) ) { 223 if ( isset( $fields['post_date_gmt'] ) ) { 195 224 $post['post_date_gmt'] = get_gmt_from_date( $fields['post_date_gmt'] ); 196 225 } 197 226 198 if ( array_key_exists( 'post_status', $fields ) ) { 199 $post_status = [ 'draft', 'pending', 'future' ]; 200 201 $post['post_status'] = $this->generate_post_status( $fields['post_status'] ); 202 } 203 204 $raw_categories = $this->get_admin_fields( 'post_categories' ); 205 $raw_tags = $this->get_admin_fields( 'post_tags' ); 206 207 if ( is_array( $raw_categories ) && ! empty( $raw_categories ) ) { 208 $categories = $this->get_categories_ids( $raw_categories ); 209 } 210 211 if ( is_array( $raw_tags ) && ! empty( $raw_tags ) ) { 212 $tags = $raw_tags; 213 } 214 215 if ( isset( $categories ) ) { 216 $post['post_category'] = $categories; 217 } 218 219 if ( isset( $tags ) ) { 220 $post['tags_input'] = $tags; 227 if ( isset( $fields['post_status'] ) ) { 228 $valid_post_statuses = [ 'draft', 'pending', 'future' ]; 229 $post_status = $fields['post_status']; 230 231 if ( is_int( $fields['post_status'] ) && $valid_post_statuses[ $post_status ] ) { 232 $post_status = $this->generate_post_status( $fields['post_status'] ); 233 } else { 234 $post['post_status'] = $post_status; 235 } 236 } 237 238 if ( isset( $fields['post_category'] ) ) { 239 $post['post_category'] = $this->register_taxonomy( $fields['post_category'], 'category' ); 240 } 241 242 if ( isset( $fields['tags_input'] ) ) { 243 $post['tags_input'] = $this->register_taxonomy( $fields['tags_input'], 'post_tag' ); 221 244 } 222 245 … … 233 256 $stackcommerce_wp_media = new StackCommerce_WP_Media(); 234 257 235 $ fields['post_content'] = $stackcommerce_wp_media->process_body_images( $fields['post_content'] );258 $post['post_content'] = $stackcommerce_wp_media->process_body_images( $post['post_content'] ); 236 259 237 260 $post = $this->prepare_fields( $fields ); -
stackcommerce-connect/trunk/includes/class-stackcommerce-wp-settings.php
r1752090 r1756975 41 41 42 42 /** 43 * Get WordPress categories43 * Arrange taxonomies values 44 44 * 45 * @since 1. 1.045 * @since 1.6.0 46 46 */ 47 private function get_categories() { 48 $categories_filter = array( 49 'hide_empty' => false, 50 ); 51 52 $categories = get_categories( $categories_filter ); 53 $categories_return = array(); 54 55 foreach ( $categories as $category ) { 56 $categories_return[ $category->slug ] = $category->name; 57 } 58 59 return $categories_return; 60 } 61 62 /** 63 * Get WordPress tags 64 * 65 * @since 1.0.0 66 */ 67 private function get_tags() { 68 $tags_filter = array( 69 'hide_empty' => false, 70 ); 71 72 $tags = get_tags( $tags_filter ); 73 $tags_return = array(); 74 75 foreach ( $tags as $tag ) { 76 $tags_return[ $tag->slug ] = $tag->name; 77 } 78 79 return $tags_return; 47 private function arrange_taxonomies( $taxonomies_list ) { 48 if ( ! is_array( $taxonomies_list ) || sizeof( $taxonomies_list ) === 0 ) { 49 return []; 50 } 51 52 $arranged_list = []; 53 54 foreach ( $taxonomies_list as $key => $label ) { 55 $arranged_list[ $label ] = $label; 56 } 57 58 return $arranged_list; 80 59 } 81 60 … … 192 171 'section' => 'stackcommerce_wp_section_four', 193 172 'type' => 'multiselect', 194 'options' => $this-> get_categories(),173 'options' => $this->arrange_taxonomies( get_option( 'stackcommerce_wp_categories' ) ), 195 174 'default' => array(), 196 175 'placeholder' => '', … … 203 182 'section' => 'stackcommerce_wp_section_four', 204 183 'type' => 'multiselect', 205 'options' => $this-> get_tags(),184 'options' => $this->arrange_taxonomies( get_option( 'stackcommerce_wp_tags' ) ), 206 185 'default' => array(), 207 186 'placeholder' => '', … … 276 255 break; 277 256 case 'select': 278 case 'multiselect': 257 $attributes = ''; 258 $options_markup = ''; 259 279 260 if ( is_array( $arguments['options'] ) ) { 280 $attributes = '';281 $options_markup = '';282 283 261 foreach ( $arguments['options'] as $key => $label ) { 284 262 $options_markup .= sprintf( '<option value="%s" %s>%s</option>', $key, selected( @$value[ array_search( $key, $value, true ) ], $key, false ), $label ); 285 263 } 286 287 if ( 'multiselect' === $arguments['type'] ) { 288 $attributes = ' class="stackcommerce-wp-form-select2" multiple="multiple" '; 264 } 265 266 if ( 'multiselect' === $arguments['type'] ) { 267 $attributes = ' class="stackcommerce-wp-form-select2" multiple="multiple" '; 268 } 269 270 printf( '<select name="%1$s[]" id="%1$s" %2$s>%3$s</select>', esc_attr( $arguments['uid'] ), $attributes, $options_markup ); 271 break; 272 case 'multiselect': 273 $attributes = ''; 274 $options_markup = ''; 275 276 if ( is_array( $arguments['options'] ) ) { 277 foreach ( $arguments['options'] as $key => $label ) { 278 $options_markup .= sprintf( '<option value="%s" %s selected>%s</option>', $key, selected( @$value[ array_search( $key, $value, true ) ], $key, false ), $label ); 289 279 } 290 291 printf( '<select name="%1$s[]" id="%1$s" %2$s>%3$s</select>', esc_attr( $arguments['uid'] ), $attributes, $options_markup ); 292 } 280 } 281 282 if ( 'multiselect' === $arguments['type'] ) { 283 $attributes = ' class="stackcommerce-wp-form-select2" multiple="multiple" '; 284 } 285 286 printf( '<select name="%1$s[]" id="%1$s" %2$s>%3$s</select>', esc_attr( $arguments['uid'] ), $attributes, $options_markup ); 293 287 break; 294 288 case 'radio': … … 326 320 327 321 if ( $supplemental ) { 328 printf( '<p class="description">%s</p>', esc_attr( $supplemental ) ); 322 // @codingStandardsIgnoreLine 323 printf( '<p class="description">%s</p>', $supplemental ); 329 324 } 330 325 } -
stackcommerce-connect/trunk/includes/class-stackcommerce-wp.php
r1752090 r1756975 45 45 $this->register_endpoint(); 46 46 $this->add_sc_js_code(); 47 $this->search();48 47 } 49 48 … … 67 66 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-stackcommerce-wp-settings.php'; 68 67 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-stackcommerce-wp-maintenance.php'; 69 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-stackcommerce-wp-search.php';70 68 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-stackcommerce-wp-media.php'; 71 69 … … 127 125 */ 128 126 public function styles() { 129 wp_register_style( 'stackcommerce_wp_admin_style_select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0. 3/css/select2.min.css', array(), '', 'all' );127 wp_register_style( 'stackcommerce_wp_admin_style_select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css', array(), '', 'all' ); 130 128 wp_register_style( 'stackcommerce_wp_admin_style', plugin_dir_url( dirname( __FILE__ ) ) . 'dist/styles/stackcommerce-wp.css', array(), '1.3.0', 'all' ); 131 129 … … 140 138 */ 141 139 public function scripts() { 142 wp_register_script( 'stackcommerce_wp_admin_script_select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0. 3/js/select2.min.js', array(), '', 'all' );140 wp_register_script( 'stackcommerce_wp_admin_script_select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.min.js', array(), '', 'all' ); 143 141 wp_register_script( 'stackcommerce_wp_admin_script', plugin_dir_url( dirname( __FILE__ ) ) . 'dist/scripts/stackcommerce-wp.min.js', array( 'jquery' ), '1.3.0', 'all' ); 144 142 … … 187 185 } 188 186 189 /*190 * Enable admin-ajax.php RESTful search of taxonomies191 *192 * @since 1.1.0193 */194 public function search() {195 $stackcommerce_wp_search = new StackCommerce_WP_Search();196 197 $this->loader->add_action( 'wp_ajax_sc_api_search', $stackcommerce_wp_search, 'receive' );198 }199 200 187 /** 201 188 * Run the loader to execute all of the hooks with WordPress. -
stackcommerce-connect/trunk/index.php
r1752090 r1756975 5 5 * Plugin URI: https://wordpress.org/plugins/stackcommerce-connect/ 6 6 * Description: The Connect plugin by StackCommerce connects your WordPress CMS to the StackCommerce Articles repository. 7 * Version: 1. 5.07 * Version: 1.6.0 8 8 * Author: StackCommerce, Inc 9 9 * Author URI: https://www.stackcommerce.com … … 19 19 define( 'SCWP_REQUIRED_WP_VERSION', '4.4' ); 20 20 define( 'SCWP_API_VERSION', '1' ); 21 define( 'SCWP_PLUGIN_VERSION', '1. 5.0' );21 define( 'SCWP_PLUGIN_VERSION', '1.6.0' ); 22 22 define( 'CMS_API_ENDPOINT', 'https://hive.stackcommerce.net' ); 23 23 -
stackcommerce-connect/trunk/readme.txt
r1752090 r1756975 4 4 Requires at least: 4.4 5 5 Tested up to: 4.8 6 Stable tag: 1. 5.06 Stable tag: 1.6.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 53 53 == Changelog == 54 54 55 = 1.6.0 = 56 * Add support for per article tags and categories. 57 55 58 = 1.5.0 = 56 59 * Updates for WordPress VIP compatibility. -
stackcommerce-connect/trunk/version.txt
r1752090 r1756975 1 1. 5.01 1.6.0
Note: See TracChangeset
for help on using the changeset viewer.