0

I am using a JSON API plugin for wordpress to allow me to work with the sites content in a phonegap application I'm building.

However due to the complexity of some of the content on the site (caused by shortcodes outputting graphs, sliders etc..) these aren't suitable to be displayed in the mobile app. I need to remove the shortcodes from the JSON output.

I have found that I can hook into the_content filter in wordpress and use remove_shortcode to take out the necessary shortcodes. But the problem is I can only do this when I access the json url via my browser.

For example, I may use http://example.com?json=1 to return recent posts. If I type this in my url bar I can parse the url, determine that json=1 is there and strip the shortcodes.

However when I am doing an ajax (JSONP) request from my mobile application, it doesn't appear to be able to check the url for the json parameter, thus my shortcodes are not being stripped. I can't even pass in any headers either as they won't make it because of the nature of JSONP requests I believe.

Has anyone got any ideas as to how I can figure out when a JSON request from my mobile application is received, so that I can then remove the shortcodes?

Something like

if(is_json()){
//remove shortcodes
}

And before it's brought up, I have asked this on the Wordpress Stackexchange but to no avail

Update: Here is the code I use for the ajax request from the mobile app

  $.ajax({
                    url: "http://www.example.com/?json=1",
                    dataType: "jsonp",
                    async: true,
                    success: function(result) {
                        app.populate(result)
                    },
                    error: function(request, error) {
                        alert('Network error has occurred please try again!');
                    }
                });
4

2 回答 2

1

在其中一条评论的提示下,我在 JSON-API 插件文件中找到了我需要的内容。

如果您查看json-api/models/post.php有一个功能set_content_value(),可以显示插件在哪里提取内容。在这里您可以根据需要对其进行修改,在我的情况下,我使用它通过 Wordpressremove_shortcode()功能删除某些短代码

于 2014-08-17T22:16:26.903 回答
0

每当您的插件向客户端提供内容时,您就不能只使用 remove_shortcode 功能吗?

您能否也给我们您的插件的名称/网址?也许一点代码也不会受到伤害。您介意使用您的 phonegap 应用程序的 API 请求代码片段吗?

谢谢。

于 2014-08-17T18:48:16.280 回答