From 9d1c191f918ab3861d9522edab1e1d9d4a2ee2fa Mon Sep 17 00:00:00 2001 From: Akshay Paghdar Date: Thu, 1 Apr 2021 18:17:20 +0530 Subject: [PATCH 1/3] Added improvements --- .gitignore | 8 ++ ...e-admin.css => qsm-custom-addon-admin.css} | 0 .../qsm-custom-addon-front.css | 0 index.php | 3 +- js/index.php | 3 - js/qsm-custom-addon-admin.js | 3 + js/qsm-custom-addon-front.js | 3 + php/addon-settings-tab-content.php | 38 ------ php/functions.php | 48 ++++++++ php/index.php | 3 +- php/qsm-addon-settings.php | 27 +++++ php/qsm-quiz-settings.php | 29 +++++ php/quiz-settings-tab-content.php | 38 ------ php/variables.php | 29 ----- plugin-name.php | 113 ------------------ qsm-addon.php | 110 +++++++++++++++++ uninstall.php | 1 - 17 files changed, 230 insertions(+), 226 deletions(-) create mode 100644 .gitignore rename css/{plugin-name-admin.css => qsm-custom-addon-admin.css} (100%) rename js/plugin-name-admin.js => css/qsm-custom-addon-front.css (100%) delete mode 100644 js/index.php create mode 100644 js/qsm-custom-addon-admin.js create mode 100644 js/qsm-custom-addon-front.js delete mode 100644 php/addon-settings-tab-content.php create mode 100644 php/functions.php create mode 100644 php/qsm-addon-settings.php create mode 100644 php/qsm-quiz-settings.php delete mode 100644 php/quiz-settings-tab-content.php delete mode 100644 php/variables.php delete mode 100644 plugin-name.php create mode 100644 qsm-addon.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e8ef19 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +node_modules/ +target/ +dist/ +vendor +*.class +*.log +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/css/plugin-name-admin.css b/css/qsm-custom-addon-admin.css similarity index 100% rename from css/plugin-name-admin.css rename to css/qsm-custom-addon-admin.css diff --git a/js/plugin-name-admin.js b/css/qsm-custom-addon-front.css similarity index 100% rename from js/plugin-name-admin.js rename to css/qsm-custom-addon-front.css diff --git a/index.php b/index.php index 62a2de0..6220032 100644 --- a/index.php +++ b/index.php @@ -1,3 +1,2 @@ +// Silence is golden. diff --git a/js/index.php b/js/index.php deleted file mode 100644 index 62a2de0..0000000 --- a/js/index.php +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/js/qsm-custom-addon-admin.js b/js/qsm-custom-addon-admin.js new file mode 100644 index 0000000..8e1d649 --- /dev/null +++ b/js/qsm-custom-addon-admin.js @@ -0,0 +1,3 @@ +(function ($) { + +}(jQuery)); \ No newline at end of file diff --git a/js/qsm-custom-addon-front.js b/js/qsm-custom-addon-front.js new file mode 100644 index 0000000..8e1d649 --- /dev/null +++ b/js/qsm-custom-addon-front.js @@ -0,0 +1,3 @@ +(function ($) { + +}(jQuery)); \ No newline at end of file diff --git a/php/addon-settings-tab-content.php b/php/addon-settings-tab-content.php deleted file mode 100644 index 0ab9066..0000000 --- a/php/addon-settings-tab-content.php +++ /dev/null @@ -1,38 +0,0 @@ -pluginHelper ) && method_exists( $mlwQuizMasterNext->pluginHelper, 'register_quiz_settings_tabs' ) ) { - $mlwQuizMasterNext->pluginHelper->register_addon_settings_tab( "Plugin Name", 'qsm_addon_xxxxx_addon_settings_tabs_content' ); - } -} - -/** - * Generates the content for your addon settings tab - * - * @since 1.0.0 - * @return void - * @todo Replace the xxxxx with your addon's name - */ -function qsm_addon_xxxxx_addon_settings_tabs_content() { - - // Enqueue your scripts and styles. - wp_enqueue_script( 'plugin_name_admin_script', plugins_url( '../js/plugin-name-admin.js' , __FILE__ ), array( 'jquery' ) ); - wp_enqueue_style( 'plugin_name_admin_style', plugins_url( '../css/plugin-name-admin.css' , __FILE__ ) ); - - // Display your addon settings here! -} -?> diff --git a/php/functions.php b/php/functions.php new file mode 100644 index 0000000..b85be0b --- /dev/null +++ b/php/functions.php @@ -0,0 +1,48 @@ + 0) { + $args = array( + 'posts_per_page' => 1, + 'post_type' => 'qsm_quiz', + 'meta_query' => array( + array( + 'key' => 'quiz_id', + 'value' => $quiz_id, + 'compare' => '=', + ), + ), + ); + $the_query = new WP_Query($args); + if ($the_query->have_posts()) { + while ($the_query->have_posts()) { + $the_query->the_post(); + $permalink = get_the_permalink(get_the_ID()); + } + wp_reset_postdata(); + } + } + return $permalink; + } + + } + +} +global $AddonFunctions_XXXX; +$AddonFunctions_XXXX = new AddonFunctions_XXXX(); diff --git a/php/index.php b/php/index.php index 62a2de0..6220032 100644 --- a/php/index.php +++ b/php/index.php @@ -1,3 +1,2 @@ +// Silence is golden. diff --git a/php/qsm-addon-settings.php b/php/qsm-addon-settings.php new file mode 100644 index 0000000..c670fa4 --- /dev/null +++ b/php/qsm-addon-settings.php @@ -0,0 +1,27 @@ +pluginHelper) && method_exists($mlwQuizMasterNext->pluginHelper, 'register_quiz_settings_tabs')) { + $mlwQuizMasterNext->pluginHelper->register_addon_settings_tab("Custom Addon", 'qsm_addon_XXXX_addon_settings_tabs_content'); + } +} + +/** + * Generates the content for your addon settings tab + * + * @since 1.0.0 + * @return void + */ +function qsm_addon_XXXX_addon_settings_tabs_content() { + // Display your addon settings here! +} diff --git a/php/qsm-quiz-settings.php b/php/qsm-quiz-settings.php new file mode 100644 index 0000000..9fa5f78 --- /dev/null +++ b/php/qsm-quiz-settings.php @@ -0,0 +1,29 @@ +pluginHelper) && method_exists($mlwQuizMasterNext->pluginHelper, 'register_quiz_settings_tabs')) { + $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs("Sendinblue", 'qsm_addon_XXXX_quiz_settings_tabs_content'); + } +} + +/** + * Generates the content for your quiz settings tab + * + * @since 1.0.0 + * @return void + */ +function qsm_addon_XXXX_quiz_settings_tabs_content() { + + // Display your quiz settings here! +} diff --git a/php/quiz-settings-tab-content.php b/php/quiz-settings-tab-content.php deleted file mode 100644 index 224ea7b..0000000 --- a/php/quiz-settings-tab-content.php +++ /dev/null @@ -1,38 +0,0 @@ -pluginHelper ) && method_exists( $mlwQuizMasterNext->pluginHelper, 'register_quiz_settings_tabs' ) ) { - $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( "Plugin Name", 'qsm_addon_xxxxx_quiz_settings_tabs_content' ); - } -} - -/** - * Generates the content for your quiz settings tab - * - * @since 1.0.0 - * @return void - * @todo Replace the xxxxx with your addon's name - */ -function qsm_addon_xxxxx_quiz_settings_tabs_content() { - - // Enqueue your scripts and styles. - wp_enqueue_script( 'plugin_name_admin_script', plugins_url( '../js/plugin-name-admin.js' , __FILE__ ), array( 'jquery' ) ); - wp_enqueue_style( 'plugin_name_admin_style', plugins_url( '../css/plugin-name-admin.css' , __FILE__ ) ); - - // Display your quiz settings here! -} -?> diff --git a/php/variables.php b/php/variables.php deleted file mode 100644 index d3fa5fd..0000000 --- a/php/variables.php +++ /dev/null @@ -1,29 +0,0 @@ - diff --git a/plugin-name.php b/plugin-name.php deleted file mode 100644 index c872fb3..0000000 --- a/plugin-name.php +++ /dev/null @@ -1,113 +0,0 @@ -load_dependencies(); - $this->add_hooks(); - } - - /** - * Load File Dependencies - * - * @since 1.0.0 - * @return void - * @todo If you are not setting up the addon settings tab, the quiz settings tab, or variables, simply remove the include file below - */ - public function load_dependencies() { - include 'php/addon-settings-tab-content.php'; - include 'php/quiz-settings-tab-content.php'; - include 'php/variables.php'; - } - - /** - * Add Hooks - * - * Adds functions to relavent hooks and filters - * - * @since 1.0.0 - * @return void - * @todo If you are not setting up the addon settings tab, the quiz settings tab, or variables, simply remove the relevant add_action below - */ - public function add_hooks() { - add_action( 'admin_init', 'qsm_addon_xxxxx_register_quiz_settings_tabs' ); - add_action( 'admin_init', 'qsm_addon_xxxxx_register_addon_settings_tabs' ); - add_filter( 'mlw_qmn_template_variable_results_page', 'qsm_addon_xxxxx_my_variable', 10, 2 ); - } -} - -/** - * Loads the addon if QSM is installed and activated - * - * @since 1.0.0 - */ -function qsm_addon_xxxxx_load() { - // Make sure QSM is active. - if ( class_exists( 'MLWQuizMasterNext' ) ) { - $plugin_name = new Plugin_Name(); - } else { - add_action( 'admin_notices', 'qsm_addon_xxxxx_missing_qsm' ); - } -} -add_action( 'plugins_loaded', 'qsm_addon_xxxxx_load' ); - -/** - * Display notice if Quiz And Survey Master isn't installed - * - * @since 1.0.0 - */ -function qsm_addon_xxxxx_missing_qsm() { - echo '

Plugin Name requires Quiz And Survey Master. Please install and activate the Quiz And Survey Master plugin.

'; -} -?> diff --git a/qsm-addon.php b/qsm-addon.php new file mode 100644 index 0000000..0c836c6 --- /dev/null +++ b/qsm-addon.php @@ -0,0 +1,110 @@ +load_dependencies(); + $this->add_hooks(); + } + + /** + * Load Dependencies Files + * + * @since 1.0.0 + * @return void + * @todo If you are not setting up the addon settings tab, the quiz settings tab, or variables, simply remove the include file below + */ + public function load_dependencies() { + include_once(QSM_XXXX_ADDON_PHP_DIR . '/functions.php'); + include_once(QSM_XXXX_ADDON_PHP_DIR . '/qsm-addon-settings.php'); + include_once(QSM_XXXX_ADDON_PHP_DIR . '/qsm-quiz-settings.php'); + } + + public function add_hooks() { + add_action('plugins_loaded', array(&$this, 'load_textdomain')); + } + + public function load_textdomain() { + load_plugin_textdomain(QSM_XXXX_ADDON_TXTDOMAIN, false, dirname(plugin_basename(__FILE__)) . '/lang/'); + } + +} + +/** + * Loads the addon if QSM is installed and activated + * + * @since 1.0.0 + */ +function qsm_addon_customization_XXXX_load() { + if (class_exists('MLWQuizMasterNext')) { + $qsm_customization_XXXX = new QSM_Customization_XXXX(); + } else { + add_action('admin_notices', 'qsm_addon_customization_XXXX_missing_qsm'); + } +} + +add_action('plugins_loaded', 'qsm_addon_customization_XXXX_load'); + +/** + * Display notice if Quiz And Survey Master isn't installed + * + * @since 1.0.0 + */ +function qsm_addon_customization_XXXX_missing_qsm() { + echo '

Custom Addon requires Quiz And Survey Master. Please install and activate the Quiz And Survey Master plugin.

'; +} diff --git a/uninstall.php b/uninstall.php index 1e6ac3c..96ee13d 100644 --- a/uninstall.php +++ b/uninstall.php @@ -9,4 +9,3 @@ } // Delete any options you have created with the addon. -?> From 20c635f18745ebd9dc85fa5f92dca1ddbf7dd678 Mon Sep 17 00:00:00 2001 From: Akshay Paghdar Date: Tue, 13 Apr 2021 15:36:08 +0530 Subject: [PATCH 2/3] Fixed plugin init process. --- php/functions.php | 29 +++++++++++++++++++++++++++++ qsm-addon.php | 38 +++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/php/functions.php b/php/functions.php index b85be0b..d327220 100644 --- a/php/functions.php +++ b/php/functions.php @@ -41,6 +41,35 @@ function qsm_get_quiz_url($quiz_id = 0) { return $permalink; } + /** + * Get a specific property of an array without needing to check if that property exists. + * + * Provide a default value if you want to return a specific value if the property is not set. + * + * @since Unknown + * @access public + * + * @param array $array Array from which the property's value should be retrieved. + * @param string $prop Name of the property to be retrieved. + * @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null. + * + * @return null|string|mixed The value + */ + function rgar($array, $prop, $default = null) { + + if (!is_array($array) && !( is_object($array) && $array instanceof ArrayAccess )) { + return $default; + } + + if (isset($array[$prop])) { + $value = $array[$prop]; + } else { + $value = ''; + } + + return empty($value) && $default !== null ? $default : $value; + } + } } diff --git a/qsm-addon.php b/qsm-addon.php index 0c836c6..6a6bf0b 100644 --- a/qsm-addon.php +++ b/qsm-addon.php @@ -58,8 +58,21 @@ class QSM_Customization_XXXX { * @return void */ public function __construct() { - $this->load_dependencies(); - $this->add_hooks(); + if (class_exists('MLWQuizMasterNext')) { + $this->load_dependencies(); + $this->add_hooks(); + } else { + add_action('admin_notices', array(&$this, 'admin_notices')); + } + } + + /** + * Display notice if Quiz And Survey Master isn't installed + * + * @since 1.0.0 + */ + function admin_notices() { + echo '

Custom Addon requires Quiz And Survey Master. Please install and activate the Quiz And Survey Master plugin.

'; } /** @@ -86,25 +99,8 @@ public function load_textdomain() { } /** - * Loads the addon if QSM is installed and activated + * Loads the addon * * @since 1.0.0 */ -function qsm_addon_customization_XXXX_load() { - if (class_exists('MLWQuizMasterNext')) { - $qsm_customization_XXXX = new QSM_Customization_XXXX(); - } else { - add_action('admin_notices', 'qsm_addon_customization_XXXX_missing_qsm'); - } -} - -add_action('plugins_loaded', 'qsm_addon_customization_XXXX_load'); - -/** - * Display notice if Quiz And Survey Master isn't installed - * - * @since 1.0.0 - */ -function qsm_addon_customization_XXXX_missing_qsm() { - echo '

Custom Addon requires Quiz And Survey Master. Please install and activate the Quiz And Survey Master plugin.

'; -} +$qsm_customization_XXXX = new QSM_Customization_XXXX(); From 66f63582295c5cd7280d0d4101cd8266fa3ea49e Mon Sep 17 00:00:00 2001 From: Akshay Paghdar Date: Mon, 19 Apr 2021 18:18:31 +0530 Subject: [PATCH 3/3] Added Improvements. --- php/functions.php | 41 +++++++----------------- qsm-addon.php | 81 ++++++++++++----------------------------------- uninstall.php | 11 ------- 3 files changed, 33 insertions(+), 100 deletions(-) delete mode 100644 uninstall.php diff --git a/php/functions.php b/php/functions.php index d327220..3e80177 100644 --- a/php/functions.php +++ b/php/functions.php @@ -11,10 +11,22 @@ public function __construct() { /** * Add Hooks & Functions. */ + //add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'), 9999); + //add_action('wp_enqueue_scripts', array(&$this, 'wp_enqueue_scripts'), 9999); //add_action('admin_init', 'qsm_addon_XXXX_register_settings_tabs'); //add_action('admin_init', 'qsm_addon_XXXX_register_quiz_settings_tabs'); } + public function admin_enqueue_scripts() { + wp_enqueue_script('qsm-custom-addon-admin-js', QSM_XXXX_ADDON_JS_URL . '/qsm-custom-addon-admin.js', array('jquery'), QSM_XXXX_ADDON_VERSION, true); + wp_enqueue_style('qsm-custom-addon-admin-css', QSM_XXXX_ADDON_CSS_URL . '/qsm-custom-addon-admin.css'); + } + + public function wp_enqueue_scripts() { + wp_enqueue_script('qsm-custom-addon-front-js', QSM_XXXX_ADDON_JS_URL . '/qsm-custom-addon-front.js', array('jquery'), QSM_XXXX_ADDON_VERSION, true); + wp_enqueue_style('qsm-custom-addon-front-css', QSM_XXXX_ADDON_CSS_URL . '/qsm-custom-addon-front.css'); + } + function qsm_get_quiz_url($quiz_id = 0) { $permalink = ''; if (!empty($quiz_id) && $quiz_id > 0) { @@ -41,35 +53,6 @@ function qsm_get_quiz_url($quiz_id = 0) { return $permalink; } - /** - * Get a specific property of an array without needing to check if that property exists. - * - * Provide a default value if you want to return a specific value if the property is not set. - * - * @since Unknown - * @access public - * - * @param array $array Array from which the property's value should be retrieved. - * @param string $prop Name of the property to be retrieved. - * @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null. - * - * @return null|string|mixed The value - */ - function rgar($array, $prop, $default = null) { - - if (!is_array($array) && !( is_object($array) && $array instanceof ArrayAccess )) { - return $default; - } - - if (isset($array[$prop])) { - $value = $array[$prop]; - } else { - $value = ''; - } - - return empty($value) && $default !== null ? $default : $value; - } - } } diff --git a/qsm-addon.php b/qsm-addon.php index 6a6bf0b..7fd66a4 100644 --- a/qsm-addon.php +++ b/qsm-addon.php @@ -33,74 +33,35 @@ define('QSM_XXXX_ADDON_TXTDOMAIN', 'QSMCustomAddon'); /** - * This class is the main class of the plugin - * - * When loaded, it loads the included plugin files and add functions to hooks or filters. + * Include Required files. + */ +include_once(QSM_XXXX_ADDON_PHP_DIR . '/functions.php'); +include_once(QSM_XXXX_ADDON_PHP_DIR . '/qsm-addon-settings.php'); +include_once(QSM_XXXX_ADDON_PHP_DIR . '/qsm-quiz-settings.php'); + +/** + * Check if QSM is installed and activated * * @since 1.0.0 */ -class QSM_Customization_XXXX { - - /** - * Version Number - * - * @var string - * @since 1.0.0 - */ - public $version = '1.0.0'; - - /** - * Main Construct Function - * - * @since 1.0.0 - * @uses QSM_Customization_XXXX::load_dependencies() Loads required filed - * @uses QSM_Customization_XXXX::add_hooks() Adds actions to hooks and filters - * @return void - */ - public function __construct() { - if (class_exists('MLWQuizMasterNext')) { - $this->load_dependencies(); - $this->add_hooks(); - } else { - add_action('admin_notices', array(&$this, 'admin_notices')); - } - } - - /** - * Display notice if Quiz And Survey Master isn't installed - * - * @since 1.0.0 - */ - function admin_notices() { - echo '

Custom Addon requires Quiz And Survey Master. Please install and activate the Quiz And Survey Master plugin.

'; - } - - /** - * Load Dependencies Files - * - * @since 1.0.0 - * @return void - * @todo If you are not setting up the addon settings tab, the quiz settings tab, or variables, simply remove the include file below - */ - public function load_dependencies() { - include_once(QSM_XXXX_ADDON_PHP_DIR . '/functions.php'); - include_once(QSM_XXXX_ADDON_PHP_DIR . '/qsm-addon-settings.php'); - include_once(QSM_XXXX_ADDON_PHP_DIR . '/qsm-quiz-settings.php'); - } - - public function add_hooks() { - add_action('plugins_loaded', array(&$this, 'load_textdomain')); - } - - public function load_textdomain() { +function qsm_addon_customization_XXXX_load() { + if (class_exists('MLWQuizMasterNext')) { + /** + * Load Translation Support + */ load_plugin_textdomain(QSM_XXXX_ADDON_TXTDOMAIN, false, dirname(plugin_basename(__FILE__)) . '/lang/'); + } else { + add_action('admin_notices', 'qsm_addon_customization_XXXX_missing_qsm'); } - } +add_action('plugins_loaded', 'qsm_addon_customization_XXXX_load'); + /** - * Loads the addon + * Display notice if Quiz And Survey Master isn't installed * * @since 1.0.0 */ -$qsm_customization_XXXX = new QSM_Customization_XXXX(); +function qsm_addon_customization_XXXX_missing_qsm() { + echo '

Custom Addon requires Quiz And Survey Master. Please install and activate the Quiz And Survey Master plugin.

'; +} diff --git a/uninstall.php b/uninstall.php deleted file mode 100644 index 96ee13d..0000000 --- a/uninstall.php +++ /dev/null @@ -1,11 +0,0 @@ -