diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..29e9549 --- /dev/null +++ b/README.txt @@ -0,0 +1,31 @@ +=== Plugin Name === +Tags: teste, apiki +Requires at least: 3.0.1 +Tested up to: 6.0 +Stable tag: 1.0.0 +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html + +Plugin para favoritar posts + +== Description == + +Plugin do desafio da apiki com a função de favoritar posts + +== Installation == + +1. Faça upload da pasta `wordpress-back-end-challenge` para `/wp-content/plugins/` diretorio +2. Ative o plug-in através do menu "Plugins" no WordPress. +3. Compre uma chave e insira no local indicado. +4. Ative os gatilhos que desejar e personalize o teamplate de cada um. +5. Faça um teste criando um pedido .enjoy + +== Frequently Asked Questions == + +Se você tiver alguma dúvida, problema ou solicitação de alteração, por favor, me pergunte no Fórum. Vou tentar o meu melhor para resolvê-lo o mais cedo possível. Se você gostou deste plugin, por favor deixe um comentário e será muito apreciado. Obrigado. + + +== Changelog == + += 1.0 = +* Primeiro lançamento \ No newline at end of file diff --git a/admin/class-wbec-admin.php b/admin/class-wbec-admin.php new file mode 100644 index 0000000..5df9c1d --- /dev/null +++ b/admin/class-wbec-admin.php @@ -0,0 +1,39 @@ + admin_url( 'admin-ajax.php' ), + ) + ); + } + + public static function wbec_startview() { + + /*Buscar favoritos*/ + $request = new WP_REST_Request( 'GET', '/wbec/v1/favs' ); + $response = rest_do_request( $request ); + $data = rest_get_server()->response_to_data( $response, true ); + $favs = json_decode($data); + + /*Buscar Posts*/ + $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); + $response = rest_do_request( $request ); + $data = rest_get_server()->response_to_data( $response, true ); + + include_once(WBEC_WP_PATH.'admin/partials/wbec-start-view.php'); + } + +} +WBEC_Admin::init(); \ No newline at end of file diff --git a/admin/js/admin.js b/admin/js/admin.js new file mode 100644 index 0000000..6af5b02 --- /dev/null +++ b/admin/js/admin.js @@ -0,0 +1,21 @@ +(function( $ ) { + $('.wbec-fav-btn').each(function(index, el) { + $(el).click(function(event) { + var post_id = $(el).data('id'); + $(el).find('span').toggleClass('dashicons-star-filled'); + $(el).find('span').toggleClass('dashicons-star-empty'); + toggleFav(post_id); + }); + }); + function toggleFav(idPost){ + var ajaxurl = wbec_var['ajaxurl']; + $.ajax({ + type: "post", + url: ajaxurl, + data: {action: "toggle_fav",id: idPost}, + success: function(msg){ + alert('Alterado com sucesso!'); + } + }); + } +})( jQuery ); \ No newline at end of file diff --git a/admin/partials/wbec-start-view.php b/admin/partials/wbec-start-view.php new file mode 100644 index 0000000..e894df9 --- /dev/null +++ b/admin/partials/wbec-start-view.php @@ -0,0 +1,33 @@ + + +
Clique na estrela para favoritar ou desfavoritar um post
+Fav. | +Título | +Data | +Status | +
---|---|---|---|
+ + + + | ++ | + | + |